From a70fe275195740ecefc2984b32ebd8ae93658c18 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 19 Jul 2026 03:57:46 +0100 Subject: [PATCH] Authenticate multi-generation workspace recovery --- .../src/bin/epiphany-daemon-supervisor.rs | 50 ++----- epiphany-core/src/lib.rs | 1 + .../workspace_coverage_process_documents.rs | 131 ++++++++++++++++-- .../src/workspace_coverage_projector.rs | 22 ++- notes/fresh-workspace-handoff.md | 21 +++ state/map.yaml | 3 +- 6 files changed, 175 insertions(+), 53 deletions(-) diff --git a/epiphany-core/src/bin/epiphany-daemon-supervisor.rs b/epiphany-core/src/bin/epiphany-daemon-supervisor.rs index c85f40c4..5da8e07c 100644 --- a/epiphany-core/src/bin/epiphany-daemon-supervisor.rs +++ b/epiphany-core/src/bin/epiphany-daemon-supervisor.rs @@ -58,9 +58,9 @@ use epiphany_core::{ ProcessInstanceIdentity, ProcessInstanceObservation, WORKSPACE_COVERAGE_PROCESS_LAUNCH_SCHEMA_VERSION, WorkspaceCoverageManagedProcessLaunchEntry, WorkspaceCoverageProcessBootstrap, WorkspaceCoverageProcessLifecycleObservation, - authenticate_historical_workspace_coverage_managed_process_launch, authenticate_recovery_workspace_coverage_claim_sight, authenticate_workspace_coverage_managed_process_launch, + authenticate_workspace_coverage_replacement_lineage, authenticate_workspace_coverage_provider_heartbeat, authenticate_workspace_coverage_termination_with_envelope_digest, capture_process_instance, load_latest_workspace_coverage_managed_process_launch, @@ -2469,35 +2469,19 @@ fn reconcile_workspace_coverage_projector( .clone() .context("workspace coverage mismatch lost its authenticated claim target")?; let in_flight = (|| -> Result<_> { - let (termination, termination_digest) = - authenticate_workspace_coverage_termination_with_envelope_digest( - &args.store, - args.runtime_id.clone(), - &old_target.launch_id, - host.entry(), - )?; - authenticate_historical_workspace_coverage_managed_process_launch( - &args.store, - args.runtime_id.clone(), - &old_target.launch_id, - host.entry(), - )?; let replacement = authenticate_workspace_coverage_managed_process_launch( &args.store, args.runtime_id.clone(), &latest.launch_id, host.entry(), )?; - if replacement.replaces_launch_id.as_deref() != Some(old_target.launch_id.as_str()) - || replacement.replaces_termination_id.as_deref() - != Some(termination.termination_id.as_str()) - || replacement.replaces_termination_envelope_digest.as_deref() - != Some(termination_digest.as_str()) - { - anyhow::bail!( - "latest launch is not the exact authenticated in-flight replacement lineage" - ); - } + authenticate_workspace_coverage_replacement_lineage( + &args.store, + &args.runtime_id, + &old_target.launch_id, + &latest.launch_id, + host.entry(), + )?; Ok(replacement) })(); if let Ok(replacement) = in_flight { @@ -2559,6 +2543,9 @@ fn reconcile_workspace_coverage_projector( } } } + let lineage_error = in_flight + .expect_err("workspace coverage mismatch branch lost its lineage error") + .to_string(); println!( "{}", serde_json::to_string_pretty(&json!({ @@ -2566,7 +2553,7 @@ fn reconcile_workspace_coverage_projector( "status": "observation-refused", "serviceId": policy.service_id, "launchId": latest.launch_id, - "reason": "authenticated claim sight does not name the current managed launch", + "reason": lineage_error, "restarted": false, "privateStateExposed": false, }))? @@ -4455,9 +4442,7 @@ mod semantic_projector_authority_tests { assert!(observation + termination < launch && launch < readiness && readiness < recovery); assert!(body.contains("write_workspace_coverage_process_termination_observation")); assert!(body.contains("status == \"ready\"")); - assert!( - body.contains("authenticated claim sight does not name the current managed launch") - ); + assert!(body.contains("authenticate_workspace_coverage_replacement_lineage")); assert!(!body.contains("awaiting-exact-termination")); assert!(!body.contains("open_workspace_coverage_authority")); assert!(!body.contains("recover_workspace_coverage_projection")); @@ -4524,22 +4509,15 @@ mod semantic_projector_authority_tests { .find("\n let observation = match observe_workspace_coverage_managed_process") .unwrap(); let branch = &body[mismatch..normal_observation]; - let termination = branch - .find("authenticate_workspace_coverage_termination_with_envelope_digest") - .unwrap(); - let old_launch = branch - .find("authenticate_historical_workspace_coverage_managed_process_launch") - .unwrap(); let replacement = branch .find("let replacement = authenticate_workspace_coverage_managed_process_launch") .unwrap(); let lineage = branch - .find("replacement.replaces_termination_envelope_digest") + .find("authenticate_workspace_coverage_replacement_lineage") .unwrap(); let resume = branch .find("return finish_workspace_coverage_recovery") .unwrap(); - assert!(termination < old_launch && old_launch < replacement); assert!(replacement < lineage && lineage < resume); assert!(!branch.contains("replacement.policy_envelope_digest != old_launch")); assert!(!branch.contains("service_launch_internal")); diff --git a/epiphany-core/src/lib.rs b/epiphany-core/src/lib.rs index e9937fe3..e3d9c766 100644 --- a/epiphany-core/src/lib.rs +++ b/epiphany-core/src/lib.rs @@ -1244,6 +1244,7 @@ pub use workspace_coverage_process_documents::{ authenticate_historical_workspace_coverage_managed_process_launch, authenticate_recovery_workspace_coverage_claim_sight, authenticate_workspace_coverage_managed_process_launch, + authenticate_workspace_coverage_replacement_lineage, authenticate_workspace_coverage_process_termination_observation, authenticate_workspace_coverage_provider_heartbeat, authenticate_workspace_coverage_termination_with_envelope_digest, diff --git a/epiphany-core/src/workspace_coverage_process_documents.rs b/epiphany-core/src/workspace_coverage_process_documents.rs index 058eb028..7a47c3c1 100644 --- a/epiphany-core/src/workspace_coverage_process_documents.rs +++ b/epiphany-core/src/workspace_coverage_process_documents.rs @@ -1233,6 +1233,79 @@ pub(crate) fn authenticate_historical_workspace_coverage_managed_process_launch_ Ok((launch, envelope_digest(&envelope))) } +pub fn authenticate_workspace_coverage_replacement_lineage( + store_path: impl AsRef, + runtime_id: &str, + old_launch_id: &str, + replacement_launch_id: &str, + host_identity: &HostIncarnationIdentityEntry, +) -> Result<()> { + let store_path = store_path.as_ref(); + if old_launch_id == replacement_launch_id { + bail!("workspace coverage replacement lineage did not advance"); + } + authenticate_historical_workspace_coverage_managed_process_launch( + store_path, + runtime_id.to_string(), + old_launch_id, + host_identity, + )?; + let mut cursor = replacement_launch_id.to_string(); + let mut visited = std::collections::BTreeSet::new(); + loop { + if !visited.insert(cursor.clone()) { + bail!("workspace coverage replacement lineage contains a cycle"); + } + let child = if cursor == replacement_launch_id { + authenticate_workspace_coverage_managed_process_launch( + store_path, + runtime_id.to_string(), + &cursor, + host_identity, + )? + } else { + authenticate_historical_workspace_coverage_managed_process_launch( + store_path, + runtime_id.to_string(), + &cursor, + host_identity, + )? + }; + let parent_id = child + .replaces_launch_id + .as_deref() + .ok_or_else(|| anyhow!("workspace coverage replacement lineage ended before the claimed launch"))?; + let (termination, termination_digest) = + authenticate_workspace_coverage_termination_with_envelope_digest( + store_path, + runtime_id.to_string(), + parent_id, + host_identity, + )?; + if child.replaces_termination_id.as_deref() != Some(termination.termination_id.as_str()) + || child.replaces_termination_envelope_digest.as_deref() + != Some(termination_digest.as_str()) + { + bail!("workspace coverage replacement lineage has a broken termination edge"); + } + let terminated_at = chrono::DateTime::parse_from_rfc3339(&termination.observed_at_utc)?; + let launched_at = chrono::DateTime::parse_from_rfc3339(&child.launched_at_utc)?; + if terminated_at >= launched_at { + bail!("workspace coverage replacement lineage violates termination ordering"); + } + if parent_id == old_launch_id { + return Ok(()); + } + authenticate_historical_workspace_coverage_managed_process_launch( + store_path, + runtime_id.to_string(), + parent_id, + host_identity, + )?; + cursor = parent_id.to_string(); + } +} + pub fn observe_workspace_coverage_managed_process( store_path: impl AsRef, runtime_id: impl Into, @@ -2300,6 +2373,13 @@ pub fn write_workspace_coverage_recovery_directive( replacement_launch_id, host.entry(), )?; + authenticate_workspace_coverage_replacement_lineage( + local_verse_store, + runtime_id, + &claim_sight.launch_id, + replacement_launch_id, + host.entry(), + )?; let (ready, ready_digest) = authenticate_workspace_coverage_provider_heartbeat_with_envelope_digest( local_verse_store, @@ -2307,10 +2387,7 @@ pub fn write_workspace_coverage_recovery_directive( replacement_ready_heartbeat_id, host.entry(), )?; - if replacement.replaces_launch_id.as_deref() != Some(claim_sight.launch_id.as_str()) - || replacement.replaces_termination_id.as_deref() - != Some(termination.termination_id.as_str()) - || ready.launch_id != replacement.launch_id + if ready.launch_id != replacement.launch_id || ready.status != "ready" { bail!("workspace coverage recovery directive evidence is not an exact ready replacement"); @@ -4432,6 +4509,42 @@ mod tests { ); assert_eq!(std::fs::read(&body_store)?, body_before_refusal); + let intermediate_provider = provider_key(); + let mut intermediate = launch( + &policy, + envelope_digest(&policy_envelope), + &host, + &intermediate_provider, + )?; + intermediate.replaces_launch_id = Some(old_launch.launch_id.clone()); + intermediate.replaces_termination_id = Some(termination.termination_id.clone()); + intermediate.replaces_termination_envelope_digest = Some(termination_digest); + sign_workspace_coverage_launch(&mut intermediate, &host)?; + write_workspace_coverage_managed_process_launch( + &verse, + "local", + intermediate.clone(), + host.entry(), + )?; + let intermediate_source = FakeObservation { + boot: Some(intermediate.boot_identity.clone()), + process: ProcessInstanceObservation::Missing, + }; + let intermediate_termination = + write_workspace_coverage_process_termination_observation_with_source( + &verse, + "local", + &intermediate.launch_id, + &host, + &intermediate_source, + )?; + let (_, intermediate_termination_digest) = + authenticate_workspace_coverage_termination_with_envelope_digest( + &verse, + "local", + &intermediate.launch_id, + host.entry(), + )?; let replacement_provider = provider_key(); let mut replacement = launch( &policy, @@ -4439,9 +4552,9 @@ mod tests { &host, &replacement_provider, )?; - replacement.replaces_launch_id = Some(old_launch.launch_id.clone()); - replacement.replaces_termination_id = Some(termination.termination_id.clone()); - replacement.replaces_termination_envelope_digest = Some(termination_digest); + replacement.replaces_launch_id = Some(intermediate.launch_id.clone()); + replacement.replaces_termination_id = Some(intermediate_termination.termination_id.clone()); + replacement.replaces_termination_envelope_digest = Some(intermediate_termination_digest); sign_workspace_coverage_launch(&mut replacement, &host)?; write_workspace_coverage_managed_process_launch( &verse, @@ -4456,8 +4569,8 @@ mod tests { &host, &competing_provider, )?; - competing.replaces_launch_id = Some(old_launch.launch_id.clone()); - competing.replaces_termination_id = Some(termination.termination_id.clone()); + competing.replaces_launch_id = Some(intermediate.launch_id.clone()); + competing.replaces_termination_id = Some(intermediate_termination.termination_id.clone()); competing.replaces_termination_envelope_digest = replacement.replaces_termination_envelope_digest.clone(); sign_workspace_coverage_launch(&mut competing, &host)?; diff --git a/epiphany-core/src/workspace_coverage_projector.rs b/epiphany-core/src/workspace_coverage_projector.rs index 850e753a..b06aa06c 100644 --- a/epiphany-core/src/workspace_coverage_projector.rs +++ b/epiphany-core/src/workspace_coverage_projector.rs @@ -33,6 +33,7 @@ use crate::{ validate_workspace_coverage_projection_plan, workspace_coverage_execution_collection, workspace_coverage_process_documents::{ authenticate_historical_workspace_coverage_managed_process_launch_with_envelope_digest, + authenticate_workspace_coverage_replacement_lineage, authenticate_workspace_coverage_managed_process_launch_with_envelope_digest, authenticate_workspace_coverage_provider_heartbeat_with_envelope_digest, authenticate_workspace_coverage_termination_with_envelope_digest, @@ -1232,6 +1233,13 @@ pub fn authenticate_workspace_coverage_recovery_receipt( &receipt.ready_heartbeat_id, host, )?; + authenticate_workspace_coverage_replacement_lineage( + cultmesh_store.as_ref(), + runtime_id, + &receipt.old_launch_id, + &receipt.replacement_launch_id, + host, + )?; let latest = load_latest_workspace_coverage_provider_heartbeat( cultmesh_store, runtime_id, @@ -2147,6 +2155,13 @@ pub(crate) fn recover_workspace_coverage_projection_with_authority( replacement_ready_heartbeat_id, host, )?; + authenticate_workspace_coverage_replacement_lineage( + cultmesh_store, + runtime_id, + old_launch_id, + replacement_launch_id, + host, + )?; let latest = load_latest_workspace_coverage_provider_heartbeat( cultmesh_store, runtime_id, @@ -2162,13 +2177,6 @@ pub(crate) fn recover_workspace_coverage_projection_with_authority( let ready_at = chrono::DateTime::parse_from_rfc3339(&ready.observed_at_utc)?; let latest_at = chrono::DateTime::parse_from_rfc3339(&latest.observed_at_utc)?; if old_launch.launch_id == replacement_launch.launch_id - || replacement_launch.replaces_launch_id.as_deref() != Some(old_launch.launch_id.as_str()) - || replacement_launch.replaces_termination_id.as_deref() - != Some(termination.termination_id.as_str()) - || replacement_launch - .replaces_termination_envelope_digest - .as_deref() - != Some(termination_digest.as_str()) || ready.launch_id != replacement_launch.launch_id || ready.status != "ready" || ready.sequence == 0 diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index a754f0b5..39e575e4 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -2880,3 +2880,24 @@ the old launch historically. The full causal test now performs real policy rotation and proves current refusal, historical recovery, directive fencing, lease transfer, successor current sight, exact replay, and tamper refusal. Full core passes 573/573 with one ignored; all binaries compile. + +Candidate `351355d3baee2d475f84168136380d2f50197ef8` reached live runtime with all +three service owners active and the brake engaged, but emitted +`authenticated claim sight does not name the current managed launch`. The old +claim named the original historical launch while successive failed deployment +attempts had created a valid signed chain of replacement generations. Recovery +still required the current launch to be the old claim's direct child. The exact +Idunn process group was terminated, services stopped, active pointer and +witness removed, and Bifrost authority revoked; no deployment witness exists. + +Recovery now proves ancestry rather than pretending retries did not happen. +It walks backward from the selected current-policy launch to the claimed +historical launch, authenticating every host-signed launch, exact parent +termination id and envelope digest, and termination-before-child chronology. +It refuses cycles, missing ancestors, broken edges, and a non-current endpoint. +Directive writing, directive receipt verification, atomic lease transfer, and +supervisor crash-resume use the same lineage proof. The supervisor publishes +the actual lineage error instead of collapsing it into a generic mismatch. +The causal test now includes an intermediate failed-deployment generation and +passes the complete recovery transaction. Full library passes 573/573 with one +ignored; supervisor authority tests pass 24/24. diff --git a/state/map.yaml b/state/map.yaml index e80a15de..c1158ad2 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -794,4 +794,5 @@ current_status: - Workspace-coverage process authority now separates history from admission. A stored host-signed launch remains authentic historical identity after managed-policy rotation and may authorize only exact process observation and immutable termination evidence. Its termination binds the launch's signed policy id/digest and CAS-fences the exact launch/evidence head; it no longer pretends the current policy authored history. Reconciliation detects a stale-policy latest launch, terminates only its exact live process identity or records terminal sight, then launches a replacement bound to the exact current policy and historical termination. Current public observation still rejects stale launches, and only a current-policy launch can run. Full core proof passes 573/573 with one ignored; all binaries compile. - Candidate `b5405beaa95cddc837f3b7a7ca268ac9b5ae4502` built and started all three services, proving the historical authenticator itself shipped, but still produced `workspace coverage launch disagrees with current managed policy`. The stale-policy branch was unreachable because reconciliation authenticated provider claim sight before loading supervisor-owned latest launch, and claim authentication correctly rejected the stale policy. The candidate was rolled back, authority revoked, active pointer removed, and no deployment witness exists. Reconciliation now orders supervisor latest-launch sight and stale-policy rotation before current provider claim authentication. Provider claim state cannot veto retirement of obsolete supervisor process lineage; it participates only after a current-policy launch exists. Supervisor tests pass 24/24 and full core remains 573/573 with one ignored. - Candidate `b8517d9d7905eb62314db675cc2f0688510aa5bd` proved stale launch terminalization and current-policy replacement launch: supervisor PID `1147968` launched replacement workspace projector PID `1148157`, whose authenticated ready heartbeat advanced while the engaged brake held. Recovery still stalled because the old Body claim could be read only through current-claim authentication, which correctly rejected its historical policy before the mismatch recovery branch. The candidate was rolled back and revoked; no deployment witness exists. Claim sight now has two explicit authorities: current authentication is required for provider projection work and rejects stale launches; recovery authentication proves the old signed claim/body/route lineage only. Supervisor recovery and directive writing use the recovery reader, while old launch authentication inside the atomic lease-transfer transaction is historical and the replacement launch/heartbeat remain current-policy evidence. The full causal test performs an actual policy rotation and proves current refusal, historical recovery, directive fencing, lease transfer, successor current sight, and replay/tamper boundaries. Full core passes 573/573 with one ignored; all binaries compile. - next_action: "Commit and push the current-claim/recovery-claim authority split, authorize the exact successor through Bifrost, and let Idunn redeploy under the engaged sleep brake. Require stale launch terminalization without evidence deletion, a ready replacement workspace projector bound to the new policy, a typed recovery directive and recovered current claim, immutable package inspection, app-owned release publication, three healthy local service owners, signed aggregate health, and the final deployment.env witness. Then run the Starfire-offline rehearsal before 2026-07-22: persistent Modeling map -> autonomous bounded Imagination proposal, with classified organization feedback through Persona as an additional pressure path; explicit Mind adoption -> Hands consequence -> Bifrost release -> Idunn deployment remain separate gates. Prove replay/tamper refusal and that conversation alone grants no Mind, Hands, Persona-speech, release, or deployment authority. No host reboot is authorized." + - Candidate `351355d3baee2d475f84168136380d2f50197ef8` authenticated the historical claim and started all three owners under the brake, but recovery refused because the claim named an older launch than the current replacement's direct parent. Repeated failed candidate deployments had formed a valid signed replacement chain, while recovery still assumed one direct old-to-new edge. The exact Idunn process group was terminated, all services stopped, active pointer and witness removed, and Bifrost authority revoked. No deployment witness exists. Recovery now authenticates the complete immutable chain from the claim's historical launch to the live current-policy descendant: every intermediate launch is host-signed, every parent termination id and envelope digest is exact, chronology is ordered, cycles and broken edges refuse, and the selected endpoint must be current. Directive writing, receipt verification, atomic lease transfer, and supervisor resume share this proof. Typed refusal now exposes the exact lineage fault instead of swallowing it. The causal recovery test contains a real intermediate generation and still proves the full fenced transaction. Full library passes 573/573 with one ignored; supervisor authority tests pass 24/24. + next_action: "Commit and push authenticated multi-generation workspace recovery, authorize the exact successor through Bifrost, and let Idunn redeploy under the engaged sleep brake. Require the historical claim to transfer across every signed replacement edge to the current ready projector, followed by advancing authoritative coverage, immutable package inspection, app-owned release publication, three healthy local service owners, signed aggregate health, and the final deployment.env witness. Then run the Starfire-offline rehearsal before 2026-07-22: persistent Modeling map -> autonomous bounded Imagination proposal, with classified organization feedback through Persona as an additional pressure path; explicit Mind adoption -> Hands consequence -> Bifrost release -> Idunn deployment remain separate gates. Prove replay/tamper refusal and that conversation alone grants no Mind, Hands, Persona-speech, release, or deployment authority. No host reboot is authorized."