From 396404bb9d469e41f4af6663b5ab9b53e84ca990 Mon Sep 17 00:00:00 2001 From: Cstack Date: Mon, 16 Nov 2026 23:56:19 -0500 Subject: [PATCH] Repin EndoForge to main 68eaa75 for macOS durable sync; honest run status The vendored EndoForge ledger writer called os.fdatasync, which macOS Python lacks, so every forge goal on macOS failed with "isolate ledger bridge failed: exit 70". Repin with tools/pin_endoforge.py to EndoForge origin/main 68eaa75a0ce5f65b5517077cb736d8d7ffebb755, which syncs through tools/durable.py (F_FULLFSYNC on macOS, else fdatasync, else fsync; endoforge #163). The slice gains tools/durable.py and core/runtime/isolate-wasm-tooling.mjs, now imported by the ledger writer and IsolatePool (27 -> 29 files). No interface in icd-endoforge.md section 8 changed: Ledger and FrozenEvaluators are byte-identical, and IsolatePool only gained optional options Cstack does not pass. cli.py reported run_status "completed" even when the workcell never ran. It now reports completed only when every outcome executed and responded; otherwise stopped, outcome_unknown, failed or not_executed, and a new top-level not_completed list carries each such outcome's status, assessment and limitations. Enforced by RunStatusTests and the NotExecuted forge tests under new requirement CS-REQ-088. Full suite, before -> after: Python 3.13 CI-like venv 71F+3E -> 5F; Python 3.15 on macOS 70F+4E -> 5F. The remaining five are tests/test_workcell_kill.py, whose helpers use GNU ps --ppid and /proc. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 + EXPORT-MANIFEST.json | 108 +++++----- cli.py | 21 +- contracts/SOURCE-PINS.json | 8 +- docs/architecture/architecture.md | 2 +- .../configuration/configuration-management.md | 9 +- .../guides/explanation/endoforge-vendoring.md | 4 +- docs/guides/how-to/repin-endoforge.md | 2 +- docs/guides/reference/commands.md | 3 +- docs/icd/icd-endoforge-pin.md | 9 +- docs/icd/icd-endoforge.md | 5 +- docs/requirements/requirements.md | 15 +- docs/verification/test-plan.md | 2 +- docs/verification/verification-matrix.md | 6 +- tests/test_forge_identity.py | 19 +- tests/test_process_and_cli.py | 18 +- tests/test_workcell_run.py | 1 + tools/pin_endoforge.py | 4 +- vendor/endoforge/SOURCE-MANIFEST.json | 34 +-- vendor/endoforge/core/lifecycle.py | 3 - .../endoforge/core/runtime/isolate-cgroup.mjs | 8 +- .../endoforge/core/runtime/isolate-ledger.mjs | 4 + .../endoforge/core/runtime/isolate-pool.mjs | 180 +++++++++++++++- .../core/runtime/isolate-wasm-tooling.mjs | 198 ++++++++++++++++++ .../endoforge/core/runtime/isolate-wasm.mjs | 13 +- .../core/runtime/isolate-workcell.mjs | 2 +- vendor/endoforge/tools/durable.py | 49 +++++ vendor/endoforge/tools/ledger_writer.py | 20 +- 28 files changed, 630 insertions(+), 119 deletions(-) create mode 100644 vendor/endoforge/core/runtime/isolate-wasm-tooling.mjs create mode 100644 vendor/endoforge/tools/durable.py diff --git a/CHANGELOG.md b/CHANGELOG.md index caf68d0..30e01a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ release yet; entries name the pull requests that made them. ### Changed +- Vendored EndoForge repinned to `main` at `68eaa75`; the slice gains `vendor/endoforge/tools/durable.py` (portable durable sync: `F_FULLFSYNC` on macOS, else `fdatasync`, else `fsync`; endoforge #163) and `vendor/endoforge/core/runtime/isolate-wasm-tooling.mjs` (29 files). Forge goals now run on macOS, where the old ledger writer's `os.fdatasync` call made the ledger bridge exit 70. No Cstack-called interface changed. +- `cli.py` reports `run_status: completed` only when every dispatched call executed and responded; otherwise `not_executed`, `failed`, `outcome_unknown` or `stopped`, with a new top-level `not_completed` list giving each such outcome's status, assessment and limitations (CS-REQ-088). - Re-vendored the four pinned foundations at the commits that merged the 2026-11-09 backfill-review fixes: refrigeration `f78905d`, film `52fa82c`, robotics `d61de96`, template `0dcf469` (template gains one test file, 50 entries). Upstream changed only docs, tests and tools; no bridge or schema changed, so inventory hashes are unchanged. `poodo_skill` moves to `aeba967` (its 45 synced files are byte-identical; the new upstream release-docs test file is listed as deferred). `EXPORT-MANIFEST.json` rebuilt. EndoForge stays pinned until its rounds 8-10 merge. - README and docs index rewritten for a first-time reader: purpose, a real approval run, a top-down diagram and install first; the NASA control documents sit behind one "Engineering records" section. Material moved out of the README went to new how-to guides (approve asks, define bots, use a real model, add a domain, merge train) and an explanation of Foundations and pins. The README's Measured table moved to `docs/verification/measured-2026-11.md`, with every figure tied to a commit on `main` (assurance finding F-7) (#80). diff --git a/EXPORT-MANIFEST.json b/EXPORT-MANIFEST.json index f7a575a..c34e444 100644 --- a/EXPORT-MANIFEST.json +++ b/EXPORT-MANIFEST.json @@ -27,7 +27,7 @@ "bytes": 1415 }, ".github/workflows/ci.yml": { - "sha256": "7a77c7f271c47d8c89db411c767ce79eab77c9d497961d6abe1fdbd4f3227fea", + "sha256": "e50ae65fffd328ad8b1b3ab7b3561a6f22ddd488cd334159324280d0165e635b", "bytes": 1052 }, ".gitignore": { @@ -51,8 +51,8 @@ "bytes": 4359 }, "CHANGELOG.md": { - "sha256": "4b45ad9f8663e5d4e32a2398d5be78a5eeb21bbf95ad3ec5f520f845524c828e", - "bytes": 7103 + "sha256": "1a9c3d31167801964d360bc2019b7a7332939cad8f619dd34c28794d05ebc1ba", + "bytes": 7811 }, "CODE_OF_CONDUCT.md": { "sha256": "6228457a516409a784d807676564c8477f58d979eb7df3a4f690008d8a794442", @@ -403,8 +403,8 @@ "bytes": 158 }, "cli.py": { - "sha256": "c6c687ad9fd223584aa50d9950739cdaa9d790cb47f1ccd58d953d02f68f8408", - "bytes": 9577 + "sha256": "04bf55fc8c71ec54ba023540d3b90dd229e09ba4bc92a0a91c85f92c843bbcb5", + "bytes": 10442 }, "contracts/ACCEPTANCE.md": { "sha256": "bc7eba9871279b57f8d8c71f3e5ac03ecae5f267848f42fd9284bf99ebea5a55", @@ -447,7 +447,7 @@ "bytes": 2565 }, "contracts/SOURCE-PINS.json": { - "sha256": "ab1069af603ad59cd3e1b97dcb766c5df497b4ef2fa3867c6ca0aea6e52158e8", + "sha256": "cc32fd5f8fa33886c07eabb12b1741b1ae2c144e0918811845bcb929b0660a23", "bytes": 9207 }, "contracts/adapters.schema.json": { @@ -475,16 +475,16 @@ "bytes": 7078 }, "docs/architecture/architecture.md": { - "sha256": "d5a259bcfc07576eac4cea7a74036744a5320dec2d98e74debc53a1df47243c3", - "bytes": 22319 + "sha256": "85b9db883a80055088fef2543e4e8ddf58397931736395b6e079908eb8d84ed6", + "bytes": 22331 }, "docs/assurance/assurance-record.md": { "sha256": "71d5308e71aa46f70dd1ac06cd99e19955ae63bafd3cea57355634924b3b8a7f", "bytes": 8279 }, "docs/configuration/configuration-management.md": { - "sha256": "df65f3d26e003ab038b1a9f4df324ee2ae16b0c8fe05983b81626b6dcc902049", - "bytes": 16687 + "sha256": "1b23d089f1bd3f689bde48a37af660bf03de1cc4d9bf7e5336ed9a4b33dbf8a2", + "bytes": 16822 }, "docs/data/data-dictionary.md": { "sha256": "abd81fc7faf9533885139909d7748dcc720bd3308e93e0aa838b257c9f38e6cb", @@ -499,8 +499,8 @@ "bytes": 1051 }, "docs/guides/explanation/endoforge-vendoring.md": { - "sha256": "c99bbc59dfb0054b163a47cc9656ac1f45915a4da3320b4e2759d4ed770960a6", - "bytes": 8168 + "sha256": "ddbbc7eff9f7f9b199b356e60f6c99c54a7bac3fa6a9ef7976f3c0f6c1710026", + "bytes": 8289 }, "docs/guides/explanation/foundations-and-pins.md": { "sha256": "20b9b80dbffff240e4b6caf06f38677c7a40ebca114ad19a9d937e5f8075a8a1", @@ -535,8 +535,8 @@ "bytes": 3363 }, "docs/guides/how-to/repin-endoforge.md": { - "sha256": "1532c7554e343aaea7702f3ebc24ba79efda1aa72ced1ffdb4da6bc56b1f9e0d", - "bytes": 4911 + "sha256": "36fd284348130c8920f637f3e4c4256e1e999e3684b5164cc67904cfc9dffa2e", + "bytes": 5053 }, "docs/guides/how-to/run-ci-locally.md": { "sha256": "2cf4d16896f4863d3949be5e6d0a352606d9782ba1ac79717d62c6c148215ce8", @@ -551,8 +551,8 @@ "bytes": 1800 }, "docs/guides/reference/commands.md": { - "sha256": "61af7b706324d15cdcd8af87a460d801aaafda861750b40662811f01ca855519", - "bytes": 9258 + "sha256": "92bbef1083f83ac71ed34492cbd058440753ed9881517f3cd0d52fc3e64eae8c", + "bytes": 9872 }, "docs/guides/reference/configuration.md": { "sha256": "edf4f27e425d74117146a5ae2393d793dba08b2cf6911ad5874dc9c23040092c", @@ -571,12 +571,12 @@ "bytes": 7604 }, "docs/icd/icd-endoforge-pin.md": { - "sha256": "7602054207a725e24ef5c28153582ebdf09d3f89df5e82dac286f827f0147c06", - "bytes": 5086 + "sha256": "6f1b5e9cdc4e5c6e73c6eafa36f65b151f7e3d6cbd36446bd0594acfdf52d36f", + "bytes": 5669 }, "docs/icd/icd-endoforge.md": { - "sha256": "46ebe62d65b97ef6d9f89fab8a9f2254a342cb5d1ef809df02bcf9ebae37cbb1", - "bytes": 21041 + "sha256": "394685253dbcd3b6fd79da1d90ba39e264f34396a2086bf0933e9f4470fea5ca", + "bytes": 21585 }, "docs/icd/icd-foundations.md": { "sha256": "bcabb16e735448824c89dcb91ca416b0f80a555e316991252dcc6fe01c67fd03", @@ -603,8 +603,8 @@ "bytes": 5760 }, "docs/requirements/requirements.md": { - "sha256": "aa5457afcdd3ae494306a74b75319ccd0fd0725de4c3587832083699a29491a7", - "bytes": 49158 + "sha256": "eef135ea51a7e6372693545b49f74366ae6d7cec9f547686faf88f38d92a9a92", + "bytes": 49914 }, "docs/rules/no-comments.md": { "sha256": "cd0aac16b8119228bb5b7e79d38e71ddcc430679916a9f7080d7b3bd88fb4a90", @@ -707,12 +707,12 @@ "bytes": 4756 }, "docs/verification/test-plan.md": { - "sha256": "e7568f1451f2ee0f6b5685984bf96e7cc25fc762ca62e7d0cfb29a38c6c6a8aa", - "bytes": 9734 + "sha256": "f2d03648bdfd1dddc6fde71db5b5fb7a884283273e5da1ece7d654e4e84ff03a", + "bytes": 9725 }, "docs/verification/verification-matrix.md": { - "sha256": "36973230602038f7ee2a96fc73ff992c3a37ce7e8c2f89feb8e2aed3a13f2391", - "bytes": 23845 + "sha256": "6c50cecd4e6c7c8271313892332d3f4253265f6ce3d278c13b6efabb64089df9", + "bytes": 24311 }, "docs/verification/wiring-acceptance.md": { "sha256": "a063e0580bf60ca41b37d473f1df7989b12c7e0aa915cecef30b916a4c4720d8", @@ -2299,8 +2299,8 @@ "bytes": 2651 }, "tests/test_forge_identity.py": { - "sha256": "6e0303dd9ea15f31e9cf517d9b574980ee5382ef44505c25ebff26fe2d617911", - "bytes": 7462 + "sha256": "1e1772fa8ce0f6c3c4c70aa9365b9f93dccca2ced4a836314c37d4144b194170", + "bytes": 7915 }, "tests/test_forge_inputs.py": { "sha256": "61ebe7afe2987cc42a0e03a8faabbff01f7116531aa1b2c0e6b49d17891b44f2", @@ -2375,8 +2375,8 @@ "bytes": 5129 }, "tests/test_process_and_cli.py": { - "sha256": "b3f741614d5d18599f1e4a9a4af3f301fb72923e80dec72f40d94ee7a87fe68f", - "bytes": 8933 + "sha256": "57a8e45667c63aa3f4e7997d02a263719545173e163b026295526e3046ad1ba0", + "bytes": 10052 }, "tests/test_provider_policy.py": { "sha256": "ec241cb9ca46d52e97d701ef465ae4b69f3dafc4e8695ada747d4d0157e01951", @@ -2459,8 +2459,8 @@ "bytes": 10945 }, "tests/test_workcell_run.py": { - "sha256": "2e869f4dfa73675aabf7d09bf7c9d497d7e8a02a32c3e5c10cce12e2b2b11b2d", - "bytes": 4435 + "sha256": "fc0772606bab58cc2288f6a72861e5032fb1c434bf748ba16c33dd5263e58633", + "bytes": 4489 }, "tests/test_workspace_snapshots.py": { "sha256": "4aff69a78080c0abcd07e9ca87cbc3973a180c82da0e131d3b8d6671a521c85a", @@ -2531,8 +2531,8 @@ "bytes": 9762 }, "tools/pin_endoforge.py": { - "sha256": "3a23984286d2e27327e296a58f1f1c2c32cf2ac6d19dc6cca32d54c419e87eca", - "bytes": 5538 + "sha256": "5629a42f15e26b3c842ffe96c0eb671f0681871b24a8f21178c3381819c66da0", + "bytes": 5599 }, "tools/pin_workcell.py": { "sha256": "e7740a583e385324a5730f17da45a9682871475161d7000d35d4143f1a7be629", @@ -2571,8 +2571,8 @@ "bytes": 35149 }, "vendor/endoforge/SOURCE-MANIFEST.json": { - "sha256": "c59a2e91d89afc3b6a9cce0bc84edd53da793659e8d658837a21f42c2a8c7612", - "bytes": 5654 + "sha256": "4dfd1e67e5ca1f5441e2ec5376161477d422d56ad1f2eff9a71200116b1f2e28", + "bytes": 6056 }, "vendor/endoforge/core/__init__.py": { "sha256": "fa04d7c1baadd8d76b569dbbeaee47e538384f60e588c6b756dbf1edd2f39c6a", @@ -2607,8 +2607,8 @@ "bytes": 6551 }, "vendor/endoforge/core/lifecycle.py": { - "sha256": "42e3c4b3ffa19ddc0c6ce5a583245fb175d9ceac82380dc12e52cc534fd0b330", - "bytes": 10121 + "sha256": "56686c3d3670fb04082bb9743d3fd77b1519ce9240f322438421584a067c80d6", + "bytes": 10118 }, "vendor/endoforge/core/runtime/capacity/cli.mjs": { "sha256": "361ae1a647e24b95f0234aebefd09ad86d6adb23fda089717dff095065434fee", @@ -2639,28 +2639,32 @@ "bytes": 5253 }, "vendor/endoforge/core/runtime/isolate-cgroup.mjs": { - "sha256": "60ed29794aaeb4951793454c72e393d9981619f78bc6fa36348376a7412be1b1", - "bytes": 2533 + "sha256": "f73eb78eb495bf447bc934fb41808908852a79acb9d0c65e04c656740a507458", + "bytes": 2735 }, "vendor/endoforge/core/runtime/isolate-ledger.mjs": { - "sha256": "82584b718359900d7396401162f328669b016ca9472171a9f917d57357f7f7d5", - "bytes": 7581 + "sha256": "6c6fa141d12578ee6c3567bdea65303da6f62350a65c81fe7c4a3769d901e0dc", + "bytes": 7629 }, "vendor/endoforge/core/runtime/isolate-pool.mjs": { - "sha256": "137846fa05dd2c099201acb6fdb24694f592968c2f6bc3660432d4d21f2a961e", - "bytes": 24703 + "sha256": "b84c62d22331d9aea9f5942d959828d4ecd82c4a96e83d2ff981fd3327241a37", + "bytes": 32512 }, "vendor/endoforge/core/runtime/isolate-wasm-compile.mjs": { "sha256": "9644689bd4f48ba88ca2c3216b57af35772e5a03530ac7c933cdce5072789c32", "bytes": 653 }, + "vendor/endoforge/core/runtime/isolate-wasm-tooling.mjs": { + "sha256": "23ae0d3f0c7e0ac5b8b9b7bcea859c9313a8c365fee522cc2f90a294c56e2693", + "bytes": 9694 + }, "vendor/endoforge/core/runtime/isolate-wasm.mjs": { - "sha256": "b6dc03955db4aefbe2c1f6a7f7d554afb96ec79ee6d8a1f0b13626d88ae439ca", - "bytes": 14524 + "sha256": "0e1d049f1b31155c41d09882e238ea754e806095e86fee643cb1de75ea3925f3", + "bytes": 15404 }, "vendor/endoforge/core/runtime/isolate-workcell.mjs": { - "sha256": "722d3b68ae1a8b9c02f086f79fb7fec40ba31a6cd301ddd79a47fec8cba29ed8", - "bytes": 3647 + "sha256": "7482d0679f5bc4704d92f5a9992267d18f0af5fcf2fcec5eae3844c3c87a9c21", + "bytes": 3675 }, "vendor/endoforge/tests/test_endoforge_core_boundary.py": { "sha256": "c3cf526f13e0723754ae7bd4f8be1c9bc8394176c011623ea65ec5a76c3df822", @@ -2670,13 +2674,17 @@ "sha256": "5feac43d815ded2489260b13a1cdcde515c734e873726be6a3519365ed7847a7", "bytes": 6813 }, + "vendor/endoforge/tools/durable.py": { + "sha256": "61cd2c5cad1c2b8550753b5e4f607fad8c9ef9759f5e2c672757b5c2ad8c7456", + "bytes": 1057 + }, "vendor/endoforge/tools/factory_quality/index.mjs": { "sha256": "3779ac6c6b48a273186200612a556d9bf3f5e00f541e1e2dff3812775231bf31", "bytes": 13551 }, "vendor/endoforge/tools/ledger_writer.py": { - "sha256": "a000160b86fe11ace9a483a073671f6d1accfc7143cdf1e21e95dfe0c9ce7044", - "bytes": 21064 + "sha256": "7c410bcc030b43361492914164a733c202beb07e35b8ff3f1ed4c21c50e15d2d", + "bytes": 21265 }, "vendor/foundation-engine-v020/SOURCE-MANIFEST.json": { "sha256": "0617efcbbb594919137ca6b748de189516ee9ec35e49f56765109cfe9fb01349", diff --git a/cli.py b/cli.py index 44bb21f..eae06e6 100644 --- a/cli.py +++ b/cli.py @@ -14,6 +14,7 @@ CLI_SCHEMA = "cstack.run/0.1" MAX_OUTPUT = 33 * 1024 * 1024 +EXECUTED = ("completed", "tool_error") class DriverRefusal(ContractError): @@ -103,8 +104,11 @@ def _run_document(document, host, approver): "reason": "core_contract_or_retention_gate" if isinstance(error, ContractError) else "endoforge_storage_failure", "later_not_dispatched": decisions[index+1:]} break + outcomes = [e["data"]["outcome"] for e in core.ledger() if e["kind"] == "outcome"] return {"schema": "cstack.run-result/0.1", "goal": core.snapshot(goal.goal_id).to_dict(), - "events": core.ledger(), "run_status": "stopped" if stopped else "completed", "stopped": stopped, + "events": core.ledger(), "run_status": run_status(stopped, outcomes), "stopped": stopped, + "not_completed": [{key: o[key] for key in ("decision_id", "attempt_id", "execution_status", "execution_certainty", + "assessment", "limitations")} for o in outcomes if not executed(o)], "outcome_unknown": [{"decision_id": e["data"]["outcome"]["decision_id"], "attempt_id": e["data"]["outcome"]["attempt_id"], "assessment": e["data"]["outcome"]["assessment"]} for e in core.ledger() if e["kind"] == "outcome" and e["data"]["outcome"]["execution_certainty"] == "unknown"], @@ -112,6 +116,21 @@ def _run_document(document, host, approver): "note": "Preauthored checkpoint records were structurally checked, not researched or reasoned by this driver."} +def executed(outcome): + return outcome["execution_status"] in EXECUTED and outcome["execution_certainty"] == "responded" + + +def run_status(stopped, outcomes): + if stopped: + return "stopped" + missed = [o for o in outcomes if not executed(o)] + if any(o["execution_certainty"] == "unknown" for o in missed): + return "outcome_unknown" + if any(o["execution_certainty"] == "responded" for o in missed): + return "failed" + return "not_executed" if missed else "completed" + + def _goal_domain(value): domain_id = value["goal"].get("domain_id") if type(value) is dict and type(value.get("goal")) is dict else None return domain_id if type(domain_id) is str else None diff --git a/contracts/SOURCE-PINS.json b/contracts/SOURCE-PINS.json index 0a72cb9..9493882 100644 --- a/contracts/SOURCE-PINS.json +++ b/contracts/SOURCE-PINS.json @@ -39,11 +39,11 @@ }, "endoforge": { "root": "vendor/endoforge", - "commit": "ea7b8d651ce23acd100f5a5d81d6e8fda0d604a3", - "source_manifest_sha256": "c59a2e91d89afc3b6a9cce0bc84edd53da793659e8d658837a21f42c2a8c7612", - "source_manifest_entry_count": 27, + "commit": "68eaa75a0ce5f65b5517077cb736d8d7ffebb755", + "source_manifest_sha256": "4dfd1e67e5ca1f5441e2ec5376161477d422d56ad1f2eff9a71200116b1f2e28", + "source_manifest_entry_count": 29, "on_main": true, - "main_commit": "ea7b8d651ce23acd100f5a5d81d6e8fda0d604a3" + "main_commit": "68eaa75a0ce5f65b5517077cb736d8d7ffebb755" }, "poodo_skill": { "root": "reasoning/poodo", diff --git a/docs/architecture/architecture.md b/docs/architecture/architecture.md index fafe6da..70cc2cf 100644 --- a/docs/architecture/architecture.md +++ b/docs/architecture/architecture.md @@ -66,7 +66,7 @@ Each component lists the requirements allocated to it. `python -B tools/check_tr | SDD-C6 | Sibling Foundation adapters | `adapters/foundation_stdio.py`, `adapters/film_stdio.py`, `adapters/refrigeration_stdio.py`, `adapters/robotics_stdio.py`, `adapters/template_stdio.py`, `extensions/foundation_film.py`, `extensions/foundation_refrigeration.py`, `extensions/foundation_robotics.py`, `extensions/foundation_template.py` | Profile-driven pins, schema checks and receipt binding for the vendored Film, Refrigeration, Robotics and Template Foundations | CS-REQ-064 | | SDD-C7 | Engine adapter | `adapters/engine_stdio.py`, `extensions/foundation_engine.py` | Pinned partial copy of the Foundation Engine bridge; two read-only validators | CS-REQ-065 | | SDD-C8 | Process executor | `adapters/execution.py` | Fixed module launch, deadlines, cancellation, output bounds and process-group cleanup | CS-REQ-009, CS-REQ-010, CS-REQ-011 | -| SDD-C9 | CLI driver and terminal approval | `cli.py`, `__main__.py`, `adapters/terminal_approver.py`, `tools/e2e_refrigeration.sh` | Reads one structured document, drives the core, asks for approval, prints one JSON result | CS-REQ-017, CS-REQ-018, CS-REQ-031, CS-REQ-067 | +| SDD-C9 | CLI driver and terminal approval | `cli.py`, `__main__.py`, `adapters/terminal_approver.py`, `tools/e2e_refrigeration.sh` | Reads one structured document, drives the core, asks for approval, prints one JSON result | CS-REQ-017, CS-REQ-018, CS-REQ-031, CS-REQ-067, CS-REQ-088 | | SDD-C10 | Approval store and scheduled approvals | `adapters/approval_store.py`, `adapters/private_sqlite.py`, `tools/scheduled_approvals.py` | Durable owner approvals: write once, consume once; the owner's ask list | CS-REQ-039, CS-REQ-056 | | SDD-C11 | Witnessed evidence (EndoForge port) | `poodo_core/ports.py` (EndoforgePort), `adapters/endoforge_ledger.py` | Hash-chained, fsynced, exclusively locked evidence file; routing from configured cores | CS-REQ-020, CS-REQ-021, CS-REQ-022, CS-REQ-023, CS-REQ-024, CS-REQ-025, CS-REQ-026, CS-REQ-027, CS-REQ-028, CS-REQ-029, CS-REQ-030 | | SDD-C12 | Forge runtime | `extensions/cstack_forge.py`, `adapters/endoforge_workcell.py`, `adapters/workcell/`, `adapters/workcell-toolchain/`, `tools/pin_workcell.py` | One governed EndoForge run per call in `IsolatePool` workcells, registered in `bootstrap.RUNTIMES` | CS-REQ-032, CS-REQ-033, CS-REQ-034, CS-REQ-035, CS-REQ-068, CS-REQ-069 | diff --git a/docs/configuration/configuration-management.md b/docs/configuration/configuration-management.md index 1aa9fa5..eb9ed61 100644 --- a/docs/configuration/configuration-management.md +++ b/docs/configuration/configuration-management.md @@ -63,10 +63,10 @@ These public main heads were copied on 2026-11-08. Each source manifest and ever ### Endoforge source -`vendor/endoforge/` holds a 27-file slice of Endoforge commit -`ea7b8d651ce23acd100f5a5d81d6e8fda0d604a3` on `main`: the lifecycle model, run ledger, -gates and evaluator, `IsolatePool` and its workcell, the capacity planner and two -support tools. Control the slice list in `tools/pin_endoforge.py`, the upstream and +`vendor/endoforge/` holds a 29-file slice of Endoforge commit +`68eaa75a0ce5f65b5517077cb736d8d7ffebb755` on `main`: the lifecycle model, run ledger, +gates and evaluator, `IsolatePool` and its workcell, the capacity planner and the +support tools they import. Control the slice list in `tools/pin_endoforge.py`, the upstream and exported hashes, and the `endoforge` record in `contracts/SOURCE-PINS.json` together, as described in [the source-pin ICD](../icd/icd-endoforge-pin.md) and [the repin guide](../guides/how-to/repin-endoforge.md). Python comment tokens are @@ -169,3 +169,4 @@ Control `examples/refrigeration-e2e.json`, `tests/test_refrigeration_e2e.py`, an | 2.0 | 2026-11-08 | 6ae5481fd302439dabb23044d1b715ac8c4a9bec | Family standard header; organization, status accounting, audits, generated outputs, release management; vendored docs and upstream; trace suite in CI | docs/nasa-standard PR | | 2.1 | 2026-11-08 | b7c64b19e3966baaf1aa6793491b454e28f51446 | Foundation, Engine and POODO repin: manifest digests, upstream commits, POODO commit | PR #78 | | 2.2 | 2026-11-08 | 84cd19d238a057b1c07af63e64b50edfb515d615 | EndoForge repin to ea7b8d6: 27-file slice, manifest digest | PR #79 | +| 2.3 | 2026-11-16 | this PR | EndoForge repin to 68eaa75: 29-file slice, manifest digest | fix/repin-endoforge-macos PR | diff --git a/docs/guides/explanation/endoforge-vendoring.md b/docs/guides/explanation/endoforge-vendoring.md index 25f058f..ab289ed 100644 --- a/docs/guides/explanation/endoforge-vendoring.md +++ b/docs/guides/explanation/endoforge-vendoring.md @@ -16,7 +16,7 @@ The cost is that the copy falls behind. A pin says the bytes are unchanged. It d ## What is in the slice -The slice is the `SLICE` list in `tools/pin_endoforge.py`. It has 27 files: +The slice is the `SLICE` list in `tools/pin_endoforge.py`. It has 29 files: | Part | Files | Used by Cstack for | |---|---|---| @@ -25,7 +25,7 @@ The slice is the `SLICE` list in `tools/pin_endoforge.py`. It has 27 files: | Gates and evaluator | `vendor/endoforge/core/engine/` | The universal gates and frozen evaluator that judge each candidate inside a cell | | Workcell runtime | `vendor/endoforge/core/runtime/isolate-*.mjs`, `vendor/endoforge/core/runtime/dump-list.mjs` | `IsolatePool`, which `adapters/workcell/supervisor.mjs` imports, and the cells, WASM limits, cgroup attachment, ledger bridge and memguard dump-list registration it uses | | Capacity planner | `vendor/endoforge/core/runtime/capacity/` | Nothing at run time. It is carried because its CLI is its interface for non-Node callers. Since EndoForge P-68, `IsolatePool` doesn't import it, and Cstack sets the pool size itself (`workcell.size`, default 1) | -| Support | `vendor/endoforge/tools/factory_quality/index.mjs`, `vendor/endoforge/tools/ledger_writer.py`, `vendor/endoforge/tools/dump_list.py`, `vendor/endoforge/LICENSE` | Contract and signature checks the gates import; the group-commit ledger writer the ledger bridge runs, and its dump-list registration | +| Support | `vendor/endoforge/tools/factory_quality/index.mjs`, `vendor/endoforge/tools/ledger_writer.py`, `vendor/endoforge/tools/dump_list.py`, `vendor/endoforge/tools/durable.py`, `vendor/endoforge/LICENSE` | Contract and signature checks the gates import; the group-commit ledger writer the ledger bridge runs, its dump-list registration, and its portable durable sync (`F_FULLFSYNC` on macOS, else `fdatasync`, else `fsync`) | Everything else in EndoForge stays out: the agent pool and loop, the oracle, caching, experiments and the other tools. Cstack doesn't run coding agents through EndoForge's own loop; it runs one governed goal through the pool. diff --git a/docs/guides/how-to/repin-endoforge.md b/docs/guides/how-to/repin-endoforge.md index 9f0949c..7ef0d94 100644 --- a/docs/guides/how-to/repin-endoforge.md +++ b/docs/guides/how-to/repin-endoforge.md @@ -59,7 +59,7 @@ python -B -m unittest discover -s tests bash ci/run-local.sh python links trace ``` -The forge goal must print `completed ['candidate_passed']`. It needs a `cstack.config.json` copied from `cstack.config.example.json`. The workcell tests (`tests/test_workcell_*.py`) run the real pool, gates and ledger, so a breaking change upstream shows there. +The forge goal must print `completed ['candidate_passed']`. If the workcell could not run (for example the ledger bridge exits), it prints `not_executed` and the result's `not_completed` list says why. It needs a `cstack.config.json` copied from `cstack.config.example.json`. The workcell tests (`tests/test_workcell_*.py`) run the real pool, gates and ledger, so a breaking change upstream shows there. ## 4. Update the records diff --git a/docs/guides/reference/commands.md b/docs/guides/reference/commands.md index 80a9f2c..9e61548 100644 --- a/docs/guides/reference/commands.md +++ b/docs/guides/reference/commands.md @@ -31,7 +31,8 @@ Output, on stdout, exit 0: one `cstack.run-result/0.1` document. | Field | Meaning | |---|---| -| `run_status` | `completed`, or `stopped` when a call was refused or storage failed | +| `run_status` | `completed` only when every dispatched call executed and responded (execution status `completed` or `tool_error`). Otherwise `stopped` when a call was refused or storage failed, `outcome_unknown` when an attempt may have run but its result is unknown, `failed` when a call responded with another execution status, or `not_executed` when a call was not dispatched (for example no `node`, no `npm ci`, or a ledger that cannot open) | +| `not_completed` | One entry per outcome that did not execute and respond: `decision_id`, `attempt_id`, `execution_status`, `execution_certainty`, `assessment` and `limitations`, so the reason is at top level. Empty when `run_status` is `completed` | | `stopped` | `null`, or the decision, its `execution_certainty` (`not_dispatched` or `unknown`), the reason and the decisions not dispatched after it | | `goal` | The goal snapshot. `closed` is always `false`; a run never closes a goal | | `events` | The core ledger for this run | diff --git a/docs/icd/icd-endoforge-pin.md b/docs/icd/icd-endoforge-pin.md index b951698..38d4ec9 100644 --- a/docs/icd/icd-endoforge-pin.md +++ b/docs/icd/icd-endoforge-pin.md @@ -3,17 +3,17 @@ | Field | Value | |---|---| | Document ID | CSTACK-ICD-ENDOFORGE-PIN | -| Version | 2.1 | +| Version | 2.2 | | Status | Baselined | | Owner | Akilleez-QA | -| Date | 2026-11-08 | +| Date | 2026-11-16 | | Baseline commit | 84cd19d238a057b1c07af63e64b50edfb515d615 | | Applies to | cstack main at baseline commit | | Classification | Self-assessed Class E analog; not safety-critical (see [SMP §1](../plan/software-management-plan.md#1-software-classification-self-assessed)) | > Organized after [NPR 7150.2D](https://nodis3.gsfc.nasa.gov/displayAll.cfm?Internal_ID=N_PR_7150_002D_&page_name=all), [NASA-STD-8739.8B](https://standards.nasa.gov/standard/nasa/nasa-std-87398) and the [NASA Software Engineering Handbook](https://swehb.nasa.gov/display/SWEHBVD/7.18+-+Documentation+Guidance) documentation guidance. This is not a NASA compliance determination or certification. The software classification is a self-assessed analog (Class E, not safety-critical); no NASA authority, independent verification and validation, or hazard analysis is asserted. The document describes the implementation inspected at the baseline commit. -The source is Endoforge commit `ea7b8d651ce23acd100f5a5d81d6e8fda0d604a3`, on `main` (the merge of Akilleez-QA/endoforge#131). Since the previous pin, `6dffea9`, the slice gained `vendor/endoforge/core/runtime/dump-list.mjs` and `vendor/endoforge/tools/dump_list.py`, which `IsolatePool` and the ledger writer import for memguard dump-list registration (Akilleez-QA/endoforge#111); it lost nothing. +The source is Endoforge commit `68eaa75a0ce5f65b5517077cb736d8d7ffebb755`, on `main` (the merge of Akilleez-QA/endoforge#161). Since the previous pin, `ea7b8d6`, the slice gained `vendor/endoforge/tools/durable.py`, the portable durable-sync helper the ledger writer now imports (`F_FULLFSYNC` on macOS, else `fdatasync`, else `fsync`; Akilleez-QA/endoforge#163), and `vendor/endoforge/core/runtime/isolate-wasm-tooling.mjs`, which `IsolatePool` and the WASM limit now import for digest-pinned tooling modules (Akilleez-QA/endoforge#153, #155); it lost nothing. The earlier ledger writer called `os.fdatasync`, which macOS Python does not provide, so every forge goal on macOS failed with `isolate ledger bridge failed: exit 70`. `vendor/endoforge/` holds the lifecycle model, its import-boundary test, the ledger and frozen evaluator, the real gates and evaluator, `IsolatePool` and its workcell, the capacity planner (`core/runtime/capacity/`, code name Mjölnir), the group-commit ledger writer its bridge runs, the dump-list registration modules both import, the guard, and the checks the gates import. It can't run coding agents by itself; [the interface](icd-endoforge.md) says how Cstack runs it. @@ -33,7 +33,7 @@ The tool refuses a commit that isn't reachable from the clone's `origin/main`, s `--allow-unmerged` pins an unmerged commit as a deliberate exception; the record then says `"on_main": false, "allow_unmerged": true`. The pin test checks that the record carries one of these forms. With `CSTACK_ENDOFORGE_CLONE` set to a fetched EndoForge clone, it also checks that an `on_main` pin is reachable from `main_commit` and from that clone's `origin/main`; CI doesn't set it. The same stripping reproduces the earlier lifecycle file's bytes, commit `4ede82329c64f3f72026dea57ac66095324ec1c4`. -The slice is the fixed list in `tools/pin_endoforge.py`. It includes all of `core/runtime/capacity/`, because the module's CLI is its interface for non-Node callers (EndoForge's [capacity ICD](https://github.com/Akilleez-QA/endoforge/blob/main/docs/interfaces/capacity-icd.md)). Since P-68, `IsolatePool`'s default size is `availableParallelism()` again and it no longer imports the planner. It excludes EndoForge's `tools/` other than `vendor/endoforge/tools/factory_quality/index.mjs`, `vendor/endoforge/tools/ledger_writer.py`, which the isolate ledger bridge imports, and `vendor/endoforge/tools/dump_list.py`, which the ledger writer imports, and it excludes the agent pool and all experiments. The pin doesn't prove the content is correct, and `main` moves on upstream; a change needs a new pin. +The slice is the fixed list in `tools/pin_endoforge.py`. It includes all of `core/runtime/capacity/`, because the module's CLI is its interface for non-Node callers (EndoForge's [capacity ICD](https://github.com/Akilleez-QA/endoforge/blob/main/docs/interfaces/capacity-icd.md)). Since P-68, `IsolatePool`'s default size is `availableParallelism()` again and it no longer imports the planner. It excludes EndoForge's `tools/` other than `vendor/endoforge/tools/factory_quality/index.mjs`, `vendor/endoforge/tools/ledger_writer.py`, which the isolate ledger bridge imports, and `vendor/endoforge/tools/dump_list.py` and `vendor/endoforge/tools/durable.py`, which the ledger writer imports, and it excludes the agent pool and all experiments. The pin doesn't prove the content is correct, and `main` moves on upstream; a change needs a new pin. AssemblyScript 0.28.20 and its dependencies (binaryen, long; all Apache-2.0) are third-party npm packages, locked in `adapters/workcell-toolchain/package-lock.json`, not vendored. `adapters/workcell/compiler.mjs` checks their hashes before every run. @@ -48,3 +48,4 @@ CS-REQ-070 (EndoForge pin) and CS-REQ-069 (forge part pins). See the [verificati | 1.x | 2026-10 to 2026-11-08 | various | Earlier versions | See `git log -- docs/icd/icd-endoforge-pin.md` | | 2.0 | 2026-11-08 | 6ae5481fd302439dabb23044d1b715ac8c4a9bec | Family standard header and disclaimer; requirements-addressed section | docs/nasa-standard PR | | 2.1 | 2026-11-08 | 84cd19d238a057b1c07af63e64b50edfb515d615 | EndoForge repin to ea7b8d6; slice gains the dump-list modules | PR #79 | +| 2.2 | 2026-11-16 | this PR | EndoForge repin to 68eaa75; slice gains `vendor/endoforge/tools/durable.py` and `vendor/endoforge/core/runtime/isolate-wasm-tooling.mjs` (29 files) | fix/repin-endoforge-macos PR | diff --git a/docs/icd/icd-endoforge.md b/docs/icd/icd-endoforge.md index 7d38e49..3ce0339 100644 --- a/docs/icd/icd-endoforge.md +++ b/docs/icd/icd-endoforge.md @@ -45,7 +45,7 @@ when host configuration binds this port, otherwise `False`. The current claim-gate CLI rejects `--atoms`, `--atom-refs` and `--consumer` requests with exit status 2 and a `cstack.claim-gate/0.1` JSON error on stderr stating that the approved-atoms Registry is unavailable. It emits no verdict on stdout. The pinned lifecycle slice does not provide that Registry; the dead optional import has been removed. Calls without atom options retain the ledger-only interface. -[PR #16](https://github.com/Akilleez-QA/cstack/pull/16) added a pinned lifecycle-core slice from Endoforge commit `cebd463ea9828dfd9bbf09181a631ee604eac8cf`. That slice held data and lifecycle rules plus an import-boundary test; the current pin, Endoforge `main` commit `ea7b8d651ce23acd100f5a5d81d6e8fda0d604a3`, adds the gates, ledger, `IsolatePool` and capacity planner that section 7 runs or carries. It has no agent runner or caching implementation. Its source-pin ICD, [icd-endoforge-pin.md](icd-endoforge-pin.md), records the manifest hash. Vendoring source does not implement `EndoforgePort`. +[PR #16](https://github.com/Akilleez-QA/cstack/pull/16) added a pinned lifecycle-core slice from Endoforge commit `cebd463ea9828dfd9bbf09181a631ee604eac8cf`. That slice held data and lifecycle rules plus an import-boundary test; the current pin, Endoforge `main` commit `68eaa75a0ce5f65b5517077cb736d8d7ffebb755`, adds the gates, ledger, `IsolatePool` and capacity planner that section 7 runs or carries. It has no agent runner or caching implementation. Its source-pin ICD, [icd-endoforge-pin.md](icd-endoforge-pin.md), records the manifest hash. Vendoring source does not implement `EndoforgePort`. ## 3. Operations and sequencing @@ -201,7 +201,7 @@ Limits, and what the runtime doesn't prove: V8 has no instruction fuel, so `fuel ## 8. Endoforge interfaces Cstack uses -These are the only vendored Endoforge names Cstack code calls at the current pin. A repin that changes any of them changes this interface; see [the repin guide](../guides/how-to/repin-endoforge.md). +These are the only vendored Endoforge names Cstack code calls at the current pin. A repin that changes any of them changes this interface; see [the repin guide](../guides/how-to/repin-endoforge.md). The repin to `68eaa75` changed none of them: `Ledger` and `FrozenEvaluators` are byte-identical, `IsolatePool` only gained the optional `toolingWasmModules` and `syncHostCalls` options (Cstack passes neither, so the pool behaves as before), `ENDOFORGE_LEDGER_JOURNAL` and `ENDOFORGE_DUMP_LIST` are read as before, and the ledger writer now syncs through `vendor/endoforge/tools/durable.py`. | Caller | Endoforge interface | Use | |---|---|---| @@ -226,3 +226,4 @@ CS-REQ-020 to CS-REQ-030 (evidence port, file adapter and configured routing); C | 2.0 | 2026-11-08 | 6ae5481fd302439dabb23044d1b715ac8c4a9bec | Family standard header and disclaimer; requirements-addressed section | docs/nasa-standard PR | | 2.1 | 2026-11-08 | 84cd19d238a057b1c07af63e64b50edfb515d615 | Pin commit updated; ENDOFORGE_DUMP_LIST row added to section 8 | PR #79 | | 2.2 | 2026-11-09 | 6088dd4 | Lost-controller row: a session that ends with an unknown outcome keeps its core ledger as `.recovered` | PR fixing the 2026-11-09 backfill-review findings | +| 2.3 | 2026-11-16 | this PR | Pin commit updated to 68eaa75; section 8 records that no Cstack-called interface changed | fix/repin-endoforge-macos PR | diff --git a/docs/requirements/requirements.md b/docs/requirements/requirements.md index 604e464..46082c5 100644 --- a/docs/requirements/requirements.md +++ b/docs/requirements/requirements.md @@ -3,10 +3,10 @@ | Field | Value | |---|---| | Document ID | CSTACK-SRS | -| Version | 2.1 | +| Version | 2.2 | | Status | Baselined | | Owner | Akilleez-QA | -| Date | 2026-11-09 | +| Date | 2026-11-16 | | Baseline commit | 6ae5481fd302439dabb23044d1b715ac8c4a9bec | | Applies to | cstack main at baseline commit | | Classification | Self-assessed Class E analog; not safety-critical (see [SMP §1](../plan/software-management-plan.md#1-software-classification-self-assessed)) | @@ -373,6 +373,16 @@ The CLI shall reject duplicate keys, floating-point and non-finite numbers, inva - Verification: T - Status: Baselined +### CS-REQ-088 — Honest run status + +The CLI run result shall report `run_status` `completed` only when no call was stopped and every outcome has execution status `completed` or `tool_error` with certainty `responded`. Otherwise it shall report `stopped`, `outcome_unknown`, `failed` or `not_executed`, in that precedence, and list each outcome that did not execute and respond, with its execution status, certainty, assessment and limitations, in a top-level `not_completed` field. + +- Rationale: a run whose workcell never ran must not look like a success at top level. +- Derivation: `cli.py` +- Allocated to: SDD-C9 +- Verification: T +- Status: Baselined + ### CS-REQ-039 — Durable approval store The SQLite approval store shall give cores a reader with no write path, let a consume succeed exactly once across restarts and racing processes while recording the consumer, allow one final answer per decision, refuse declined and expired approvals at their boundary, and fail closed on a bad clock, a symlinked path or a closed store. @@ -866,3 +876,4 @@ GPL-3.0-only. Commercial licenses under different terms are available from Refri | 1.x | 2026-10 to 2026-11-08 | various | CS-REQ-001 to CS-REQ-035 added across earlier PRs | See `git log -- docs/requirements/requirements.md` | | 2.0 | 2026-11-08 | 6ae5481fd302439dabb23044d1b715ac8c4a9bec | Family standard format: metadata, record fields, allocation to SDD components; CS-REQ-036 to CS-REQ-077 added from tested behaviour; CS-REQ-027 to CS-REQ-030 restated without repeating the port text | docs/nasa-standard PR | | 2.1 | 2026-11-09 | 6088dd4 | CS-REQ-045 covers a session that ends with an unknown outcome; CS-REQ-047 covers a failed file open | PR fixing the 2026-11-09 backfill-review findings | +| 2.2 | 2026-11-16 | this PR | CS-REQ-088 honest run status added | fix/repin-endoforge-macos PR | diff --git a/docs/verification/test-plan.md b/docs/verification/test-plan.md index 38b3785..58563bc 100644 --- a/docs/verification/test-plan.md +++ b/docs/verification/test-plan.md @@ -104,7 +104,7 @@ Automated suites: the code is the procedure; run the command in §2. The numbere - Preconditions: a fetched EndoForge clone. - Steps: `CSTACK_ENDOFORGE_CLONE= python -B -m unittest tests.test_endoforge_pin`. - Expected result: 4 tests OK, none skipped. -- Last run: 2026-11-08 for the repin to `ea7b8d6` (PR #79), with a clone fetched at `ea7b8d6`: 4 tests OK, none skipped. +- Last run: 2026-11-16 for the repin to `68eaa75`, with a clone fetched at `68eaa75`: 4 tests OK, none skipped. ### TP-5 — README commands on a fresh clone diff --git a/docs/verification/verification-matrix.md b/docs/verification/verification-matrix.md index 1be2ee1..8657819 100644 --- a/docs/verification/verification-matrix.md +++ b/docs/verification/verification-matrix.md @@ -3,10 +3,10 @@ | Field | Value | |---|---| | Document ID | CSTACK-VM | -| Version | 2.1 | +| Version | 2.2 | | Status | Baselined | | Owner | Akilleez-QA | -| Date | 2026-11-09 | +| Date | 2026-11-16 | | Baseline commit | 6ae5481fd302439dabb23044d1b715ac8c4a9bec | | Applies to | cstack main at baseline commit | | Classification | Self-assessed Class E analog; not safety-critical (see [SMP §1](../plan/software-management-plan.md#1-software-classification-self-assessed)) | @@ -98,6 +98,7 @@ The matrix does not embed pass counts. A mapped test shows the requirement is ex | CS-REQ-065 | T | `tests/test_engine_conformance.py` | Two read-only validators only | [STR-baseline](reports/STR-baseline.md) | | CS-REQ-066 | T | `tests/test_domain_registry.py` | Copies the checkout without `foundations/refrigeration/` | [STR-baseline](reports/STR-baseline.md) | | CS-REQ-067 | T | `tests/test_process_and_cli.py::CliTests` | Exit status 2 on each rejected document | [STR-baseline](reports/STR-baseline.md) | +| CS-REQ-088 | T | `tests/test_process_and_cli.py::RunStatusTests`; `tests/test_forge_identity.py::NotExecuted`; `tests/test_workcell_run.py::OneGoal` | Status precedence for each outcome mix; a forge run that never dispatched reports `not_executed` with the reason in `not_completed`; a passing run reports `completed` with an empty list | [STR-baseline](reports/STR-baseline.md) | | CS-REQ-068 | T | `tests/test_forge_identity.py`; `tests/test_forge_inputs.py`; `tests/test_forge_journal.py` | Not-executed cases run nothing | [STR-baseline](reports/STR-baseline.md) | | CS-REQ-069 | T | `tests/test_forge_integrity.py::Pins`; `tests/test_forge_integrity.py::Attribution`; `tests/test_foundation_kernels.py::Pins`; `tests/test_workcell_film_robotics.py::Pins` | Changed parts refuse to run | [STR-baseline](reports/STR-baseline.md) | | CS-REQ-070 | T | `tests/test_endoforge_pin.py`; `tests/test_pin_endoforge_tool.py` | Byte identity of the vendored slice; upstream boundary suite needs `CSTACK_ENDOFORGE_CLONE` | [STR-baseline](reports/STR-baseline.md) | @@ -157,3 +158,4 @@ GPL-3.0-only. Commercial licenses under different terms are available from Refri | 1.x | 2026-10 to 2026-11-08 | various | Rows for CS-REQ-001 to CS-REQ-035 | See `git log -- docs/verification/verification-matrix.md` | | 2.0 | 2026-11-08 | 6ae5481fd302439dabb23044d1b715ac8c4a9bec | One row per requirement in `file::Class.method` form; rows for CS-REQ-036 to CS-REQ-077; gap table; every test file traced; `tools/check_trace.py` | docs/nasa-standard PR | | 2.1 | 2026-11-09 | 6088dd4 | CS-REQ-045 row adds the session-end and workcell-kill tests; CS-REQ-047 row names a failed file open | PR fixing the 2026-11-09 backfill-review findings | +| 2.2 | 2026-11-16 | this PR | Row for CS-REQ-088 | fix/repin-endoforge-macos PR | diff --git a/tests/test_forge_identity.py b/tests/test_forge_identity.py index f1da555..ffed3fb 100644 --- a/tests/test_forge_identity.py +++ b/tests/test_forge_identity.py @@ -41,13 +41,21 @@ def assert_not_executed(self, final): self.assertEqual((final["execution_status"], final["execution_certainty"]), ("unavailable", "not_dispatched"), final) self.assertNotIn("may have executed", json.dumps(final["limitations"])) + def assert_run_not_executed(self, document): + final = outcome(document) + self.assert_not_executed(final) + self.assertEqual(document["run_status"], "not_executed") + self.assertEqual(document["not_completed"], [{key: final[key] for key in ( + "decision_id", "attempt_id", "execution_status", "execution_certainty", "assessment", "limitations")}]) + self.assertNotEqual(document["not_completed"][0]["assessment"], "candidate_passed") + return final + def test_no_node_on_path(self): forge = Forge(SATURATION) self.addCleanup(forge.close) env = {**forge.env, "PATH": str(Path(sys.executable).parent)} result = forge.raw(GOAL, env=env) - final = outcome(json.loads(result.stdout)) - self.assert_not_executed(final) + final = self.assert_run_not_executed(json.loads(result.stdout)) self.assertIn("node", json.dumps(final["limitations"])) def test_missing_node_modules_says_how_to_fix_it(self): @@ -57,20 +65,19 @@ def test_missing_node_modules_says_how_to_fix_it(self): (copy.root / "adapters/workcell-toolchain/node_modules").unlink() forge = Forge(SATURATION, root=copy.root) self.addCleanup(forge.close) - final = outcome(forge.run(GOAL)) - self.assert_not_executed(final) + final = self.assert_run_not_executed(forge.run(GOAL)) self.assertIn("npm ci", json.dumps(final["limitations"])) def test_a_host_without_a_transport_ran_nothing(self): forge = Forge(transport=False) self.addCleanup(forge.close) - self.assert_not_executed(outcome(forge.run(GOAL))) + self.assert_run_not_executed(forge.run(GOAL)) def test_a_ledger_that_cannot_open_ran_nothing(self): forge = Forge(SATURATION) self.addCleanup(forge.close) (forge.directory / "forge.sqlite").mkdir() - self.assert_not_executed(outcome(forge.run(GOAL))) + self.assert_run_not_executed(forge.run(GOAL)) class RequestShape(unittest.TestCase): diff --git a/tests/test_process_and_cli.py b/tests/test_process_and_cli.py index 861272a..c49790f 100644 --- a/tests/test_process_and_cli.py +++ b/tests/test_process_and_cli.py @@ -14,7 +14,7 @@ from poodo_core import * from adapters.memory_ledger import MemoryLedger from extensions.foundation_math import FoundationMath, MATH_CAPABILITY, TOOL_NAMES -from cli import run_document +from cli import run_document, run_status from tests.test_math_adapter import math_request ROOT = Path(__file__).resolve().parents[1] @@ -99,6 +99,22 @@ def exchange(self, frames, cancellation=None): self.assertIsNone(result["raw_result"]) +class RunStatusTests(unittest.TestCase): + def outcome(self, status, certainty): + return {"execution_status": status, "execution_certainty": certainty} + + def test_completed_only_when_every_attempt_executed_and_responded(self): + executed = [self.outcome("completed", "responded"), self.outcome("tool_error", "responded")] + self.assertEqual(run_status(None, executed), "completed") + self.assertEqual(run_status(None, executed + [self.outcome("unavailable", "not_dispatched")]), "not_executed") + self.assertEqual(run_status(None, executed + [self.outcome("protocol_error", "responded")]), "failed") + self.assertEqual(run_status(None, [self.outcome("unavailable", "not_dispatched"), self.outcome("indeterminate", "unknown")]), + "outcome_unknown") + self.assertEqual(run_status(None, [self.outcome("protocol_error", "responded"), self.outcome("unavailable", "not_dispatched")]), + "failed") + self.assertEqual(run_status({"decision_id": "d"}, [self.outcome("unavailable", "not_dispatched")]), "stopped") + + class CliTests(unittest.TestCase): def run_cli_without_host_config(self, raw): with tempfile.TemporaryDirectory() as tmp: diff --git a/tests/test_workcell_run.py b/tests/test_workcell_run.py index 31f44fd..f464607 100644 --- a/tests/test_workcell_run.py +++ b/tests/test_workcell_run.py @@ -10,6 +10,7 @@ def check_passes(self, isolation): self.addCleanup(forge.close) result = forge.run(GOAL) self.assertEqual(result["run_status"], "completed") + self.assertEqual(result["not_completed"], []) self.assertIs(result["endoforge_implemented"], True) self.assertEqual(result["outcome_unknown"], []) final = outcome(result) diff --git a/tools/pin_endoforge.py b/tools/pin_endoforge.py index 8055908..905f872 100644 --- a/tools/pin_endoforge.py +++ b/tools/pin_endoforge.py @@ -18,8 +18,8 @@ "core/runtime/capacity/cli.mjs", "core/runtime/capacity/controller.mjs", "core/runtime/capacity/index.mjs", "core/runtime/capacity/plan.mjs", "core/runtime/capacity/probe.mjs", "core/runtime/capacity/tuner.mjs", "core/runtime/dump-list.mjs", "core/runtime/isolate-cgroup.mjs", "core/runtime/isolate-ledger.mjs", "core/runtime/isolate-pool.mjs", - "core/runtime/isolate-wasm-compile.mjs", "core/runtime/isolate-wasm.mjs", "core/runtime/isolate-workcell.mjs", - "tools/dump_list.py", "tools/factory_quality/index.mjs", "tools/ledger_writer.py", "LICENSE") + "core/runtime/isolate-wasm-compile.mjs", "core/runtime/isolate-wasm-tooling.mjs", "core/runtime/isolate-wasm.mjs", + "core/runtime/isolate-workcell.mjs", "tools/dump_list.py", "tools/durable.py", "tools/factory_quality/index.mjs", "tools/ledger_writer.py", "LICENSE") def sha256(data): diff --git a/vendor/endoforge/SOURCE-MANIFEST.json b/vendor/endoforge/SOURCE-MANIFEST.json index f22150d..56c9e5a 100644 --- a/vendor/endoforge/SOURCE-MANIFEST.json +++ b/vendor/endoforge/SOURCE-MANIFEST.json @@ -1,11 +1,11 @@ { "schema": "endoforge-source-manifest/1", "repository": "https://github.com/Akilleez-QA/endoforge", - "commit": "ea7b8d651ce23acd100f5a5d81d6e8fda0d604a3", + "commit": "68eaa75a0ce5f65b5517077cb736d8d7ffebb755", "strip_python_comments": true, "upstream_files": { "core/__init__.py": "fa04d7c1baadd8d76b569dbbeaee47e538384f60e588c6b756dbf1edd2f39c6a", - "core/lifecycle.py": "f44a569b571d28f987cd5863a84197fbb6fde3660dbf1f96d9ffccd92f3c634b", + "core/lifecycle.py": "56686c3d3670fb04082bb9743d3fd77b1519ce9240f322438421584a067c80d6", "tests/test_endoforge_core_boundary.py": "c3cf526f13e0723754ae7bd4f8be1c9bc8394176c011623ea65ec5a76c3df822", "core/ledger/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "core/ledger/frozen.py": "ed00f30823f28d7997877005f1830c07a8df6806b325d57730a6e60cc6c3413e", @@ -21,20 +21,22 @@ "core/runtime/capacity/probe.mjs": "3123bec1f48d41e297e95384ab661baa524fe050c761b4c46b0b804faf0867f2", "core/runtime/capacity/tuner.mjs": "a8bc21a810c49f8293c8ce016855a43f671db10184d25904d7759186d7ab11dc", "core/runtime/dump-list.mjs": "8b187c9cdc60364beb2770bc7312b470ee999cb43728b38762fc5277c35e8c98", - "core/runtime/isolate-cgroup.mjs": "60ed29794aaeb4951793454c72e393d9981619f78bc6fa36348376a7412be1b1", - "core/runtime/isolate-ledger.mjs": "82584b718359900d7396401162f328669b016ca9472171a9f917d57357f7f7d5", - "core/runtime/isolate-pool.mjs": "137846fa05dd2c099201acb6fdb24694f592968c2f6bc3660432d4d21f2a961e", + "core/runtime/isolate-cgroup.mjs": "f73eb78eb495bf447bc934fb41808908852a79acb9d0c65e04c656740a507458", + "core/runtime/isolate-ledger.mjs": "6c6fa141d12578ee6c3567bdea65303da6f62350a65c81fe7c4a3769d901e0dc", + "core/runtime/isolate-pool.mjs": "b84c62d22331d9aea9f5942d959828d4ecd82c4a96e83d2ff981fd3327241a37", "core/runtime/isolate-wasm-compile.mjs": "9644689bd4f48ba88ca2c3216b57af35772e5a03530ac7c933cdce5072789c32", - "core/runtime/isolate-wasm.mjs": "b6dc03955db4aefbe2c1f6a7f7d554afb96ec79ee6d8a1f0b13626d88ae439ca", - "core/runtime/isolate-workcell.mjs": "722d3b68ae1a8b9c02f086f79fb7fec40ba31a6cd301ddd79a47fec8cba29ed8", + "core/runtime/isolate-wasm-tooling.mjs": "23ae0d3f0c7e0ac5b8b9b7bcea859c9313a8c365fee522cc2f90a294c56e2693", + "core/runtime/isolate-wasm.mjs": "0e1d049f1b31155c41d09882e238ea754e806095e86fee643cb1de75ea3925f3", + "core/runtime/isolate-workcell.mjs": "7482d0679f5bc4704d92f5a9992267d18f0af5fcf2fcec5eae3844c3c87a9c21", "tools/dump_list.py": "5feac43d815ded2489260b13a1cdcde515c734e873726be6a3519365ed7847a7", + "tools/durable.py": "61cd2c5cad1c2b8550753b5e4f607fad8c9ef9759f5e2c672757b5c2ad8c7456", "tools/factory_quality/index.mjs": "3779ac6c6b48a273186200612a556d9bf3f5e00f541e1e2dff3812775231bf31", - "tools/ledger_writer.py": "a000160b86fe11ace9a483a073671f6d1accfc7143cdf1e21e95dfe0c9ce7044", + "tools/ledger_writer.py": "7c410bcc030b43361492914164a733c202beb07e35b8ff3f1ed4c21c50e15d2d", "LICENSE": "3972dc9744f6499f0f9b2dbf76696f2ae7ad8af9b23dde66d6af86c9dfb36986" }, "files": { "core/__init__.py": "fa04d7c1baadd8d76b569dbbeaee47e538384f60e588c6b756dbf1edd2f39c6a", - "core/lifecycle.py": "42e3c4b3ffa19ddc0c6ce5a583245fb175d9ceac82380dc12e52cc534fd0b330", + "core/lifecycle.py": "56686c3d3670fb04082bb9743d3fd77b1519ce9240f322438421584a067c80d6", "tests/test_endoforge_core_boundary.py": "c3cf526f13e0723754ae7bd4f8be1c9bc8394176c011623ea65ec5a76c3df822", "core/ledger/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "core/ledger/frozen.py": "ed00f30823f28d7997877005f1830c07a8df6806b325d57730a6e60cc6c3413e", @@ -50,15 +52,17 @@ "core/runtime/capacity/probe.mjs": "3123bec1f48d41e297e95384ab661baa524fe050c761b4c46b0b804faf0867f2", "core/runtime/capacity/tuner.mjs": "a8bc21a810c49f8293c8ce016855a43f671db10184d25904d7759186d7ab11dc", "core/runtime/dump-list.mjs": "8b187c9cdc60364beb2770bc7312b470ee999cb43728b38762fc5277c35e8c98", - "core/runtime/isolate-cgroup.mjs": "60ed29794aaeb4951793454c72e393d9981619f78bc6fa36348376a7412be1b1", - "core/runtime/isolate-ledger.mjs": "82584b718359900d7396401162f328669b016ca9472171a9f917d57357f7f7d5", - "core/runtime/isolate-pool.mjs": "137846fa05dd2c099201acb6fdb24694f592968c2f6bc3660432d4d21f2a961e", + "core/runtime/isolate-cgroup.mjs": "f73eb78eb495bf447bc934fb41808908852a79acb9d0c65e04c656740a507458", + "core/runtime/isolate-ledger.mjs": "6c6fa141d12578ee6c3567bdea65303da6f62350a65c81fe7c4a3769d901e0dc", + "core/runtime/isolate-pool.mjs": "b84c62d22331d9aea9f5942d959828d4ecd82c4a96e83d2ff981fd3327241a37", "core/runtime/isolate-wasm-compile.mjs": "9644689bd4f48ba88ca2c3216b57af35772e5a03530ac7c933cdce5072789c32", - "core/runtime/isolate-wasm.mjs": "b6dc03955db4aefbe2c1f6a7f7d554afb96ec79ee6d8a1f0b13626d88ae439ca", - "core/runtime/isolate-workcell.mjs": "722d3b68ae1a8b9c02f086f79fb7fec40ba31a6cd301ddd79a47fec8cba29ed8", + "core/runtime/isolate-wasm-tooling.mjs": "23ae0d3f0c7e0ac5b8b9b7bcea859c9313a8c365fee522cc2f90a294c56e2693", + "core/runtime/isolate-wasm.mjs": "0e1d049f1b31155c41d09882e238ea754e806095e86fee643cb1de75ea3925f3", + "core/runtime/isolate-workcell.mjs": "7482d0679f5bc4704d92f5a9992267d18f0af5fcf2fcec5eae3844c3c87a9c21", "tools/dump_list.py": "5feac43d815ded2489260b13a1cdcde515c734e873726be6a3519365ed7847a7", + "tools/durable.py": "61cd2c5cad1c2b8550753b5e4f607fad8c9ef9759f5e2c672757b5c2ad8c7456", "tools/factory_quality/index.mjs": "3779ac6c6b48a273186200612a556d9bf3f5e00f541e1e2dff3812775231bf31", - "tools/ledger_writer.py": "a000160b86fe11ace9a483a073671f6d1accfc7143cdf1e21e95dfe0c9ce7044", + "tools/ledger_writer.py": "7c410bcc030b43361492914164a733c202beb07e35b8ff3f1ed4c21c50e15d2d", "LICENSE": "3972dc9744f6499f0f9b2dbf76696f2ae7ad8af9b23dde66d6af86c9dfb36986" } } diff --git a/vendor/endoforge/core/lifecycle.py b/vendor/endoforge/core/lifecycle.py index de7a826..0cfdb06 100644 --- a/vendor/endoforge/core/lifecycle.py +++ b/vendor/endoforge/core/lifecycle.py @@ -54,7 +54,6 @@ class State(str, Enum): _LIVE = (State.PROPOSED, State.GENERATED, State.QUALIFIED, State.PREVIEWED) - LEGAL = { State.GENERATED: (State.PROPOSED,), State.QUALIFIED: (State.GENERATED,), @@ -64,7 +63,6 @@ class State(str, Enum): State.REJECTED: _LIVE, State.DISPOSED: tuple(s for s in State if s is not State.DISPOSED), } - _EVIDENCE = { State.GENERATED: {"candidate_sha256"}, State.QUALIFIED: {"receipt"}, @@ -236,7 +234,6 @@ def apply(self, proposal: TransitionProposal, decision: PoodoDecision) -> "Lifec artifact = replace(artifact, candidate_sha256=evidence["candidate_sha256"]) elif proposal.to_state is State.QUALIFIED: artifact = replace(artifact, qualification_receipt_sha256=evidence["receipt"].sha256) - record = object.__new__(LifecycleRecord) for name, value in (("artifact", artifact), ("frozen_oracle_id", self.frozen_oracle_id), ("state", proposal.to_state), diff --git a/vendor/endoforge/core/runtime/isolate-cgroup.mjs b/vendor/endoforge/core/runtime/isolate-cgroup.mjs index 976c2ca..05aee5f 100644 --- a/vendor/endoforge/core/runtime/isolate-cgroup.mjs +++ b/vendor/endoforge/core/runtime/isolate-cgroup.mjs @@ -51,8 +51,14 @@ export function attachCgroup(pid, root, limits, swapPresent = hostHasSwap) { } } +const removeGroup = (directory, attempts) => { + try { rmdirSync(directory); } catch (error) { + if (error.code === 'EBUSY' && attempts > 0) setTimeout(removeGroup, 20, directory, attempts - 1).unref(); + } +}; + export function releaseCgroup(directory) { if (!directory) return; try { writeFileSync(join(directory, 'cgroup.kill'), '1'); } catch { } - try { rmdirSync(directory); } catch { } + removeGroup(directory, 100); } diff --git a/vendor/endoforge/core/runtime/isolate-ledger.mjs b/vendor/endoforge/core/runtime/isolate-ledger.mjs index 67236d3..acecde3 100644 --- a/vendor/endoforge/core/runtime/isolate-ledger.mjs +++ b/vendor/endoforge/core/runtime/isolate-ledger.mjs @@ -101,6 +101,10 @@ export class LedgerBridge { return Boolean(this.#failure); } + get pid() { + return this.#child?.pid; + } + request(action, job, result) { if (this.#failure) return Promise.reject(this.#failure); const id = ++this.#next; diff --git a/vendor/endoforge/core/runtime/isolate-pool.mjs b/vendor/endoforge/core/runtime/isolate-pool.mjs index 537c09d..ba4f519 100644 --- a/vendor/endoforge/core/runtime/isolate-pool.mjs +++ b/vendor/endoforge/core/runtime/isolate-pool.mjs @@ -4,11 +4,13 @@ import { resolve } from 'node:path'; import { fileURLToPath, pathToFileURL } from 'node:url'; import { Worker } from 'node:worker_threads'; import { execFileSync, fork, spawn } from 'node:child_process'; -import { readFileSync } from 'node:fs'; +import { readFileSync, readSync, writeSync } from 'node:fs'; +import { deserialize, serialize } from 'node:v8'; import { dumpListEnabled, registerHolder } from './dump-list.mjs'; import { attachCgroup, prepareCgroup, releaseCgroup } from './isolate-cgroup.mjs'; import { LedgerBridge } from './isolate-ledger.mjs'; import { trustedWasmPolicy } from './isolate-wasm.mjs'; +import { toolingWasmPolicy } from './isolate-wasm-tooling.mjs'; const positive = value => Number.isSafeInteger(value) && value > 0; const stackMargin = 192; @@ -25,6 +27,10 @@ const requireProcessStack = stackSizeMb => { }; const maxHostCalls = 4096; const maxHostCallBytes = 1048576; +const maxSyncReplyBytes = 17 * 1048576; +const syncHeader = 8; +const syncIdle = 0, syncRequest = 1, syncReply = 2, syncClosed = 3; +const syncRequestFd = 4, syncReplyFd = 5; const killGraceMs = 1000; const exitGraceMs = 500; export const POOL_DUMP_DEFAULTS = Object.freeze({ name: 'endoforge-isolate-pool', priority: 20, floor: 1, holdMs: 30000, intervalMs: 2000, settleMs: 1500 }); @@ -39,6 +45,7 @@ export class IsolatePool { #limits; #wasmMemoryMaxMb; #trustedWasmModules; + #toolingWasmModules; #isolation; #cgroupRoot; #cgroupLimits; @@ -71,9 +78,10 @@ export class IsolatePool { #shedUntil = 0; #holdTimer = null; #rates; + #syncHostCalls; constructor({ hostPort, size = availableParallelism(), resourceLimits = {}, wasmMemoryMaxMb = 64, - isolation = 'thread', cgroupRoot, cgroupLimits = {}, trustedWasmModules = [], sharedWasmModules = [], prewarm = false, warm, warmTimeoutMs = 60000, jobTimeoutMs, jobDeadlineMs, hostCall, hostCalls, frozenThroughLedger = false, cellEnv, cellFlags = [], ledgerBridge, retireAfterJobs = 256, dumpList, rates = null } = {}) { + isolation = 'thread', cgroupRoot, cgroupLimits = {}, trustedWasmModules = [], sharedWasmModules = [], toolingWasmModules = [], prewarm = false, warm, warmTimeoutMs = 60000, jobTimeoutMs, jobDeadlineMs, hostCall, hostCalls, syncHostCalls, frozenThroughLedger = false, cellEnv, cellFlags = [], ledgerBridge, retireAfterJobs = 256, dumpList, rates = null } = {}) { if (!positive(retireAfterJobs)) throw new TypeError('retireAfterJobs must be a positive integer'); this.#retireAfterJobs = retireAfterJobs; this.#rates = rates; @@ -91,7 +99,9 @@ export class IsolatePool { if (!positive(warmTimeoutMs)) throw new TypeError('warmTimeoutMs must be a positive integer'); if (hostCalls !== undefined && typeof hostCalls !== 'function') throw new TypeError('hostCalls must be a function'); if (typeof frozenThroughLedger !== 'boolean') throw new TypeError('frozenThroughLedger must be boolean'); + if (syncHostCalls !== undefined && typeof syncHostCalls !== 'function') throw new TypeError('syncHostCalls must be a function'); this.#hostCalls = hostCalls; + this.#syncHostCalls = syncHostCalls; this.#frozenThroughLedger = frozenThroughLedger; this.#warmOptions = warm; this.#warmTimeoutMs = warmTimeoutMs; @@ -116,6 +126,8 @@ export class IsolatePool { this.#limits = Object.freeze(limits); this.#wasmMemoryMaxMb = wasmMemoryMaxMb; this.#trustedWasmModules = trustedWasmPolicy(trustedWasmModules, wasmMemoryMaxMb); + this.#toolingWasmModules = toolingWasmPolicy(toolingWasmModules, wasmMemoryMaxMb); + if (this.#toolingWasmModules.some(({ sha256 }) => this.#trustedWasmModules.some(entry => entry.sha256 === sha256))) throw new TypeError('a digest cannot be both trusted and tooling'); this.#isolation = isolation; if (!Array.isArray(sharedWasmModules) || !sharedWasmModules.every(({ sha256, path }) => typeof path === 'string' && path && this.#trustedWasmModules.some(entry => entry.sha256 === sha256))) throw new TypeError('sharedWasmModules must name trustedWasmModules digests and paths'); @@ -271,10 +283,10 @@ export class IsolatePool { #spawn() { const subprocess = this.#isolation === 'process'; const entry = new URL('./isolate-workcell.mjs', import.meta.url); - const policy = { wasmMemoryMaxMb: this.#wasmMemoryMaxMb, trustedWasmModules: this.#trustedWasmModules, + const policy = { wasmMemoryMaxMb: this.#wasmMemoryMaxMb, trustedWasmModules: this.#trustedWasmModules, toolingWasmModules: this.#toolingWasmModules, ...(this.#warmOptions ? { warm: this.#warmOptions, hostPort: this.#hostPort } : {}) }; const heapArgv = [`--max-old-space-size=${this.#limits.maxOldGenerationSizeMb}`, `--max-semi-space-size=${this.#limits.maxYoungGenerationSizeMb}`, ...this.#cellFlags]; - const processOptions = { serialization: 'advanced', stdio: ['ignore', 'ignore', 'pipe', 'ipc'], ...(this.#cellEnv ? { env: this.#cellEnv } : {}) }; + const processOptions = { serialization: 'advanced', stdio: ['ignore', 'ignore', 'pipe', 'ipc', ...(this.#syncHostCalls ? ['pipe', 'pipe'] : [])], ...(this.#cellEnv ? { env: this.#cellEnv } : {}) }; const processArguments = [JSON.stringify({ ...policy, resourceLimits: this.#limits })]; const stackKb = this.#limits.stackSizeMb && this.#limits.stackSizeMb * 1024; const worker = subprocess ? (stackKb @@ -303,6 +315,7 @@ export class IsolatePool { worker.kill(); }); } + if (this.#syncHostCalls) this.#openSync(cell); cell.started = new Promise(resolve => { cell.markStarted = resolve; }); cell.gone = new Promise(resolve => { cell.markGone = resolve; }); this.#cells.add(cell); @@ -345,6 +358,7 @@ export class IsolatePool { clearTimeout(exitTimer); clearTimeout(cell.warmTimer); cell.markGone(); + this.#closeSync(cell); this.#cells.delete(cell); cell.markStarted(false); releaseCgroup(directory); @@ -395,7 +409,8 @@ export class IsolatePool { if (this.#jobDeadlineMs) job.total = setTimeout(() => this.#stop(cell), this.#jobDeadlineMs); const { reference, candidates, portOptions } = job.data; job.hostCalls = 0; - cell.worker.postMessage({ reference, candidates, portOptions, hostPort: this.#hostPort, frozenThroughLedger: this.#frozenThroughLedger }); + cell.worker.postMessage({ reference, candidates, portOptions: cell.sync ? { ...portOptions, syncHostCall: cell.sync.channel } : portOptions, + hostPort: this.#hostPort, frozenThroughLedger: this.#frozenThroughLedger }); } catch (error) { if (cell?.job === job) cell.job = null; if (this.#claim(job)) this.#finish(job, { status: 'outcome_unknown', reason: error.message, @@ -448,6 +463,7 @@ export class IsolatePool { job.budget -= performance.now() - job.armed; job.pong = performance.now(); job.liveness = setInterval(() => { + if (job.syncing) job.pong = performance.now(); if (performance.now() - job.pong > this.#jobTimeoutMs) return this.#stop(cell); try { cell.worker.postMessage({ type: 'ping' }); } catch { } }, Math.ceil(this.#jobTimeoutMs / 3)); @@ -460,12 +476,101 @@ export class IsolatePool { job.calls -= 1; if (job.calls === 0 && this.#jobTimeoutMs) { clearInterval(job.liveness); - this.#arm(cell, job); + if (!job.syncing) this.#arm(cell, job); } try { cell.worker.postMessage({ type: 'host-reply', ...reply }); } catch { } }); } + #openSync(cell) { + if (this.#isolation === 'thread') { + const buffer = new SharedArrayBuffer(syncHeader + 65536, { maxByteLength: syncHeader + maxSyncReplyBytes }); + cell.sync = { channel: { kind: 'shared', buffer }, control: new Int32Array(buffer, 0, 2) }; + this.#watchShared(cell); + return; + } + const input = cell.worker.stdio[syncRequestFd], output = cell.worker.stdio[syncReplyFd]; + cell.sync = { channel: { kind: 'pipe', request: syncRequestFd, reply: syncReplyFd } }; + let pending = Buffer.alloc(0), queue = Promise.resolve(); + input.on('error', () => {}); + output.on('error', () => {}); + input.on('data', chunk => { + pending = Buffer.concat([pending, chunk]); + while (pending.length >= 4) { + const length = pending.readUInt32LE(0); + if (length > maxHostCallBytes) { + pending = Buffer.alloc(0); + cell.error = { code: 'ERR_WORKCELL_HOST_CALL_SIZE' }; + cell.stopping = true; + cell.worker.terminate(); + return; + } + if (pending.length < 4 + length) return; + const body = pending.subarray(4, 4 + length); + pending = pending.subarray(4 + length); + queue = queue.then(() => this.#serveSync(cell, body)).then(reply => { + const head = Buffer.alloc(4); + head.writeUInt32LE(reply.length); + if (!output.destroyed) output.write(Buffer.concat([head, reply])); + }); + } + }); + } + + async #watchShared(cell) { + const { channel: { buffer }, control } = cell.sync; + let expected = syncIdle; + for (;;) { + const waiting = Atomics.waitAsync(control, 0, expected); + if (waiting.async) await waiting.value; + const state = Atomics.load(control, 0); + if (state === syncClosed) return; + if (state !== syncRequest) { expected = state; continue; } + const length = control[1]; + const body = length >= 0 && syncHeader + length <= buffer.byteLength ? new Uint8Array(buffer, syncHeader, length).slice() : null; + const reply = await this.#serveSync(cell, body); + if (Atomics.load(control, 0) === syncClosed) return; + if (buffer.byteLength < syncHeader + reply.length) buffer.grow(syncHeader + reply.length); + new Uint8Array(buffer, syncHeader, reply.length).set(reply); + control[1] = reply.length; + Atomics.store(control, 0, syncReply); + Atomics.notify(control, 0); + expected = syncReply; + } + } + + #closeSync(cell) { + if (!cell.sync?.control) return; + Atomics.store(cell.sync.control, 0, syncClosed); + Atomics.notify(cell.sync.control, 0); + } + + async #serveSync(cell, body) { + const job = cell.job; + let reply; + try { + if (!job || job.settled) throw new Error('no job is running in this workcell'); + if (++job.hostCalls > maxHostCalls) throw new Error('host-call-limit'); + if (!body || body.byteLength > maxHostCallBytes) throw new Error('host-call-size'); + const request = deserialize(body); + job.syncing = true; + if (this.#jobTimeoutMs && job.deadline && !job.calls) { + clearTimeout(job.deadline); + job.budget -= performance.now() - job.armed; + } + try { + reply = { result: await this.#syncHostCalls(request, { candidates: job.data.candidates, workcell: cell.id, data: job.data }) }; + } finally { + job.syncing = false; + if (this.#jobTimeoutMs && !job.calls && cell.job === job && !job.settled && !cell.stopping) this.#arm(cell, job); + } + } catch (error) { reply = { error: error?.message || String(error) }; } + try { + const encoded = serialize(reply); + return encoded.length > maxSyncReplyBytes ? serialize({ error: 'host-call-reply-size' }) : encoded; + } catch (error) { return serialize({ error: `host-call-reply: ${error.message}` }); } + } + #claim(job) { if (!job || job.settled) return false; job.settled = true; @@ -474,7 +579,7 @@ export class IsolatePool { } async #finish(job, result) { - result = { ...result, trustedWasmModules: this.#trustedWasmModules }; + result = { ...result, trustedWasmModules: this.#trustedWasmModules, ...(this.#toolingWasmModules.length ? { toolingWasmModules: this.#toolingWasmModules } : {}) }; try { const evaluated = performance.now(); const receipts = job.data.ledger === 'caller' ? [] : await this.#persist('append', job.data, result); @@ -505,3 +610,64 @@ function poolDumpOptions(options) { if (!Number.isSafeInteger(merged.floor) || merged.floor < 0 || ![merged.holdMs, merged.intervalMs, merged.settleMs].every(positive)) throw new TypeError('dump list floor must be a non-negative integer and holdMs, intervalMs and settleMs positive integers'); return merged; } + +const pause = new Int32Array(new SharedArrayBuffer(4)); +const retrying = (operation, fd, buffer, offset, length) => { + for (;;) { + try { return operation(fd, buffer, offset, length); } + catch (error) { + if (error.code !== 'EAGAIN' && error.code !== 'EINTR') throw error; + Atomics.wait(pause, 0, 0, 1); + } + } +}; +const readExact = (fd, length) => { + const buffer = Buffer.alloc(length); + for (let offset = 0; offset < length;) { + const read = retrying(readSync, fd, buffer, offset, length - offset); + if (read === 0) throw new Error('host call channel closed'); + offset += read; + } + return buffer; +}; +const unwrap = reply => { + if (reply === null || typeof reply !== 'object') throw new Error('host call reply malformed'); + if (Object.hasOwn(reply, 'error')) throw new Error(String(reply.error)); + return reply.result; +}; + +export function connectSyncHostCall(channel) { + if (channel?.kind === 'shared' && channel.buffer instanceof SharedArrayBuffer) { + const { buffer } = channel; + const control = new Int32Array(buffer, 0, 2); + return request => { + const body = serialize(request); + if (body.length > maxHostCallBytes) throw new Error('host-call-size'); + if (Atomics.load(control, 0) !== syncIdle) throw new Error('host call channel closed'); + if (buffer.byteLength < syncHeader + body.length) buffer.grow(syncHeader + body.length); + new Uint8Array(buffer, syncHeader, body.length).set(body); + control[1] = body.length; + Atomics.store(control, 0, syncRequest); + Atomics.notify(control, 0); + Atomics.wait(control, 0, syncRequest); + if (Atomics.load(control, 0) !== syncReply) throw new Error('host call channel closed'); + const encoded = new Uint8Array(buffer, syncHeader, control[1]).slice(); + Atomics.store(control, 0, syncIdle); + return unwrap(deserialize(encoded)); + }; + } + if (channel?.kind === 'pipe' && channel.request === syncRequestFd && channel.reply === syncReplyFd) { + return request => { + const body = serialize(request); + if (body.length > maxHostCallBytes) throw new Error('host-call-size'); + const frame = Buffer.alloc(4 + body.length); + frame.writeUInt32LE(body.length); + body.copy(frame, 4); + for (let offset = 0; offset < frame.length;) offset += retrying(writeSync, channel.request, frame, offset, frame.length - offset); + const length = readExact(channel.reply, 4).readUInt32LE(0); + if (length > maxSyncReplyBytes) throw new Error('host-call-reply-size'); + return unwrap(deserialize(readExact(channel.reply, length))); + }; + } + throw new TypeError('a synchronous host call channel from IsolatePool syncHostCalls is required'); +} diff --git a/vendor/endoforge/core/runtime/isolate-wasm-tooling.mjs b/vendor/endoforge/core/runtime/isolate-wasm-tooling.mjs new file mode 100644 index 0000000..b6194c6 --- /dev/null +++ b/vendor/endoforge/core/runtime/isolate-wasm-tooling.mjs @@ -0,0 +1,198 @@ +const { validate, CompileError, RuntimeError } = WebAssembly; +const refuse = message => { throw new CompileError(message); }; +const leb = value => { + const bytes = []; + do { const part = value % 128; value = Math.floor(value / 128); bytes.push(part | (value ? 128 : 0)); } while (value); + return bytes; +}; +const order = [1, 2, 3, 4, 5, 13, 6, 7, 8, 9, 12, 10, 11]; +const valueTypes = [0x7f, 0x7e, 0x7d, 0x7c, 0x7b, 0x70, 0x6f, 0x69]; +const indexed = new Set([0x07, 0x08, 0x09, 0x0c, 0x0d, 0x10, 0x12, 0x14, 0x15, 0x18, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x3f, 0xd2, 0xd4, 0xd6]); +const plain = new Set([0x00, 0x01, 0x05, 0x0a, 0x0b, 0x0f, 0x19, 0x1a, 0x1b, 0xd1, 0xd3, 0xd5]); + +export function toolingWasmPolicy(entries, maxMb) { + if (!Array.isArray(entries)) throw new TypeError('toolingWasmModules must be an array'); + const names = new Set(), hashes = new Set(); + return Object.freeze(entries.map(({ name, sha256, maximumPages } = {}) => { + if (typeof name !== 'string' || !/^[a-zA-Z0-9._-]{1,100}$/.test(name) || + typeof sha256 !== 'string' || !/^[a-f0-9]{64}$/.test(sha256) || + !Number.isSafeInteger(maximumPages) || maximumPages < 1 || maximumPages > maxMb * 16 || + names.has(name) || hashes.has(sha256)) throw new TypeError('invalid toolingWasmModules entry'); + names.add(name); hashes.add(sha256); + return Object.freeze({ name, sha256, maximumPages }); + })); +} + +export function admitToolingWasm(bytes, entry) { + if (!validate(bytes)) refuse('invalid wasm module'); + let offset = 8, memories = 0, types = 0, functions = 0, globals = 0; + const limits = [], exportedMemories = [], names = new Set(), sections = []; + const byte = () => offset < bytes.length ? bytes[offset++] : refuse('truncated wasm'); + const uint = () => { + let value = 0; + for (let i = 0; i < 5; i++) { + const next = byte(); + value += (next & 127) * 2 ** (7 * i); + if (!(next & 128)) return value; + } + return refuse('invalid wasm integer'); + }; + const skipLeb = (max = 5) => { for (let i = 0; i < max; i++) if (!(byte() & 128)) return; refuse('invalid wasm integer'); }; + const skip = () => { const length = uint(); offset += length; }; + const unsupported = () => refuse('unsupported wasm feature in tooling module'); + const valueType = () => { if (!valueTypes.includes(byte())) unsupported(); }; + const blockType = () => { if ([0x63, 0x64].includes(bytes[offset])) unsupported(); skipLeb(); }; + const memarg = () => { if (uint() & 0x40) uint(); skipLeb(10); }; + const ended = (end, name) => { if (offset !== end) refuse(`malformed ${name} section`); }; + while (offset < bytes.length) { + const start = offset, id = byte(), size = uint(), end = offset + size; + const part = { id, start, end, content: offset }; + sections.push(part); + if (id === 1) { + for (let count = uint(); count; count--, types++) { + if (byte() !== 0x60) unsupported(); + for (let j = uint(); j; j--) valueType(); + for (let j = uint(); j; j--) valueType(); + } + ended(end, 'type'); + } else if (id === 2) { + for (let count = uint(); count; count--) { + skip(); skip(); + const kind = byte(); + if (kind === 0) { uint(); functions++; } + else if (kind === 1) { if (![0x70, 0x6f].includes(byte())) unsupported(); const flag = uint(); if (flag > 1) unsupported(); uint(); if (flag) uint(); } + else if (kind === 3) { valueType(); byte(); globals++; } + else if (kind === 4) { byte(); uint(); } + else unsupported(); + } + ended(end, 'import'); + } else if (id === 3) functions += uint(); + else if (id === 6) globals += uint(); + else if (id === 7) { + for (let count = uint(); count; count--) { + const length = uint(), name = new TextDecoder().decode(bytes.subarray(offset, offset + length)); + offset += length; + names.add(name); + const kind = byte(), index = uint(); + if (kind === 2) exportedMemories.push({ name, memory: index }); + } + ended(end, 'export'); + } else if (id === 5) { + const entries = []; + for (let count = uint(); count; count--) { + if (++memories > 1) unsupported(); + const flag = uint(); + if (flag > 1) unsupported(); + const initial = uint(), maximum = Math.min(flag ? uint() : Infinity, entry.maximumPages); + if (initial > maximum) refuse('tooling module memory exceeds its pinned maximum'); + limits.push(maximum); + entries.push(1, ...leb(initial), ...leb(maximum)); + } + ended(end, 'memory'); + part.replace = [...leb(memories), ...entries]; + } + offset = end; + } + const admitted = { flag: null, start: null, tooling: entry.name, limits, exportedMemories }; + const code = sections.find(part => part.id === 10); + if (memories && code) { + let flag = '__ef_grow_failed'; + while (names.has(flag)) flag += '_'; + const helper = functions, flagIndex = globals; + const call = Uint8Array.from([0x10, ...leb(helper)]); + offset = code.content; + const count = uint(), bodies = []; + for (let i = 0; i < count; i++) { + const size = uint(), end = offset + size, parts = []; + let from = offset; + for (let j = uint(); j; j--) { uint(); valueType(); } + while (offset < end) { + const at = offset, op = byte(); + if (op === 0x40) { + if (uint() !== 0) unsupported(); + parts.push(bytes.subarray(from, at), call); + from = offset; + } else if (op >= 0x45 && op <= 0xc4 || plain.has(op)) continue; + else if (indexed.has(op)) uint(); + else if ([0x02, 0x03, 0x04, 0x06].includes(op)) blockType(); + else if (op === 0x0e) { for (let j = uint() + 1; j; j--) uint(); } + else if ([0x11, 0x13].includes(op)) { uint(); uint(); } + else if (op === 0x1c) { for (let j = uint(); j; j--) valueType(); } + else if (op === 0x1f) { + blockType(); + for (let j = uint(); j; j--) { const kind = byte(); if (kind > 3) unsupported(); if (kind < 2) uint(); uint(); } + } else if (op >= 0x28 && op <= 0x3e) memarg(); + else if (op === 0x41) skipLeb(); + else if (op === 0x42) skipLeb(10); + else if (op === 0x43) offset += 4; + else if (op === 0x44) offset += 8; + else if (op === 0xd0) blockType(); + else if (op === 0xfc) { + const sub = uint(); + if ([8, 10, 12, 14].includes(sub)) { uint(); uint(); } + else if ([9, 11, 13, 15, 16, 17].includes(sub)) uint(); + else if (sub > 7) unsupported(); + } else if (op === 0xfd) { + const sub = uint(); + if (sub <= 11 || sub === 92 || sub === 93) memarg(); + else if (sub === 12 || sub === 13) offset += 16; + else if (sub >= 21 && sub <= 34) offset += 1; + else if (sub >= 84 && sub <= 91) { memarg(); offset += 1; } + } else unsupported(); + } + if (offset !== end) refuse('malformed code section'); + parts.push(bytes.subarray(from, end)); + bodies.push(Uint8Array.from(leb(parts.reduce((total, piece) => total + piece.length, 0))), ...parts); + } + ended(code.end, 'code'); + const grow = [0, 1, 1, 0x7f, 0x20, 0, 0x40, 0, 0x22, 1, 0x41, 0x7f, 0x46, 0x04, 0x40, 0x41, 1, 0x24, ...leb(flagIndex), 0x0b, 0x20, 1, 0x0b]; + grow[0] = grow.length - 1; + const extend = (id, entries) => { + const part = sections.find(item => item.id === id); + if (!part) return sections.push({ id, replace: [...leb(1), ...entries] }); + offset = part.content; + const total = uint() + 1; + part.replace = [...leb(total), ...bytes.subarray(offset, part.end), ...entries]; + }; + extend(1, [0x60, 1, 0x7f, 1, 0x7f]); + extend(3, leb(types)); + extend(6, [0x7f, 1, 0x41, 0, 0x0b]); + extend(7, [...leb(flag.length), ...Buffer.from(flag), 3, ...leb(flagIndex)]); + code.pieces = [Uint8Array.from(leb(count + 1)), ...bodies, Uint8Array.from(grow)]; + admitted.flag = flag; + } + const rank = id => order.indexOf(id); + const placed = sections.filter(part => part.start !== undefined); + for (const part of sections.filter(item => item.start === undefined)) { + const at = placed.findIndex(item => item.id && rank(item.id) > rank(part.id)); + placed.splice(at < 0 ? placed.length : at, 0, part); + } + const output = [bytes.subarray(0, 8)]; + for (const part of placed) { + const pieces = part.pieces ?? (part.replace ? [Uint8Array.from(part.replace)] : null); + if (!pieces) { output.push(bytes.subarray(part.start, part.end)); continue; } + output.push(Uint8Array.from([part.id, ...leb(pieces.reduce((total, piece) => total + piece.length, 0))]), ...pieces); + } + admitted.bytes = new Uint8Array(output.reduce((total, piece) => total + piece.length, 0)); + output.reduce((at, piece) => { admitted.bytes.set(piece, at); return at + piece.length; }, 0); + return admitted; +} + +export function guardToolingExports(instance, flagName, fail) { + const flag = flagName ? instance.exports[flagName] : null; + let depth = 0; + const trapped = error => { + if (flag?.value && error instanceof RuntimeError && error.message === 'unreachable') fail(); + throw error; + }; + const wrap = target => function (...args) { + if (flag && !depth) flag.value = 0; + depth++; + try { return Reflect.apply(target, this, args); } catch (error) { return trapped(error); } finally { depth--; } + }; + const exports = Object.create(null); + for (const [name, value] of Object.entries(instance.exports)) { + if (name !== flagName) exports[name] = typeof value === 'function' ? wrap(value) : value; + } + Object.defineProperty(instance, 'exports', { value: Object.freeze(exports), enumerable: true }); +} diff --git a/vendor/endoforge/core/runtime/isolate-wasm.mjs b/vendor/endoforge/core/runtime/isolate-wasm.mjs index b1916e2..410534d 100644 --- a/vendor/endoforge/core/runtime/isolate-wasm.mjs +++ b/vendor/endoforge/core/runtime/isolate-wasm.mjs @@ -1,4 +1,5 @@ import { createHash } from 'node:crypto'; +import { admitToolingWasm, guardToolingExports, toolingWasmPolicy } from './isolate-wasm-tooling.mjs'; const pageBytes = 65536; const leb = value => { @@ -50,8 +51,10 @@ export function trustedWasmPolicy(entries, maxMb) { })); } -export function installWasmLimit(maxMb, breach, trustedWasmModules = [], sharedWasmModules = []) { +export function installWasmLimit(maxMb, breach, trustedWasmModules = [], sharedWasmModules = [], toolingWasmModules = []) { const trustedModules = new Map(trustedWasmPolicy(trustedWasmModules, maxMb).map(entry => [entry.sha256, entry])); + const toolingModules = new Map(toolingWasmPolicy(toolingWasmModules, maxMb).map(entry => [entry.sha256, entry])); + if ([...toolingModules.keys()].some(sha256 => trustedModules.has(sha256))) throw new TypeError('a digest cannot be both trusted and tooling'); const sharedModules = new Map(sharedWasmModules.map(entry => [entry.sha256, entry])); const native = Object.fromEntries(Object.getOwnPropertyNames(WebAssembly).map(key => [key, WebAssembly[key]])); const cap = maxMb * 1024 * 1024 / pageBytes; @@ -91,6 +94,8 @@ export function installWasmLimit(maxMb, breach, trustedWasmModules = [], sharedW const bytes = ArrayBuffer.isView(source) ? new Uint8Array(source.buffer, source.byteOffset, source.byteLength).slice() : new Uint8Array(source).slice(); + const tooling = toolingModules.size ? toolingModules.get(createHash('sha256').update(bytes).digest('hex')) : undefined; + if (tooling) return admitToolingWasm(bytes, tooling); if (!native.validate(bytes)) throw new native.CompileError('invalid wasm module'); const trusted = trustedModules.size ? trustedModules.get(createHash('sha256').update(bytes).digest('hex')) : undefined; const reader = new Reader(bytes); @@ -260,6 +265,12 @@ export function installWasmLimit(maxMb, breach, trustedWasmModules = [], sharedW const instance = (module, imports, derived = WebAssembly.Instance) => { const data = modules.get(module); if (!data) throw new TypeError('workcell requires a locally checked WebAssembly.Module'); + if (data.tooling) { + const result = Reflect.construct(native.Instance, [module, imports], derived); + for (const { name, memory } of data.exportedMemories) memoryLimits.set(result.exports[name], data.limits[memory]); + guardToolingExports(result, data.flag, fail); + return result; + } const result = Reflect.construct(native.Instance, [module, imports], derived); if (data.flag) { const limit = (object, memory) => { if (data.limits[memory] < cap) memoryLimits.set(object, data.limits[memory]); }; diff --git a/vendor/endoforge/core/runtime/isolate-workcell.mjs b/vendor/endoforge/core/runtime/isolate-workcell.mjs index 5163be3..213fdb7 100644 --- a/vendor/endoforge/core/runtime/isolate-workcell.mjs +++ b/vendor/endoforge/core/runtime/isolate-workcell.mjs @@ -26,7 +26,7 @@ WebAssembly.instantiate = nativeInstantiate; const checkWasm = installWasmLimit(wasmMemoryMaxMb, error => { send({ type: 'limit', error }); process.exit(18); -}, options.trustedWasmModules, options.sharedWasmModules); +}, options.trustedWasmModules, options.sharedWasmModules, options.toolingWasmModules); const warmed = options.warm ? (async () => { await (await import(options.hostPort)).warm(options.warm); })().catch(error => error.message || String(error)) : null; diff --git a/vendor/endoforge/tools/durable.py b/vendor/endoforge/tools/durable.py new file mode 100644 index 0000000..3bdf2ec --- /dev/null +++ b/vendor/endoforge/tools/durable.py @@ -0,0 +1,49 @@ +import os +import sys + +try: + import fcntl +except ImportError: + fcntl = None + +FULL_FSYNC = getattr(fcntl, "F_FULLFSYNC", None) if fcntl else None +DIRECTORY_FLAG = getattr(os, "O_DIRECTORY", None) + + +def _full_sync(fd): + if FULL_FSYNC is not None: + try: + fcntl.fcntl(fd, FULL_FSYNC) + return "full_fsync" + except OSError: + pass + os.fsync(fd) + return "fsync" + + +def sync_file(fd): + if FULL_FSYNC is not None: + return _full_sync(fd) + os.fsync(fd) + return "fsync" + + +def sync_data(fd): + if FULL_FSYNC is not None: + return _full_sync(fd) + datasync = getattr(os, "fdatasync", None) + if datasync is not None: + datasync(fd) + return "fdatasync" + os.fsync(fd) + return "fsync" + + +def sync_dir(path, nofollow=False): + if DIRECTORY_FLAG is None or sys.platform == "win32": + return "skipped" + fd = os.open(path, os.O_RDONLY | DIRECTORY_FLAG | (os.O_NOFOLLOW if nofollow else 0)) + try: + return sync_file(fd) + finally: + os.close(fd) diff --git a/vendor/endoforge/tools/ledger_writer.py b/vendor/endoforge/tools/ledger_writer.py index 231b9dc..60f2d88 100644 --- a/vendor/endoforge/tools/ledger_writer.py +++ b/vendor/endoforge/tools/ledger_writer.py @@ -17,6 +17,7 @@ from core.ledger.ledger import TABLES, Ledger from tools import dump_list +from tools.durable import sync_data, sync_dir, sync_file MAGIC = b"EFJ1" HEADER = struct.Struct(">4sI32s") @@ -108,11 +109,13 @@ def trim_heap(): def fsync_path(path, directory=False): try: - fd = os.open(path, os.O_RDONLY | (os.O_DIRECTORY if directory else 0)) + if directory: + return 0 if sync_dir(path) == "skipped" else 1 + fd = os.open(path, os.O_RDONLY) except FileNotFoundError: return 0 try: - os.fsync(fd) + sync_file(fd) finally: os.close(fd) return 1 @@ -188,6 +191,7 @@ def __init__(self, directory, segment_bytes=SEGMENT_BYTES): journal_bytes=0, segments_recovered=0, frames_replayed=0, ledgers_replayed=0, torn_tails=0, conflicts=0, ledgers_missing=0) self.retiring = [] + self.retire_lock = threading.Lock() self.serial = 0 lock = os.open(self.directory / ".recover", os.O_RDWR | os.O_CREAT, 0o600) try: @@ -236,9 +240,9 @@ def recover(self, path, fd): with open(quarantine, "xb") as output: output.write(data[end:]) output.flush() - os.fsync(output.fileno()) + sync_file(output.fileno()) os.ftruncate(fd, end) - os.fsync(fd) + sync_file(fd) self.counts["recovery_syncs"] += 2 + fsync_path(self.directory, True) self.counts["torn_tails"] += 1 pending = {} @@ -286,7 +290,7 @@ def replay(self, path, entries): with open(conflict, "x") as output: json.dump(dict(writer=self.writer, error=str(error), versions=[v for v, _, _ in entries]), output) output.flush() - os.fsync(output.fileno()) + sync_file(output.fileno()) self.counts["recovery_syncs"] += 1 self.counts["conflicts"] += 1 finally: @@ -302,7 +306,7 @@ def append(self, data): view = view[os.write(self.fd, view):] def sync(self): - os.fdatasync(self.fd) + sync_data(self.fd) self.counts["journal_syncs"] += 1 def write(self, entries): @@ -320,7 +324,9 @@ def write(self, entries): self.retiring.append(thread) def retire(self, fd, path, touched): - self.counts["retire_syncs"] += make_durable(list(touched)) + syncs = make_durable(list(touched)) + with self.retire_lock: + self.counts["retire_syncs"] += syncs os.unlink(path) os.close(fd)