From 7d691e22474d644c3468d2dc3e980f622ee5dd90 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Mon, 13 Jul 2026 17:07:14 +0100 Subject: [PATCH] Bind operator status to matching lifecycle evidence --- .../src/bin/epiphany-operator-run.rs | 98 +++++++++++++++++- .../src/bin/epiphany-operator-snapshot.rs | 2 +- epiphany-core/src/cultmesh_integration.rs | 9 ++ epiphany-core/src/lib.rs | 1 + ...onceptual-substitution-audit-2026-07-12.md | 16 +++ notes/fresh-workspace-handoff.md | 9 ++ state/ledgers.msgpack | Bin 480980 -> 481332 bytes state/map.yaml | 2 +- 8 files changed, 132 insertions(+), 5 deletions(-) diff --git a/epiphany-core/src/bin/epiphany-operator-run.rs b/epiphany-core/src/bin/epiphany-operator-run.rs index 3ea8ece6..d50236db 100644 --- a/epiphany-core/src/bin/epiphany-operator-run.rs +++ b/epiphany-core/src/bin/epiphany-operator-run.rs @@ -10,6 +10,7 @@ use epiphany_core::epiphany_cultmesh_coordinator_run_receipt_from_summary_json; use epiphany_core::epiphany_cultmesh_hands_action_gate_from_summary_json; use epiphany_core::epiphany_cultmesh_role_review_event_from_summary_json; use epiphany_core::load_epiphany_cultmesh_operator_run_intent; +use epiphany_core::load_epiphany_cultmesh_operator_run_receipt; use epiphany_core::load_latest_epiphany_cultmesh_operator_run_intent; use epiphany_core::load_latest_epiphany_cultmesh_operator_run_receipt; use epiphany_core::write_epiphany_cultmesh_coordinator_run_receipt; @@ -126,10 +127,17 @@ fn main() -> Result<()> { "latest" => { let intent = load_latest_epiphany_cultmesh_operator_run_intent(&args.store, &args.runtime_id)?; - let receipt = - load_latest_epiphany_cultmesh_operator_run_receipt(&args.store, &args.runtime_id)?; + let receipt = if let Some(intent) = intent.as_ref() { + load_epiphany_cultmesh_operator_run_receipt( + &args.store, + &args.runtime_id, + &intent.run_id, + )? + } else { + load_latest_epiphany_cultmesh_operator_run_receipt(&args.store, &args.runtime_id)? + }; print_json(json!({ - "status": if intent.is_some() || receipt.is_some() { "ready" } else { "missing" }, + "status": operator_run_status(intent.as_ref(), receipt.as_ref()), "store": args.store, "intent": intent, "receipt": receipt, @@ -242,6 +250,90 @@ fn main() -> Result<()> { Ok(()) } +fn operator_run_status( + intent: Option<&EpiphanyCultMeshOperatorRunIntentEntry>, + receipt: Option<&EpiphanyCultMeshOperatorRunReceiptEntry>, +) -> &'static str { + match (intent, receipt) { + (None, None) => "missing", + (Some(_), None) => "requested", + (None, Some(_)) => "orphaned-receipt", + (Some(intent), Some(receipt)) + if intent.run_id == receipt.run_id && receipt.status == "completed" => + { + "completed" + } + (Some(_), Some(_)) => "attention", + } +} + +#[cfg(test)] +mod tests { + use super::*; + + fn intent(run_id: &str) -> EpiphanyCultMeshOperatorRunIntentEntry { + EpiphanyCultMeshOperatorRunIntentEntry { + schema_version: EPIPHANY_CULTMESH_OPERATOR_RUN_INTENT_SCHEMA_VERSION.to_string(), + runtime_id: "epiphany-test".to_string(), + verse_id: EPIPHANY_CULTMESH_INTERNAL_VERSE_ID.to_string(), + run_id: run_id.to_string(), + requested_at_utc: "2026-07-13T00:00:00Z".to_string(), + mode: "status".to_string(), + root: "root".to_string(), + workspace: "workspace".to_string(), + thread_id: String::new(), + codex_home: String::new(), + target_dir: String::new(), + max_steps: 1, + timeout_seconds: 1, + auto_review: false, + no_ephemeral: false, + artifact_root: "artifacts".to_string(), + dogfood_root: String::new(), + } + } + + fn receipt(run_id: &str, status: &str) -> EpiphanyCultMeshOperatorRunReceiptEntry { + EpiphanyCultMeshOperatorRunReceiptEntry { + schema_version: EPIPHANY_CULTMESH_OPERATOR_RUN_RECEIPT_SCHEMA_VERSION.to_string(), + runtime_id: "epiphany-test".to_string(), + verse_id: EPIPHANY_CULTMESH_INTERNAL_VERSE_ID.to_string(), + run_id: run_id.to_string(), + completed_at_utc: "2026-07-13T00:00:01Z".to_string(), + mode: "status".to_string(), + status: status.to_string(), + result_path: "result.json".to_string(), + artifact_root: "artifacts".to_string(), + dogfood_root: String::new(), + operator_snapshot_store: String::new(), + operator_snapshot_id: String::new(), + artifact_refs: Vec::new(), + notes: Vec::new(), + } + } + + #[test] + fn intent_presence_is_requested_not_ready() { + let intent = intent("run-new"); + assert_eq!(operator_run_status(Some(&intent), None), "requested"); + } + + #[test] + fn only_matching_completed_receipt_closes_latest_intent() { + let intent = intent("run-new"); + let old_receipt = receipt("run-old", "completed"); + let matching_receipt = receipt("run-new", "completed"); + assert_eq!( + operator_run_status(Some(&intent), Some(&old_receipt)), + "attention" + ); + assert_eq!( + operator_run_status(Some(&intent), Some(&matching_receipt)), + "completed" + ); + } +} + struct Args { command: String, store: PathBuf, diff --git a/epiphany-core/src/bin/epiphany-operator-snapshot.rs b/epiphany-core/src/bin/epiphany-operator-snapshot.rs index 86271459..a2830176 100644 --- a/epiphany-core/src/bin/epiphany-operator-snapshot.rs +++ b/epiphany-core/src/bin/epiphany-operator-snapshot.rs @@ -41,7 +41,7 @@ fn main() -> Result<()> { let latest = load_latest_epiphany_cultmesh_operator_snapshot(&args.store, &args.runtime_id)?; print_json(json!({ - "status": if latest.is_some() { "ready" } else { "missing" }, + "status": if latest.is_some() { "loaded" } else { "missing" }, "store": args.store, "snapshot": latest, }))?; diff --git a/epiphany-core/src/cultmesh_integration.rs b/epiphany-core/src/cultmesh_integration.rs index dc3cfec6..3d3a717a 100644 --- a/epiphany-core/src/cultmesh_integration.rs +++ b/epiphany-core/src/cultmesh_integration.rs @@ -2933,6 +2933,15 @@ pub fn load_latest_epiphany_cultmesh_operator_run_receipt( node.get(EPIPHANY_CULTMESH_OPERATOR_RUN_RECEIPT_LATEST_KEY) } +pub fn load_epiphany_cultmesh_operator_run_receipt( + store_path: impl AsRef, + runtime_id: impl Into, + run_id: &str, +) -> Result> { + let node = open_epiphany_cultmesh_node(store_path, runtime_id)?; + node.get(epiphany_cultmesh_operator_run_receipt_key(run_id).as_str()) +} + pub fn epiphany_cultmesh_coordinator_run_receipt_from_summary_json( runtime_id: impl Into, receipt_id: impl Into, diff --git a/epiphany-core/src/lib.rs b/epiphany-core/src/lib.rs index c3706765..9ca0ea81 100644 --- a/epiphany-core/src/lib.rs +++ b/epiphany-core/src/lib.rs @@ -425,6 +425,7 @@ pub use cultmesh_integration::load_epiphany_cultmesh_idunn_deployment_receipt; pub use cultmesh_integration::load_epiphany_cultmesh_managed_service_policies; pub use cultmesh_integration::load_epiphany_cultmesh_managed_service_policy; pub use cultmesh_integration::load_epiphany_cultmesh_operator_run_intent; +pub use cultmesh_integration::load_epiphany_cultmesh_operator_run_receipt; pub use cultmesh_integration::load_epiphany_cultmesh_operator_snapshot; pub use cultmesh_integration::load_epiphany_cultmesh_repo_work_map_entries; pub use cultmesh_integration::load_epiphany_cultmesh_repo_work_overviews; diff --git a/notes/conceptual-substitution-audit-2026-07-12.md b/notes/conceptual-substitution-audit-2026-07-12.md index a66ac3e2..be14e1b3 100644 --- a/notes/conceptual-substitution-audit-2026-07-12.md +++ b/notes/conceptual-substitution-audit-2026-07-12.md @@ -1464,3 +1464,19 @@ is `unconfigured`; active participants whose pending turns are running are smoke asserts the distinction at the emitted projection layer. State loading owns readability. Participant physiology derives scheduler status. Presence alone owns no readiness verdict. + +## Cache presence is not operator-run readiness + +The operator-run `latest` projection emitted `ready` when either a latest intent +or a latest receipt existed. This collapsed request, execution, and completion, +and the two independent latest mirrors could pair a new intent with an older +run's receipt. A historical completion could therefore lend authority to work +that had only been requested. + +Readback now loads the latest intent, then looks up that intent's receipt by +`run_id`. It reports `requested` until the matching receipt exists, `completed` +only for a matching completed receipt, `attention` for an inconsistent pair, +`orphaned-receipt` when receipt state exists without an intent, and `missing` +when neither exists. The operator snapshot readback likewise reports `loaded`, +not `ready`, when a snapshot is merely present. Cache lookup owns retrieval; +the joined lifecycle evidence owns lifecycle status. diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index b6cd68fc..aae93f3b 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -555,3 +555,12 @@ as `unconfigured`, `active`, or `attention` from participants and pending-turn state. The focused library suite, all-bin check, and native heartbeat smoke pass. Continue through cache/freshness projections; do not let existence, successful decode, or a latest mirror impersonate current consequence authority. + +Operator cache readback is also purified. `epiphany-operator-run latest` joins +the latest intent to its exact receipt by `run_id`; a new intent cannot borrow +an older latest completion. Its statuses are lifecycle facts (`missing`, +`requested`, `completed`, `attention`, `orphaned-receipt`), never generic +`ready`. `epiphany-operator-snapshot latest` reports present state as `loaded`. +Negative unit coverage proves intent presence is only requested and mismatched +receipt identity cannot close it. Both native smokes, 259 library tests, focused +binary tests, and the all-bin check pass. diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index 56b70a59baac236e4addb5cd12ff9410e9056f2a..e449def03dd8134438a8c12b37579c5e576c5229 100644 GIT binary patch delta 361 zcmXw!%SuB*42C^bdq7t%T~q?@q&E>Q)J5OG3ls!*=}hdIUMAC-9I-1Gf^OX$y7mEt zf`V`06Zk;Rsdn*`ko-x${Jhsbm$l`7veW6dPjA0B(wn`H!(^5u&re0=rKluPW!#L~ zirS8RAfVpJsjm$yi(uD~M1p%L1 z@PvARY78SbHmp0w3RwYRpa)bdXT#`dR%Dz2S`C`Kxu+0ovpg;%-BLVt6DqS2N;z-X zw%EH2E$PPpY-?&lFm`wjyhaQbUC3C#c?x6|#hs45L>fj-x(+rrOVD`}E@+4n55pa+ kJdj?zU8M&{je)TcA64V}3U0uXf&DXvDUTzk!w~JwU!V