From c5f99c46354159e06e0da18973d410f57307e34a Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 8 Aug 2026 00:53:01 +0100 Subject: [PATCH] Return failed resident pressure to heartbeat --- epiphany-core/src/resident_self.rs | 91 ++++++++++++++++++++-- notes/epiphany-current-algorithmic-map.md | 9 +++ notes/fresh-workspace-handoff.md | 31 ++++++-- state/ledgers.msgpack | Bin 561689 -> 562143 bytes state/map.yaml | 10 +-- 5 files changed, 123 insertions(+), 18 deletions(-) diff --git a/epiphany-core/src/resident_self.rs b/epiphany-core/src/resident_self.rs index 096abe07..560e4a2a 100644 --- a/epiphany-core/src/resident_self.rs +++ b/epiphany-core/src/resident_self.rs @@ -1413,6 +1413,16 @@ pub fn cancel_resident_self_turn( let grant = cache .get::(&lease.grant_id)? .ok_or_else(|| anyhow!("resident Self cancellation grant missing"))?; + let mut pressure = cache + .get::(&grant.pressure_id)? + .ok_or_else(|| anyhow!("resident Self cancellation pressure missing"))?; + if pressure.status != "consumed" + || pressure.consumed_by_grant_id.as_deref() != Some(&grant.grant_id) + { + return Err(anyhow!( + "resident Self cancellation pressure authority changed" + )); + } let ack = ResidentSelfTerminalAck { schema_version: RESIDENT_SELF_ACK_SCHEMA_VERSION.into(), ack_id: format!("resident-self-cancel-{}-{status}", lease.grant_id), @@ -1426,22 +1436,35 @@ pub fn cancel_resident_self_turn( consumed_by_heartbeat_at_millis: None, private_state_exposed: false, }; - let expected = cache - .snapshot_envelopes() - .into_iter() + let envelopes = cache.snapshot_envelopes(); + let expected_state = envelopes + .iter() .find(|entry| { entry.r#type == ::TYPE && entry.key == RESIDENT_SELF_STATE_KEY }) + .cloned() .ok_or_else(|| anyhow!("resident Self cancellation state envelope missing"))?; + let expected_pressure = envelopes + .iter() + .find(|entry| { + entry.r#type == ::TYPE + && entry.key == pressure.pressure_id + }) + .cloned() + .ok_or_else(|| anyhow!("resident Self cancellation pressure envelope missing"))?; state.active_turn = None; state.revision += 1; state.consecutive_failures += u64::from(status != "brake-cancelled"); + pressure.status = "pending".into(); + pressure.consumed_by_grant_id = None; let (state_entry, _) = cache.prepare_entry(RESIDENT_SELF_STATE_KEY, &state)?; + let (pressure_entry, _) = cache.prepare_entry(&pressure.pressure_id, &pressure)?; let (ack_entry, _) = cache.prepare_entry(&ack.ack_id, &ack)?; - if !SingleFileMessagePackBackingStore::new(path) - .compare_and_swap_batch(&[expected], vec![state_entry, ack_entry])? - { + if !SingleFileMessagePackBackingStore::new(path).compare_and_swap_batch( + &[expected_state, expected_pressure], + vec![state_entry, pressure_entry, ack_entry], + )? { return Err(anyhow!("resident Self lost cancellation CAS")); } Ok(ack) @@ -1878,6 +1901,62 @@ mod tests { Ok(()) } + #[test] + fn failed_resident_turn_atomically_returns_exact_pressure_to_heartbeat() -> Result<()> { + let temp = tempfile::tempdir()?; + let store = temp.path().join("resident-self.cc"); + let coordinator = temp.path().join("epiphany-mvp-coordinator"); + std::fs::write(&coordinator, b"witnessed executable")?; + let mut policy = policy(); + policy.coordinator_bin = coordinator.clone(); + enqueue_resident_self_pressure( + &store, + &ResidentSelfPressure { + schema_version: RESIDENT_SELF_PRESSURE_SCHEMA_VERSION.into(), + pressure_id: "pressure-retry-1".into(), + kind: "admitted-model-direction-consideration".into(), + provenance_ref: + "cultcache://admitted-model-direction-consideration/request-retry-1".into(), + objective: "Launch exact typed model direction request.".into(), + created_at_millis: 1, + status: "pending".into(), + consumed_by_grant_id: None, + private_state_exposed: false, + }, + )?; + let first_grant = + heartbeat_issue_resident_self_grant(&store, "heartbeat-1", "action-1", 2)? + .expect("first grant"); + let prepared = prepare_resident_self_launch(&store, &policy, 3)?.expect("preparation"); + let process = LaunchedCoordinator { + process_id: 44, + process_creation_token: 55, + process_executable_path: coordinator, + }; + claim_resident_self_preparation_as_child(&store, &prepared.preparation_id, &process, 4)?; + let lease = + acknowledge_resident_self_launch(&store, &prepared.preparation_id, &process, 5)?; + let ack = cancel_resident_self_turn( + &store, + &lease, + "process-failed", + "coordinator rejected its startup configuration", + 6, + )?; + assert_eq!(ack.grant_id, first_grant.grant_id); + let pressure = state_cache(&store)? + .get::("pressure-retry-1")? + .expect("requeued pressure"); + assert_eq!(pressure.status, "pending"); + assert_eq!(pressure.consumed_by_grant_id, None); + let retry_grant = + heartbeat_issue_resident_self_grant(&store, "heartbeat-2", "action-2", 7)? + .expect("retry grant"); + assert_eq!(retry_grant.pressure_id, first_grant.pressure_id); + assert_ne!(retry_grant.grant_id, first_grant.grant_id); + Ok(()) + } + #[test] fn autonomous_frontier_pressure_launches_exact_modeling_selection_without_objective() -> Result<()> { diff --git a/notes/epiphany-current-algorithmic-map.md b/notes/epiphany-current-algorithmic-map.md index cfbf19b8..b9a37562 100644 --- a/notes/epiphany-current-algorithmic-map.md +++ b/notes/epiphany-current-algorithmic-map.md @@ -1242,6 +1242,15 @@ admitted-model direction, autonomous proposal Modeling, and Imagination consideration pressure. Verification replays after timestamp change and after heartbeat consumption, and retains a hostile changed-objective collision. +Resident cancellation owns retry admission for a failed bounded coordinator +turn. In the same CAS that clears the exact active lease and writes its typed +terminal acknowledgement, cancellation verifies the grant still owns the +source pressure and returns that pressure from `consumed` to `pending`. It does +not mint the retry grant. The standard heartbeat remains the sole scheduler and +may issue a new grant with a new identity for the same exact pressure after it +has reconciled the terminal turn. A failed launch can therefore recover without +operator pressure duplication or an authority-bypassing coordinator call. + ## Exact release build cache ownership Release construction has two serialized cache authorities. The graph cache is diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index ce5e7e4d..d32cdf0b 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -23,24 +23,41 @@ failed before launch because replay recreated the same producer pressure ID with a later `created_at_millis`; full document equality misclassified that ordinary replay as an identity collision. -The current worktree repairs ownership in `resident_self.rs`: producer replay +Pushed commit `b81092b2` repairs ownership in `resident_self.rs`: producer replay compares immutable producer identity, while timestamp and pressure lifecycle remain derived/mutable. Changed objective, provenance, kind, schema, identity, or privacy authority still collide. All 15 resident-Self tests pass, and the autonomous promotion integration proves ingestion after heartbeat consumption returns zero without recreating work. +Exact `b81092b2` packages as +`sha256-da343dcfe478720320f94c582eebcef2804aac41ac136a9c6a504cd248f495fa` +with witness +`sha256-41f081ce260467325a759bf6c888b30cf7d57faff1b1fdcfab398191323cf333`. +The authenticated replay clone `live-20260808-v32-replay` crossed the original +collision and launched the resident coordinator. The child correctly refused +an operator-supplied artifact root outside `.epiphany-dogfood`. Its typed +cancellation then exposed a second continuity wound: the source pressure stayed +`consumed`, so heartbeat could never grant an exact retry. + +The current worktree makes cancellation atomically return the exact pressure to +`pending` while writing the failed terminal acknowledgement. Heartbeat remains +the sole retry scheduler and issues a new grant identity. All 16 resident-Self +tests pass, including exact failed-turn pressure recovery. + ## Next action -1. Commit and push the resident-pressure replay repair. -2. Package and independently authenticate the exact commit through the stable - caches; preserve v31 as failure evidence and publish into fresh v32. -3. Re-run pressure ingestion twice, heartbeat selection, and resident launch. +1. Commit, push, package, and authenticate the failed-turn retry repair. +2. Preserve v31 and v32-replay as failure evidence; clone the recovered boundary + into a new replay runtime using an approved `.epiphany-dogfood` artifact root. +3. Re-run heartbeat selection and resident launch, including exact retry after + one deliberate failed launch. +4. In a fresh runtime, re-run pressure ingestion twice and resident launch. Prove autonomous direction consideration, proposal-bound Modeling, canonical Imagination, dedicated Mind adoption, and exact Hands authority. -4. Deliberately fail one bounded worker and prove typed terminalization, +5. Deliberately fail one bounded worker and prove typed terminalization, restart/recovery, Reorientation, and Soul-verifiable closure. -5. Continue through Persona consequence, retention, endurance/resource +6. Continue through Persona consequence, retention, endurance/resource plateau, and Linux/Yggdrasil cognition. Do not execute v31's direct Hands gate, read raw worker transcripts, mutate diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index 98b5bdb59c82aad81c4a65d1ee498d7892ea9196..7217c98794c477d6b9f7bb0ed8075331c6ed2aba 100644 GIT binary patch delta 502 zcmYk2v2GJV5QaGiNThUBNKlMIZQ~rW389MM4WOc%+Z)@XjCYUSIh&(#5hO~aCt12X=Z5LN>4E8?Y4c*;+xqhD(aB{wEXV!fUVr%VefeU4RQ~wYZ9ZB3ExsSL zIwP;_P^pG$Z+G~rtV$4G5JYMOJ8&_iWS>?DA@Ymk zj+D4IFuWs~4B#yZR}{?z*e_7H28=7^2|De^5Y!qbZ8C62o4Y{23QIr@a~ocyvjo~kpDY31 z>DK@a`I`L{mNOQDWn|5_ybkRebDbc|e=B$R8fJu1D>4L1@C26GLgixP#}1|zRR?e& V0#A3xw|na6J=u)OiW^L6a1H&Kv^f9( delta 65 zcmcb=TxsSKr415{+{PAGCI(T*7&s<;+pNr3$jGSIJe8?^Dib3RgJ@