From 51e683c98e03a3a0a5206caa4889675145f26c51 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 12 Jul 2026 08:33:10 +0100 Subject: [PATCH] Make repo closure retries immutable --- epiphany-core/src/bin/epiphany-work.rs | 49 ++++++++++++++++++--- epiphany-core/src/runtime_spine.rs | 39 ++++++++++++++++ notes/epiphany-current-algorithmic-map.md | 6 +++ notes/epiphany-fork-implementation-plan.md | 4 +- notes/fresh-workspace-handoff.md | 9 ++++ state/ledgers.msgpack | Bin 418514 -> 419009 bytes state/map.yaml | 2 +- 7 files changed, 101 insertions(+), 8 deletions(-) diff --git a/epiphany-core/src/bin/epiphany-work.rs b/epiphany-core/src/bin/epiphany-work.rs index 2674d850..6470b137 100644 --- a/epiphany-core/src/bin/epiphany-work.rs +++ b/epiphany-core/src/bin/epiphany-work.rs @@ -11366,7 +11366,7 @@ fn run_close(args: CloseArgs) -> Result { normalize_path_for_receipt(&closure_review_path), ]; evidence_ids.extend(declared_changed_paths.clone()); - let soul_verdict = SoulVerdictReceipt { + let mut soul_verdict = SoulVerdictReceipt { schema_version: SOUL_VERDICT_RECEIPT_SCHEMA_VERSION.to_string(), receipt_id: soul_verdict_id.clone(), source_result_id: format!("repo-work-execute-{item_slug}"), @@ -11411,7 +11411,19 @@ fn run_close(args: CloseArgs) -> Result { emitted_at: now.clone(), contract: "Soul verdict for repo-work closure; verifies the Hands patch/command/commit consequence before Modeling/Mind closure and Bifrost publication.".to_string(), }; - put_soul_verdict_receipt(&runtime_store, &soul_verdict)?; + if let Some(existing) = + epiphany_core::runtime_soul_verdict_receipt(&runtime_store, &soul_verdict.receipt_id)? + { + soul_verdict.emitted_at = existing.emitted_at.clone(); + if soul_verdict != existing { + return Err(anyhow!( + "closure retry conflicts with immutable Soul verdict receipt" + )); + } + soul_verdict = existing; + } else { + put_soul_verdict_receipt(&runtime_store, &soul_verdict)?; + } let closure_receipt_path = artifact_dir.join(format!("work-close-{item_slug}.json")); if !verification_passed { @@ -11464,7 +11476,7 @@ fn run_close(args: CloseArgs) -> Result { ) }); let modeling_finding_receipt_id = format!("repo-work-close-{item_slug}-modeling-finding"); - let modeling_finding = RepoWorkModelingFinding { + let mut modeling_finding = RepoWorkModelingFinding { schema_version: REPO_WORK_MODELING_FINDING_SCHEMA_VERSION.to_string(), receipt_id: modeling_finding_receipt_id.clone(), item: item.clone(), @@ -11488,10 +11500,22 @@ fn run_close(args: CloseArgs) -> Result { private_state_exposed: false, contract: "Modeling interpretation of Soul-verified repo consequence; Mind must reread this typed receipt before map admission.".to_string(), }; - put_repo_work_modeling_finding(&runtime_store, &modeling_finding)?; - let modeling_finding = + if let Some(existing) = runtime_repo_work_modeling_finding(&runtime_store, &modeling_finding_receipt_id)? - .ok_or_else(|| anyhow!("persisted Modeling finding could not be reread"))?; + { + modeling_finding.emitted_at = existing.emitted_at.clone(); + if modeling_finding != existing { + return Err(anyhow!( + "closure retry conflicts with immutable Modeling finding" + )); + } + modeling_finding = existing; + } else { + put_repo_work_modeling_finding(&runtime_store, &modeling_finding)?; + modeling_finding = + runtime_repo_work_modeling_finding(&runtime_store, &modeling_finding_receipt_id)? + .ok_or_else(|| anyhow!("persisted Modeling finding could not be reread"))?; + } if modeling_finding.soul_verdict_receipt_id != soul_verdict.receipt_id || modeling_finding.commit_sha != commit_sha || modeling_finding.changed_paths != declared_changed_paths @@ -16234,6 +16258,9 @@ mod authority_tests { assert!(put_repo_work_modeling_finding(&store, &finding).is_err()); finding.private_state_exposed = false; put_repo_work_modeling_finding(&store, &finding)?; + let mut conflicting_finding = finding.clone(); + conflicting_finding.summary = "different meaning".to_string(); + assert!(put_repo_work_modeling_finding(&store, &conflicting_finding).is_err()); assert_eq!( runtime_repo_work_modeling_finding(&store, &finding.receipt_id)?, Some(finding.clone()) @@ -16287,6 +16314,16 @@ mod authority_tests { map.modeling_summary = finding.summary.clone(); commit_repo_work_map_admission(&store, &map, &review, &commit)?; + let admitted = runtime_repo_work_map_entry(&store, &map.map_entry_id)?.unwrap(); + assert_eq!(admitted, map); + let mut retry = map.clone(); + retry.admitted_at = "2026-07-12T00:10:00Z".to_string(); + assert_eq!( + commit_repo_work_map_admission(&store, &retry, &review, &commit)?, + admitted + ); + retry.safe_action_family = "repo.task_card".to_string(); + assert!(commit_repo_work_map_admission(&store, &retry, &review, &commit).is_err()); assert_eq!( runtime_repo_work_map_entry(&store, &map.map_entry_id)?, Some(map) diff --git a/epiphany-core/src/runtime_spine.rs b/epiphany-core/src/runtime_spine.rs index dd0e4c1c..325ab8bb 100644 --- a/epiphany-core/src/runtime_spine.rs +++ b/epiphany-core/src/runtime_spine.rs @@ -1714,6 +1714,14 @@ pub fn put_soul_verdict_receipt( let mut cache = runtime_spine_cache(store_path)?; cache.pull_all_backing_stores()?; require_identity(&cache)?; + if let Some(existing) = cache.get::(&receipt.receipt_id)? { + if existing == *receipt { + return Ok(()); + } + return Err(anyhow!( + "Soul verdict receipt id already belongs to different immutable evidence" + )); + } cache.put(&receipt.receipt_id, receipt)?; Ok(()) } @@ -1760,6 +1768,14 @@ pub fn put_repo_work_modeling_finding( "Modeling finding requires a passing Soul verdict receipt" )); } + if let Some(existing) = cache.get::(&finding.receipt_id)? { + if existing == *finding { + return Ok(()); + } + return Err(anyhow!( + "Modeling finding receipt id already belongs to different immutable evidence" + )); + } cache.put(&finding.receipt_id, finding)?; Ok(()) } @@ -1818,6 +1834,29 @@ pub fn commit_repo_work_map_admission( "repo-work map entry does not match its typed Modeling finding" )); } + if let Some(existing) = cache.get::(&entry.map_entry_id)? { + let mut candidate = entry.clone(); + candidate.admitted_at = existing.admitted_at.clone(); + if existing != candidate { + return Err(anyhow!( + "repo-work map entry id already belongs to different admitted state" + )); + } + let stored_review = cache + .get::(&existing.mind_gateway_review_id)? + .ok_or_else(|| anyhow!("admitted repo-work map is missing its Mind review"))?; + let stored_commit = cache + .get::(&existing.mind_state_commit_receipt_id)? + .ok_or_else(|| anyhow!("admitted repo-work map is missing its Mind commit"))?; + if stored_review.gateway_id != existing.mind_gateway_review_id + || stored_commit.gateway_id != stored_review.gateway_id + { + return Err(anyhow!( + "admitted repo-work map has incoherent Mind witnesses" + )); + } + return Ok(existing); + } let (review_envelope, _) = cache.prepare_entry(&mind_review.gateway_id, mind_review)?; let (commit_envelope, _) = cache.prepare_entry(&mind_commit.receipt_id, mind_commit)?; let (map_envelope, _) = cache.prepare_entry(&entry.map_entry_id, entry)?; diff --git a/notes/epiphany-current-algorithmic-map.md b/notes/epiphany-current-algorithmic-map.md index c4bf44fb..f20dfaaa 100644 --- a/notes/epiphany-current-algorithmic-map.md +++ b/notes/epiphany-current-algorithmic-map.md @@ -120,6 +120,12 @@ Mind commit in one prepared batch. The former bespoke `.epiphany/state/repo-work-map.msgpack` owner is deleted. CultMesh remains a projection after admission and cannot repair or override the canonical entry. +Closure phase documents are immutable by stable receipt ID. An identical retry +reuses the existing Soul verdict and Modeling finding, rereads an already +admitted Mind/map batch, and regenerates only operator/CultMesh projections. +Conflicting same-ID Soul, Modeling, or map cargo is refused; no reconciliation +loop may overwrite the earlier truth. + Manual edits and programmatic actions converge at the same receipt and Mind admission boundaries. A later action cannot retroactively make an unrecorded consequence valid. diff --git a/notes/epiphany-fork-implementation-plan.md b/notes/epiphany-fork-implementation-plan.md index 53e48dd4..5d2c1939 100644 --- a/notes/epiphany-fork-implementation-plan.md +++ b/notes/epiphany-fork-implementation-plan.md @@ -121,7 +121,9 @@ as a typed runtime document backed by a passing Soul receipt; Mind rereads it, and repo-map/CultMesh admission carries its receipt ID. Repo-map admission is now atomic: the typed canonical map entry and both Mind witnesses publish in one CultCache batch, while CultMesh lowers the committed entry. The custom map -MessagePack owner is deleted. +MessagePack owner is deleted. Stable phase IDs are immutable: identical retries +reread existing Soul, Modeling, and Mind/map documents, while conflicting retry +cargo fails without changing admitted state. - Prove Hands → Soul → Modeling → Mind → Self on a fresh repository without supervisor implementation or direct worker-thought inspection. diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 1f6ef362..2e4332c7 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -2030,6 +2030,15 @@ source test. CultMesh projects the reread canonical entry. Next inspect crash and retry semantics across the earlier Soul and Modeling phase receipts versus the final atomic Mind/map admission; do not add a repair loop to hide partial phase ownership. +Crash/retry semantics are now explicit. Soul verdicts and repo-work Modeling +findings are immutable by receipt ID. An identical closure retry reuses them; +the atomic Mind/map owner rereads an already-admitted matching entry instead of +republishing it. Conflicting same-ID evidence or map meaning is refused. Real +CLI replay with the rebuilt executable returned `closed` for identical cargo, +returned exit 1 for a conflicting Modeling reinterpretation, and left the +admitted map byte-for-byte equivalent at the operator projection. Next restore +autonomous movement by having Self launch/await a real Modeling result at +`await-modeling`; Self must not regain the ability to synthesize that finding. ## Immediate Re-entry Instruction diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index 4ce0da24140a50e2689ceb24081a462e06fba1fa..935955acf26990fa079bd2f90dc42286f3509fbb 100644 GIT binary patch delta 533 zcmYk3zityj5XLzJY3Qg(fix0r>^MF|P!LrrB;15lRE&4Wz6ty1vO5>!%0&uZAXd6O z0}=(ILMcF^>E?dzZ0pB_~Y>iS?@zx{D%%UpeaQk_=S z@AJ*z<7QB4l{lp)SCr85+c0o@4R#Lo5gX|&`xEFhz& zAzQG~be@8OLR9iKY}GoQ{)Kj?eyav&7~JDrL%0%rg%b!x~J~Yg@3X} jaNHzPKRRh*Vp)MuR@;g{Y8yW+(zbBCI(T*7}yfmZ&qe3WMq8QJe8?^Dib3RgJ@?Ngc9 GY!d)CQxZV{ diff --git a/state/map.yaml b/state/map.yaml index 803bdf6b..6ec005ac 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -659,4 +659,4 @@ current_status: - Service lifecycle receipt history is now event-only: `load_epiphany_cultmesh_daemon_service_lifecycle_receipts` filters out the `epiphany-local/daemon-service-lifecycle-receipt/latest` mirror, while `load_latest_epiphany_cultmesh_daemon_service_lifecycle_receipt` remains the latest-state reader. Focused unit test `service_lifecycle_receipt_history_excludes_latest_mirror` proves two per-receipt writes return exactly two history records and latest points at the second. Fresh smoke `verse-query-lifecycle-history-filter-smoke` and live overview/triage `local-20260618-145632-497-efac6f0d` / `local-20260618-145632-321-867947af` prove compact swarm sights still expose service lifecycle attention plus the present elevated runbook artifact without daemon pokes or service mutation. Do not use a broad unscoped cargo test filter for this check on Windows; it fans out across bin harnesses and hit a broken pipe during this pass. - `epiphany-verse-query seed-compact` is the compact seed receipt for wrappers and read-only rites. The older `seed` command still prints the full local Verse context for explicit debugging, but compact wrapper modes now avoid full `seed`/final `query` readback after the combined overview proof exposed Windows debug stack overflow from full-context serialization pressure. last_completed_repo_swarm_cut: Huginn live-fire has crossed the first real repo Body from Persona pressure to branch-local Hands commit and Soul/Mind closure, and now has repeatable closure and redacted-public-proof mouths. On `E:\Projects\Huginn` branch `epiphany/huginn/first-awakening`, `tools/epiphany_local_run.ps1 -Mode repo-persona-intake` accepted item `huginn-inspection-readback-livefire`, Weksa/Persona intake remained sealed, and `epiphany-work derive-plan` lowered it to model-authored safe family `repo.status_section` for `README.md` only. `tools/epiphany_local_run.ps1 -Mode repo-swarm-run` advanced four bounded pulses: run-from-plan, adopt-from-plan, execute-from-plan, and close-from-execute. Huginn commit `e9b07c38fceabbdc89ea35c2156326c80c0393a2` updated only `README.md`; closure receipt `.epiphany\work\work-close-huginn-inspection-readback-livefire.json` records status `closed`, Soul verdict `passed`, Mind state commit `repo-work-close-huginn-inspection-readback-livefire-mind-commit`, safe family `repo.status_section`, path scope `README.md`, Bifrost publication gate, and `privateStateExposed=false`. Verification also ran Huginn's TypeScript compiler through concrete Node path: `C:\Program Files\nodejs\node.exe E:\Projects\Huginn\node_modules\typescript\bin\tsc -p tsconfig.json` passed. Native verifier `epiphany-repo-livefire-closure-smoke --workspace E:\Projects\Huginn --item huginn-inspection-readback-livefire --expected-path README.md --expected-family repo.status_section --expected-gate awaiting-publication --expected-blocker bifrost-publication-missing` checks closure receipt, Mind map entry, overview gate/blocker, authority seals, and `git show` changed paths, returning `status=ok`, `soulVerdict=passed`, `publicationGate=Bifrost`, and `privateStateExposed=false`. Wrapper `tools/epiphany_local_run.ps1 -Mode repo-livefire-closure -Workspace E:\Projects\Huginn -RepoWorkItem huginn-inspection-readback-livefire -SkipBuild` exposes the same read-only proof through the local operator mouth; artifact `local-20260621-190156-803-2f85ba15` printed commit, path, gate, blocker, Soul verdict, Mind commit receipt, and `privateStateExposed=False` without push, merge, publication, or target mutation. New wrapper `tools/epiphany_local_run.ps1 -Mode repo-work-public-proof -Workspace E:\Projects\Huginn -RepoWorkItem huginn-inspection-readback-livefire -SkipBuild` exports the redacted proof bundle and repo-local Verse index without publishing; artifact `local-20260621-190645-345-4555b1dc` wrote `.epiphany\public\proof-bundles\repo-work-public-proof-huginn-inspection-readback-livefire.json`, proof id `repo-work-public-proof-huginn-inspection-readback-livefire`, SHA-256 `857545b199f3e37eb06c2e757e5cfc201958e46667bb1f8403fd333a22620f63`, nine artifact rows, zero publication rows, and `privateStateExposed=False`. Gjallar readback `local-20260621-190701-140-b9519ec6` sees the `REPO-WORK-PUBLIC-PROOF` row and action row from Huginn's repo-local Verse with the same SHA-256 while Bifrost publication remains missing. Launcher compact modes are now named compact operator-context modes instead of read-only modes, and `bifrost-public-proof` summaries print item, target public Verse, room, proof SHA-256, review receipts, and credit receipts so publication receipts are auditable without claiming upstream sync. - next_action: Audit the remaining repo-work closure orchestration boundary. Soul verdict and Modeling finding are persisted before the atomic Mind/map batch; determine whether closure needs one larger transaction or explicit recoverable phase receipts, then make crash/retry behavior idempotent without adding a reconciliation owner. + next_action: Restore autonomous progress at the new `await-modeling` boundary without giving Self Modeling authority. Route the repo-work scheduler through a typed Modeling launch/finding path over the Soul receipt, then let the existing immutable closure admission consume that result; prove Self cannot synthesize the finding and the loop reaches Bifrost gate on a fresh repo.