From c77824ef05714d005834eea217f942651ce9c97c Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 9 Aug 2026 21:17:30 +0100 Subject: [PATCH] Fence resident grant authority for heartbeat turn lifetime --- epiphany-core/src/resident_self.rs | 42 +++++++++++++---------- notes/epiphany-current-algorithmic-map.md | 15 ++++---- notes/fresh-workspace-handoff.md | 27 +++++++++++++++ state/map.yaml | 8 ++--- 4 files changed, 63 insertions(+), 29 deletions(-) diff --git a/epiphany-core/src/resident_self.rs b/epiphany-core/src/resident_self.rs index dcd44136..42665161 100644 --- a/epiphany-core/src/resident_self.rs +++ b/epiphany-core/src/resident_self.rs @@ -1096,11 +1096,12 @@ pub fn heartbeat_issue_resident_self_grant( if state.active_turn.is_some() || state.prepared_launch.is_some() { return Ok(None); } - if cache - .get_all::()? - .iter() - .any(|grant| grant.consumed_at_millis.is_none()) - { + 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) + }) { return Ok(None); } let mut pending = cache @@ -1116,8 +1117,7 @@ pub fn heartbeat_issue_resident_self_grant( let Some(mut pressure) = pending.into_iter().next() else { return Ok(None); }; - let attempt_ordinal = cache - .get_all::()? + let attempt_ordinal = grants .iter() .filter(|grant| grant.pressure_id == pressure.pressure_id) .count() @@ -1162,12 +1162,10 @@ pub fn heartbeat_issue_resident_self_grant( let (pressure_entry, _) = cache.prepare_entry(&pressure.pressure_id, &pressure)?; let (grant_entry, _) = cache.prepare_entry(&grant.grant_id, &grant)?; let (state_entry, _) = cache.prepare_entry(RESIDENT_SELF_STATE_KEY, &state)?; - if !SingleFileMessagePackBackingStore::new(path) - .compare_and_swap_batch( - &[expected_state, expected_pressure], - vec![state_entry, pressure_entry, grant_entry], - )? - { + if !SingleFileMessagePackBackingStore::new(path).compare_and_swap_batch( + &[expected_state, expected_pressure], + vec![state_entry, pressure_entry, grant_entry], + )? { return Err(anyhow!( "heartbeat lost resident Self pressure-to-grant CAS" )); @@ -2630,8 +2628,7 @@ mod tests { }, )?; assert!( - heartbeat_issue_resident_self_grant(&store, "heartbeat-1", "action-1", 5)? - .is_none(), + heartbeat_issue_resident_self_grant(&store, "heartbeat-1", "action-1", 5)?.is_none(), "one Heartbeat coordinator turn cannot issue a companion grant while Self is prepared" ); assert!(prepare_resident_self_launch(&store, &policy, 5)?.is_none()); @@ -2649,8 +2646,7 @@ mod tests { acknowledge_resident_self_launch(&store, &prepared.preparation_id, &process, 6)?; assert_eq!(lease.grant_id, grant.grant_id); assert!( - heartbeat_issue_resident_self_grant(&store, "heartbeat-1", "action-1", 7)? - .is_none(), + heartbeat_issue_resident_self_grant(&store, "heartbeat-1", "action-1", 7)?.is_none(), "one Heartbeat coordinator turn cannot issue a companion grant while Self is active" ); assert_eq!( @@ -2777,6 +2773,10 @@ mod tests { private_state_exposed: false, }; enqueue_resident_self_pressure(&store, &later_pressure)?; + assert!( + heartbeat_issue_resident_self_grant(&store, "heartbeat-1", "action-1", 11)?.is_none(), + "completion cannot reopen grant authority for the same Heartbeat turn" + ); heartbeat_issue_resident_self_grant(&store, "heartbeat-later", "action-later", 12)? .expect("later Heartbeat grant"); assert!(prepare_resident_self_launch(&store, &policy, 10_009)?.is_none()); @@ -3145,9 +3145,13 @@ mod tests { .expect("requeued pressure"); assert_eq!(pressure.status, "pending"); assert_eq!(pressure.consumed_by_grant_id, None); + assert!( + heartbeat_issue_resident_self_grant(&store, "heartbeat-1", "action-1", 7)?.is_none(), + "a terminal acknowledgement ends grant authority for its Heartbeat turn" + ); let retry_grant = - heartbeat_issue_resident_self_grant(&store, "heartbeat-1", "action-1", 7)? - .expect("retry grant"); + heartbeat_issue_resident_self_grant(&store, "heartbeat-2", "action-2", 8)? + .expect("later Heartbeat turn retry grant"); assert_eq!(retry_grant.pressure_id, first_grant.pressure_id); assert_ne!(retry_grant.grant_id, first_grant.grant_id); assert!(retry_grant.grant_id.contains("-attempt-2-")); diff --git a/notes/epiphany-current-algorithmic-map.md b/notes/epiphany-current-algorithmic-map.md index 2a057aaa..648912e9 100644 --- a/notes/epiphany-current-algorithmic-map.md +++ b/notes/epiphany-current-algorithmic-map.md @@ -1369,13 +1369,16 @@ grant before that deadline, so `serve`, `once`, and crash/restart do not need separate cooldown opinions. One Heartbeat coordinator turn owns at most one resident grant. Grant issuance -first refuses any prepared or active Self authority, then atomically advances +first loads every persisted grant and refuses if any grant already names the +requesting schedule/action, whether consumed or not. It also refuses any other +unconsumed grant plus prepared or active Self authority, then atomically advances the singleton `ResidentSelfState` revision with the exact pressure-to-grant -transition. That state envelope is the cardinality fence: two pressures cannot -be issued under one schedule/action after the first grant has been consumed by -preparation, and concurrent issuers cannot win disjoint pressure CASes. Pressure -arriving during a prepared or active turn stays pending until Heartbeat closes -the exact acknowledgement and schedules a later coordinator turn. +transition. Persisted grant identity is the lifetime cardinality fence; the +state-envelope CAS is the concurrency fence. Completion, cancellation, cooldown +expiry, restart, or later pressure cannot restore grant authority to the same +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. Imagination candidate time is part of that causal contract. A candidate must have a valid RFC3339 timestamp at or after its request timestamp. A diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 74c383b2..f3bb9a46 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -1288,3 +1288,30 @@ the shared preparation primitive. A fresh post-completion call with a committed later grant now refuses at deadline minus one and prepares exactly at the deadline. Package latest source containing both `90648073` and `ee05d9bb`; never resume or publish the stopped de2e8ad5 build. + +Exact `d303dd1f` then packaged as warning-free 24-binary release +`sha256-8e55c6f76dd2cf6ad93393ea99ed98a871370e68f9fe59ae234f5e494481c67d` +with witness +`sha256-1834a1f7717d6d12510f3747c5d2a758572e7267d0b766be5c1b0fa0130300e3`. +Receipts are under `.epiphany-run/active-cognition3-d303dd1f`. Exact typed +fulfillment persisted `nextEligibleAtMillis=1786305955374`. Self stopped zero +123 seconds before that deadline, restarted against the same resident store, +and remained sleeping with the exact deadline through expiry. Cooldown ownership +and restart refusal are accepted. + +The same run exposed the remaining cardinality fault. Once completion removed +prepared/active Self authority, repeated pulses of the still-running Heartbeat +schedule/action could issue again because the grant fence remembered only +unconsumed grants, not that this turn had already spent its grant. Work launched +again under `epiphany-active-cognition3-d303dd1f.serve-000131` / +`heartbeat.coordinator.work`. The copied run was stopped and rejected; immutable +logs and `run-invalidated.txt` preserve the intervention. + +The source cut now makes the persisted grant set the lifetime fence: if any +grant already names the requesting schedule/action, issuance returns none +regardless of consumption, resident idleness, cooldown expiry, cancellation, or +later pressure. Cancellation retry moves to a different Heartbeat turn; the old +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. diff --git a/state/map.yaml b/state/map.yaml index 8e268715..1ab35442 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 e09104a7 proved live typed fulfillment and exposed two continuity faults; pushed 90648073 repairs their source ownership, but 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 e09104a7 packaged as warning-free 24-binary release sha256-40d4971a3b7ecf4debf558621b80c6384c6c1a155971e42aecf44bf05d13e418 with witness sha256-5f68e73e0b9ad2dff7e7cfa912455bd7e27f1a653c2a2eecd8bf5a012f146c68. Its 900-pulse copied-state active run launched the valid cognitive-runtime request, retained Self authority after coordinator exit, accepted exact typed fulfillment, and exited Heartbeat/Self zero. The run then falsified cooldown and grant exclusion: terminal completion left nextEligibleAtMillis zero, and Heartbeat issued later pressure under the still-open schedule after the first grant was consumed. Three turns ran where one bounded turn plus cooldown was intended. Commit 90648073 atomically persists the cooldown deadline and makes grant issuance contend on ResidentSelfState while refusing prepared or active authority. Pre-package inspection then found preparation did not read the persisted deadline; invalid-source package de2e8ad5 was stopped. Commit ee05d9bb makes the shared preparation primitive refuse before nextEligibleAtMillis and proves a fresh read cannot consume a committed later grant early. Twenty-four resident and eight swarm tests pass; exact packaging and live replay 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 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. 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, and one exact live typed-fulfillment closure are accepted. The e091 endurance body is rejected as bounded-turn proof because one Heartbeat turn issued multiple sequential grants and persisted no cooldown. Commits 90648073 and ee05d9bb are 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: Package and authenticate exact latest source containing 90648073 plus ee05d9bb with the persistent Starfire cache. From a fresh accepted-idle copy, replay active cognition and require one Heartbeat schedule to issue exactly one grant; later pressure must remain pending until the first typed acknowledgement closes and the persisted cooldown expires. Prove restart cannot bypass nextEligibleAtMillis, one exact result closes one exact grant, return-to-plateau and retention are bounded, both direct-PID bodies exit zero, and no external consequence occurs. 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, 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. active_subgoals: - Prove Persona, Self, Eyes, Modeling, Imagination, Hands, Soul, Mind, Continuity, and nervous-system behavior individually.