Bind operator receipts by run identity

This commit is contained in:
Meta Vens 2026-07-13 01:16:14 +01:00
commit 37a006c791
7 changed files with 181 additions and 11 deletions

View file

@ -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
);
}

View file

@ -2784,14 +2784,31 @@ pub fn write_epiphany_cultmesh_operator_run_intent(
store_path: impl AsRef<Path>,
intent: EpiphanyCultMeshOperatorRunIntentEntry,
) -> Result<EpiphanyCultMeshOperatorRunIntentEntry> {
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::<EpiphanyCultMeshOperatorRunIntentEntry>(
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<Path>,
runtime_id: impl Into<String>,
run_id: &str,
) -> Result<Option<EpiphanyCultMeshOperatorRunIntentEntry>> {
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<Path>,
runtime_id: impl Into<String>,
@ -2804,14 +2821,98 @@ pub fn write_epiphany_cultmesh_operator_run_receipt(
store_path: impl AsRef<Path>,
receipt: EpiphanyCultMeshOperatorRunReceiptEntry,
) -> Result<EpiphanyCultMeshOperatorRunReceiptEntry> {
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::<EpiphanyCultMeshOperatorRunReceiptEntry>(
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<FixedOffset>, &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<FixedOffset>, &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<Path>,
runtime_id: impl Into<String>,
@ -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!(

View file

@ -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;

View file

@ -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

View file

@ -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.

Binary file not shown.

View file

@ -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.