From b81b59a7d7531c77d8a9b1429d15d1e26214f757 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 11 Aug 2026 11:31:58 +0200 Subject: [PATCH] Retire superseded model direction grants --- .../admitted_model_direction_consideration.rs | 40 ++-- epiphany-core/src/resident_self.rs | 194 +++++++++++++++++- notes/epiphany-current-algorithmic-map.md | 30 +++ notes/fresh-workspace-handoff.md | 41 ++++ state/map.yaml | 4 +- 5 files changed, 291 insertions(+), 18 deletions(-) diff --git a/epiphany-core/src/admitted_model_direction_consideration.rs b/epiphany-core/src/admitted_model_direction_consideration.rs index 62378839..2445bb4b 100644 --- a/epiphany-core/src/admitted_model_direction_consideration.rs +++ b/epiphany-core/src/admitted_model_direction_consideration.rs @@ -180,20 +180,8 @@ pub fn validate_current_request( cache: &cultcache_rs::CultCache, request: &AdmittedModelDirectionConsiderationRequest, ) -> Result<()> { - if request.schema_version != REQUEST_SCHEMA - || request.contract != REQUEST_CONTRACT - || request.private_state_included - || request.request_id.trim().is_empty() - { - bail!("invalid model direction consideration request"); - } - let model = cache - .get::(crate::MEMORY_GRAPH_KEY)? - .ok_or_else(|| anyhow!("model direction consideration map disappeared"))? - .snapshot()?; - if request.model_revision != model.model_revision - || request.model_hash != crate::memory_graph_model_hash(&model)? - { + validate_request_shape(request)?; + if request_is_superseded(cache, request)? { bail!("model direction consideration request is stale"); } let receipts = cache @@ -211,6 +199,30 @@ pub fn validate_current_request( Ok(()) } +fn validate_request_shape(request: &AdmittedModelDirectionConsiderationRequest) -> Result<()> { + if request.schema_version != REQUEST_SCHEMA + || request.contract != REQUEST_CONTRACT + || request.private_state_included + || request.request_id.trim().is_empty() + { + bail!("invalid model direction consideration request"); + } + Ok(()) +} + +pub fn request_is_superseded( + cache: &cultcache_rs::CultCache, + request: &AdmittedModelDirectionConsiderationRequest, +) -> Result { + validate_request_shape(request)?; + let model = cache + .get::(crate::MEMORY_GRAPH_KEY)? + .ok_or_else(|| anyhow!("model direction consideration map disappeared"))? + .snapshot()?; + Ok(request.model_revision != model.model_revision + || request.model_hash != crate::memory_graph_model_hash(&model)?) +} + pub fn validate_result( request: &AdmittedModelDirectionConsiderationRequest, result: &AdmittedModelDirectionConsiderationResult, diff --git a/epiphany-core/src/resident_self.rs b/epiphany-core/src/resident_self.rs index a54be9b0..24a67e48 100644 --- a/epiphany-core/src/resident_self.rs +++ b/epiphany-core/src/resident_self.rs @@ -1537,6 +1537,27 @@ pub fn verify_resident_self_grant_fulfillment( ) } +fn resident_self_grant_typed_request_is_superseded( + resident_store: &Path, + runtime_store: &Path, + grant_id: &str, +) -> Result { + let grant = state_cache(resident_store)? + .get::(grant_id)? + .ok_or_else(|| anyhow!("resident Self supersession check lost its grant"))?; + let Some(crate::RuntimeTypedRequestRef::AdmittedModelDirection(request_id)) = + resident_self_typed_request_ref(&grant)? + else { + return Ok(false); + }; + let mut runtime = crate::runtime_spine_cache(runtime_store)?; + runtime.pull_all_backing_stores()?; + let request = runtime + .get::(request_id)? + .ok_or_else(|| anyhow!("model direction supersession check lost its request"))?; + crate::admitted_model_direction_consideration::request_is_superseded(&runtime, &request) +} + fn resident_self_typed_request_ref<'a>( grant: &'a ResidentSelfHeartbeatGrant, ) -> Result>> { @@ -1803,6 +1824,24 @@ pub fn settle_resident_self_exited_coordinator( ) -> Result { validate_resident_self_coordinator_receipt_binding(lease, receipt)?; let typed = resident_self_grant_has_typed_request(resident_store, &lease.grant_id)?; + if typed + && resident_self_grant_typed_request_is_superseded( + resident_store, + runtime_store, + &lease.grant_id, + )? + { + complete_resident_self_turn_with_terminal( + resident_store, + lease, + &receipt.receipt_id, + "superseded", + now_millis, + cooldown_seconds, + false, + )?; + return Ok(ResidentSelfOutcome::Completed); + } let typed_attempt = typed && resident_self_typed_attempt_exists(resident_store, runtime_store, &lease.grant_id)?; let successful_receipt = matches!( @@ -1903,7 +1942,22 @@ pub fn settle_resident_self_exited_coordinator( }) } Err(error) => { - if typed_attempt { + let superseded = resident_self_grant_typed_request_is_superseded( + resident_store, + runtime_store, + &lease.grant_id, + )?; + if superseded { + complete_resident_self_turn_with_terminal( + resident_store, + lease, + &receipt.receipt_id, + "superseded", + now_millis, + cooldown_seconds, + false, + )?; + } else if typed_attempt { complete_resident_self_turn_with_terminal( resident_store, lease, @@ -1922,7 +1976,11 @@ pub fn settle_resident_self_exited_coordinator( now_millis, )?; } - Ok(ResidentSelfOutcome::Failed) + Ok(if superseded { + ResidentSelfOutcome::Completed + } else { + ResidentSelfOutcome::Failed + }) } Ok(ResidentSelfGrantFulfillment::Fulfilled) => { complete_resident_self_turn_with_terminal( @@ -3986,6 +4044,138 @@ mod tests { Ok(()) } + #[test] + fn superseded_model_direction_request_terminalizes_without_requeue() -> 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(); + policy.runtime_store = temp.path().join("runtime.cc"); + policy.artifact_root = temp.path().join("artifacts"); + seed_model_direction_request( + &policy.runtime_store, + "request-superseded", + "cognitive-runtime", + "implementation-thread-superseded", + )?; + enqueue_resident_self_pressure(&store, &ResidentSelfPressure { + schema_version: RESIDENT_SELF_PRESSURE_SCHEMA_VERSION.into(), + pressure_id: "pressure-superseded".into(), + kind: "admitted-model-direction-consideration".into(), + provenance_ref: "cultcache://admitted-model-direction-consideration/request-superseded".into(), + objective: "Consider the exact admitted model direction.".into(), + created_at_millis: 1, + status: "pending".into(), + consumed_by_grant_id: None, + private_state_exposed: false, + })?; + let grant = heartbeat_issue_resident_self_grant( + &store, + "heartbeat-superseded", + "action-superseded", + 2, + )?.expect("superseded request grant"); + let prepared = prepare_resident_self_launch(&store, &policy, 3)? + .expect("superseded request 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, + 4, + )?; + + let mut runtime = crate::runtime_spine_cache(&policy.runtime_store)?; + runtime.pull_all_backing_stores()?; + let mut advanced = crate::runtime_current_repo_model(&policy.runtime_store)? + .expect("current model fixture"); + advanced.model_revision += 1; + let expected_model = runtime.snapshot_envelopes().into_iter().find(|entry| { + entry.r#type == crate::EpiphanyMemoryGraphEntry::TYPE + && entry.key == crate::MEMORY_GRAPH_KEY + }).expect("current model envelope"); + let (advanced_entry, _) = runtime.prepare_entry( + crate::MEMORY_GRAPH_KEY, + &crate::EpiphanyMemoryGraphEntry::from_snapshot(&advanced)?, + )?; + assert!(SingleFileMessagePackBackingStore::new(&policy.runtime_store) + .compare_and_swap_entry(&expected_model, advanced_entry)?); + assert!(resident_self_grant_typed_request_is_superseded( + &store, + &policy.runtime_store, + &grant.grant_id, + )?); + + let receipt = crate::EpiphanyCoordinatorRunReceipt { + schema_version: crate::COORDINATOR_RUN_RECEIPT_SCHEMA_VERSION.into(), + receipt_id: "coordinator-superseded".into(), + session_id: crate::coordinator_run_session_id( + &lease.turn_id, + Some(&lease.launch_digest), + )?, + thread_id: lease.turn_id.clone(), + mode: "plan".into(), + status: "planned".into(), + final_action: "waitForImaginationResult".into(), + final_reason: None, + step_count: 1, + created_at: "2026-07-18T00:00:01Z".into(), + model_provider: Some("local".into()), + runtime_store: policy.runtime_store.display().to_string(), + artifact_refs: vec![], + sealed_artifact_refs: vec![], + metadata: Default::default(), + resident_grant_id: Some(lease.grant_id.clone()), + resident_launch_digest: Some(lease.launch_digest.clone()), + resident_policy_digest: Some(lease.policy_digest.clone()), + resident_argv_digest: Some(lease.argv_digest.clone()), + resident_objective_digest: Some(lease.objective_digest.clone()), + resident_release_commit: Some(lease.release_commit.clone()), + resident_release_manifest_digest: Some(lease.release_manifest_digest.clone()), + resident_executable_digest: Some(lease.coordinator_executable_digest.clone()), + }; + assert_eq!(settle_resident_self_exited_coordinator( + &store, + &policy.runtime_store, + &lease, + &receipt, + false, + false, + false, + 5, + policy.cooldown_seconds, + )?, ResidentSelfOutcome::Completed); + assert!(load_resident_self_state(&store)?.active_turn.is_none()); + let pressure = resident_self_pressures(&store)?.into_iter() + .find(|pressure| pressure.pressure_id == "pressure-superseded") + .expect("superseded pressure"); + assert_eq!(pressure.status, "consumed"); + assert_eq!(pressure.consumed_by_grant_id.as_deref(), Some(grant.grant_id.as_str())); + let terminal = state_cache(&store)? + .get::(&grant.grant_id)? + .expect("superseded terminal grant"); + assert_eq!(terminal.terminal_status.as_deref(), Some("superseded")); + let ack = pending_resident_self_acks(&store)?.into_iter() + .find(|ack| ack.grant_id == grant.grant_id) + .expect("superseded terminal acknowledgement"); + assert_eq!(ack.coordinator_receipt_id, receipt.receipt_id); + assert_eq!(ack.terminal_status, "superseded"); + assert!(heartbeat_issue_resident_self_grant( + &store, + "heartbeat-after-supersession", + "action-after-supersession", + 6, + )?.is_none(), "superseded typed authority must not requeue"); + Ok(()) + } + #[test] fn plain_objective_uses_mounted_runtime_identity_for_thread_and_argv() -> Result<()> { let temp = tempfile::tempdir()?; diff --git a/notes/epiphany-current-algorithmic-map.md b/notes/epiphany-current-algorithmic-map.md index efa4e04d..8a16da6b 100644 --- a/notes/epiphany-current-algorithmic-map.md +++ b/notes/epiphany-current-algorithmic-map.md @@ -3990,3 +3990,33 @@ state is now the sole final-action owner for these review paths. second exact braked process start held the same authority/hashes at 0.36% sampled CPU and exited zero again, proving startup stewardship without resurrection. + +## Superseded admitted-model-direction authority + +- Owner: runtime RepoModel owns whether an + `AdmittedModelDirectionConsiderationRequest` still names the current exact + model revision and hash. Resident Self owns terminalization of the exact + Heartbeat grant; neither scheduler timing nor coordinator prose decides + supersession. +- Inputs: a structurally valid typed request, current RepoModel snapshot, exact + resident grant and active lease, and the exact bound coordinator receipt. +- Outputs: a superseded request terminalizes that exact grant once with status + `superseded` and the real receipt ID. The consumed pressure stays consumed; + failure count does not advance and Heartbeat cannot issue a replacement + grant from the dead authority. +- Derived state: request age, the `stale` error text, cooldown, receipt action, + and operator projection are observations only. +- Forbidden writers: resident retry policy, error-string parsing, Heartbeat + cadence, and a generic stale-work cleanup pass cannot decide typed request + death or create a retry. +- Shared paths: settlement checks supersession before fulfillment and checks it + again after a failed fulfillment read, covering a concurrent RepoModel + advance without weakening the ordinary exact-result verifier. +- Cut line: the old invalid-fulfillment cancellation path no longer requeues a + structurally valid request whose model binding has been superseded. Historical + `epiphany-work` acceptance remains inert and is not a fallback workflow. +- Verification: focused source proof passes 31 resident tests, four + admitted-model-direction contract tests, and all eight swarm tests. Exact + Linux packaging and copied-state replay remain open; acceptance requires one + superseded terminal acknowledgement, no regrant, and zero external + consequence. diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 600fc837..85d1f252 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -3424,6 +3424,47 @@ strict ingress decoder as one ownership boundary. Remove the cause of duplicate top-level fields without weakening admission or adding a repair parser. Repeat the copied proposal and require first-attempt completion, exact one-grant terminalization, and zero external consequence. Yggdrasil never builds. + +## Copied frontier turnover exposed stale typed-request resurrection — 2026-08-11 + +Actual c006 remains exact `c9a2a979`, alive and cognitively braked. A stopped +copy of exact accepted `d4907ee8` state accepted proposal +`proposal-close-organ-loop-plan-reconcile-20260811`, issued one proposal +Modeling grant, admitted its first result, and settled its downstream review. +The Modeling transaction advanced RepoModel while an older +`AdmittedModelDirectionConsiderationRequest` still named the prior exact model +revision and hash. Its coordinator then failed with `model direction +consideration request is stale`. Restart recovery requeued and relaunched the +same impossible typed pressure until the copied brake was engaged. Both copied +owners stopped cleanly; actual c006 was untouched. Receipts and before/after +hashes are under `.epiphany-run/frontier-turnover-d4907ee8-plan-reconcile`. + +Owner map: runtime RepoModel owns whether an admitted-model-direction request +has been superseded; resident Self owns terminalization of the exact grant. +Inputs are the structurally valid request, its bound revision/hash, the current +RepoModel, exact resident lease, and exact coordinator receipt. The output for +a superseded request is one terminal grant and acknowledgement with status +`superseded`, using the real coordinator receipt ID. Failure counters, pressure +requeue, retries, and new grants are forbidden outputs. Receipt text, error +strings, cooldown, and pulse timing are observations, not supersession owners. + +Source now exposes the narrow runtime-owned supersession predicate and checks it +at resident settlement, including the race where the model advances during +fulfillment verification. Focused proof passes 31 resident tests, four +admitted-model-direction tests, and all eight swarm tests. Packaging and exact +copied-state replay remain required before acceptance. + +The attempted fresh `epiphany-repo-work-order-family-smoke` was rejected as an +active readiness path. Its historical `epiphany-work` mutation surface is +deliberately inert and refuses acceptance; runtime-spine RepoModel/RepoFrontier +is the canonical live workflow. Do not restore a second repo-swarm owner or +revive the old scheduler to make archaeological smokes green. + +Next: commit and push the bounded source/Mind cut, package the exact commit on +Starfire, then replay copied state. Require one superseded terminal grant and +acknowledgement, no failure count, no requeue or regrant, zero external +consequence, and clean shutdown. Then inspect the next canonical typed action. +Yggdrasil never builds. ## Failed outer-worker attempt retention cut in source — 2026-08-10 Runtime spine now owns `EpiphanyArchivedRuntimeWorkerAttempt` for failed or diff --git a/state/map.yaml b/state/map.yaml index 636ac01d..b68f564b 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -36,7 +36,7 @@ invariants: 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, exact 16c4b19f coordinator receipt and Heartbeat artifact retention, exact cce2b8ac narrow model-generation retention, exact eea15e82 model-turn JSON ingress, exact b1e8c89a semantic unattempted-generation retention, exact 6bc3ec3f semantic physical-epoch retirement, and exact 44230a05 Persona conversation retention are proven. Gamecult-ops 059821f owns Yggdrasil stream retention and exact 6ee08a4 owns stable Starfire Persona-permit firewall ingress. Exact 16c4b19f genuine idle and exact a987d2f7 active cognition completed 900-pulse bounded plateaus. Runtime-owned typed fulfillment is accepted live under exact 6dd9b132. Yggdrasil is the small public crossing body, never the release forge. - latest_phase: Actual c006 remains exact c9a2a979, alive and cognitively braked. Its eight-hour endurance exposed 9-24% resident CPU spikes at one-second shakedown cadence without authority drift. Exact pushed 3f37503e blocks repository/domain/continuation cognition ingress under brake while preserving exact active/prepared child reconciliation; copied braked CPU fell to 0.29-0.33%. Exact pushed f04abd6b makes retention maintenance run on startup, resident revision change, or a bounded 60-second deadline rather than every poll. Exact Linux release sha256-544b95404d9445b2af0fdd67495bcff5f284ab2d2a29e16450e90d50f72a3f84 with witness sha256-79639e35da79f7038111234fa33e21829e88eddcb77eb702f8f53f5369e9def3 passed 24-binary inspection with zero warnings and warm Cargo 4.33s. On copied 23 MiB state, released sleeping Self at five-second cadence used 91 process clock ticks over 30 seconds (about 3.0% of one core), held revision 66 with no grant and exact runtime hash, restored the brake, and exited zero. A second exact braked process start held the same revision/hashes with no grant at 0.36% sampled CPU and exited zero, proving restart without resurrection. Live Yggdrasil reinspection confirms the Persona mouth is healthy/listening but its root-managed delivery credential remains absent or empty; no owned alternate bot token was found. Actual c006 was untouched. + latest_phase: Actual c006 remains exact c9a2a979, alive and cognitively braked. Canonical copied turnover from d4907ee8 accepted one proposal Modeling result and terminal review, then exposed an admitted-model-direction request whose exact RepoModel revision/hash had been superseded by the Modeling transaction. The old settlement path requeued that impossible typed authority and relaunched it after restart. Runtime RepoModel now owns the typed supersession predicate; resident Self terminalizes the exact grant as superseded with the exact coordinator receipt, without failure count or pressure requeue. Thirty-one resident tests, four admitted-model-direction contract tests, and eight swarm tests pass. The cut is source-proven but not yet packaged or replayed on copied state. Historical repo-work family smokes are not a live readiness gate: their mutating epiphany-work path is sealed archaeology, while runtime-spine RepoModel/RepoFrontier owns the canonical workflow. Actual c006 was untouched. Yggdrasil never builds. operational_state: local_worktree: exact_acd91e6e_imagination_runtime_owned_causality_live_accepted operator_wireguard: restored @@ -70,7 +70,7 @@ current_status: yggdrasil_epiphany_service_contract: repaired_in_gamecult_ops_812b427_not_installed resident_physiology: c006_exact_c9a2a979_alive_braked_revision_34_after_two_receipt_bound_continuation_grants unresolved_authority: Coordinator receipt, Heartbeat pulse-artifact, genuine-idle and active resource plateaus, exact-grant terminality, restart-persistent cooldown refusal, schedule/action issuance cardinality, runtime-owned typed fulfillment, all three packaged fulfilled-before-receipt lanes, genuine packaged Imagination option generation, narrow model-generation retention, published model-turn JSON ingress, semantic logical/physical retention, Persona conversation retention, stable Starfire firewall ownership, completed model-adapter session archival, normal coordinator lifecycle opening/error closure/legacy repair/archival, co-resident resident lifecycle retention, authenticated outer-worker attempt retention, deployed supervisor/projector journald ownership, Docker named-volume atomic snapshot visibility, and deterministic incremental release construction are accepted. Starfire's Docker Desktop F: bind is rejected for mutable authority after an exact packaged lockless reader observed an empty published snapshot during writer interruption. Historical migrated semantic attempts without recorded physical namespace remain durable and non-retirable. One completed Discord consequence remains blocked by the absent Yggdrasil credential. Exact aa841873 also makes legacy coordinator repair one full-snapshot transaction so a later hostile family cannot leave an earlier partial repair. - next_action: Keep actual c006 exact c9a2a979 alive under its cognitive brake. Treat exact f04abd6b resident maintenance/ingress cadence and exact d4907ee8 proposal single-consumption review as accepted. Persona public consequence remains an external credential decision; do not fabricate or borrow a bot identity. Continue the copied autonomous turnover from typed awaitFrontierProposal or select the next still-partial organ without recreating consumed proposal/review authority. Preserve zero external consequence. Yggdrasil never builds. + next_action: Keep actual c006 exact c9a2a979 alive under its cognitive brake. Commit and push the source-proven superseded model-direction grant cut, package that exact commit with the persistent Starfire cache, and replay only on copied state. Require one exact superseded terminal grant and acknowledgement, the real coordinator receipt ID, no failure count, no pressure requeue or new grant, zero external consequence, and clean owner shutdown. Then inspect the next canonical RepoFrontier typed action; do not revive historical epiphany-work mutation or its stale family smokes. Persona public consequence remains an external credential decision. Yggdrasil never builds. active_subgoals: - Prove Persona, Self, Eyes, Modeling, Imagination, Hands, Soul, Mind, Continuity, and nervous-system behavior individually.