From 182a591369131d621461947723e7fb71637fa386 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 8 Aug 2026 09:52:42 +0100 Subject: [PATCH] Add atomic Hands route relinquishment --- .../src/bin/epiphany-hands-action.rs | 57 ++- epiphany-core/src/bin/epiphany-mvp-status.rs | 4 + epiphany-core/src/hands_gateway.rs | 40 ++ epiphany-core/src/lib.rs | 2 + epiphany-core/src/memory_graph/store.rs | 25 + epiphany-core/src/repo_model_gateway.rs | 39 ++ epiphany-core/src/runtime_spine.rs | 431 +++++++++++++++++- epiphany-state-model/src/lib.rs | 4 + notes/epiphany-current-algorithmic-map.md | 45 +- notes/fresh-workspace-handoff.md | 41 +- state/ledgers.msgpack | Bin 572575 -> 573057 bytes state/map.yaml | 8 +- 12 files changed, 661 insertions(+), 35 deletions(-) diff --git a/epiphany-core/src/bin/epiphany-hands-action.rs b/epiphany-core/src/bin/epiphany-hands-action.rs index 216674c6..60a57265 100644 --- a/epiphany-core/src/bin/epiphany-hands-action.rs +++ b/epiphany-core/src/bin/epiphany-hands-action.rs @@ -10,6 +10,7 @@ use epiphany_core::hands_patch_receipt_for_review; use epiphany_core::put_hands_command_receipt; use epiphany_core::put_hands_commit_receipt; use epiphany_core::put_hands_patch_receipt; +use epiphany_core::relinquish_repo_frontier_hands_route; use epiphany_core::runtime_hands_action_intent; use epiphany_core::runtime_hands_action_review; use serde_json::json; @@ -26,6 +27,7 @@ fn main() -> Result<()> { Command::RecordCommand(command) => record_command(&args.store, command)?, Command::RecordCommit(command) => record_commit(&args.store, command)?, Command::RecordPass(command) => record_pass(&args.store, command)?, + Command::RecordRefusal(command) => record_refusal(&args.store, command)?, }; println!("{}", serde_json::to_string_pretty(&output)?); Ok(()) @@ -43,6 +45,7 @@ enum Command { RecordCommand(RecordCommandArgs), RecordCommit(RecordCommitArgs), RecordPass(RecordPassArgs), + RecordRefusal(RecordRefusalArgs), } #[derive(Debug, Clone)] @@ -91,6 +94,12 @@ struct RecordPassArgs { validate_commit_sha: bool, } +#[derive(Debug)] +struct RecordRefusalArgs { + gate: GateArgs, + missing_required_paths: Vec, +} + impl Args { fn parse() -> Result { let mut tokens = env::args().skip(1).peekable(); @@ -105,12 +114,29 @@ impl Args { "record-command" => Command::RecordCommand(parse_record_command(tokens)?), "record-commit" => Command::RecordCommit(parse_record_commit(tokens)?), "record-pass" => Command::RecordPass(parse_record_pass(tokens)?), + "record-refusal" => Command::RecordRefusal(parse_record_refusal(tokens)?), _ => return Err(anyhow!("unknown command {command_name}\n{}", usage())), }; Ok(Self { store, command }) } } +fn parse_record_refusal(tokens: impl Iterator) -> Result { + let mut options = ParsedOptions::parse(tokens)?; + let gate = options.take_gate()?; + let missing_required_paths = options.take_many("--missing-required-path"); + options.finish()?; + if missing_required_paths.is_empty() { + return Err(anyhow!( + "record-refusal requires at least one --missing-required-path" + )); + } + Ok(RecordRefusalArgs { + gate, + missing_required_paths, + }) +} + fn parse_record_patch(tokens: impl Iterator) -> Result { let mut options = ParsedOptions::parse(tokens)?; let gate = options.take_gate()?; @@ -399,6 +425,35 @@ fn record_pass(store: &PathBuf, args: RecordPassArgs) -> Result Result { + let resolved = resolve_gate(&args.gate)?; + let receipt_id = args + .gate + .receipt_id + .unwrap_or_else(|| generated_receipt_id("hands-refusal")); + let receipt = relinquish_repo_frontier_hands_route( + store, + &resolved.intent_id, + &resolved.review_id, + &receipt_id, + normalize_paths(args.missing_required_paths), + args.gate.summary, + now(), + )?; + Ok(json!({ + "status": "ok", + "type": "epiphany.mind.repo_frontier_relinquishment_receipt", + "receiptId": receipt.receipt_id, + "handsRefusalReceiptId": receipt.hands_refusal_receipt_id, + "routeId": receipt.route_id, + "frontierItemId": receipt.frontier_item_id, + "admittedModelRevision": receipt.admitted_model_revision, + "admittedModelHash": receipt.admitted_model_hash, + "modelAdmissionReceiptId": receipt.model_admission_receipt_id, + "store": store, + })) +} + fn pass_gate(gate: &GateArgs, operation: &str) -> GateArgs { let mut gate = gate.clone(); gate.receipt_id = None; @@ -570,7 +625,7 @@ fn take_value(tokens: &mut impl Iterator, name: &str) -> Result &'static str { - "usage: epiphany-hands-action [--store path] (--gate-summary path | --intent-id id --review-id id) --summary text ..." + "usage: epiphany-hands-action [--store path] (--gate-summary path | --intent-id id --review-id id) --summary text ..." } #[cfg(test)] diff --git a/epiphany-core/src/bin/epiphany-mvp-status.rs b/epiphany-core/src/bin/epiphany-mvp-status.rs index 02d5a9bf..11959e2a 100644 --- a/epiphany-core/src/bin/epiphany-mvp-status.rs +++ b/epiphany-core/src/bin/epiphany-mvp-status.rs @@ -472,6 +472,9 @@ fn run_native_status(args: &Args, include_auxiliary_status: bool) -> Result Result, + #[cultcache(key = 12)] + pub summary: String, + #[cultcache(key = 13)] + pub refused_at: String, + #[cultcache(key = 14)] + pub contract: String, +} + #[derive(Debug, Clone, PartialEq, Eq, DatabaseEntry)] #[cultcache(type = "epiphany.hands.patch_receipt", schema = "HandsPatchReceipt")] pub struct HandsPatchReceipt { diff --git a/epiphany-core/src/lib.rs b/epiphany-core/src/lib.rs index b5e0415c..dab6c2de 100644 --- a/epiphany-core/src/lib.rs +++ b/epiphany-core/src/lib.rs @@ -1044,6 +1044,7 @@ pub use runtime_spine::put_runtime_reorient_worker_result; pub use runtime_spine::put_runtime_role_worker_result; pub use runtime_spine::put_soul_verdict_receipt; pub use runtime_spine::put_substrate_gate_repo_access_grant_receipt; +pub use runtime_spine::relinquish_repo_frontier_hands_route; pub use runtime_spine::replace_or_append_epiphany_job_binding; pub use runtime_spine::runtime_continuity_recovery_receipt; pub use runtime_spine::runtime_current_repo_model; @@ -1061,6 +1062,7 @@ pub use runtime_spine::runtime_has_actionable_imagination_frontier; pub use runtime_spine::runtime_hello_frame; pub use runtime_spine::runtime_job_snapshot; pub use runtime_spine::runtime_latest_hands_receipt_chain_after; +pub use runtime_spine::runtime_latest_repo_frontier_relinquishment; pub use runtime_spine::runtime_mind_gateway_review; pub use runtime_spine::runtime_mind_state_commit_receipt; pub use runtime_spine::runtime_modeling_semantic_projection_input; diff --git a/epiphany-core/src/memory_graph/store.rs b/epiphany-core/src/memory_graph/store.rs index 86c140a3..9bcc5cb4 100644 --- a/epiphany-core/src/memory_graph/store.rs +++ b/epiphany-core/src/memory_graph/store.rs @@ -249,6 +249,18 @@ pub fn derive_repo_model_patch( )); } } + epiphany_state_model::RepoModelPatchPurpose::RelinquishFrontierRoute { .. } => { + if patch.operations.len() != 1 + || !matches!( + patch.operations[0], + RepoModelPatchOperation::RetireFrontier { .. } + ) + { + return Err(anyhow!( + "RelinquishFrontierRoute purpose requires exactly one frontier retirement" + )); + } + } _ if patch.operations.iter().any(|operation| { matches!(operation, RepoModelPatchOperation::AdoptFrontierPlan { .. }) }) => @@ -417,6 +429,19 @@ fn apply_operation( .iter_mut() .find(|item| &item.id == item_id) .ok_or_else(|| anyhow!("cannot retire missing frontier item {item_id}"))?; + if item.adopted_plan.is_some() + && !matches!( + purpose, + epiphany_state_model::RepoModelPatchPurpose::RelinquishFrontierRoute { + route_id: _, + hands_refusal_receipt_id: _ + } + ) + { + return Err(anyhow!( + "only route relinquishment may retire an adopted frontier without a Soul verdict" + )); + } item.status = if superseded_by.is_some() { RepoFrontierStatus::Superseded } else { diff --git a/epiphany-core/src/repo_model_gateway.rs b/epiphany-core/src/repo_model_gateway.rs index 82e91659..573ae8ab 100644 --- a/epiphany-core/src/repo_model_gateway.rs +++ b/epiphany-core/src/repo_model_gateway.rs @@ -40,6 +40,12 @@ pub const REPO_FRONTIER_HANDS_AUTHORITY_SCHEMA_VERSION: &str = pub const REPO_FRONTIER_ROUTE_CONTRACT: &str = "epiphany.repo_frontier_route.v1"; pub const REPO_FRONTIER_HANDS_AUTHORITY_CONTRACT: &str = "epiphany.repo_frontier_hands_authority.v0"; +pub const REPO_FRONTIER_RELINQUISHMENT_RECEIPT_TYPE: &str = + "epiphany.mind.repo_frontier_relinquishment_receipt"; +pub const REPO_FRONTIER_RELINQUISHMENT_RECEIPT_SCHEMA_VERSION: &str = + "epiphany.mind.repo_frontier_relinquishment_receipt.v0"; +pub const REPO_FRONTIER_RELINQUISHMENT_RECEIPT_CONTRACT: &str = + "epiphany.repo_frontier_relinquishment.v0"; pub const REPO_FRONTIER_MODELING_REQUEST_TYPE: &str = "epiphany.modeling.repo_frontier_verdict_request"; pub const REPO_FRONTIER_MODELING_REQUEST_SCHEMA_VERSION: &str = @@ -900,6 +906,38 @@ pub struct RepoFrontierHandsAuthority { pub contract: String, } +#[derive(Debug, Clone, PartialEq, Eq, DatabaseEntry)] +#[cultcache( + type = "epiphany.mind.repo_frontier_relinquishment_receipt", + schema = "RepoFrontierRelinquishmentReceipt" +)] +pub struct RepoFrontierRelinquishmentReceipt { + #[cultcache(key = 0)] + pub schema_version: String, + #[cultcache(key = 1)] + pub receipt_id: String, + #[cultcache(key = 2)] + pub hands_refusal_receipt_id: String, + #[cultcache(key = 3)] + pub route_id: String, + #[cultcache(key = 4)] + pub frontier_item_id: String, + #[cultcache(key = 5)] + pub previous_model_revision: u64, + #[cultcache(key = 6)] + pub previous_model_hash: String, + #[cultcache(key = 7)] + pub admitted_model_revision: u64, + #[cultcache(key = 8)] + pub admitted_model_hash: String, + #[cultcache(key = 9)] + pub model_admission_receipt_id: String, + #[cultcache(key = 10)] + pub relinquished_at: String, + #[cultcache(key = 11)] + pub contract: String, +} + #[derive(Debug, Clone, PartialEq, Eq, DatabaseEntry)] #[cultcache( type = "epiphany.mind.repo_model_admission_review", @@ -941,6 +979,7 @@ pub struct RepoModelAdmissionReview { pub enum RepoModelAdmissionSource { WorkerResult { result_id: String, job_id: String }, FrontierPlanDecision { decision_id: String }, + HandsRelinquishment { receipt_id: String }, } #[derive(Debug, Clone, PartialEq, Eq, DatabaseEntry)] diff --git a/epiphany-core/src/runtime_spine.rs b/epiphany-core/src/runtime_spine.rs index 6950736b..be8ba3c0 100644 --- a/epiphany-core/src/runtime_spine.rs +++ b/epiphany-core/src/runtime_spine.rs @@ -83,9 +83,9 @@ use crate::repo_model_gateway::{ RepoFrontierPlanningLaunchBinding, RepoFrontierPlanningLifecycle, RepoFrontierPlanningLifecycleStage, RepoFrontierPlanningRequest, RepoFrontierProposalModelingLaunchBinding, RepoFrontierProposalModelingRequest, - RepoFrontierRoute, RepoFrontierVerdictDisposition, RepoFrontierWorkProposal, - RepoModelAdmissionReceipt, RepoModelAdmissionReview, RepoModelClaimChallenge, - RepoModelClaimRepairFrontierRef, RepoModelClaimRepairLaunchBinding, + RepoFrontierRelinquishmentReceipt, RepoFrontierRoute, RepoFrontierVerdictDisposition, + RepoFrontierWorkProposal, RepoModelAdmissionReceipt, RepoModelAdmissionReview, + RepoModelClaimChallenge, RepoModelClaimRepairFrontierRef, RepoModelClaimRepairLaunchBinding, RepoModelClaimRepairRequest, RepoModelMigrationReceipt, RuntimeRepositoryDomainBinding, }; use crate::soul_gateway::SoulVerdictReceipt; @@ -900,6 +900,8 @@ pub fn runtime_spine_cache(store_path: impl AsRef) -> Result { cache.register_entry_type::()?; cache.register_entry_type::()?; cache.register_entry_type::()?; + cache.register_entry_type::()?; + cache.register_entry_type::()?; cache.register_entry_type::()?; cache.register_entry_type::()?; cache.register_entry_type::()?; @@ -2725,6 +2727,11 @@ pub fn commit_repo_model_admission( "frontier plan adoption is Mind-owned and cannot enter through generic repo model admission" )); } + crate::RepoModelPatchPurpose::RelinquishFrontierRoute { .. } => { + return Err(anyhow!( + "frontier route relinquishment is a Mind-owned transaction and cannot enter through generic repo model admission" + )); + } crate::RepoModelPatchPurpose::RepairClaim => { if result.repo_frontier_modeling_request_id.is_some() || result.proposal_modeling_request_id.is_some() @@ -7019,6 +7026,251 @@ pub fn put_repo_frontier_hands_authority( } } +/// Atomically records Hands' inability to act under an exact route and lets +/// Mind retire that route's frontier. The historical route and authority stay +/// immutable, while the admitted model revision makes them structurally stale. +pub fn relinquish_repo_frontier_hands_route( + store_path: impl AsRef, + intent_id: &str, + review_id: &str, + refusal_receipt_id: &str, + missing_required_paths: Vec, + summary: String, + relinquished_at: String, +) -> Result { + let store_path = store_path.as_ref(); + validate_non_empty(intent_id, "Hands intent id")?; + validate_non_empty(review_id, "Hands review id")?; + validate_non_empty(refusal_receipt_id, "Hands refusal receipt id")?; + validate_non_empty(&summary, "Hands refusal summary")?; + if !safe_sorted_unique_paths(&missing_required_paths) || missing_required_paths.is_empty() { + return Err(anyhow!( + "Hands refusal requires non-empty safe missing paths in strict sorted order" + )); + } + chrono::DateTime::parse_from_rfc3339(&relinquished_at) + .map_err(|_| anyhow!("Hands refusal timestamp must be RFC3339"))?; + + let mut cache = runtime_spine_cache(store_path)?; + cache.pull_all_backing_stores()?; + require_identity(&cache)?; + if let Some(existing) = cache.get::(refusal_receipt_id)? { + if existing.intent_id != intent_id + || existing.review_id != review_id + || existing.missing_required_paths != missing_required_paths + || existing.summary != summary + || existing.refused_at != relinquished_at + { + return Err(anyhow!("Hands refusal receipt ids are immutable")); + } + let matches = cache + .get_all::()? + .into_iter() + .filter(|receipt| receipt.hands_refusal_receipt_id == existing.receipt_id) + .collect::>(); + return match matches.as_slice() { + [receipt] => Ok(receipt.clone()), + _ => Err(anyhow!( + "Hands refusal replay lost its unique Mind relinquishment receipt" + )), + }; + } + + let authorities = cache + .get_all::()? + .into_iter() + .filter(|authority| { + authority.hands_intent_id == intent_id && authority.hands_review_id == review_id + }) + .collect::>(); + let [authority] = authorities.as_slice() else { + return Err(anyhow!( + "Hands refusal requires exactly one current route authority" + )); + }; + validate_repo_frontier_hands_authority_chain(&cache, authority)?; + let route = cache + .get::(&authority.route_id)? + .ok_or_else(|| anyhow!("Hands refusal lost its route"))?; + if missing_required_paths.iter().all(|path| { + route.source_scope.iter().any(|scope| { + path == scope || path.starts_with(&format!("{}/", scope.trim_end_matches(['/', '\\']))) + }) + }) { + return Err(anyhow!( + "Hands refusal must identify at least one required path outside the adopted route scope" + )); + } + let has_consequence = cache + .get_all::()? + .iter() + .any(|receipt| receipt.intent_id == intent_id) + || cache + .get_all::()? + .iter() + .any(|receipt| receipt.intent_id == intent_id) + || cache + .get_all::()? + .iter() + .any(|receipt| receipt.intent_id == intent_id) + || cache + .get_all::()? + .iter() + .any(|receipt| receipt.intent_id == intent_id); + if has_consequence { + return Err(anyhow!( + "Hands cannot relinquish a route after mutation consequences exist" + )); + } + + let backing = SingleFileMessagePackBackingStore::new(store_path); + let current_envelope = backing + .pull_all()? + .into_iter() + .find(|entry| { + entry.r#type == crate::MEMORY_GRAPH_TYPE && entry.key == crate::MEMORY_GRAPH_KEY + }) + .ok_or_else(|| anyhow!("Hands refusal requires canonical RepoModel"))?; + let current_entry: crate::EpiphanyMemoryGraphEntry = + rmp_serde::from_slice(¤t_envelope.payload)?; + crate::validate_memory_graph_entry(¤t_entry)?; + let current = current_entry.snapshot()?; + let current_hash = crate::memory_graph_model_hash(¤t)?; + if current.model_revision != route.model_revision || current_hash != route.model_hash { + return Err(anyhow!("Hands refusal route is no longer current")); + } + + let refusal = HandsActionRefusalReceipt { + schema_version: HANDS_ACTION_REFUSAL_RECEIPT_SCHEMA_VERSION.into(), + receipt_id: refusal_receipt_id.to_string(), + route_id: route.route_id.clone(), + authority_id: authority.authority_id.clone(), + intent_id: intent_id.to_string(), + review_id: review_id.to_string(), + substrate_gate_grant_receipt_id: authority.substrate_grant_receipt_id.clone(), + model_revision: route.model_revision, + model_hash: route.model_hash.clone(), + frontier_item_id: route.frontier_item_id.clone(), + frontier_item_hash: route.frontier_item_hash.clone(), + missing_required_paths: missing_required_paths.clone(), + summary: summary.clone(), + refused_at: relinquished_at.clone(), + contract: HANDS_ACTION_REFUSAL_RECEIPT_CONTRACT.into(), + }; + let relinquishment_id = format!( + "repo-frontier-relinquishment-{:x}", + Sha256::digest(format!("{}:{}", route.route_id, refusal.receipt_id).as_bytes()) + ); + let patch = crate::RepoModelPatch { + patch_id: format!("repo-frontier-relinquishment-patch-{}", refusal.receipt_id), + base_revision: current.model_revision, + base_hash: current_hash.clone(), + applied_at: relinquished_at.clone(), + purpose: crate::RepoModelPatchPurpose::RelinquishFrontierRoute { + route_id: route.route_id.clone(), + hands_refusal_receipt_id: refusal.receipt_id.clone(), + }, + operations: vec![crate::RepoModelPatchOperation::RetireFrontier { + item_id: route.frontier_item_id.clone(), + retired_at: Some(relinquished_at.clone()), + superseded_by: None, + }], + }; + let patch_bytes = rmp_serde::to_vec_named(&patch)?; + let patch_sha256 = format!("{:x}", Sha256::digest(&patch_bytes)); + let next = crate::derive_repo_model_patch(¤t, &patch)?; + let next_entry = crate::EpiphanyMemoryGraphEntry::from_snapshot(&next)?; + let review_id_value = format!("repo-model-review-{relinquishment_id}"); + let admission_id = format!("repo-model-admission-{relinquishment_id}"); + let source = crate::RepoModelAdmissionSource::HandsRelinquishment { + receipt_id: refusal.receipt_id.clone(), + }; + let review = RepoModelAdmissionReview { + schema_version: REPO_MODEL_ADMISSION_REVIEW_SCHEMA_VERSION.into(), + review_id: review_id_value.clone(), + result_id: None, + job_id: None, + patch_id: patch.patch_id.clone(), + patch_sha256: patch_sha256.clone(), + base_revision: current.model_revision, + base_hash: current_hash.clone(), + decision: MindGatewayDecision::Accept, + evidence_ids: vec![route.route_id.clone(), refusal.receipt_id.clone()], + reviewed_at: relinquished_at.clone(), + contract: REPO_MODEL_ADMISSION_CONTRACT.into(), + repository_body_observation_basis: None, + admission_source: Some(source.clone()), + }; + let admission = RepoModelAdmissionReceipt { + schema_version: REPO_MODEL_ADMISSION_RECEIPT_SCHEMA_VERSION.into(), + receipt_id: admission_id.clone(), + review_id: review_id_value, + result_id: None, + patch_id: patch.patch_id, + patch_sha256, + previous_revision: current.model_revision, + previous_hash: current_hash, + admitted_revision: next.model_revision, + admitted_hash: next.model_hash.clone(), + admitted_at: relinquished_at.clone(), + contract: REPO_MODEL_ADMISSION_CONTRACT.into(), + purpose: patch.purpose, + frontier_route_id: route.route_id.clone(), + verification_request_id: String::new(), + soul_verdict_receipt_id: String::new(), + frontier_modeling_request_id: String::new(), + proposal_modeling_request_id: String::new(), + claim_repair_request_id: String::new(), + frontier_plan_decision_id: String::new(), + repository_body_observation_basis: None, + admission_source: Some(source), + }; + let relinquishment = RepoFrontierRelinquishmentReceipt { + schema_version: crate::REPO_FRONTIER_RELINQUISHMENT_RECEIPT_SCHEMA_VERSION.into(), + receipt_id: relinquishment_id, + hands_refusal_receipt_id: refusal.receipt_id.clone(), + route_id: route.route_id, + frontier_item_id: route.frontier_item_id, + previous_model_revision: current.model_revision, + previous_model_hash: admission.previous_hash.clone(), + admitted_model_revision: next.model_revision, + admitted_model_hash: next.model_hash.clone(), + model_admission_receipt_id: admission_id, + relinquished_at: relinquished_at.clone(), + contract: crate::REPO_FRONTIER_RELINQUISHMENT_RECEIPT_CONTRACT.into(), + }; + let obligation = modeling_projection_obligation( + &cache, + &next, + &admission.receipt_id, + &admission.admitted_at, + )?; + let writes = vec![ + cache.prepare_entry(crate::MEMORY_GRAPH_KEY, &next_entry)?.0, + cache.prepare_entry(&refusal.receipt_id, &refusal)?.0, + cache.prepare_entry(&review.review_id, &review)?.0, + cache.prepare_entry(&admission.receipt_id, &admission)?.0, + cache + .prepare_entry(&relinquishment.receipt_id, &relinquishment)? + .0, + cache + .prepare_entry(&obligation.obligation_id, &obligation)? + .0, + ]; + if !backing.compare_and_swap_batch(&[current_envelope], writes)? { + return relinquish_repo_frontier_hands_route( + store_path, + intent_id, + review_id, + refusal_receipt_id, + missing_required_paths, + summary, + relinquished_at, + ); + } + Ok(relinquishment) +} + pub fn put_repo_frontier_verification_request( store_path: impl AsRef, request: &RepoFrontierVerificationRequest, @@ -7157,6 +7409,20 @@ pub fn runtime_repo_frontier_route( cache.get::(route_id) } +pub fn runtime_latest_repo_frontier_relinquishment( + store_path: impl AsRef, +) -> Result> { + let mut cache = runtime_spine_cache(store_path)?; + cache.pull_all_backing_stores()?; + let mut receipts = cache.get_all::()?; + receipts.sort_by(|left, right| { + left.relinquished_at + .cmp(&right.relinquished_at) + .then_with(|| left.receipt_id.cmp(&right.receipt_id)) + }); + Ok(receipts.pop()) +} + pub fn commit_repo_frontier_modeling_request( store_path: impl AsRef, acceptance: &epiphany_state_model::EpiphanyAcceptanceReceipt, @@ -8782,6 +9048,18 @@ fn epiphany_mutation_contracts() -> Vec { vec![], vec!["Hands refusal receipts preserve why an action intent was denied."], ), + mutation_contract( + crate::REPO_FRONTIER_RELINQUISHMENT_RECEIPT_TYPE, + crate::REPO_FRONTIER_RELINQUISHMENT_RECEIPT_SCHEMA_VERSION, + vec![ + CultNetDocumentOperation::Snapshot, + CultNetDocumentOperation::ReceiptWatch, + ], + CultNetMutationAuthority::ReadOnly, + vec![], + vec![], + vec!["Mind relinquishment receipts prove that an exact Hands refusal retired route authority without a repository consequence."], + ), mutation_contract( SOUL_VERIFICATION_REQUEST_TYPE, SOUL_VERIFICATION_REQUEST_SCHEMA_VERSION, @@ -11457,6 +11735,122 @@ pub(crate) mod tests { Ok((route, authority)) } + #[test] + fn hands_relinquishment_atomically_retires_route_authority_without_consequences() -> Result<()> + { + let temp = tempdir()?; + let store = temp.path().join("runtime.cc"); + initialize_runtime_spine( + &store, + RuntimeSpineInitOptions { + runtime_id: "relinquishment-runtime".to_string(), + display_name: "Relinquishment".to_string(), + created_at: "2026-08-08T12:00:00Z".to_string(), + }, + )?; + let paths = vec!["epiphany-core/src/runtime_spine.rs".to_string()]; + let grant = crate::substrate_gate_coordinator_implementation_grant( + "relinquishment-grant".to_string(), + "relinquishment-job".to_string(), + paths.clone(), + "2026-08-08T12:00:01Z".to_string(), + ); + put_substrate_gate_repo_access_grant_receipt(&store, &grant)?; + let intent = HandsActionIntent { + schema_version: HANDS_ACTION_INTENT_SCHEMA_VERSION.to_string(), + intent_id: "relinquishment-intent".to_string(), + runtime_job_id: grant.runtime_job_id.clone(), + binding_id: grant.binding_id.clone(), + role: grant.role.clone(), + authority_scope: grant.authority_scope.clone(), + requested_action: "patch".to_string(), + requested_paths: paths, + substrate_gate_grant_receipt_id: grant.receipt_id.clone(), + requested_at: "2026-08-08T12:00:02Z".to_string(), + contract: "test".to_string(), + frontier_route_id: String::new(), + plan_candidate_sha256: String::new(), + plan_action: String::new(), + }; + put_hands_action_intent(&store, &intent)?; + let review = crate::hands_action_review_for_intent( + "relinquishment-review".to_string(), + &intent, + "approved".to_string(), + vec!["patch".to_string()], + vec!["bounded route".to_string()], + "2026-08-08T12:00:03Z".to_string(), + ); + put_hands_action_review(&store, &review)?; + let (route, authority) = + admit_route_and_authorize_hands(&store, &intent, &review, "relinquishment")?; + let before = runtime_current_repo_model(&store)?.expect("current model"); + assert!( + relinquish_repo_frontier_hands_route( + &store, + &intent.intent_id, + &review.review_id, + "hands-refusal-not-a-gap", + vec!["epiphany-core/src/runtime_spine.rs".to_string()], + "This path was already authorized.".to_string(), + "2026-08-08T12:00:04Z".to_string(), + ) + .is_err() + ); + assert_eq!(runtime_current_repo_model(&store)?.unwrap(), before); + let receipt = relinquish_repo_frontier_hands_route( + &store, + &intent.intent_id, + &review.review_id, + "hands-refusal-relinquishment", + vec!["epiphany-state-model/src/lib.rs".to_string()], + "The adopted path ceiling cannot express the required authority transfer.".to_string(), + "2026-08-08T12:00:04Z".to_string(), + )?; + let after = runtime_current_repo_model(&store)?.expect("current model"); + assert_eq!(receipt.route_id, route.route_id); + assert_eq!(receipt.previous_model_revision, before.model_revision); + assert_eq!(receipt.admitted_model_revision, before.model_revision + 1); + assert_eq!(after.model_revision, receipt.admitted_model_revision); + assert_eq!( + after + .frontier + .iter() + .find(|item| item.id == route.frontier_item_id) + .expect("retained frontier") + .status, + crate::RepoFrontierStatus::Retired + ); + assert!(!runtime_has_actionable_hands_frontier(&store)?); + assert!(put_repo_frontier_hands_authority(&store, &authority).is_err()); + assert_eq!( + relinquish_repo_frontier_hands_route( + &store, + &intent.intent_id, + &review.review_id, + "hands-refusal-relinquishment", + vec!["epiphany-state-model/src/lib.rs".to_string()], + "The adopted path ceiling cannot express the required authority transfer." + .to_string(), + "2026-08-08T12:00:04Z".to_string(), + )?, + receipt + ); + assert!( + relinquish_repo_frontier_hands_route( + &store, + &intent.intent_id, + &review.review_id, + "hands-refusal-relinquishment", + vec!["epiphany-state-model/src/lib.rs".to_string()], + "collision".to_string(), + "2026-08-08T12:00:04Z".to_string(), + ) + .is_err() + ); + Ok(()) + } + struct FrontierVerdictFixture { store: std::path::PathBuf, route: RepoFrontierRoute, @@ -11650,6 +12044,34 @@ pub(crate) mod tests { }) } + #[test] + fn hands_relinquishment_refuses_to_erase_existing_consequences() -> Result<()> { + let temp = tempdir()?; + let fixture = frontier_verdict_fixture(temp.path(), "relinquish-after-work", "pass")?; + let mut cache = runtime_spine_cache(&fixture.store)?; + cache.pull_all_backing_stores()?; + let authority = cache + .get_all::()? + .into_iter() + .find(|authority| authority.route_id == fixture.route.route_id) + .expect("route authority"); + let before = fs::read(&fixture.store)?; + assert!( + relinquish_repo_frontier_hands_route( + &fixture.store, + &authority.hands_intent_id, + &authority.hands_review_id, + "hands-refusal-after-consequence", + vec!["epiphany-state-model/src/lib.rs".to_string()], + "Too late to claim no consequence.".to_string(), + "2026-08-08T12:00:09Z".to_string(), + ) + .is_err() + ); + assert_eq!(fs::read(&fixture.store)?, before); + Ok(()) + } + fn incorporation_result_and_review( fixture: &FrontierVerdictFixture, suffix: &str, @@ -12170,6 +12592,9 @@ pub(crate) mod tests { crate::RepoModelPatchPurpose::AdoptFrontierPlan { .. } => { vec!["adopt".to_string()] } + crate::RepoModelPatchPurpose::RelinquishFrontierRoute { .. } => { + vec!["relinquish".to_string()] + } }; review.patch_id = patch.patch_id.clone(); review.patch_sha256 = format!("{:x}", Sha256::digest(&bytes)); diff --git a/epiphany-state-model/src/lib.rs b/epiphany-state-model/src/lib.rs index 4b03ae01..60cb2480 100644 --- a/epiphany-state-model/src/lib.rs +++ b/epiphany-state-model/src/lib.rs @@ -867,6 +867,10 @@ pub enum RepoModelPatchPurpose { result_id: String, candidate_id: String, }, + RelinquishFrontierRoute { + route_id: String, + hands_refusal_receipt_id: String, + }, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, TS)] diff --git a/notes/epiphany-current-algorithmic-map.md b/notes/epiphany-current-algorithmic-map.md index 3fef5b34..e10d7b10 100644 --- a/notes/epiphany-current-algorithmic-map.md +++ b/notes/epiphany-current-algorithmic-map.md @@ -1331,29 +1331,30 @@ the continuity checkpoint deterministically from accepted RepoModel evidence, or CRRC consumes canonical RepoModel admission directly. Canonical Imagination and dedicated Mind must adopt the choice before Hands changes the seam. -Fresh v44 then proved that planning path through canonical Imagination and -dedicated Mind adoption. Inspection at the Hands boundary found the adopted -safe-path set omitted `epiphany-core/src/bin/epiphany-mvp-status.rs`, the actual -composition owner. The gate correctly forbids editing it. The route cannot yet -return this falsified plan to planning authority: the Hands contract catalogs -an action-refusal receipt, but no typed record, writer, CLI transition, or -frontier lifecycle effect implements it. A route currently terminates only -after a complete mutation, verification, Soul verdict, and Modeling -incorporation chain. Hands must gain a typed refusal/relinquish consequence -before the checkpoint repair can continue without fabricating work. +Fresh v49 proves the current planning path through canonical Imagination and +dedicated Mind adoption. Its six safe paths are the complete implementation +owner set at that revision; the previously named vendored app-server owner does +not exist. The route is nevertheless preserved as incomplete evidence because +the machine itself lacked the newly required relinquishment transaction when +Mind adopted that plan. Historical route authority is never widened after the +fact. -The repair boundary is split deliberately. Hands owns an immutable refusal -receipt bound to the exact route, action intent, review, adopted-plan digest, -and current model/frontier hashes; it may state that inspection proved the -authorized path ceiling insufficient, but it may not revise RepoModel. Mind -owns the companion frontier transition: after validating exactly one matching -Hands refusal against the still-current route and model, it may retire or -supersede that frontier item and admit the revised model through the normal -model CAS. The route remains historical selection evidence and is not mutated -into a second lifecycle owner. Evolution remains forbidden from bypassing a -current route, and the full consequence/Soul path remains the only route to a -`Resolved` frontier. The old route can neither authorize edits after -relinquishment nor be hidden by a later repair loop. +The live repair boundary is split deliberately. `hands_gateway.rs` defines the +immutable refusal receipt. `runtime_spine.rs::relinquish_repo_frontier_hands_route` +requires exactly one still-current route/authority/intent/review/grant chain, +requires at least one safe missing path outside the adopted scope, and refuses +to run after patch, command, commit, or PR consequences exist. Hands attests +inability; it does not revise RepoModel. In the same compare-and-swap, Mind +writes its review and admission receipts, retires the exact frontier through +`RepoModelPatchPurpose::RelinquishFrontierRoute`, emits the next Modeling +projection obligation, and records the companion relinquishment receipt. The +route and authority remain immutable historical evidence. Their old +model revision/hash can no longer validate after the retirement admission, so +they are structurally unable to authorize edits. Native status projects the +latest relinquishment; `epiphany-hands-action record-refusal` is the operator +mouth. Generic Modeling admission explicitly rejects this Mind-owned purpose, +and the full consequence/Soul path remains the only route to a `Resolved` +frontier. Planning failure has two adjacent authorities. The generic runtime job owns process and transport terminal status. The typed role result owns what Self may diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 8a917688..b0363796 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -175,8 +175,39 @@ Self derived exact Hands route `repo-frontier-route-d4d595821804c3f5bbe24d06084762ed19c3185a945827dfa6b10c53df798e2e`. The operator-safe gate is `.epiphany-dogfood/v49-hands-gate-r7/coordinator-summary.json`. Its six paths -include `epiphany-mvp-status.rs` but omit the app-server projection owner after -the proposal Modeling worker's only failed source read. Do not mutate source -under this incomplete gate. Preserve v49 and implement the missing typed -relinquishment path as a labeled supervisor intervention across all mapped -owners, then exercise it against a fresh incomplete route. +are the complete implementation owner set at that revision. The earlier claim +that `vendor/codex/codex-rs/app-server/src/epiphany.rs` was an omitted owner was +stale archaeology: that source does not exist and the vendored app-server has +no Epiphany projection. Do not mutate source under the historical v49 route, +because the newly discovered relinquishment transaction was never part of its +adopted plan. Preserve v49 and implement the missing typed relinquishment path +as a labeled supervisor intervention across the state model and real six-file +owner set, then exercise it against a fresh incomplete route. + +The labeled supervisor implementation is now local. Hands persists +`HandsActionRefusalReceipt`; Mind atomically retires the exact frontier and +writes review, admission, projection-obligation, and +`RepoFrontierRelinquishmentReceipt` companions through +`relinquish_repo_frontier_hands_route`. The transaction requires one current +route authority, at least one missing safe path outside route scope, and zero +patch/command/commit/PR consequences. Exact replay is idempotent; collision, +already-authorized paths, existing consequences, and reuse of the stale route +fail closed. `epiphany-hands-action record-refusal` is the operator mouth and +native status projects `frontierRelinquishment`. + +Focused proof is green: two relinquishment tests, all five existing Hands CLI +tests, both native status tests, and the state-model test pass. A broad +645-test library run passed 642 with one ignored and found two failures in +unchanged test bodies: autonomous direction ingestion expected one pressure +but observed zero, and the route eligibility test attempted to admit a +non-active proposal frontier that current admission already forbids. Both +failures reproduce unchanged in an isolated worktree at pushed HEAD +`d1d9cd10`; they are pre-existing suite corrosion, not regressions from the new +patch-purpose enum. The temporary baseline worktree was removed after the +comparison. Commit and push this pass, then package its exact source once. +The baseline worktree used temporary junctions for gitlink dependencies; its +forced removal cleared the live `cultcache-rs` and `cultnet-rs` submodule +worktrees. The evidence write caught the damage immediately. Both were restored +with `git submodule update --init --checkout` to pinned SHAs `7676a4c2` and +`fab5b31d`, and `git submodule status` is clean. Do not reuse junctioned live +submodule targets for future baseline archives. diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index 2b66a9686dcd497db9740c9cd4149eb19285ae15..b6c35bf5a879a1eb4f85a4f35144a8184404867b 100644 GIT binary patch delta 519 zcmY*VJx?1!5amn)DExsmNF!3>Gj=3PjyseOxj__Ap$KW&9djGq?Hn_^n9x{=f`-;| z2|ocrfrLbx|3ncfa~4gCr`egEH}B2dzHVOr-Ms&pt@nGw{^!F#OKUGjkDs#BEE`?T zTGz8yrfA}_;+^8XVnwm~G;6JWc%E-OXc*+(!9jO0?Dyt(TiM3+VXsCukvKOg7R3Gn z9Z1sRnHOU4A?g!D^c28Xb%~WG0!pd8g^>wPfGI@;#?pt=ArH$8#^yhZC^GOwBf(fBZ$eKL7v# delta 65 zcmZqtt2F>>_HY+n0GBUb1Pi1PK%ESo7AetG7S%8=oh}nRc Lefv}<4z67Q#_kkP diff --git a/state/map.yaml b/state/map.yaml index 5c8171b0..db04b496 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -34,9 +34,9 @@ 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 a6c23872 packages as sha256-5605ff00ffea1fce8f679868ae1081215707ef881cc5795172385aae27f96f0c with witness sha256-d9ed1d70a3e1db42b23761991a961f8e9c60531bd480ba01db7e8669a8bfd0e2. v46/v47 remain sealed negative evidence. Fresh route-free v49 proves proposal Modeling, canonical Imagination, dedicated Mind adoption, terminal planning lifecycle, and exact Hands gate without overrides. Canonicalized candidate ingress succeeded live; test evidence covers typed failure and reviewed immutable retries. The adopted v49 path ceiling includes the gateway, Hands CLI, runtime spine, and status composition but omits app-server projection after that source read failed, so mutation is not yet truthful. Persona consequence, retention, endurance, and Linux/Yggdrasil cognition remain open. + summary: Epiphany is a supervised engineering alpha on Starfire, not deployment-ready. Exact a6c23872 packages as sha256-5605ff00ffea1fce8f679868ae1081215707ef881cc5795172385aae27f96f0c with witness sha256-d9ed1d70a3e1db42b23761991a961f8e9c60531bd480ba01db7e8669a8bfd0e2. v46/v47 remain sealed negative evidence. Fresh route-free v49 proves proposal Modeling, canonical Imagination, dedicated Mind adoption, terminal planning lifecycle, and exact Hands gate without overrides. The historical v49 route remains immutable and cannot authorize the new relinquishment implementation. A labeled supervisor pass now gives Hands a typed refusal and Mind one atomic route-retirement admission; focused tests prove replay, collision, insufficient-gap, old-authority, and existing-consequence negatives. Persona consequence, retention, endurance, and Linux/Yggdrasil cognition remain open. operational_state: - local_worktree: v49_planning_proven_supervisor_relinquishment_implementation_next + local_worktree: supervisor_relinquishment_implemented_verification_and_commit_next operator_wireguard: restored yggdrasil: canonical_small_public_crossing_body starfire: temporary_epiphany_cognition_body @@ -52,8 +52,8 @@ current_status: bifrost_feedback_crossing: authenticated_transport_only yggdrasil_epiphany_services: absent resident_physiology: heartbeat_and_self_running - unresolved_authority: v49 proves the repaired live planning circuit through terminal Mind adoption. Its exact Hands gate still omits vendor/codex/codex-rs/app-server/src/epiphany.rs after the proposal Modeling worker failed that source read. The cataloged Hands action-refusal receipt still has no typed persistence or route-lifecycle transition, so v49 cannot lawfully relinquish its incomplete route and the source must not be mutated under that gate. - next_action: Preserve v49 as sealed planning and incomplete-gate evidence. Under the operator-authorized labeled supervisor intervention, implement the mapped Hands refusal receipt and Mind-owned frontier/route retirement path across the gateway, CLI, runtime spine, status composition, and app-server projection owners. Prove exact binding, replay refusal, stale model/frontier, old-route-authority, and no-fabricated-consequence negatives. Package, exercise the refusal against a fresh incomplete plan, then replay sealed v44 through corrected replanning, CRRC, accepted Reorientation, Continuity recovery, and Soul closure. + unresolved_authority: The supervisor implementation is local and verified but not yet committed, pushed, packaged, or exercised against a live coordinator-created route. The broad 645-test library run passed 642 with one ignored. Its two failures (`autonomous_direction_option_is_atomically_bound_and_selected_for_modeling` and `repo_frontier_route_refuses_unadmitted_and_ineligible_models`) reproduce unchanged against isolated pushed HEAD d1d9cd10, so they are pre-existing suite corrosion rather than relinquishment regressions. Focused relinquishment, Hands CLI, status, and state-model checks pass. + next_action: Commit and push the completed supervisor relinquishment pass with the isolated d1d9cd10 baseline comparison as its failure receipt. Package the exact source once, exercise `record-refusal` against a fresh incomplete coordinator route, prove native status and the retired model authority in-process, then replan and continue CRRC, accepted Reorientation, Continuity recovery, and Soul closure. active_subgoals: - Prove Persona, Self, Eyes, Modeling, Imagination, Hands, Soul, Mind, Continuity, and nervous-system behavior individually.