diff --git a/epiphany-core/src/coordinator_results.rs b/epiphany-core/src/coordinator_results.rs index 44f89f96..b377b484 100644 --- a/epiphany-core/src/coordinator_results.rs +++ b/epiphany-core/src/coordinator_results.rs @@ -42,7 +42,7 @@ pub fn read_runtime_reorient_result( ); } }; - let status = reorient_result_status(&snapshot); + let status = reorient_result_status(&snapshot.job.status); let finding = match status { EpiphanyCrrcResultStatus::Completed => { match runtime_reorient_worker_result(runtime_store_path, job_id) { @@ -116,13 +116,10 @@ fn interpret_reorient_lifecycle_failure( } } -fn reorient_result_status(snapshot: &EpiphanyRuntimeJobSnapshot) -> EpiphanyCrrcResultStatus { - match snapshot.job.status { +fn reorient_result_status(status: &EpiphanyRuntimeJobStatus) -> EpiphanyCrrcResultStatus { + match status { EpiphanyRuntimeJobStatus::Queued => EpiphanyCrrcResultStatus::Pending, - EpiphanyRuntimeJobStatus::Completed if snapshot.result.is_some() => { - EpiphanyCrrcResultStatus::Completed - } - EpiphanyRuntimeJobStatus::Completed => EpiphanyCrrcResultStatus::Pending, + EpiphanyRuntimeJobStatus::Completed => EpiphanyCrrcResultStatus::Completed, EpiphanyRuntimeJobStatus::Failed => EpiphanyCrrcResultStatus::Failed, } } diff --git a/epiphany-core/src/reasoning_context.rs b/epiphany-core/src/reasoning_context.rs index 98ae61bf..8179bd98 100644 --- a/epiphany-core/src/reasoning_context.rs +++ b/epiphany-core/src/reasoning_context.rs @@ -2658,7 +2658,6 @@ mod tests { decision: Some(crate::EpiphanyArchivedRuntimeWorkerDecision { decision_context_id: context.context_id.clone(), role_result: None, - job_results: vec![terminal_result], }), }; archive_cache.put(&archived.job_id, &archived)?; diff --git a/epiphany-core/src/reorientation_work.rs b/epiphany-core/src/reorientation_work.rs index 7866665d..f4016b1f 100644 --- a/epiphany-core/src/reorientation_work.rs +++ b/epiphany-core/src/reorientation_work.rs @@ -1023,6 +1023,13 @@ mod tests { decision_context_id: Some(context.context_id.clone()), }, )?; + assert!( + crate::runtime_job_snapshot(&store, &job_id)? + .expect("reorientation job snapshot") + .result + .is_none(), + "typed reorientation decisions must not persist a generic result mirror" + ); cache.pull_all_backing_stores()?; cache.put( diff --git a/epiphany-core/src/runtime_spine.rs b/epiphany-core/src/runtime_spine.rs index b662bf1c..a627f467 100644 --- a/epiphany-core/src/runtime_spine.rs +++ b/epiphany-core/src/runtime_spine.rs @@ -55,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.v43"; +pub const RUNTIME_SPINE_SCHEMA_VERSION: &str = "epiphany.runtime_spine.v44"; pub const EPIPHANY_RUNTIME_ROOT_SESSION_ID: &str = "epiphany-main"; #[derive(Clone, Debug, PartialEq, DatabaseEntry)] #[cultcache(type = "epiphany.runtime.identity", schema = "EpiphanyRuntimeIdentity")] @@ -234,7 +234,7 @@ pub struct EpiphanyRuntimeWorkerProcessClaim { #[derive(Clone, Debug, PartialEq, DatabaseEntry)] #[cultcache( - type = "epiphany.runtime.archived_worker_attempt.v2", + type = "epiphany.runtime.archived_worker_attempt.v3", schema = "EpiphanyArchivedRuntimeWorkerAttempt" )] pub struct EpiphanyArchivedRuntimeWorkerAttempt { @@ -256,7 +256,6 @@ pub struct EpiphanyArchivedRuntimeWorkerAttempt { pub struct EpiphanyArchivedRuntimeWorkerDecision { pub decision_context_id: String, pub role_result: Option, - pub job_results: Vec, } impl EpiphanyArchivedRuntimeWorkerAttempt { @@ -286,17 +285,6 @@ impl EpiphanyArchivedRuntimeWorkerAttempt { &decision.decision_context_id, "archived worker decision context id", )?; - if decision.job_results.is_empty() - || decision.job_results.iter().any(|result| { - result.job_id != self.job_id - || result.decision_context_id.as_deref() - != Some(decision.decision_context_id.as_str()) - }) - { - return Err(anyhow!( - "archived worker decision lost its exact generic result family" - )); - } match &decision.role_result { Some(result) if fulfilled @@ -8210,12 +8198,9 @@ fn archive_runtime_worker_attempt( if let Some(context_id) = decision_context_id.as_deref() { require_worker_decision_context(&cache, context_id, job_id)?; } - let mut archived_job_results = worker_job_results.clone(); - archived_job_results.sort_by(|left, right| left.result_id.cmp(&right.result_id)); let decision = decision_context_id.map(|context_id| EpiphanyArchivedRuntimeWorkerDecision { decision_context_id: context_id, role_result: role_result.clone(), - job_results: archived_job_results, }); let mut deletions = snapshot .iter() @@ -8754,11 +8739,41 @@ pub fn complete_runtime_job( next_safe_move: options.next_safe_move, decision_context_id: options.decision_context_id, }; + let role = cache.get::(&result.job_id)?; + let reorient = cache.get::(&result.job_id)?; + let (structured_result_id, structured_result_envelope) = match (&role, &reorient) { + (Some(_), Some(_)) => { + return Err(anyhow!( + "runtime worker job has both role and reorientation terminal outcomes" + )); + } + (Some(result), None) => ( + Some(result.result_id.clone()), + Some( + cache + .get_envelope::(&result.job_id)? + .ok_or_else(|| anyhow!("runtime worker completion lost its role result"))?, + ), + ), + (None, Some(result)) => ( + Some(result.result_id.clone()), + Some( + cache + .get_envelope::(&result.job_id)? + .ok_or_else(|| anyhow!("runtime worker completion lost its reorient result"))?, + ), + ), + (None, None) => (None, None), + }; let mut expected = vec![job_envelope]; - let mut writes = vec![ - cache.prepare_entry(&job.job_id, &job)?.0, - cache.prepare_entry(&result.result_id, &result)?.0, - ]; + let mut writes = vec![cache.prepare_entry(&job.job_id, &job)?.0]; + if let Some(envelope) = structured_result_envelope { + expected.push(envelope.clone()); + writes.push(envelope); + } + if structured_result_id.is_none() { + writes.push(cache.prepare_entry(&result.result_id, &result)?.0); + } let claim_id = worker_process_claim_id(&result.job_id); if let Some(claim) = cache.get::(&claim_id)? { match crate::WorkerProcessStatus::parse(&claim.status)? { @@ -8772,17 +8787,7 @@ pub fn complete_runtime_job( .cloned() .ok_or_else(|| anyhow!("runtime worker completion lost its claim envelope"))?; let mut terminal = claim; - let role = cache.get::(&result.job_id)?; - let reorient = cache.get::(&result.job_id)?; - if role.is_some() && reorient.is_some() { - return Err(anyhow!( - "runtime worker job has both role and reorientation terminal outcomes" - )); - } - if let Some(terminal_result_id) = role - .map(|result| result.result_id) - .or_else(|| reorient.map(|result| result.result_id)) - { + if let Some(terminal_result_id) = structured_result_id { terminal.status = crate::WorkerProcessStatus::TerminalResult.as_str().into(); terminal.terminal_authority_id = Some(terminal_result_id); } else { diff --git a/epiphany-openai-runtime/src/bin/epiphany-openai-runtime.rs b/epiphany-openai-runtime/src/bin/epiphany-openai-runtime.rs index 2330e964..c7dd6819 100644 --- a/epiphany-openai-runtime/src/bin/epiphany-openai-runtime.rs +++ b/epiphany-openai-runtime/src/bin/epiphany-openai-runtime.rs @@ -24,8 +24,6 @@ use epiphany_openai_adapter::{ use epiphany_openai_runtime::DEFAULT_CODEX_CONNECTOR_ENDPOINT; use epiphany_openai_runtime::DEFAULT_PROVIDER_REQUEST_TIMEOUT; use epiphany_openai_runtime::EpiphanyOpenAiRuntimeOptions; -#[cfg(test)] -use epiphany_openai_runtime::OPENAI_RUNTIME_ROLE; use epiphany_openai_runtime::append_requested_public_source_receipts; use epiphany_openai_runtime::assistant_text_from_model_events; use epiphany_openai_runtime::build_tool_followup_model_request; diff --git a/epiphany-openai-runtime/src/lib.rs b/epiphany-openai-runtime/src/lib.rs index 026bdccc..fea970ec 100644 --- a/epiphany-openai-runtime/src/lib.rs +++ b/epiphany-openai-runtime/src/lib.rs @@ -3262,7 +3262,8 @@ mod tests { runtime_job_snapshot(&store, &worker_job_id)? .expect("snapshot") .result - .is_some() + .is_none(), + "structured worker decisions must not persist a generic result mirror" ); Ok(()) }