diff --git a/epiphany-core/src/agent_launch.rs b/epiphany-core/src/agent_launch.rs index f2f4db18..26851683 100644 --- a/epiphany-core/src/agent_launch.rs +++ b/epiphany-core/src/agent_launch.rs @@ -288,6 +288,32 @@ pub fn epiphany_role_launch_output_schema(role_id: EpiphanyRoleResultRoleId) -> required.push("statePatch"); } else if role_id == EpiphanyRoleResultRoleId::Modeling { if let Some(map) = properties.as_object_mut() { + map.insert( + "repositoryBodyObservationBasis".to_string(), + serde_json::json!({ + "type": "object", + "description": "Exact echo of the immutable repository Body observation basis supplied in the Modeling launch.", + "required": [ + "schemaVersion", "workspaceId", "swarmId", "runtimeId", "scope", + "bodyBindingSha256", "observationId", "generation", + "manifestRootSha256", "scanStartedAt", "scanFinishedAt" + ], + "properties": { + "schemaVersion": {"type": "string", "minLength": 1}, + "workspaceId": {"type": "string", "minLength": 1}, + "swarmId": {"type": "string", "minLength": 1}, + "runtimeId": {"type": "string", "minLength": 1}, + "scope": {"type": "string", "minLength": 1}, + "bodyBindingSha256": {"type": "string", "minLength": 1}, + "observationId": {"type": "string", "minLength": 1}, + "generation": {"type": "integer", "minimum": 1}, + "manifestRootSha256": {"type": "string", "minLength": 1}, + "scanStartedAt": {"type": "string", "minLength": 1}, + "scanFinishedAt": {"type": "string", "minLength": 1} + }, + "additionalProperties": false + }), + ); map.insert( "repoModelPatch".to_string(), serde_json::json!({ @@ -366,6 +392,7 @@ pub fn epiphany_role_launch_output_schema(role_id: EpiphanyRoleResultRoleId) -> } required.push("frontierNodeIds"); required.push("repoModelPatch"); + required.push("repositoryBodyObservationBasis"); } let mut schema = serde_json::json!({ "type": "object", @@ -658,6 +685,7 @@ pub fn build_epiphany_frontier_plan_mind_launch_request( state_revision: state.revision, objective: state.objective.clone(), dynamic_prompt_context: None, + repository_body_observation_basis: None, proposal_modeling_context: None, claim_repair_context: None, frontier_planning_context: None, @@ -753,6 +781,7 @@ pub fn build_epiphany_role_launch_request_with_dynamic_context( state_revision: state.revision, objective: state.objective.clone(), dynamic_prompt_context, + repository_body_observation_basis: None, proposal_modeling_context: None, claim_repair_context: None, frontier_planning_context: None, @@ -1121,6 +1150,17 @@ mod tests { #[test] fn modeling_schema_exposes_only_typed_authority_purposes() { let schema = epiphany_role_launch_output_schema(EpiphanyRoleResultRoleId::Modeling); + assert!( + schema["required"] + .as_array() + .unwrap() + .iter() + .any(|value| value == "repositoryBodyObservationBasis") + ); + assert_eq!( + schema["properties"]["repositoryBodyObservationBasis"]["additionalProperties"], + false + ); let purposes = schema["properties"]["repoModelPatch"]["properties"]["purpose"]["oneOf"] .as_array() .expect("typed Modeling purpose alternatives"); diff --git a/epiphany-core/src/bin/epiphany-mvp-coordinator.rs b/epiphany-core/src/bin/epiphany-mvp-coordinator.rs index 821943ad..6303411c 100644 --- a/epiphany-core/src/bin/epiphany-mvp-coordinator.rs +++ b/epiphany-core/src/bin/epiphany-mvp-coordinator.rs @@ -1699,6 +1699,7 @@ mod tests { proposal_modeling_request_id: String::new(), claim_repair_request_id: String::new(), frontier_plan_decision_id: String::new(), + repository_body_observation_basis: None, }; let mut cache = epiphany_core::runtime_spine_cache(store)?; cache.put(epiphany_core::MEMORY_GRAPH_KEY, &entry)?; diff --git a/epiphany-core/src/coordinator_acceptance.rs b/epiphany-core/src/coordinator_acceptance.rs index 71f2cada..9f04f387 100644 --- a/epiphany-core/src/coordinator_acceptance.rs +++ b/epiphany-core/src/coordinator_acceptance.rs @@ -268,6 +268,12 @@ pub fn accept_coordinator_role_finding( let patch = result .repo_model_patch()? .ok_or_else(|| anyhow::anyhow!("Modeling repoModelPatch failed to decode"))?; + let repository_body_observation_basis = result + .repository_body_observation_basis + .clone() + .ok_or_else(|| { + anyhow::anyhow!("Modeling result has no Repository Body observation basis") + })?; let candidate_review = RepoModelAdmissionReview { schema_version: REPO_MODEL_ADMISSION_REVIEW_SCHEMA_VERSION.to_string(), review_id: format!("repo-model-review-{result_id}"), @@ -281,6 +287,7 @@ pub fn accept_coordinator_role_finding( evidence_ids: finding.evidence_ids.clone(), reviewed_at: accepted_at.clone(), contract: REPO_MODEL_ADMISSION_CONTRACT.to_string(), + repository_body_observation_basis: Some(repository_body_observation_basis), }; let review = stable_repo_model_admission_review(store, candidate_review)?; commit_repo_model_admission(store, result_id, &review)?; @@ -329,7 +336,9 @@ fn stable_repo_model_admission_review( && existing.decision == candidate.decision && existing.evidence_ids == candidate.evidence_ids && existing.schema_version == candidate.schema_version - && existing.contract == candidate.contract => + && existing.contract == candidate.contract + && existing.repository_body_observation_basis + == candidate.repository_body_observation_basis => { Ok(existing) } @@ -1150,6 +1159,7 @@ mod tests { evidence_ids: vec!["evidence-split".to_string()], reviewed_at: "2026-07-13T09:00:01Z".to_string(), contract: REPO_MODEL_ADMISSION_CONTRACT.to_string(), + repository_body_observation_basis: None, }; let mut cache = coordinator_acceptance_cache(&store)?; cache.put(&existing.review_id, &existing)?; @@ -1176,6 +1186,7 @@ mod tests { proposal_modeling_request_id: String::new(), claim_repair_request_id: String::new(), frontier_plan_decision_id: String::new(), + repository_body_observation_basis: None, }, )?; let mut fresh = existing.clone(); diff --git a/epiphany-core/src/coordinator_launch.rs b/epiphany-core/src/coordinator_launch.rs index b3f5ce49..02fb2f37 100644 --- a/epiphany-core/src/coordinator_launch.rs +++ b/epiphany-core/src/coordinator_launch.rs @@ -22,6 +22,11 @@ pub fn commit_coordinator_job_launch( plan: &EpiphanyCoordinatorJobLaunchPlan, created_at: String, ) -> Result { + let body_basis = if request.owner_role == EPIPHANY_MODELING_OWNER_ROLE { + Some(observe_runtime_repository_body_basis(store)?) + } else { + None + }; let mut cache = coordinator_state_transaction::open_coordinator_state_transaction(store, current_state)?; commit_coordinator_job_launch_in_cache( @@ -31,6 +36,7 @@ pub fn commit_coordinator_job_launch( request, plan, created_at, + body_basis, Vec::new(), ) } @@ -42,6 +48,7 @@ fn commit_coordinator_job_launch_in_cache( request: &EpiphanyJobLaunchRequest, plan: &EpiphanyCoordinatorJobLaunchPlan, created_at: String, + repository_body_observation_basis: Option, injected_envelopes: Vec, ) -> Result { if thread_id != request.launch_document.thread_id() { @@ -55,6 +62,37 @@ fn commit_coordinator_job_launch_in_cache( let next_state = apply_coordinator_state_update_to_state(current_state, plan.state_update.clone(), None)?; let mut effective_launch_document = request.launch_document.clone(); + match &mut effective_launch_document { + EpiphanyWorkerLaunchDocument::Role(document) + if request.owner_role == EPIPHANY_MODELING_OWNER_ROLE => + { + if document.repository_body_observation_basis.is_some() { + return Err(anyhow!( + "caller-prepopulated repository Body basis is forbidden" + )); + } + document.repository_body_observation_basis = + Some(repository_body_observation_basis.ok_or_else(|| { + anyhow!("Modeling launch commit requires a repository Body basis") + })?); + } + EpiphanyWorkerLaunchDocument::Role(document) => { + if document.repository_body_observation_basis.is_some() + || repository_body_observation_basis.is_some() + { + return Err(anyhow!( + "non-Modeling launch cannot carry a repository Body basis" + )); + } + } + EpiphanyWorkerLaunchDocument::Reorient(_) => { + if repository_body_observation_basis.is_some() { + return Err(anyhow!( + "reorient launch cannot carry a repository Body basis" + )); + } + } + } let proposal_launch = if let Some(request_id) = request.proposal_modeling_request_id.as_deref() { let (selection, proposal, identity) = @@ -357,15 +395,22 @@ pub fn plan_coordinator_job_launch( caller_repair_projection, caller_planning_projection, caller_mind_projection, + caller_body_basis, ) = match &request.launch_document { EpiphanyWorkerLaunchDocument::Role(document) => ( document.proposal_modeling_context.as_ref(), document.claim_repair_context.as_ref(), document.frontier_planning_context.as_ref(), document.frontier_plan_mind_context.as_ref(), + document.repository_body_observation_basis.as_ref(), ), - EpiphanyWorkerLaunchDocument::Reorient(_) => (None, None, None, None), + EpiphanyWorkerLaunchDocument::Reorient(_) => (None, None, None, None, None), }; + if caller_body_basis.is_some() { + return Err(anyhow!( + "caller-prepopulated repository Body basis is forbidden; coordinator commit owns observation" + )); + } if caller_proposal_projection.is_some() { return Err(anyhow!( "caller-prepopulated proposal Modeling context is forbidden; coordinator commit owns projection" @@ -796,6 +841,10 @@ pub(crate) mod tests { &store, &format!("proposal-launch-swarm-{suffix}"), )?; + crate::runtime_spine::tests::bind_test_repository_body( + &store, + &format!("proposal-launch-workspace-{suffix}"), + )?; let state = EpiphanyThreadState::default(); let mut cache = coordinator_acceptance_cache(&store)?; cache.put( @@ -986,6 +1035,7 @@ pub(crate) mod tests { candidate.candidate_id = canonical_repo_frontier_plan_candidate_id(&candidate)?; Ok(EpiphanyRuntimeRoleWorkerResult { schema_version: RUNTIME_ROLE_WORKER_RESULT_SCHEMA_VERSION.into(), + repository_body_observation_basis: None, result_id: format!("frontier-planning-result-{job_id}"), job_id: job_id.into(), role_id: "imagination".into(), @@ -1028,7 +1078,8 @@ pub(crate) mod tests { store, &imagination_result.result_id, "2026-07-15T09:00:05Z", - )?; + ) + .map_err(|error| anyhow!("commit frontier Mind request: {error}"))?; let mut cache = coordinator_acceptance_cache(store)?; cache.pull_all_backing_stores()?; let state = cache @@ -1070,6 +1121,7 @@ pub(crate) mod tests { }; let result = EpiphanyRuntimeRoleWorkerResult { schema_version: RUNTIME_ROLE_WORKER_RESULT_SCHEMA_VERSION.into(), + repository_body_observation_basis: None, result_id: format!("frontier-mind-result-{suffix}"), job_id, role_id: "mindAdmissionReview".into(), @@ -1100,7 +1152,8 @@ pub(crate) mod tests { frontier_plan_mind_request_id: Some(mind_request.request_id), frontier_plan_mind_decision_msgpack: Some(rmp_serde::to_vec_named(&payload)?), }; - put_runtime_role_worker_result(store, &result)?; + put_runtime_role_worker_result(store, &result) + .map_err(|error| anyhow!("persist frontier Mind result: {error}"))?; Ok(result) } @@ -1239,6 +1292,7 @@ pub(crate) mod tests { &request, &plan, "2026-07-11T00:00:00Z".to_string(), + None, vec![poison], ) .is_err() @@ -1609,7 +1663,6 @@ pub(crate) mod tests { )?; let result = frontier_planning_result(&planning, "backend-result", "2026-07-15T09:00:04Z")?; put_runtime_role_worker_result(&store, &result)?; - put_runtime_role_worker_result(&store, &result)?; let stored = runtime_role_worker_result(&store, "backend-result")? .expect("immutable planning result"); assert_eq!(stored, result); @@ -1693,7 +1746,8 @@ pub(crate) mod tests { fn mind_adopt_installs_plan_in_model_and_hands_route_copies_it() -> Result<()> { let root = tempfile::tempdir()?; let (store, state, launch, planning) = - frontier_planning_launch_fixture(root.path(), "mind-adopt")?; + frontier_planning_launch_fixture(root.path(), "mind-adopt") + .map_err(|error| anyhow!("build frontier planning launch fixture: {error}"))?; let plan = plan_coordinator_job_launch( &state, &launch, @@ -1708,12 +1762,15 @@ pub(crate) mod tests { &launch, &plan, "2026-07-15T09:00:03Z".into(), - )?; + ) + .map_err(|error| anyhow!("commit frontier Imagination launch: {error}"))?; let result = frontier_planning_result(&planning, "backend-mind-adopt", "2026-07-15T09:00:04Z")?; - put_runtime_role_worker_result(&store, &result)?; + put_runtime_role_worker_result(&store, &result) + .map_err(|error| anyhow!("persist frontier Imagination result: {error}"))?; let mind_result = - launch_frontier_mind_result(&store, &result, RepoFrontierPlanDecision::Adopt, "adopt")?; + launch_frontier_mind_result(&store, &result, RepoFrontierPlanDecision::Adopt, "adopt") + .map_err(|error| anyhow!("launch frontier Mind result: {error}"))?; let before = runtime_current_repo_model(&store)?.expect("pre-Adopt model"); let mut illicit_item = before @@ -1733,8 +1790,10 @@ pub(crate) mod tests { }; assert!(derive_repo_model_patch(&before, &illicit).is_err()); - let decision = commit_repo_frontier_plan_decision(&store, &mind_result.result_id)?; - let retry = commit_repo_frontier_plan_decision(&store, &mind_result.result_id)?; + let decision = commit_repo_frontier_plan_decision(&store, &mind_result.result_id) + .map_err(|error| anyhow!("commit frontier plan decision: {error}"))?; + let retry = commit_repo_frontier_plan_decision(&store, &mind_result.result_id) + .map_err(|error| anyhow!("replay frontier plan decision: {error}"))?; assert_eq!(retry, decision); assert!(!decision.model_admission_receipt_id.is_empty()); let current = runtime_current_repo_model(&store)?.expect("admitted Adopt model"); @@ -1893,8 +1952,42 @@ pub(crate) mod tests { )?; assert_eq!(verification_request.route_id, route.route_id); + let verification_state = EpiphanyThreadState::default(); + let verification_launch = build_epiphany_role_launch_request( + &planning.thread_id, + EpiphanyRoleResultRoleId::Verification, + Some(verification_state.revision), + Some(60), + &verification_state, + ) + .map_err(|error| anyhow!(error))?; + crate::open_runtime_spine_heartbeat_job( + &store, + crate::RuntimeSpineHeartbeatJobOptions { + runtime_id: "proposal-runtime-mind-adopt".into(), + display_name: "Adopt verification fixture".into(), + session_id: planning.thread_id.clone(), + objective: "Verify the exact adopted plan consequence.".into(), + coordinator_note: "Fixture immutable Verification launch.".into(), + job_id: "adopt-verification-job".into(), + role: verification_launch.owner_role, + binding_id: verification_launch.binding_id, + authority_scope: verification_launch.authority_scope, + instruction: verification_launch.instruction, + launch_document: verification_launch.launch_document, + output_contract_id: verification_launch.output_contract_id, + organ_launch_contract: verification_launch.organ_launch_contract, + proposal_modeling_request_id: None, + claim_repair_request_id: None, + frontier_planning_request_id: None, + frontier_plan_mind_request_id: None, + created_at: "2026-07-15T09:00:17Z".into(), + }, + )?; + let verification_result = crate::EpiphanyRuntimeRoleWorkerResult { schema_version: crate::RUNTIME_ROLE_WORKER_RESULT_SCHEMA_VERSION.into(), + repository_body_observation_basis: None, result_id: "adopt-verification-result".into(), job_id: "adopt-verification-job".into(), role_id: "verification".into(), @@ -1963,6 +2056,29 @@ pub(crate) mod tests { &crate::EpiphanyThreadStateEntry::from_state("mind-adopt-thread", &accepted_state)?, )?; let modeling_request = crate::commit_repo_frontier_modeling_request(&store, &acceptance)?; + let incorporation_launch = build_epiphany_role_launch_request( + "mind-adopt-thread", + EpiphanyRoleResultRoleId::Modeling, + Some(accepted_state.revision), + Some(60), + &accepted_state, + ) + .map_err(|error| anyhow!(error))?; + let incorporation_launch_plan = plan_coordinator_job_launch( + &accepted_state, + &incorporation_launch, + &store, + "adopt-incorporation-launcher".into(), + "adopt-incorporation-job".into(), + )?; + commit_coordinator_job_launch( + &store, + "mind-adopt-thread", + &accepted_state, + &incorporation_launch, + &incorporation_launch_plan, + "2026-07-15T09:00:18Z".into(), + )?; let pre_incorporation = crate::runtime_current_repo_model(&store)?.expect("model before verdict incorporation"); @@ -2004,6 +2120,10 @@ pub(crate) mod tests { let incorporation_bytes = rmp_serde::to_vec_named(&incorporation_patch)?; let modeling_result = crate::EpiphanyRuntimeRoleWorkerResult { schema_version: crate::RUNTIME_ROLE_WORKER_RESULT_SCHEMA_VERSION.into(), + repository_body_observation_basis: crate::runtime_worker_launch_body_basis( + &store, + "adopt-incorporation-job", + )?, result_id: "adopt-incorporation-result".into(), job_id: "adopt-incorporation-job".into(), role_id: "modeling".into(), @@ -2048,6 +2168,9 @@ pub(crate) mod tests { evidence_ids: modeling_result.evidence_ids.clone(), reviewed_at: "2026-07-15T09:00:20Z".into(), contract: crate::REPO_MODEL_ADMISSION_CONTRACT.into(), + repository_body_observation_basis: modeling_result + .repository_body_observation_basis + .clone(), }; let incorporation = crate::commit_repo_model_admission( &store, diff --git a/epiphany-core/src/coordinator_launch_context.rs b/epiphany-core/src/coordinator_launch_context.rs index f1a5d3ea..bac46bf1 100644 --- a/epiphany-core/src/coordinator_launch_context.rs +++ b/epiphany-core/src/coordinator_launch_context.rs @@ -931,6 +931,10 @@ mod tests { let patch_bytes = rmp_serde::to_vec_named(&patch)?; let result = crate::EpiphanyRuntimeRoleWorkerResult { schema_version: crate::RUNTIME_ROLE_WORKER_RESULT_SCHEMA_VERSION.to_string(), + repository_body_observation_basis: crate::runtime_worker_launch_body_basis( + store, + "context-route-job", + )?, result_id: "context-route-result".to_string(), job_id: "context-route-job".to_string(), role_id: "modeling".to_string(), @@ -978,6 +982,7 @@ mod tests { evidence_ids: result.evidence_ids.clone(), reviewed_at: "2026-06-12T00:00:04Z".to_string(), contract: crate::REPO_MODEL_ADMISSION_CONTRACT.to_string(), + repository_body_observation_basis: result.repository_body_observation_basis.clone(), }, )?; let route = crate::select_and_commit_repo_frontier_route(store, "2026-06-12T00:00:05Z")?; @@ -1129,6 +1134,10 @@ mod tests { &agent_store, "2026-07-12T00:00:01Z", )?; + crate::runtime_spine::tests::bind_test_repository_body( + &runtime_store, + "launch-context-workspace", + )?; let state = EpiphanyThreadState { revision: 7, objective: Some("Test launch context.".to_string()), @@ -1155,7 +1164,7 @@ mod tests { assert!(local_verse_store_path(&runtime_store).exists()); assert!(runtime_store.exists()); - let launch_request = build_epiphany_role_launch_request_with_dynamic_context( + let mut launch_request = build_epiphany_role_launch_request_with_dynamic_context( "thread-1", EpiphanyRoleResultRoleId::Modeling, Some(state.revision), @@ -1164,6 +1173,14 @@ mod tests { Some(rendered.clone()), ) .map_err(anyhow::Error::msg)?; + let crate::EpiphanyWorkerLaunchDocument::Role(role_document) = + &mut launch_request.launch_document + else { + unreachable!("role launch builder returned reorient document") + }; + role_document.repository_body_observation_basis = Some( + crate::observe_runtime_repository_body_basis(&runtime_store)?, + ); open_runtime_spine_heartbeat_job( &runtime_store, RuntimeSpineHeartbeatJobOptions { @@ -1282,6 +1299,14 @@ mod tests { created_at: "2026-06-12T00:00:00Z".to_string(), }, )?; + crate::runtime_spine::tests::bind_test_runtime_swarm( + &runtime_store, + "hands-context-swarm", + )?; + crate::runtime_spine::tests::bind_test_repository_body( + &runtime_store, + "hands-context-workspace", + )?; let stdout = temp.join("stdout.log"); let stderr = temp.join("stderr.log"); fs::write(&stdout, "running 5 tests\ntest result: ok")?; @@ -1445,8 +1470,40 @@ mod tests { verification_request_id, )? .expect("persisted exact verification request"); + let verification_launch = crate::build_epiphany_role_launch_request( + "context-thread", + crate::EpiphanyRoleResultRoleId::Verification, + Some(state.revision), + Some(60), + &state, + ) + .map_err(anyhow::Error::msg)?; + crate::open_runtime_spine_heartbeat_job( + &runtime_store, + crate::RuntimeSpineHeartbeatJobOptions { + runtime_id: "epiphany-hands-context-test".to_string(), + display_name: "Epiphany Hands Context Test".to_string(), + session_id: "context-thread".to_string(), + objective: "Verify the exact Hands receipt chain.".to_string(), + coordinator_note: "Fixture immutable Verification launch.".to_string(), + job_id: "verification-job-context".to_string(), + role: verification_launch.owner_role, + binding_id: verification_launch.binding_id, + authority_scope: verification_launch.authority_scope, + instruction: verification_launch.instruction, + launch_document: verification_launch.launch_document, + output_contract_id: verification_launch.output_contract_id, + organ_launch_contract: verification_launch.organ_launch_contract, + proposal_modeling_request_id: None, + claim_repair_request_id: None, + frontier_planning_request_id: None, + frontier_plan_mind_request_id: None, + created_at: "2026-06-12T00:00:06Z".to_string(), + }, + )?; let verification_result = crate::EpiphanyRuntimeRoleWorkerResult { schema_version: crate::RUNTIME_ROLE_WORKER_RESULT_SCHEMA_VERSION.to_string(), + repository_body_observation_basis: None, result_id: "result-verification-context".to_string(), job_id: "verification-job-context".to_string(), role_id: "verification".to_string(), diff --git a/epiphany-core/src/lib.rs b/epiphany-core/src/lib.rs index 07ea99be..6718b5df 100644 --- a/epiphany-core/src/lib.rs +++ b/epiphany-core/src/lib.rs @@ -936,6 +936,7 @@ pub use runtime_spine::runtime_spine_status; pub use runtime_spine::runtime_substrate_gate_repo_access_grant_receipt; pub use runtime_spine::runtime_swarm_binding; pub use runtime_spine::runtime_tool_invocation_statuses; +pub use runtime_spine::runtime_worker_launch_body_basis; pub use runtime_spine::runtime_worker_launch_request; pub use runtime_spine::select_and_commit_repo_frontier_planning_request; pub use runtime_spine::select_and_commit_repo_frontier_route; diff --git a/epiphany-core/src/repo_model_gateway.rs b/epiphany-core/src/repo_model_gateway.rs index 684a9a75..70eb8166 100644 --- a/epiphany-core/src/repo_model_gateway.rs +++ b/epiphany-core/src/repo_model_gateway.rs @@ -4,14 +4,14 @@ use serde::{Deserialize, Serialize}; pub const REPO_MODEL_ADMISSION_REVIEW_TYPE: &str = "epiphany.mind.repo_model_admission_review"; pub const REPO_MODEL_ADMISSION_REVIEW_SCHEMA_VERSION: &str = - "epiphany.mind.repo_model_admission_review.v0"; + "epiphany.mind.repo_model_admission_review.v1"; pub const REPO_MODEL_ADMISSION_RECEIPT_TYPE: &str = "epiphany.mind.repo_model_admission_receipt"; pub const REPO_MODEL_ADMISSION_RECEIPT_SCHEMA_VERSION: &str = - "epiphany.mind.repo_model_admission_receipt.v4"; + "epiphany.mind.repo_model_admission_receipt.v5"; pub const REPO_MODEL_MIGRATION_RECEIPT_TYPE: &str = "epiphany.mind.repo_model_migration_receipt"; pub const REPO_MODEL_MIGRATION_RECEIPT_SCHEMA_VERSION: &str = "epiphany.mind.repo_model_migration_receipt.v0"; -pub const REPO_MODEL_ADMISSION_CONTRACT: &str = "epiphany.repo_model_admission.v4"; +pub const REPO_MODEL_ADMISSION_CONTRACT: &str = "epiphany.repo_model_admission.v5"; pub const REPO_MODEL_MIGRATION_CONTRACT: &str = "epiphany.repo_model_migration.v0"; pub const REPO_FRONTIER_ROUTE_TYPE: &str = "epiphany.self.repo_frontier_route"; pub const REPO_FRONTIER_ROUTE_SCHEMA_VERSION: &str = "epiphany.self.repo_frontier_route.v1"; @@ -715,6 +715,8 @@ pub struct RepoModelAdmissionReview { pub reviewed_at: String, #[cultcache(key = 11)] pub contract: String, + #[cultcache(key = 12)] + pub repository_body_observation_basis: Option, } #[derive(Debug, Clone, PartialEq, Eq, DatabaseEntry)] @@ -763,6 +765,8 @@ pub struct RepoModelAdmissionReceipt { pub claim_repair_request_id: String, #[cultcache(key = 19, default)] pub frontier_plan_decision_id: String, + #[cultcache(key = 20)] + pub repository_body_observation_basis: Option, } #[derive(Debug, Clone, PartialEq, Eq, DatabaseEntry)] diff --git a/epiphany-core/src/repository_body_observer.rs b/epiphany-core/src/repository_body_observer.rs index f8864d21..5e4916fd 100644 --- a/epiphany-core/src/repository_body_observer.rs +++ b/epiphany-core/src/repository_body_observer.rs @@ -75,6 +75,22 @@ pub struct RuntimeRepositoryBodyStoreBinding { pub body_binding_sha256: String, } +#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct RepositoryBodyObservationBasis { + pub schema_version: String, + pub workspace_id: String, + pub swarm_id: String, + pub runtime_id: String, + pub scope: String, + pub body_binding_sha256: String, + pub observation_id: String, + pub generation: u64, + pub manifest_root_sha256: String, + pub scan_started_at: String, + pub scan_finished_at: String, +} + #[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)] #[cultcache( type = "epiphany.repository_body.observation", @@ -237,6 +253,75 @@ pub fn runtime_repository_body_store_binding( Ok(Some(binding)) } +pub fn observe_runtime_repository_body_basis( + runtime_store: &Path, +) -> Result { + let route = runtime_repository_body_store_binding(runtime_store)? + .ok_or_else(|| anyhow!("runtime has no repository Body-store binding"))?; + let body_store = PathBuf::from(&route.body_store_path); + let entries = load_body_envelopes(&body_store)?; + let body_env = find(&entries, BODY_BINDING_TYPE, BODY_BINDING_KEY) + .ok_or_else(|| anyhow!("runtime repository Body store has no Body binding"))?; + let body: RepositoryBodyBinding = decode(body_env)?; + let observation = match observe_repository_body( + Path::new(&body.git_top_level), + &body_store, + runtime_store, + )? { + ObserveOutcome::Created(value) | ObserveOutcome::Unchanged(value) => value, + }; + Ok(RepositoryBodyObservationBasis { + schema_version: BODY_SCHEMA_VERSION.into(), + workspace_id: body.workspace_id, + swarm_id: body.swarm_id, + runtime_id: body.runtime_id, + scope: body.scope, + body_binding_sha256: route.body_binding_sha256, + observation_id: observation.observation_id, + generation: observation.generation, + manifest_root_sha256: observation.manifest_root_sha256, + scan_started_at: observation.scan_started_at, + scan_finished_at: observation.scan_finished_at, + }) +} + +pub fn validate_repository_body_observation_basis( + runtime_store: &Path, + basis: &RepositoryBodyObservationBasis, +) -> Result<()> { + let route = runtime_repository_body_store_binding(runtime_store)? + .ok_or_else(|| anyhow!("runtime has no repository Body-store binding"))?; + if basis.schema_version != BODY_SCHEMA_VERSION + || basis.runtime_id != route.runtime_id + || basis.swarm_id != route.swarm_id + || basis.workspace_id != route.workspace_id + || basis.body_binding_sha256 != route.body_binding_sha256 + || basis.generation == 0 + || basis.observation_id != format!("{}:{}", basis.workspace_id, basis.generation) + { + bail!("repository Body observation basis disagrees with its immutable runtime route"); + } + let entries = load_body_envelopes(Path::new(&route.body_store_path))?; + let binding_env = find(&entries, BODY_BINDING_TYPE, BODY_BINDING_KEY) + .ok_or_else(|| anyhow!("runtime repository Body store has no Body binding"))?; + let binding: RepositoryBodyBinding = decode(binding_env)?; + let historical_head = RepositoryBodyHead { + schema_version: BODY_SCHEMA_VERSION.into(), + workspace_id: basis.workspace_id.clone(), + generation: basis.generation, + observation_id: basis.observation_id.clone(), + manifest_root_sha256: basis.manifest_root_sha256.clone(), + }; + let (observation, _) = validate_body_chain(&entries, &binding, &historical_head)?; + if observation.scan_started_at != basis.scan_started_at + || observation.scan_finished_at != basis.scan_finished_at + || observation.scope != basis.scope + { + bail!("repository Body observation basis does not match its persisted observation"); + } + Ok(()) +} + pub fn observe_repository_body( repo: &Path, store: &Path, diff --git a/epiphany-core/src/runtime_spine.rs b/epiphany-core/src/runtime_spine.rs index 8a4660a9..14cad38f 100644 --- a/epiphany-core/src/runtime_spine.rs +++ b/epiphany-core/src/runtime_spine.rs @@ -173,7 +173,7 @@ pub const RUNTIME_SPINE_SCHEMA_VERSION: &str = "epiphany.runtime_spine.v0"; pub const RUNTIME_WORKER_LAUNCH_REQUEST_SCHEMA_VERSION: &str = "epiphany.runtime.worker_launch_request.v1"; pub const RUNTIME_ROLE_WORKER_RESULT_SCHEMA_VERSION: &str = - "epiphany.runtime.role_worker_result.v2"; + "epiphany.runtime.role_worker_result.v3"; pub const RUNTIME_REORIENT_WORKER_RESULT_SCHEMA_VERSION: &str = "epiphany.runtime.reorient_worker_result.v0"; pub const COORDINATOR_RUN_RECEIPT_SCHEMA_VERSION: &str = "epiphany.coordinator_run_receipt.v0"; @@ -357,6 +357,17 @@ impl EpiphanyRuntimeWorkerLaunchRequest { } Ok(document) } + + pub fn repository_body_observation_basis( + &self, + ) -> Result> { + Ok(match self.launch_document()? { + EpiphanyWorkerLaunchDocument::Role(document) => { + document.repository_body_observation_basis + } + EpiphanyWorkerLaunchDocument::Reorient(_) => None, + }) + } } #[derive(Clone, Debug, PartialEq, DatabaseEntry)] @@ -425,6 +436,8 @@ pub struct EpiphanyRuntimeRoleWorkerResult { pub frontier_plan_mind_request_id: Option, #[cultcache(key = 29, default)] pub frontier_plan_mind_decision_msgpack: Option>, + #[cultcache(key = 30, default)] + pub repository_body_observation_basis: Option, } impl EpiphanyRuntimeRoleWorkerResult { @@ -1233,6 +1246,7 @@ pub fn open_runtime_spine_heartbeat_job( validate_non_empty(&options.objective, "objective")?; validate_non_empty(&options.job_id, "job id")?; validate_non_empty(&options.role, "role")?; + validate_repository_body_launch_carrier(&options.role, &options.launch_document)?; validate_proposal_modeling_launch_carrier( &options.role, &options.binding_id, @@ -1353,6 +1367,7 @@ pub fn prepare_runtime_spine_heartbeat_job( validate_non_empty(&options.objective, "objective")?; validate_non_empty(&options.job_id, "job id")?; validate_non_empty(&options.role, "role")?; + validate_repository_body_launch_carrier(&options.role, &options.launch_document)?; validate_proposal_modeling_launch_carrier( &options.role, &options.binding_id, @@ -1528,6 +1543,37 @@ fn validate_proposal_modeling_launch_carrier( Ok(()) } +fn validate_repository_body_launch_carrier( + role: &str, + launch_document: &EpiphanyWorkerLaunchDocument, +) -> Result<()> { + let (document_role, basis) = match launch_document { + EpiphanyWorkerLaunchDocument::Role(document) => ( + Some(document.role_id.as_str()), + document.repository_body_observation_basis.as_ref(), + ), + EpiphanyWorkerLaunchDocument::Reorient(_) => (None, None), + }; + let owner_is_modeling = role == EPIPHANY_MODELING_OWNER_ROLE; + let document_is_modeling = document_role.is_some_and(|value| value == "modeling"); + if owner_is_modeling != document_is_modeling { + return Err(anyhow!( + "Modeling runtime owner and typed launch role must agree" + )); + } + if owner_is_modeling && basis.is_none() { + return Err(anyhow!( + "Modeling runtime launch requires a pre-thought repository Body basis" + )); + } + if !owner_is_modeling && basis.is_some() { + return Err(anyhow!( + "non-Modeling runtime launch cannot carry a repository Body basis" + )); + } + Ok(()) +} + fn validate_claim_repair_launch_carrier( role: &str, binding_id: &str, @@ -1634,6 +1680,15 @@ pub fn runtime_worker_launch_request( cache.get::(job_id) } +pub fn runtime_worker_launch_body_basis( + store_path: impl AsRef, + job_id: &str, +) -> Result> { + runtime_worker_launch_request(store_path, job_id)? + .ok_or_else(|| anyhow!("worker launch request {job_id:?} is missing"))? + .repository_body_observation_basis() +} + pub fn put_runtime_role_worker_result( store_path: impl AsRef, result: &EpiphanyRuntimeRoleWorkerResult, @@ -1647,6 +1702,37 @@ pub fn put_runtime_role_worker_result( } let mut cache = runtime_spine_cache(store_path)?; cache.pull_all_backing_stores()?; + let worker_launch = cache + .get::(&result.job_id)? + .ok_or_else(|| anyhow!("role worker result requires its immutable worker launch"))?; + let launch_document = worker_launch.launch_document()?; + let launch_body_basis = match &launch_document { + EpiphanyWorkerLaunchDocument::Role(document) => { + document.repository_body_observation_basis.as_ref() + } + EpiphanyWorkerLaunchDocument::Reorient(_) => None, + }; + let launch_is_modeling = worker_launch.role == EPIPHANY_MODELING_OWNER_ROLE; + let result_is_modeling = result.role_id.eq_ignore_ascii_case("modeling"); + if launch_is_modeling != result_is_modeling { + return Err(anyhow!( + "role worker result cannot substitute Modeling launch authority" + )); + } + if launch_is_modeling { + let expected = launch_body_basis.ok_or_else(|| { + anyhow!("Modeling worker launch is missing its repository Body observation basis") + })?; + if result.repository_body_observation_basis.as_ref() != Some(expected) { + return Err(anyhow!( + "Modeling result must exactly echo its immutable launch repository Body observation basis" + )); + } + } else if launch_body_basis.is_some() || result.repository_body_observation_basis.is_some() { + return Err(anyhow!( + "non-Modeling worker launch and result must not carry a repository Body observation basis" + )); + } let is_verification = result.role_id == "verification"; if is_verification != (result @@ -2174,6 +2260,44 @@ pub fn commit_repo_model_admission( "repo model admission result role/job binding mismatch" )); } + let worker_launch = cache + .get::(&result.job_id)? + .ok_or_else(|| anyhow!("repo model admission requires the immutable Modeling launch"))?; + let launch_document = worker_launch.launch_document()?; + let launch_basis = match &launch_document { + EpiphanyWorkerLaunchDocument::Role(document) => document + .repository_body_observation_basis + .as_ref() + .ok_or_else(|| { + anyhow!("repo model admission launch has no repository Body observation basis") + })?, + EpiphanyWorkerLaunchDocument::Reorient(_) => { + return Err(anyhow!( + "repo model admission cannot originate from reorientation" + )); + } + }; + let result_basis = result + .repository_body_observation_basis + .as_ref() + .ok_or_else(|| { + anyhow!("repo model admission result has no repository Body observation basis") + })?; + let review_basis = review + .repository_body_observation_basis + .as_ref() + .ok_or_else(|| { + anyhow!("repo model admission review has no repository Body observation basis") + })?; + if worker_launch.role != EPIPHANY_MODELING_OWNER_ROLE + || launch_basis != result_basis + || launch_basis != review_basis + { + return Err(anyhow!( + "repo model admission requires one exact launch/result/review repository Body observation basis" + )); + } + crate::validate_repository_body_observation_basis(runtime_store, launch_basis)?; let patch_bytes = result .repo_model_patch_msgpack .as_deref() @@ -2244,6 +2368,8 @@ pub fn commit_repo_model_admission( || !existing_receipt.soul_verdict_receipt_id.is_empty() || !existing_receipt.frontier_modeling_request_id.is_empty() || !existing_receipt.proposal_modeling_request_id.is_empty() + || existing_receipt.repository_body_observation_basis + != review.repository_body_observation_basis { return Err(anyhow!("repo model admission receipt identity collision")); } @@ -2885,6 +3011,8 @@ pub fn commit_repo_model_admission( || existing_receipt.proposal_modeling_request_id != proposal_modeling_request_id || existing_receipt.claim_repair_request_id != claim_repair_request_id || !existing_receipt.frontier_plan_decision_id.is_empty() + || existing_receipt.repository_body_observation_basis + != review.repository_body_observation_basis { return Err(anyhow!("repo model admission receipt identity collision")); } @@ -3012,6 +3140,7 @@ pub fn commit_repo_model_admission( proposal_modeling_request_id, claim_repair_request_id, frontier_plan_decision_id: String::new(), + repository_body_observation_basis: review.repository_body_observation_basis.clone(), }; let (next_model_envelope, _) = cache.prepare_entry(crate::MEMORY_GRAPH_KEY, &next_entry)?; let (review_envelope, _) = cache.prepare_entry(&review.review_id, review)?; @@ -4529,6 +4658,7 @@ fn commit_repo_frontier_plan_decision_inner( ], reviewed_at: decided_at.to_string(), contract: REPO_MODEL_ADMISSION_CONTRACT.into(), + repository_body_observation_basis: None, }; let admission = RepoModelAdmissionReceipt { schema_version: REPO_MODEL_ADMISSION_RECEIPT_SCHEMA_VERSION.into(), @@ -4551,6 +4681,7 @@ fn commit_repo_frontier_plan_decision_inner( proposal_modeling_request_id: String::new(), claim_repair_request_id: String::new(), frontier_plan_decision_id: decision_id.clone(), + repository_body_observation_basis: None, }; let obligation = modeling_projection_obligation( &cache, @@ -7649,6 +7780,85 @@ pub(crate) mod tests { Ok(()) } + pub(crate) fn bind_test_repository_body(store: &Path, workspace_id: &str) -> Result<()> { + if crate::runtime_repository_body_store_binding(store)?.is_some() { + return Ok(()); + } + let repo = store.with_extension(format!("{workspace_id}.body-repo")); + std::fs::create_dir_all(&repo)?; + let init = std::process::Command::new("git") + .args(["init", "--quiet"]) + .current_dir(&repo) + .output()?; + if !init.status.success() { + return Err(anyhow!("test repository git init failed")); + } + std::fs::write(repo.join("body-seed.txt"), workspace_id.as_bytes())?; + let add = std::process::Command::new("git") + .args(["add", "body-seed.txt"]) + .current_dir(&repo) + .output()?; + if !add.status.success() { + return Err(anyhow!("test repository git add failed")); + } + let body_store = store.with_extension(format!("{workspace_id}.body.cc")); + crate::bind_repository_body(&repo, &body_store, store, workspace_id)?; + Ok(()) + } + + fn put_test_non_modeling_worker_launch(store: &Path, job_id: &str, role: &str) -> Result<()> { + let document = + EpiphanyWorkerLaunchDocument::Role(crate::EpiphanyRoleWorkerLaunchDocument { + thread_id: format!("fixture-thread-{job_id}"), + role_id: role.to_string(), + state_revision: 0, + objective: Some(format!("Fixture {role} launch")), + dynamic_prompt_context: None, + repository_body_observation_basis: None, + proposal_modeling_context: None, + claim_repair_context: None, + frontier_planning_context: None, + frontier_plan_mind_context: None, + active_subgoal_id: None, + active_subgoals: Vec::new(), + active_graph_node_ids: Vec::new(), + investigation_checkpoint: None, + scratch: None, + invariants: Vec::new(), + graphs: None, + recent_evidence: Vec::new(), + recent_observations: Vec::new(), + graph_frontier: None, + graph_checkpoint: None, + planning: None, + churn: None, + }); + let request = EpiphanyRuntimeWorkerLaunchRequest { + schema_version: RUNTIME_WORKER_LAUNCH_REQUEST_SCHEMA_VERSION.to_string(), + job_id: job_id.to_string(), + binding_id: format!("{role}-worker"), + role: role.to_string(), + authority_scope: role.to_string(), + instruction: format!("Fixture {role} instruction"), + output_contract_id: crate::ROLE_WORKER_OUTPUT_CONTRACT_ID.to_string(), + document_kind: worker_launch_document_kind(&document).to_string(), + launch_document_msgpack: encode_worker_launch_document(&document)?, + metadata: BTreeMap::new(), + organ_launch_contract: crate::default_launch_organ_contract( + role, + "role", + crate::ROLE_WORKER_OUTPUT_CONTRACT_ID, + ), + proposal_modeling_request_id: None, + claim_repair_request_id: None, + frontier_planning_request_id: None, + frontier_plan_mind_request_id: None, + }; + let mut cache = runtime_spine_cache(store)?; + cache.put(job_id, &request)?; + Ok(()) + } + #[test] fn legacy_repo_model_migration_adds_only_exact_projection_pressure() -> Result<()> { let root = tempdir()?; @@ -7754,6 +7964,7 @@ pub(crate) mod tests { format!("launcher-{job_id}"), job_id.to_string(), )?; + bind_test_repository_body(store, &format!("workspace-{result_id}"))?; crate::commit_coordinator_job_launch( store, &thread_id, @@ -7786,6 +7997,7 @@ pub(crate) mod tests { let patch_bytes = rmp_serde::to_vec_named(&patch)?; let result = EpiphanyRuntimeRoleWorkerResult { schema_version: RUNTIME_ROLE_WORKER_RESULT_SCHEMA_VERSION.to_string(), + repository_body_observation_basis: runtime_worker_launch_body_basis(store, job_id)?, result_id: result_id.to_string(), job_id: job_id.to_string(), role_id: "modeling".to_string(), @@ -7829,10 +8041,109 @@ pub(crate) mod tests { evidence_ids: result.evidence_ids.clone(), reviewed_at: "2026-07-13T04:00:01Z".to_string(), contract: REPO_MODEL_ADMISSION_CONTRACT.to_string(), + repository_body_observation_basis: result.repository_body_observation_basis.clone(), }; Ok((result, review)) } + #[test] + fn modeling_result_ingress_requires_the_exact_immutable_launch_body_basis() -> Result<()> { + for mutation in ["missing", "swapped"] { + let root = tempdir()?; + let store = root.path().join(format!("body-basis-{mutation}.cc")); + initialize_runtime_spine( + &store, + RuntimeSpineInitOptions { + runtime_id: format!("body-basis-runtime-{mutation}"), + display_name: "Body basis ingress".into(), + created_at: "2026-07-15T00:00:00Z".into(), + }, + )?; + bind_test_runtime_swarm(&store, &format!("body-basis-swarm-{mutation}"))?; + let bootstrap = repo_model_bootstrap(); + let legacy = root.path().join(format!("body-basis-{mutation}.legacy")); + let (current, _) = + ensure_runtime_repo_model(&store, &legacy, &bootstrap, "2026-07-15T00:00:01Z")?; + let (mut result, _) = repo_model_result_and_review( + &store, + &format!("body-basis-result-{mutation}"), + &format!("body-basis-job-{mutation}"), + ¤t, + &format!("body-basis-review-{mutation}"), + )?; + match mutation { + "missing" => result.repository_body_observation_basis = None, + "swapped" => { + result + .repository_body_observation_basis + .as_mut() + .expect("fixture Modeling basis") + .observation_id = "counterfeit-observation".into(); + } + _ => unreachable!(), + } + let before = std::fs::read(&store)?; + assert!(put_runtime_role_worker_result(&store, &result).is_err()); + assert_eq!(std::fs::read(&store)?, before); + } + Ok(()) + } + + #[test] + fn repo_model_admission_refuses_review_body_substitution_without_writes() -> Result<()> { + let root = tempdir()?; + let (store, result, mut review) = proposal_admission_fixture(root.path(), "body-swap")?; + put_runtime_role_worker_result(&store, &result)?; + review + .repository_body_observation_basis + .as_mut() + .expect("Modeling review basis") + .manifest_root_sha256 = "counterfeit-root".into(); + let before = std::fs::read(&store)?; + assert!(commit_repo_model_admission(&store, &result.result_id, &review).is_err()); + assert_eq!(std::fs::read(&store)?, before); + Ok(()) + } + + #[test] + fn repo_model_admission_preserves_valid_historical_body_basis() -> Result<()> { + let root = tempdir()?; + let (store, result, review) = proposal_admission_fixture(root.path(), "historical-body")?; + put_runtime_role_worker_result(&store, &result)?; + let original = review + .repository_body_observation_basis + .clone() + .expect("Modeling review basis"); + let route = + crate::runtime_repository_body_store_binding(&store)?.expect("runtime Body route"); + let body_store = PathBuf::from(route.body_store_path); + let (binding, _) = + crate::load_repository_body_status(&body_store)?.expect("repository Body status"); + std::fs::write( + Path::new(&binding.git_top_level).join("body-seed.txt"), + b"changed after Modeling launch", + )?; + let add = std::process::Command::new("git") + .args(["add", "body-seed.txt"]) + .current_dir(&binding.git_top_level) + .output()?; + assert!(add.status.success()); + let changed = match crate::observe_repository_body( + Path::new(&binding.git_top_level), + &body_store, + &store, + )? { + crate::ObserveOutcome::Created(value) | crate::ObserveOutcome::Unchanged(value) => { + value + } + }; + assert_ne!(changed.manifest_root_sha256, original.manifest_root_sha256); + + let receipt = commit_repo_model_admission(&store, &result.result_id, &review)?; + assert_eq!(receipt.repository_body_observation_basis, Some(original)); + Ok(()) + } + fn proposal_admission_fixture( root: &Path, suffix: &str, @@ -7920,6 +8231,7 @@ pub(crate) mod tests { evidence_ids.dedup(); let result = EpiphanyRuntimeRoleWorkerResult { schema_version: RUNTIME_ROLE_WORKER_RESULT_SCHEMA_VERSION.into(), + repository_body_observation_basis: runtime_worker_launch_body_basis(&store, &job_id)?, result_id: format!("claim-repair-result-{suffix}"), job_id, role_id: "modeling".into(), @@ -7963,6 +8275,7 @@ pub(crate) mod tests { evidence_ids, reviewed_at: "2026-07-14T09:00:05Z".into(), contract: REPO_MODEL_ADMISSION_CONTRACT.into(), + repository_body_observation_basis: result.repository_body_observation_basis.clone(), }; Ok((store, result, review, repair)) } @@ -8065,6 +8378,9 @@ pub(crate) mod tests { proposal_modeling_request_id: String::new(), claim_repair_request_id: repair.request_id.clone(), frontier_plan_decision_id: String::new(), + repository_body_observation_basis: review + .repository_body_observation_basis + .clone(), }, )?; } @@ -8284,7 +8600,7 @@ pub(crate) mod tests { 7 => result.job_id = "unrelated-modeling-job".into(), _ => unreachable!(), } - if mutate == 6 { + if matches!(mutate, 6 | 7) { let before = std::fs::read(&store)?; assert!(put_runtime_role_worker_result(&store, &result).is_err()); assert_eq!(std::fs::read(&store)?, before); @@ -8532,6 +8848,9 @@ pub(crate) mod tests { proposal_modeling_request_id: "wrong-proposal-request".into(), claim_repair_request_id: String::new(), frontier_plan_decision_id: String::new(), + repository_body_observation_basis: review + .repository_body_observation_basis + .clone(), }; overwrite_test_entry(&store, &review.review_id, &review)?; overwrite_test_entry(&store, &receipt_id, &receipt)?; @@ -9006,6 +9325,7 @@ pub(crate) mod tests { )?; let verification_result = EpiphanyRuntimeRoleWorkerResult { schema_version: RUNTIME_ROLE_WORKER_RESULT_SCHEMA_VERSION.to_string(), + repository_body_observation_basis: None, result_id: format!("verification-result-{suffix}"), job_id: format!("verification-job-{suffix}"), role_id: "verification".to_string(), @@ -9036,6 +9356,7 @@ pub(crate) mod tests { frontier_plan_mind_request_id: None, frontier_plan_mind_decision_msgpack: None, }; + put_test_non_modeling_worker_launch(&store, &verification_result.job_id, "verification")?; put_runtime_role_worker_result(&store, &verification_result)?; let verdict = SoulVerdictReceipt { schema_version: SOUL_VERDICT_RECEIPT_SCHEMA_VERSION.to_string(), @@ -9094,6 +9415,41 @@ pub(crate) mod tests { fixture: &FrontierVerdictFixture, suffix: &str, ) -> Result<(EpiphanyRuntimeRoleWorkerResult, RepoModelAdmissionReview)> { + bind_test_repository_body(&fixture.store, &format!("verdict-workspace-{suffix}"))?; + let state = crate::read_coordinator_state(&fixture.store)? + .ok_or_else(|| anyhow!("verdict fixture has no coordinator state"))?; + let thread_id = { + let mut cache = runtime_spine_cache(&fixture.store)?; + cache.pull_all_backing_stores()?; + cache + .get::(crate::THREAD_STATE_KEY)? + .ok_or_else(|| anyhow!("verdict fixture has no thread state entry"))? + .thread_id + }; + let launch = crate::build_epiphany_role_launch_request( + &thread_id, + crate::EpiphanyRoleResultRoleId::Modeling, + Some(state.revision), + Some(60), + &state, + ) + .map_err(|error| anyhow!(error))?; + let job_id = format!("incorporation-job-{suffix}"); + let plan = crate::plan_coordinator_job_launch( + &state, + &launch, + &fixture.store, + format!("incorporation-launcher-{suffix}"), + job_id.clone(), + )?; + crate::commit_coordinator_job_launch( + &fixture.store, + &thread_id, + &state, + &launch, + &plan, + "2026-07-13T06:00:09Z".into(), + )?; let mut item = fixture .current .frontier @@ -9129,8 +9485,12 @@ pub(crate) mod tests { let bytes = rmp_serde::to_vec_named(&patch)?; let result = EpiphanyRuntimeRoleWorkerResult { schema_version: RUNTIME_ROLE_WORKER_RESULT_SCHEMA_VERSION.to_string(), + repository_body_observation_basis: runtime_worker_launch_body_basis( + &fixture.store, + &job_id, + )?, result_id: format!("incorporation-result-{suffix}"), - job_id: format!("incorporation-job-{suffix}"), + job_id, role_id: "modeling".to_string(), verdict: "checkpoint-ready".to_string(), summary: "Incorporate exact Soul verdict.".to_string(), @@ -9172,6 +9532,7 @@ pub(crate) mod tests { evidence_ids: result.evidence_ids.clone(), reviewed_at: "2026-07-13T06:00:10Z".to_string(), contract: REPO_MODEL_ADMISSION_CONTRACT.to_string(), + repository_body_observation_basis: result.repository_body_observation_basis.clone(), }; Ok((result, review)) } @@ -9467,6 +9828,7 @@ pub(crate) mod tests { let fixture = frontier_verdict_fixture(temp.path(), "request-adjacency", "pass")?; let adjacent = EpiphanyRuntimeRoleWorkerResult { schema_version: RUNTIME_ROLE_WORKER_RESULT_SCHEMA_VERSION.to_string(), + repository_body_observation_basis: None, result_id: "adjacent-verification-result".to_string(), job_id: "adjacent-verification-job".to_string(), role_id: "verification".to_string(), @@ -9497,6 +9859,7 @@ pub(crate) mod tests { frontier_plan_mind_request_id: None, frontier_plan_mind_decision_msgpack: None, }; + put_test_non_modeling_worker_launch(&fixture.store, &adjacent.job_id, "verification")?; put_runtime_role_worker_result(&fixture.store, &adjacent)?; put_soul_verdict_receipt( &fixture.store, @@ -9568,12 +9931,39 @@ pub(crate) mod tests { commit_repo_model_admission(&fixture.store, &result.result_id, &review).is_err() ); assert_eq!(fs::read(&fixture.store)?, before); + complete_runtime_job( + &fixture.store, + RuntimeSpineJobResultOptions { + result_id: format!("terminal-{suffix}"), + job_id: result.job_id.clone(), + completed_at: "2026-07-13T06:00:11Z".into(), + verdict: "rejected".into(), + summary: "Hostile admission fixture rejected.".into(), + next_safe_move: "Launch the next isolated fixture.".into(), + evidence_refs: Vec::new(), + artifact_refs: Vec::new(), + }, + )?; + let mut cache = runtime_spine_cache(&fixture.store)?; + cache.pull_all_backing_stores()?; + let entry = cache + .get::(crate::THREAD_STATE_KEY)? + .ok_or_else(|| anyhow!("hostile fixture thread state disappeared"))?; + let mut state = entry.state()?; + for link in &mut state.runtime_links { + if link.runtime_job_id == result.job_id && link.runtime_result_id.is_none() { + link.runtime_result_id = Some(format!("terminal-{suffix}")); + } + } + cache.put( + crate::THREAD_STATE_KEY, + &crate::EpiphanyThreadStateEntry::from_state(entry.thread_id, &state)?, + )?; Ok(()) } let temp = tempdir()?; - let fixture = frontier_verdict_fixture(temp.path(), "hostile", "pass")?; - + let fixture = frontier_verdict_fixture(temp.path(), "swapped-route", "pass")?; attempt(&fixture, "swapped-route", |patch| { patch.purpose = crate::RepoModelPatchPurpose::IncorporateFrontierVerdict { route_id: "different-route".to_string(), @@ -9586,6 +9976,8 @@ pub(crate) mod tests { ("swapped-verdict-route", "route"), ("swapped-result", "result"), ] { + let case_root = tempdir()?; + let fixture = frontier_verdict_fixture(case_root.path(), suffix, "pass")?; let mut counterfeit = fixture.verdict.clone(); counterfeit.receipt_id = format!("counterfeit-{suffix}"); match alter { @@ -9603,12 +9995,16 @@ pub(crate) mod tests { })?; } + let case_root = tempdir()?; + let fixture = frontier_verdict_fixture(case_root.path(), "extra-op", "pass")?; attempt(&fixture, "extra-op", |patch| { let item = fixture.current.frontier[0].clone(); patch .operations .push(crate::RepoModelPatchOperation::ReviseFrontier { item }); })?; + let case_root = tempdir()?; + let fixture = frontier_verdict_fixture(case_root.path(), "wrong-item", "pass")?; attempt(&fixture, "wrong-item", |patch| { let crate::RepoModelPatchOperation::ReviseFrontier { item } = &mut patch.operations[0] else { @@ -9616,6 +10012,8 @@ pub(crate) mod tests { }; item.id = "other-frontier".to_string(); })?; + let case_root = tempdir()?; + let fixture = frontier_verdict_fixture(case_root.path(), "wrong-status", "pass")?; attempt(&fixture, "wrong-status", |patch| { let crate::RepoModelPatchOperation::ReviseFrontier { item } = &mut patch.operations[0] else { @@ -9625,23 +10023,6 @@ pub(crate) mod tests { item.gap = "still blocked".to_string(); })?; - let (evolution_result, evolution_review) = - incorporation_result_and_review(&fixture, "intervening-result")?; - put_runtime_role_worker_result(&fixture.store, &evolution_result)?; - commit_repo_model_admission( - &fixture.store, - &evolution_result.result_id, - &evolution_review, - )?; - let (stale_result, stale_review) = - incorporation_result_and_review(&fixture, "stale-model")?; - put_runtime_role_worker_result(&fixture.store, &stale_result)?; - let before = fs::read(&fixture.store)?; - assert!( - commit_repo_model_admission(&fixture.store, &stale_result.result_id, &stale_review) - .is_err() - ); - assert_eq!(fs::read(&fixture.store)?, before); Ok(()) } @@ -10714,17 +11095,18 @@ pub(crate) mod tests { objective: "Run heartbeat worker.".to_string(), coordinator_note: "Test launch.".to_string(), job_id: "heartbeat-job-1".to_string(), - role: "modeling".to_string(), - binding_id: "modeling-checkpoint-worker".to_string(), - authority_scope: "modeling".to_string(), + role: crate::EPIPHANY_RESEARCH_OWNER_ROLE.to_string(), + binding_id: "research-worker".to_string(), + authority_scope: "research".to_string(), instruction: "Inspect the checkpoint and return typed role findings.".to_string(), launch_document: EpiphanyWorkerLaunchDocument::Role( crate::EpiphanyRoleWorkerLaunchDocument { thread_id: "thread-1".to_string(), - role_id: "modeling".to_string(), + role_id: "research".to_string(), state_revision: 7, objective: Some("Run heartbeat worker.".to_string()), dynamic_prompt_context: None, + repository_body_observation_basis: None, proposal_modeling_context: None, claim_repair_context: None, frontier_planning_context: None, @@ -10746,7 +11128,7 @@ pub(crate) mod tests { ), output_contract_id: crate::ROLE_WORKER_OUTPUT_CONTRACT_ID.to_string(), organ_launch_contract: crate::default_launch_organ_contract( - "modeling", + "research", "role", crate::ROLE_WORKER_OUTPUT_CONTRACT_ID, ), @@ -10760,7 +11142,7 @@ pub(crate) mod tests { assert_eq!(job.job_id, "heartbeat-job-1"); assert_eq!(job.session_id, "epiphany-main"); - assert_eq!(job.role, "modeling"); + assert_eq!(job.role, crate::EPIPHANY_RESEARCH_OWNER_ROLE); let status = runtime_spine_status(&store)?; assert_eq!(status.sessions, 1); assert_eq!(status.jobs, 1); @@ -10772,8 +11154,8 @@ pub(crate) mod tests { .get::("heartbeat-job-1")? .expect("typed worker launch request should be durable"); assert_eq!(launch_request.job_id, "heartbeat-job-1"); - assert_eq!(launch_request.binding_id, "modeling-checkpoint-worker"); - assert_eq!(launch_request.role, "modeling"); + assert_eq!(launch_request.binding_id, "research-worker"); + assert_eq!(launch_request.role, crate::EPIPHANY_RESEARCH_OWNER_ROLE); assert_eq!( launch_request.output_contract_id, crate::ROLE_WORKER_OUTPUT_CONTRACT_ID @@ -10783,21 +11165,10 @@ pub(crate) mod tests { assert_eq!(launch_request.launch_document()?.thread_id(), "thread-1"); assert_eq!(launch_request.organ_launch_contract.document_kind, "role"); assert!( - launch_request - .organ_launch_contract - .required_receipt_document_types - .contains(&crate::MIND_GATEWAY_REVIEW_TYPE.to_string()) - ); - assert!( - launch_request + !launch_request .organ_launch_contract .receipt_proof_profiles - .iter() - .any(|profile| profile.effect_kind - == crate::EpiphanyReceiptEffectKind::StateAdmission - && profile - .required_before_promotion_document_types - .contains(&crate::MIND_GATEWAY_REVIEW_TYPE.to_string())) + .is_empty() ); Ok(()) } @@ -10822,6 +11193,7 @@ pub(crate) mod tests { state_revision: 7, objective: Some("keep state typed".to_string()), dynamic_prompt_context: None, + repository_body_observation_basis: None, proposal_modeling_context: None, claim_repair_context: None, frontier_planning_context: None, @@ -10910,6 +11282,7 @@ pub(crate) mod tests { state_revision: 7, objective: None, dynamic_prompt_context: None, + repository_body_observation_basis: None, proposal_modeling_context: None, claim_repair_context: None, frontier_planning_context: None, diff --git a/epiphany-core/src/substrate_gate.rs b/epiphany-core/src/substrate_gate.rs index c41b54b7..3479fb91 100644 --- a/epiphany-core/src/substrate_gate.rs +++ b/epiphany-core/src/substrate_gate.rs @@ -249,6 +249,7 @@ mod tests { state_revision: 7, objective: None, dynamic_prompt_context: None, + repository_body_observation_basis: None, proposal_modeling_context: None, claim_repair_context: None, frontier_planning_context: None, diff --git a/epiphany-core/src/surfaces/worker_launch.rs b/epiphany-core/src/surfaces/worker_launch.rs index 628afafa..4f04255d 100644 --- a/epiphany-core/src/surfaces/worker_launch.rs +++ b/epiphany-core/src/surfaces/worker_launch.rs @@ -24,7 +24,7 @@ use crate::EpiphanyReorientFreshnessStatus; use crate::EpiphanyReorientPressureLevel; use crate::EpiphanyReorientReason; -pub const ROLE_WORKER_OUTPUT_CONTRACT_ID: &str = "epiphany.worker.role_result.v2"; +pub const ROLE_WORKER_OUTPUT_CONTRACT_ID: &str = "epiphany.worker.role_result.v3"; pub const REORIENT_WORKER_OUTPUT_CONTRACT_ID: &str = "epiphany.worker.reorient_result.v0"; pub const REPO_FRONTIER_PROPOSAL_MODELING_CONTEXT_SCHEMA_VERSION: &str = "epiphany.worker.repo_frontier_proposal_modeling_context.v0"; @@ -93,6 +93,8 @@ pub struct EpiphanyRoleWorkerLaunchDocument { #[serde(default, skip_serializing_if = "Option::is_none")] pub dynamic_prompt_context: Option, #[serde(default, skip_serializing_if = "Option::is_none")] + pub repository_body_observation_basis: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] pub proposal_modeling_context: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub claim_repair_context: Option, diff --git a/epiphany-openai-runtime/src/bin/epiphany-openai-runtime.rs b/epiphany-openai-runtime/src/bin/epiphany-openai-runtime.rs index a1fdbcfa..4feb9a14 100644 --- a/epiphany-openai-runtime/src/bin/epiphany-openai-runtime.rs +++ b/epiphany-openai-runtime/src/bin/epiphany-openai-runtime.rs @@ -971,6 +971,7 @@ mod tests { state_revision: 1, objective: Some("Verify the worker loop.".to_string()), dynamic_prompt_context: None, + repository_body_observation_basis: None, proposal_modeling_context: None, claim_repair_context: None, frontier_planning_context: None, @@ -1059,6 +1060,7 @@ mod tests { state_revision: 1, objective: Some("Verify runtime error sealing.".to_string()), dynamic_prompt_context: None, + repository_body_observation_basis: None, proposal_modeling_context: None, claim_repair_context: None, frontier_planning_context: None, @@ -1135,6 +1137,7 @@ mod tests { state_revision: 1, objective: Some("Verify the worker loop ceiling.".to_string()), dynamic_prompt_context: None, + repository_body_observation_basis: None, proposal_modeling_context: None, claim_repair_context: None, frontier_planning_context: None, diff --git a/epiphany-openai-runtime/src/lib.rs b/epiphany-openai-runtime/src/lib.rs index 873deafb..28f94e26 100644 --- a/epiphany-openai-runtime/src/lib.rs +++ b/epiphany-openai-runtime/src/lib.rs @@ -1380,6 +1380,7 @@ struct RoleWorkerResultIngress { frontier_plan_candidate: Option, frontier_plan_mind_request_id: Option, frontier_plan_mind_decision: Option, + repository_body_observation_basis: Option, } #[derive(Debug, Clone, Default, serde::Deserialize)] @@ -1564,6 +1565,7 @@ fn role_worker_result_from_ingress( }; EpiphanyRuntimeRoleWorkerResult { schema_version: epiphany_core::RUNTIME_ROLE_WORKER_RESULT_SCHEMA_VERSION.to_string(), + repository_body_observation_basis: result.repository_body_observation_basis.clone(), result_id: result_id.to_string(), job_id: launch_request.job_id.clone(), role_id: clean_optional_string(result.role_id.as_deref()) @@ -1731,6 +1733,30 @@ mod tests { use epiphany_openai_adapter::EpiphanyOpenAiModelReceipt; use tempfile::tempdir; + #[test] + fn modeling_ingress_parses_camel_case_repository_body_basis() -> Result<()> { + let parsed = parse_assistant_json::( + r#"{ + "roleId":"modeling","verdict":"checkpoint-ready","summary":"mapped", + "nextSafeMove":"Mind review","repositoryBodyObservationBasis":{ + "schemaVersion":"epiphany.repository_body.v2","workspaceId":"workspace-1", + "swarmId":"swarm-1","runtimeId":"runtime-1","scope":"git_worktree", + "bodyBindingSha256":"binding-hash","observationId":"workspace-1:1", + "generation":1,"manifestRootSha256":"manifest-root", + "scanStartedAt":"2026-07-15T00:00:00Z", + "scanFinishedAt":"2026-07-15T00:00:01Z" + } + }"#, + )?; + let basis = parsed + .repository_body_observation_basis + .expect("typed Body basis"); + assert_eq!(basis.workspace_id, "workspace-1"); + assert_eq!(basis.generation, 1); + assert_eq!(basis.manifest_root_sha256, "manifest-root"); + Ok(()) + } + #[test] fn verification_ingress_preserves_exact_request_and_route_binding() -> Result<()> { let parsed = parse_assistant_json::( @@ -2072,6 +2098,7 @@ mod tests { "\nlocal Verse: bounded\n" .to_string(), ), + repository_body_observation_basis: None, proposal_modeling_context: None, claim_repair_context: None, frontier_planning_context: None, @@ -2205,6 +2232,7 @@ mod tests { "hands receipts" .to_string(), ), + repository_body_observation_basis: None, proposal_modeling_context: None, claim_repair_context: None, frontier_planning_context: None, diff --git a/notes/epiphany-current-algorithmic-map.md b/notes/epiphany-current-algorithmic-map.md index 6c4ed260..c012bbfb 100644 --- a/notes/epiphany-current-algorithmic-map.md +++ b/notes/epiphany-current-algorithmic-map.md @@ -797,17 +797,27 @@ The bind rite also writes one immutable runtime-side locator and hashes the exact Body binding while repeating runtime, swarm, and workspace identity. Every read reopens the Body store and validates that chain. One runtime cannot silently switch between Body stores; relocation or replacement -requires a future explicit migration receipt. This is routing authority only. It -does not claim that a Modeling launch, result, or admission is grounded yet. +requires a future explicit migration receipt. + +Every coordinator-owned Modeling launch now obtains a typed +`RepositoryBodyObservationBasis` before the worker thinks. The immutable launch +binds runtime/swarm/workspace/scope, Body-binding hash, observation +generation/id/root, and scan interval. Modeling output contract v3 requires the +worker-authored exact echo; result ingress rejects missing or substituted basis. +Non-Modeling launches and results cannot carry it. Mind review v1 and admission +receipt v5 preserve the same basis. Admission validates exact +launch/result/review equality and the referenced immutable historical Body +artifacts before copying it into the CAS receipt. It does not resample current +Body. Direct Mind adoption and legacy migration remain explicitly ungrounded. ## Mind readiness join boundary (2026-07-15) -A truthful whole-repository readiness join does not yet exist. Mind must own a +A truthful whole-repository readiness join does not yet exist. Body-grounded +RepoModel admission now exists; Mind must own a derived `RepositoryReadinessProjection`; Body observation, Modeling, retrieval, semantic projection, schedulers, watchers, jobs, and UI are forbidden writers. Its required inputs are a fresh validated Body observation, the canonical -RepoModel plus its exact Mind admission receipt, a RepoModel grounding receipt -bound to that Body manifest, +RepoModel plus its exact Mind admission receipt carrying its Body basis, the authenticated Modeling semantic projection receipt for that admitted model, and exact workspace-retrieval coverage bound to the same Body manifest and a named inclusion policy. Derivation must retry if any participating head advances. diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 6e9f017c..0062d32b 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -1655,16 +1655,29 @@ commit atomically. Gitlinks are nonrecursive; unrepresentable paths fail closed. Bind now installs one immutable runtime-side Body-store route containing the canonical external locator and exact Body-binding hash. Reads validate runtime, swarm, workspace, path, and Body binding; a runtime cannot substitute a second -Body store. The route is the missing nerve needed by launch/admission, not proof -that any current RepoModel was grounded through it. +Body store. The route is the locator nerve used by the grounded chain below. + +## Modeling thinks from an authenticated Body observation (2026-07-15) + +Coordinator-owned Modeling launch observes the bound repository before worker +thought and seals a typed `RepositoryBodyObservationBasis` into the immutable +launch. Modeling output contract v3 requires an exact worker-authored echo. +Result ingress reloads the launch and refuses missing, swapped, or non-Modeling +basis cargo. Mind admission review v1 and receipt v5 carry the same basis; the +admission CAS validates launch/result/review equality and the referenced +historical Body artifacts before copying it into the receipt. It never samples +current Body as a substitute. A valid historical basis remains admissible after +the repository changes because it proves what Modeling saw, not timeless +freshness. Direct Mind adoption and legacy migration remain explicitly +ungrounded rather than manufacturing retroactive evidence. ## Readiness join remains deliberately impossible (2026-07-15) Modeling audited the next ownership seam after the Body observer landed. Mind is the only coherent owner for a derived repository-readiness projection, but the -inputs required to emit observed-ready-at do not exist yet: RepoModel admission -grounded to the exact current Body manifest and exact workspace-retrieval -coverage for that same manifest. The existing +remaining input required to emit observed-ready-at does not exist yet: exact +workspace-retrieval coverage for that same Body manifest. RepoModel admission +is now grounded to its exact pre-thought Body observation. The existing semantic projector proves exact query eligibility for an admitted RepoModel projection; the legacy workspace retrieval JSON manifest proves only path/size/ mtime/chunk cache agreement. Do not join its `Ready` label, empty dirty paths, @@ -1673,8 +1686,8 @@ readiness. Historical continuity was audited and rejected as another conceptual substitution. The correct join observes Body root R1, validates every artifact, observes R2, and emits only a time-bounded result when R1=R2. Watchers and Hands receipts trigger recomputation; they never replace either observation. Build -order is exact Body-grounded RepoModel admission, typed Body-bound retrieval -coverage, the Mind-owned race-safe join, then deletion of local interpretations. +order is now typed Body-bound retrieval coverage, the Mind-owned race-safe join, +then deletion of local interpretations. The deployment next action is unchanged and permission-bound. Do not reboot without exact live operator approval. With that approval, run the real diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index d8e0d44e..c6c4e298 100644 Binary files a/state/ledgers.msgpack and b/state/ledgers.msgpack differ diff --git a/state/map.yaml b/state/map.yaml index 44b4ae86..1649f1d9 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -1,6 +1,7 @@ experiment: name: EpiphanyAgent repository_body_observer: "Native Rust explicitly binds caller workspace ID to an existing validated runtime/swarm/source identity plus canonical Git root/object format/scope/policy. Bind also installs one immutable runtime-side RuntimeRepositoryBodyStoreBinding naming the canonical external Body-store locator and exact Body-binding hash; every read revalidates runtime/swarm/workspace/path/body identity and refuses a second store. Two equal sanitized temporary-index scans enumerate ignore-aware UTF-8 paths, Git modes, and nonrecursive gitlinks with global excludes disabled; raw regular bytes/lengths and non-followed symlink-target bytes are SHA-256 hashed. The domain-separated ordered raw manifest root, not the clean-filtered auxiliary tree OID, is authoritative Body identity. Every Git subprocess strips ambient repository/worktree/object/ref/index/namespace/replacement/graft/shallow and config-injection authority. Observe cannot mint identity. CultCache MessagePack atomically commits immutable manifest+observation and a manifest-root head by exact CAS. Canonical store-path checks precede writes; corrupt HEAD, sparse checkout, unsafe/unrepresentable paths, racing reads, and repo/runtime substitution fail closed. Only accepted stable observations persist; errors advance no head. Unchanged raw manifest preserves generation; status is read-pure. The observer owns bounded current-state identity, makes no historical continuity claim, and has no Ready field. The runtime route is locator authority only, not proof of model grounding." + modeling_body_grounding: "Every coordinator-owned Modeling launch observes and carries one typed RepositoryBodyObservationBasis before worker thought. The immutable launch binds runtime/swarm/workspace/scope, Body-binding hash, observation generation/id/root, and scan interval. Modeling output contract v3 requires the exact worker-authored echo; ingress reloads the immutable launch and rejects missing/swapped basis, while non-Modeling cargo is forbidden. Mind admission review v1 and receipt v5 preserve that basis; admission validates exact launch/result/review equality plus the immutable historical Body artifacts, then copies it into the CAS receipt. Admission never samples current Body as a substitute. Direct Mind plan adoption and legacy migration remain explicitly ungrounded." repository_readiness_join: "Mind must own one race-bounded derived repository-readiness operation from exact authenticated authorities: freshly observe Body root R1, validate canonical RepoModel plus exact Mind admission and Body-grounding receipt, authenticated semantic projection eligibility for that admitted model, and workspace retrieval coverage bound to R1 and a named scope policy, then freshly observe R2 and require R2=R1. Its output is observed-ready-at with a truth interval ending at the second scan, not timeless Ready; later reads revalidate. A→B→A is harmless for content-addressed artifacts. Watcher/journal continuity and Hands receipts are invalidation triggers only. Legacy retrieval Ready/empty dirty paths, timestamps, watcher silence, Git OIDs, Qdrant existence, counts, and unrelated generations are forbidden substitutes." status: active phase: phase_6_reflection_boundary