From 2f99a16e7752d2dbe31471781b31ceb5aa90c8a0 Mon Sep 17 00:00:00 2001 From: "marcin p. joachimiak" <4625870+realmarcin@users.noreply.github.com> Date: Tue, 17 Nov 2026 20:01:32 -0800 Subject: [PATCH 1/3] Bind future review prerequisites and preserve mixed source definitions --- NEXT_TASKS.md | 4 +- .../plans/m5-prerequisite-package-20261117.md | 77 +++++ ...scientific-invocation-contract-20261117.md | 118 +++++++ ...m5-source-fidelity-witness-map-20261117.md | 156 +++++++++ ...ce-fidelity-decision-procedure-20261117.md | 107 ++++++ ...rerequisite-adversarial-review-20261117.md | 30 ++ .../reviewer-clone-prerequisites-20261117.md | 93 ++++++ scripts/adhoc/calibration_round_20261116.py | 7 + .../inspect_fresh32_definition_20261117.py | 109 +++++++ ...y_m5_source_fidelity_witnesses_20261117.py | 97 ++++++ .../adhoc/prepare_m5_future_views_20261117.py | 151 +++++++++ ...repare_m5_prerequisite_package_20261117.py | 213 ++++++++++++ .../provision_reviewer_clone_20261117.py | 216 +++++++++++++ .../adhoc/run_m5_review_worker_20261116.py | 32 +- .../adhoc/scientific_invocation_20261117.py | 306 ++++++++++++++++++ tests/test_m5_future_views.py | 82 +++++ tests/test_m5_prerequisite_package.py | 159 +++++++++ tests/test_m5_review_worker.py | 31 ++ tests/test_m5_scientific_invocation.py | 201 ++++++++++++ tests/test_reviewer_clone_provisioning.py | 193 +++++++++++ 20 files changed, 2380 insertions(+), 2 deletions(-) create mode 100644 docs/plans/m5-prerequisite-package-20261117.md create mode 100644 docs/plans/m5-scientific-invocation-contract-20261117.md create mode 100644 docs/plans/m5-source-fidelity-witness-map-20261117.md create mode 100644 docs/plans/source-fidelity-decision-procedure-20261117.md create mode 100644 docs/validation/prerequisite-adversarial-review-20261117.md create mode 100644 docs/validation/reviewer-clone-prerequisites-20261117.md create mode 100644 scripts/adhoc/inspect_fresh32_definition_20261117.py create mode 100644 scripts/adhoc/inventory_m5_source_fidelity_witnesses_20261117.py create mode 100644 scripts/adhoc/prepare_m5_future_views_20261117.py create mode 100644 scripts/adhoc/prepare_m5_prerequisite_package_20261117.py create mode 100644 scripts/adhoc/provision_reviewer_clone_20261117.py create mode 100644 scripts/adhoc/scientific_invocation_20261117.py create mode 100644 tests/test_m5_future_views.py create mode 100644 tests/test_m5_prerequisite_package.py create mode 100644 tests/test_m5_scientific_invocation.py create mode 100644 tests/test_reviewer_clone_provisioning.py diff --git a/NEXT_TASKS.md b/NEXT_TASKS.md index 70db70a..cc72974 100644 --- a/NEXT_TASKS.md +++ b/NEXT_TASKS.md @@ -1,5 +1,7 @@ # Edge-review next tasks +**Prerequisite repair in progress, 2026-11-17:** #203 binds future scientific instructions, package purpose, navigation and fresh session roots; #205 clarifies direct semantic comparison versus trace-dependent source fidelity; #206 makes canonical clone/environment provisioning reproducible. Both retained round03 reviewer environments already pass actual production readback with their original receipts. Fresh environment and package checks are being prepared on `fix/calibration-prerequisites-20261117`; these are engineering checks and do not start another calibration. Missing original evidence remains a separate scientific blocker. Preserve all earlier packages, ratings, failed attempts and clones. + **Round03 finalized failed, 2026-11-16:** [Round03 results](docs/validation/m5-calibration-round03-results-20261116.md) preserve two fresh sealed matrices and separate adjudication. Initial agreement is 54/60, but source-fidelity agreement 7/10 and final resolution 3/10 fail their unchanged 8/10 floors. Six initial claim/model judgments and three supplemental source-fidelity judgments are unsupported; four disagreements remain unresolved, including one blocking model judgment. Mechanical finalization passes 20/20 canonical pairs, 153/153 selected initial proofs and 55/55 final citation rows, with 59 final local proofs separately validated. Eleven rejected authoring attempts remain preserved. A missed historical producer clause independently fails blinding (#200); the earlier blanket preparation audit is corrected. All scientific workers exited with ending bindings intact. Remaining90/9900 remain closed. The next scientific step requires missing original source/identity/definition witnesses and a separately identified round with unchanged thresholds. **Engineering and delivery, [PR #190](https://github.com/CultureBotAI/EdgeMech/pull/190):** publication #199, future producer views #200, preseal frozen kind/version #201, report delivery #202 and publication import setup #204 are repaired and independently reviewed. The first failed derivative canary remains preserved. New runtime `2e31b6f` passed 1,290 tests, 192 focused tests, 16 contracts, Ruff, builds, exact CI, a fresh same-clone production save/check, an inspected derivative canary and full twenty-review publication replay. The [bounded result bundle](artifacts/edge-calibration-round03-20261116/README.md) preserves the failed scientific result, all six confusion tables and original accounting. Future science remains blocked by missing original witnesses and deferred instruction/package coherence [#203](https://github.com/CultureBotAI/EdgeMech/issues/203). Shared CLAW `4fad8df` remains reviewed but unmerged. The directional exercise uses a primary abstract; full-paper inspection is not claimed. Old rounds, inputs/seals, failed attempts and owner candidates stay intact. No new run may reuse a receipt after its runtime bindings change. @@ -10,7 +12,7 @@ The earlier #152 operational save/check canary passed and remains excluded from **Completed round01, 2026-11-16, [PR #150](https://github.com/CultureBotAI/EdgeMech/pull/150):** [Round01 failed after execution and separate adjudication](docs/validation/m5-calibration-20261116.md). Two fresh same-model sessions sealed 10-by-6 matrices; initial agreement 56/60, but object-node agreement 7/10 fails the required 8. Independent audit found eight unsupported initial modeling labels, source-fidelity resolution 7/10 and two blocking disagreements. All 18 available canonical pairs replayed, but both fresh-05 saves failed; all saved reviews remain partial. Original matrices and failed saves remain unchanged. Issues #152–#157 track acceptance semantics, predicate reasoning, METPO hierarchy, local definitions, fidelity/exposure and aggregate quotation budgets; #145 tracks fresh-04 identity. Helper findings #144/#148/#149/#158/#159 are repaired. Final checks: 830 tests, full Ruff scope, contracts and package builds passed. [Round02 registration and revised rubric](docs/plans/m5-calibration-round02-20261116.md) preserve every original threshold. Remaining-90 and 9,900 gates stay closed. Both original M5 workers have exited; the release worker delivered the source-only candidate referenced above. Current follow-up execution is reported separately in the round02 entry. -Last reconciled: **2026-11-16** (America/Los_Angeles), against `main` at `f841b1dff874e78d1a14075413be6a92c90f1378`, merged PRs #135/#131/#128/#120 and open PRs #102/#37. PR #131 is merged and #127 is closed. #130's bounded source quarantine has been independently verified against regenerated producer bytes and merged in [KG-Microbe PR #1867](https://github.com/Knowledge-Graph-Hub/kg-microbe/pull/1867); graph-release verification remains pending. Independent scientific calibration has not passed. +Last reconciled: **2026-11-17** (America/Los_Angeles), against `main` at `f841b1dff874e78d1a14075413be6a92c90f1378`, merged PRs #135/#131/#128/#120 and open PRs #190/#167/#151/#150/#136/#102/#37. Shared CLAW PR #1289 remains open at `4fad8df`. PR #131 is merged and #127 is closed. #130's bounded source quarantine has been independently verified against regenerated producer bytes and merged in [KG-Microbe PR #1867](https://github.com/Knowledge-Graph-Hub/kg-microbe/pull/1867); graph-release verification remains pending. Independent scientific calibration has not passed. Scope: the stratified edge review and related edge-quality follow-ups. Update this file when work starts or ships, checking GitHub and current code before changing status. Record completion dates and PRs. Preserve historical manifests, packets, reports and scientific decisions; a merged engineering PR does not promote an edge's scientific status. Unrelated release/deployment work is outside this backlog. diff --git a/docs/plans/m5-prerequisite-package-20261117.md b/docs/plans/m5-prerequisite-package-20261117.md new file mode 100644 index 0000000..d735afb --- /dev/null +++ b/docs/plans/m5-prerequisite-package-20261117.md @@ -0,0 +1,77 @@ +# M5 prerequisite package and actual-environment checks + +This engineering procedure addresses #203, #205 and #206, with independent +review fixes #207 and #208. It does not start another calibration or replace +the failed round03 result. The scientific invocation contract additionally +rejects adjudication until its initial matrices, seals and comparison have a +reviewed typed binding (#209). + +## Inputs and boundaries + +Use `prepare_m5_prerequisite_package_20261117.py` in a freshly provisioned clone +at the exact committed candidate runtime. The retained source is M5's +`m5-calibration-round03-20261116` worktree. The repaired engineering manifest is +`.temp/m5-round03-worker-20261116/publication-runtime-02/manifest.json`, SHA256 +`1e0ad8f7dea88d5138d891341d46ac772f8a7896f0282ee11ddaf2b0686fd168`. +Its conservative operational specification is +`.temp/m5-round03-worker-20261116/engineering-operational-canary-spec-02.json`, +SHA256 `3321872d3bb7685836b46d0d799973ffb17335ea6b78a5783bf63c941a7c1e32`. + +The helper checks both exact input hashes before staging. Retained evidence, +source packets, original records and bounded-view receipts retain their exact +bytes and case/evidence identities. Current tracked runtime files receive new +pins, with old/new identities recorded in a transition ledger. Historical +scientific instructions are excluded from instruction roles. The only active +instruction is the operational replay canary. New v4 case views have distinct +paths; their inclusion does not itself establish blinding or scientific readiness. + +Every maintained execution input, including hidden/ignored executable helpers, +is pinned using the launcher's inventory. The original cohort, protocol, +thresholds, schema and shared contract remain bound. The new neutral procedure, +coordinator witness map and setup audit may be supplied with repeated +`--prerequisite-document`; they receive coordinator-only visibility here. + +All destinations must be new and private under Git-ignored `.temp`. Metadata, +documents, canonical review destination and source pins are checked before +copying. The helper replays planned evidence hashes, document pins, execution +inventory, HEAD and clean tracked state around freezing and authoring. It +preserves failed attempts rather than overwriting them or emitting success. + +## Execution sequence + +1. Provision exactly one fresh M5 reviewer clone with the maintained setup + helper. Inspect its on-disk receipt, origin, revision and isolated environment. +2. Run package preparation with `--plan`, then the identical arguments and + `--run`. Supply the source root/manifest/hash and operational spec/hash above; + a new `--output`, `--package-id`, UTC `--timestamp` and matching timestamped + `--review-id` are required. Inspect the persisted preparation receipt. +3. Use the maintained worker launcher with role `canary`, the new manifest, + `operational/review.json`, `operational/proofs.json`, the original fresh-47 + packet, and `scripts/adhoc/m5_review_20261116/replay-canary.md`. First plan, + then run through the actual native Codex launcher with a new output root. +4. Inspect the actual canonical YAML/Markdown pair, its exact hashes and the + parent production save/check validators. Confirm the receipt identifies this + clone, runtime and manifest. A child success message alone is insufficient. +5. Only after that whole unit passes, provision and check a second fresh clone + through the same path. A changed runtime or failed canary requires a new + verified canary before any further fanout. + +The operational fixture stays `scientific_review: false`, `not_assessed`, with +all six axes unresolved. It is outside scientific matrices, canonical scientific +pair denominators and graph admission. A new engineering manifest explicitly +uses `package_purpose: engineering_prerequisites`; the scientific invocation +contract rejects it even when all production checks pass. + +## What remains scientific work + +This freezes complete **available byte bindings**, not missing original +witnesses. The coordinator witness map names the unresolved source selection, +identity, field meaning, units, bin interpretation and version dependencies. +The bounded MetaTraits mapping/polarity replay is a concrete next recovery task. +No new literature service, primary full-paper inspection, scientific rating, +graph release or expansion is part of these operational checks. Retained-90 +and 9,900 remain gated on an independently evaluated successful calibration. + +Live results belong in a separate validation record naming the actual runtime +and receipts. A later documentation commit does not retroactively change a +frozen clone's runtime or make its receipt valid for another commit. diff --git a/docs/plans/m5-scientific-invocation-contract-20261117.md b/docs/plans/m5-scientific-invocation-contract-20261117.md new file mode 100644 index 0000000..f4f2bf8 --- /dev/null +++ b/docs/plans/m5-scientific-invocation-contract-20261117.md @@ -0,0 +1,118 @@ +# Future scientific invocation contract + +Issue #203 separates engineering readiness from the instructions for a future +scientific session. This contract adds coherence checks; it grants no scientific +approval, evidence-sufficiency finding, threshold change or authority to start a +replacement calibration. Completed rounds and their v3 projections remain intact. + +`calibration_round_20261116.py freeze` accepts an optional `package_purpose` in its +config. New engineering packages use `engineering_prerequisites`. A separately +reviewed future scientific package uses `scientific_calibration_candidate`. +Legacy packages remain replayable; neither a legacy purpose nor an engineering +purpose can prepare or launch a new scientific invocation. + +## Package-pinned instruction plan + +Add one JSON file with role `scientific_instructions` to the package. It contains +exactly these fields: + +```json +{ + "schema": "edgemech-scientific-instructions/v1", + "purpose": "scientific_calibration_candidate", + "round_id": "THE-NEW-PACKAGE-ID", + "manifest_path": ".temp/NEW-PACKAGE/manifest.json", + "phase": "blinded_initial_review", + "instruction_paths": [".temp/NEW-PACKAGE/instructions.json"], + "read_paths": ["artifacts/edge-calibration-20261115/protocol.json"], + "sessions": [{ + "reviewer_id": "reviewer-a", + "workdir": "/ABSOLUTE/NEW-CLONE-A", + "session_root": "/ABSOLUTE/NEW-CLONE-A/.temp/NEW-SESSION", + "output_root": "/ABSOLUTE/NEW-CLONE-A/.temp/NEW-SESSION/worker" + }] +} +``` + +This is a shape example, not a runnable package. Complete `read_paths` with every +reviewer-facing instruction, case view and evidence path. It must equal the set +of pins marked `visibility: reviewer`, plus the original protocol. Original +packets remain mechanical replay inputs. Each case's evidence IDs must resolve +uniquely to allowed evidence or its original packet. Every instruction path must +be an allowed pin of role `instructions`. Pin the invocation helper and the full +execution/runtime inventory. Existing package replay validates the original +occurrences, endpoint identities, packet inputs and pinned file bytes. + +Sessions have distinct clone roots and nonoverlapping, absent session roots. The +worker output is an immediate child of its session root. A fresh output directory +inside a completed session does not constitute a fresh session. The native worker +uses a new `codex exec`, never a resume. Only `blinded_initial_review` is supported. +Issue #209 records why `evidence_adjudication` is rejected: it needs a separately +reviewed typed binding for initial matrices, seals and comparison results before +any prompt can require those inputs. This helper does not establish readiness for +a complete scientific round. Historical adjudication tooling is unchanged, and +no default old scoring roots exist in this new contract. + +## Instruction templates + +Scientific instruction assets use this JSON format, not historical launch prose: + +```json +{ + "schema": "edgemech-scientific-instruction-template/v1", + "text": "Use package {{round_id}} at {{manifest_path}}. Work under {{output_root}}." +} +``` + +Supported placeholders are `manifest_path`, `round_id`, `workdir`, `session_root`, +`output_root`, and `reviewer_id`. The helper renders them from the verified plan +and current invocation. Templates cannot contain literal slash or backslash path +expressions or reserved invocation output filenames. Spell out ambiguous prose +such as “save and check”; use placeholders for paths. This conservative constraint +applies to executable instruction templates, not source evidence or quotations. +It rejects the real old round03 launch instructions even if their new file hashes +are correctly pinned. Shared semantic prose must be carried faithfully into a +reviewed template; this helper does not decide scientific semantics. + +## Per-clone preparation and launch + +After the future package and runtime are reviewed/frozen, run exactly one real +production save/readback canary in each actual new reviewer clone. Its receipt is +an operational prerequisite only. Preparing the invocation is read-only with +respect to package inputs and writes exclusive JSON/prompt artifacts outside the +fresh session root: + +```sh +python -B scripts/adhoc/scientific_invocation_20261117.py \ + --root /ABSOLUTE/NEW-CLONE-A \ + --manifest .temp/NEW-PACKAGE/manifest.json \ + --instruction-plan .temp/NEW-PACKAGE/scientific-plan.json \ + --reviewer-id reviewer-a \ + --production-receipt .temp/NEW-CANARY/canary-receipt.json \ + --output .temp/invocations/reviewer-a.json +``` + +The envelope binds manifest ID/path/hash, instruction-plan hash, actual runtime, +same-clone canary receipt, planned clone/session/output paths and generated prompt. +Use `--scientific-invocation .temp/invocations/reviewer-a.json` with launcher role +`reviewer`, the exact manifest, receipt and output root, and prompt +`.temp/invocations/reviewer-a.json.prompt.md`. First use the launcher's `--plan`. +It does not create a session or load credentials. Scientific execution still +requires the user's authorization for that new work. + +A real launch exclusively reserves the session before starting its child and +records the contract in worker metadata. Failure preserves the reservation. +Package, runtime, receipt, prompt and session marker are checked again at exit; +drift cannot produce completed status. Scientific invocations cannot add extra +writable directories. Frozen historical receipt verification stays unchanged. + +The v4 case-view helper is `prepare_m5_future_views_20261117.py`. Historical v3 +replay remains unchanged. For the exact inspected mixed process description, +v4 removes only three historical review-status tokens and retains the original +definition, scope limitations and version/provenance caveats. The complete source +field hash, omitted UTF-8 byte spans and retained-span hashes bind that change. +Changed source text requires new content inspection. Preserving the original +meaning is not independent confirmation of that meaning or of the generating +source version. Other source fields remain unchanged. External producer-text +omissions still require their separate content-reviewed bounded receipts; code +status alone does not justify retaining evaluation prose. diff --git a/docs/plans/m5-source-fidelity-witness-map-20261117.md b/docs/plans/m5-source-fidelity-witness-map-20261117.md new file mode 100644 index 0000000..463eb73 --- /dev/null +++ b/docs/plans/m5-source-fidelity-witness-map-20261117.md @@ -0,0 +1,156 @@ +# M5 source-fidelity prerequisites after round03 + +**Coordinator-only. Do not place this file, its historical inventory or any +linked outcome report in blinded reviewer navigation.** The separate +[case-neutral procedure](source-fidelity-decision-procedure-20261117.md) contains +no case results. This map addresses [#205](https://github.com/CultureBotAI/EdgeMech/issues/205) +and refines #156 without re-rating any occurrence. + +Round03 remains failed: source agreement was 7/10 and final resolution was 3/10, +both below the unchanged 8/10 floors. Engineering save/readback succeeded, but +missing semantic witnesses, unsupported initial judgments and blinding failure +remain scientific limitations. No new round or expansion is established by this +map. Original assertions, source rows, multiplicity and completed reviews stay +unchanged. + +## What the disagreement reveals + +The existing neutral rubric already distinguishes faithful preservation, +demonstrated semantic error and unknown derivation. The missing operational +detail is **when a producer trace is necessary**. The final audit accepts narrow +source-crosswalk preservation for first-32 from its explicit source coassignment, +but requires an original branch for first-43 and fresh-14. This may reflect +different dependencies, not incorrect historical labels. A future reviewer must +state the dependency that makes the branch necessary, or explain why directly +bound source and target meanings suffice. The new procedure makes both proof +routes explicit while retaining the original label definitions. + +There is also a distinct source-identity dependency in mixed BactoTraits rows: +replaying which identifier the producer selected does not establish which culture +supplied a phenotype cell. A primary organism paper can support biology but +cannot repair that missing data lineage. A successful selection replay and a +recovered source-cell provenance record would establish different facts. + +## Exact source → transformation → ontology witness map + +`P(case)` denotes the original `packet-` binding. `E(n)` denotes the +original `r03-evidence-` binding. These names refer to the immutable round03 +manifest, not to newly retrieved or silently substituted sources. The private +inventory described below carries every full occurrence ID, assertion and pin. +The table records dependencies and recovery candidates, not new verdicts. + +| Case and original assertion | Bound source and transformation context | Ontology/identity context | Necessary recovery or next check | +| --- | --- | --- | --- | +| first-01: BacDive171442 strain → METPO2000511 → API20E CIT procedure | P(first-01): original positive CIT observation ref117337, distinct derived record ref68368, transformed row3378887. E039 binds the assay builder. | E040 manufacturer procedure meaning; E045 original relation meaning; E046 material-entity definition; E024 strain identity. | Determine the original emitted relation's result/observation convention and the intended meaning of the generic assay description. A positive assay record is not itself a result-bearing procedure edge. Inspect the exact original builder and emission branch; do not infer assimilation or fermentation from the neighboring derived entry. | +| first-28: NCBI113559 → has_phenotype → METPO1000870 | P(first-28): summary1498, generic sporulation, three observations/two databases; transformed row96074. | E014 exact species authority; E047 original endpoint template. A related synonym is not the source-field definition or proof of execution. | Bind the original MetaTraits field definition and the lookup entry/branch actually selecting this target. Determine whether source generic wording and target specificity can be compared directly or whether field meaning remains unknown. Bounded owner-code recovery lead below. | +| first-30: GTDB SYIM01_sp009921765 → has_phenotype → METPO1000625 | P(first-30): source line54895 separately reports salinity minimum, growth and maximum; transformed row2984816 carries maximum1.8 percent w/v. Original owner-method result and owner003 bind selected-statistic replay. | E047 fixes original optimum-based target meaning. Independent original GTDB release identity remains unresolved. | Preserve the existing bounded maximum/optimum witness. Do not rerun it as a biological experiment. Recover the relevant GTDB release/taxonomy entry for the subject-node/claim dependency; it is separate from the already scoped transformation comparison. Unknown historical dirty state remains an execution limit. | +| first-32: LPSN46511 → close_match → NCBI1281099 | P(first-32): MicrobeDecoder row10743 explicitly coassigns the same IDs; transformed row85111. | E015 and E023 independently establish the different taxonomic concepts; E001 defines the original mapping relation. | Retain explicit source coassignment separately from independent mapping validity. State why the source-to-occurrence linkage permits direct comparison; do not turn source fidelity into approval of the crosswalk. No additional source-fidelity witness was identified as necessary in the completed audit. | +| first-43: NCBI1540872 → capable_of → METPO1005039 | P(first-43): summary10486 has negative aggregate polarity over ten observations/two databases; transformed row820840 is positive. | E047 binds the original process definition; E018 subject identity; E049 a different producer's participation convention, not this producer's polarity rule. | Bind exact MetaTraits lookup, original mapping inputs, polarity handling and emission convention. Determine whether qualifiers preserve the negative source meaning or whether an established branch loses it. Do not treat the negative aggregate as an independent biological refutation. Bounded owner-code recovery lead below. | +| fresh-04: NCBI1642702 → has_phenotype → METPO1000471 | P(fresh-04): BactoTraits row10677, transformed row85027; three salt-bin weights0.25/0.25/0.5 and separate optimum datum. Name/BacDive and culture-accession chains conflict. | E017 exact endpoint identity; E025 conflicting culture authority; E047 original range-class template. Numeric bounds alone do not define the source weights. | Recover the original bin/weight data dictionary, selected-cell lineage and culture-selection rule. Identify what0.25 measures and which culture supplied it. Original BactoTraits publication/supplement/versioned input are recovery candidates, not already-inspected proof. This also blocks the object-node disagreement. | +| fresh-05: NCBI1123071 → has_phenotype → METPO1000703 | P(fresh-05): BactoTraits row8521, transformed row78420; nonmotile indicator. Name/BacDive identity conflicts with DSM19353/JCM14586. | E020/E021 bind opposing culture identities; E016 original subject; E047 original trait meaning. E011 is a matching primary abstract, not cell-lineage evidence. | Recover original cell provenance and producer identity-selection rule. Later quarantine cannot assign the original cell to a culture. Independent published biology does not resolve the mixed-row association. The full primary paper remains a separate literature task; only its abstract was inspected in round03. | +| fresh-14: LPSN781160 → close_match → JCM14905 strain | P(fresh-14): LPSN row29573 nomenclatural-type field; transformed row116674. E007 can emit type-strain and close-match relations. | E005 type meaning, E006 exact species/type listing, E001 relation meaning. | Establish why this original occurrence is linked to the type field, then determine whether directly bound meanings suffice or the historical emitting branch/lookup must be recovered. A later producer capable of two paths does not identify the original path. Preserve species/strain scope independently of source fidelity. | +| fresh-32: LPSN775534 → capable_of → original hashed process | P(fresh-32): MicrobeDecoder row5072, transformed row153238. E032/E033/E041 preserve source token, process-generation context and FAPROTAX context. | E051 exact species identity. The sampled process description was unavailable to the blinded adjudicator; the process hash does not supply its meaning. | Recover the full original producer definition inputs and create a content-reviewed bounded authority view that preserves every substantive process definition/counterwitness while excluding historical verdicts. Verify the exact original process ID/version. Current FAPROTAX membership or a later label is insufficient. | +| fresh-47: LPSN783091 → has_attribute → original hashed source attribute | P(fresh-47): MicrobeDecoder row20904, transformed row241764, selected salt token and BacDive6845 observation ref119830; E028 source-field/literal minting. | E001 relation/Attribute context; original proposition is a source report. Independent subject authority remains missing in the final assessment. | Preserve the report-only scope and participating LPSN/BacDive chain. Independently recover original LPSN subject authority for the claim/node requirement. The unrelated NCBI crosswalk cannot automatically invalidate the selected literal report. The old E028 producer view had exposure; only a separately reviewed future view may repair that preparation defect. | + +## A concrete local recovery lead + +Read-only M5 inspection on 2026-11-17 located the actual owner file +`kg_microbe/transform_utils/metatraits/metatraits.py` in the canonical KG-Microbe +checkout. Comparing sampled clean base `bcfa6bf5bfaa5fca23063fd1483d9fcbcb58a977` +with `d6baf5b90003a2032747559d94c00f86a7a4c615` showed no diff for that file. +This does not recover the sampled build's unknown dirty state. + +The serial branch around lines2834–2854 and worker branch around3503–3520 read +the source majority and true-percentage fields, then select the Tier1 ontology +mapping's stored predicate. The later fallback branches invoke a separate +polarity routine. This identifies a concrete **candidate** first-28/first-43 +mapping witness. It has not yet established which exact lookup entry was loaded +for those occurrences, replayed their emitted output, or resolved the source +field's original meaning. + +The next bounded owner replay must bind the source row, ontology/mapping input, +loader and selected branch, preserve all output qualifiers, and compare against +the original occurrence. Start with exactly one occurrence through the intended +replay helper and inspect its persisted receipt before a second. Preserve input +hashes and failed attempts. Do not substitute a handwritten classification rule +or infer biological truth from the result. A full graph transform is unnecessary +for testing this bounded dependency and would not itself recover dirty history. + +## Bounded recovery of the mixed fresh-32 description + +Independent review found that the future v4 projection inherited v3's omission +of the entire mixed fresh-32 description while claiming substantive definitions +were preserved. [Issue #210](https://github.com/CultureBotAI/EdgeMech/issues/210) +records that finding. The original description contains both historical review +status and substantive process meaning, scope limits, FAPROTAX source/version +provenance and a warning that the vocabulary version does not establish the +generating CSV version. Those substantive spans can be retained independently +of the status tokens. + +The corrected future v4 projection requires the complete original description +SHA256 `5d1f1915951a1ebfed7d6cbe745bb5fa316f89054dea753b0c73871db2b3c5e8`. +It omits only three nine-byte status tokens at UTF-8 half-open offsets `[0,9)`, +`[310,319)` and `[709,718)`. Its retained spans preserve the other 778 of 805 bytes, +with per-span hashes, the full source-field hash and the unchanged original +endpoint record identity. Source rows, assertion, measurement context and other +endpoint fields are unchanged. The old v3 projection and old packet remain intact. + +The private actual-packet check is +`.temp/source-fidelity-prerequisites-20261117/fresh32-bounded-verification.json`, +SHA256 `7d3df1dfa8a26dca8c9785d0b49d5d9f60e9d378f3541bac7c634ef35f92122a`. +Its sibling `.view.json` has SHA256 +`e5b1cb5e4fc2e627875b976ca877349c97c15cf530579757270d42b31ab560f2`. +Both were persisted and read back. The maintained +[`inspect_fresh32_definition_20261117.py`](../../scripts/adhoc/inspect_fresh32_definition_20261117.py) +pins the exact original packet and verifies that the actual projection changes +no bytes beyond the independently enumerated status spans. The first projection +invocation used an interpreter without the project dependency; the next exposed +a tuple/set mismatch in the inspection helper. Both stopped before producing +projection artifacts. The corrected invocation under the project environment +passed, as did six focused v3/v4 tests and Ruff. + +The historical blinded adjudicator still lacked this description. Restoring it +in a separately identified future view does not repair that completed assessment +or promote the original producer description into independent authority. The +generating-version caveat and need for exact source-to-process evidence remain. + +## Search scope, services and verification + +The inspection used the retained round03 manifest, final audit and case fragments; +the retained preparation/rubric/results; selected original evidence views; and +the canonical M5 owner source. Ignored and hidden paths were included with +`rg --files -uu` over the old round03 `.temp` tree and the canonical KG-Microbe +`data` and `docs` trees, plus `rg -uu` over the actual MetaTraits producer. +The search identified retained replay files, raw BactoTraits/LPSN/MicrobeDecoder +inputs and transformation metadata. It was not a complete search of every M5 +checkout, compressed source body, remote archive or historical Git object. +“Missing” above means unresolved in the audited frozen evidence, not nonexistent +everywhere. No remote literature query was needed for this dependency inventory. + +No new LBNL/CBORG literature service, paid research or authenticated full-text +helper was used. The retained E040 manifest identifies an earlier Tavily capture +of the manufacturer manual; that is provenance of reused evidence, not a new +retrieval by this task. No new paper DOI, snippet or full-text inspection is +claimed. Private evidence stays private; this document quotes no source passages. + +The new helper +[`inventory_m5_source_fidelity_witnesses_20261117.py`](../../scripts/adhoc/inventory_m5_source_fidelity_witnesses_20261117.py) +checks the exact original manifest SHA256 +`3928396bf4c089620ec0209fdcb986c14f36969259ed01ab563c6807037ee298` +and audit SHA256 +`ff949f12e4e88c332736085798fa2b4454b107a5ed32203cc6ed4ecf7024cefe`. +It requires the same ten case and occurrence identities and every historical +source-fidelity evidence ID in the correct case and manifest. Its private output +is `.temp/source-fidelity-prerequisites-20261117/historical-witness-inventory.json`, +SHA256 `d0382822b3dbcef69085413920e30f74f76b0b1cf0142671019eefa6d04eacce`. +The output was read back after creation; it preserves all ten original +assertions and outcomes. The initial invocation failed before output on a +manifest key typo, corrected before the successful invocation. This inventory +does **not** replay the underlying source bytes or prove scientific sufficiency. + +Freeze a future package only after these distinctions and the invocation +contract receive independent review. Complete evidence bindings mean every +required file/role can be checked; complete semantic support means the necessary +dependencies actually resolve. Record unresolved dependencies explicitly even +when the engineering freeze succeeds. Neither state warrants inventing labels +to reach eight resolved source-fidelity cases. diff --git a/docs/plans/source-fidelity-decision-procedure-20261117.md b/docs/plans/source-fidelity-decision-procedure-20261117.md new file mode 100644 index 0000000..65dd8ce --- /dev/null +++ b/docs/plans/source-fidelity-decision-procedure-20261117.md @@ -0,0 +1,107 @@ +# Source-fidelity decision procedure + +This case-neutral clarification addresses [#205](https://github.com/CultureBotAI/EdgeMech/issues/205). +It supplements the common occurrence-review rubric; it does not change the +categories, original propositions, calibration thresholds or completed results. +It must be reviewed and separately pinned before use in a future scientific +package. It is not a launch authorization. + +## Establish the comparison before choosing a category + +Write down the exact original assertion: subject, predicate, object, original +definitions, qualifiers, aggregation level and assertion basis. Separately write +what the identified source instance asserts. Source fidelity compares those two +meanings at the **same stated scope**. It does not test the independent truth of +the source, or merely whether the identifiers and text survived copying. + +List the dependencies needed to interpret that comparison: + +1. The exact source version, record, selected field and its occurrence linkage. +2. The source field's meaning, polarity, units, statistics and relevant conditions. +3. The participating identity chain, including the entity to which the source + assigns the datum. A code-selected identifier and the actual datum's referent + are separate dependencies when the source mixes identities. +4. The original endpoint and predicate meanings, with independent version-bound + authorities where those meanings are necessary to the comparison. +5. Any selection, normalization, aggregation or mapping rule necessary to + establish what was transferred or how its meaning changed. + +For each dependency, record its evidence IDs, whether it is established, +conflicting or missing, and why it is necessary. Do not require an unrelated +identity, biological experiment or reconstruction of the entire build merely +because it exists elsewhere in the source record. Conversely, an exact row +hash cannot establish an ambiguous field meaning or identity association. + +## Use the proof route that answers the dependency + +**Direct semantic comparison** is possible when the source assertion, its +linkage to this occurrence, participating identities and original target +meaning are independently established. Compare them directly. A complete +historical execution trace is not an additional requirement when it would add +nothing to those established dependencies. This route can establish faithful +preservation of an erroneous source assertion: its independent correctness +remains a separate judgment. A coincidental matching row or a plausible source +candidate is insufficient to establish the linkage. + +**Transformation-dependent comparison** is needed when the selected field, +identity, polarity handling, statistic or mapping is uncertain. Bind the +relevant rule and inputs. Inspect or replay the actual owner implementation at +a stated version, with the original source and mapping/ontology inputs needed +by that path. A later implementation, related synonym, successful ID hash or +handwritten simulation cannot alone prove the historical rule. State precisely +what a bounded replay establishes and what it omits. An unrecovered dirty build +limits a historical execution claim; it does not erase a separately established +bounded source-to-target comparison. + +Both routes require a semantic comparison. Neither a successful replay nor +copied bytes establish that the translation preserves meaning. A producer rule +can itself introduce a semantic error. Do not impose a trace requirement on one +case while dispensing with the same necessary dependency in another. + +## Apply the existing categories + +| Category | Decision at the declared source-fidelity scope | +| --- | --- | +| `SUPPORTED` | The necessary dependencies are established, and the original assertion preserves the source's meaning, identity association, polarity, specificity and qualifiers. | +| `CONTRADICTED` | Established witnesses demonstrate a change or loss of represented meaning. Name that change and the evidence establishing the source-to-occurrence linkage. This category can describe a proven unjustified narrowing; it does not assert the narrower biological proposition is false. | +| `NOT_ASSESSABLE` | At least one necessary dependency is missing or conflicting, so the semantic comparison cannot be completed. Name the dependency and the smallest witness that could resolve it. An unproved transformation story is not a demonstrated defect. | +| `UNASSESSED` | The assessment was not performed; this cannot remain in a completed initial matrix. | + +Missing support for a narrower biological claim is not evidence of its opposite. +Likewise, a generic label in a partial source view does not establish the full +meaning of the source field. Distinguish an established source meaning that an +established mapping exceeds from a source meaning or selection that remains +unknown. If both preservation and mismatch remain plausible because a necessary +dependency is unknown, retain that uncertainty. + +An endpoint-category or predicate-domain defect affects source fidelity only +when it changes the represented source meaning. Explain that connection; +never copy a relation or node verdict into this axis automatically. A report-only +assertion stays report-only only when that is the original proposition. Do not +recast a biological assertion or narrow the assessed proposition to make a +resolved category save successfully. Evidence for literal transfer alone does +not establish an unqualified claim that the entire source assertion is faithful. + +## Bind evidence without confusing completeness and sufficiency + +Every witness used by a judgment must be explicitly bound to that axis in the +authored draft, canonical review, matrix and frozen evidence inventory. Record +the original input identity, source kind, version, case role, source locator and +inspected extent. Include relevant contrary witnesses. A rationale mentioning a +source does not bind it. Later additions belong to a separately identified stage. + +Record these outcomes separately: + +- **Binding completeness:** all cited witnesses and roles are present, pinned + and replayable. This is an engineering property of the package and authored + review, not a verdict about entailment. +- **Semantic sufficiency:** the necessary dependencies are established and the + stated comparison follows from the evidence. This requires scientific review. +- **Calibration readiness:** the protocol's original scientific, blinding and + operational prerequisites are met. Complete manifests or successful saves do + not establish readiness, and unresolved dependencies remain visible. + +Use missing evidence to guide recovery, not to optimize labels or replace +difficult occurrences. Do not change denominators, resolution floors or +historical ratings. A new package or replay never repairs a completed round's +exposure or outcome. diff --git a/docs/validation/prerequisite-adversarial-review-20261117.md b/docs/validation/prerequisite-adversarial-review-20261117.md new file mode 100644 index 0000000..14927cf --- /dev/null +++ b/docs/validation/prerequisite-adversarial-review-20261117.md @@ -0,0 +1,30 @@ +# Prerequisite adversarial review — 2026-11-17 + +The implementation was reviewed in separate read-only passes. Reviewers did not +edit files or overwrite outputs while reviewing. Each material finding was +filed before remediation. All old scientific artifacts and historical v3 +projections remain unchanged. + +| Finding | Resolution in this candidate | +| --- | --- | +| #203: a manifest/receipt can be valid while scientific instructions refer to a different package or completed session | Generate instructions from a package-pinned structured plan and constrained templates; bind the actual runtime, receipt, clone and fresh session; reject legacy/engineering packages, stale prompts and reused sessions. | +| #205: direct semantic comparison versus trace-dependent fidelity was underspecified | Add a neutral dependency-based decision procedure and a coordinator-only ten-case witness map. Preserve all historical ratings and distinguish missing evidence from contradiction. | +| #206: corrected clone setup was manual | Add canonical-origin, exact-commit, isolated-environment provisioning with persisted non-authorizing receipts and preserved failures. | +| #207: invalid output/metadata could fail after evidence copying | Require new private ignored output, valid metadata, prerequisite documents and unused canonical target before staging. Negative tests cover no-write rejection. | +| #208: planned tracked evidence/runtime could drift before freeze recomputed hashes | Replay planned input/document hashes, complete execution inventory, HEAD and clean tracked state before and after freeze and after authoring. Drift prevents a success receipt. | +| #209: adjudication accepted a plan without bound initial results | Reject that phase at validation and prompt generation. A typed initial-matrix/seal/comparison contract remains necessary before a complete future round. | +| #210: whole-field blinding omitted substantive process meaning while claiming definitions were retained | Restore the exact mixed definition except three separable review-status tokens; retain scope/version limitations and provenance with original hashes and bounded byte-span records. | + +Independent re-review found #207/#208 corrected and no additional material +defect in the provisioning path or #203/#209 invocation/launcher integration. +The #210 re-review directly compared the actual private original and persisted +view: all 778 substantive bytes remain, 27 review-status bytes are omitted, and +the original/view/helper hashes match the receipt. Final tests are recorded +separately with the actual runtime before live results are claimed. Focused tests +include actual production save/check, rejection of stale instruction assets, +fresh-session enforcement, drift, private output and mixed-field retention. + +These checks establish engineering behavior and honest limits. No reviewer +agreement, scientific resolution, independent full-paper inspection or graph +admission follows from them. Live setup and production canaries require actual +same-clone execution; test stubs and coordinator receipts are insufficient. diff --git a/docs/validation/reviewer-clone-prerequisites-20261117.md b/docs/validation/reviewer-clone-prerequisites-20261117.md new file mode 100644 index 0000000..c5f92d2 --- /dev/null +++ b/docs/validation/reviewer-clone-prerequisites-20261117.md @@ -0,0 +1,93 @@ +# Reviewer clone setup and retained save/readback audit — 2026-11-17 + +Issue [#206](https://github.com/CultureBotAI/EdgeMech/issues/206) makes the +documented fresh-clone setup reproducible. The retained round03 environments +already corrected round02's local-origin defect. This change supplies a maintained +setup path for future reviewers; it does not change old clones or authorize a new +scientific round. + +## Read-only audit of retained round03 + +Both actual reviewer clones beneath +`/Users/marcin/agent-work/EdgeMech/m5-round03-reviewers-20261116` were inspected on M5: + +| Binding | reviewer-a | reviewer-b | +| --- | --- | --- | +| Exact HEAD | `fa67837be82cf0244678e564071beb9a2e2203b3` | Same | +| Origin | `https://github.com/CultureBotAI/EdgeMech.git` | Same | +| Python prefix | `reviewer-a/.venv` | `reviewer-b/.venv` | +| Venv base | M5 Miniforge Python 3.14.7, system packages excluded | Same | +| Installed CLAW commit | `4fad8df5b2367da68faca6379ce32eb9b8f4ba9b` | Same | +| Recorded reviewer completion, UTC | `2026-11-17T03:45:51.949027` | `2026-11-17T03:47:14.400608` | + +The retained production receipt hashes match their recorded bindings: + +- A: `4d0be8fc15da46edbd8b6dc2443afc772e7b9fefcdff7593f0707c9b7639e80e`. +- B: `7b4ee1ac97b88f73769c04139c25bc5a700f46ea53c54ef2572102db3859d830`. + +Both canonical operational pairs at +`reviews/structured/20261117T030400Z-round03-operational-fresh47/` are nonempty +and match their receipt hashes: `review.yaml` is +`c099b3ec493ec5a2e912ec6363a4a0f19b89be2e6fb4266b5c257b1ed7b0f7a7`, and +`review.md` is `4c60af4b45be3da1b697ac28ce5931a58a2760fa09bda28132715191d7b7b195`. +Each clone's own `.venv/bin/python -B -m edgemech.occurrence_review check` was +replayed against that pair, its fresh47 packet, and the original operational +proofs; both passed. The conservative fixture still admits zero graph edges. +Both clones' tracked working files remained clean. The checks read retained +outputs and used `-B`; no old reviews or receipts were rewritten. + +An ignored-inclusive (`rg -uu`) filename and content search across `scripts/`, +`src/`, `tests/`, and `docs/` found the launcher identity/save guards and manual +setup instructions. The Python/shell implementation search in `scripts/` and +`src/` found no existing clone/venv provisioning helper. This bounded search +does not assert absence elsewhere on either machine. + +## Fresh clone provisioning + +Run one setup end to end and inspect its receipt before provisioning additional +clones. Use the exact reviewed commit containing this helper. The parent +directory must exist; the destination must not. The helper rejects local and +alternate origins by fixing the canonical HTTPS URL, checks out the full commit +detached, creates an isolated venv on the executing machine, installs with +`uv sync --locked --extra dev`, and runs dependency, import-location, exact CLAW +commit, and installed-contract checks inside that venv. The interpreter path is +explicit; it must exist locally. `uv` may be supplied explicitly as below. + +```bash +python3 scripts/adhoc/provision_reviewer_clone_20261117.py \ + --revision FULL_REVIEWED_40_CHARACTER_COMMIT \ + --destination /Users/marcin/agent-work/EdgeMech/NEW_REVIEWER_CLONE \ + --python /opt/homebrew/Caskroom/miniforge/base/bin/python3 \ + --uv /Users/marcin/.local/bin/uv \ + --plan +``` + +Inspect the read-only plan, then use the same arguments with `--run`. Inspect +`NEW_REVIEWER_CLONE/.temp/reviewer-provisioning/receipt.json` on disk. It records +the clone, exact revision, helper/tool hashes, host, Python/venv, lockfile and +installed distribution identities. Provisioning does not copy credentials; +dependency child processes receive no inherited CBORG key. Existing machine +credentials used later by the worker launcher remain a separate concern. + +A failure retains its partial clone and failure receipt when a clone directory +was reserved. Retry at a fresh destination; the helper neither cleans up nor +overwrites attempts. A successful receipt has capability +`clone-and-dependency-setup-only`, `authorizes_reviewer_launch: false`, and +`scientific_gate_passed: false`. + +Freeze and verify the complete new evidence package next. Then use the existing +durable launcher to run a real production save/readback canary in **each** actual +reviewer clone before its reviewer session. The provisioning receipt cannot +substitute for that launcher receipt. The reviewed invocation contract and +scientific calibration thresholds still apply. Retained round03 readiness does +not establish fresh readiness after a runtime or package change. + +## Verification boundary + +Focused tests exercise real Git checkout identity, exact revision rejection, +read-only planning, destination preservation, failed installs, credential and +environment isolation, venv boundaries, and non-authorizing receipt readback. +They stub dependency installation; root's real M5 one-clone provisioning and +production save/readback canary provide the network and actual runtime evidence. +This document records only the retained round03 readback until that new run is +separately recorded. diff --git a/scripts/adhoc/calibration_round_20261116.py b/scripts/adhoc/calibration_round_20261116.py index 6032116..1644e85 100644 --- a/scripts/adhoc/calibration_round_20261116.py +++ b/scripts/adhoc/calibration_round_20261116.py @@ -120,6 +120,9 @@ def reviewer_view(root, case, packet, paths): view = read(root, case["reviewer_view_path"]) if "blinding" in view: from prepare_m5_round02_views_20261116 import HELPER, VERSION, projection + if view["blinding"].get("version") == "edgemech-blinded-view/v4": + require(HELPER in paths, "Unpinned historical projection dependency") + from prepare_m5_future_views_20261117 import HELPER, VERSION, projection require(HELPER in paths and "scripts/adhoc/prepare_m5_reviewer_views_20261116.py" in paths, "Unpinned blinding adapters") @@ -191,6 +194,10 @@ def freeze(root, config_path, output): "cohort_id": protocol["cohort_id"], "files": files, "cases": cases, "scientific_status": "unassessed", "thresholds_changed": False, "scope": "input_freeze_not_evidence_entailment_or_calibration_pass"} + if "package_purpose" in config: + require(config["package_purpose"] in { + "engineering_prerequisites", "scientific_calibration_candidate"}, "Invalid package purpose") + manifest["package_purpose"] = config["package_purpose"] return {"manifest_sha256": write(root, output, manifest), "path": output} diff --git a/scripts/adhoc/inspect_fresh32_definition_20261117.py b/scripts/adhoc/inspect_fresh32_definition_20261117.py new file mode 100644 index 0000000..5b58d42 --- /dev/null +++ b/scripts/adhoc/inspect_fresh32_definition_20261117.py @@ -0,0 +1,109 @@ +#!/usr/bin/env python3 +"""Inspect exact fresh32 mixed-description spans for issue210, 2026-11-17. + +Input: immutable original packet. Output: exclusive private JSON span inventory; +no source quotations or scientific labels. This is not an omission authorization. +""" +from __future__ import annotations + +import argparse +import hashlib +import json +import os +from pathlib import Path + +PACKET_SHA256 = "14b21623a1726591121ea2882d9168e081f832e22143a58cad438163551326f7" + + +def inspect(packet_path: Path, output: Path, *, project: bool = False) -> dict: + if output.exists() or output.is_symlink(): + raise ValueError("Inspection output already exists") + raw = packet_path.read_bytes() + if hashlib.sha256(raw).hexdigest() != PACKET_SHA256: + raise ValueError("Original fresh32 packet changed") + packet = json.loads(raw) + description = packet["endpoints"]["object"]["record"]["description"].encode() + markers = [ + (b"Reviewed source-local process meaning for ", 0, len(b"Reviewed ")), + (b"Reviewed vocabulary: ", 0, len(b"Reviewed ")), + (b"The reviewed vocabulary version", len(b"The "), len(b"reviewed ")), + ] + spans = [] + for marker, prefix, length in markers: + if description.count(marker) != 1: + raise ValueError("Original review-status marker is missing or ambiguous") + start = description.index(marker) + prefix + spans.append({"source_byte_start": start, "source_byte_end": start + length, + "sha256": hashlib.sha256(description[start:start + length]).hexdigest()}) + result = {"schema": "edgemech-fresh32-description-inspection/v1", + "packet_sha256": PACKET_SHA256, + "source_pointer": "/endpoints/object/record/description", + "source_field_sha256": hashlib.sha256(description).hexdigest(), + "source_bytes": len(description), "candidate_omissions": spans, + "offset_encoding": "UTF-8 bytes; zero-based half-open", + "scope": "inspection_only_no_scientific_rating_or_omission_authorization"} + if project: + import prepare_m5_future_views_20261117 as future + + view = future.projection(packet) + actual = view["endpoints"]["object"]["record"]["description"].encode() + cursor = 0 + retained = [] + for span in spans: + retained.append(description[cursor:span["source_byte_start"]]) + cursor = span["source_byte_end"] + retained.append(description[cursor:]) + if actual != b"".join(retained): + raise ValueError("Projection changed bytes beyond independently inspected spans") + for key in set(future.original.FIELDS) - {"endpoints"}: + if view[key] != packet[key]: + raise ValueError(f"Projection changed retained field: {key}") + for side in packet["endpoints"]: + original_endpoint = dict(packet["endpoints"][side]) + expected_record = dict(original_endpoint["record"]) + if side == "object": + expected_record["description"] = actual.decode() + original_endpoint["record"] = expected_record + if original_endpoint != view["endpoints"][side]: + raise ValueError("Projection changed endpoint beyond inspected description spans") + projected_path = output.with_suffix(".view.json") + output.parent.mkdir(parents=True, exist_ok=True) + with projected_path.open("x") as stream: + os.fchmod(stream.fileno(), 0o600) + json.dump(view, stream, indent=2, sort_keys=True) + stream.write("\n") + if json.loads(projected_path.read_bytes()) != view: + raise ValueError("Projection failed persisted readback") + result["projection"] = { + "path": str(projected_path), + "sha256": hashlib.sha256(projected_path.read_bytes()).hexdigest(), + "helper_sha256": hashlib.sha256(Path(future.__file__).read_bytes()).hexdigest(), + "projected_description_sha256": hashlib.sha256(actual).hexdigest(), + "source_bytes": len(description), "retained_bytes": len(actual), + "omitted_bytes": len(description) - len(actual), + "blinding": view["blinding"], + "outside_span_changes": 0, + "scientific_ratings": 0, + } + output.parent.mkdir(parents=True, exist_ok=True) + with output.open("x") as stream: + os.fchmod(stream.fileno(), 0o600) + json.dump(result, stream, sort_keys=True, indent=2) + stream.write("\n") + if json.loads(output.read_bytes()) != result: + raise ValueError("Inspection report failed persisted readback") + return {"output": str(output), "sha256": hashlib.sha256(output.read_bytes()).hexdigest(), + "source_field_sha256": result["source_field_sha256"], "candidate_spans": spans} + + +def main() -> None: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--packet", type=Path, required=True) + parser.add_argument("--output", type=Path, required=True) + parser.add_argument("--project", action="store_true") + args = parser.parse_args() + print(json.dumps(inspect(args.packet, args.output, project=args.project), sort_keys=True)) + + +if __name__ == "__main__": + main() diff --git a/scripts/adhoc/inventory_m5_source_fidelity_witnesses_20261117.py b/scripts/adhoc/inventory_m5_source_fidelity_witnesses_20261117.py new file mode 100644 index 0000000..3175938 --- /dev/null +++ b/scripts/adhoc/inventory_m5_source_fidelity_witnesses_20261117.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python3 +"""Inventory immutable round03 source-fidelity bindings for issue205, 2026-11-17. + +Inputs: exact original manifest and completed adjudication audit. Output: a +coordinator-only JSON inventory; no evidence text, new categories or readiness +claim is generated. Historical categories remain historical. No network calls. +""" + +from __future__ import annotations + +import argparse +import hashlib +import json +from pathlib import Path + +MANIFEST_SHA256 = "3928396bf4c089620ec0209fdcb986c14f36969259ed01ab563c6807037ee298" +AUDIT_SHA256 = "ff949f12e4e88c332736085798fa2b4454b107a5ed32203cc6ed4ecf7024cefe" + + +def read_pinned(path: Path, expected: str) -> dict: + data = path.read_bytes() + actual = hashlib.sha256(data).hexdigest() + if actual != expected: + raise ValueError(f"Original input hash mismatch: {path}: {actual}") + return json.loads(data) + + +def inventory(manifest: dict, audit: dict) -> dict: + if audit["package_sha256"] != MANIFEST_SHA256: + raise ValueError("Audit references a different original package") + if manifest["round_id"] != audit["round_id"]: + raise ValueError("Audit and package round identities differ") + cases = {case["case_id"]: case for case in manifest["cases"]} + finals = {case["case_id"]: case for case in audit["final_cases"]} + if len(cases) != 10 or len(finals) != 10 or cases.keys() != finals.keys(): + raise ValueError("Expected the same ten original and adjudicated cases") + pins: dict[str, list[dict]] = {} + for pin in manifest["files"]: + for evidence_id in pin.get("evidence_ids", []): + pins.setdefault(evidence_id, []).append(pin) + records = [] + for case_id, case in cases.items(): + final = finals[case_id] + if final["occurrence_id"] != case["occurrence_id"]: + raise ValueError(f"Changed occurrence identity: {case_id}") + assessments = [a for a in final["assessments"] if a["axis"] == "source_fidelity"] + if len(assessments) != 1: + raise ValueError(f"Expected exactly one source-fidelity assessment: {case_id}") + assessment = assessments[0] + evidence = [] + for evidence_id in assessment["evidence_ids"]: + if evidence_id not in case["evidence_ids"] or evidence_id not in pins: + raise ValueError(f"Unbound historical evidence: {case_id}/{evidence_id}") + evidence.append({"evidence_id": evidence_id, "original_pins": pins[evidence_id]}) + records.append({ + "case_id": case_id, + "occurrence_id": case["occurrence_id"], + "original_assertion": case["original_assertion"], + "historical_final_source_fidelity": assessment["category"], + "historical_scope": assessment["scope"], + "historical_evidence_bindings": evidence, + }) + return { + "purpose": "coordinator_only_historical_binding_inventory", + "issue": "https://github.com/CultureBotAI/EdgeMech/issues/205", + "round_id": manifest["round_id"], + "manifest_sha256": MANIFEST_SHA256, + "audit_sha256": AUDIT_SHA256, + "limitations": [ + "No new scientific assessment or evidence sufficiency decision.", + "Original pin membership is checked; underlying source bytes are not replayed.", + "Contains historical outcomes: never include in blinded reviewer navigation.", + "A complete binding inventory does not authorize another round or expansion.", + ], + "cases": records, + } + + +def main() -> None: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--manifest", type=Path, required=True) + parser.add_argument("--audit", type=Path, required=True) + parser.add_argument("--output", type=Path, required=True) + args = parser.parse_args() + result = inventory(read_pinned(args.manifest, MANIFEST_SHA256), read_pinned(args.audit, AUDIT_SHA256)) + if args.output.exists(): + raise ValueError(f"Refusing to overwrite an existing inventory: {args.output}") + args.output.parent.mkdir(parents=True, exist_ok=True) + with args.output.open("x", encoding="utf-8") as stream: + stream.write(json.dumps(result, indent=2, sort_keys=True) + "\n") + args.output.chmod(0o600) + print(json.dumps({"output": str(args.output), "cases": len(result["cases"]), + "sha256": hashlib.sha256(args.output.read_bytes()).hexdigest()})) + + +if __name__ == "__main__": + main() diff --git a/scripts/adhoc/prepare_m5_future_views_20261117.py b/scripts/adhoc/prepare_m5_future_views_20261117.py new file mode 100644 index 0000000..7bda625 --- /dev/null +++ b/scripts/adhoc/prepare_m5_future_views_20261117.py @@ -0,0 +1,151 @@ +#!/usr/bin/env python3 +"""Prepare v4 future case views; inputs are original packets, outputs exclusive views. + +Issues #203/#210, 2026-11-17. Preserve historical v3 replay. The future view removes +only inspected review-status spans from the exact mixed description; definitions, +limitations and provenance remain. This is not a scientific assessment. +""" +from __future__ import annotations + +import argparse +import hashlib +import json + +import prepare_m5_reviewer_views_20261116 as original +import prepare_m5_round02_views_20261116 as prior + +ROOT = original.ROOT +VERSION = "edgemech-blinded-view/v4" +HELPER = "scripts/adhoc/prepare_m5_future_views_20261117.py" +MIXED_DESCRIPTION_SHA256 = "5d1f1915951a1ebfed7d6cbe745bb5fa316f89054dea753b0c73871db2b3c5e8" + + +def bounded_description(raw, pointer): + """Remove only three independently inspected status tokens from exact bytes.""" + source_hash = hashlib.sha256(raw).hexdigest() + if source_hash != MIXED_DESCRIPTION_SHA256: + raise ValueError("Mixed original description changed; inspect the semantic spans") + markers = ( + (b"Reviewed source-local process meaning for ", 0, len(b"Reviewed ")), + (b"Reviewed vocabulary: ", 0, len(b"Reviewed ")), + (b"The reviewed vocabulary version", len(b"The "), len(b"reviewed ")), + ) + omissions, retained, pieces = [], [], [] + cursor = 0 + for marker, prefix, length in markers: + if raw.count(marker) != 1: + raise ValueError("Review-status span missing or ambiguous") + start = raw.index(marker) + prefix + end = start + length + if start < cursor: + raise ValueError("Review-status spans are out of order") + if cursor < start: + retained.append({"pointer": pointer, "source_byte_start": cursor, + "source_byte_end": start, + "sha256": hashlib.sha256(raw[cursor:start]).hexdigest()}) + pieces.append(raw[cursor:start]) + omissions.append({"pointer": pointer, "source_field_sha256": source_hash, + "source_byte_start": start, "source_byte_end": end, + "sha256": hashlib.sha256(raw[start:end]).hexdigest(), + "offset_encoding": "UTF-8 bytes; zero-based half-open", + "scope": "review-status token only", + "reason": "Separable historical review status; semantic text retained"}) + cursor = end + if cursor < len(raw): + retained.append({"pointer": pointer, "source_byte_start": cursor, + "source_byte_end": len(raw), + "sha256": hashlib.sha256(raw[cursor:]).hexdigest()}) + pieces.append(raw[cursor:]) + return b"".join(pieces).decode(), omissions, retained + + +def projection(packet): + view = prior.projection(packet) + omissions, retained_semantics = [], [] + for item in view["blinding"]["redactions"]: + _, _, side, _, field = item["pointer"].split("/") + raw = packet["endpoints"][side]["record"][field].encode() + text, spans, retained = bounded_description(raw, item["pointer"]) + view["endpoints"][side]["record"][field] = text + omissions.extend(spans) + retained_semantics.extend(retained) + # Record the specific fields actually retained; no assertion that all producer + # wording is inseparable or that a code string is necessarily substantive. + exposed = [{"pointer": "/" + key, "sha256": hashlib.sha256( + json.dumps(view[key], sort_keys=True, ensure_ascii=False).encode()).hexdigest()} + for key in sorted(original.FIELDS)] + view["blinding"] = { + "version": VERSION, "bounded_omissions": omissions, + "retained_semantic_spans": retained_semantics, + "retained_field_bindings": exposed, + "binding_encoding": "JSON sorted keys, ensure_ascii=false, default separators; UTF-8", + "original_record_hashes": "Bind complete original endpoint records before omission", + "exposure": ( + "The bound occurrence identity, assertion, endpoint fields, measurement context and " + "source rows remain visible, including their original selection and any wording in " + "those retained fields. The listed omissions remove only inspected review-status " + "tokens from an exact mixed description. Its substantive definition, scope limits, " + "source/version provenance and warning about the unknown generating version remain " + "verbatim in the retained spans. Preserved wording is not independently validated " + "meaning or a scientific verdict. Other definitions and counterevidence remain. " + "This projection does not classify external producer prose or executable strings: " + "their content-reviewed omissions require separate package-pinned span receipts. " + "Code status alone does not make evaluation prose inseparable." + ), + } + return view + + +def configuration(): + return {**prior.configuration(), HELPER: original.sha(ROOT / HELPER)} + + +def check(case, base): + packet_path, packet, validation = original.load_case(case) + receipt = original.read(base / case / "receipt.json") + view_path = base / case / "view.json" + expected = {"case_id": case, "configuration": configuration(), + "packet_path": str(packet_path.relative_to(ROOT)), + "packet_sha256": original.sha(packet_path), + "view_sha256": original.sha(view_path), "validation": validation, + "scientific_ratings": 0, "blinding": projection(packet)["blinding"]} + if receipt != expected or original.read(view_path) != projection(packet): + raise ValueError("Future view or bound configuration changed") + return receipt + + +def prepare(case, base): + base = original.checked(base, exists=False) + if case != "fresh-47": + check("fresh-47", base) + packet_path, packet, validation = original.load_case(case) + view = projection(packet) + original.private_parents(base) + folder = base / case + folder.mkdir(mode=0o700) + original.write_new(folder / "view.json", view) + original.write_new(folder / "receipt.json", { + "case_id": case, "configuration": configuration(), + "packet_path": str(packet_path.relative_to(ROOT)), + "packet_sha256": original.sha(packet_path), + "view_sha256": original.sha(folder / "view.json"), + "validation": validation, "scientific_ratings": 0, "blinding": view["blinding"], + }) + return check(case, base) + + +def main(): + from pathlib import Path + + parser = argparse.ArgumentParser(description=__doc__) + mode = parser.add_mutually_exclusive_group(required=True) + mode.add_argument("--case") + mode.add_argument("--check") + parser.add_argument("--output-root", type=Path, required=True) + args = parser.parse_args() + result = prepare(args.case, args.output_root) if args.case else check(args.check, args.output_root) + print(json.dumps(result, sort_keys=True)) + + +if __name__ == "__main__": + main() diff --git a/scripts/adhoc/prepare_m5_prerequisite_package_20261117.py b/scripts/adhoc/prepare_m5_prerequisite_package_20261117.py new file mode 100644 index 0000000..83b4428 --- /dev/null +++ b/scripts/adhoc/prepare_m5_prerequisite_package_20261117.py @@ -0,0 +1,213 @@ +#!/usr/bin/env python3 +"""Freeze an engineering-only M5 prerequisite bundle (#203/#205/#206; 2026-11-17). + +Inputs: exact retained manifest and conservative operational fixture, plus this +committed clone's runtime. Outputs: private immutable copied evidence, v4 views, +runtime transition ledger, manifest and production authoring inputs. Never rates +science, changes an old package, retrieves papers or authorizes reviewer launch. +""" +from __future__ import annotations + +import argparse +import copy +import json +import re +import subprocess +from datetime import datetime +from pathlib import Path + +import author_m5_review_data_20261116 as author +import calibration_round_20261116 as rounds +import prepare_m5_future_views_20261117 as views +import run_m5_review_worker_20261116 as worker + +ROOT = Path(__file__).resolve().parents[2] +SCHEMA = "edgemech-prerequisite-package/v1" +FIXED = {rounds.PROTOCOL, rounds.COHORT, "docs/record-review-profile.md", + "scripts/adhoc/calibration_round_20261116.py"} +REFRESH_ROLES = {"proof_adapter", "profile", "round_helper", "instructions"} + + +def checked_document(root, path, expected): + raw = rounds.safe(root, path).read_bytes() + rounds.require(rounds.digest(raw) == expected, f"Source hash changed: {path}") + return json.loads(raw, object_pairs_hook=rounds.unique_object) + + +def plan(root, source_root, manifest_path, manifest_sha, spec_path, spec_sha, output): + rounds.require(root.resolve() != source_root.resolve(), "Use a fresh destination clone") + rounds.require(Path(output).parts and Path(output).parts[0] == ".temp" + and len(Path(output).parts) > 1, "Output must be a private .temp directory") + rounds.require(not rounds.safe(root, output, exists=False).exists(), "Output already exists") + ignored = subprocess.run(["git", "check-ignore", "--quiet", "--no-index", output], cwd=root) + rounds.require(ignored.returncode == 0, "Output must be gitignored") + rounds.require(not subprocess.check_output( + ["git", "-C", str(root), "status", "--porcelain", "--untracked-files=no"], + text=True).strip(), "Commit runtime before staging") + origin = subprocess.check_output( + ["git", "-C", str(root), "remote", "get-url", "origin"], text=True).strip() + rounds.require(origin == "https://github.com/CultureBotAI/EdgeMech.git", "Noncanonical origin") + manifest = checked_document(source_root, manifest_path, manifest_sha) + spec = checked_document(source_root, spec_path, spec_sha) + rounds.require(spec["review"].get("scientific_review") is False + and spec["review"]["verdict"] == "not_assessed", "Scientific fixture forbidden") + unknown = {"NOT_ASSESSABLE", "UNAVAILABLE", "UNRESOLVED"} + rounds.require(len(spec["assessments"]) == 6 + and all(a["category"] in unknown for a in spec["assessments"]), + "Operational fixture must remain unresolved on every axis") + tracked = set(subprocess.check_output( + ["git", "-C", str(root), "ls-files"], text=True).splitlines()) + actions = [] + for pin in manifest["files"]: + path = pin["path"] + if pin["role"] == "instructions": + actions.append({"path": path, "action": "omit_historical_instructions", + "previous_sha256": pin["sha256"]}) + continue + if path in tracked: + raw = rounds.safe(root, path).read_bytes() + current = rounds.digest(raw) + rounds.require(current == pin["sha256"] or pin["role"] in REFRESH_ROLES, + f"Non-runtime tracked evidence changed: {path}") + actions.append({"path": path, "action": "bind_current_runtime", + "previous_sha256": pin["sha256"], "sha256": current}) + else: + raw = rounds.safe(source_root, path).read_bytes() + rounds.require(rounds.digest(raw) == pin["sha256"], f"Retained evidence changed: {path}") + target = rounds.safe(root, path, exists=False) + rounds.require(not target.exists(), f"Evidence destination already exists: {path}") + actions.append({"path": path, "action": "copy_exact_retained_input", + "sha256": pin["sha256"]}) + return manifest, spec, tracked, actions + + +def metadata_preflight(root, args): + rounds.text(args.package_id, "package ID") + rounds.require(re.fullmatch(r"[0-9]{8}T[0-9]{6}Z-[a-z0-9][a-z0-9-]*", args.review_id), + "Review ID needs a UTC timestamp and safe suffix") + timestamp = datetime.strptime(args.timestamp, "%Y-%m-%dT%H:%M:%SZ") + rounds.require(timestamp.strftime("%Y%m%dT%H%M%SZ") == args.review_id.split("-", 1)[0], + "Review ID and timestamp differ") + target = rounds.safe(root, f"reviews/structured/{args.review_id}/review.yaml", exists=False) + rounds.require(not target.parent.exists(), "Canonical review destination already exists") + for path in args.prerequisite_document: + rounds.safe(root, path) + + +def verify_transition(root, ledger): + current_head = subprocess.check_output( + ["git", "-C", str(root), "rev-parse", "HEAD"], text=True).strip() + rounds.require(current_head == ledger["runtime_commit"], "Runtime commit changed during staging") + rounds.require(not subprocess.check_output( + ["git", "-C", str(root), "status", "--porcelain", "--untracked-files=no"], + text=True).strip(), "Tracked runtime changed during staging") + rounds.require(worker.execution_inventory(root) == ledger["execution_inventory"], + "Execution inventory changed during staging") + for item in [*ledger["actions"], *ledger["prerequisite_documents"]]: + if item.get("action") == "omit_historical_instructions": + continue + rounds.require(rounds.digest(rounds.safe(root, item["path"]).read_bytes()) == item["sha256"], + f"Planned input changed during staging: {item['path']}") + + +def prepare(args): + root, source = args.root.resolve(), args.source_root.resolve() + metadata_preflight(root, args) + manifest, spec, tracked, actions = plan(root, source, args.source_manifest, + args.source_sha256, args.operational_spec, args.spec_sha256, args.output) + ledger = {"schema": SCHEMA, "package_purpose": "engineering_prerequisites", + "scientific_authorization": False, "source_manifest": { + "path": args.source_manifest, "sha256": args.source_sha256}, + "source_fixture": {"path": args.operational_spec, "sha256": args.spec_sha256}, + "runtime_commit": subprocess.check_output( + ["git", "-C", str(root), "rev-parse", "HEAD"], text=True).strip(), + "execution_inventory": worker.execution_inventory(root), + "prerequisite_documents": [{"path": path, "sha256": rounds.digest( + rounds.safe(root, path).read_bytes())} for path in args.prerequisite_document], + "actions": actions, + "scope": "Complete retained byte bindings; unresolved scientific witnesses remain missing."} + if args.plan: + return {"status": "plan_only", "files": len(actions), "cases": len(manifest["cases"]), + "runtime_commit": ledger["runtime_commit"], "scientific_authorization": False} + prefix = Path(args.output) + files = {} + for pin, action in zip(manifest["files"], actions, strict=True): + if action["action"] == "omit_historical_instructions": + continue + if action["action"] == "copy_exact_retained_input": + # Check again immediately before persistence; never accept a changed source. + raw = rounds.safe(source, pin["path"]).read_bytes() + rounds.require(rounds.digest(raw) == pin["sha256"], "Source changed after plan") + rounds.write(root, pin["path"], raw=raw) + if pin["path"] not in FIXED: + files[pin["path"]] = {k: v for k, v in pin.items() if k != "sha256"} + # Freeze every maintained execution input, including newly added helpers. + for execution_pin in worker.execution_inventory(root): + path = execution_pin["path"] + if path not in FIXED: + files.setdefault(path, {"path": path, "role": "proof_adapter"}) + for path in ("uv.lock", "pyproject.toml"): + files.setdefault(path, {"path": path, "role": "proof_adapter"}) + instruction = "scripts/adhoc/m5_review_20261116/replay-canary.md" + files[instruction] = {"path": instruction, "role": "instructions"} + for path in args.prerequisite_document: + rounds.safe(root, path) + files[path] = {"path": path, "role": "coordinator_prerequisite_document", + "visibility": "coordinator_only"} + cases = copy.deepcopy(manifest["cases"]) + for case in cases: + path = str(prefix / "views" / case["case_id"] / "view.json") + rounds.write(root, path, views.projection(rounds.read(root, case["packet_path"]))) + case["reviewer_view_path"] = path + files[path] = {"path": path, "role": "reviewer_view"} + ledger_path = str(prefix / "binding-transition.json") + rounds.write(root, ledger_path, ledger) + files[ledger_path] = {"path": ledger_path, "role": "provenance_receipt"} + review = spec["review"] + review.update(review_id=args.review_id, title="Prerequisite canonical transport canary") + spec["reviewer_identity"].update(id="prerequisite-operational-fixture", model="configured_default", + session_id="operational-fixture-no-scientific-session") + review["reviewer"].update(identity="prerequisite-operational-fixture", model="configured_default") + spec["accessed_at"] = review["started_at"] = review["finished_at"] = args.timestamp + spec_path = str(prefix / "operational-spec.json") + rounds.write(root, spec_path, spec) + files[spec_path] = {"path": spec_path, "role": "operational_fixture", + "visibility": "coordinator_only"} + config_path, target_manifest = str(prefix / "freeze-config.json"), str(prefix / "manifest.json") + config = {"round_id": args.package_id, "package_purpose": "engineering_prerequisites", + "files": list(files.values()), "cases": cases} + rounds.write(root, config_path, config) + verify_transition(root, ledger) + frozen = rounds.freeze(root, config_path, target_manifest) + verified = rounds.verify(root, target_manifest) + verify_transition(root, ledger) + authored = author.assemble(root, target_manifest, spec_path, str(prefix / "operational")) + verify_transition(root, ledger) + result = {"schema": SCHEMA, "status": "prepared", "manifest": frozen, + "verification": verified, "operational": authored, + "scientific_authorization": False} + rounds.write(root, str(prefix / "preparation-receipt.json"), result) + return result + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--root", type=Path, default=ROOT) + parser.add_argument("--source-root", type=Path, required=True) + parser.add_argument("--source-manifest", required=True) + parser.add_argument("--source-sha256", required=True) + parser.add_argument("--operational-spec", required=True) + parser.add_argument("--spec-sha256", required=True) + parser.add_argument("--output", required=True) + parser.add_argument("--package-id", required=True) + parser.add_argument("--review-id", required=True) + parser.add_argument("--timestamp", required=True) + parser.add_argument("--prerequisite-document", action="append", default=[]) + mode = parser.add_mutually_exclusive_group(required=True) + mode.add_argument("--plan", action="store_true") + mode.add_argument("--run", action="store_true") + print(json.dumps(prepare(parser.parse_args()), indent=2)) + + +if __name__ == "__main__": + main() diff --git a/scripts/adhoc/provision_reviewer_clone_20261117.py b/scripts/adhoc/provision_reviewer_clone_20261117.py new file mode 100644 index 0000000..b655d2b --- /dev/null +++ b/scripts/adhoc/provision_reviewer_clone_20261117.py @@ -0,0 +1,216 @@ +#!/usr/bin/env python3 +"""Provision a fresh reviewer clone; inputs: exact revision/tool paths; output: receipt. + +Issue #206, 2026-11-17. This proves setup only, never canonical save or scientific readiness. +Failed destinations remain intact. No credentials, evidence, or old reviews are copied. +""" + +from __future__ import annotations + +import argparse +import hashlib +import importlib.metadata +import json +import os +import platform +import re +import subprocess +import sys +import tomllib +from datetime import datetime, timezone +from pathlib import Path + +ORIGIN = "https://github.com/CultureBotAI/EdgeMech.git" +CLAW_ORIGIN = "https://github.com/CultureBotAI/culturebotai-claw.git" +HELPER = Path(__file__).resolve() +RELATIVE_HELPER = Path("scripts/adhoc") / HELPER.name +RECEIPT = Path(".temp/reviewer-provisioning/receipt.json") +SCHEMA = "edgemech-reviewer-clone-provisioning/v1" + + +def require(condition, message): + if not condition: + raise ValueError(message) + + +def digest(path): + return hashlib.sha256(Path(path).read_bytes()).hexdigest() + + +def canonical_name(name): + return re.sub(r"[-_.]+", "-", name).lower() + + +def environment(root): + # Do not inherit credentials or environment redirects from the coordinator. + child = {key: value for key, value in os.environ.items() + if key in {"HOME", "PATH", "TMPDIR", "LANG", "LC_ALL", "SYSTEMROOT"}} + child.update(PYTHONDONTWRITEBYTECODE="1", PYTHONNOUSERSITE="1", + UV_PROJECT_ENVIRONMENT=str(root / ".venv"), UV_PYTHON_DOWNLOADS="never", + GIT_TERMINAL_PROMPT="0") + return child + + +def git(root, *arguments): + return subprocess.check_output(["git", "-C", str(root), *arguments], text=True, + env=environment(root)).strip() + + +def inspect_environment(root): + """Executed by the newly installed clone interpreter, not the coordinator.""" + root = root.resolve() + require(Path(sys.prefix).resolve() == root / ".venv", "Interpreter is outside clone venv") + require(sys.prefix != sys.base_prefix, "Interpreter is not a virtual environment") + config = (root / ".venv/pyvenv.cfg").read_text() + require(re.search(r"^include-system-site-packages\s*=\s*false\s*$", config, + re.MULTILINE | re.IGNORECASE), "Venv includes system packages") + import edgemech + from edgemech.pins import check_contracts + + require(Path(edgemech.__file__).resolve().parent == root / "src/edgemech", + "EdgeMech import does not come from this clone") + pins = json.loads((root / "src/edgemech/contract-pins.json").read_text()) + shared = importlib.metadata.distribution("kg-microbe-orchestration") + direct = json.loads(shared.read_text("direct_url.json") or "{}") + require(direct.get("url") == CLAW_ORIGIN + and direct.get("vcs_info", {}).get("vcs") == "git" + and direct.get("vcs_info", {}).get("commit_id") == pins["commit"], + "Installed CLAW source/commit differs from reviewed contract pin") + lock = tomllib.loads((root / "uv.lock").read_text()) + locked = {(canonical_name(item["name"]), item["version"]) for item in lock["package"]} + packages = sorted([{"name": canonical_name(item.metadata["Name"]), + "version": item.version, + "direct_url": json.loads(item.read_text("direct_url.json") or "null")} + for item in importlib.metadata.distributions()], key=lambda item: item["name"]) + require(all((item["name"], item["version"]) in locked for item in packages), + "Installed distribution version is outside uv.lock") + contracts = check_contracts() + require(contracts.get("verified") is True and contracts["claw_commit"] == pins["commit"], + "Installed contract verification failed") + return {"host": platform.node(), "platform": platform.platform(), + "python_executable": sys.executable, "python_prefix": sys.prefix, + "python_base_prefix": sys.base_prefix, "python_version": platform.python_version(), + "python_base_executable": sys._base_executable, + "venv_config_sha256": digest(root / ".venv/pyvenv.cfg"), + "pyproject_sha256": digest(root / "pyproject.toml"), + "lock_sha256": digest(root / "uv.lock"), "contracts": contracts, + "distributions": packages} + + +def plan(args): + require(re.fullmatch(r"[0-9a-f]{40}", args.revision) is not None, + "Revision must be an exact full lowercase 40-character commit") + root = args.destination.expanduser().absolute() + require(root.parent.is_dir(), "Destination parent must already exist") + require(root.parent.resolve() == root.parent, "Destination parent must not traverse symlinks") + require(not root.exists() and not root.is_symlink(), + "Destination already exists; preserve it and choose a fresh path") + for name, path in (("uv", args.uv), ("Python", args.python)): + require(path.is_absolute() and path.is_file() and os.access(path, os.X_OK), + f"{name} must name an absolute executable on this machine") + python = root / ".venv/bin/python" + return {"schema": SCHEMA, "mode": "plan", "destination": str(root), + "origin": ORIGIN, "revision": args.revision, "receipt": str(root / RECEIPT), + "authorizes_reviewer_launch": False, "scientific_gate_passed": False, + "commands": [ + ["git", "clone", "--no-checkout", "--no-hardlinks", "--origin", "origin", + ORIGIN, str(root)], + ["git", "-C", str(root), "fetch", "--no-tags", "origin", args.revision], + ["git", "-C", str(root), "checkout", "--detach", args.revision], + [str(args.uv), "sync", "--locked", "--extra", "dev", "--python", str(args.python), + "--no-config"], + [str(args.uv), "pip", "check", "--python", str(python), "--no-config"], + [str(python), "-B", str(root / RELATIVE_HELPER), "--inspect-root", str(root)], + ]} + + +def run_command(command, root): + completed = subprocess.run(command, cwd=root if root.exists() else root.parent, + env=environment(root), capture_output=True, text=True) + if completed.returncode: + raise RuntimeError(f"Command failed ({completed.returncode}): {command[0]} " + f"{command[1]}\n{completed.stderr[-4000:]}") + return completed.stdout + + +def verify_checkout(root, revision): + require(git(root, "remote", "get-url", "origin") == ORIGIN, "Clone origin is not canonical") + require(git(root, "rev-parse", "HEAD") == revision, "Clone HEAD differs from requested commit") + require(not git(root, "status", "--porcelain", "--untracked-files=no"), + "Clone has changed tracked files") + require(digest(root / RELATIVE_HELPER) == digest(HELPER), + "Requested commit contains a different provisioning helper") + + +def write_receipt(root, receipt): + path = root / RECEIPT + path.parent.mkdir(parents=True, exist_ok=True) + with path.open("x") as stream: + json.dump(receipt, stream, indent=2, sort_keys=True) + stream.write("\n") + + +def provision(args): + proposed = plan(args) + if args.plan: + return proposed + root = Path(proposed["destination"]) + # Reserve the fresh path atomically; a competing creator must not receive our receipt. + root.mkdir() + receipt = {**proposed, "mode": "run", "status": "failed", "steps_completed": 0, + "started_at": datetime.now(timezone.utc).isoformat(), + "coordinator_host": platform.node(), "helper_sha256": digest(HELPER), + "uv_sha256": digest(args.uv), "requested_python": str(args.python), + "capability": "clone-and-dependency-setup-only", + "requires": ["frozen evidence package", "same-clone production save/readback", + "passing scientific calibration"]} + try: + for index, command in enumerate(proposed["commands"]): + if index == 3: + verify_checkout(root, args.revision) + require(not (root / ".venv").exists() and not (root / ".venv").is_symlink(), + "Fresh checkout unexpectedly contains a venv") + output = run_command(command, root) + receipt["steps_completed"] = index + 1 + if index == len(proposed["commands"]) - 1: + receipt["environment"] = json.loads(output) + verify_checkout(root, args.revision) + require(receipt["environment"]["host"] == receipt["coordinator_host"], + "Environment probe returned a different host") + require(Path(receipt["environment"]["python_base_executable"]).resolve() + == args.python.resolve(), "Venv used a different base interpreter") + receipt["status"] = "passed" + except Exception as error: + receipt["error"] = str(error) + if root.is_dir() and not root.is_symlink(): + receipt["finished_at"] = datetime.now(timezone.utc).isoformat() + write_receipt(root, receipt) + raise + receipt["finished_at"] = datetime.now(timezone.utc).isoformat() + write_receipt(root, receipt) + require(json.loads((root / RECEIPT).read_text()) == receipt, "Receipt failed disk readback") + return receipt + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--inspect-root", type=Path, help=argparse.SUPPRESS) + parser.add_argument("--revision") + parser.add_argument("--destination", type=Path) + parser.add_argument("--python", type=Path) + parser.add_argument("--uv", type=Path, default=Path("/Users/marcin/.local/bin/uv")) + mode = parser.add_mutually_exclusive_group() + mode.add_argument("--plan", action="store_true") + mode.add_argument("--run", action="store_true") + args = parser.parse_args() + if args.inspect_root: + result = inspect_environment(args.inspect_root) + else: + require(args.revision and args.destination and args.python and (args.plan or args.run), + "Require --revision, --destination, --python and exactly one of --plan/--run") + result = provision(args) + print(json.dumps(result, indent=2, sort_keys=True)) + + +if __name__ == "__main__": + main() diff --git a/scripts/adhoc/run_m5_review_worker_20261116.py b/scripts/adhoc/run_m5_review_worker_20261116.py index 232c586..f5fad25 100644 --- a/scripts/adhoc/run_m5_review_worker_20261116.py +++ b/scripts/adhoc/run_m5_review_worker_20261116.py @@ -414,6 +414,24 @@ def verify_receipt(path, bindings, root, environment, *, reviewer_package=None): "production_replay": production} +def scientific_context(root, args, bindings, *, fresh=True): + import scientific_invocation_20261117 as invocation + + contract = getattr(args, "scientific_invocation", None) + require(contract, "Reviewer requires a structured scientific invocation") + require(not args.add_dir, "Scientific invocation cannot add undeclared writable directories") + return invocation.validate( + root, contract, manifest_path=args.package_manifest, runtime=bindings, + receipt_path=args.canary_receipt, output=Path(args.output_root).absolute(), + prompt=Path(args.prompt).resolve(), fresh=fresh) + + +def reserve_scientific(root, contract): + import scientific_invocation_20261117 as invocation + + invocation.reserve(root, contract) + + def launch(args): root = Path(args.workdir).resolve() environment = child_environment(root) @@ -457,6 +475,12 @@ def launch(args): require(args.canary_receipt, "A passing canary receipt is required") canary = verify_receipt(args.canary_receipt, bindings, root, environment, reviewer_package=package if args.role == "reviewer" else None) + scientific = None + if args.role == "reviewer": + scientific = scientific_context(root, args, bindings) + else: + require(getattr(args, "scientific_invocation", None) is None, + "Scientific invocation requires reviewer role") # Automatic approval review already selects workspace-write (CLI issue #142). command = [str(codex), "exec", "--approve-for-me", "--json", "--color", "never", "-C", str(root), "-o", str(output / "final.md")] @@ -481,13 +505,16 @@ def launch(args): "output_root": str(output), "prompt_path": str(prompt), "prompt_sha256": hashlib.sha256(prompt_bytes).hexdigest(), "executed_prompt_sha256": hashlib.sha256(execution_prompt).hexdigest(), - "canary": canary, "production_plan": production, "command": command, + "canary": canary, "production_plan": production, + "scientific_invocation": scientific, "command": command, "host": socket.gethostname(), "launcher_pid": os.getpid(), "model": "configured_default"} if args.plan: print(json.dumps({**state, "status": "plan_only"}, indent=2)) return 0 load_cborg(environment) require(bool(environment.get("CBORG_API_KEY")), "CBORG credential unavailable") + if scientific is not None: + reserve_scientific(root, args.scientific_invocation) output.mkdir(parents=True, mode=0o700, exist_ok=False) os.chmod(output, 0o700) environment["EDGEMECH_WORKER_OUTPUT_ROOT"] = str(output) @@ -515,6 +542,8 @@ def launch(args): if args.role == "reviewer": state["ending_replay"] = verify_receipt(args.canary_receipt, bindings, root, environment, reviewer_package=package) + require(scientific_context(root, args, bindings, fresh=False) == scientific, + "Scientific invocation changed during execution") # Validators are read-only. Recheck after running them before declaring completion. assert_immutable_execution(root, bindings, environment, "Reviewer") production_current(root, state["ending_replay"]["production_replay"]["spec"]) @@ -559,6 +588,7 @@ def main(): parser.add_argument("--role", choices=("canary", "calibration", "release", "reviewer"), required=True) parser.add_argument("--canary-receipt", "--production-receipt", dest="canary_receipt", type=Path) parser.add_argument("--package-manifest") + parser.add_argument("--scientific-invocation", help="Repository-relative generated invocation JSON") parser.add_argument("--production-review") parser.add_argument("--production-packet") parser.add_argument("--production-proofs") diff --git a/scripts/adhoc/scientific_invocation_20261117.py b/scripts/adhoc/scientific_invocation_20261117.py new file mode 100644 index 0000000..9ba79e8 --- /dev/null +++ b/scripts/adhoc/scientific_invocation_20261117.py @@ -0,0 +1,306 @@ +#!/usr/bin/env python3 +"""Bind future reviewer prompts to a verified package, clone and fresh session. + +Issue #203, 2026-11-17. Inputs: a package-pinned structured instruction plan and +same-clone production receipt. Outputs: exclusive invocation JSON and generated +prompt. Preparing or checking this contract does not authorize scientific work, +assign ratings, certify evidence sufficiency, or relax the unchanged thresholds. +""" +from __future__ import annotations + +import argparse +import json +import re +import subprocess +from pathlib import Path + +import calibration_round_20261116 as rounds + +PLAN_SCHEMA = "edgemech-scientific-instructions/v1" +TEMPLATE_SCHEMA = "edgemech-scientific-instruction-template/v1" +SCHEMA = "edgemech-scientific-invocation/v1" +PURPOSE = "scientific_calibration_candidate" +HELPER = "scripts/adhoc/scientific_invocation_20261117.py" +PHASES = {"blinded_initial_review"} +SESSION_KEYS = {"reviewer_id", "workdir", "session_root", "output_root"} +PLACEHOLDERS = {"manifest_path", "round_id", "workdir", "session_root", "output_root", "reviewer_id"} +# Invocation paths belong in typed placeholders, never in copied prose. Treat +# ambiguous slash expressions conservatively: templates can spell out “save and +# check” while source evidence retains its exact scientific text unchanged. +LITERAL_PATH = re.compile(r"[/\\]|\b(?:manifest|initial-seal|reviewer-result)\.json\b|" + r"\b(?:FINAL_REPORT|final)\.md\b") + + +def instruction_templates(root, plan): + templates = [] + for path in plan["instruction_paths"]: + try: + template = rounds.read(root, path) + except (ValueError, TypeError) as error: + raise ValueError("Scientific instructions require structured templates, not legacy prose") \ + from error + rounds.require(isinstance(template, dict) and set(template) == {"schema", "text"} + and template["schema"] == TEMPLATE_SCHEMA + and isinstance(template["text"], str) and template["text"].strip(), + "Scientific instructions require structured templates") + body = template["text"] + names = re.findall(r"\{\{([a-z_]+)\}\}", body) + rounds.require(set(names) <= PLACEHOLDERS, "Unknown instruction placeholder") + literal = re.sub(r"\{\{[a-z_]+\}\}", "", body) + rounds.require("{{" not in literal and "}}" not in literal + and not LITERAL_PATH.search(literal), + "Instruction templates must use bound placeholders for paths") + templates.append(template) + return templates + + +def absolute(path): + rounds.require(isinstance(path, str), "Missing absolute path") + value = Path(path) + rounds.require(value.is_absolute() and str(value) == str(value.resolve()), + "Path must be absolute, canonical and free of symlinks") + rounds.require(not any(part.is_symlink() for part in (value, *value.parents)), "Symlink path") + return value + + +def pin(root, path): + return {"path": path, "sha256": rounds.digest(rounds.safe(root, path).read_bytes())} + + +def checked_plan(root, manifest_path, plan_path): + """Replay originals with the existing verifier; add only invocation coherence.""" + replay = rounds.verify(root, manifest_path) + manifest = rounds.read(root, manifest_path) + rounds.require(manifest.get("package_purpose") == PURPOSE, + "Engineering-only or undeclared package cannot authorize scientific invocation") + files = {item["path"]: item for item in manifest["files"]} + rounds.require(plan_path in files and files[plan_path]["role"] == "scientific_instructions", + "Scientific instruction plan must be pinned with its explicit role") + rounds.require(HELPER in files, "Invocation helper must be pinned") + plan = rounds.read(root, plan_path) + rounds.require(set(plan) == {"schema", "purpose", "round_id", "manifest_path", "phase", + "instruction_paths", "read_paths", "sessions"}, + "Unexpected or missing scientific instruction fields") + rounds.require(plan["schema"] == PLAN_SCHEMA and plan["purpose"] == PURPOSE, + "Invalid scientific instruction purpose or schema") + rounds.require(plan["round_id"] == manifest["round_id"] + and plan["manifest_path"] == manifest_path, + "Instruction/package manifest ID or path mismatch") + rounds.require(plan["phase"] in PHASES, + "Unsupported scientific phase; only blinded initial review is implemented") + for name in ("read_paths", "instruction_paths"): + values = plan[name] + rounds.require(isinstance(values, list) and values + and all(isinstance(value, str) for value in values) + and len(values) == len(set(values)), "Invalid " + name) + allowed = set(plan["read_paths"]) + rounds.require(allowed == ({path for path, item in files.items() + if item.get("visibility") == "reviewer"} | {rounds.PROTOCOL}), + "Allowed navigation must exactly match package reviewer visibility") + rounds.require(set(plan["instruction_paths"]) == { + path for path in allowed if files[path]["role"] == "instructions"}, + "Instruction paths differ from reviewer-facing instruction pins") + instruction_templates(root, plan) + rounds.require(rounds.PROTOCOL in allowed, "Original protocol must remain reviewer-facing") + for case in manifest["cases"]: + rounds.require(case.get("reviewer_view_path") in allowed + and case["packet_path"] not in allowed, + "Case views must be visible; original packets are mechanical inputs") + for eid in case["evidence_ids"]: + matches = [item for item in files.values() if eid in item.get("evidence_ids", [])] + rounds.require(len(matches) == 1, "Evidence binding is missing or ambiguous") + item = matches[0] + rounds.require(item["path"] in allowed or item["path"] == case["packet_path"], + "Case evidence is outside declared navigation") + sessions = plan["sessions"] + rounds.require(isinstance(sessions, list) and sessions, "Missing planned sessions") + ids, roots, clones = set(), [], set() + for session in sessions: + rounds.require(isinstance(session, dict) and set(session) == SESSION_KEYS, + "Invalid planned session fields") + rid = session["reviewer_id"] + rounds.require(isinstance(rid, str) and re.fullmatch(r"[a-z0-9][a-z0-9-]{0,79}", rid) + and rid not in ids, "Invalid or repeated reviewer ID") + ids.add(rid) + clone = absolute(session["workdir"]) + fresh = absolute(session["session_root"]) + output = absolute(session["output_root"]) + rounds.require(fresh != clone and fresh.is_relative_to(clone) + and output.parent == fresh, "Session/output roots must be inside their clone") + rounds.require(clone not in clones, "Independent sessions require distinct reviewer clones") + rounds.require(all(not fresh.is_relative_to(other) and not other.is_relative_to(fresh) + for other in roots), "Session roots overlap") + clones.add(clone) + roots.append(fresh) + return plan, manifest, {"manifest": {"path": manifest_path, + "sha256": replay["manifest_sha256"]}, + "instructions": pin(root, plan_path)} + + +def generated_prompt(plan, manifest, session, bindings, templates): + """There is no user-supplied launch prose or hardcoded historical round path.""" + rounds.require(plan["phase"] in PHASES, "Unsupported scientific phase") + context = {"round_id": plan["round_id"], "phase": plan["phase"], **bindings, + "session": session, "allowed_read_paths": plan["read_paths"], + "instruction_paths": plan["instruction_paths"], + "cases": [{key: case[key] for key in + ("case_id", "occurrence_id", "reviewer_view_path", "evidence_ids")} + for case in manifest["cases"]]} + replacements = {"manifest_path": bindings["manifest"]["path"], + "round_id": plan["round_id"], **session} + rendered = [] + for template in templates: + body = template["text"] + for key, value in replacements.items(): + body = body.replace("{{" + key + "}}", value) + rendered.append(body) + phase = ( + "Independently assess all cases on all six axes under the original protocol. Do not " + "delegate ratings or read another session. Author complete canonical drafts and proof " + "sidecars before sealing. Validate exactly one fresh-47 draft and inspect persisted " + "artifacts before the remaining cases. Use seal_m5_round03_initial_20261116.py " + "validate/seal/check, with this bound manifest and this session's output root. Preserve " + "rejected attempts; never change scientific judgments to pass transport. After sealing, " + "save/check the canonical reviews with python -B -m edgemech.occurrence_review, first " + "fresh-47 and then the remaining cases only after inspecting actual YAML/Markdown. " + "All expected slots, failures and unattempted blockers remain in the denominator." + ) + text = ( + "You are a fresh scientific reviewer. This generated invocation binds the exact package " + "and session below; operational readiness is not scientific approval.\n\n" + + json.dumps(context, indent=2, sort_keys=True) + "\n\n" + "Run calibration_round_20261116.py verify --manifest using exactly the manifest.path " + "above. The package-pinned instruction templates are rendered below; use these bound " + "renderings rather than supplying your own substitutions. The allowed_read_paths list is the " + "complete scientific navigation boundary. Other package files are mechanical replay " + "inputs only: do not print their hidden contents. Do not follow source links, retrieve " + "new evidence, inspect Git history, issues, coordinator notes, operational judgments, " + "or unlisted directories. Record unavoidable exposure and deviations.\n\n" + + "\n\n".join(rendered) + "\n\n" + + phase + "\n\n" + "Keep claim, literature, source-fidelity, relation, subject-node and object-node " + "assessments distinct, using the pinned shared schemas and instruction assets. " + "Original occurrence, predicate, endpoints and source version stay fixed. Source-report " + "support does not establish biological truth or independent literature support. " + "Missing access is not refutation. Existing thresholds and scope remain unchanged.\n\n" + "Determine actual model/session from this output root's events.jsonl using " + "identify_m5_worker_20261116.py. Use the supplied reviewer_id consistently; " + "configured_default is not an actual model. Same-model agreement is operational only. " + "Use short literal quotations; the 25-word limit per source is shared across the whole " + "package's reviewers and cases. Do not omit counterevidence to meet that limit.\n\n" + "Use only frozen maintained execution helpers and production CLIs. Do not create new " + "execution code, edit inputs/runtime/environment, waive a gate or alter an initial seal. " + "Author JSON/Markdown data only under the supplied output root, apart from canonical " + "review saves inside this clone. Helper gaps go to the coordinator. Record commands, " + "exit statuses, exact paths/hashes, exposure, blockers and all expected slots in " + "reviewer-result.json. Save a complete durable FINAL_REPORT.md in the output root. " + "The launcher owns final.md; your final message must be self-contained. No commits, " + "issues, messages, merges, publication, graph admission or expansion.\n" + ) + return text.encode() + + +def session_marker(contract_path, value): + return {"schema": SCHEMA, "invocation": contract_path, + "invocation_sha256": rounds.digest(json.dumps(value, sort_keys=True).encode()), + "session": value["session"]} + + +def validate(root, contract_path, *, manifest_path, runtime, receipt_path, output, prompt, + fresh=True): + value = rounds.read(root, contract_path) + rounds.require(set(value) == {"schema", "purpose", "round_id", "manifest", "instructions", + "runtime", "production_receipt", "session", "prompt"} + and value["schema"] == SCHEMA and value["purpose"] == PURPOSE, + "Invalid scientific invocation contract") + rounds.require(value["manifest"]["path"] == manifest_path, + "Supplied package differs from scientific invocation") + plan, manifest, bindings = checked_plan(root, manifest_path, value["instructions"]["path"]) + rounds.require(value["round_id"] == manifest["round_id"] + and all(value[key] == binding for key, binding in bindings.items()), + "Invocation package/instruction hash or ID mismatch") + rounds.require(value["runtime"] == runtime, "Scientific invocation runtime changed") + receipt_path = Path(receipt_path).absolute() + rounds.require(receipt_path.is_relative_to(root), "Receipt belongs to another clone") + rounds.require(value["production_receipt"] == pin(root, str(receipt_path.relative_to(root))), + "Scientific invocation production receipt changed") + session = value["session"] + rounds.require(session in plan["sessions"] and session["workdir"] == str(root), + "Invocation session differs from package plan or clone") + session_root = absolute(session["session_root"]) + rounds.require(session["output_root"] == str(output), "Invocation output root differs") + if fresh: + rounds.require(not session_root.exists(), "Scientific session root already exists") + else: + marker = session_root / "invocation.json" + rounds.require(marker.is_file() and not marker.is_symlink() + and json.loads(marker.read_bytes()) == session_marker(contract_path, value), + "Scientific session reservation changed") + expected = generated_prompt(plan, manifest, session, bindings, instruction_templates(root, plan)) + rounds.require(value["prompt"] == pin(root, str(Path(prompt).relative_to(root))) + and Path(prompt).read_bytes() == expected, + "Scientific prompt differs from verified structured instructions") + return {"path": contract_path, "sha256": pin(root, contract_path)["sha256"], + "manifest": value["manifest"], "session": session, + "scope": "invocation_coherence_not_scientific_approval"} + + +def reserve(root, contract_path): + value = rounds.read(root, contract_path) + target = absolute(value["session"]["session_root"]) + target.mkdir(mode=0o700, parents=True, exist_ok=False) + rounds.write(root, str((target / "invocation.json").relative_to(root)), + session_marker(contract_path, value)) + + +def prepare(root, manifest_path, plan_path, reviewer_id, receipt_path, output): + import run_m5_review_worker_20261116 as worker + + plan, manifest, bindings = checked_plan(root, manifest_path, plan_path) + matches = [item for item in plan["sessions"] if item["reviewer_id"] == reviewer_id] + rounds.require(len(matches) == 1 and matches[0]["workdir"] == str(root), + "No planned session for reviewer in this clone") + session = matches[0] + rounds.require(not absolute(session["session_root"]).exists(), + "Scientific session root already exists") + receipt = rounds.read(root, receipt_path) + environment = worker.child_environment(root) + runtime = {"git_head": subprocess.check_output( + ["git", "-C", str(root), "rev-parse", "HEAD"], text=True).strip(), + "helper_sha256": worker.digest(worker.HELPER), + "codex_path": receipt["codex_path"], "codex_sha256": worker.digest(receipt["codex_path"]), + **worker.runtime_bindings(root, environment), **worker.repository_bindings(root)} + worker.verify_receipt(root / receipt_path, runtime, root, environment, + reviewer_package=manifest_path) + prompt_path = output + ".prompt.md" + for path in (output, prompt_path): + rounds.require(not rounds.safe(root, path, exists=False).exists(), "Invocation output exists") + rounds.require(not (root / path).is_relative_to(absolute(session["session_root"])), + "Instruction artifacts must be outside the reserved fresh session") + value = {"schema": SCHEMA, "purpose": PURPOSE, "round_id": manifest["round_id"], + **bindings, "runtime": runtime, "production_receipt": pin(root, receipt_path), + "session": session} + prompt = generated_prompt(plan, manifest, session, bindings, instruction_templates(root, plan)) + value["prompt"] = {"path": prompt_path, "sha256": rounds.digest(prompt)} + rounds.write(root, prompt_path, raw=prompt) + rounds.write(root, output, value) + return validate(root, output, manifest_path=manifest_path, runtime=runtime, + receipt_path=root / receipt_path, output=Path(session["output_root"]), + prompt=root / prompt_path) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--root", type=Path, default=rounds.ROOT) + parser.add_argument("--manifest", required=True) + parser.add_argument("--instruction-plan", required=True) + parser.add_argument("--reviewer-id", required=True) + parser.add_argument("--production-receipt", required=True) + parser.add_argument("--output", required=True, help="Exclusive repository-relative invocation JSON") + args = parser.parse_args() + print(json.dumps(prepare(args.root.resolve(), args.manifest, args.instruction_plan, + args.reviewer_id, args.production_receipt, args.output), sort_keys=True)) + + +if __name__ == "__main__": + main() diff --git a/tests/test_m5_future_views.py b/tests/test_m5_future_views.py new file mode 100644 index 0000000..2a4edd6 --- /dev/null +++ b/tests/test_m5_future_views.py @@ -0,0 +1,82 @@ +"""The future disclosure is specific; frozen v3 projections remain replayable.""" +import copy +import hashlib +import sys +from pathlib import Path + +import pytest +from test_m5_round02_views import packet + +sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts/adhoc")) +import prepare_m5_future_views_20261117 as future # noqa: E402 +import prepare_m5_round02_views_20261116 as prior # noqa: E402 + + +@pytest.fixture +def mixed_packet(monkeypatch): + source = packet() + # Synthetic mixed meaning/status text; actual original bytes stay private. + source["endpoints"]["object"]["record"]["description"] = ( + "Reviewed source-local process meaning for original_field: Synthetic α definition. " + "This does not establish a neighboring process or organism-level confirmation. " + "Reviewed vocabulary: version-1; source locator: exact-row. " + "The reviewed vocabulary version does not establish the generating version of the saved CSV." + ) + raw = source["endpoints"]["object"]["record"]["description"].encode() + monkeypatch.setattr(future, "MIXED_DESCRIPTION_SHA256", hashlib.sha256(raw).hexdigest()) + return source + + +def test_future_projection_preserves_mixed_semantics_and_bounds_only_status_tokens(mixed_packet): + source = mixed_packet + source["source_records"].append({"text": "Counterevidence and substantive definition remain."}) + before = copy.deepcopy(source) + view = future.projection(source) + old = prior.projection(source) + assert source == before + without_restored_description = copy.deepcopy(view) + without_restored_description["endpoints"]["object"]["record"].pop("description") + assert {k: v for k, v in without_restored_description.items() if k != "blinding"} == { + k: v for k, v in old.items() if k != "blinding"} + assert view["blinding"]["version"] == "edgemech-blinded-view/v4" + assert old["blinding"]["version"] == "edgemech-blinded-view/v3" + assert "cannot be blinded" in old["blinding"]["exposure"] + assert "cannot be blinded" not in view["blinding"]["exposure"] + raw = source["endpoints"]["object"]["record"]["description"].encode() + omissions = view["blinding"]["bounded_omissions"] + assert len(omissions) == 3 + for omission in omissions: + part = raw[omission["source_byte_start"]:omission["source_byte_end"]] + assert part in {b"Reviewed ", b"reviewed "} + assert omission["sha256"] == hashlib.sha256(part).hexdigest() + assert omission["source_field_sha256"] == hashlib.sha256(raw).hexdigest() + spans = view["blinding"]["retained_semantic_spans"] + reconstructed = b"".join(raw[span["source_byte_start"]:span["source_byte_end"]] + for span in spans).decode() + assert reconstructed == view["endpoints"]["object"]["record"]["description"] + assert reconstructed == raw.decode().replace("Reviewed ", "").replace("reviewed ", "") + assert "Synthetic α definition" in reconstructed + assert "does not establish a neighboring process" in reconstructed + assert "vocabulary version does not establish the generating version" in reconstructed + assert "version-1; source locator: exact-row" in reconstructed + assert sum(item["source_byte_end"] - item["source_byte_start"] + for item in [*omissions, *spans]) == len(raw) + assert {x["pointer"] for x in view["blinding"]["retained_field_bindings"]} == { + "/" + key for key in future.original.FIELDS} + assert view["source_records"] == source["source_records"] + + +def test_future_projection_does_not_infer_additional_omissions_from_evaluative_words(mixed_packet): + source = mixed_packet + source["source_records"] = [{"text": "Reviewed biological definition is contrary evidence."}] + source["endpoints"]["object"]["record"]["name"] = "supported substantive process label" + view = future.projection(source) + assert view["source_records"] == source["source_records"] + assert view["endpoints"]["object"]["record"]["name"].startswith("supported") + assert len(view["blinding"]["bounded_omissions"]) == 3 + + +def test_changed_mixed_definition_requires_new_content_inspection(mixed_packet): + mixed_packet["endpoints"]["object"]["record"]["description"] += " Changed substantive meaning." + with pytest.raises(ValueError, match="Mixed original description changed"): + future.projection(mixed_packet) diff --git a/tests/test_m5_prerequisite_package.py b/tests/test_m5_prerequisite_package.py new file mode 100644 index 0000000..d2e7f2a --- /dev/null +++ b/tests/test_m5_prerequisite_package.py @@ -0,0 +1,159 @@ +"""Prerequisite staging must not rebind changed evidence or overwrite old work.""" +from __future__ import annotations + +import json +import sys +from pathlib import Path +from types import SimpleNamespace + +import pytest + +sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts" / "adhoc")) +import prepare_m5_prerequisite_package_20261117 as package # noqa: E402 + + +@pytest.fixture +def staging(tmp_path, monkeypatch): + root, source = tmp_path / "new", tmp_path / "retained" + root.mkdir() + source.mkdir() + (root / "runtime.py").write_text("new runtime\n") + (source / "evidence.txt").write_text("retained source\n") + manifest = {"files": [ + {"path": "runtime.py", "role": "proof_adapter", "sha256": "old-runtime-hash"}, + {"path": "evidence.txt", "role": "authority", "version": "1", + "sha256": package.rounds.digest((source / "evidence.txt").read_bytes())}, + {"path": "old-prompt.md", "role": "instructions", "sha256": "historical"}, + ], "cases": []} + fixture = {"review": {"scientific_review": False, "verdict": "not_assessed"}, + "assessments": [{"category": "NOT_ASSESSABLE"}] * 6} + + def put(name, value): + raw = json.dumps(value).encode() + (source / name).write_bytes(raw) + return package.rounds.digest(raw) + + def git(command, **kwargs): + if "status" in command: + return "" + if "remote" in command: + return "https://github.com/CultureBotAI/EdgeMech.git\n" + if "ls-files" in command: + return "runtime.py\n" + if "rev-parse" in command: + return "a" * 40 + raise AssertionError(command) + + monkeypatch.setattr(package.subprocess, "check_output", git) + monkeypatch.setattr(package.subprocess, "run", lambda *a, **kw: SimpleNamespace(returncode=0)) + + def invoke(): + return package.plan(root, source, "manifest.json", put("manifest.json", manifest), + "spec.json", put("spec.json", fixture), ".temp/new-package") + + return root, source, manifest, fixture, invoke + + +def staged_ledger(staging, monkeypatch): + root, source, _, _, invoke = staging + _, _, _, actions = invoke() + (root / "evidence.txt").write_bytes((source / "evidence.txt").read_bytes()) + monkeypatch.setattr(package.worker, "execution_inventory", lambda root: []) + return root, {"runtime_commit": "a" * 40, "actions": actions, + "execution_inventory": [], "prerequisite_documents": []} + + +def test_transition_rejects_authority_drift_after_approved_plan(staging, monkeypatch): + root, ledger = staged_ledger(staging, monkeypatch) + package.verify_transition(root, ledger) + (root / "evidence.txt").write_text("different authority\n") + with pytest.raises(ValueError, match="Planned input changed"): + package.verify_transition(root, ledger) + + +@pytest.mark.parametrize("change", ["head", "execution"]) +def test_transition_rejects_runtime_drift(staging, monkeypatch, change): + root, ledger = staged_ledger(staging, monkeypatch) + if change == "head": + ledger["runtime_commit"] = "b" * 40 + else: + ledger["execution_inventory"] = [{"path": "different.py", "sha256": "changed"}] + with pytest.raises(ValueError, match="Runtime commit changed|Execution inventory changed"): + package.verify_transition(root, ledger) + + +def test_nonprivate_output_rejected_before_any_input_read(staging): + root, source, _, _, _ = staging + with pytest.raises(ValueError, match="private .temp"): + package.plan(root, source, "missing.json", "unused", "missing-spec.json", "unused", + "artifacts/new-package") + assert not (root / "artifacts").exists() + assert not (root / "evidence.txt").exists() + + +def test_unignored_output_rejected_before_any_input_read(staging, monkeypatch): + root, source, _, _, _ = staging + monkeypatch.setattr(package.subprocess, "run", lambda *a, **kw: SimpleNamespace(returncode=1)) + with pytest.raises(ValueError, match="gitignored"): + package.plan(root, source, "missing.json", "unused", "missing-spec.json", "unused", + ".temp/new-package") + assert not (root / ".temp").exists() + + +@pytest.mark.parametrize("changes, message", [ + ({"review_id": "bad"}, "Review ID"), + ({"timestamp": "2026-11-18T01:00:00Z"}, "timestamp differ"), + ({"package_id": ""}, "package ID"), + ({"prerequisite_document": ["missing.md"]}, "Missing input"), +]) +def test_metadata_rejected_before_staging(tmp_path, changes, message): + values = {"package_id": "engineering-prerequisites", "review_id": "20261118T000000Z-canary", + "timestamp": "2026-11-18T00:00:00Z", "prerequisite_document": []} + values.update(changes) + with pytest.raises(ValueError, match=message): + package.metadata_preflight(tmp_path, SimpleNamespace(**values)) + assert not list(tmp_path.iterdir()) + + +def test_plan_distinguishes_runtime_refresh_from_immutable_evidence(staging): + root, _, _, _, invoke = staging + _, _, _, actions = invoke() + assert [a["action"] for a in actions] == [ + "bind_current_runtime", "copy_exact_retained_input", "omit_historical_instructions"] + assert not (root / "evidence.txt").exists() + assert not (root / ".temp").exists() + + +def test_changed_retained_evidence_fails_before_persistence(staging): + root, source, _, _, invoke = staging + (source / "evidence.txt").write_text("different evidence\n") + with pytest.raises(ValueError, match="Retained evidence changed"): + invoke() + assert not (root / ".temp").exists() + + +def test_tracked_authority_cannot_be_refreshed_as_runtime(staging): + _, _, manifest, _, invoke = staging + manifest["files"][0]["role"] = "authority" + with pytest.raises(ValueError, match="Non-runtime tracked evidence changed"): + invoke() + + +def test_existing_private_input_is_preserved_even_if_equal(staging): + root, source, _, _, invoke = staging + original = (source / "evidence.txt").read_bytes() + (root / "evidence.txt").write_bytes(original) + with pytest.raises(ValueError, match="already exists"): + invoke() + assert (root / "evidence.txt").read_bytes() == original + + +@pytest.mark.parametrize("mutation", ["scientific", "resolved"]) +def test_scientific_fixture_cannot_be_recycled_as_operational(staging, mutation): + _, _, _, fixture, invoke = staging + if mutation == "scientific": + fixture["review"]["scientific_review"] = True + else: + fixture["assessments"][0] = {"category": "SUPPORTED_AS_STATED"} + with pytest.raises(ValueError, match="Scientific fixture|remain unresolved"): + invoke() diff --git a/tests/test_m5_review_worker.py b/tests/test_m5_review_worker.py index 1df6452..8aafb61 100644 --- a/tests/test_m5_review_worker.py +++ b/tests/test_m5_review_worker.py @@ -372,6 +372,11 @@ def production_validator(command, **kwargs): monkeypatch.setattr(module.subprocess, "run", production_validator) monkeypatch.setattr(module.subprocess, "check_output", subprocess.check_output) monkeypatch.setattr(module, "repository_identity", repository_identity) + # These fixtures isolate production save/readback and drift. Scientific + # contract validation has a real-package suite in test_m5_scientific_invocation. + controls["scientific_context"] = module.scientific_context + monkeypatch.setattr(module, "scientific_context", lambda *a, **kw: {"fixture": "contract"}) + monkeypatch.setattr(module, "reserve_scientific", lambda *a: None) return module, args, controls @@ -380,6 +385,7 @@ def reviewer_args(args): args.output_root = args.workdir / "reviewer" args.role = "reviewer" args.production_review = args.production_packet = args.production_proofs = None + args.scientific_invocation = "synthetic-scientific-invocation.json" def test_176_parent_runs_real_save_check_and_reviewer_replays_same_clone(production_worker): @@ -405,6 +411,31 @@ def test_176_parent_runs_real_save_check_and_reviewer_replays_same_clone(product assert state["ending_replay"]["production_replay"]["outputs"] == pair +def test_203_production_canary_cannot_substitute_for_scientific_invocation( + production_worker, monkeypatch): + module, args, controls = production_worker + assert module.launch(args) == 0 + reviewer_args(args) + monkeypatch.syspath_prepend(str(HELPER.parent)) + monkeypatch.setattr(module, "scientific_context", controls["scientific_context"]) + args.scientific_invocation = None + with pytest.raises(ValueError, match="structured scientific invocation"): + module.launch(args) + assert controls["calls"] == 1 and not args.output_root.exists() + + +def test_203_scientific_invocation_cannot_widen_writable_directories(production_worker, monkeypatch): + module, args, controls = production_worker + assert module.launch(args) == 0 + reviewer_args(args) + monkeypatch.syspath_prepend(str(HELPER.parent)) + monkeypatch.setattr(module, "scientific_context", controls["scientific_context"]) + args.add_dir = [args.workdir.parent] + with pytest.raises(ValueError, match="undeclared writable directories"): + module.launch(args) + assert controls["calls"] == 1 and not args.output_root.exists() + + def test_176_production_plan_validates_without_saving_or_starting_child(production_worker): module, args, controls = production_worker args.plan = True diff --git a/tests/test_m5_scientific_invocation.py b/tests/test_m5_scientific_invocation.py new file mode 100644 index 0000000..b66ed5d --- /dev/null +++ b/tests/test_m5_scientific_invocation.py @@ -0,0 +1,201 @@ +"""Future scientific launch coherence is independent of engineering readiness (#203).""" +from __future__ import annotations + +import copy +import shutil +import sys +from pathlib import Path + +import pytest +from test_calibration_round import round_inputs as round_inputs + +ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT / "scripts/adhoc")) +import scientific_invocation_20261117 as invocation # noqa: E402 + + +@pytest.fixture +def contract(round_inputs, monkeypatch): + rounds, root, _, _, config, put = round_inputs + monkeypatch.setattr(invocation, "rounds", rounds) + original_put = put + + def put(path, value): + target = root / path + if target.is_file(): + target.chmod(0o600) + original_put(path, value) + + put("instructions.md", {"schema": invocation.TEMPLATE_SCHEMA, + "text": "Use {{manifest_path}} and write under {{output_root}}."}) + config["package_purpose"] = invocation.PURPOSE + for item in config["files"]: + if item["role"] in {"instructions", "authority", "evidence", "view"}: + item["visibility"] = "reviewer" + helper = root / invocation.HELPER + helper.parent.mkdir(parents=True, exist_ok=True) + shutil.copyfile(ROOT / invocation.HELPER, helper) + config["files"].append({"path": invocation.HELPER, "role": "proof_adapter"}) + session = {"reviewer_id": "reviewer-a", "workdir": str(root), + "session_root": str(root / ".temp/future-reviewer-a"), + "output_root": str(root / ".temp/future-reviewer-a/worker")} + plan = {"schema": invocation.PLAN_SCHEMA, "purpose": invocation.PURPOSE, + "round_id": config["round_id"], "manifest_path": "future-manifest.json", + "phase": "blinded_initial_review", "sessions": [session], + "instruction_paths": ["instructions.md"], + "read_paths": [rounds.PROTOCOL, *[item["path"] for item in config["files"] + if item.get("visibility") == "reviewer"]]} + put("instruction-plan.json", plan) + config["files"].append({"path": "instruction-plan.json", "role": "scientific_instructions"}) + put("future-config.json", config) + rounds.freeze(root, "future-config.json", "future-manifest.json") + plan, manifest, bindings = invocation.checked_plan( + root, "future-manifest.json", "instruction-plan.json") + put("production/receipt.json", {"fixture": "readiness is not scientific authorization"}) + value = {"schema": invocation.SCHEMA, "purpose": invocation.PURPOSE, + "round_id": config["round_id"], **bindings, "runtime": {"git_head": "a" * 40}, + "production_receipt": invocation.pin(root, "production/receipt.json"), + "session": session} + prompt = invocation.generated_prompt(plan, manifest, session, bindings, + invocation.instruction_templates(root, plan)) + (root / "generated.prompt.md").write_bytes(prompt) + value["prompt"] = invocation.pin(root, "generated.prompt.md") + put("invocation.json", value) + kwargs = {"manifest_path": "future-manifest.json", "runtime": value["runtime"], + "receipt_path": root / "production/receipt.json", + "output": Path(session["output_root"]), "prompt": root / "generated.prompt.md"} + return root, plan, manifest, value, kwargs, put + + +def test_verified_structured_prompt_and_session_are_bound_and_exclusive(contract): + root, plan, manifest, value, kwargs, _ = contract + result = invocation.validate(root, "invocation.json", **kwargs) + prompt = kwargs["prompt"].read_text() + assert result["manifest"] == value["manifest"] + assert plan["round_id"] in prompt and value["manifest"]["sha256"] in prompt + assert "round03-package" not in prompt and "reviewer-a" in prompt + assert not Path(value["session"]["session_root"]).exists() + invocation.reserve(root, "invocation.json") + marker = Path(value["session"]["session_root"]) / "invocation.json" + assert marker.is_file() and marker.stat().st_size > 0 + assert invocation.validate(root, "invocation.json", **kwargs, fresh=False) == result + with pytest.raises(ValueError, match="session root already exists"): + invocation.validate(root, "invocation.json", **kwargs) + with pytest.raises(FileExistsError): + invocation.reserve(root, "invocation.json") + + +@pytest.mark.parametrize("field,replacement,error", [ + ("manifest_path", "manifest.json", "Supplied package differs"), + ("output", Path("/different/output"), "output root differs"), + ("runtime", {"git_head": "b" * 40}, "runtime changed"), +]) +def test_supplied_package_output_and_runtime_must_agree(contract, field, replacement, error): + root, _, _, _, kwargs, _ = contract + kwargs[field] = replacement + with pytest.raises(ValueError, match=error): + invocation.validate(root, "invocation.json", **kwargs) + + +@pytest.mark.parametrize("purpose", [None, "engineering_prerequisites"]) +def test_engineering_and_legacy_packages_cannot_be_scientific_authorization(contract, purpose): + root, _, manifest, _, kwargs, put = contract + if purpose: + manifest["package_purpose"] = purpose + else: + manifest.pop("package_purpose") + put("future-manifest.json", manifest) + with pytest.raises(ValueError, match="Engineering-only or undeclared"): + invocation.validate(root, "invocation.json", **kwargs) + + +def mutate_plan(root, plan, manifest, put): + put("instruction-plan.json", plan) + for item in manifest["files"]: + if item["path"] == "instruction-plan.json": + item["sha256"] = invocation.pin(root, item["path"])["sha256"] + put("future-manifest.json", manifest) + + +@pytest.mark.parametrize("field,value,error", [ + ("round_id", "previous-round", "manifest ID or path mismatch"), + ("manifest_path", "old-round03/manifest.json", "manifest ID or path mismatch"), + ("read_paths", ["private-originals/old-labels.json"], "Allowed navigation"), + ("instruction_paths", ["authority.txt"], "Instruction paths differ"), +]) +def test_package_pinned_instruction_mismatch_is_rejected(contract, field, value, error): + root, plan, manifest, _, kwargs, put = contract + plan[field] = value + mutate_plan(root, plan, manifest, put) + with pytest.raises(ValueError, match=error): + invocation.validate(root, "invocation.json", **kwargs) + + +def test_matching_new_hash_cannot_make_stale_freeform_prompt_valid(contract): + root, _, _, value, kwargs, put = contract + kwargs["prompt"].write_text("Use old round03-package/manifest.json and completed reviewer roots.") + value["prompt"] = invocation.pin(root, "generated.prompt.md") + put("invocation.json", value) + with pytest.raises(ValueError, match="differs from verified structured instructions"): + invocation.validate(root, "invocation.json", **kwargs) + + +def test_completed_session_cannot_be_reused_with_a_fresh_child_output(contract): + root, plan, manifest, value, kwargs, put = contract + session = Path(value["session"]["session_root"]) + (session / "previous-output").mkdir(parents=True) + (session / "previous-output/FINAL_REPORT.md").write_text("Completed retained result") + assert not kwargs["output"].exists() + with pytest.raises(ValueError, match="session root already exists"): + invocation.validate(root, "invocation.json", **kwargs) + assert (session / "previous-output/FINAL_REPORT.md").read_text() == "Completed retained result" + + +def test_modified_production_receipt_and_session_reservation_fail_closed(contract): + root, _, _, _, kwargs, put = contract + invocation.reserve(root, "invocation.json") + put("production/receipt.json", {"other": "receipt"}) + with pytest.raises(ValueError, match="production receipt changed"): + invocation.validate(root, "invocation.json", **kwargs, fresh=False) + + +def test_session_clone_and_overlapping_work_are_not_interchangeable(contract): + root, plan, manifest, _, kwargs, put = contract + other = copy.deepcopy(plan["sessions"][0]) + other["reviewer_id"] = "reviewer-b" + other["session_root"] = str(root / ".temp/other") + other["output_root"] = str(root / ".temp/other/worker") + plan["sessions"].append(other) + mutate_plan(root, plan, manifest, put) + with pytest.raises(ValueError, match="distinct reviewer clones"): + invocation.validate(root, "invocation.json", **kwargs) + + +def test_209_adjudication_rejected_without_a_typed_initial_seals_and_results_contract(contract): + root, plan, manifest, value, kwargs, put = contract + plan["phase"] = "evidence_adjudication" + mutate_plan(root, plan, manifest, put) + with pytest.raises(ValueError, match="Unsupported scientific phase"): + invocation.validate(root, "invocation.json", **kwargs) + with pytest.raises(ValueError, match="Unsupported scientific phase"): + invocation.generated_prompt(plan, manifest, value["session"], { + key: value[key] for key in ("manifest", "instructions")}, + invocation.instruction_templates(root, plan)) + + +@pytest.mark.parametrize("legacy", [True, False]) +def test_old_embedded_instruction_paths_cannot_reenter_via_pinned_assets(contract, legacy): + root, plan, manifest, _, kwargs, put = contract + path = root / "instructions.md" + if legacy: + path.write_bytes((ROOT / "scripts/adhoc/m5_review_20261116/round03-blinded-review.md") + .read_bytes()) + else: + put("instructions.md", {"schema": invocation.TEMPLATE_SCHEMA, + "text": "Read .temp/round03-package/manifest.json."}) + for item in manifest["files"]: + if item["path"] == "instructions.md": + item["sha256"] = invocation.pin(root, item["path"])["sha256"] + put("future-manifest.json", manifest) + with pytest.raises(ValueError, match="structured templates|bound placeholders"): + invocation.validate(root, "invocation.json", **kwargs) diff --git a/tests/test_reviewer_clone_provisioning.py b/tests/test_reviewer_clone_provisioning.py new file mode 100644 index 0000000..f7a86cc --- /dev/null +++ b/tests/test_reviewer_clone_provisioning.py @@ -0,0 +1,193 @@ +"""Issue #206: provisioning preserves failed clones and cannot authorize reviewers.""" + +from __future__ import annotations + +import argparse +import importlib.util +import json +import os +import subprocess +import sys +from pathlib import Path + +import pytest + +HELPER = Path(__file__).resolve().parents[1] / "scripts/adhoc/provision_reviewer_clone_20261117.py" + + +@pytest.fixture +def provisioning(tmp_path): + spec = importlib.util.spec_from_file_location("provision_reviewer_clone", HELPER) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + args = argparse.Namespace(revision="a" * 40, destination=tmp_path / "reviewer", + python=Path(sys.executable), uv=Path(sys.executable), plan=True) + return module, args + + +def test_plan_does_not_create_clone_or_spawn_process(provisioning, monkeypatch): + module, args = provisioning + monkeypatch.setattr(module, "run_command", lambda *_: pytest.fail("Plan spawned a process")) + result = module.provision(args) + assert not args.destination.exists() + assert result["origin"] == module.ORIGIN + assert result["commands"][0][-2:] == [module.ORIGIN, str(args.destination)] + assert result["commands"][2][-2:] == ["--detach", args.revision] + assert "--locked" in result["commands"][3] + assert not result["authorizes_reviewer_launch"] + assert not result["scientific_gate_passed"] + + +@pytest.mark.parametrize("revision", ["main", "abcdef1", "A" * 40, "a" * 39, "a" * 40 + " "]) +def test_nonexact_revision_is_rejected(provisioning, revision): + module, args = provisioning + args.revision = revision + with pytest.raises(ValueError, match="exact full"): + module.plan(args) + + +@pytest.mark.parametrize("existing", ["directory", "file", "dangling_symlink"]) +def test_existing_destination_is_never_reused(provisioning, existing): + module, args = provisioning + if existing == "directory": + args.destination.mkdir() + (args.destination / "retained.txt").write_text("historical failure") + elif existing == "file": + args.destination.write_text("historical failure") + else: + args.destination.symlink_to(args.destination.parent / "absent") + with pytest.raises(ValueError, match="already exists"): + module.provision(args) + assert os.path.lexists(args.destination) + + +def test_environment_cannot_redirect_venv_or_inherit_credentials(provisioning, monkeypatch): + module, args = provisioning + monkeypatch.setenv("UV_PROJECT_ENVIRONMENT", "/outside/retained-venv") + monkeypatch.setenv("VIRTUAL_ENV", "/outside/retained-venv") + monkeypatch.setenv("PYTHONPATH", "/outside/python") + monkeypatch.setenv("CBORG_API_KEY", "test-only-placeholder") + child = module.environment(args.destination) + assert child["UV_PROJECT_ENVIRONMENT"] == str(args.destination / ".venv") + assert child["UV_PYTHON_DOWNLOADS"] == "never" + assert not {"VIRTUAL_ENV", "PYTHONPATH", "CBORG_API_KEY"} & child.keys() + + +@pytest.fixture +def actual_checkout(provisioning, monkeypatch): + module, args = provisioning + source = args.destination.parent / "source" + source.mkdir() + subprocess.run(["git", "init", str(source)], check=True, capture_output=True) + helper = source / module.RELATIVE_HELPER + helper.parent.mkdir(parents=True) + helper.write_bytes(HELPER.read_bytes()) + (source / ".gitignore").write_text(".temp/\n.venv/\n") + subprocess.run(["git", "-C", str(source), "add", "."], check=True) + subprocess.run(["git", "-C", str(source), "-c", "user.name=Fixture", + "-c", "user.email=fixture@example.invalid", "commit", "-m", "Fixture"], + check=True, capture_output=True) + args.revision = subprocess.check_output(["git", "-C", str(source), "rev-parse", "HEAD"], + text=True).strip() + args.plan = False + controls = {"bad_origin": False, "bad_helper": False, "install_failure": False, + "wrong_host": False, "calls": []} + + def run(command, root): + controls["calls"].append(command) + if command[1] == "clone": + subprocess.run(["git", "clone", "--no-hardlinks", str(source), str(root)], + check=True, capture_output=True) + subprocess.run(["git", "-C", str(root), "remote", "set-url", "origin", + "https://github.com/other/repository.git" if controls["bad_origin"] + else module.ORIGIN], check=True) + if controls["bad_helper"]: + (root / module.RELATIVE_HELPER).write_text("modified helper\n") + elif "checkout" in command: + subprocess.run(command, check=True, capture_output=True) + elif command[1] == "sync": + (root / ".venv").mkdir() + (root / ".venv/retained-partial-install").write_text("retain after failure") + if controls["install_failure"]: + raise RuntimeError("simulated install failure") + elif "--inspect-root" in command: + return json.dumps({"host": "wrong-host" if controls["wrong_host"] + else module.platform.node(), + "python_base_executable": str(args.python)}) + return "" + + monkeypatch.setattr(module, "run_command", run) + return module, args, controls + + +def test_success_receipt_is_persisted_and_non_authorizing(actual_checkout): + module, args, controls = actual_checkout + receipt = module.provision(args) + assert json.loads((args.destination / module.RECEIPT).read_text()) == receipt + assert receipt["status"] == "passed" + assert receipt["steps_completed"] == 6 + assert receipt["capability"] == "clone-and-dependency-setup-only" + assert not receipt["authorizes_reviewer_launch"] + assert not receipt["scientific_gate_passed"] + assert module.git(args.destination, "rev-parse", "HEAD") == args.revision + assert any(command[1:3] == ["pip", "check"] for command in controls["calls"]) + + +@pytest.mark.parametrize("fault", ["bad_origin", "bad_helper"]) +def test_invalid_checkout_cannot_install_or_pass(actual_checkout, fault): + module, args, controls = actual_checkout + controls[fault] = True + with pytest.raises(ValueError): + module.provision(args) + assert not any(command[1] == "sync" for command in controls["calls"]) + receipt = json.loads((args.destination / module.RECEIPT).read_text()) + assert receipt["status"] == "failed" + assert args.destination.is_dir() + + +def test_failed_install_preserves_artifacts_and_refuses_retry(actual_checkout): + module, args, controls = actual_checkout + controls["install_failure"] = True + with pytest.raises(RuntimeError, match="simulated install failure"): + module.provision(args) + path = args.destination / module.RECEIPT + retained = path.read_bytes() + assert json.loads(retained)["status"] == "failed" + assert (args.destination / ".venv/retained-partial-install").read_text() + with pytest.raises(ValueError, match="already exists"): + module.provision(args) + assert path.read_bytes() == retained + + +def test_wrong_host_probe_cannot_pass(actual_checkout): + module, args, controls = actual_checkout + controls["wrong_host"] = True + with pytest.raises(ValueError, match="different host"): + module.provision(args) + assert json.loads((args.destination / module.RECEIPT).read_text())["status"] == "failed" + + +def test_probe_rejects_coordinator_interpreter(provisioning): + module, args = provisioning + with pytest.raises(ValueError, match="outside clone venv"): + module.inspect_environment(args.destination) + + +def test_probe_rejects_system_packages(provisioning, monkeypatch): + module, args = provisioning + venv = args.destination / ".venv" + venv.mkdir(parents=True) + (venv / "pyvenv.cfg").write_text("include-system-site-packages = true\n") + monkeypatch.setattr(module.sys, "prefix", str(venv)) + monkeypatch.setattr(module.sys, "base_prefix", "/system-python") + with pytest.raises(ValueError, match="includes system packages"): + module.inspect_environment(args.destination) + + +def test_symlink_parent_is_rejected(provisioning): + module, args = provisioning + alias = args.destination.parent / "alias" + alias.symlink_to(args.destination.parent, target_is_directory=True) + args.destination = alias / "reviewer" + with pytest.raises(ValueError, match="traverse symlinks"): + module.plan(args) From 3057bb2bae6c38ba8b588659da023a42a3bfe6b9 Mon Sep 17 00:00:00 2001 From: "marcin p. joachimiak" <4625870+realmarcin@users.noreply.github.com> Date: Tue, 17 Nov 2026 20:11:28 -0800 Subject: [PATCH 2/3] Bind bootstrap receipts and verify real replay before native canaries --- NEXT_TASKS.md | 4 +- .../plans/m5-prerequisite-package-20261117.md | 15 ++- .../m5-prerequisites-live-20261117.md | 87 +++++++++++++ ...rerequisite-adversarial-review-20261117.md | 1 + ...repare_m5_prerequisite_package_20261117.py | 116 +++++++++++++++++- tests/test_m5_prerequisite_package.py | 101 +++++++++++++++ 6 files changed, 315 insertions(+), 9 deletions(-) create mode 100644 docs/validation/m5-prerequisites-live-20261117.md diff --git a/NEXT_TASKS.md b/NEXT_TASKS.md index cc72974..feb454a 100644 --- a/NEXT_TASKS.md +++ b/NEXT_TASKS.md @@ -1,6 +1,6 @@ # Edge-review next tasks -**Prerequisite repair in progress, 2026-11-17:** #203 binds future scientific instructions, package purpose, navigation and fresh session roots; #205 clarifies direct semantic comparison versus trace-dependent source fidelity; #206 makes canonical clone/environment provisioning reproducible. Both retained round03 reviewer environments already pass actual production readback with their original receipts. Fresh environment and package checks are being prepared on `fix/calibration-prerequisites-20261117`; these are engineering checks and do not start another calibration. Missing original evidence remains a separate scientific blocker. Preserve all earlier packages, ratings, failed attempts and clones. +**Prerequisite repair in progress, 2026-11-17, [PR #211](https://github.com/CultureBotAI/EdgeMech/pull/211):** #203 binds future scientific instructions, package purpose, navigation and fresh session roots; #205 clarifies direct semantic comparison versus trace-dependent source fidelity; #206 makes canonical clone/environment provisioning reproducible. Both retained round03 environments pass actual readback. The first fresh M5 clone passed setup and 378 package bindings, but its native canary found missing bootstrap receipt/mode requirements (#212); that failed attempt is preserved and a repaired runtime must pass a fresh canary before the second clone starts. #207/#208 staging guards and #210 bounded definition retention passed independent re-review. Adjudication fails closed pending typed initial-result bindings (#209). These engineering checks do not start another calibration or resolve the missing original scientific witnesses. **Round03 finalized failed, 2026-11-16:** [Round03 results](docs/validation/m5-calibration-round03-results-20261116.md) preserve two fresh sealed matrices and separate adjudication. Initial agreement is 54/60, but source-fidelity agreement 7/10 and final resolution 3/10 fail their unchanged 8/10 floors. Six initial claim/model judgments and three supplemental source-fidelity judgments are unsupported; four disagreements remain unresolved, including one blocking model judgment. Mechanical finalization passes 20/20 canonical pairs, 153/153 selected initial proofs and 55/55 final citation rows, with 59 final local proofs separately validated. Eleven rejected authoring attempts remain preserved. A missed historical producer clause independently fails blinding (#200); the earlier blanket preparation audit is corrected. All scientific workers exited with ending bindings intact. Remaining90/9900 remain closed. The next scientific step requires missing original source/identity/definition witnesses and a separately identified round with unchanged thresholds. @@ -40,7 +40,7 @@ Evidence: [fresh-canary report](artifacts/edge-recanary-20261113/RECANARY-REPORT | 2 — **PENDING, actionable bounded audit** | Semantic identity, relation and node-category correctness | Prepare pinned authorities and audit the selected calibration cases, then the existing 100 after gates pass. Prioritize [#68](https://github.com/CultureBotAI/EdgeMech/issues/68)/[#106](https://github.com/CultureBotAI/EdgeMech/issues/106) identity joins and [#75](https://github.com/CultureBotAI/EdgeMech/issues/75)/[#86](https://github.com/CultureBotAI/EdgeMech/issues/86)/[#87](https://github.com/CultureBotAI/EdgeMech/issues/87) relation/type-strain/bin semantics. Review nonempty categories, not only missing fields. All 22 fresh-canary biological-literature exclusions still receive identity/modeling review. | | 3 — **PENDING, actionable retained-evidence work** | DOI identity, exact snippets and categorical claim judgments | Resolve publication identity [#69](https://github.com/CultureBotAI/EdgeMech/issues/69); replay retained evidence for the selected calibration cases first, then retrieve missing relevant text through appropriate channels. Verify literal quotes and independently judge entailment, conditions and organism/strain scope. Record support, refutation, conflicts, insufficient evidence and assessment blockers distinctly. | | Parallel — **IN PROGRESS** | General full-text credential protection: [#100](https://github.com/CultureBotAI/EdgeMech/issues/100), [PR #102](https://github.com/CultureBotAI/EdgeMech/pull/102) | The draft has a clean independent review and green CI at `2364161819951b7899ba62cebcd461bf0394c4a7`. Reconcile with current main and validate before a separately authorized merge. Complete this before further authenticated general-helper retrieval; it need not block local modeling or retained-evidence review. | -| 4 — **ROUND02 FAILED AFTER ADJUDICATION** | Preserve results and repair prerequisites before a separate round | Initial agreement 52/60, source-fidelity agreement 4/10, final source-fidelity resolution 7/10 and evidence integrity fail. All 20 canonical slots replayed as missing; audit covers every emitted initial/final resolved claim/model label and all 60 final axes. Preserve three unresolved source-fidelity disagreements, failed proof attempts and exposure #175; repair clone-origin preparation under #176 and exact citation/proof bindings before new canaries and a separately frozen round. Retained-90 and 9,900 review remain closed. | +| 4 — **ROUND03 FAILED; prerequisite repair in progress** | Recover original witnesses and repair prerequisites before a separate round | Round03 achieved 20 canonical pairs, but source-fidelity agreement 7/10, resolution 3/10, unsupported initial labels and blinding fail the unchanged gates. PR #211 repairs setup/invocation/fidelity guidance and future definition visibility; its first fresh native canary exposed bootstrap staging #212. Recover the exact source selection/identity/field-meaning witnesses in the ten-case map, complete typed adjudication bindings #209, then separately freeze a scientifically reviewed package and rerun real same-clone readiness. All historical failures stay intact. Retained-90 and 9,900 remain closed. | | 5 — **PENDING; upstream fixes/releases where needed** | Correct and verify affected assertions and nodes | File each finding, identify its maintained owner, retain before/after proposals, add regressions, regenerate a new candidate and independently re-assess affected occurrences. Include [#56](https://github.com/CultureBotAI/EdgeMech/issues/56), [#70](https://github.com/CultureBotAI/EdgeMech/issues/70), [#72](https://github.com/CultureBotAI/EdgeMech/issues/72) and proof of existing fixes [#71](https://github.com/CultureBotAI/EdgeMech/issues/71)/[#73](https://github.com/CultureBotAI/EdgeMech/issues/73). A merged source PR is distinct from a verified corrected graph release. | **Completed initial execution, 2026-11-16:** M5 main was synchronized to `f841b1d` for the original [execution plan](docs/plans/m5-review-execution-20261116.md). The original calibration and BactoTraits verification workers ran and exited. Round01 failed; the BactoTraits-only candidate passed its bounded verification, while full canonical release/publication remains outstanding. Round02 subsequently failed initial agreement, final source-fidelity resolution and evidence integrity after separate adjudication; both initial reviewer jobs exited. Preserve sampled/current authority distinctions, all original thresholds and both rounds' immutable failures. Retained-90 and 9,900 review remain gated; neither operational startup nor source-only candidate verification establishes scientific calibration or full-release completion. This reconciliation retains #165's historical execution context. diff --git a/docs/plans/m5-prerequisite-package-20261117.md b/docs/plans/m5-prerequisite-package-20261117.md index d735afb..abe58b6 100644 --- a/docs/plans/m5-prerequisite-package-20261117.md +++ b/docs/plans/m5-prerequisite-package-20261117.md @@ -16,6 +16,12 @@ at the exact committed candidate runtime. The retained source is M5's Its conservative operational specification is `.temp/m5-round03-worker-20261116/engineering-operational-canary-spec-02.json`, SHA256 `3321872d3bb7685836b46d0d799973ffb17335ea6b78a5783bf63c941a7c1e32`. +Also supply `--bootstrap-receipt-sha256 +894a803fc18fdf66e715884f51a899fdb5ba5107cec3ad13b237c9c9e369f7af`. +This binds the original `fresh-47/receipt.json` outside the retained manifest. +Its original timestamp and bytes stay unchanged; it is not a new runtime/save +receipt. Configuration equality and the maintained preparation checker are +required before it can be reused for byte replay. The helper checks both exact input hashes before staging. Retained evidence, source packets, original records and bounded-view receipts retain their exact @@ -36,6 +42,13 @@ documents, canonical review destination and source pins are checked before copying. The helper replays planned evidence hashes, document pins, execution inventory, HEAD and clean tracked state around freezing and authoring. It preserves failed attempts rather than overwriting them or emitting success. +The bootstrap quartet is copied at mode 0600 inside a 0700 case directory, as +required by the real checker; other sealed package inputs retain their existing +mode policy. The actual free `prepare_calibration_20261115.py --check fresh-47` +must pass before freezing succeeds. It also reads the retained private source +archive on M5, verifies its expected upstream hashes, and leaves it unchanged. +The public fresh-canary projection is explicitly pinned. This addition fixes +the first actual native-worker failure (#212), which remains preserved. ## Execution sequence @@ -43,7 +56,7 @@ preserves failed attempts rather than overwriting them or emitting success. helper. Inspect its on-disk receipt, origin, revision and isolated environment. 2. Run package preparation with `--plan`, then the identical arguments and `--run`. Supply the source root/manifest/hash and operational spec/hash above; - a new `--output`, `--package-id`, UTC `--timestamp` and matching timestamped + the bootstrap receipt hash, a new `--output`, `--package-id`, UTC `--timestamp` and matching timestamped `--review-id` are required. Inspect the persisted preparation receipt. 3. Use the maintained worker launcher with role `canary`, the new manifest, `operational/review.json`, `operational/proofs.json`, the original fresh-47 diff --git a/docs/validation/m5-prerequisites-live-20261117.md b/docs/validation/m5-prerequisites-live-20261117.md new file mode 100644 index 0000000..52279eb --- /dev/null +++ b/docs/validation/m5-prerequisites-live-20261117.md @@ -0,0 +1,87 @@ +# M5 prerequisite verification — 2026-11-17 + +This record covers engineering checks for [PR #211](https://github.com/CultureBotAI/EdgeMech/pull/211). +The frozen executable runtime is `2f99a16e7752d2dbe31471781b31ceb5aa90c8a0`, +stacked on round03 delivery `d0ed406`. No new scientific calibration has started. +The failed round03 result, original packages, seals, reviews and clones remain +unchanged. The new checks do not review the retained 90 or expand to 9,900. + +## Code and independent review + +[Exact-runtime CI](https://github.com/CultureBotAI/EdgeMech/actions/runs/44234472702) +passed all **1,345 tests**, all 16 pinned CLAW contract payloads, full Ruff scope, +and source/wheel builds. The shared dependency remains the reviewed, unmerged +CLAW candidate `4fad8df5b2367da68faca6379ce32eb9b8f4ba9b`. + +Separate read-only reviews covered the clone/environment setup, package staging, +invocation/launcher integration and actual fresh-32 definition bytes. Findings +#207–#210 were filed before remediation. Re-review and a final complete-PR pass +found no additional material issue. The [review record](prerequisite-adversarial-review-20261117.md) +distinguishes fixes from the intentionally unsupported adjudication phase. + +## Actual M5 environments + +Fresh clone roots are beneath +`/Users/marcin/agent-work/EdgeMech/m5-prerequisite-reviewers-20261117`. +Both are intended to use the same exact runtime and canonical GitHub origin; +results below are recorded only after their artifacts are checked. + +| Binding | reviewer-a | reviewer-b | +| --- | --- | --- | +| Setup | Passed six real provisioning steps | Pending | +| Interpreter | Clone-local `.venv`, Python 3.14.7 | Pending | +| Provisioning receipt SHA256 | `8c6a9bdbfc4e1aef0fe3af5eb1b96483a88a20ca7c2b62ed955f0594debec4ab` | Pending | +| New engineering manifest SHA256 | `e3536cb66bb01badd2360228e7c99ae59034c4ec0c674c21a59cda5d19980964` | Pending | +| Verified input bindings / original packets | 378 / 10 | Pending | +| Real native worker and production save/readback | Failed bootstrap; no save attempted | Not started | + +Reviewer-a's preparation receipt is +`0a3092569231c22b05fd2534a153d702b812a47c0ef07513bfd642bd4680b859`. +It records a validated conservative draft, with no canonical save yet claimed. +The actual scientific-invocation CLI rejected this engineering manifest before +writing any invocation, with the expected engineering-purpose error. The +separate same-clone production launch plan passed before real execution. + +The first live canary failed before production save under #212. Its package had +complete declared bindings but omitted the bootstrap receipt outside that +manifest; the copied seed files also had mode 0400 where the maintained bootstrap +checker requires 0600. The child correctly reported failure, and the parent +rejected it despite child exit code 0. The failure result SHA256 is +`8364a86fb72b75e23a3a2b6c95b0733f0fbcd42ffba1649d549b763b15a4b4c9`. +It finished at `2026-11-18T04:07:36Z`; the failed clone and all logs remain intact. +Direct path checks found neither a canonical review directory nor a passing +canary receipt, and tracked runtime files stayed clean. A repaired runtime must +pass a new clone canary before the second environment is provisioned. + +The maintained provisioner and package/worker CLIs were used throughout. Exactly +one clone is checked end to end before another is provisioned. The native worker +uses configured defaults without a model override or a new credential copy. +The parent executes the production save/check and compares authored content and +on-disk YAML/Markdown hashes; worker prose is not the acceptance criterion. + +## Scientific boundary + +The new package freezes complete **available byte bindings** and preserves +unresolved scientific dependencies explicitly. The [neutral fidelity procedure](../plans/source-fidelity-decision-procedure-20261117.md) +distinguishes direct source-to-assertion comparison from cases needing a trace +to establish field selection, identity or meaning. The coordinator-only +[ten-case witness map](../plans/m5-source-fidelity-witness-map-20261117.md) records +what remains missing. + +The new fresh-32 view preserves 778 substantive bytes and removes only 27 bytes +of review-status wording. Definitions, scope limits, provenance and the unknown +generating-version caveat remain. This repairs future evidence visibility; it +does not turn inherited text into independent ontology authority or repair the +completed round's exposure. + +The operational fixture remains non-scientific and unresolved on all six axes, +outside scientific matrices and graph-admission denominators. A full future +round still needs missing original witnesses and a reviewed typed adjudication +contract for initial matrices, seals and comparison (#209). The concrete next +source recovery is the bounded MetaTraits mapping/polarity path with exact +loader/template/source pins. No new LBNL/CBORG literature query or primary +full-paper inspection occurred in these prerequisite checks. + +Every production receipt applies only to its recorded clone, package and +runtime. A later delivery/documentation commit does not retroactively authorize +that commit or a different scientific package. diff --git a/docs/validation/prerequisite-adversarial-review-20261117.md b/docs/validation/prerequisite-adversarial-review-20261117.md index 14927cf..1caa5b1 100644 --- a/docs/validation/prerequisite-adversarial-review-20261117.md +++ b/docs/validation/prerequisite-adversarial-review-20261117.md @@ -14,6 +14,7 @@ projections remain unchanged. | #208: planned tracked evidence/runtime could drift before freeze recomputed hashes | Replay planned input/document hashes, complete execution inventory, HEAD and clean tracked state before and after freeze and after authoring. Drift prevents a success receipt. | | #209: adjudication accepted a plan without bound initial results | Reject that phase at validation and prompt generation. A typed initial-matrix/seal/comparison contract remains necessary before a complete future round. | | #210: whole-field blinding omitted substantive process meaning while claiming definitions were retained | Restore the exact mixed definition except three separable review-status tokens; retain scope/version limitations and provenance with original hashes and bounded byte-span records. | +| #212: first native canary lacked its bootstrap receipt and required seed modes | Bind the unchanged historical receipt and full bootstrap inputs, preserve 0600 files/0700 case directory, and run the actual maintained bootstrap checker before any native worker. Preserve the failed clone and re-canary a new runtime before fanout. | Independent re-review found #207/#208 corrected and no additional material defect in the provisioning path or #203/#209 invocation/launcher integration. diff --git a/scripts/adhoc/prepare_m5_prerequisite_package_20261117.py b/scripts/adhoc/prepare_m5_prerequisite_package_20261117.py index 83b4428..33b2618 100644 --- a/scripts/adhoc/prepare_m5_prerequisite_package_20261117.py +++ b/scripts/adhoc/prepare_m5_prerequisite_package_20261117.py @@ -12,12 +12,15 @@ import copy import json import re +import stat import subprocess +import sys from datetime import datetime from pathlib import Path import author_m5_review_data_20261116 as author import calibration_round_20261116 as rounds +import prepare_calibration_20261115 as bootstrap import prepare_m5_future_views_20261117 as views import run_m5_review_worker_20261116 as worker @@ -26,6 +29,9 @@ FIXED = {rounds.PROTOCOL, rounds.COHORT, "docs/record-review-profile.md", "scripts/adhoc/calibration_round_20261116.py"} REFRESH_ROLES = {"proof_adapter", "profile", "round_helper", "instructions"} +BOOTSTRAP_ROOT = bootstrap.PRIVATE / bootstrap.CANARY +BOOTSTRAP_RECEIPT = str(BOOTSTRAP_ROOT / "receipt.json") +BOOTSTRAP_NAMES = {"occurrence.json", "source.json", "packet.json"} def checked_document(root, path, expected): @@ -34,7 +40,58 @@ def checked_document(root, path, expected): return json.loads(raw, object_pairs_hook=rounds.unique_object) -def plan(root, source_root, manifest_path, manifest_sha, spec_path, spec_sha, output): +def complete_bootstrap_manifest(root, source_root, manifest, receipt_sha): + """Bind exact retained preparation; never regenerate or re-date its receipt (#212).""" + receipt = checked_document(source_root, BOOTSTRAP_RECEIPT, receipt_sha) + cases = [case for case in manifest["cases"] if case["case_id"] == bootstrap.CANARY] + rounds.require(len(cases) == 1 and receipt.get("case_id") == bootstrap.CANARY + and receipt.get("occurrence_id") == cases[0]["occurrence_id"] + and receipt.get("cohort_id") == bootstrap.COHORT_ID + and receipt.get("profile") == "edgemech-calibration-preparation/v1", + "Bootstrap receipt identity differs") + rounds.require(receipt.get("configuration") == bootstrap.configuration(root), + "Retained bootstrap configuration differs; new preparation required") + rounds.require(receipt.get("scientific_status") == "unassessed" + and receipt.get("kg_admissions") == 0 + and receipt.get("native_capability_enabled") is False + and receipt.get("canary_receipt") is None, "Invalid bootstrap capability") + rounds.require(set(receipt["artifacts"]) == BOOTSTRAP_NAMES, + "Bootstrap artifact inventory differs") + complete = copy.deepcopy(manifest) + pins = {item["path"]: item for item in complete["files"]} + rounds.require(len(pins) == len(complete["files"]), "Repeated source manifest path") + for name, pin in receipt["artifacts"].items(): + path = str(BOOTSTRAP_ROOT / name) + rounds.require(pin.get("path") == path and path in pins + and pin.get("sha256") == pins[path]["sha256"], + "Bootstrap artifact differs from retained manifest") + rounds.require(rounds.digest(rounds.safe(source_root, path).read_bytes()) == pin["sha256"], + "Retained bootstrap artifact changed") + pins[path]["required_mode"] = "0600" + if BOOTSTRAP_RECEIPT in pins: + rounds.require(pins[BOOTSTRAP_RECEIPT]["sha256"] == receipt_sha, + "Bootstrap receipt differs from retained manifest") + pins[BOOTSTRAP_RECEIPT]["required_mode"] = "0600" + else: + complete["files"].append({"path": BOOTSTRAP_RECEIPT, "sha256": receipt_sha, + "role": "bootstrap_receipt", "visibility": "coordinator_only", + "required_mode": "0600"}) + public_path, public_sha = bootstrap.PUBLIC["fresh"] + rounds.require(rounds.digest(rounds.safe(source_root, public_path).read_bytes()) == public_sha + and rounds.digest(rounds.safe(root, public_path).read_bytes()) == public_sha, + "Bootstrap public occurrence projection changed") + if public_path in pins: + rounds.require(pins[public_path]["sha256"] == public_sha, + "Bootstrap public projection differs from retained manifest") + else: + complete["files"].append({"path": public_path, "sha256": public_sha, + "role": "bootstrap_public_projection", + "visibility": "coordinator_only"}) + return complete + + +def plan(root, source_root, manifest_path, manifest_sha, spec_path, spec_sha, output, + *, bootstrap_receipt_sha256=None): rounds.require(root.resolve() != source_root.resolve(), "Use a fresh destination clone") rounds.require(Path(output).parts and Path(output).parts[0] == ".temp" and len(Path(output).parts) > 1, "Output must be a private .temp directory") @@ -48,6 +105,9 @@ def plan(root, source_root, manifest_path, manifest_sha, spec_path, spec_sha, ou ["git", "-C", str(root), "remote", "get-url", "origin"], text=True).strip() rounds.require(origin == "https://github.com/CultureBotAI/EdgeMech.git", "Noncanonical origin") manifest = checked_document(source_root, manifest_path, manifest_sha) + if bootstrap_receipt_sha256 is not None: + manifest = complete_bootstrap_manifest(root, source_root, manifest, + bootstrap_receipt_sha256) spec = checked_document(source_root, spec_path, spec_sha) rounds.require(spec["review"].get("scientific_review") is False and spec["review"]["verdict"] == "not_assessed", "Scientific fixture forbidden") @@ -77,7 +137,9 @@ def plan(root, source_root, manifest_path, manifest_sha, spec_path, spec_sha, ou target = rounds.safe(root, path, exists=False) rounds.require(not target.exists(), f"Evidence destination already exists: {path}") actions.append({"path": path, "action": "copy_exact_retained_input", - "sha256": pin["sha256"]}) + "sha256": pin["sha256"], + **({"required_mode": pin["required_mode"]} + if "required_mode" in pin else {})}) return manifest, spec, tracked, actions @@ -103,18 +165,52 @@ def verify_transition(root, ledger): text=True).strip(), "Tracked runtime changed during staging") rounds.require(worker.execution_inventory(root) == ledger["execution_inventory"], "Execution inventory changed during staging") + if "bootstrap" in ledger: + directory = rounds.safe(root, ledger["bootstrap"]["case_directory"], exists=False) + rounds.require(directory.is_dir() and stat.S_IMODE(directory.stat().st_mode) + == int(ledger["bootstrap"]["directory_mode"], 8), + "Bootstrap directory mode changed") for item in [*ledger["actions"], *ledger["prerequisite_documents"]]: if item.get("action") == "omit_historical_instructions": continue rounds.require(rounds.digest(rounds.safe(root, item["path"]).read_bytes()) == item["sha256"], f"Planned input changed during staging: {item['path']}") + if "required_mode" in item: + rounds.require(stat.S_IMODE((root / item["path"]).stat().st_mode) + == int(item["required_mode"], 8), "Bootstrap file mode changed") + + +def copy_retained(root, source, pin): + raw = rounds.safe(source, pin["path"]).read_bytes() + rounds.require(rounds.digest(raw) == pin["sha256"], "Source changed after plan") + rounds.write(root, pin["path"], raw=raw) + if "required_mode" in pin: + path = rounds.safe(root, pin["path"]) + path.chmod(int(pin["required_mode"], 8)) + rounds.require(path.read_bytes() == raw, "Bootstrap bytes changed during mode setup") + + +def check_bootstrap(root): + """The same free maintained checker used by the actual durable worker launcher.""" + directory = root / BOOTSTRAP_ROOT + rounds.require(stat.S_IMODE(directory.stat().st_mode) == 0o700, + "Bootstrap directory must remain mode 0700") + command = [sys.executable, "-B", str(root / "scripts/adhoc/prepare_calibration_20261115.py"), + "--check", bootstrap.CANARY] + record, receipt = worker.production_validator("bootstrap-preparation-check", command, + root, worker.child_environment(root)) + rounds.require(receipt == rounds.read(root, BOOTSTRAP_RECEIPT), + "Bootstrap checker returned another receipt") + return record def prepare(args): root, source = args.root.resolve(), args.source_root.resolve() metadata_preflight(root, args) + rounds.text(args.bootstrap_receipt_sha256, "bootstrap receipt SHA256") manifest, spec, tracked, actions = plan(root, source, args.source_manifest, - args.source_sha256, args.operational_spec, args.spec_sha256, args.output) + args.source_sha256, args.operational_spec, args.spec_sha256, args.output, + bootstrap_receipt_sha256=args.bootstrap_receipt_sha256) ledger = {"schema": SCHEMA, "package_purpose": "engineering_prerequisites", "scientific_authorization": False, "source_manifest": { "path": args.source_manifest, "sha256": args.source_sha256}, @@ -125,6 +221,12 @@ def prepare(args): "prerequisite_documents": [{"path": path, "sha256": rounds.digest( rounds.safe(root, path).read_bytes())} for path in args.prerequisite_document], "actions": actions, + "bootstrap": {"receipt_path": BOOTSTRAP_RECEIPT, + "receipt_sha256": args.bootstrap_receipt_sha256, + "case_directory": str(BOOTSTRAP_ROOT), "directory_mode": "0700", + "artifact_mode": "0600", "archive_root": str(bootstrap.ARCHIVE), + "private_upstream_inputs": rounds.read( + source, BOOTSTRAP_RECEIPT)["private_upstream_inputs"]}, "scope": "Complete retained byte bindings; unresolved scientific witnesses remain missing."} if args.plan: return {"status": "plan_only", "files": len(actions), "cases": len(manifest["cases"]), @@ -136,9 +238,7 @@ def prepare(args): continue if action["action"] == "copy_exact_retained_input": # Check again immediately before persistence; never accept a changed source. - raw = rounds.safe(source, pin["path"]).read_bytes() - rounds.require(rounds.digest(raw) == pin["sha256"], "Source changed after plan") - rounds.write(root, pin["path"], raw=raw) + copy_retained(root, source, pin) if pin["path"] not in FIXED: files[pin["path"]] = {k: v for k, v in pin.items() if k != "sha256"} # Freeze every maintained execution input, including newly added helpers. @@ -178,6 +278,7 @@ def prepare(args): "files": list(files.values()), "cases": cases} rounds.write(root, config_path, config) verify_transition(root, ledger) + bootstrap_check = check_bootstrap(root) frozen = rounds.freeze(root, config_path, target_manifest) verified = rounds.verify(root, target_manifest) verify_transition(root, ledger) @@ -185,6 +286,7 @@ def prepare(args): verify_transition(root, ledger) result = {"schema": SCHEMA, "status": "prepared", "manifest": frozen, "verification": verified, "operational": authored, + "bootstrap_check": bootstrap_check, "scientific_authorization": False} rounds.write(root, str(prefix / "preparation-receipt.json"), result) return result @@ -198,6 +300,8 @@ def main(): parser.add_argument("--source-sha256", required=True) parser.add_argument("--operational-spec", required=True) parser.add_argument("--spec-sha256", required=True) + parser.add_argument("--bootstrap-receipt-sha256", required=True, + help="Exact original fresh-47 preparation receipt SHA256") parser.add_argument("--output", required=True) parser.add_argument("--package-id", required=True) parser.add_argument("--review-id", required=True) diff --git a/tests/test_m5_prerequisite_package.py b/tests/test_m5_prerequisite_package.py index d2e7f2a..29a04e3 100644 --- a/tests/test_m5_prerequisite_package.py +++ b/tests/test_m5_prerequisite_package.py @@ -2,11 +2,15 @@ from __future__ import annotations import json +import shutil +import stat +import subprocess import sys from pathlib import Path from types import SimpleNamespace import pytest +from test_calibration_preparation import preparation as preparation sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts" / "adhoc")) import prepare_m5_prerequisite_package_20261117 as package # noqa: E402 @@ -157,3 +161,100 @@ def test_scientific_fixture_cannot_be_recycled_as_operational(staging, mutation) fixture["assessments"][0] = {"category": "SUPPORTED_AS_STATED"} with pytest.raises(ValueError, match="Scientific fixture|remain unresolved"): invoke() + + +@pytest.fixture +def retained_bootstrap(preparation, tmp_path, monkeypatch): + maintained, source, archive = preparation + receipt = maintained.prepare(source, archive, maintained.CANARY) + root = tmp_path / "new-reviewer" + root.mkdir() + subprocess.run(["git", "init", "-q", str(root)], check=True) + for path in [".gitignore", *maintained.CODE_PATHS, str(maintained.PROTOCOL), + str(maintained.COHORT), *[item[0] for item in maintained.PUBLIC.values()]]: + target = root / path + target.parent.mkdir(parents=True, exist_ok=True) + shutil.copyfile(source / path, target) + manifest = {"cases": [{"case_id": maintained.CANARY, + "occurrence_id": receipt["occurrence_id"]}], + "files": [{**pin, "role": "original_input"} + for pin in receipt["artifacts"].values()]} + receipt_sha = maintained.digest((source / package.BOOTSTRAP_RECEIPT).read_bytes()) + monkeypatch.setattr(package, "bootstrap", maintained) + return maintained, root, source, archive, manifest, receipt_sha + + +def test_212_complete_bootstrap_replays_real_checker_and_keeps_original_bytes(retained_bootstrap): + maintained, root, source, archive, manifest, receipt_sha = retained_bootstrap + complete = package.complete_bootstrap_manifest(root, source, manifest, receipt_sha) + assert len(complete["files"]) == 5 and len(manifest["files"]) == 3 + quartet = [pin for pin in complete["files"] if "required_mode" in pin] + assert len(quartet) == 4 and {pin["required_mode"] for pin in quartet} == {"0600"} + public = next(pin for pin in complete["files"] if pin["role"] == "bootstrap_public_projection") + assert public["sha256"] == maintained.PUBLIC["fresh"][1] + for pin in quartet: + package.copy_retained(root, source, pin) + assert (root / pin["path"]).read_bytes() == (source / pin["path"]).read_bytes() + assert stat.S_IMODE((root / pin["path"]).stat().st_mode) == 0o600 + actual = maintained.check_case(root, archive, maintained.CANARY) + assert actual == json.loads((source / package.BOOTSTRAP_RECEIPT).read_bytes()) + assert actual["scientific_status"] == "unassessed" + assert actual["kg_admissions"] == 0 + assert stat.S_IMODE((root / package.BOOTSTRAP_ROOT).stat().st_mode) == 0o700 + + +def test_212_old_incomplete_staging_and_0400_modes_fail_real_checker(retained_bootstrap): + maintained, root, source, archive, manifest, receipt_sha = retained_bootstrap + for pin in manifest["files"]: + package.rounds.write(root, pin["path"], raw=(source / pin["path"]).read_bytes()) + with pytest.raises(Exception, match="missing artifact"): + maintained.check_case(root, archive, maintained.CANARY) + package.rounds.write(root, package.BOOTSTRAP_RECEIPT, + raw=(source / package.BOOTSTRAP_RECEIPT).read_bytes()) + with pytest.raises(ValueError, match="Private artifact permissions differ"): + maintained.check_case(root, archive, maintained.CANARY) + + +@pytest.mark.parametrize("fault", ["receipt_hash", "configuration", "artifact", "public_projection"]) +def test_212_bootstrap_binding_drift_fails_before_copy(retained_bootstrap, fault): + maintained, root, source, archive, manifest, receipt_sha = retained_bootstrap + if fault == "receipt_hash": + receipt_sha = "0" * 64 + elif fault == "configuration": + with (root / maintained.CODE_PATHS[0]).open("a") as stream: + stream.write("\n# another runtime\n") + elif fault == "artifact": + manifest["files"][0]["sha256"] = "0" * 64 + else: + (root / maintained.PUBLIC["fresh"][0]).write_text("different public projection") + with pytest.raises(ValueError, + match="Source hash changed|configuration differs|artifact differs|projection"): + package.complete_bootstrap_manifest(root, source, manifest, receipt_sha) + assert not (root / ".temp").exists() + + +def test_212_free_bootstrap_gate_invokes_actual_checker_with_clone_python( + retained_bootstrap, monkeypatch): + maintained, root, source, archive, manifest, receipt_sha = retained_bootstrap + complete = package.complete_bootstrap_manifest(root, source, manifest, receipt_sha) + for pin in complete["files"]: + if "required_mode" not in pin: + continue + package.copy_retained(root, source, pin) + commands = [] + + def validator(name, command, actual_root, environment): + commands.append(command) + assert name == "bootstrap-preparation-check" and actual_root == root + return {"exit_code": 0, "command": command}, maintained.check_case( + root, archive, maintained.CANARY) + + monkeypatch.setattr(package.worker, "production_validator", validator) + result = package.check_bootstrap(root) + assert result["exit_code"] == 0 + assert commands == [[sys.executable, "-B", + str(root / "scripts/adhoc/prepare_calibration_20261115.py"), + "--check", "fresh-47"]] + (root / package.BOOTSTRAP_ROOT / "packet.json").chmod(0o400) + with pytest.raises(ValueError, match="Private artifact permissions differ"): + package.check_bootstrap(root) From 27be00ddc57688b3e9edbca60175a84aba91961c Mon Sep 17 00:00:00 2001 From: "marcin p. joachimiak" <4625870+realmarcin@users.noreply.github.com> Date: Tue, 17 Nov 2026 20:26:33 -0800 Subject: [PATCH 3/3] Record independently verified M5 prerequisite canaries and remaining gates --- NEXT_TASKS.md | 6 +- .../m5-prerequisites-live-20261117.md | 66 +++++++++++++------ 2 files changed, 48 insertions(+), 24 deletions(-) diff --git a/NEXT_TASKS.md b/NEXT_TASKS.md index feb454a..af52cd2 100644 --- a/NEXT_TASKS.md +++ b/NEXT_TASKS.md @@ -1,6 +1,6 @@ # Edge-review next tasks -**Prerequisite repair in progress, 2026-11-17, [PR #211](https://github.com/CultureBotAI/EdgeMech/pull/211):** #203 binds future scientific instructions, package purpose, navigation and fresh session roots; #205 clarifies direct semantic comparison versus trace-dependent source fidelity; #206 makes canonical clone/environment provisioning reproducible. Both retained round03 environments pass actual readback. The first fresh M5 clone passed setup and 378 package bindings, but its native canary found missing bootstrap receipt/mode requirements (#212); that failed attempt is preserved and a repaired runtime must pass a fresh canary before the second clone starts. #207/#208 staging guards and #210 bounded definition retention passed independent re-review. Adjudication fails closed pending typed initial-result bindings (#209). These engineering checks do not start another calibration or resolve the missing original scientific witnesses. +**Prerequisite repairs verified on M5, 2026-11-17; unmerged [PR #211](https://github.com/CultureBotAI/EdgeMech/pull/211):** two fresh environments at `3057bb2` passed actual native canaries, canonical save/readback and 380 frozen input bindings each; [live results](docs/validation/m5-prerequisites-live-20261117.md) retain the first failed attempt and #212 bootstrap repair. The corrected first clone passed before the second was provisioned. Exact-runtime CI passes 1,352 tests, 16 contracts, Ruff and builds. #203 binds future instructions/package/session paths; #205 clarifies fidelity proof dependencies; #206 makes setup reproducible; #207/#208 prevent unsafe staging/drift; #210 preserves substantive definition text with bounded omissions. No scientific round started. Next: recover missing original source/identity/definition witnesses using the ten-case map, beginning with bounded MetaTraits mapping/polarity replay, and finish typed adjudication inputs (#209). Retained-90/9,900 stay closed; old rounds and failed attempts remain unchanged. **Round03 finalized failed, 2026-11-16:** [Round03 results](docs/validation/m5-calibration-round03-results-20261116.md) preserve two fresh sealed matrices and separate adjudication. Initial agreement is 54/60, but source-fidelity agreement 7/10 and final resolution 3/10 fail their unchanged 8/10 floors. Six initial claim/model judgments and three supplemental source-fidelity judgments are unsupported; four disagreements remain unresolved, including one blocking model judgment. Mechanical finalization passes 20/20 canonical pairs, 153/153 selected initial proofs and 55/55 final citation rows, with 59 final local proofs separately validated. Eleven rejected authoring attempts remain preserved. A missed historical producer clause independently fails blinding (#200); the earlier blanket preparation audit is corrected. All scientific workers exited with ending bindings intact. Remaining90/9900 remain closed. The next scientific step requires missing original source/identity/definition witnesses and a separately identified round with unchanged thresholds. @@ -12,7 +12,7 @@ The earlier #152 operational save/check canary passed and remains excluded from **Completed round01, 2026-11-16, [PR #150](https://github.com/CultureBotAI/EdgeMech/pull/150):** [Round01 failed after execution and separate adjudication](docs/validation/m5-calibration-20261116.md). Two fresh same-model sessions sealed 10-by-6 matrices; initial agreement 56/60, but object-node agreement 7/10 fails the required 8. Independent audit found eight unsupported initial modeling labels, source-fidelity resolution 7/10 and two blocking disagreements. All 18 available canonical pairs replayed, but both fresh-05 saves failed; all saved reviews remain partial. Original matrices and failed saves remain unchanged. Issues #152–#157 track acceptance semantics, predicate reasoning, METPO hierarchy, local definitions, fidelity/exposure and aggregate quotation budgets; #145 tracks fresh-04 identity. Helper findings #144/#148/#149/#158/#159 are repaired. Final checks: 830 tests, full Ruff scope, contracts and package builds passed. [Round02 registration and revised rubric](docs/plans/m5-calibration-round02-20261116.md) preserve every original threshold. Remaining-90 and 9,900 gates stay closed. Both original M5 workers have exited; the release worker delivered the source-only candidate referenced above. Current follow-up execution is reported separately in the round02 entry. -Last reconciled: **2026-11-17** (America/Los_Angeles), against `main` at `f841b1dff874e78d1a14075413be6a92c90f1378`, merged PRs #135/#131/#128/#120 and open PRs #190/#167/#151/#150/#136/#102/#37. Shared CLAW PR #1289 remains open at `4fad8df`. PR #131 is merged and #127 is closed. #130's bounded source quarantine has been independently verified against regenerated producer bytes and merged in [KG-Microbe PR #1867](https://github.com/Knowledge-Graph-Hub/kg-microbe/pull/1867); graph-release verification remains pending. Independent scientific calibration has not passed. +Last reconciled: **2026-11-17** (America/Los_Angeles), against `main` at `f841b1dff874e78d1a14075413be6a92c90f1378`, merged PRs #135/#131/#128/#120 and open PRs #211/#190/#167/#151/#150/#136/#102/#37. Shared CLAW PR #1289 remains open at `4fad8df`. PR #131 is merged and #127 is closed. #130's bounded source quarantine has been independently verified against regenerated producer bytes and merged in [KG-Microbe PR #1867](https://github.com/Knowledge-Graph-Hub/kg-microbe/pull/1867); graph-release verification remains pending. Independent scientific calibration has not passed. Scope: the stratified edge review and related edge-quality follow-ups. Update this file when work starts or ships, checking GitHub and current code before changing status. Record completion dates and PRs. Preserve historical manifests, packets, reports and scientific decisions; a merged engineering PR does not promote an edge's scientific status. Unrelated release/deployment work is outside this backlog. @@ -40,7 +40,7 @@ Evidence: [fresh-canary report](artifacts/edge-recanary-20261113/RECANARY-REPORT | 2 — **PENDING, actionable bounded audit** | Semantic identity, relation and node-category correctness | Prepare pinned authorities and audit the selected calibration cases, then the existing 100 after gates pass. Prioritize [#68](https://github.com/CultureBotAI/EdgeMech/issues/68)/[#106](https://github.com/CultureBotAI/EdgeMech/issues/106) identity joins and [#75](https://github.com/CultureBotAI/EdgeMech/issues/75)/[#86](https://github.com/CultureBotAI/EdgeMech/issues/86)/[#87](https://github.com/CultureBotAI/EdgeMech/issues/87) relation/type-strain/bin semantics. Review nonempty categories, not only missing fields. All 22 fresh-canary biological-literature exclusions still receive identity/modeling review. | | 3 — **PENDING, actionable retained-evidence work** | DOI identity, exact snippets and categorical claim judgments | Resolve publication identity [#69](https://github.com/CultureBotAI/EdgeMech/issues/69); replay retained evidence for the selected calibration cases first, then retrieve missing relevant text through appropriate channels. Verify literal quotes and independently judge entailment, conditions and organism/strain scope. Record support, refutation, conflicts, insufficient evidence and assessment blockers distinctly. | | Parallel — **IN PROGRESS** | General full-text credential protection: [#100](https://github.com/CultureBotAI/EdgeMech/issues/100), [PR #102](https://github.com/CultureBotAI/EdgeMech/pull/102) | The draft has a clean independent review and green CI at `2364161819951b7899ba62cebcd461bf0394c4a7`. Reconcile with current main and validate before a separately authorized merge. Complete this before further authenticated general-helper retrieval; it need not block local modeling or retained-evidence review. | -| 4 — **ROUND03 FAILED; prerequisite repair in progress** | Recover original witnesses and repair prerequisites before a separate round | Round03 achieved 20 canonical pairs, but source-fidelity agreement 7/10, resolution 3/10, unsupported initial labels and blinding fail the unchanged gates. PR #211 repairs setup/invocation/fidelity guidance and future definition visibility; its first fresh native canary exposed bootstrap staging #212. Recover the exact source selection/identity/field-meaning witnesses in the ten-case map, complete typed adjudication bindings #209, then separately freeze a scientifically reviewed package and rerun real same-clone readiness. All historical failures stay intact. Retained-90 and 9,900 remain closed. | +| 4 — **ROUND03 FAILED; engineering prerequisites verified in unmerged PR #211** | Recover original witnesses before a separate round | Round03 achieved 20 canonical pairs, but source-fidelity agreement 7/10, resolution 3/10, unsupported initial labels and blinding fail the unchanged gates. PR #211's repaired runtime passes two actual same-clone canaries/save/readback checks after preserving the initial #212 failure. Next recover source selection/identity/field-meaning witnesses in the ten-case map and complete typed adjudication inputs #209; then freeze a new scientifically reviewed package and run its own readiness checks. All historical failures stay intact. Retained-90 and 9,900 remain closed. | | 5 — **PENDING; upstream fixes/releases where needed** | Correct and verify affected assertions and nodes | File each finding, identify its maintained owner, retain before/after proposals, add regressions, regenerate a new candidate and independently re-assess affected occurrences. Include [#56](https://github.com/CultureBotAI/EdgeMech/issues/56), [#70](https://github.com/CultureBotAI/EdgeMech/issues/70), [#72](https://github.com/CultureBotAI/EdgeMech/issues/72) and proof of existing fixes [#71](https://github.com/CultureBotAI/EdgeMech/issues/71)/[#73](https://github.com/CultureBotAI/EdgeMech/issues/73). A merged source PR is distinct from a verified corrected graph release. | **Completed initial execution, 2026-11-16:** M5 main was synchronized to `f841b1d` for the original [execution plan](docs/plans/m5-review-execution-20261116.md). The original calibration and BactoTraits verification workers ran and exited. Round01 failed; the BactoTraits-only candidate passed its bounded verification, while full canonical release/publication remains outstanding. Round02 subsequently failed initial agreement, final source-fidelity resolution and evidence integrity after separate adjudication; both initial reviewer jobs exited. Preserve sampled/current authority distinctions, all original thresholds and both rounds' immutable failures. Retained-90 and 9,900 review remain gated; neither operational startup nor source-only candidate verification establishes scientific calibration or full-release completion. This reconciliation retains #165's historical execution context. diff --git a/docs/validation/m5-prerequisites-live-20261117.md b/docs/validation/m5-prerequisites-live-20261117.md index 52279eb..ed4ae81 100644 --- a/docs/validation/m5-prerequisites-live-20261117.md +++ b/docs/validation/m5-prerequisites-live-20261117.md @@ -1,17 +1,20 @@ # M5 prerequisite verification — 2026-11-17 This record covers engineering checks for [PR #211](https://github.com/CultureBotAI/EdgeMech/pull/211). -The frozen executable runtime is `2f99a16e7752d2dbe31471781b31ceb5aa90c8a0`, -stacked on round03 delivery `d0ed406`. No new scientific calibration has started. +The repaired executable runtime is `3057bb2bae6c38ba8b588659da023a42a3bfe6b9`, +stacked on round03 delivery `d0ed406`. The first attempted runtime `2f99a16` +and its live failure remain preserved. No new scientific calibration has started. The failed round03 result, original packages, seals, reviews and clones remain unchanged. The new checks do not review the retained 90 or expand to 9,900. ## Code and independent review -[Exact-runtime CI](https://github.com/CultureBotAI/EdgeMech/actions/runs/44234472702) -passed all **1,345 tests**, all 16 pinned CLAW contract payloads, full Ruff scope, +[Exact repaired-runtime CI](https://github.com/CultureBotAI/EdgeMech/actions/runs/44235602842) +passed all **1,352 tests**, all 16 pinned CLAW contract payloads, full Ruff scope, and source/wheel builds. The shared dependency remains the reviewed, unmerged CLAW candidate `4fad8df5b2367da68faca6379ce32eb9b8f4ba9b`. +The initial candidate separately passed 1,345 local/CI tests; the real canary +then found #212. Its repair passed 22 focused tests before the full CI run. Separate read-only reviews covered the clone/environment setup, package staging, invocation/launcher integration and actual fresh-32 definition bytes. Findings @@ -23,26 +26,42 @@ distinguishes fixes from the intentionally unsupported adjudication phase. Fresh clone roots are beneath `/Users/marcin/agent-work/EdgeMech/m5-prerequisite-reviewers-20261117`. -Both are intended to use the same exact runtime and canonical GitHub origin; -results below are recorded only after their artifacts are checked. +Both use the same exact runtime and canonical GitHub origin. Their artifacts +were checked on disk, and production readback was repeated using each clone's +own interpreter after its worker finished. -| Binding | reviewer-a | reviewer-b | +| Binding | reviewer-a-retry-01 | reviewer-b | | --- | --- | --- | -| Setup | Passed six real provisioning steps | Pending | -| Interpreter | Clone-local `.venv`, Python 3.14.7 | Pending | -| Provisioning receipt SHA256 | `8c6a9bdbfc4e1aef0fe3af5eb1b96483a88a20ca7c2b62ed955f0594debec4ab` | Pending | -| New engineering manifest SHA256 | `e3536cb66bb01badd2360228e7c99ae59034c4ec0c674c21a59cda5d19980964` | Pending | -| Verified input bindings / original packets | 378 / 10 | Pending | -| Real native worker and production save/readback | Failed bootstrap; no save attempted | Not started | +| Setup | Passed six real provisioning steps | Passed six real provisioning steps | +| Interpreter | Clone-local `.venv`, Python 3.14.7 | Separate clone-local `.venv`, Python 3.14.7 | +| Provisioning receipt SHA256 | `043c88b6406795a9a7b1b925cb2df6d5fd56f77d65dcff10b74d18267a790c33` | `0637f9dfbd1ef6ee651ac83fd7d1a1731aafb2abca763bb035af9a4e047b5ef2` | +| New engineering manifest SHA256 | `336136476ea5fe68f6f3bde715031360bf59840ab992f9600d6501e4c27ac6ed` | `8e1c5ac5bfd08ebcaaa5072ed4275c5a03d1c4ccbeb14f4835beeb25504c6afa` | +| Verified input bindings / original packets | 380 / 10 | 380 / 10 | +| Real bootstrap checker / required modes | Passed / 0700 directory, four 0600 files | Passed / same required modes | +| Real native worker and production save/readback | Passed, exit 0 | Passed, exit 0 | +| Worker completion, UTC | `2026-11-18T04:17:57Z` | `2026-11-18T04:22:20Z` | +| Production receipt SHA256 | `58025aa5fc9ea8e47a84587c61579eee551efc1d5a7741cb946ce4862e325873` | `3b47ad8114f75ae792cf66438a6167d12053a22bfe9c79f54f36038aba59077c` | +| Canonical YAML SHA256 | `3270bdfbcd3c9a273ab29d39a6a1e5372304c04711116d5dbdc5cb53fc96666f` | `40fc541bda56e960ce154c2bb96bcbd8db90f4b432e2ee9240470e3ecb8f7496` | +| Canonical Markdown SHA256 | `fc59826ed03f5a13310f7d75b60e05f171ad0de3e947e0fb4cd93e2b0be80597` | `3905236e4209616a2f3020e0264e2f744d8078a3179b373a3a3d1f7a4ae86b61` | -Reviewer-a's preparation receipt is -`0a3092569231c22b05fd2534a153d702b812a47c0ef07513bfd642bd4680b859`. -It records a validated conservative draft, with no canonical save yet claimed. -The actual scientific-invocation CLI rejected this engineering manifest before +Reviewer-a-retry-01's preparation receipt is +`65c2e9e172716c3d71a37eb7d6c0a630387fc0353823d7c563f68012142e26be`. +Reviewer-b's preparation receipt is +`a68754a81fd868a537b14d18b35137f57f6b2119b6264ddd84dd328a34d1cd3d`. +These preparation receipts record validated conservative drafts; the distinct +production receipts above prove the subsequent saves. The canonical review IDs +are `20261118T041135Z-prerequisite-a-retry01-fresh47` and +`20261118T041822Z-prerequisite-b-fresh47`, each beneath its own clone's +`reviews/structured/`. Actual readback returns one verified context witness, +zero quotations, all six unresolved categories, zero graph admissions and +`native_capability_enabled: false` for each pair. +The actual scientific-invocation CLI rejected the first engineering manifest before writing any invocation, with the expected engineering-purpose error. The separate same-clone production launch plan passed before real execution. -The first live canary failed before production save under #212. Its package had +The first live canary in `reviewer-a` at runtime `2f99a16` failed before production +save under #212. Its manifest `e3536cb66bb01badd2360228e7c99ae59034c4ec0c674c21a59cda5d19980964` +verified 378 declared inputs. Its package had complete declared bindings but omitted the bootstrap receipt outside that manifest; the copied seed files also had mode 0400 where the maintained bootstrap checker requires 0600. The child correctly reported failure, and the parent @@ -50,14 +69,19 @@ rejected it despite child exit code 0. The failure result SHA256 is `8364a86fb72b75e23a3a2b6c95b0733f0fbcd42ffba1649d549b763b15a4b4c9`. It finished at `2026-11-18T04:07:36Z`; the failed clone and all logs remain intact. Direct path checks found neither a canonical review directory nor a passing -canary receipt, and tracked runtime files stayed clean. A repaired runtime must -pass a new clone canary before the second environment is provisioned. +canary receipt, and tracked runtime files stayed clean. The repaired first +canary passed at `04:17:57.089357Z`, before reviewer-b provisioning began at +`04:18:53.405253Z`. No failed output or receipt was overwritten. The maintained provisioner and package/worker CLIs were used throughout. Exactly -one clone is checked end to end before another is provisioned. The native worker +one repaired clone was checked end to end before the second was provisioned. The native worker uses configured defaults without a model override or a new credential copy. The parent executes the production save/check and compares authored content and on-disk YAML/Markdown hashes; worker prose is not the acceptance criterion. +Separate read-only audits of both actual environments confirmed the runtime, +380 bindings, installed contracts, modes, canonical pairs and exclusion from +scientific scoring. Both workers exited successfully; this task launched no +scientific worker or expansion job. ## Scientific boundary