From 61d061404b4fe45a8f1fc4ff5cc0ad68d090af1a Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 9 Aug 2026 21:40:34 +0100 Subject: [PATCH] Make terminal acknowledgement kill resident grant --- epiphany-core/src/resident_self.rs | 46 ++++++++++++++++++++--- notes/epiphany-current-algorithmic-map.md | 9 +++++ notes/fresh-workspace-handoff.md | 22 +++++++++++ state/map.yaml | 8 ++-- 4 files changed, 76 insertions(+), 9 deletions(-) diff --git a/epiphany-core/src/resident_self.rs b/epiphany-core/src/resident_self.rs index 42665161..551ca8b7 100644 --- a/epiphany-core/src/resident_self.rs +++ b/epiphany-core/src/resident_self.rs @@ -1096,11 +1096,15 @@ pub fn heartbeat_issue_resident_self_grant( if state.active_turn.is_some() || state.prepared_launch.is_some() { return Ok(None); } + let terminal_grant_ids = cache + .get_all::()? + .into_iter() + .map(|ack| ack.grant_id) + .collect::>(); let grants = cache.get_all::()?; if grants.iter().any(|grant| { - grant.consumed_at_millis.is_none() - || (grant.heartbeat_schedule_id == schedule_id - && grant.heartbeat_action_id == action_id) + (grant.heartbeat_schedule_id == schedule_id && grant.heartbeat_action_id == action_id) + || (grant.consumed_at_millis.is_none() && !terminal_grant_ids.contains(&grant.grant_id)) }) { return Ok(None); } @@ -1352,10 +1356,18 @@ pub fn settle_resident_self_exited_coordinator( } pub fn pending_resident_self_grant(path: &Path) -> Result> { - let mut grants = state_cache(path)? + let cache = state_cache(path)?; + let terminal_grant_ids = cache + .get_all::()? + .into_iter() + .map(|ack| ack.grant_id) + .collect::>(); + let mut grants = cache .get_all::()? .into_iter() - .filter(|grant| grant.consumed_at_millis.is_none()) + .filter(|grant| { + grant.consumed_at_millis.is_none() && !terminal_grant_ids.contains(&grant.grant_id) + }) .collect::>(); grants.sort_by(|a, b| { a.issued_at_millis @@ -2761,6 +2773,30 @@ mod tests { let acks = pending_resident_self_acks(&store)?; assert_eq!(acks.len(), 1); assert_eq!(acks[0].coordinator_receipt_id, receipt.receipt_id); + let cache = state_cache(&store)?; + let mut stale_grant = cache + .get::(&grant.grant_id)? + .expect("completed grant"); + let expected_grant = cache + .snapshot_envelopes() + .into_iter() + .find(|entry| { + entry.r#type == ResidentSelfHeartbeatGrant::TYPE + && entry.key == stale_grant.grant_id + }) + .expect("completed grant envelope"); + stale_grant.consumed_at_millis = None; + let (stale_entry, _) = cache.prepare_entry(&stale_grant.grant_id, &stale_grant)?; + assert!( + SingleFileMessagePackBackingStore::new(&store) + .compare_and_swap_entry(&expected_grant, stale_entry)?, + "test must install the observed restart-corruption shape" + ); + assert!( + pending_resident_self_grant(&store)?.is_none(), + "terminal acknowledgement permanently kills its exact grant" + ); + assert!(prepare_resident_self_launch(&store, &policy, 10_010)?.is_none()); let later_pressure = ResidentSelfPressure { schema_version: RESIDENT_SELF_PRESSURE_SCHEMA_VERSION.into(), pressure_id: "pressure-after-completion".into(), diff --git a/notes/epiphany-current-algorithmic-map.md b/notes/epiphany-current-algorithmic-map.md index 648912e9..3f13e483 100644 --- a/notes/epiphany-current-algorithmic-map.md +++ b/notes/epiphany-current-algorithmic-map.md @@ -1380,6 +1380,15 @@ Heartbeat turn. Pressure arriving after that turn spent its grant stays pending until Heartbeat consumes the exact terminal acknowledgement and schedules a different coordinator turn. +Terminal acknowledgement is irreversible grant death. Pending-grant selection +loads all `ResidentSelfTerminalAck` rows first and excludes their exact grant IDs +before considering `consumed_at_millis`. Heartbeat applies the same exclusion +when deciding whether another unconsumed grant blocks issuance. The consumed +marker proves preparation consumed launch authority; it cannot reopen authority +after completion, cancellation, restart, stale-envelope resolution, or marker +regression. Lifecycle retention may delete this evidence only after Heartbeat has +consumed the acknowledgement and the owning turn is already closed. + Imagination candidate time is part of that causal contract. A candidate must have a valid RFC3339 timestamp at or after its request timestamp. A well-shaped candidate from before the request cannot close resident authority. diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index f3bb9a46..5078ff51 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -1315,3 +1315,25 @@ test that explicitly blessed same-turn retry was corrected. Twenty-four resident eight swarm, and eleven heartbeat-state tests pass. Commit and push this cut, package the exact commit, and replay from a fresh idle copy. Do not reuse the invalid d303 body as bounded-turn evidence. + +Exact `c77824ef` packaged as warning-free 24-binary release +`sha256-e0b7c5cf54c4fb62929d91326c4604e8ad486c59411d6b2509de9182e7a83482` +with witness +`sha256-f923a10c4a96b4301a952c3f874a913535f3165fee531034bbce077811a5629b`. +The fresh copied body under `.epiphany-run/active-cognition4-c77824ef` +matched all 7,668 accepted-idle files. One exact grant completed and persisted +`nextEligibleAtMillis=1786307607233`; Self restarted zero and slept through the +deadline. Heartbeat never issued another grant after the original pulse-48 +grant, so schedule/action issuance cardinality is accepted. + +After expiry, Self nevertheless launched again. The typed diagnostic proved the +active lease named the exact already-completed pulse-48 grant, not another +Heartbeat grant. This run is rejected and was stopped with receipts. The deeper +ownership rule is that `ResidentSelfTerminalAck`, not the mutable +`consumed_at_millis` marker, permanently kills its exact grant. Pending selection +and Heartbeat's unconsumed-grant fence now exclude every terminally acknowledged +grant. A focused test deliberately regresses a completed grant's consumed marker +to absent and proves it remains unselectable while a different Heartbeat turn may +still grant later pending pressure. Twenty-four resident, eight swarm, and eleven +heartbeat-state tests pass. Commit, push, package, and replay this terminal fence; +do not treat c778 as bounded endurance evidence. diff --git a/state/map.yaml b/state/map.yaml index 1ab35442..90ef52ea 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -35,8 +35,8 @@ invariants: - Evidence and git retain history; this map retains only state that changes future decisions. current_status: - summary: Epiphany is a supervised engineering alpha on Starfire, not deployment-ready. Exact b8138a6b active-child SIGTERM and restart, exact 9f369528 deterministic warm packaging, exact c930f505 cross-container ownership, exact ed15f83a resident lifecycle retention, and exact 16c4b19f coordinator receipt and Heartbeat artifact retention are proven. Gamecult-ops 059821f makes journald the sole Yggdrasil supervisor/projector stream-retention owner. The exact 16c4b19f genuine-idle control completed 900 refused pulses with constant state, zero artifacts, flat RSS, and clean direct-PID exits. Exact d303dd1f proves typed completion persists cooldown and restart cannot bypass it, but its live replay exposed a surviving same-turn regrant authority. Source now refuses every schedule/action that already owns any persisted grant; an exact-package replay remains required. Broad session/model/event/tool retention and stable Starfire firewall ownership remain open. Yggdrasil is the small public crossing body, never the release forge. - latest_phase: Exact d303dd1f packaged as warning-free 24-binary release sha256-8e55c6f76dd2cf6ad93393ea99ed98a871370e68f9fe59ae234f5e494481c67d with witness sha256-1834a1f7717d6d12510f3747c5d2a758572e7267d0b766be5c1b0fa0130300e3. Its copied-state run accepted exact typed fulfillment and persisted nextEligibleAtMillis=1786305955374. Self was stopped cleanly 123 seconds before that deadline and restarted from the same store; the fresh process remained sleeping with the exact deadline until expiry. The run then falsified the grant fence: because issuance only refused unconsumed grants plus current prepared/active state, the still-running Heartbeat schedule/action recovered authority after completion and relaunched work under the same turn. Receipts are under .epiphany-run/active-cognition3-d303dd1f and the run is rejected as bounded-turn proof. Source now treats any persisted grant with the same schedule/action as permanent evidence that the turn spent its one grant; later pressure requires a different Heartbeat turn. Twenty-four resident, eight swarm, and eleven heartbeat-state tests pass; packaging and exact replay of this final cut are open. + summary: Epiphany is a supervised engineering alpha on Starfire, not deployment-ready. Exact b8138a6b active-child SIGTERM and restart, exact 9f369528 deterministic warm packaging, exact c930f505 cross-container ownership, exact ed15f83a resident lifecycle retention, and exact 16c4b19f coordinator receipt and Heartbeat artifact retention are proven. Gamecult-ops 059821f makes journald the sole Yggdrasil supervisor/projector stream-retention owner. The exact 16c4b19f genuine-idle control completed 900 refused pulses with constant state, zero artifacts, flat RSS, and clean direct-PID exits. Exact c77824ef proves package authentication, typed completion, and restart-persistent cooldown, but its live replay showed a terminally acknowledged grant could become selectable again after restart. Source now makes terminal acknowledgement the irreversible grant-death authority; another exact-package replay remains required. Broad session/model/event/tool retention and stable Starfire firewall ownership remain open. Yggdrasil is the small public crossing body, never the release forge. + latest_phase: Exact c77824ef packaged as warning-free 24-binary release sha256-e0b7c5cf54c4fb62929d91326c4604e8ad486c59411d6b2509de9182e7a83482 with witness sha256-f923a10c4a96b4301a952c3f874a913535f3165fee531034bbce077811a5629b. A fresh 7,668-file accepted-idle copy matched with zero hash differences. Its exact typed turn completed, persisted nextEligibleAtMillis=1786307607233, and a zero-exit Self restart slept through the deadline. Heartbeat issued no second grant, proving the schedule/action issuance fence. After expiry, however, preparation selected the exact already-completed grant again; diagnostic evidence bound the active lease to the same grant ID while Heartbeat remained on its original turn. Receipts are under .epiphany-run/active-cognition4-c77824ef and the run is rejected. Pending-grant selection and Heartbeat's unconsumed-grant exclusion now treat any ResidentSelfTerminalAck as irreversible closure for its exact grant, even if consumed_at_millis regresses. Twenty-four resident, eight swarm, and eleven heartbeat-state tests pass; packaging and exact replay of this terminal fence are open. operational_state: local_worktree: coordinator_receipt_retention_packaged_proven operator_wireguard: restored @@ -68,8 +68,8 @@ current_status: starfire_linux_modeling_peak: 109887488_bytes_resident_body_plus_modeling_circuit yggdrasil_epiphany_service_contract: repaired_in_gamecult_ops_812b427_not_installed resident_physiology: authenticated_9b8df0b4_c005_bound_to_eyes_tools_nervous_system_with_217dd_and_bd96305e_helpers_running - unresolved_authority: Coordinator receipt, Heartbeat pulse-artifact, deployed supervisor/projector log retention, genuine-idle resource plateau, one exact live typed-fulfillment closure, and restart-persistent cooldown refusal are accepted. The d303 endurance body is rejected as bounded-turn proof because one Heartbeat turn recovered grant authority after its first grant completed. The final same-schedule/action fence is tested source only. Broader semantic/runtime histories remain unbounded pending a typed archived-session owner. Repository Body observation still performs two authenticated full-tree Git index/manifest passes. Execute-mode workers require a persistent process body. Keyed storage has not earned live migration. One Discord consequence remains blocked by the absent Yggdrasil credential. - next_action: Commit and push the same-schedule/action grant fence, package and authenticate that exact source with the persistent Starfire cache, then replay from a fresh accepted-idle copy. Require one Heartbeat schedule/action to issue exactly one grant for its lifetime; later pressure must remain pending until the exact acknowledgement closes that Heartbeat turn and a different schedule/action begins. Reprove restart cooldown, exact typed fulfillment, bounded return to plateau and retention, clean direct-PID exits, and zero external consequence. Preserve active c005. Do not compact session/model/event/tool history until typed archived-session ownership exists. + unresolved_authority: Coordinator receipt, Heartbeat pulse-artifact, deployed supervisor/projector log retention, genuine-idle resource plateau, one exact live typed-fulfillment closure, restart-persistent cooldown refusal, and schedule/action issuance cardinality are accepted. The c778 endurance body is rejected because preparation relaunched its exact terminally acknowledged grant after restart. The terminal-acknowledgement grant-death fence is tested source only. Broader semantic/runtime histories remain unbounded pending a typed archived-session owner. Repository Body observation still performs two authenticated full-tree Git index/manifest passes. Execute-mode workers require a persistent process body. Keyed storage has not earned live migration. One Discord consequence remains blocked by the absent Yggdrasil credential. + next_action: Commit and push terminal-acknowledgement grant death, package and authenticate the exact source, then replay from a fresh accepted-idle copy. Require restart and cooldown expiry to leave the acknowledged grant permanently unselectable; later pressure may launch only from a new grant owned by a different Heartbeat schedule/action after the first acknowledgement closes. Prove bounded plateau/retention, clean direct-PID exits, and zero external consequence. Preserve active c005. Do not compact session/model/event/tool history until typed archived-session ownership exists. active_subgoals: - Prove Persona, Self, Eyes, Modeling, Imagination, Hands, Soul, Mind, Continuity, and nervous-system behavior individually.