From 37a006c7914c34941003d27806074d38da4fe925 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Mon, 13 Jul 2026 01:16:14 +0100 Subject: [PATCH] Bind operator receipts by run identity --- .../src/bin/epiphany-operator-run.rs | 15 +- epiphany-core/src/cultmesh_integration.rs | 158 +++++++++++++++++- epiphany-core/src/lib.rs | 1 + ...onceptual-substitution-audit-2026-07-12.md | 13 ++ notes/fresh-workspace-handoff.md | 3 + state/ledgers.msgpack | Bin 454343 -> 454729 bytes state/map.yaml | 2 +- 7 files changed, 181 insertions(+), 11 deletions(-) diff --git a/epiphany-core/src/bin/epiphany-operator-run.rs b/epiphany-core/src/bin/epiphany-operator-run.rs index 514d6752..3ea8ece6 100644 --- a/epiphany-core/src/bin/epiphany-operator-run.rs +++ b/epiphany-core/src/bin/epiphany-operator-run.rs @@ -9,6 +9,7 @@ use epiphany_core::EpiphanyCultMeshOperatorRunReceiptEntry; 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_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; @@ -49,15 +50,17 @@ fn main() -> Result<()> { print_json(json!({"status": "written", "store": args.store, "intent": written}))?; } "receipt" => { - let intent = - load_latest_epiphany_cultmesh_operator_run_intent(&args.store, &args.runtime_id)? - .context("operator-run receipt requires a persisted run intent")?; - if intent.run_id != args.run_id || intent.mode != args.mode { + let intent = load_epiphany_cultmesh_operator_run_intent( + &args.store, + &args.runtime_id, + &args.run_id, + )? + .context("operator-run receipt requires a persisted intent for its run id")?; + if intent.mode != args.mode { anyhow::bail!( - "operator-run receipt does not match latest intent: requested run={} mode={}, latest run={} mode={}", + "operator-run receipt mode does not match its intent: run={} requested mode={} intent mode={}", args.run_id, args.mode, - intent.run_id, intent.mode ); } diff --git a/epiphany-core/src/cultmesh_integration.rs b/epiphany-core/src/cultmesh_integration.rs index 21cc819e..2fdeb2c2 100644 --- a/epiphany-core/src/cultmesh_integration.rs +++ b/epiphany-core/src/cultmesh_integration.rs @@ -2784,14 +2784,31 @@ pub fn write_epiphany_cultmesh_operator_run_intent( store_path: impl AsRef, intent: EpiphanyCultMeshOperatorRunIntentEntry, ) -> Result { + validate_operator_run_intent(&intent)?; let mut node = open_epiphany_cultmesh_node(&store_path, intent.runtime_id.clone())?; let intent_key = epiphany_cultmesh_operator_run_intent_key(&intent.run_id); let written = node.put(intent_key.as_str(), &intent)?; - node.put(EPIPHANY_CULTMESH_OPERATOR_RUN_INTENT_LATEST_KEY, &written)?; + let current_latest = node.get::( + EPIPHANY_CULTMESH_OPERATOR_RUN_INTENT_LATEST_KEY, + )?; + if current_latest.as_ref().is_none_or(|current| { + operator_run_intent_event_key(&written) >= operator_run_intent_event_key(current) + }) { + node.put(EPIPHANY_CULTMESH_OPERATOR_RUN_INTENT_LATEST_KEY, &written)?; + } node.flush()?; Ok(written) } +pub fn load_epiphany_cultmesh_operator_run_intent( + 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_intent_key(run_id).as_str()) +} + pub fn load_latest_epiphany_cultmesh_operator_run_intent( store_path: impl AsRef, runtime_id: impl Into, @@ -2804,14 +2821,98 @@ pub fn write_epiphany_cultmesh_operator_run_receipt( store_path: impl AsRef, receipt: EpiphanyCultMeshOperatorRunReceiptEntry, ) -> Result { + validate_operator_run_receipt(&receipt)?; let mut node = open_epiphany_cultmesh_node(&store_path, receipt.runtime_id.clone())?; let receipt_key = epiphany_cultmesh_operator_run_receipt_key(&receipt.run_id); let written = node.put(receipt_key.as_str(), &receipt)?; - node.put(EPIPHANY_CULTMESH_OPERATOR_RUN_RECEIPT_LATEST_KEY, &written)?; + let current_latest = node.get::( + EPIPHANY_CULTMESH_OPERATOR_RUN_RECEIPT_LATEST_KEY, + )?; + if current_latest.as_ref().is_none_or(|current| { + operator_run_receipt_event_key(&written) >= operator_run_receipt_event_key(current) + }) { + node.put(EPIPHANY_CULTMESH_OPERATOR_RUN_RECEIPT_LATEST_KEY, &written)?; + } node.flush()?; Ok(written) } +fn validate_operator_run_intent(intent: &EpiphanyCultMeshOperatorRunIntentEntry) -> Result<()> { + if intent.schema_version != EPIPHANY_CULTMESH_OPERATOR_RUN_INTENT_SCHEMA_VERSION { + return Err(anyhow!( + "operator run intent has unsupported schema version" + )); + } + if intent.verse_id != EPIPHANY_CULTMESH_INTERNAL_VERSE_ID { + return Err(anyhow!( + "operator run intent must remain in the internal Verse" + )); + } + for (label, value) in [ + ("runtime id", intent.runtime_id.as_str()), + ("run id", intent.run_id.as_str()), + ("mode", intent.mode.as_str()), + ("root", intent.root.as_str()), + ("workspace", intent.workspace.as_str()), + ("artifact root", intent.artifact_root.as_str()), + ] { + if value.trim().is_empty() { + return Err(anyhow!("operator run intent missing {label}")); + } + } + DateTime::parse_from_rfc3339(&intent.requested_at_utc) + .map_err(|error| anyhow!("operator run intent has invalid requested_at_utc: {error}"))?; + Ok(()) +} + +fn validate_operator_run_receipt(receipt: &EpiphanyCultMeshOperatorRunReceiptEntry) -> Result<()> { + if receipt.schema_version != EPIPHANY_CULTMESH_OPERATOR_RUN_RECEIPT_SCHEMA_VERSION { + return Err(anyhow!( + "operator run receipt has unsupported schema version" + )); + } + if receipt.verse_id != EPIPHANY_CULTMESH_INTERNAL_VERSE_ID { + return Err(anyhow!( + "operator run receipt must remain in the internal Verse" + )); + } + for (label, value) in [ + ("runtime id", receipt.runtime_id.as_str()), + ("run id", receipt.run_id.as_str()), + ("mode", receipt.mode.as_str()), + ("status", receipt.status.as_str()), + ("result path", receipt.result_path.as_str()), + ("artifact root", receipt.artifact_root.as_str()), + ] { + if value.trim().is_empty() { + return Err(anyhow!("operator run receipt missing {label}")); + } + } + DateTime::parse_from_rfc3339(&receipt.completed_at_utc) + .map_err(|error| anyhow!("operator run receipt has invalid completed_at_utc: {error}"))?; + Ok(()) +} + +fn operator_run_intent_event_key( + intent: &EpiphanyCultMeshOperatorRunIntentEntry, +) -> (DateTime, &str) { + ( + DateTime::parse_from_rfc3339(&intent.requested_at_utc) + .expect("validated operator run intent timestamp"), + intent.run_id.as_str(), + ) +} + +fn operator_run_receipt_event_key( + receipt: &EpiphanyCultMeshOperatorRunReceiptEntry, +) -> (DateTime, &str) { + ( + DateTime::parse_from_rfc3339(&receipt.completed_at_utc) + .expect("validated operator run receipt timestamp"), + receipt.run_id.as_str(), + ) +} + pub fn load_latest_epiphany_cultmesh_operator_run_receipt( store_path: impl AsRef, runtime_id: impl Into, @@ -7909,11 +8010,60 @@ mod tests { assert_eq!( load_latest_epiphany_cultmesh_operator_run_intent(&store, "epiphany-test")?, - Some(intent) + Some(intent.clone()) ); assert_eq!( load_latest_epiphany_cultmesh_operator_run_receipt(&store, "epiphany-test")?, - Some(receipt) + Some(receipt.clone()) + ); + + let mut newer_intent = intent.clone(); + newer_intent.run_id = "run-newer".to_string(); + newer_intent.requested_at_utc = "2026-05-27T01:00:00Z".to_string(); + write_epiphany_cultmesh_operator_run_intent(&store, newer_intent.clone())?; + let mut delayed_intent = intent.clone(); + delayed_intent.run_id = "run-delayed".to_string(); + delayed_intent.requested_at_utc = "2026-05-26T23:00:00Z".to_string(); + write_epiphany_cultmesh_operator_run_intent(&store, delayed_intent.clone())?; + assert_eq!( + load_latest_epiphany_cultmesh_operator_run_intent(&store, "epiphany-test")?, + Some(newer_intent) + ); + assert_eq!( + load_epiphany_cultmesh_operator_run_intent(&store, "epiphany-test", "run-delayed")?, + Some(delayed_intent) + ); + + let mut newer_receipt = receipt.clone(); + newer_receipt.run_id = "run-newer".to_string(); + newer_receipt.completed_at_utc = "2026-05-27T01:00:01Z".to_string(); + write_epiphany_cultmesh_operator_run_receipt(&store, newer_receipt.clone())?; + let mut delayed_receipt = receipt.clone(); + delayed_receipt.run_id = "run-delayed".to_string(); + delayed_receipt.completed_at_utc = "2026-05-26T23:00:01Z".to_string(); + write_epiphany_cultmesh_operator_run_receipt(&store, delayed_receipt)?; + assert_eq!( + load_latest_epiphany_cultmesh_operator_run_receipt(&store, "epiphany-test")?, + Some(newer_receipt) + ); + + let mut invalid_intent = intent.clone(); + invalid_intent.run_id = "run-invalid".to_string(); + invalid_intent.requested_at_utc = "not-a-time".to_string(); + assert!( + write_epiphany_cultmesh_operator_run_intent(&store, invalid_intent) + .unwrap_err() + .to_string() + .contains("invalid requested_at_utc") + ); + let mut wrong_verse_receipt = receipt; + wrong_verse_receipt.run_id = "run-wrong-verse".to_string(); + wrong_verse_receipt.verse_id = EPIPHANY_CULTMESH_LOCAL_AREA_VERSE_ID.to_string(); + assert!( + write_epiphany_cultmesh_operator_run_receipt(&store, wrong_verse_receipt) + .unwrap_err() + .to_string() + .contains("internal Verse") ); let node = open_epiphany_cultmesh_node(&store, "epiphany-test")?; assert!( diff --git a/epiphany-core/src/lib.rs b/epiphany-core/src/lib.rs index 961cdfc2..4d2cc2c4 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_aftercare_audit_recei 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_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 47ee22a0..b628f733 100644 --- a/notes/conceptual-substitution-audit-2026-07-12.md +++ b/notes/conceptual-substitution-audit-2026-07-12.md @@ -634,6 +634,19 @@ source identity, and valid RFC3339 generation time. `latest` advances by `(generation time, snapshot ID)`; snapshots remain observations and acquire no coordinator or runtime authority. +## Global chronology substituted for operator-run identity + +Operator-run intents and receipts were stored by `run_id`, but receipt +admission loaded the global latest intent and required it to match the +completing run. A newer concurrent run therefore stole the identity lookup for +an older legitimate completion. Both global mirrors were also arrival-owned +and their typed documents were accepted without boundary validation. Receipt +admission now loads the intent directly by its own `run_id`; `latest` remains a +convenience projection ordered by each document's owner timestamp. Intent and +receipt writers validate schema, internal Verse, required identity/path fields, +and RFC3339 time. Delayed writes remain addressable by identity without +rewinding either mirror. + ## Unresolved: provider receipts without chronology Bifrost body-change/GitHub publication receipts are externally owned and their diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 6282ba20..47a7473e 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -159,6 +159,9 @@ The confirmed conceptual substitutions have been cut: - Operator snapshots are validated internal-Verse observations and `latest` is generation-time-owned; delayed status transport cannot rewind the observed coordinator/runtime surface. +- Operator-run receipt admission resolves its intent by `run_id`, not by the + unrelated global latest mirror. Intent/receipt mirrors are validated and + owner-time ordered; concurrent runs retain independent identity. - Bifrost provider receipt contracts still lack provider timestamp/revision. Do not invent consumer-side ordering; repair that in a Bifrost-owned schema. diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index 4cca670871427e685f6ae745071e6eb4d5b569f7..81a42156050a5fd6d228fca8844492d0ce28c00d 100644 GIT binary patch delta 377 zcmX|+JxT;Y5QUvpJJ1uzA`}P){_Ke025M+xBpL{sNbhvbTF}!yTivtEMjIHInk}!a0RCLT8vF?!6}(rkzIuLbzr3~YmXd|;?$*xv(~SCBeOO5bNwR-6ZCy`W ziKv;gqB+t0sO$QlqDULgE7{U1wSg%b0ilU#*-na=~klBOD zUzs!i$45*NIlxd`GIA0^c8P^fnGMy=?#*MT!vPr22sZt*xoMLtjt)*$Y|X>m8pFy6C)6VXl5X00bO| G-T(kIND`F* diff --git a/state/map.yaml b/state/map.yaml index 41b82ffb..b7ff01ab 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -660,4 +660,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`. swarm overview 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: Continue the conceptual-substitution modeling pass beyond receipt writers. Operational/evidence/self-state and operator-observation mirrors with owned clocks are event-time ordered; repo-work projections follow owning time; writerless readiness-review is deleted. Bifrost provider receipts still need a provider-owned chronology contract rather than consumer inference. Continue auditing other evidence/security mirrors, service configuration claims, adapters, and destructive path consumers for borrowed authority. + next_action: Continue the conceptual-substitution modeling pass beyond receipt writers. Operational/evidence/self-state and operator surfaces with owned clocks are event-time ordered; operator receipts bind intents by run identity rather than global chronology; repo-work projections follow owning time; writerless readiness-review is deleted. Bifrost provider receipts still need a provider-owned chronology contract rather than consumer inference. Continue auditing other evidence/security mirrors, service configuration claims, adapters, and destructive path consumers for borrowed authority.