diff --git a/epiphany-codex-bridge/src/mutation_service.rs b/epiphany-codex-bridge/src/mutation_service.rs index 29809628..16c85aeb 100644 --- a/epiphany-codex-bridge/src/mutation_service.rs +++ b/epiphany-codex-bridge/src/mutation_service.rs @@ -25,7 +25,6 @@ use epiphany_core::EpiphanyStateUpdate; use epiphany_core::EpiphanyStateUpdatedField; use epiphany_core::EpiphanyTokenUsageSnapshot; use epiphany_core::MIND_GATEWAY_REVIEW_TYPE; -use epiphany_core::MindGatewayReview; use epiphany_core::RuntimeSpineHeartbeatJobOptions; use epiphany_core::RuntimeSpineHeartbeatLaunchPlanOptions; use epiphany_core::SOUL_VERDICT_RECEIPT_TYPE; @@ -42,19 +41,9 @@ use epiphany_core::eyes_evidence_packet_from_research_finding; use epiphany_core::mind_state_commit_receipt; use epiphany_core::open_runtime_spine_heartbeat_job; use epiphany_core::plan_runtime_spine_heartbeat_launch; -use epiphany_core::put_continuity_recovery_receipt; -use epiphany_core::put_eyes_evidence_packet; -use epiphany_core::put_mind_gateway_review; -use epiphany_core::put_mind_state_commit_receipt; -use epiphany_core::put_soul_verdict_receipt; use epiphany_core::put_substrate_gate_repo_access_grant_receipt; use epiphany_core::replace_or_append_epiphany_job_binding; -use epiphany_core::runtime_continuity_recovery_receipt; -use epiphany_core::runtime_eyes_evidence_packet; use epiphany_core::runtime_job_snapshot; -use epiphany_core::runtime_mind_gateway_review; -use epiphany_core::runtime_mind_state_commit_receipt; -use epiphany_core::runtime_soul_verdict_receipt; use epiphany_core::runtime_substrate_gate_repo_access_grant_receipt; use epiphany_core::soul_verdict_receipt_from_verification_finding; use epiphany_core::substrate_gate_repo_access_grant_for_launch; @@ -486,17 +475,8 @@ pub async fn apply_thread_epiphany_role_accept( let accepted_evidence_id = acceptance_update.accepted_evidence_id.clone(); let changed_fields = acceptance_update.changed_fields.clone(); let applied_patch = acceptance_update.applied_patch.clone(); - put_mind_gateway_review(runtime_store_path.as_path(), &acceptance_update.mind_review).map_err( - |err| { - EpiphanyBridgeError::Fatal(format!( - "failed to persist Mind review receipt before role state admission: {err}" - )) - }, - )?; - let mut available_document_types = persisted_mind_review_receipt_types( - runtime_store_path.as_path(), - acceptance_update.mind_review.gateway_id.as_str(), - )?; + let mut available_document_types = vec![MIND_GATEWAY_REVIEW_TYPE.to_string()]; + let mut prerequisites = Vec::new(); if role_id == EpiphanyRoleResultRoleId::Research { let packet = eyes_evidence_packet_from_research_finding( format!("eyes-packet-{accepted_receipt_id}"), @@ -504,15 +484,8 @@ pub async fn apply_thread_epiphany_role_accept( &applied_patch, Utc::now().to_rfc3339_opts(SecondsFormat::Secs, true), ); - put_eyes_evidence_packet(runtime_store_path.as_path(), &packet).map_err(|err| { - EpiphanyBridgeError::Fatal(format!( - "failed to persist Eyes evidence packet before research state admission: {err}" - )) - })?; - available_document_types.extend(persisted_eyes_evidence_packet_types( - runtime_store_path.as_path(), - packet.packet_id.as_str(), - )?); + available_document_types.push(EYES_EVIDENCE_PACKET_TYPE.to_string()); + prerequisites.push(epiphany_core::EpiphanyAcceptancePrerequisite::Eyes(packet)); available_document_types.extend(persisted_substrate_gate_grant_types( runtime_store_path.as_path(), substrate_gate_grant_receipt_id(finding.runtime_job_id.as_deref().unwrap_or_default()) @@ -524,15 +497,8 @@ pub async fn apply_thread_epiphany_role_accept( &finding, Utc::now().to_rfc3339_opts(SecondsFormat::Secs, true), ); - put_soul_verdict_receipt(runtime_store_path.as_path(), &verdict).map_err(|err| { - EpiphanyBridgeError::Fatal(format!( - "failed to persist Soul verdict receipt before verification state admission: {err}" - )) - })?; - available_document_types.extend(persisted_soul_verdict_types( - runtime_store_path.as_path(), - verdict.receipt_id.as_str(), - )?); + available_document_types.push(SOUL_VERDICT_RECEIPT_TYPE.to_string()); + prerequisites.push(epiphany_core::EpiphanyAcceptancePrerequisite::Soul(verdict)); } enforce_current_receipt_proofs( &organ_contract, @@ -540,17 +506,33 @@ pub async fn apply_thread_epiphany_role_accept( &available_document_types, &role_acceptance_enforceable_receipts(role_id), )?; - let epiphany_state = admit_epiphany_state_with_mind_commit( - thread, - runtime_store_path.as_path(), + let reference_turn_id = thread.epiphany_reference_turn_id().await; + let epiphany_state = epiphany_core::apply_coordinator_state_update_to_state( + &state, acceptance_update.state_update, - acceptance_update.mind_review, - format!("mind-commit-{accepted_receipt_id}"), - &changed_fields, - "role", + reference_turn_id, ) - .await?; - let epiphany_state = thread.client_visible_epiphany_state(epiphany_state).await; + .map_err(|error| EpiphanyBridgeError::InvalidRequest(error.to_string()))?; + let commit_receipt = mind_state_commit_receipt( + format!("mind-commit-{accepted_receipt_id}"), + &acceptance_update.mind_review, + epiphany_state.revision, + changed_fields + .iter() + .map(|field| format!("{field:?}")) + .collect(), + Utc::now().to_rfc3339_opts(SecondsFormat::Secs, true), + ); + let thread_id = thread.epiphany_thread_id().await; + epiphany_core::commit_state_with_mind_witness( + runtime_store_path.as_path(), + &thread_id, + &epiphany_state, + &acceptance_update.mind_review, + &commit_receipt, + &prerequisites, + ) + .map_err(|error| EpiphanyBridgeError::Fatal(error.to_string()))?; Ok(EpiphanyRoleAcceptApplied { revision: epiphany_state.revision, @@ -610,34 +592,14 @@ pub async fn apply_thread_epiphany_reorient_accept( let accepted_observation_id = acceptance_update.accepted_observation_id.clone(); let accepted_evidence_id = acceptance_update.accepted_evidence_id.clone(); let changed_fields = acceptance_update.changed_fields.clone(); - put_mind_gateway_review(runtime_store_path.as_path(), &acceptance_update.mind_review).map_err( - |err| { - EpiphanyBridgeError::Fatal(format!( - "failed to persist Mind review receipt before reorientation state admission: {err}" - )) - }, - )?; - let mut available_document_types = persisted_mind_review_receipt_types( - runtime_store_path.as_path(), - acceptance_update.mind_review.gateway_id.as_str(), - )?; + let mut available_document_types = vec![MIND_GATEWAY_REVIEW_TYPE.to_string()]; let recovery_receipt = continuity_recovery_receipt_from_reorient_finding( format!("continuity-recovery-{accepted_receipt_id}"), binding_id.to_string(), &finding, Utc::now().to_rfc3339_opts(SecondsFormat::Secs, true), ); - put_continuity_recovery_receipt(runtime_store_path.as_path(), &recovery_receipt).map_err( - |err| { - EpiphanyBridgeError::Fatal(format!( - "failed to persist Continuity recovery receipt before reorientation state admission: {err}" - )) - }, - )?; - available_document_types.extend(persisted_continuity_recovery_types( - runtime_store_path.as_path(), - recovery_receipt.receipt_id.as_str(), - )?); + available_document_types.push(CONTINUITY_RECOVERY_RECEIPT_TYPE.to_string()); enforce_current_receipt_proofs( &organ_contract, &reorient_acceptance_claimed_effects(), @@ -647,17 +609,35 @@ pub async fn apply_thread_epiphany_reorient_accept( CONTINUITY_RECOVERY_RECEIPT_TYPE.to_string(), ], )?; - let epiphany_state = admit_epiphany_state_with_mind_commit( - thread, - runtime_store_path.as_path(), + let reference_turn_id = thread.epiphany_reference_turn_id().await; + let epiphany_state = epiphany_core::apply_coordinator_state_update_to_state( + &state, acceptance_update.state_update, - acceptance_update.mind_review, - format!("mind-commit-{accepted_receipt_id}"), - &changed_fields, - "reorientation", + reference_turn_id, ) - .await?; - let epiphany_state = thread.client_visible_epiphany_state(epiphany_state).await; + .map_err(|error| EpiphanyBridgeError::InvalidRequest(error.to_string()))?; + let commit_receipt = mind_state_commit_receipt( + format!("mind-commit-{accepted_receipt_id}"), + &acceptance_update.mind_review, + epiphany_state.revision, + changed_fields + .iter() + .map(|field| format!("{field:?}")) + .collect(), + Utc::now().to_rfc3339_opts(SecondsFormat::Secs, true), + ); + let thread_id = thread.epiphany_thread_id().await; + epiphany_core::commit_state_with_mind_witness( + runtime_store_path.as_path(), + &thread_id, + &epiphany_state, + &acceptance_update.mind_review, + &commit_receipt, + &[epiphany_core::EpiphanyAcceptancePrerequisite::Continuity( + recovery_receipt, + )], + ) + .map_err(|error| EpiphanyBridgeError::Fatal(error.to_string()))?; Ok(EpiphanyReorientAcceptApplied { revision: epiphany_state.revision, @@ -950,78 +930,6 @@ fn enforce_current_receipt_proofs( .map_err(map_coordinator_admission_error) } -async fn admit_epiphany_state_with_mind_commit( - thread: &impl EpiphanyMutationHost, - runtime_store_path: &Path, - state_update: EpiphanyStateUpdate, - mind_review: MindGatewayReview, - commit_receipt_id: String, - changed_fields: &[EpiphanyStateUpdatedField], - admission_kind: &str, -) -> BridgeResult { - let epiphany_state = apply_epiphany_state_update_to_thread(thread, state_update).await?; - let commit_receipt = mind_state_commit_receipt( - commit_receipt_id.clone(), - &mind_review, - epiphany_state.revision, - changed_fields - .iter() - .map(|field| format!("{field:?}")) - .collect(), - Utc::now().to_rfc3339_opts(SecondsFormat::Secs, true), - ); - put_mind_state_commit_receipt(runtime_store_path, &commit_receipt).map_err(|err| { - EpiphanyBridgeError::Fatal(format!( - "failed to persist Mind state-commit receipt after {admission_kind} state admission: {err}" - )) - })?; - let persisted = runtime_mind_state_commit_receipt(runtime_store_path, commit_receipt_id.as_str()) - .map_err(|err| { - EpiphanyBridgeError::Fatal(format!( - "failed to verify Mind state-commit receipt after {admission_kind} state admission: {err}" - )) - })?; - if persisted.is_none() { - return Err(EpiphanyBridgeError::Fatal(format!( - "Mind state-commit receipt {:?} was missing after {admission_kind} state admission", - commit_receipt_id - ))); - } - Ok(epiphany_state) -} - -fn persisted_mind_review_receipt_types( - runtime_store_path: &Path, - gateway_id: &str, -) -> BridgeResult> { - let review = runtime_mind_gateway_review(runtime_store_path, gateway_id).map_err(|err| { - EpiphanyBridgeError::Fatal(format!( - "failed to verify persisted Mind review receipt {:?}: {err}", - gateway_id - )) - })?; - Ok(review - .is_some() - .then(|| vec![MIND_GATEWAY_REVIEW_TYPE.to_string()]) - .unwrap_or_default()) -} - -fn persisted_eyes_evidence_packet_types( - runtime_store_path: &Path, - packet_id: &str, -) -> BridgeResult> { - let packet = runtime_eyes_evidence_packet(runtime_store_path, packet_id).map_err(|err| { - EpiphanyBridgeError::Fatal(format!( - "failed to verify persisted Eyes evidence packet {:?}: {err}", - packet_id - )) - })?; - Ok(packet - .is_some() - .then(|| vec![EYES_EVIDENCE_PACKET_TYPE.to_string()]) - .unwrap_or_default()) -} - fn maybe_put_substrate_gate_launch_grant( runtime_store_path: &Path, request: &EpiphanyJobLaunchRequest, @@ -1060,39 +968,6 @@ fn persisted_substrate_gate_grant_types( .unwrap_or_default()) } -fn persisted_soul_verdict_types( - runtime_store_path: &Path, - receipt_id: &str, -) -> BridgeResult> { - let verdict = runtime_soul_verdict_receipt(runtime_store_path, receipt_id).map_err(|err| { - EpiphanyBridgeError::Fatal(format!( - "failed to verify persisted Soul verdict {:?}: {err}", - receipt_id - )) - })?; - Ok(verdict - .is_some() - .then(|| vec![SOUL_VERDICT_RECEIPT_TYPE.to_string()]) - .unwrap_or_default()) -} - -fn persisted_continuity_recovery_types( - runtime_store_path: &Path, - receipt_id: &str, -) -> BridgeResult> { - let recovery = - runtime_continuity_recovery_receipt(runtime_store_path, receipt_id).map_err(|err| { - EpiphanyBridgeError::Fatal(format!( - "failed to verify persisted Continuity recovery receipt {:?}: {err}", - receipt_id - )) - })?; - Ok(recovery - .is_some() - .then(|| vec![CONTINUITY_RECOVERY_RECEIPT_TYPE.to_string()]) - .unwrap_or_default()) -} - fn substrate_gate_grant_receipt_id(runtime_job_id: &str) -> String { format!("substrate-grant-{runtime_job_id}") } @@ -1124,3 +999,35 @@ fn map_coordinator_admission_error( } } } + +#[cfg(test)] +mod acceptance_architecture_tests { + #[test] + fn acceptance_routes_have_no_individual_or_post_state_receipt_writes() { + let source = include_str!("mutation_service.rs"); + let role_start = source + .find("pub async fn apply_thread_epiphany_role_accept") + .unwrap(); + let launch_start = source + .find("pub async fn launch_thread_epiphany_role") + .unwrap(); + let acceptance = &source[role_start..launch_start]; + for forbidden in [ + ["put", "mind", "gateway", "review"].join("_"), + ["put", "eyes", "evidence", "packet"].join("_"), + ["put", "soul", "verdict", "receipt"].join("_"), + ["put", "continuity", "recovery", "receipt"].join("_"), + ["admit", "epiphany", "state", "with", "mind", "commit"].join("_"), + ["epiphany", "persist", "state"].join("_"), + ] { + assert!( + !acceptance.contains(&forbidden), + "acceptance route regrew obsolete writer {forbidden:?}" + ); + } + assert_eq!( + acceptance.matches("commit_state_with_mind_witness").count(), + 2 + ); + } +} diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 0d2c6119..a0a4e5cc 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -752,6 +752,15 @@ state exists. A corrupt unified store fails closed instead of letting stale Codex state retake authority. The vendored app-server check passes. Replace the role/reorient write path with the atomic batch next. +Bridge role and reorientation acceptance now use the unified transaction. +Next state is derived in memory, proof profiles are checked against the exact +documents destined for the batch, and state + Mind review + role-specific +prerequisites + Mind commit receipt publish once. The individual Mind/Eyes/ +Soul/Continuity writes and post-state commit helper were deleted. A bridge +source guard proves both acceptance routes contain exactly one batch call each +and no obsolete writer or Codex state persistence call. Four native acceptance +tests, nine bridge tests, and the app-server check pass. + Bridge identity correction from 2026-06-22: Epiphany owns swarm execution, repo Body work, branch-local lanes, memory, evidence, and Persona cognition. Bifrost owns GameCult identity, governed crossings into GitHub/Discord/Reddit diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index fd03db71..61b749ee 100644 Binary files a/state/ledgers.msgpack and b/state/ledgers.msgpack differ diff --git a/state/map.yaml b/state/map.yaml index c97830cb..6428d98f 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: Replace bridge role/reorient acceptance writes with the unified batch transaction specified in `notes/native-coordinator-liberation-map.md`. Compatibility host reads now prefer unified accepted state and fail closed on corruption. Build each prerequisite set, publish state plus all witnesses once, delete the old cross-store write sequence, then extract launch and remove `thread/epiphany/*` JSON-RPC from the coordinator. + next_action: Extract worker launch into its own native organ, following `notes/native-coordinator-liberation-map.md`. Role/reorient acceptance now publishes state and every witness atomically through the unified store; obsolete cross-store writers are deleted and guarded. Move typed dynamic context, launch document construction, runtime-spine opening/interruption, and state linkage into the launch organ, then remove `thread/epiphany/*` JSON-RPC from `epiphany-mvp-coordinator`.