From 83611f9b711af70ad2a4447aa4cd5c7eef64b7c9 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Mon, 24 Aug 2026 11:06:25 +0200 Subject: [PATCH] Collapse Eyes acceptance into Mind commits --- epiphany-core/src/current_work.rs | 48 +++------ epiphany-core/src/eyes_gateway.rs | 163 ----------------------------- epiphany-core/src/lib.rs | 6 -- epiphany-core/src/runtime_spine.rs | 162 +++++++++++++--------------- 4 files changed, 87 insertions(+), 292 deletions(-) delete mode 100644 epiphany-core/src/eyes_gateway.rs diff --git a/epiphany-core/src/current_work.rs b/epiphany-core/src/current_work.rs index 0bcae08a..341e75fb 100644 --- a/epiphany-core/src/current_work.rs +++ b/epiphany-core/src/current_work.rs @@ -1731,21 +1731,24 @@ pub fn accept_frontier_research_result( )); } if let Some(receipt) = receipts.pop() { + receipt.validate()?; let request_id = result .repo_frontier_research_request_id .as_deref() .ok_or_else(|| anyhow!("frontier Research replay lost its request identity"))?; - let packet_id = format!("eyes-packet-{request_id}"); - let packet = cache - .get::(&packet_id)? - .ok_or_else(|| anyhow!("frontier Research replay lost its evidence packet"))?; - if packet.research_request_id != request_id - || packet.decision_context_id != result.decision_context_id - || !receipt - .writes - .iter() - .any(|write| write.document_type == crate::EpiphanyMindEvidenceDocument::TYPE) - { + if !receipt.strong_reads.iter().any(|read| { + read.document_type == crate::RepoFrontierResearchRequest::TYPE + && read.document_key == request_id + }) || !receipt.strong_reads.iter().any(|read| { + read.document_type == crate::EpiphanyRuntimeRoleWorkerResult::TYPE + && read.document_key == job_id + }) || !receipt.writes.iter().any(|write| { + matches!( + write.document_type.as_str(), + crate::EpiphanyMindEvidenceDocument::TYPE + | crate::EpiphanyMindObservationDocument::TYPE + ) + }) { return Err(anyhow!( "frontier Research replay does not preserve its exact accepted decision" )); @@ -1812,20 +1815,6 @@ pub fn accept_frontier_research_result( "frontier Research result did not expose every proposed evidence identity" )); } - let finding = crate::interpret_runtime_role_worker_result( - crate::EpiphanyRoleResultRoleId::Research, - &result, - ); - let packet_id = format!("eyes-packet-{}", request.request_id); - let packet = crate::eyes_evidence_packet_from_research_finding( - packet_id.clone(), - request.request_id.clone(), - result.decision_context_id.clone(), - &finding, - &decision, - &lookups, - accepted_at.to_string(), - ); let mut writes = Vec::new(); for evidence in &decision.evidence { writes.push(crate::mind_documents::prepare_mind_document( @@ -1889,14 +1878,12 @@ pub fn accept_frontier_research_result( } strong_reads.push(envelope.clone()); } - let packet_envelope = cache.prepare_entry(&packet_id, &packet)?.0; - match crate::reasoning_context::commit_mind_mutation_with_derived_companions( + match crate::reasoning_context::commit_mind_mutation( store_path, &result.decision_context_id, "Eyes.frontier_research", strong_reads, writes, - vec![packet_envelope], accepted_at, )? { crate::EpiphanyMindCommitOutcome::Committed(receipt) => Ok(receipt), @@ -6062,11 +6049,6 @@ mod tests { .get::(&observation.id)? .is_some() ); - let packet = admitted_research_cache - .get::(&format!("eyes-packet-{research_request_id}"))? - .expect("request-bound Eyes packet"); - assert_eq!(packet.research_request_id, research_request_id); - assert_eq!(packet.decision_context_id, research_context.context_id); let after_research = project_current_work(&store)?; assert!(after_research.research.continuation_action().is_none()); assert!(after_research.body_modeling.is_none()); diff --git a/epiphany-core/src/eyes_gateway.rs b/epiphany-core/src/eyes_gateway.rs deleted file mode 100644 index f6c6ceef..00000000 --- a/epiphany-core/src/eyes_gateway.rs +++ /dev/null @@ -1,163 +0,0 @@ -use crate::EpiphanyResearchDecision; -use crate::EpiphanyRoleFindingInterpretation; -use cultcache_rs::DatabaseEntry; - -pub const EYES_SOURCE_LOOKUP_RECEIPT_SCHEMA_VERSION: &str = - "epiphany.eyes.source_lookup_receipt.v0"; -pub const EYES_EVIDENCE_PACKET_SCHEMA_VERSION: &str = "epiphany.eyes.evidence_packet.v2"; - -#[derive(Debug, Clone, PartialEq, Eq, DatabaseEntry)] -#[cultcache( - type = "epiphany.eyes.source_lookup_receipt", - schema = "EyesSourceLookupReceipt" -)] -pub struct EyesSourceLookupReceipt { - #[cultcache(key = 0)] - pub schema_version: String, - #[cultcache(key = 1)] - pub receipt_id: String, - #[cultcache(key = 2)] - pub source_job_id: String, - #[cultcache(key = 3)] - pub substrate_grant_receipt_id: String, - #[cultcache(key = 4)] - pub tool_intent_id: String, - #[cultcache(key = 5)] - pub tool_receipt_id: String, - #[cultcache(key = 6)] - pub provider: String, - #[cultcache(key = 7)] - pub repository: String, - #[cultcache(key = 8)] - pub revision: String, - #[cultcache(key = 9)] - pub path: String, - #[cultcache(key = 10)] - pub source_ref: String, - #[cultcache(key = 11)] - pub content_sha256: String, - #[cultcache(key = 12)] - pub byte_count: u64, - #[cultcache(key = 13)] - pub observed_at: String, - #[cultcache(key = 14)] - pub contract: String, -} - -#[derive(Debug, Clone, PartialEq, Eq, DatabaseEntry)] -#[cultcache(type = "epiphany.eyes.evidence_packet", schema = "EyesEvidencePacket")] -pub struct EyesEvidencePacket { - #[cultcache(key = 0)] - pub schema_version: String, - #[cultcache(key = 1)] - pub packet_id: String, - #[cultcache(key = 2)] - pub source_result_id: String, - #[cultcache(key = 3)] - pub source_job_id: String, - #[cultcache(key = 4)] - pub evidence_ids: Vec, - #[cultcache(key = 5)] - pub observation_ids: Vec, - #[cultcache(key = 6)] - pub source_refs: Vec, - #[cultcache(key = 7)] - pub summary: String, - #[cultcache(key = 8)] - pub uncertainty: String, - #[cultcache(key = 9)] - pub emitted_at: String, - #[cultcache(key = 10)] - pub contract: String, - #[cultcache(key = 11, default)] - pub source_lookup_receipt_ids: Vec, - #[cultcache(key = 12)] - pub research_request_id: String, - #[cultcache(key = 13)] - pub decision_context_id: String, -} - -pub fn eyes_evidence_packet_from_research_finding( - packet_id: String, - research_request_id: String, - decision_context_id: String, - finding: &EpiphanyRoleFindingInterpretation, - decision: &EpiphanyResearchDecision, - source_lookups: &[EyesSourceLookupReceipt], - emitted_at: String, -) -> EyesEvidencePacket { - let evidence_ids = decision - .evidence - .iter() - .filter_map(|evidence| non_empty_string(&evidence.id)) - .collect::>(); - let observation_ids = decision - .observations - .iter() - .filter_map(|observation| non_empty_string(&observation.id)) - .collect::>(); - let mut source_refs = Vec::new(); - for evidence in &decision.evidence { - for code_ref in &evidence.code_refs { - let mut rendered = code_ref.path.display().to_string(); - if let Some(start_line) = code_ref.start_line { - rendered.push(':'); - rendered.push_str(&start_line.to_string()); - } - if let Some(end_line) = code_ref.end_line - && Some(end_line) != code_ref.start_line - { - rendered.push('-'); - rendered.push_str(&end_line.to_string()); - } - if let Some(symbol) = code_ref.symbol.as_deref().filter(|value| !value.is_empty()) { - rendered.push('#'); - rendered.push_str(symbol); - } - push_unique(&mut source_refs, rendered); - } - } - for lookup in source_lookups { - push_unique(&mut source_refs, lookup.source_ref.clone()); - } - EyesEvidencePacket { - schema_version: EYES_EVIDENCE_PACKET_SCHEMA_VERSION.to_string(), - packet_id, - source_result_id: finding.runtime_result_id.clone().unwrap_or_default(), - source_job_id: finding.runtime_job_id.clone().unwrap_or_default(), - evidence_ids, - observation_ids, - source_refs, - summary: finding.summary.clone().unwrap_or_default(), - uncertainty: if finding.evidence_gaps.is_empty() && finding.risks.is_empty() { - "no declared research gaps or risks".to_string() - } else { - finding - .evidence_gaps - .iter() - .chain(finding.risks.iter()) - .cloned() - .collect::>() - .join("; ") - }, - emitted_at, - contract: "Eyes packet emitted from a reviewed Research lane finding; it makes the source-gathering evidence claim citable before Mind admission.".to_string(), - source_lookup_receipt_ids: source_lookups - .iter() - .map(|lookup| lookup.receipt_id.clone()) - .collect(), - research_request_id, - decision_context_id, - } -} - -fn non_empty_string(value: &str) -> Option { - let value = value.trim(); - (!value.is_empty()).then(|| value.to_string()) -} - -fn push_unique(out: &mut Vec, value: String) { - if !out.contains(&value) { - out.push(value); - } -} diff --git a/epiphany-core/src/lib.rs b/epiphany-core/src/lib.rs index 7c61a29e..bcefb78f 100644 --- a/epiphany-core/src/lib.rs +++ b/epiphany-core/src/lib.rs @@ -6,7 +6,6 @@ mod coordinator_results; pub mod coordinator_status; mod cultmesh_integration; mod current_work; -mod eyes_gateway; mod hands_gateway; mod idunn_provider_health; mod idunn_runtime_health; @@ -105,11 +104,6 @@ pub use epiphany_state_model::EpiphanyMemoryDomain; pub use epiphany_state_model::EpiphanyMemoryEdge; pub use epiphany_state_model::EpiphanyMemoryLifecycle; pub use epiphany_state_model::EpiphanyMemoryNode; -pub use eyes_gateway::EYES_EVIDENCE_PACKET_SCHEMA_VERSION; -pub use eyes_gateway::EYES_SOURCE_LOOKUP_RECEIPT_SCHEMA_VERSION; -pub use eyes_gateway::EyesEvidencePacket; -pub use eyes_gateway::EyesSourceLookupReceipt; -pub use eyes_gateway::eyes_evidence_packet_from_research_finding; pub use hands_gateway::*; pub use idunn_provider_health::{ EPIPHANY_IDUNN_PROVIDER_HEALTH_ADMISSION_SCHEMA, EPIPHANY_IDUNN_PROVIDER_HEALTH_ADMISSION_TYPE, diff --git a/epiphany-core/src/runtime_spine.rs b/epiphany-core/src/runtime_spine.rs index d489ae51..b3c55eed 100644 --- a/epiphany-core/src/runtime_spine.rs +++ b/epiphany-core/src/runtime_spine.rs @@ -5,8 +5,6 @@ use crate::agent_launch::{ EPIPHANY_MIND_OWNER_ROLE, EPIPHANY_MIND_ROLE_BINDING_ID, EPIPHANY_MODELING_OWNER_ROLE, EPIPHANY_MODELING_ROLE_BINDING_ID, }; -use crate::eyes_gateway::EyesEvidencePacket; -use crate::eyes_gateway::EyesSourceLookupReceipt; use crate::hands_gateway::*; use crate::repo_model_gateway::{ RUNTIME_REPOSITORY_DOMAIN_BINDING_KEY, RepoFrontierHandsAuthority, RepoFrontierModelingRequest, @@ -57,7 +55,7 @@ pub const COORDINATOR_RUN_RECEIPT_TYPE: &str = "epiphany.coordinator_run_receipt pub const RUNTIME_IDENTITY_KEY: &str = "self"; pub const RUNTIME_SWARM_BINDING_KEY: &str = "runtime-swarm-binding"; pub const RUNTIME_SWARM_BINDING_SCHEMA_VERSION: &str = "epiphany.runtime.swarm_binding.v1"; -pub const RUNTIME_SPINE_SCHEMA_VERSION: &str = "epiphany.runtime_spine.v34"; +pub const RUNTIME_SPINE_SCHEMA_VERSION: &str = "epiphany.runtime_spine.v35"; pub const EPIPHANY_RUNTIME_ROOT_SESSION_ID: &str = "epiphany-main"; #[derive(Clone, Debug, PartialEq, DatabaseEntry)] #[cultcache(type = "epiphany.runtime.identity", schema = "EpiphanyRuntimeIdentity")] @@ -781,8 +779,6 @@ fn runtime_spine_schema_cache() -> 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::()?; @@ -2986,10 +2982,16 @@ pub(crate) fn frontier_verification_request_for_launch( Ok(Some(request)) } +#[derive(Clone, Debug, PartialEq, Eq)] +pub(crate) struct AuthenticatedPublicSourceLookup { + pub receipt_id: String, + pub source_ref: String, +} + pub(crate) fn runtime_authenticated_public_source_lookups_for_worker( store_path: impl AsRef, worker_job_id: &str, -) -> Result> { +) -> Result> { validate_non_empty(worker_job_id, "public source worker job id")?; let mut cache = runtime_spine_cache(store_path)?; cache.pull_all_backing_stores()?; @@ -3000,7 +3002,7 @@ pub(crate) fn runtime_authenticated_public_source_lookups_for_worker( fn authenticated_public_source_lookup_receipts_for_worker( cache: &CultCache, worker_job_id: &str, -) -> Result> { +) -> Result> { validate_non_empty(worker_job_id, "public source worker job id")?; require_identity(cache)?; let launch = cache @@ -3011,7 +3013,6 @@ fn authenticated_public_source_lookup_receipts_for_worker( { return Err(anyhow!("public source evidence is Eyes-owned")); } - let grant_id = format!("substrate-grant-{worker_job_id}"); let model_request_ids = cache .get_all::()? .into_iter() @@ -3076,22 +3077,9 @@ fn authenticated_public_source_lookup_receipts_for_worker( { return Err(anyhow!("public source result provenance is substituted")); } - lookups.push(EyesSourceLookupReceipt { - schema_version: crate::EYES_SOURCE_LOOKUP_RECEIPT_SCHEMA_VERSION.to_string(), + lookups.push(AuthenticatedPublicSourceLookup { receipt_id: lookup_receipt_id, - source_job_id: worker_job_id.to_string(), - substrate_grant_receipt_id: grant_id.clone(), - tool_intent_id: intent.intent_id, - tool_receipt_id: receipt.receipt_id, - provider: "github".to_string(), - repository, - revision: source.revision().to_string(), - path: source.path().to_string(), source_ref, - content_sha256, - byte_count, - observed_at: receipt.completed_at, - contract: "Eyes admitted one bounded immutable public source only after authenticating its worker, causal request or model execution, tool, grant, provider identity, and content digest.".to_string(), }); } lookups.sort_by(|left, right| left.receipt_id.cmp(&right.receipt_id)); @@ -3105,7 +3093,7 @@ fn authenticated_public_source_lookup_receipts_for_worker( pub(crate) fn authenticated_requested_public_source_lookups_for_worker( cache: &CultCache, worker_job_id: &str, -) -> Result> { +) -> Result> { validate_non_empty(worker_job_id, "frontier public source worker job id")?; let launch = cache .get::(worker_job_id)? @@ -6326,8 +6314,7 @@ pub(crate) fn select_and_commit_repo_frontier_research_request( let (view, basis) = current_keyed_repo_model(&cache)?; let model = view.memory_context_projection(); let launches = cache.get_all::()?; - let packets = cache.get_all::()?; - let item = match next_repo_frontier_research_work(&cache, &model, &launches, &packets)? { + let item = match next_repo_frontier_research_work(&cache, &model, &launches)? { Some(NextRepoFrontierResearchWork::Existing(request)) => return Ok(request), Some(NextRepoFrontierResearchWork::Unrequested(item)) => item, None => { @@ -6467,7 +6454,7 @@ impl RepoFrontierResearchLifecycle { } /// Projects the next exact actionable Eyes frontier through request, worker, -/// review, and accepted-packet lifecycle. This is the launch-currency owner: +/// review, and accepted Mind-commit lifecycle. This is the launch-currency owner: /// an uncovered frontier is not launchable while its current attempt is still /// running or awaiting review. pub(crate) fn runtime_repo_frontier_research_lifecycle( @@ -6478,14 +6465,13 @@ pub(crate) fn runtime_repo_frontier_research_lifecycle( cache.pull_all_backing_stores()?; require_identity(&cache)?; let launches = cache.get_all::()?; - let packets = cache.get_all::()?; let jobs = cache.get_all::()?; let job_results = cache.get_all::()?; let role_results = cache.get_all::()?; let (view, _basis) = current_keyed_repo_model(&cache)?; let model = view.memory_context_projection(); - let work = next_repo_frontier_research_work(&cache, &model, &launches, &packets)?; + let work = next_repo_frontier_research_work(&cache, &model, &launches)?; let request = match work { Some(NextRepoFrontierResearchWork::Unrequested(item)) => { return Ok(RepoFrontierResearchLifecycle { @@ -6593,14 +6579,13 @@ fn next_repo_frontier_research_work( cache: &CultCache, model: &crate::EpiphanyMemoryGraphSnapshot, launches: &[EpiphanyRuntimeWorkerLaunchRequest], - packets: &[EyesEvidencePacket], ) -> Result> { let existing_actionable = actionable_repo_frontier_research_requests(cache)?; let mut existing_uncovered = existing_actionable .iter() .cloned() .filter_map(|request| { - match repo_frontier_research_request_is_covered(cache, &request, launches, packets) { + match repo_frontier_research_request_is_covered(cache, &request, launches) { Ok(false) => Some(Ok(request)), Ok(true) => None, Err(error) => Some(Err(error)), @@ -6632,7 +6617,6 @@ fn repo_frontier_research_request_is_covered( cache: &CultCache, request: &RepoFrontierResearchRequest, launches: &[EpiphanyRuntimeWorkerLaunchRequest], - packets: &[EyesEvidencePacket], ) -> Result { let mut matching_jobs = BTreeSet::new(); for launch in launches { @@ -6648,32 +6632,29 @@ fn repo_frontier_research_request_is_covered( } matching_jobs.insert(launch.job_id.as_str()); } - for packet in packets - .iter() - .filter(|packet| packet.research_request_id == request.request_id) - { - let result = cache.get::(&packet.source_job_id)?; - let archived = cache.get::(&packet.source_job_id)?; - let exact_live = result.as_ref().is_some_and(|result| { - matching_jobs.contains(result.job_id.as_str()) - && result.result_id == packet.source_result_id - && result.decision_context_id == packet.decision_context_id - && result.repo_frontier_research_request_id.as_deref() - == Some(request.request_id.as_str()) - }); - let exact_archived = archived.as_ref().is_some_and(|attempt| { - attempt.request_kind == "frontier-research" - && attempt.request_id == request.request_id - && attempt.fulfilled_result_id() == Some(packet.source_result_id.as_str()) - && attempt.decision_context_id() == Some(packet.decision_context_id.as_str()) - && attempt.decision.as_ref().is_some_and(|decision| { - decision.role_result.as_ref().is_some_and(|result| { - result.repo_frontier_research_request_id.as_deref() - == Some(request.request_id.as_str()) - }) - }) - }); - if exact_live || exact_archived { + for job_id in matching_jobs { + if let Some(result) = cache.get::(job_id)? + && result.repo_frontier_research_request_id.as_deref() + == Some(request.request_id.as_str()) + && result.role_id.eq_ignore_ascii_case("research") + && result.item_error.is_none() + && worker_result_has_keyed_mind_commit(cache, &result)? + { + return Ok(true); + } + if let Some(attempt) = cache.get::(job_id)? + && attempt.request_kind == "frontier-research" + && attempt.request_id == request.request_id + && let Some(decision) = attempt.decision.as_ref() + && let Some(result) = decision.role_result.as_ref() + && result.repo_frontier_research_request_id.as_deref() + == Some(request.request_id.as_str()) + && result.role_id.eq_ignore_ascii_case("research") + && result.item_error.is_none() + && attempt.fulfilled_result_id() == Some(result.result_id.as_str()) + && attempt.decision_context_id() == Some(result.decision_context_id.as_str()) + && worker_result_has_keyed_mind_commit(cache, result)? + { return Ok(true); } } @@ -7492,39 +7473,40 @@ fn worker_result_has_keyed_mind_commit( result: &EpiphanyRuntimeRoleWorkerResult, ) -> Result { require_worker_decision_context(cache, &result.decision_context_id, &result.job_id)?; - Ok(cache - .get_all::()? - .into_iter() - .any(|receipt| { - matches!( - receipt.authority, - crate::EpiphanyMindCommitAuthority::ModelDecisionContext { - ref decision_context_id - } if decision_context_id == &result.decision_context_id - ) && if result.role_id.eq_ignore_ascii_case("modeling") { - receipt.invariant_owner.starts_with("Modeling.") - && receipt - .writes - .iter() - .any(|write| write.document_type.starts_with("epiphany.mind.repo_model.")) - } else if result.role_id.eq_ignore_ascii_case("research") { - receipt.invariant_owner == "Eyes.frontier_research" - && receipt.writes.iter().any(|write| { - matches!( - write.document_type.as_str(), - crate::EpiphanyMindEvidenceDocument::TYPE - | crate::EpiphanyMindObservationDocument::TYPE - ) - }) - } else if result.role_id.eq_ignore_ascii_case("verification") { - receipt.invariant_owner == "Soul.verification" - && receipt.writes.iter().any(|write| { - write.document_type == crate::EpiphanyMindVerificationAuditDocument::TYPE - }) - } else { - false - } - })) + for receipt in cache.get_all::()? { + receipt.validate()?; + if matches!( + receipt.authority, + crate::EpiphanyMindCommitAuthority::ModelDecisionContext { + ref decision_context_id + } if decision_context_id == &result.decision_context_id + ) && if result.role_id.eq_ignore_ascii_case("modeling") { + receipt.invariant_owner.starts_with("Modeling.") + && receipt + .writes + .iter() + .any(|write| write.document_type.starts_with("epiphany.mind.repo_model.")) + } else if result.role_id.eq_ignore_ascii_case("research") { + receipt.invariant_owner == "Eyes.frontier_research" + && receipt.writes.iter().any(|write| { + matches!( + write.document_type.as_str(), + crate::EpiphanyMindEvidenceDocument::TYPE + | crate::EpiphanyMindObservationDocument::TYPE + ) + }) + } else if result.role_id.eq_ignore_ascii_case("verification") { + receipt.invariant_owner == "Soul.verification" + && receipt.writes.iter().any(|write| { + write.document_type == crate::EpiphanyMindVerificationAuditDocument::TYPE + }) + } else { + false + } { + return Ok(true); + } + } + Ok(false) } pub(crate) fn validate_repo_frontier_verification_request_intrinsic(