Delete generic runtime job results
This commit is contained in:
parent
7e5ea3e733
commit
2c3335dcaf
12 changed files with 565 additions and 926 deletions
|
|
@ -1636,9 +1636,9 @@ fn accept_reorient(runtime_store: &Path) -> Result<Value> {
|
|||
.attempt
|
||||
.job_id
|
||||
.ok_or_else(|| anyhow!("reorientation review lost its runtime job"))?;
|
||||
let snapshot = epiphany_core::runtime_job_snapshot(runtime_store, &job_id)?
|
||||
let job = epiphany_core::runtime_job(runtime_store, &job_id)?
|
||||
.ok_or_else(|| anyhow!("reorientation review lost its runtime job"))?;
|
||||
let accepted = match snapshot.job.status {
|
||||
let accepted = match job.status {
|
||||
epiphany_core::EpiphanyRuntimeJobStatus::Completed => {
|
||||
epiphany_core::accept_reorientation_result(runtime_store, &job_id, &now())?
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ pub struct EpiphanyCoordinatorReorientResultSnapshot {
|
|||
pub finding: Option<EpiphanyReorientFindingInterpretation>,
|
||||
pub note: String,
|
||||
}
|
||||
|
||||
pub fn read_runtime_reorient_result(
|
||||
runtime_store_path: Option<&Path>,
|
||||
job_id: &str,
|
||||
|
|
@ -21,8 +20,8 @@ pub fn read_runtime_reorient_result(
|
|||
),
|
||||
);
|
||||
};
|
||||
let snapshot = match runtime_job_snapshot(runtime_store_path, job_id) {
|
||||
Ok(Some(snapshot)) => snapshot,
|
||||
let job = match runtime_job(runtime_store_path, job_id) {
|
||||
Ok(Some(job)) => job,
|
||||
Ok(None) => {
|
||||
return reorient_snapshot(
|
||||
EpiphanyCrrcResultStatus::Pending,
|
||||
|
|
@ -42,7 +41,7 @@ pub fn read_runtime_reorient_result(
|
|||
);
|
||||
}
|
||||
};
|
||||
let status = reorient_result_status(&snapshot.job.status);
|
||||
let status = reorient_result_status(&job.status);
|
||||
let finding = match status {
|
||||
EpiphanyCrrcResultStatus::Completed => {
|
||||
match runtime_reorient_worker_result(runtime_store_path, job_id) {
|
||||
|
|
@ -67,10 +66,14 @@ pub fn read_runtime_reorient_result(
|
|||
}
|
||||
}
|
||||
}
|
||||
EpiphanyCrrcResultStatus::Failed | EpiphanyCrrcResultStatus::Cancelled => snapshot
|
||||
.result
|
||||
.as_ref()
|
||||
.map(interpret_reorient_lifecycle_failure),
|
||||
EpiphanyCrrcResultStatus::Failed | EpiphanyCrrcResultStatus::Cancelled => {
|
||||
match runtime_reorient_worker_result(runtime_store_path, job_id) {
|
||||
Ok(result) => result
|
||||
.as_ref()
|
||||
.map(interpret_runtime_reorient_worker_result),
|
||||
Err(_) => None,
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
reorient_snapshot(status, finding, None)
|
||||
|
|
@ -97,25 +100,6 @@ fn reorient_snapshot(
|
|||
}
|
||||
}
|
||||
|
||||
fn interpret_reorient_lifecycle_failure(
|
||||
result: &EpiphanyRuntimeJobResult,
|
||||
) -> EpiphanyReorientFindingInterpretation {
|
||||
EpiphanyReorientFindingInterpretation {
|
||||
mode: None,
|
||||
summary: Some(result.summary.clone()),
|
||||
next_safe_move: nonempty(&result.next_safe_move),
|
||||
checkpoint_still_valid: None,
|
||||
files_inspected: Vec::new(),
|
||||
frontier_node_ids: Vec::new(),
|
||||
evidence_ids: Vec::new(),
|
||||
artifact_refs: Vec::new(),
|
||||
runtime_result_id: Some(result.result_id.clone()),
|
||||
runtime_job_id: Some(result.job_id.clone()),
|
||||
job_error: Some(result.summary.clone()),
|
||||
item_error: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn reorient_result_status(status: &EpiphanyRuntimeJobStatus) -> EpiphanyCrrcResultStatus {
|
||||
match status {
|
||||
EpiphanyRuntimeJobStatus::Queued => EpiphanyCrrcResultStatus::Pending,
|
||||
|
|
@ -163,7 +147,3 @@ fn render_reorient_result_note(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn nonempty(value: &str) -> Option<String> {
|
||||
(!value.trim().is_empty()).then(|| value.to_string())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3689,14 +3689,15 @@ mod tests {
|
|||
);
|
||||
let mut death_cache = crate::runtime_spine_cache(&store)?;
|
||||
death_cache.pull_all_backing_stores()?;
|
||||
let death = death_cache
|
||||
.get::<crate::EpiphanyRuntimeJobResult>(&format!("result-worker-death-{scheduled}"))?
|
||||
.expect("worker death emits its terminal runtime result");
|
||||
assert_eq!(death.verdict, "failed");
|
||||
let death_context = death
|
||||
.decision_context_id
|
||||
.as_deref()
|
||||
.expect("model-backed death preserves its decision context");
|
||||
let death_failures = death_cache
|
||||
.get_all::<crate::EpiphanyModelPassFailure>()?
|
||||
.into_iter()
|
||||
.filter(|failure| failure.pass_id == scheduled)
|
||||
.collect::<Vec<_>>();
|
||||
let [death_failure] = death_failures.as_slice() else {
|
||||
panic!("worker death emits one typed model-pass failure")
|
||||
};
|
||||
let death_context = death_failure.decision_context_id.as_str();
|
||||
assert!(crate::audit_decision_context(&store, death_context).is_ok());
|
||||
assert_eq!(
|
||||
crate::runtime_worker_process_claim(&store, &failed_launch.job_id)?
|
||||
|
|
@ -3924,18 +3925,6 @@ mod tests {
|
|||
decision_context_id: direction_context.context_id.clone(),
|
||||
};
|
||||
crate::put_runtime_role_worker_result(&store, &direction_worker_result)?;
|
||||
crate::complete_runtime_job(
|
||||
&store,
|
||||
crate::RuntimeSpineJobResultOptions {
|
||||
result_id: "direction-runtime-result".into(),
|
||||
job_id: direction_job_id,
|
||||
completed_at: "2026-08-17T00:00:05.500Z".into(),
|
||||
verdict: "suggest".into(),
|
||||
summary: direction_result.summary,
|
||||
next_safe_move: "Promote through the exact proposal owner.".into(),
|
||||
decision_context_id: Some(direction_context.context_id),
|
||||
},
|
||||
)?;
|
||||
let mut promoted = crate::promote_autonomous_direction_options_for_modeling(
|
||||
&store,
|
||||
"GameCult/Epiphany",
|
||||
|
|
@ -4014,17 +4003,12 @@ mod tests {
|
|||
)
|
||||
.is_err()
|
||||
);
|
||||
crate::complete_runtime_job(
|
||||
crate::terminalize_runtime_job(
|
||||
&store,
|
||||
crate::RuntimeSpineJobResultOptions {
|
||||
result_id: format!("runtime-result-failed-{proposal_job_id}"),
|
||||
job_id: proposal_job_id.clone(),
|
||||
completed_at: "2026-08-17T00:00:09.100Z".into(),
|
||||
verdict: "failed".into(),
|
||||
summary: "provider returned no terminal decision".into(),
|
||||
next_safe_move: "retry from the same exact obligation".into(),
|
||||
decision_context_id: None,
|
||||
},
|
||||
&proposal_job_id,
|
||||
crate::EpiphanyRuntimeJobStatus::Failed,
|
||||
"2026-08-17T00:00:09.100Z",
|
||||
&format!("worker-runtime-failure-{proposal_job_id}"),
|
||||
)?;
|
||||
let proposal_retry_projection = project_current_work(&store)?;
|
||||
assert_eq!(
|
||||
|
|
@ -4190,18 +4174,6 @@ mod tests {
|
|||
"2026-08-17T00:00:11Z",
|
||||
)?;
|
||||
crate::put_runtime_role_worker_result(&store, &proposal_result)?;
|
||||
crate::complete_runtime_job(
|
||||
&store,
|
||||
crate::RuntimeSpineJobResultOptions {
|
||||
result_id: format!("runtime-result-{proposal_job_id}"),
|
||||
job_id: proposal_job_id.clone(),
|
||||
completed_at: "2026-08-17T00:00:12Z".into(),
|
||||
verdict: proposal_result.verdict.clone(),
|
||||
summary: proposal_result.summary.clone(),
|
||||
next_safe_move: proposal_result.next_safe_move.clone(),
|
||||
decision_context_id: Some(proposal_context.context_id.clone()),
|
||||
},
|
||||
)?;
|
||||
assert_eq!(
|
||||
crate::runtime_worker_process_claim(&store, &proposal_job_id)?
|
||||
.expect("structured Modeling result terminalizes its process claim")
|
||||
|
|
@ -4341,18 +4313,6 @@ mod tests {
|
|||
"2026-08-17T00:00:13.300Z",
|
||||
)?;
|
||||
crate::put_runtime_role_worker_result(&store, &proposal_result)?;
|
||||
crate::complete_runtime_job(
|
||||
&store,
|
||||
crate::RuntimeSpineJobResultOptions {
|
||||
result_id: format!("runtime-result-{proposal_job_id}"),
|
||||
job_id: proposal_job_id.clone(),
|
||||
completed_at: "2026-08-17T00:00:13.400Z".into(),
|
||||
verdict: proposal_result.verdict.clone(),
|
||||
summary: proposal_result.summary.clone(),
|
||||
next_safe_move: proposal_result.next_safe_move.clone(),
|
||||
decision_context_id: Some(retry_context.context_id),
|
||||
},
|
||||
)?;
|
||||
assert_eq!(
|
||||
project_current_work(&store)?
|
||||
.proposal_modeling
|
||||
|
|
@ -4680,18 +4640,6 @@ mod tests {
|
|||
decision_context_id: verification_context.context_id.clone(),
|
||||
};
|
||||
crate::put_runtime_role_worker_result(&store, &verification_result)?;
|
||||
crate::complete_runtime_job(
|
||||
&store,
|
||||
crate::RuntimeSpineJobResultOptions {
|
||||
result_id: format!("runtime-result-{verification_job_id}"),
|
||||
job_id: verification_job_id.clone(),
|
||||
completed_at: "2026-08-17T00:00:15Z".into(),
|
||||
verdict: verification_result.verdict.clone(),
|
||||
summary: verification_result.summary.clone(),
|
||||
next_safe_move: verification_result.next_safe_move.clone(),
|
||||
decision_context_id: Some(verification_context.context_id.clone()),
|
||||
},
|
||||
)?;
|
||||
assert_eq!(
|
||||
project_current_work(&store)?
|
||||
.verification
|
||||
|
|
@ -5034,18 +4982,6 @@ mod tests {
|
|||
"2026-08-17T00:00:19Z",
|
||||
)?;
|
||||
crate::put_runtime_role_worker_result(&store, &verdict_result)?;
|
||||
crate::complete_runtime_job(
|
||||
&store,
|
||||
crate::RuntimeSpineJobResultOptions {
|
||||
result_id: format!("runtime-result-{verdict_job_id}"),
|
||||
job_id: verdict_job_id.clone(),
|
||||
completed_at: "2026-08-17T00:00:20Z".into(),
|
||||
verdict: verdict_result.verdict.clone(),
|
||||
summary: verdict_result.summary.clone(),
|
||||
next_safe_move: verdict_result.next_safe_move.clone(),
|
||||
decision_context_id: Some(verdict_context.context_id.clone()),
|
||||
},
|
||||
)?;
|
||||
assert_eq!(
|
||||
project_current_work(&store)?
|
||||
.frontier_verdict_modeling
|
||||
|
|
@ -5351,18 +5287,6 @@ mod tests {
|
|||
"2026-08-17T00:00:21.950Z",
|
||||
)?;
|
||||
crate::put_runtime_role_worker_result(&store, &planning_result)?;
|
||||
crate::complete_runtime_job(
|
||||
&store,
|
||||
crate::RuntimeSpineJobResultOptions {
|
||||
result_id: format!("runtime-result-{planning_job}"),
|
||||
job_id: planning_job.clone(),
|
||||
completed_at: "2026-08-17T00:00:22Z".into(),
|
||||
verdict: planning_result.verdict.clone(),
|
||||
summary: planning_result.summary.clone(),
|
||||
next_safe_move: planning_result.next_safe_move.clone(),
|
||||
decision_context_id: Some(planning_context.context_id.clone()),
|
||||
},
|
||||
)?;
|
||||
let mind_request = crate::commit_repo_frontier_plan_mind_request(
|
||||
&store,
|
||||
&planning_result.result_id,
|
||||
|
|
@ -5469,18 +5393,6 @@ mod tests {
|
|||
"2026-08-17T00:00:22.450Z",
|
||||
)?;
|
||||
crate::put_runtime_role_worker_result(&store, &mind_result)?;
|
||||
crate::complete_runtime_job(
|
||||
&store,
|
||||
crate::RuntimeSpineJobResultOptions {
|
||||
result_id: format!("runtime-result-{mind_job}"),
|
||||
job_id: mind_job.clone(),
|
||||
completed_at: "2026-08-17T00:00:22.500Z".into(),
|
||||
verdict: mind_result.verdict.clone(),
|
||||
summary: mind_result.summary.clone(),
|
||||
next_safe_move: mind_result.next_safe_move.clone(),
|
||||
decision_context_id: Some(mind_context.context_id.clone()),
|
||||
},
|
||||
)?;
|
||||
let plan_decision =
|
||||
crate::commit_repo_frontier_plan_decision(&store, &mind_result.result_id)?;
|
||||
assert_eq!(
|
||||
|
|
@ -5681,18 +5593,6 @@ mod tests {
|
|||
"2026-08-17T00:00:25Z",
|
||||
)?;
|
||||
crate::put_runtime_role_worker_result(&store, &research_result)?;
|
||||
crate::complete_runtime_job(
|
||||
&store,
|
||||
crate::RuntimeSpineJobResultOptions {
|
||||
result_id: format!("runtime-result-{research_job}"),
|
||||
job_id: research_job.clone(),
|
||||
completed_at: "2026-08-17T00:00:26Z".into(),
|
||||
verdict: research_result.verdict.clone(),
|
||||
summary: research_result.summary.clone(),
|
||||
next_safe_move: research_result.next_safe_move.clone(),
|
||||
decision_context_id: Some(research_context.context_id.clone()),
|
||||
},
|
||||
)?;
|
||||
assert_eq!(
|
||||
project_current_work(&store)?.research.continuation_action(),
|
||||
Some(RepoFrontierResearchContinuationAction::ReviewResearchResult)
|
||||
|
|
@ -5791,18 +5691,6 @@ mod tests {
|
|||
"2026-08-17T00:00:27.100Z",
|
||||
)?;
|
||||
crate::put_runtime_role_worker_result(&stale_research_store, &research_result)?;
|
||||
crate::complete_runtime_job(
|
||||
&stale_research_store,
|
||||
crate::RuntimeSpineJobResultOptions {
|
||||
result_id: format!("runtime-result-{research_job}"),
|
||||
job_id: research_job.clone(),
|
||||
completed_at: "2026-08-17T00:00:27.200Z".into(),
|
||||
verdict: research_result.verdict.clone(),
|
||||
summary: research_result.summary.clone(),
|
||||
next_safe_move: research_result.next_safe_move.clone(),
|
||||
decision_context_id: Some(research_context.context_id.clone()),
|
||||
},
|
||||
)?;
|
||||
assert_eq!(
|
||||
crate::runtime_role_worker_result(&stale_research_store, &research_job)?
|
||||
.expect("stale output remains a durable decision")
|
||||
|
|
|
|||
|
|
@ -205,8 +205,6 @@ pub use runtime_spine::EpiphanyCoordinatorRunReceipt;
|
|||
pub use runtime_spine::EpiphanyCoordinatorRunTerminality;
|
||||
pub use runtime_spine::EpiphanyRuntimeIdentity;
|
||||
pub use runtime_spine::EpiphanyRuntimeJob;
|
||||
pub use runtime_spine::EpiphanyRuntimeJobResult;
|
||||
pub use runtime_spine::EpiphanyRuntimeJobSnapshot;
|
||||
pub use runtime_spine::EpiphanyRuntimeJobStatus;
|
||||
pub use runtime_spine::EpiphanyRuntimeModelExecutionBinding;
|
||||
pub use runtime_spine::EpiphanyRuntimeReorientWorkerResult;
|
||||
|
|
@ -230,7 +228,6 @@ pub use runtime_spine::RepoFrontierVerdictModelingLaunchAuthority;
|
|||
pub use runtime_spine::RuntimeSpineHeartbeatJobOptions;
|
||||
pub use runtime_spine::RuntimeSpineInitOptions;
|
||||
pub use runtime_spine::RuntimeSpineJobOptions;
|
||||
pub use runtime_spine::RuntimeSpineJobResultOptions;
|
||||
pub use runtime_spine::RuntimeSpineSessionClosureOptions;
|
||||
pub use runtime_spine::abandon_unactivated_runtime_worker_process;
|
||||
pub use runtime_spine::activate_runtime_worker_process;
|
||||
|
|
@ -241,7 +238,6 @@ pub use runtime_spine::claim_runtime_worker_process;
|
|||
pub use runtime_spine::close_runtime_session;
|
||||
pub use runtime_spine::commit_repo_frontier_plan_decision;
|
||||
pub use runtime_spine::commit_repo_frontier_plan_mind_request;
|
||||
pub use runtime_spine::complete_runtime_job;
|
||||
pub use runtime_spine::coordinator_run_receipts;
|
||||
pub use runtime_spine::coordinator_run_session_id;
|
||||
pub use runtime_spine::finalize_coordinator_run;
|
||||
|
|
@ -274,8 +270,8 @@ pub use runtime_spine::runtime_hands_commit_receipt;
|
|||
pub use runtime_spine::runtime_hands_patch_receipt;
|
||||
pub(crate) use runtime_spine::runtime_has_actionable_hands_frontier;
|
||||
pub use runtime_spine::runtime_identity;
|
||||
pub use runtime_spine::runtime_job_snapshot;
|
||||
pub(crate) use runtime_spine::runtime_reorient_worker_result;
|
||||
pub use runtime_spine::runtime_job;
|
||||
pub use runtime_spine::runtime_reorient_worker_result;
|
||||
pub use runtime_spine::runtime_repo_frontier_planning_lifecycle;
|
||||
pub(crate) use runtime_spine::runtime_repo_frontier_research_lifecycle;
|
||||
pub use runtime_spine::runtime_requested_public_source_refs_for_worker;
|
||||
|
|
@ -290,6 +286,7 @@ pub use runtime_spine::select_and_commit_repo_frontier_planning_request;
|
|||
pub(crate) use runtime_spine::select_and_commit_repo_frontier_research_request;
|
||||
pub use runtime_spine::select_and_commit_repo_frontier_route;
|
||||
pub use runtime_spine::terminalize_model_pass_failure_session;
|
||||
pub use runtime_spine::terminalize_runtime_job;
|
||||
pub(crate) use runtime_worker_attempt::{RuntimeTypedRequestRef, WorkerProcessStatus};
|
||||
pub use soul_gateway::*;
|
||||
pub use state_model::*;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use sha2::{Digest, Sha256};
|
|||
|
||||
use crate::{EpiphanyMindDocumentVersion, runtime_spine_cache};
|
||||
|
||||
pub const MIND_SCHEMA_EPOCH: &str = "epiphany.mind.epoch.v10";
|
||||
pub const MIND_SCHEMA_EPOCH: &str = "epiphany.mind.epoch.v11";
|
||||
pub const MIND_OBJECTIVE_KEY: &str = "objective";
|
||||
pub const MIND_FOCUS_KEY: &str = "focus";
|
||||
pub const MIND_MODE_KEY: &str = "mode";
|
||||
|
|
|
|||
|
|
@ -668,7 +668,6 @@ pub struct EpiphanyDecisionAuditIndexEntry {
|
|||
pub struct EpiphanyDecisionTerminalRecords {
|
||||
pub role_worker_results: Vec<crate::EpiphanyRuntimeRoleWorkerResult>,
|
||||
pub reorient_worker_results: Vec<crate::EpiphanyRuntimeReorientWorkerResult>,
|
||||
pub runtime_job_results: Vec<crate::EpiphanyRuntimeJobResult>,
|
||||
pub model_pass_failures: Vec<EpiphanyModelPassFailure>,
|
||||
pub archived_worker_attempts: Vec<crate::EpiphanyArchivedRuntimeWorkerAttempt>,
|
||||
pub persona_stage_receipts: Vec<crate::PersonaModelStageReceipt>,
|
||||
|
|
@ -683,7 +682,6 @@ impl EpiphanyDecisionTerminalRecords {
|
|||
fn len(&self) -> usize {
|
||||
self.role_worker_results.len()
|
||||
+ self.reorient_worker_results.len()
|
||||
+ self.runtime_job_results.len()
|
||||
+ self.model_pass_failures.len()
|
||||
+ self.archived_worker_attempts.len()
|
||||
+ self.persona_stage_receipts.len()
|
||||
|
|
@ -699,8 +697,6 @@ impl EpiphanyDecisionTerminalRecords {
|
|||
.sort_by(|left, right| left.result_id.cmp(&right.result_id));
|
||||
self.reorient_worker_results
|
||||
.sort_by(|left, right| left.result_id.cmp(&right.result_id));
|
||||
self.runtime_job_results
|
||||
.sort_by(|left, right| left.result_id.cmp(&right.result_id));
|
||||
self.model_pass_failures
|
||||
.sort_by(|left, right| left.failure_id.cmp(&right.failure_id));
|
||||
self.archived_worker_attempts
|
||||
|
|
@ -792,11 +788,6 @@ fn audit_decision_context_from_cache(
|
|||
.into_iter()
|
||||
.filter(|record| record.decision_context_id == context_id)
|
||||
.collect(),
|
||||
runtime_job_results: cache
|
||||
.get_all::<crate::EpiphanyRuntimeJobResult>()?
|
||||
.into_iter()
|
||||
.filter(|record| record.decision_context_id.as_deref() == Some(context_id))
|
||||
.collect(),
|
||||
model_pass_failures: cache
|
||||
.get_all::<EpiphanyModelPassFailure>()?
|
||||
.into_iter()
|
||||
|
|
@ -895,10 +886,6 @@ fn validate_decision_terminal_records(
|
|||
.reorient_worker_results
|
||||
.iter()
|
||||
.any(|record| record.job_id != basis.pass_id)
|
||||
|| records
|
||||
.runtime_job_results
|
||||
.iter()
|
||||
.any(|record| record.job_id != basis.pass_id)
|
||||
|| records
|
||||
.archived_worker_attempts
|
||||
.iter()
|
||||
|
|
@ -1005,12 +992,6 @@ fn validate_model_failure_companions(records: &EpiphanyDecisionTerminalRecords)
|
|||
.admitted_model_direction_consideration_result_msgpack
|
||||
.is_none()
|
||||
};
|
||||
let runtime_result_is_failure_projection = |record: &crate::EpiphanyRuntimeJobResult| {
|
||||
matches!(
|
||||
record.verdict.as_str(),
|
||||
"failed" | "fail" | "runtime-error" | "error" | "blocked" | "cancelled" | "canceled"
|
||||
)
|
||||
};
|
||||
let archived_attempt_is_failure = |record: &crate::EpiphanyArchivedRuntimeWorkerAttempt| {
|
||||
crate::WorkerProcessStatus::parse(&record.terminal_process_status)
|
||||
.map(|status| !status.is_fulfilled_terminal())
|
||||
|
|
@ -1021,10 +1002,6 @@ fn validate_model_failure_companions(records: &EpiphanyDecisionTerminalRecords)
|
|||
.role_worker_results
|
||||
.iter()
|
||||
.any(|record| !role_result_is_failure_projection(record))
|
||||
|| records
|
||||
.runtime_job_results
|
||||
.iter()
|
||||
.any(|record| !runtime_result_is_failure_projection(record))
|
||||
|| records
|
||||
.archived_worker_attempts
|
||||
.iter()
|
||||
|
|
@ -2374,19 +2351,8 @@ mod tests {
|
|||
Some(failure.clone())
|
||||
);
|
||||
let model_job =
|
||||
crate::runtime_job_snapshot(&store, "failed-model-job")?.expect("model job snapshot");
|
||||
assert_eq!(
|
||||
model_job.job.status,
|
||||
crate::EpiphanyRuntimeJobStatus::Failed
|
||||
);
|
||||
assert!(
|
||||
model_job
|
||||
.result
|
||||
.expect("model transport failure result")
|
||||
.decision_context_id
|
||||
.is_none(),
|
||||
"generic model transport must not own decision authority"
|
||||
);
|
||||
crate::runtime_job(&store, "failed-model-job")?.expect("failed model runtime job");
|
||||
assert_eq!(model_job.status, crate::EpiphanyRuntimeJobStatus::Failed);
|
||||
let audit = audit_decision_context(&store, &context.context_id)?;
|
||||
assert_eq!(
|
||||
audit.terminal_records.model_pass_failures,
|
||||
|
|
@ -2429,25 +2395,14 @@ mod tests {
|
|||
admitted_model_direction_consideration_result_msgpack: None,
|
||||
decision_context_id: context.context_id.clone(),
|
||||
};
|
||||
let failure_runtime_result = crate::EpiphanyRuntimeJobResult {
|
||||
result_id: format!("result-runtime-{}", reasoning_basis.pass_id),
|
||||
job_id: reasoning_basis.pass_id.clone(),
|
||||
verdict: "failed".into(),
|
||||
summary: failure_summary,
|
||||
completed_at: "2026-08-18T00:00:03Z".into(),
|
||||
next_safe_move: "Create a fresh work obligation and reasoning pass.".into(),
|
||||
decision_context_id: Some(context.context_id.clone()),
|
||||
};
|
||||
let mut cache = runtime_spine_cache(&store)?;
|
||||
cache.put(&failure_role_result.job_id, &failure_role_result)?;
|
||||
cache.put(&failure_runtime_result.result_id, &failure_runtime_result)?;
|
||||
let audit = audit_decision_context(&store, &context.context_id)?;
|
||||
assert_eq!(audit.terminal_records.role_worker_results.len(), 1);
|
||||
assert_eq!(audit.terminal_records.runtime_job_results.len(), 1);
|
||||
assert_eq!(audit.terminal_records.model_pass_failures.len(), 1);
|
||||
assert_eq!(
|
||||
list_auditable_decision_contexts(&store)?.decisions[0].terminal_record_count,
|
||||
3
|
||||
2
|
||||
);
|
||||
let mut false_success = failure_role_result.clone();
|
||||
false_success.verdict = "completed".into();
|
||||
|
|
@ -2621,16 +2576,33 @@ mod tests {
|
|||
let before_unterminal_audit = backing.pull_all()?;
|
||||
assert!(audit_decision_context(&store, &context.context_id).is_err());
|
||||
assert_eq!(backing.pull_all()?, before_unterminal_audit);
|
||||
let terminal_result = crate::EpiphanyRuntimeJobResult {
|
||||
let terminal_result = crate::EpiphanyRuntimeRoleWorkerResult {
|
||||
result_id: "worker-result-1".into(),
|
||||
job_id: "pass-1".into(),
|
||||
role_id: role_terminal_semantic_role(&basis)?.expect("role pass"),
|
||||
verdict: "completed".into(),
|
||||
summary: "Structured Imagination decision".into(),
|
||||
completed_at: "2026-08-14T00:00:03Z".into(),
|
||||
next_safe_move: "Inspect the durable decision context".into(),
|
||||
decision_context_id: Some(context.context_id.clone()),
|
||||
checkpoint_summary: None,
|
||||
scratch_summary: None,
|
||||
files_inspected: Vec::new(),
|
||||
frontier_node_ids: Vec::new(),
|
||||
evidence_ids: Vec::new(),
|
||||
artifact_refs: Vec::new(),
|
||||
open_questions: Vec::new(),
|
||||
evidence_gaps: Vec::new(),
|
||||
risks: Vec::new(),
|
||||
research_decision_msgpack: None,
|
||||
item_error: None,
|
||||
metadata: Default::default(),
|
||||
repo_model_mutation_proposal_msgpack: None,
|
||||
frontier_plan_candidate_msgpack: None,
|
||||
frontier_plan_mind_decision_msgpack: None,
|
||||
imagination_consideration_candidate_msgpack: None,
|
||||
admitted_model_direction_consideration_result_msgpack: None,
|
||||
decision_context_id: context.context_id.clone(),
|
||||
};
|
||||
runtime_spine_cache(&store)?.put(&terminal_result.result_id, &terminal_result)?;
|
||||
runtime_spine_cache(&store)?.put(&terminal_result.job_id, &terminal_result)?;
|
||||
let before_audit = backing.pull_all()?;
|
||||
let audit = audit_decision_context(&store, &context.context_id)?;
|
||||
assert_eq!(audit.context_id, context.context_id);
|
||||
|
|
@ -2638,7 +2610,7 @@ mod tests {
|
|||
assert_eq!(audit.terminal_native_request.request_id, "request-1");
|
||||
assert_eq!(audit.terminal_provider_request.request_id, "request-1");
|
||||
assert_eq!(
|
||||
audit.terminal_records.runtime_job_results,
|
||||
audit.terminal_records.role_worker_results,
|
||||
vec![terminal_result.clone()]
|
||||
);
|
||||
assert_eq!(audit.mind_commit_receipts.len(), 2);
|
||||
|
|
@ -2647,7 +2619,8 @@ mod tests {
|
|||
let mut archive_cache = runtime_spine_cache(&store)?;
|
||||
archive_cache.pull_all_backing_stores()?;
|
||||
assert!(
|
||||
archive_cache.delete::<crate::EpiphanyRuntimeJobResult>(&terminal_result.result_id)?
|
||||
archive_cache
|
||||
.delete::<crate::EpiphanyRuntimeRoleWorkerResult>(&terminal_result.job_id)?
|
||||
);
|
||||
let archived = crate::EpiphanyArchivedRuntimeWorkerAttempt {
|
||||
job_id: "pass-1".into(),
|
||||
|
|
@ -2666,7 +2639,7 @@ mod tests {
|
|||
assert!(
|
||||
archived_audit
|
||||
.terminal_records
|
||||
.runtime_job_results
|
||||
.role_worker_results
|
||||
.is_empty()
|
||||
);
|
||||
assert_eq!(
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ pub const REORIENTATION_REQUEST_SCHEMA_VERSION: &str = "epiphany.self.reorientat
|
|||
pub const MIND_REORIENTATION_DECISION_SCHEMA_VERSION: &str =
|
||||
"epiphany.mind.reorientation_decision.v1";
|
||||
pub const MIND_REORIENTATION_PASS_FAILURE_SCHEMA_VERSION: &str =
|
||||
"epiphany.mind.reorientation_pass_failure.v1";
|
||||
"epiphany.mind.reorientation_pass_failure.v2";
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct EpiphanyReorientationStateProjection {
|
||||
|
|
@ -78,7 +78,7 @@ pub struct EpiphanyMindReorientationDecisionDocument {
|
|||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)]
|
||||
#[cultcache(
|
||||
type = "epiphany.mind.reorientation_pass_failure.v1",
|
||||
type = "epiphany.mind.reorientation_pass_failure.v2",
|
||||
schema = "EpiphanyMindReorientationPassFailureDocument"
|
||||
)]
|
||||
pub struct EpiphanyMindReorientationPassFailureDocument {
|
||||
|
|
@ -91,14 +91,12 @@ pub struct EpiphanyMindReorientationPassFailureDocument {
|
|||
#[cultcache(key = 3)]
|
||||
pub job_id: String,
|
||||
#[cultcache(key = 4)]
|
||||
pub runtime_result_id: String,
|
||||
pub model_pass_failure_id: String,
|
||||
#[cultcache(key = 5)]
|
||||
pub decision_context_id: String,
|
||||
#[cultcache(key = 6)]
|
||||
pub verdict: String,
|
||||
#[cultcache(key = 7)]
|
||||
pub summary: String,
|
||||
#[cultcache(key = 8)]
|
||||
#[cultcache(key = 7)]
|
||||
pub failed_at: String,
|
||||
}
|
||||
|
||||
|
|
@ -283,20 +281,29 @@ pub(crate) fn current_reorientation_work(
|
|||
EpiphanyAgentPassContinuationAction::Review
|
||||
}
|
||||
EpiphanyRuntimeJobStatus::Failed => {
|
||||
let terminal = exact_runtime_job_result(cache, &launch.job_id)?;
|
||||
match terminal.decision_context_id.as_deref() {
|
||||
Some(context_id)
|
||||
let model_failures = cache
|
||||
.get_all::<crate::EpiphanyModelPassFailure>()?
|
||||
.into_iter()
|
||||
.filter(|failure| failure.pass_id == launch.job_id)
|
||||
.collect::<Vec<_>>();
|
||||
match model_failures.as_slice() {
|
||||
[] => EpiphanyAgentPassContinuationAction::Launch,
|
||||
[model_failure]
|
||||
if failures.iter().any(|failure| {
|
||||
failure.request_id == request.request_id
|
||||
&& failure.job_id == launch.job_id
|
||||
&& failure.runtime_result_id == terminal.result_id
|
||||
&& failure.decision_context_id == context_id
|
||||
&& failure.model_pass_failure_id == model_failure.failure_id
|
||||
&& failure.decision_context_id == model_failure.decision_context_id
|
||||
}) =>
|
||||
{
|
||||
EpiphanyAgentPassContinuationAction::Launch
|
||||
}
|
||||
Some(_) => EpiphanyAgentPassContinuationAction::Review,
|
||||
None => EpiphanyAgentPassContinuationAction::Launch,
|
||||
[_] => EpiphanyAgentPassContinuationAction::Review,
|
||||
_ => {
|
||||
return Err(anyhow!(
|
||||
"reorientation pass has multiple model-failure authorities"
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => EpiphanyAgentPassContinuationAction::Wait,
|
||||
|
|
@ -333,21 +340,24 @@ pub fn record_reorientation_pass_failure(
|
|||
if job.status != EpiphanyRuntimeJobStatus::Failed {
|
||||
return Err(anyhow!("reorientation pass is not a failed model pass"));
|
||||
}
|
||||
let terminal = exact_runtime_job_result(&cache, job_id)?;
|
||||
let decision_context_id = terminal
|
||||
.decision_context_id
|
||||
.as_deref()
|
||||
.ok_or_else(|| anyhow!("model-backed reorientation failure has no decision context"))?;
|
||||
let model_failures = cache
|
||||
.get_all::<crate::EpiphanyModelPassFailure>()?
|
||||
.into_iter()
|
||||
.filter(|failure| failure.pass_id == job_id)
|
||||
.collect::<Vec<_>>();
|
||||
let [model_failure] = model_failures.as_slice() else {
|
||||
return Err(anyhow!(
|
||||
"reorientation failure requires one exact model-pass failure"
|
||||
));
|
||||
};
|
||||
let context = cache
|
||||
.get::<crate::EpiphanyDecisionContext>(decision_context_id)?
|
||||
.get::<crate::EpiphanyDecisionContext>(&model_failure.decision_context_id)?
|
||||
.ok_or_else(|| anyhow!("reorientation failure lost its decision context"))?;
|
||||
let basis = cache
|
||||
.get::<crate::EpiphanyReasoningBasis>(&context.basis_id)?
|
||||
.ok_or_else(|| anyhow!("reorientation failure lost its reasoning basis"))?;
|
||||
context.validate(&basis)?;
|
||||
let model_failure =
|
||||
crate::model_pass_failure_for_request(store_path, &context.terminal_request_id)?
|
||||
.ok_or_else(|| anyhow!("reorientation failure has no exact model-pass failure"))?;
|
||||
model_failure.validate(&basis, &context)?;
|
||||
if model_failure.decision_context_id != context.context_id {
|
||||
return Err(anyhow!(
|
||||
"reorientation failure crossed its model-pass failure context"
|
||||
|
|
@ -360,14 +370,13 @@ pub fn record_reorientation_pass_failure(
|
|||
}
|
||||
let failure = EpiphanyMindReorientationPassFailureDocument {
|
||||
schema_version: MIND_REORIENTATION_PASS_FAILURE_SCHEMA_VERSION.into(),
|
||||
failure_id: format!("reorientation-pass-failure-{}", terminal.result_id),
|
||||
failure_id: format!("reorientation-pass-failure-{}", model_failure.failure_id),
|
||||
request_id: request.request_id.clone(),
|
||||
job_id: job_id.into(),
|
||||
runtime_result_id: terminal.result_id.clone(),
|
||||
decision_context_id: decision_context_id.into(),
|
||||
verdict: terminal.verdict.clone(),
|
||||
summary: terminal.summary.clone(),
|
||||
failed_at: terminal.completed_at.clone(),
|
||||
model_pass_failure_id: model_failure.failure_id.clone(),
|
||||
decision_context_id: context.context_id.clone(),
|
||||
summary: model_failure.summary.clone(),
|
||||
failed_at: model_failure.failed_at.clone(),
|
||||
};
|
||||
if let Some(existing) =
|
||||
cache.get::<EpiphanyMindReorientationPassFailureDocument>(&failure.failure_id)?
|
||||
|
|
@ -375,7 +384,7 @@ pub fn record_reorientation_pass_failure(
|
|||
if existing != failure {
|
||||
return Err(anyhow!("reorientation failure replay was substituted"));
|
||||
}
|
||||
return mind_receipt_for_failure_context(&cache, decision_context_id);
|
||||
return mind_receipt_for_failure_context(&cache, &context.context_id);
|
||||
}
|
||||
let snapshot = cache.snapshot_envelopes();
|
||||
let mut strong_reads = Vec::new();
|
||||
|
|
@ -387,10 +396,9 @@ pub fn record_reorientation_pass_failure(
|
|||
(crate::EpiphanyRuntimeWorkerLaunchRequest::TYPE, job_id),
|
||||
(crate::EpiphanyRuntimeJob::TYPE, job_id),
|
||||
(
|
||||
crate::EpiphanyRuntimeJobResult::TYPE,
|
||||
terminal.result_id.as_str(),
|
||||
crate::EpiphanyDecisionContext::TYPE,
|
||||
context.context_id.as_str(),
|
||||
),
|
||||
(crate::EpiphanyDecisionContext::TYPE, decision_context_id),
|
||||
(
|
||||
crate::EpiphanyModelPassFailure::TYPE,
|
||||
model_failure.failure_id.as_str(),
|
||||
|
|
@ -408,11 +416,11 @@ pub fn record_reorientation_pass_failure(
|
|||
crate::mind_documents::prepare_mind_document(&cache, &failure.failure_id, &failure)?;
|
||||
match crate::reasoning_context::commit_mind_mutation(
|
||||
store_path,
|
||||
decision_context_id,
|
||||
&context.context_id,
|
||||
"Continuity.reorientation_failure",
|
||||
strong_reads,
|
||||
vec![write],
|
||||
&terminal.completed_at,
|
||||
&model_failure.failed_at,
|
||||
)? {
|
||||
crate::EpiphanyMindCommitOutcome::Committed(receipt) => Ok(receipt),
|
||||
crate::EpiphanyMindCommitOutcome::Conflict {
|
||||
|
|
@ -503,9 +511,11 @@ pub fn launch_current_reorientation_work(
|
|||
);
|
||||
expected.push(
|
||||
cache
|
||||
.get_envelope::<crate::EpiphanyRuntimeJobResult>(&failure.runtime_result_id)?
|
||||
.get_envelope::<crate::EpiphanyModelPassFailure>(
|
||||
&failure.model_pass_failure_id,
|
||||
)?
|
||||
.ok_or_else(|| {
|
||||
anyhow!("reorientation retry lost its terminal result envelope")
|
||||
anyhow!("reorientation retry lost its model-failure envelope")
|
||||
})?,
|
||||
);
|
||||
}
|
||||
|
|
@ -856,26 +866,6 @@ fn mind_receipt_for_failure_context(
|
|||
}
|
||||
}
|
||||
|
||||
fn exact_runtime_job_result(
|
||||
cache: &CultCache,
|
||||
job_id: &str,
|
||||
) -> Result<crate::EpiphanyRuntimeJobResult> {
|
||||
let mut results = cache
|
||||
.get_all::<crate::EpiphanyRuntimeJobResult>()?
|
||||
.into_iter()
|
||||
.filter(|result| result.job_id == job_id)
|
||||
.collect::<Vec<_>>();
|
||||
match results.len() {
|
||||
1 => Ok(results.remove(0)),
|
||||
0 => Err(anyhow!(
|
||||
"reorientation attempt lost its terminal runtime result"
|
||||
)),
|
||||
_ => Err(anyhow!(
|
||||
"reorientation attempt has multiple terminal runtime results"
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
@ -1011,24 +1001,11 @@ mod tests {
|
|||
decision_context_id: context.context_id.clone(),
|
||||
};
|
||||
crate::put_runtime_reorient_worker_result(&store, &result)?;
|
||||
crate::complete_runtime_job(
|
||||
&store,
|
||||
crate::RuntimeSpineJobResultOptions {
|
||||
result_id: format!("runtime-result-{job_id}"),
|
||||
job_id: job_id.clone(),
|
||||
completed_at: "2026-08-18T10:00:06Z".into(),
|
||||
verdict: "resume".into(),
|
||||
summary: result.summary.clone(),
|
||||
next_safe_move: result.next_safe_move.clone(),
|
||||
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"
|
||||
assert_eq!(
|
||||
crate::runtime_job(&store, &job_id)?
|
||||
.expect("reorientation runtime job")
|
||||
.status,
|
||||
EpiphanyRuntimeJobStatus::Completed
|
||||
);
|
||||
|
||||
cache.pull_all_backing_stores()?;
|
||||
|
|
@ -1131,17 +1108,12 @@ mod tests {
|
|||
failed_activation,
|
||||
"2026-08-18T10:00:12Z",
|
||||
)?;
|
||||
crate::complete_runtime_job(
|
||||
crate::terminalize_runtime_job(
|
||||
&store,
|
||||
crate::RuntimeSpineJobResultOptions {
|
||||
result_id: format!("runtime-result-{failed_job}"),
|
||||
job_id: failed_job.clone(),
|
||||
completed_at: "2026-08-18T10:00:14Z".into(),
|
||||
verdict: "failed".into(),
|
||||
summary: "Provider failed after the terminal request was sealed.".into(),
|
||||
next_safe_move: "Review the typed failure, then retry.".into(),
|
||||
decision_context_id: Some(failed_context.context_id.clone()),
|
||||
},
|
||||
&failed_job,
|
||||
EpiphanyRuntimeJobStatus::Failed,
|
||||
"2026-08-18T10:00:14Z",
|
||||
&model_failure.failure_id,
|
||||
)?;
|
||||
assert_eq!(
|
||||
crate::project_current_work(&store)?
|
||||
|
|
|
|||
|
|
@ -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.v44";
|
||||
pub const RUNTIME_SPINE_SCHEMA_VERSION: &str = "epiphany.runtime_spine.v45";
|
||||
pub const EPIPHANY_RUNTIME_ROOT_SESSION_ID: &str = "epiphany-main";
|
||||
#[derive(Clone, Debug, PartialEq, DatabaseEntry)]
|
||||
#[cultcache(type = "epiphany.runtime.identity", schema = "EpiphanyRuntimeIdentity")]
|
||||
|
|
@ -287,9 +287,9 @@ impl EpiphanyArchivedRuntimeWorkerAttempt {
|
|||
)?;
|
||||
match &decision.role_result {
|
||||
Some(result)
|
||||
if fulfilled
|
||||
&& result.job_id == self.job_id
|
||||
&& result.decision_context_id == decision.decision_context_id =>
|
||||
if result.job_id == self.job_id
|
||||
&& result.decision_context_id == decision.decision_context_id
|
||||
&& (fulfilled == result.item_error.is_none()) =>
|
||||
{
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -305,6 +305,36 @@ fn worker_process_claim_id(job_id: &str) -> String {
|
|||
format!("runtime-worker-process-{job_id}")
|
||||
}
|
||||
|
||||
fn worker_outcome_status(
|
||||
item_error: Option<&str>,
|
||||
) -> Result<(EpiphanyRuntimeJobStatus, WorkerProcessStatus)> {
|
||||
match item_error {
|
||||
Some(error) if error.trim().is_empty() => {
|
||||
Err(anyhow!("typed worker failure requires a nonempty error"))
|
||||
}
|
||||
Some(_) => Ok((
|
||||
EpiphanyRuntimeJobStatus::Failed,
|
||||
WorkerProcessStatus::TerminalFailure,
|
||||
)),
|
||||
None => Ok((
|
||||
EpiphanyRuntimeJobStatus::Completed,
|
||||
WorkerProcessStatus::TerminalResult,
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
fn process_status_for_terminal_job(
|
||||
status: &EpiphanyRuntimeJobStatus,
|
||||
) -> Result<WorkerProcessStatus> {
|
||||
match status {
|
||||
EpiphanyRuntimeJobStatus::Completed => Ok(WorkerProcessStatus::TerminalResult),
|
||||
EpiphanyRuntimeJobStatus::Failed => Ok(WorkerProcessStatus::TerminalFailure),
|
||||
EpiphanyRuntimeJobStatus::Queued => {
|
||||
Err(anyhow!("runtime job terminal status cannot be queued"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct RepoFrontierVerdictModelingLaunchAuthority {
|
||||
pub request: RepoFrontierModelingRequest,
|
||||
|
|
@ -500,28 +530,6 @@ pub struct EpiphanyRuntimeReorientWorkerResult {
|
|||
pub decision_context_id: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DatabaseEntry)]
|
||||
#[cultcache(
|
||||
type = "epiphany.runtime.job_result",
|
||||
schema = "EpiphanyRuntimeJobResult"
|
||||
)]
|
||||
pub struct EpiphanyRuntimeJobResult {
|
||||
#[cultcache(key = 1)]
|
||||
pub result_id: String,
|
||||
#[cultcache(key = 2)]
|
||||
pub job_id: String,
|
||||
#[cultcache(key = 3)]
|
||||
pub verdict: String,
|
||||
#[cultcache(key = 4)]
|
||||
pub summary: String,
|
||||
#[cultcache(key = 5)]
|
||||
pub completed_at: String,
|
||||
#[cultcache(key = 6, default)]
|
||||
pub next_safe_move: String,
|
||||
#[cultcache(key = 7, default)]
|
||||
pub decision_context_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DatabaseEntry)]
|
||||
#[cultcache(
|
||||
type = "epiphany.coordinator_run_receipt.v1",
|
||||
|
|
@ -623,17 +631,6 @@ pub struct RuntimeSpineJobOptions {
|
|||
pub session_id: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct RuntimeSpineJobResultOptions {
|
||||
pub result_id: String,
|
||||
pub job_id: String,
|
||||
pub completed_at: String,
|
||||
pub verdict: String,
|
||||
pub summary: String,
|
||||
pub next_safe_move: String,
|
||||
pub decision_context_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct RuntimeSpineHeartbeatJobOptions {
|
||||
pub runtime_id: String,
|
||||
|
|
@ -647,12 +644,6 @@ pub struct RuntimeSpineHeartbeatJobOptions {
|
|||
pub created_at: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct EpiphanyRuntimeJobSnapshot {
|
||||
pub job: EpiphanyRuntimeJob,
|
||||
pub result: Option<EpiphanyRuntimeJobResult>,
|
||||
}
|
||||
|
||||
pub fn runtime_spine_cache(store_path: impl AsRef<Path>) -> Result<CultCache> {
|
||||
let store_path = store_path.as_ref();
|
||||
let backing_store = runtime_spine_backing_store(store_path)?;
|
||||
|
|
@ -706,7 +697,6 @@ fn runtime_spine_schema_cache() -> Result<CultCache> {
|
|||
cache.register_entry_type::<crate::EpiphanyMindReorientationPassFailureDocument>()?;
|
||||
cache.register_entry_type::<RepoFrontierVerificationRequest>()?;
|
||||
cache.register_entry_type::<EpiphanyRuntimeReorientWorkerResult>()?;
|
||||
cache.register_entry_type::<EpiphanyRuntimeJobResult>()?;
|
||||
cache.register_entry_type::<EpiphanyCoordinatorRunReceipt>()?;
|
||||
cache.register_entry_type::<EpiphanyCoordinatorDeathRecovery>()?;
|
||||
cache.register_entry_type::<SubstrateGateRepoAccessGrantReceipt>()?;
|
||||
|
|
@ -1009,21 +999,6 @@ pub fn terminalize_model_pass_failure_session(
|
|||
.get::<EpiphanyRuntimeJob>(&binding.job_id)?
|
||||
.ok_or_else(|| anyhow!("model pass failure runtime job is absent"))?;
|
||||
let model_job_is_live = matches!(model_job.status, EpiphanyRuntimeJobStatus::Queued);
|
||||
let model_job_results = cache
|
||||
.get_all::<EpiphanyRuntimeJobResult>()?
|
||||
.into_iter()
|
||||
.filter(|result| result.job_id == binding.job_id)
|
||||
.collect::<Vec<_>>();
|
||||
if model_job_is_live && !model_job_results.is_empty() {
|
||||
return Err(anyhow!("live model pass job already has a terminal result"));
|
||||
}
|
||||
if !model_job_is_live
|
||||
&& (model_job_results.len() != 1 || model_job_results[0].decision_context_id.is_some())
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"terminal model transport job lost its non-authoritative result"
|
||||
));
|
||||
}
|
||||
let session_job_ids = cache
|
||||
.get_all::<EpiphanyRuntimeModelExecutionBinding>()?
|
||||
.into_iter()
|
||||
|
|
@ -1054,24 +1029,8 @@ pub fn terminalize_model_pass_failure_session(
|
|||
];
|
||||
if model_job_is_live {
|
||||
model_job.status = EpiphanyRuntimeJobStatus::Failed;
|
||||
let model_result = EpiphanyRuntimeJobResult {
|
||||
result_id: format!("result-model-pass-failure-{}", failure.failure_id),
|
||||
job_id: binding.job_id.clone(),
|
||||
verdict: "failed".to_string(),
|
||||
summary: options.summary.clone(),
|
||||
completed_at: options.failed_at.clone(),
|
||||
next_safe_move:
|
||||
"Inspect the sealed decision context and typed model-pass failure before retrying."
|
||||
.to_string(),
|
||||
decision_context_id: None,
|
||||
};
|
||||
expected.push(model_job_envelope);
|
||||
replacements.push(cache.prepare_entry(&model_job.job_id, &model_job)?.0);
|
||||
replacements.push(
|
||||
cache
|
||||
.prepare_entry(&model_result.result_id, &model_result)?
|
||||
.0,
|
||||
);
|
||||
}
|
||||
if !runtime_spine_backing_store(store_path)?.compare_and_swap_batch(&expected, replacements)? {
|
||||
return terminalize_model_pass_failure_session(store_path, options);
|
||||
|
|
@ -1698,26 +1657,6 @@ fn archive_completed_model_session(
|
|||
.iter()
|
||||
.map(|job| job.job_id.clone())
|
||||
.collect::<BTreeSet<_>>();
|
||||
let mut job_results = cache
|
||||
.get_all::<EpiphanyRuntimeJobResult>()?
|
||||
.into_iter()
|
||||
.filter(|result| job_ids.contains(&result.job_id))
|
||||
.collect::<Vec<_>>();
|
||||
job_results.sort_by(|left, right| left.result_id.cmp(&right.result_id));
|
||||
if jobs.iter().any(|job| {
|
||||
job_results
|
||||
.iter()
|
||||
.filter(|result| result.job_id == job.job_id)
|
||||
.count()
|
||||
!= 1
|
||||
}) || job_results
|
||||
.iter()
|
||||
.any(|result| !job_ids.contains(&result.job_id))
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"runtime session archive requires exactly one terminal result per job"
|
||||
));
|
||||
}
|
||||
if cache
|
||||
.get_all::<EpiphanyRuntimeWorkerLaunchRequest>()?
|
||||
.iter()
|
||||
|
|
@ -1922,12 +1861,6 @@ fn archive_completed_model_session(
|
|||
for job in &jobs {
|
||||
retired_identities.insert((EpiphanyRuntimeJob::TYPE.to_string(), job.job_id.clone()));
|
||||
}
|
||||
for result in &job_results {
|
||||
retired_identities.insert((
|
||||
EpiphanyRuntimeJobResult::TYPE.to_string(),
|
||||
result.result_id.clone(),
|
||||
));
|
||||
}
|
||||
for binding in &model_bindings {
|
||||
retired_identities.insert((
|
||||
EpiphanyRuntimeModelExecutionBinding::TYPE.to_string(),
|
||||
|
|
@ -2427,10 +2360,10 @@ fn validate_admitted_model_direction_launch_carrier(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn runtime_job_snapshot(
|
||||
pub fn runtime_job(
|
||||
store_path: impl AsRef<Path>,
|
||||
job_id: &str,
|
||||
) -> Result<Option<EpiphanyRuntimeJobSnapshot>> {
|
||||
) -> Result<Option<EpiphanyRuntimeJob>> {
|
||||
validate_non_empty(job_id, "job id")?;
|
||||
let store_path = store_path.as_ref();
|
||||
if !store_path.exists() {
|
||||
|
|
@ -2438,19 +2371,7 @@ pub fn runtime_job_snapshot(
|
|||
}
|
||||
let mut cache = runtime_spine_cache(store_path)?;
|
||||
cache.pull_all_backing_stores()?;
|
||||
let Some(job) = cache.get::<EpiphanyRuntimeJob>(job_id)? else {
|
||||
return Ok(None);
|
||||
};
|
||||
let mut results = cache
|
||||
.get_all::<EpiphanyRuntimeJobResult>()?
|
||||
.into_iter()
|
||||
.filter(|result| result.job_id == job_id)
|
||||
.collect::<Vec<_>>();
|
||||
if results.len() > 1 {
|
||||
return Err(anyhow!("runtime job has multiple terminal results"));
|
||||
}
|
||||
let result = results.pop();
|
||||
Ok(Some(EpiphanyRuntimeJobSnapshot { job, result }))
|
||||
cache.get::<EpiphanyRuntimeJob>(job_id)
|
||||
}
|
||||
|
||||
pub fn runtime_worker_launch_request(
|
||||
|
|
@ -3288,56 +3209,13 @@ fn terminal_worker_request_id(cache: &CultCache, worker_job_id: &str) -> Result<
|
|||
}
|
||||
}
|
||||
|
||||
fn complete_persisted_worker_outcome(
|
||||
store_path: &Path,
|
||||
job_id: &str,
|
||||
completed_at: &str,
|
||||
) -> Result<Option<EpiphanyRuntimeJobResult>> {
|
||||
let mut cache = runtime_spine_cache(store_path)?;
|
||||
cache.pull_all_backing_stores()?;
|
||||
let role = cache.get::<EpiphanyRuntimeRoleWorkerResult>(job_id)?;
|
||||
let reorient = cache.get::<EpiphanyRuntimeReorientWorkerResult>(job_id)?;
|
||||
match (role, reorient) {
|
||||
(Some(_), Some(_)) => Err(anyhow!(
|
||||
"worker attempt has both role and reorientation terminal outcomes"
|
||||
)),
|
||||
(Some(result), None) => complete_runtime_job(
|
||||
store_path,
|
||||
RuntimeSpineJobResultOptions {
|
||||
result_id: result.result_id,
|
||||
job_id: job_id.to_string(),
|
||||
completed_at: completed_at.to_string(),
|
||||
verdict: result.verdict,
|
||||
summary: result.summary,
|
||||
next_safe_move: result.next_safe_move,
|
||||
decision_context_id: Some(result.decision_context_id),
|
||||
},
|
||||
)
|
||||
.map(Some),
|
||||
(None, Some(result)) => complete_runtime_job(
|
||||
store_path,
|
||||
RuntimeSpineJobResultOptions {
|
||||
result_id: result.result_id,
|
||||
job_id: job_id.to_string(),
|
||||
completed_at: completed_at.to_string(),
|
||||
verdict: result.mode,
|
||||
summary: result.summary,
|
||||
next_safe_move: result.next_safe_move,
|
||||
decision_context_id: Some(result.decision_context_id),
|
||||
},
|
||||
)
|
||||
.map(Some),
|
||||
(None, None) => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
fn commit_runtime_worker_process_death(
|
||||
store_path: impl AsRef<Path>,
|
||||
job_id: &str,
|
||||
terminal_authority_id: &str,
|
||||
terminal_at: &str,
|
||||
decision_context_id: Option<&str>,
|
||||
) -> Result<EpiphanyRuntimeJobResult> {
|
||||
) -> Result<EpiphanyRuntimeJob> {
|
||||
let store_path = store_path.as_ref();
|
||||
validate_non_empty(terminal_authority_id, "worker death terminal authority")?;
|
||||
chrono::DateTime::parse_from_rfc3339(terminal_at)
|
||||
|
|
@ -3352,22 +3230,15 @@ fn commit_runtime_worker_process_death(
|
|||
if status == WorkerProcessStatus::TerminalDeath
|
||||
&& current.terminal_authority_id.as_deref() == Some(terminal_authority_id)
|
||||
{
|
||||
let result_id = format!("result-worker-death-{job_id}");
|
||||
let result = cache
|
||||
.get::<EpiphanyRuntimeJobResult>(&result_id)?
|
||||
.ok_or_else(|| anyhow!("worker death claim lost its terminal job result"))?;
|
||||
let job = cache
|
||||
.get::<EpiphanyRuntimeJob>(job_id)?
|
||||
.ok_or_else(|| anyhow!("worker death claim lost its runtime job"))?;
|
||||
if job.status != EpiphanyRuntimeJobStatus::Failed
|
||||
|| result.job_id != job_id
|
||||
|| result.decision_context_id.as_deref() != decision_context_id
|
||||
{
|
||||
if job.status != EpiphanyRuntimeJobStatus::Failed {
|
||||
return Err(anyhow!(
|
||||
"worker death replay found split terminal authority"
|
||||
));
|
||||
}
|
||||
return Ok(result);
|
||||
return Ok(job);
|
||||
}
|
||||
if !status.is_live() {
|
||||
return Err(anyhow!(
|
||||
|
|
@ -3391,14 +3262,6 @@ fn commit_runtime_worker_process_death(
|
|||
"worker death recovery found a terminal runtime job"
|
||||
));
|
||||
}
|
||||
let existing_results = cache
|
||||
.get_all::<EpiphanyRuntimeJobResult>()?
|
||||
.into_iter()
|
||||
.filter(|result| result.job_id == job_id)
|
||||
.collect::<Vec<_>>();
|
||||
if !existing_results.is_empty() {
|
||||
return Err(anyhow!("live worker death recovery found a job result"));
|
||||
}
|
||||
let job_envelope = cache
|
||||
.get_envelope::<EpiphanyRuntimeJob>(job_id)?
|
||||
.ok_or_else(|| anyhow!("worker death recovery lost its job envelope"))?;
|
||||
|
|
@ -3409,23 +3272,7 @@ fn commit_runtime_worker_process_death(
|
|||
next.status = WorkerProcessStatus::TerminalDeath.as_str().into();
|
||||
next.terminal_at = Some(terminal_at.into());
|
||||
next.terminal_authority_id = Some(terminal_authority_id.into());
|
||||
let summary = "Runtime Continuity proved the exact worker process terminal before a structured outcome was admitted.".to_string();
|
||||
job.status = EpiphanyRuntimeJobStatus::Failed;
|
||||
let result = EpiphanyRuntimeJobResult {
|
||||
result_id: format!("result-worker-death-{job_id}"),
|
||||
job_id: job_id.to_string(),
|
||||
verdict: "failed".to_string(),
|
||||
summary: summary.clone(),
|
||||
completed_at: terminal_at.to_string(),
|
||||
next_safe_move: "Derive a fresh attempt from current typed work; never rebase the abandoned model output.".to_string(),
|
||||
decision_context_id: decision_context_id.map(str::to_string),
|
||||
};
|
||||
if cache
|
||||
.get::<EpiphanyRuntimeJobResult>(&result.result_id)?
|
||||
.is_some()
|
||||
{
|
||||
return Err(anyhow!("worker death terminal identities already exist"));
|
||||
}
|
||||
let mut expected = vec![current_envelope, job_envelope];
|
||||
let mut unchanged_strong_reads = Vec::new();
|
||||
if let Some(context_id) = decision_context_id {
|
||||
|
|
@ -3469,7 +3316,6 @@ fn commit_runtime_worker_process_death(
|
|||
let mut writes = vec![
|
||||
cache.prepare_entry(&claim_id, &next)?.0,
|
||||
cache.prepare_entry(job_id, &job)?.0,
|
||||
cache.prepare_entry(&result.result_id, &result)?.0,
|
||||
];
|
||||
writes.extend(unchanged_strong_reads);
|
||||
if !SingleFileMessagePackBackingStore::new(store_path)
|
||||
|
|
@ -3483,7 +3329,7 @@ fn commit_runtime_worker_process_death(
|
|||
decision_context_id,
|
||||
);
|
||||
}
|
||||
Ok(result)
|
||||
Ok(job)
|
||||
}
|
||||
|
||||
pub(crate) fn terminalize_dead_runtime_worker_attempt(
|
||||
|
|
@ -3491,13 +3337,44 @@ pub(crate) fn terminalize_dead_runtime_worker_attempt(
|
|||
job_id: &str,
|
||||
terminal_authority_id: &str,
|
||||
terminal_at: &str,
|
||||
) -> Result<EpiphanyRuntimeJobResult> {
|
||||
) -> Result<EpiphanyRuntimeJob> {
|
||||
let store_path = store_path.as_ref();
|
||||
if let Some(result) = complete_persisted_worker_outcome(store_path, job_id, terminal_at)? {
|
||||
return Ok(result);
|
||||
}
|
||||
let mut cache = runtime_spine_cache(store_path)?;
|
||||
cache.pull_all_backing_stores()?;
|
||||
let role = cache.get::<EpiphanyRuntimeRoleWorkerResult>(job_id)?;
|
||||
let reorient = cache.get::<EpiphanyRuntimeReorientWorkerResult>(job_id)?;
|
||||
if role.is_some() && reorient.is_some() {
|
||||
return Err(anyhow!(
|
||||
"worker attempt has both role and reorientation terminal outcomes"
|
||||
));
|
||||
}
|
||||
if role.is_some() || reorient.is_some() {
|
||||
let job = cache
|
||||
.get::<EpiphanyRuntimeJob>(job_id)?
|
||||
.ok_or_else(|| anyhow!("structured worker outcome lost its runtime job"))?;
|
||||
let claim = cache
|
||||
.get::<EpiphanyRuntimeWorkerProcessClaim>(&worker_process_claim_id(job_id))?
|
||||
.ok_or_else(|| anyhow!("structured worker outcome lost its process claim"))?;
|
||||
let result = role
|
||||
.as_ref()
|
||||
.map(|result| (&result.result_id, result.item_error.as_deref()))
|
||||
.or_else(|| {
|
||||
reorient
|
||||
.as_ref()
|
||||
.map(|result| (&result.result_id, result.item_error.as_deref()))
|
||||
})
|
||||
.expect("one structured outcome checked above");
|
||||
let (expected_job_status, expected_process_status) = worker_outcome_status(result.1)?;
|
||||
if job.status != expected_job_status
|
||||
|| WorkerProcessStatus::parse(&claim.status)? != expected_process_status
|
||||
|| claim.terminal_authority_id.as_deref() != Some(result.0.as_str())
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"structured worker outcome did not atomically terminalize its physiology"
|
||||
));
|
||||
}
|
||||
return Ok(job);
|
||||
}
|
||||
let terminal_request_id = terminal_worker_request_id(&cache, job_id)?;
|
||||
drop(cache);
|
||||
let decision_context_id = if let Some(request_id) = terminal_request_id {
|
||||
|
|
@ -3557,15 +3434,9 @@ pub fn put_runtime_role_worker_result(
|
|||
"role worker result cannot substitute its sealed launch role"
|
||||
));
|
||||
}
|
||||
let is_failure = match result.item_error.as_deref() {
|
||||
Some(error) if error.trim().is_empty() => {
|
||||
return Err(anyhow!(
|
||||
"typed role worker failure requires a nonempty error"
|
||||
));
|
||||
}
|
||||
Some(_) => true,
|
||||
None => false,
|
||||
};
|
||||
let (terminal_job_status, terminal_process_status) =
|
||||
worker_outcome_status(result.item_error.as_deref())?;
|
||||
let is_failure = terminal_job_status == EpiphanyRuntimeJobStatus::Failed;
|
||||
let carries_semantic_success = result.research_decision_msgpack.is_some()
|
||||
|| result.repo_model_mutation_proposal_msgpack.is_some()
|
||||
|| result.frontier_plan_candidate_msgpack.is_some()
|
||||
|
|
@ -3907,14 +3778,22 @@ pub fn put_runtime_role_worker_result(
|
|||
}
|
||||
let process_claim_id = worker_process_claim_id(&result.job_id);
|
||||
let process_claim = cache.get::<EpiphanyRuntimeWorkerProcessClaim>(&process_claim_id)?;
|
||||
let mut job = cache
|
||||
.get::<EpiphanyRuntimeJob>(&result.job_id)?
|
||||
.ok_or_else(|| anyhow!("role worker result requires its runtime job"))?;
|
||||
if let Some(existing) = cache.get::<EpiphanyRuntimeRoleWorkerResult>(&result.job_id)? {
|
||||
if existing != *result {
|
||||
return Err(anyhow!(
|
||||
"role worker result is immutable for its runtime job"
|
||||
));
|
||||
}
|
||||
if job.status != terminal_job_status {
|
||||
return Err(anyhow!(
|
||||
"role worker result is not terminal authority for its runtime job"
|
||||
));
|
||||
}
|
||||
if let Some(claim) = process_claim.as_ref()
|
||||
&& (!crate::WorkerProcessStatus::parse(&claim.status)?.is_fulfilled_terminal()
|
||||
&& (crate::WorkerProcessStatus::parse(&claim.status)? != terminal_process_status
|
||||
|| claim.terminal_authority_id.as_deref() != Some(result.result_id.as_str()))
|
||||
{
|
||||
return Err(anyhow!(
|
||||
|
|
@ -3945,9 +3824,18 @@ pub fn put_runtime_role_worker_result(
|
|||
}
|
||||
return Ok(());
|
||||
}
|
||||
if job.status != EpiphanyRuntimeJobStatus::Queued {
|
||||
return Err(anyhow!(
|
||||
"role worker result requires its queued runtime job"
|
||||
));
|
||||
}
|
||||
let job_envelope = cache
|
||||
.get_envelope::<EpiphanyRuntimeJob>(&result.job_id)?
|
||||
.ok_or_else(|| anyhow!("role worker result lost its job envelope"))?;
|
||||
job.status = terminal_job_status.clone();
|
||||
let (envelope, _) = cache.prepare_entry(&result.job_id, result)?;
|
||||
let mut writes = vec![envelope];
|
||||
let mut expected = Vec::new();
|
||||
let mut writes = vec![envelope, cache.prepare_entry(&result.job_id, &job)?.0];
|
||||
let mut expected = vec![job_envelope];
|
||||
if let Some(claim) = process_claim.as_ref() {
|
||||
if crate::WorkerProcessStatus::parse(&claim.status)? != crate::WorkerProcessStatus::Active {
|
||||
return Err(anyhow!(
|
||||
|
|
@ -3958,7 +3846,7 @@ pub fn put_runtime_role_worker_result(
|
|||
.get_envelope::<EpiphanyRuntimeWorkerProcessClaim>(&process_claim_id)?
|
||||
.ok_or_else(|| anyhow!("role worker result lost its process claim envelope"))?;
|
||||
let mut terminal_claim = claim.clone();
|
||||
terminal_claim.status = crate::WorkerProcessStatus::TerminalResult.as_str().into();
|
||||
terminal_claim.status = terminal_process_status.as_str().into();
|
||||
terminal_claim.terminal_at = Some(chrono::Utc::now().to_rfc3339());
|
||||
terminal_claim.terminal_authority_id = Some(result.result_id.clone());
|
||||
expected.push(current_envelope);
|
||||
|
|
@ -4014,12 +3902,16 @@ pub fn put_runtime_role_worker_result(
|
|||
.get::<EpiphanyRuntimeWorkerProcessClaim>(&process_claim_id)?
|
||||
.is_some_and(|claim| {
|
||||
crate::WorkerProcessStatus::parse(&claim.status)
|
||||
.is_ok_and(|status| status.is_fulfilled_terminal())
|
||||
.is_ok_and(|status| status == terminal_process_status)
|
||||
&& claim.terminal_authority_id.as_deref() == Some(result.result_id.as_str())
|
||||
}),
|
||||
None => true,
|
||||
};
|
||||
let job_matches = reloaded
|
||||
.get::<EpiphanyRuntimeJob>(&result.job_id)?
|
||||
.is_some_and(|job| job.status == terminal_job_status);
|
||||
if worker_matches
|
||||
&& job_matches
|
||||
&& model_direction_companion_matches
|
||||
&& imagination_candidate_companion_matches
|
||||
&& claim_matches
|
||||
|
|
@ -6067,7 +5959,6 @@ pub(crate) fn runtime_repo_frontier_research_lifecycle(
|
|||
require_identity(&cache)?;
|
||||
let launches = cache.get_all::<EpiphanyRuntimeWorkerLaunchRequest>()?;
|
||||
let jobs = cache.get_all::<EpiphanyRuntimeJob>()?;
|
||||
let job_results = cache.get_all::<EpiphanyRuntimeJobResult>()?;
|
||||
let role_results = cache.get_all::<EpiphanyRuntimeRoleWorkerResult>()?;
|
||||
let (view, _basis) = current_keyed_repo_model(&cache)?;
|
||||
let model = view.memory_context_projection();
|
||||
|
|
@ -6165,13 +6056,23 @@ pub(crate) fn runtime_repo_frontier_research_lifecycle(
|
|||
}
|
||||
}
|
||||
EpiphanyRuntimeJobStatus::Failed => {
|
||||
let terminal = job_results
|
||||
.iter()
|
||||
.filter(|result| result.job_id == job.job_id)
|
||||
.count();
|
||||
if terminal != 1 {
|
||||
let claim = cache
|
||||
.get::<EpiphanyRuntimeWorkerProcessClaim>(&worker_process_claim_id(
|
||||
&job.job_id,
|
||||
))?
|
||||
.ok_or_else(|| {
|
||||
anyhow!("failed frontier Research attempt lost its process claim")
|
||||
})?;
|
||||
let claim_status = WorkerProcessStatus::parse(&claim.status)?;
|
||||
if !matches!(
|
||||
claim_status,
|
||||
WorkerProcessStatus::TerminalResult
|
||||
| WorkerProcessStatus::TerminalFailure
|
||||
| WorkerProcessStatus::TerminalDeath
|
||||
) || claim.terminal_authority_id.is_none()
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"failed frontier Research attempt lost its exact terminal result"
|
||||
"failed frontier Research attempt lost its exact terminal authority"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
@ -6733,6 +6634,7 @@ pub fn put_runtime_reorient_worker_result(
|
|||
store_path: impl AsRef<Path>,
|
||||
result: &EpiphanyRuntimeReorientWorkerResult,
|
||||
) -> Result<()> {
|
||||
let store_path = store_path.as_ref();
|
||||
validate_non_empty(&result.job_id, "reorient worker result job id")?;
|
||||
validate_non_empty(&result.result_id, "reorient worker result id")?;
|
||||
validate_non_empty(&result.mode, "reorient worker result mode")?;
|
||||
|
|
@ -6743,8 +6645,91 @@ pub fn put_runtime_reorient_worker_result(
|
|||
let mut cache = runtime_spine_cache(store_path)?;
|
||||
cache.pull_all_backing_stores()?;
|
||||
require_worker_decision_context(&cache, &result.decision_context_id, &result.job_id)?;
|
||||
cache.put(&result.job_id, result)?;
|
||||
Ok(())
|
||||
let launch = cache
|
||||
.get::<EpiphanyRuntimeWorkerLaunchRequest>(&result.job_id)?
|
||||
.ok_or_else(|| anyhow!("reorientation result requires its immutable launch"))?;
|
||||
if !matches!(
|
||||
launch.launch_document()?,
|
||||
EpiphanyWorkerLaunchDocument::Reorient(_)
|
||||
) {
|
||||
return Err(anyhow!("reorientation result crossed a role launch"));
|
||||
}
|
||||
let (terminal_job_status, terminal_process_status) =
|
||||
worker_outcome_status(result.item_error.as_deref())?;
|
||||
let mut job = cache
|
||||
.get::<EpiphanyRuntimeJob>(&result.job_id)?
|
||||
.ok_or_else(|| anyhow!("reorientation result requires its runtime job"))?;
|
||||
let claim_id = worker_process_claim_id(&result.job_id);
|
||||
let claim = cache.get::<EpiphanyRuntimeWorkerProcessClaim>(&claim_id)?;
|
||||
if let Some(existing) = cache.get::<EpiphanyRuntimeReorientWorkerResult>(&result.job_id)? {
|
||||
if existing != *result
|
||||
|| job.status != terminal_job_status
|
||||
|| claim.as_ref().is_some_and(|claim| {
|
||||
WorkerProcessStatus::parse(&claim.status).ok() != Some(terminal_process_status)
|
||||
|| claim.terminal_authority_id.as_deref() != Some(result.result_id.as_str())
|
||||
})
|
||||
{
|
||||
return Err(anyhow!("reorientation result replay was substituted"));
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
if job.status != EpiphanyRuntimeJobStatus::Queued {
|
||||
return Err(anyhow!(
|
||||
"reorientation result requires its queued runtime job"
|
||||
));
|
||||
}
|
||||
let job_envelope = cache
|
||||
.get_envelope::<EpiphanyRuntimeJob>(&result.job_id)?
|
||||
.ok_or_else(|| anyhow!("reorientation result lost its job envelope"))?;
|
||||
job.status = terminal_job_status.clone();
|
||||
let mut expected = vec![job_envelope];
|
||||
let mut writes = vec![
|
||||
cache.prepare_entry(&result.job_id, result)?.0,
|
||||
cache.prepare_entry(&result.job_id, &job)?.0,
|
||||
];
|
||||
if let Some(claim) = claim {
|
||||
if WorkerProcessStatus::parse(&claim.status)? != WorkerProcessStatus::Active {
|
||||
return Err(anyhow!(
|
||||
"reorientation result requires its active process claim"
|
||||
));
|
||||
}
|
||||
let claim_envelope = cache
|
||||
.get_envelope::<EpiphanyRuntimeWorkerProcessClaim>(&claim_id)?
|
||||
.ok_or_else(|| anyhow!("reorientation result lost its claim envelope"))?;
|
||||
let mut terminal = claim;
|
||||
terminal.status = terminal_process_status.as_str().into();
|
||||
terminal.terminal_at = Some(chrono::Utc::now().to_rfc3339());
|
||||
terminal.terminal_authority_id = Some(result.result_id.clone());
|
||||
expected.push(claim_envelope);
|
||||
writes.push(cache.prepare_entry(&claim_id, &terminal)?.0);
|
||||
}
|
||||
if SingleFileMessagePackBackingStore::new(store_path)
|
||||
.compare_and_swap_batch(&expected, writes)?
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
let mut reloaded = runtime_spine_cache(store_path)?;
|
||||
reloaded.pull_all_backing_stores()?;
|
||||
if reloaded
|
||||
.get::<EpiphanyRuntimeReorientWorkerResult>(&result.job_id)?
|
||||
.is_some_and(|existing| existing == *result)
|
||||
&& reloaded
|
||||
.get::<EpiphanyRuntimeJob>(&result.job_id)?
|
||||
.is_some_and(|job| job.status == terminal_job_status)
|
||||
&& reloaded
|
||||
.get::<EpiphanyRuntimeWorkerProcessClaim>(&claim_id)?
|
||||
.is_none_or(|claim| {
|
||||
WorkerProcessStatus::parse(&claim.status)
|
||||
.is_ok_and(|status| status == terminal_process_status)
|
||||
&& claim.terminal_authority_id.as_deref() == Some(result.result_id.as_str())
|
||||
})
|
||||
{
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"reorientation result lost immutable insertion to a different outcome"
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fn require_worker_decision_context(
|
||||
|
|
@ -6767,7 +6752,7 @@ fn require_worker_decision_context(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn runtime_reorient_worker_result(
|
||||
pub fn runtime_reorient_worker_result(
|
||||
store_path: impl AsRef<Path>,
|
||||
job_id: &str,
|
||||
) -> Result<Option<EpiphanyRuntimeReorientWorkerResult>> {
|
||||
|
|
@ -8089,11 +8074,19 @@ fn archive_runtime_worker_attempt(
|
|||
));
|
||||
}
|
||||
let role_result = cache.get::<EpiphanyRuntimeRoleWorkerResult>(job_id)?;
|
||||
if fulfilled != role_result.is_some() {
|
||||
if fulfilled && role_result.is_none() {
|
||||
return Err(anyhow!(
|
||||
"worker attempt archive terminal result shape disagrees with requested archive kind"
|
||||
));
|
||||
}
|
||||
if role_result
|
||||
.as_ref()
|
||||
.is_some_and(|result| fulfilled == result.item_error.is_some())
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"worker attempt archive structured result disagrees with process terminality"
|
||||
));
|
||||
}
|
||||
let claim_id = worker_process_claim_id(job_id);
|
||||
let claim = cache
|
||||
.get::<EpiphanyRuntimeWorkerProcessClaim>(&claim_id)?
|
||||
|
|
@ -8167,21 +8160,14 @@ fn archive_runtime_worker_attempt(
|
|||
}
|
||||
}
|
||||
let snapshot = cache.snapshot_envelopes();
|
||||
let worker_job_results = cache
|
||||
.get_all::<EpiphanyRuntimeJobResult>()?
|
||||
.into_iter()
|
||||
.filter(|item| item.job_id == job_id)
|
||||
.collect::<Vec<_>>();
|
||||
let job_results = worker_job_results
|
||||
.iter()
|
||||
.map(|item| item.result_id.clone())
|
||||
.collect::<BTreeSet<_>>();
|
||||
let role_decision_context_id = role_result
|
||||
.as_ref()
|
||||
.map(|result| result.decision_context_id.clone());
|
||||
let mut decision_context_ids = worker_job_results
|
||||
let mut decision_context_ids = cache
|
||||
.get_all::<crate::EpiphanyModelPassFailure>()?
|
||||
.iter()
|
||||
.filter_map(|result| result.decision_context_id.clone())
|
||||
.filter(|failure| failure.pass_id == job_id)
|
||||
.map(|failure| failure.decision_context_id.clone())
|
||||
.chain(role_decision_context_id)
|
||||
.collect::<BTreeSet<_>>();
|
||||
if decision_context_ids.len() > 1 {
|
||||
|
|
@ -8208,12 +8194,8 @@ fn archive_runtime_worker_attempt(
|
|||
(entry.r#type == EpiphanyRuntimeWorkerLaunchRequest::TYPE && entry.key == job_id)
|
||||
|| (entry.r#type == EpiphanyRuntimeWorkerProcessClaim::TYPE
|
||||
&& entry.key == claim_id)
|
||||
|| (entry.r#type == EpiphanyRuntimeRoleWorkerResult::TYPE
|
||||
&& fulfilled
|
||||
&& entry.key == job_id)
|
||||
|| (entry.r#type == EpiphanyRuntimeRoleWorkerResult::TYPE && entry.key == job_id)
|
||||
|| (entry.r#type == EpiphanyRuntimeJob::TYPE && entry.key == job_id)
|
||||
|| (entry.r#type == EpiphanyRuntimeJobResult::TYPE
|
||||
&& job_results.contains(&entry.key))
|
||||
})
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
|
|
@ -8689,135 +8671,86 @@ pub fn coordinator_run_receipts(
|
|||
cache.get_all::<EpiphanyCoordinatorRunReceipt>()
|
||||
}
|
||||
|
||||
pub fn complete_runtime_job(
|
||||
pub fn terminalize_runtime_job(
|
||||
store_path: impl AsRef<Path>,
|
||||
options: RuntimeSpineJobResultOptions,
|
||||
) -> Result<EpiphanyRuntimeJobResult> {
|
||||
validate_non_empty(&options.result_id, "result id")?;
|
||||
validate_non_empty(&options.job_id, "job id")?;
|
||||
validate_non_empty(&options.completed_at, "completed at")?;
|
||||
validate_non_empty(&options.verdict, "verdict")?;
|
||||
validate_non_empty(&options.summary, "summary")?;
|
||||
let mut cache = runtime_spine_cache(store_path.as_ref())?;
|
||||
job_id: &str,
|
||||
status: EpiphanyRuntimeJobStatus,
|
||||
terminal_at: &str,
|
||||
terminal_authority_id: &str,
|
||||
) -> Result<EpiphanyRuntimeJob> {
|
||||
validate_non_empty(job_id, "job id")?;
|
||||
validate_non_empty(terminal_authority_id, "terminal authority id")?;
|
||||
chrono::DateTime::parse_from_rfc3339(terminal_at)
|
||||
.map_err(|error| anyhow!("runtime job terminal time is invalid: {error}"))?;
|
||||
if status == EpiphanyRuntimeJobStatus::Queued {
|
||||
return Err(anyhow!("runtime job terminal status cannot be queued"));
|
||||
}
|
||||
let store_path = store_path.as_ref();
|
||||
let mut cache = runtime_spine_cache(store_path)?;
|
||||
cache.pull_all_backing_stores()?;
|
||||
require_identity(&cache)?;
|
||||
let mut job = cache
|
||||
.get::<EpiphanyRuntimeJob>(&options.job_id)?
|
||||
.ok_or_else(|| anyhow!("runtime job {:?} does not exist", options.job_id))?;
|
||||
if matches!(
|
||||
job.status,
|
||||
EpiphanyRuntimeJobStatus::Completed | EpiphanyRuntimeJobStatus::Failed
|
||||
) {
|
||||
return Err(anyhow!(
|
||||
"runtime job {:?} is already terminal",
|
||||
options.job_id
|
||||
));
|
||||
}
|
||||
if cache
|
||||
.get::<EpiphanyRuntimeJobResult>(&options.result_id)?
|
||||
.get::<EpiphanyRuntimeRoleWorkerResult>(job_id)?
|
||||
.is_some()
|
||||
|| cache
|
||||
.get::<EpiphanyRuntimeReorientWorkerResult>(job_id)?
|
||||
.is_some()
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"runtime job result {:?} already exists",
|
||||
options.result_id
|
||||
"structured worker outcomes terminalize their own runtime job"
|
||||
));
|
||||
}
|
||||
let snapshot = cache.snapshot_envelopes();
|
||||
let job_envelope = snapshot
|
||||
.iter()
|
||||
.find(|entry| entry.r#type == EpiphanyRuntimeJob::TYPE && entry.key == options.job_id)
|
||||
.cloned()
|
||||
let mut job = cache
|
||||
.get::<EpiphanyRuntimeJob>(job_id)?
|
||||
.ok_or_else(|| anyhow!("runtime job {job_id:?} does not exist"))?;
|
||||
let claim_id = worker_process_claim_id(job_id);
|
||||
let claim = cache.get::<EpiphanyRuntimeWorkerProcessClaim>(&claim_id)?;
|
||||
if job.status != EpiphanyRuntimeJobStatus::Queued {
|
||||
if job.status != status {
|
||||
return Err(anyhow!("runtime job terminal status was substituted"));
|
||||
}
|
||||
if let Some(claim) = claim {
|
||||
let expected_claim_status = process_status_for_terminal_job(&status)?;
|
||||
if WorkerProcessStatus::parse(&claim.status)? != expected_claim_status
|
||||
|| claim.terminal_authority_id.as_deref() != Some(terminal_authority_id)
|
||||
{
|
||||
return Err(anyhow!("runtime job replay crossed its process authority"));
|
||||
}
|
||||
}
|
||||
return Ok(job);
|
||||
}
|
||||
let job_envelope = cache
|
||||
.get_envelope::<EpiphanyRuntimeJob>(job_id)?
|
||||
.ok_or_else(|| anyhow!("runtime job lost its exact envelope"))?;
|
||||
let terminal_status = terminal_status_for_verdict(&options.verdict);
|
||||
job.status = terminal_status;
|
||||
let result = EpiphanyRuntimeJobResult {
|
||||
result_id: options.result_id.clone(),
|
||||
job_id: options.job_id.clone(),
|
||||
verdict: options.verdict,
|
||||
summary: options.summary,
|
||||
completed_at: options.completed_at.clone(),
|
||||
next_safe_move: options.next_safe_move,
|
||||
decision_context_id: options.decision_context_id,
|
||||
};
|
||||
let role = cache.get::<EpiphanyRuntimeRoleWorkerResult>(&result.job_id)?;
|
||||
let reorient = cache.get::<EpiphanyRuntimeReorientWorkerResult>(&result.job_id)?;
|
||||
let (structured_result_id, structured_result_envelope) = match (&role, &reorient) {
|
||||
(Some(_), Some(_)) => {
|
||||
job.status = status.clone();
|
||||
let mut expected = vec![job_envelope];
|
||||
let mut writes = vec![cache.prepare_entry(job_id, &job)?.0];
|
||||
if let Some(claim) = claim {
|
||||
if WorkerProcessStatus::parse(&claim.status)? != WorkerProcessStatus::Active {
|
||||
return Err(anyhow!(
|
||||
"runtime worker job has both role and reorientation terminal outcomes"
|
||||
"runtime worker job cannot terminalize without its active process claim"
|
||||
));
|
||||
}
|
||||
(Some(result), None) => (
|
||||
Some(result.result_id.clone()),
|
||||
Some(
|
||||
cache
|
||||
.get_envelope::<EpiphanyRuntimeRoleWorkerResult>(&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::<EpiphanyRuntimeReorientWorkerResult>(&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];
|
||||
if let Some(envelope) = structured_result_envelope {
|
||||
expected.push(envelope.clone());
|
||||
writes.push(envelope);
|
||||
let claim_envelope = cache
|
||||
.get_envelope::<EpiphanyRuntimeWorkerProcessClaim>(&claim_id)?
|
||||
.ok_or_else(|| anyhow!("runtime worker terminality lost its claim envelope"))?;
|
||||
let mut terminal = claim;
|
||||
terminal.status = process_status_for_terminal_job(&status)?.as_str().into();
|
||||
terminal.terminal_at = Some(terminal_at.to_string());
|
||||
terminal.terminal_authority_id = Some(terminal_authority_id.to_string());
|
||||
expected.push(claim_envelope);
|
||||
writes.push(cache.prepare_entry(&claim_id, &terminal)?.0);
|
||||
}
|
||||
if structured_result_id.is_none() {
|
||||
writes.push(cache.prepare_entry(&result.result_id, &result)?.0);
|
||||
if runtime_spine_backing_store(store_path)?.compare_and_swap_batch(&expected, writes)? {
|
||||
return Ok(job);
|
||||
}
|
||||
let claim_id = worker_process_claim_id(&result.job_id);
|
||||
if let Some(claim) = cache.get::<EpiphanyRuntimeWorkerProcessClaim>(&claim_id)? {
|
||||
match crate::WorkerProcessStatus::parse(&claim.status)? {
|
||||
crate::WorkerProcessStatus::Active => {
|
||||
let claim_envelope = snapshot
|
||||
.iter()
|
||||
.find(|entry| {
|
||||
entry.r#type == EpiphanyRuntimeWorkerProcessClaim::TYPE
|
||||
&& entry.key == claim_id
|
||||
})
|
||||
.cloned()
|
||||
.ok_or_else(|| anyhow!("runtime worker completion lost its claim envelope"))?;
|
||||
let mut terminal = claim;
|
||||
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 {
|
||||
terminal.status = crate::WorkerProcessStatus::TerminalFailure.as_str().into();
|
||||
terminal.terminal_authority_id = Some(result.result_id.clone());
|
||||
}
|
||||
terminal.terminal_at = Some(result.completed_at.clone());
|
||||
expected.push(claim_envelope);
|
||||
writes.push(cache.prepare_entry(&claim_id, &terminal)?.0);
|
||||
}
|
||||
crate::WorkerProcessStatus::TerminalResult => {}
|
||||
crate::WorkerProcessStatus::Claimed => {
|
||||
return Err(anyhow!(
|
||||
"runtime worker job cannot complete before activation"
|
||||
));
|
||||
}
|
||||
status => {
|
||||
return Err(anyhow!(
|
||||
"runtime worker job completion found process status {:?}",
|
||||
status.as_str()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
if !runtime_spine_backing_store(store_path.as_ref())?
|
||||
.compare_and_swap_batch(&expected, writes)?
|
||||
{
|
||||
return Err(anyhow!("runtime job completion lost its exact snapshot"));
|
||||
}
|
||||
Ok(result)
|
||||
terminalize_runtime_job(
|
||||
store_path,
|
||||
job_id,
|
||||
status,
|
||||
terminal_at,
|
||||
terminal_authority_id,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn runtime_identity(store_path: impl AsRef<Path>) -> Result<Option<EpiphanyRuntimeIdentity>> {
|
||||
|
|
@ -8891,17 +8824,6 @@ where
|
|||
.transpose()
|
||||
}
|
||||
|
||||
fn terminal_status_for_verdict(verdict: &str) -> EpiphanyRuntimeJobStatus {
|
||||
if matches!(
|
||||
verdict,
|
||||
"failed" | "fail" | "error" | "blocked" | "cancelled" | "canceled"
|
||||
) {
|
||||
EpiphanyRuntimeJobStatus::Failed
|
||||
} else {
|
||||
EpiphanyRuntimeJobStatus::Completed
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) mod tests {
|
||||
use super::*;
|
||||
|
|
@ -8937,6 +8859,26 @@ pub(crate) mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn structured_worker_failure_cannot_claim_fulfillment() -> Result<()> {
|
||||
assert_eq!(
|
||||
worker_outcome_status(None)?,
|
||||
(
|
||||
EpiphanyRuntimeJobStatus::Completed,
|
||||
WorkerProcessStatus::TerminalResult,
|
||||
)
|
||||
);
|
||||
assert_eq!(
|
||||
worker_outcome_status(Some("provider refused"))?,
|
||||
(
|
||||
EpiphanyRuntimeJobStatus::Failed,
|
||||
WorkerProcessStatus::TerminalFailure,
|
||||
)
|
||||
);
|
||||
assert!(worker_outcome_status(Some(" ")).is_err());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn current_runtime_refuses_old_writable_epoch_without_mutation() -> Result<()> {
|
||||
let temp = tempfile::tempdir()?;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ pub struct EpiphanyRoleFindingInterpretation {
|
|||
pub frontier_node_ids: Vec<String>,
|
||||
pub evidence_ids: Vec<String>,
|
||||
pub artifact_refs: Vec<String>,
|
||||
pub runtime_result_id: Option<String>,
|
||||
pub result_id: Option<String>,
|
||||
pub runtime_job_id: Option<String>,
|
||||
pub open_questions: Vec<String>,
|
||||
pub evidence_gaps: Vec<String>,
|
||||
|
|
@ -45,7 +45,7 @@ pub struct EpiphanyReorientFindingInterpretation {
|
|||
pub frontier_node_ids: Vec<String>,
|
||||
pub evidence_ids: Vec<String>,
|
||||
pub artifact_refs: Vec<String>,
|
||||
pub runtime_result_id: Option<String>,
|
||||
pub result_id: Option<String>,
|
||||
pub runtime_job_id: Option<String>,
|
||||
pub job_error: Option<String>,
|
||||
pub item_error: Option<String>,
|
||||
|
|
@ -89,7 +89,7 @@ pub fn interpret_runtime_role_worker_result(
|
|||
frontier_node_ids: result.frontier_node_ids.clone(),
|
||||
evidence_ids: result.evidence_ids.clone(),
|
||||
artifact_refs: result.artifact_refs.clone(),
|
||||
runtime_result_id: Some(result.result_id.clone()),
|
||||
result_id: Some(result.result_id.clone()),
|
||||
runtime_job_id: Some(result.job_id.clone()),
|
||||
open_questions: result.open_questions.clone(),
|
||||
evidence_gaps: result.evidence_gaps.clone(),
|
||||
|
|
@ -134,7 +134,7 @@ pub fn interpret_runtime_reorient_worker_result(
|
|||
frontier_node_ids: result.frontier_node_ids.clone(),
|
||||
evidence_ids: result.evidence_ids.clone(),
|
||||
artifact_refs: result.artifact_refs.clone(),
|
||||
runtime_result_id: Some(result.result_id.clone()),
|
||||
result_id: Some(result.result_id.clone()),
|
||||
runtime_job_id: Some(result.job_id.clone()),
|
||||
job_error: None,
|
||||
item_error: result.item_error.clone(),
|
||||
|
|
|
|||
|
|
@ -139,22 +139,19 @@ async fn main() -> Result<()> {
|
|||
)?,
|
||||
Err(_) => {
|
||||
let summary = format!("Worker runtime timed out after {seconds} seconds.");
|
||||
let result = fail_worker_and_openai_jobs(
|
||||
fail_worker_and_openai_jobs(
|
||||
&timeout_store,
|
||||
&timeout_job_id,
|
||||
"runtime_timeout",
|
||||
summary.clone(),
|
||||
"Inspect provider/tool transport before relaunching the worker."
|
||||
.to_string(),
|
||||
pass_progress.terminal_request_id().as_deref(),
|
||||
)?;
|
||||
json!({
|
||||
"status": "timeout",
|
||||
"jobId": timeout_job_id,
|
||||
"workerResultId": result.result_id,
|
||||
"verdict": result.verdict,
|
||||
"verdict": "failed",
|
||||
"summary": summary,
|
||||
"nextSafeMove": result.next_safe_move,
|
||||
"nextSafeMove": "Inspect provider/tool transport before relaunching the worker.",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -301,13 +298,7 @@ fn claim_and_wait_for_worker_activation(options: &RunWorkerCliOptions) -> Result
|
|||
&process,
|
||||
&chrono::Utc::now().to_rfc3339(),
|
||||
)?;
|
||||
fail_worker_job(
|
||||
&options.store_path,
|
||||
&options.job_id,
|
||||
"Worker activation expired before provider/tool work.".into(),
|
||||
"Runtime Continuity may supersede only from the terminal unactivated process claim."
|
||||
.into(),
|
||||
)?;
|
||||
fail_worker_job(&options.store_path, &options.job_id)?;
|
||||
return Err(anyhow!(
|
||||
"worker activation gate expired before model/tool work"
|
||||
));
|
||||
|
|
@ -368,7 +359,6 @@ fn start_run_worker_timeout_watchdog(
|
|||
&job_id,
|
||||
"runtime_timeout",
|
||||
summary.clone(),
|
||||
"Inspect provider/tool transport before relaunching the worker.".to_string(),
|
||||
pass_progress.terminal_request_id().as_deref(),
|
||||
);
|
||||
process::exit(124);
|
||||
|
|
@ -381,24 +371,16 @@ fn fail_worker_and_openai_jobs(
|
|||
job_id: &str,
|
||||
failure_kind: &str,
|
||||
summary: String,
|
||||
next_safe_move: String,
|
||||
terminal_request_id: Option<&str>,
|
||||
) -> Result<epiphany_core::EpiphanyRuntimeJobResult> {
|
||||
let result = if let Some(request_id) = terminal_request_id
|
||||
) -> Result<()> {
|
||||
if let Some(request_id) = terminal_request_id
|
||||
&& persisted_model_request_exists(store_path, request_id)?
|
||||
{
|
||||
fail_model_backed_worker_job(
|
||||
store_path,
|
||||
job_id,
|
||||
request_id,
|
||||
failure_kind,
|
||||
summary.clone(),
|
||||
next_safe_move,
|
||||
)?
|
||||
fail_model_backed_worker_job(store_path, job_id, request_id, failure_kind, summary)?;
|
||||
} else {
|
||||
fail_worker_job(store_path, job_id, summary.clone(), next_safe_move)?
|
||||
};
|
||||
Ok(result)
|
||||
fail_worker_job(store_path, job_id)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn persisted_model_request_exists(store_path: &Path, request_id: &str) -> Result<bool> {
|
||||
|
|
@ -414,22 +396,19 @@ fn fail_worker_for_runtime_error(
|
|||
terminal_request_id: Option<&str>,
|
||||
) -> Result<serde_json::Value> {
|
||||
let summary = format!("Worker runtime failed before producing usable output: {error}");
|
||||
let result = fail_worker_and_openai_jobs(
|
||||
fail_worker_and_openai_jobs(
|
||||
store_path,
|
||||
job_id,
|
||||
"worker_runtime_error",
|
||||
summary.clone(),
|
||||
"Inspect provider/tool transport and runtime adapter errors before relaunching the worker."
|
||||
.to_string(),
|
||||
terminal_request_id,
|
||||
)?;
|
||||
Ok(json!({
|
||||
"status": "runtime-error",
|
||||
"jobId": job_id,
|
||||
"workerResultId": result.result_id,
|
||||
"verdict": result.verdict,
|
||||
"verdict": "failed",
|
||||
"summary": summary,
|
||||
"nextSafeMove": result.next_safe_move,
|
||||
"nextSafeMove": "Inspect provider/tool transport and runtime adapter errors before relaunching the worker.",
|
||||
}))
|
||||
}
|
||||
|
||||
|
|
@ -580,13 +559,42 @@ async fn run_worker_launch(
|
|||
|
||||
let assistant_text =
|
||||
assistant_text_from_model_events(&options.store_path, ¤t_request_id)?;
|
||||
let worker_result = complete_worker_job_from_assistant_text(
|
||||
complete_worker_job_from_assistant_text(
|
||||
&options.store_path,
|
||||
&launch_request,
|
||||
¤t_request_id,
|
||||
&openai_summary,
|
||||
&assistant_text,
|
||||
)?;
|
||||
let (worker_result_id, verdict, summary, next_safe_move) =
|
||||
match launch_request.launch_document()? {
|
||||
epiphany_core::EpiphanyWorkerLaunchDocument::Role(_) => {
|
||||
let result = epiphany_core::runtime_role_worker_result(
|
||||
&options.store_path,
|
||||
&launch_request.job_id,
|
||||
)?
|
||||
.ok_or_else(|| anyhow!("worker completion lost its typed role result"))?;
|
||||
(
|
||||
result.result_id,
|
||||
result.verdict,
|
||||
result.summary,
|
||||
result.next_safe_move,
|
||||
)
|
||||
}
|
||||
epiphany_core::EpiphanyWorkerLaunchDocument::Reorient(_) => {
|
||||
let result = epiphany_core::runtime_reorient_worker_result(
|
||||
&options.store_path,
|
||||
&launch_request.job_id,
|
||||
)?
|
||||
.ok_or_else(|| anyhow!("worker completion lost its typed reorientation result"))?;
|
||||
(
|
||||
result.result_id,
|
||||
result.mode,
|
||||
result.summary,
|
||||
result.next_safe_move,
|
||||
)
|
||||
}
|
||||
};
|
||||
epiphany_core::close_runtime_session(
|
||||
&options.store_path,
|
||||
epiphany_core::RuntimeSpineSessionClosureOptions {
|
||||
|
|
@ -600,13 +608,12 @@ async fn run_worker_launch(
|
|||
"bindingId": launch_request.binding_id,
|
||||
"role": launch_request.role,
|
||||
"requestId": current_request_id,
|
||||
"openaiResultId": openai_summary.result_id,
|
||||
"openaiVerdict": openai_summary.verdict,
|
||||
"openaiSummary": openai_summary.summary,
|
||||
"workerResultId": worker_result.result_id,
|
||||
"verdict": worker_result.verdict,
|
||||
"summary": worker_result.summary,
|
||||
"nextSafeMove": worker_result.next_safe_move,
|
||||
"workerResultId": worker_result_id,
|
||||
"verdict": verdict,
|
||||
"summary": summary,
|
||||
"nextSafeMove": next_safe_move,
|
||||
"requestedPublicSourceRuns": requested_public_source_runs,
|
||||
"toolRounds": tool_rounds,
|
||||
}))
|
||||
|
|
@ -661,14 +668,12 @@ fn fail_worker_for_tool_round_limit(
|
|||
&openai_summary.tool_intent_ids,
|
||||
"worker tool round limit closed this intent before execution",
|
||||
)?;
|
||||
let result = fail_model_backed_worker_job(
|
||||
let failure = fail_model_backed_worker_job(
|
||||
store_path,
|
||||
&launch_request.job_id,
|
||||
current_request_id,
|
||||
"tool_round_limit",
|
||||
summary.clone(),
|
||||
"Inspect the worker request, tool receipts, and model/tool loop before relaunching."
|
||||
.to_string(),
|
||||
)?;
|
||||
Ok(json!({
|
||||
"status": "tool-round-limit",
|
||||
|
|
@ -677,13 +682,12 @@ fn fail_worker_for_tool_round_limit(
|
|||
"bindingId": launch_request.binding_id,
|
||||
"role": launch_request.role,
|
||||
"requestId": current_request_id,
|
||||
"openaiResultId": openai_summary.result_id,
|
||||
"openaiVerdict": openai_summary.verdict,
|
||||
"openaiSummary": openai_summary.summary,
|
||||
"workerResultId": result.result_id,
|
||||
"verdict": result.verdict,
|
||||
"modelPassFailureId": failure.failure_id,
|
||||
"verdict": "failed",
|
||||
"summary": summary,
|
||||
"nextSafeMove": result.next_safe_move,
|
||||
"nextSafeMove": "Inspect the worker request, tool receipts, and model/tool loop before relaunching.",
|
||||
"pendingToolIntentIds": openai_summary.tool_intent_ids,
|
||||
"toolRounds": tool_rounds,
|
||||
}))
|
||||
|
|
@ -707,14 +711,12 @@ fn fail_worker_for_repeated_tool_loop(
|
|||
&openai_summary.tool_intent_ids,
|
||||
"worker repeated an identical tool round; intent closed before execution",
|
||||
)?;
|
||||
let result = fail_model_backed_worker_job(
|
||||
let failure = fail_model_backed_worker_job(
|
||||
store_path,
|
||||
&launch_request.job_id,
|
||||
current_request_id,
|
||||
"repeated_tool_loop",
|
||||
summary.clone(),
|
||||
"Inspect the repeated tool fingerprints and decide whether the worker needs a narrower evidence bundle, a repaired tool, or a higher explicit limit."
|
||||
.to_string(),
|
||||
)?;
|
||||
Ok(json!({
|
||||
"status": "tool-loop-stalled",
|
||||
|
|
@ -723,13 +725,12 @@ fn fail_worker_for_repeated_tool_loop(
|
|||
"bindingId": launch_request.binding_id,
|
||||
"role": launch_request.role,
|
||||
"requestId": current_request_id,
|
||||
"openaiResultId": openai_summary.result_id,
|
||||
"openaiVerdict": openai_summary.verdict,
|
||||
"openaiSummary": openai_summary.summary,
|
||||
"workerResultId": result.result_id,
|
||||
"verdict": result.verdict,
|
||||
"modelPassFailureId": failure.failure_id,
|
||||
"verdict": "failed",
|
||||
"summary": summary,
|
||||
"nextSafeMove": result.next_safe_move,
|
||||
"nextSafeMove": "Inspect the repeated tool fingerprints and decide whether the worker needs a narrower evidence bundle, a repaired tool, or a higher explicit limit.",
|
||||
"pendingToolIntentIds": openai_summary.tool_intent_ids,
|
||||
"pendingToolFingerprints": tool_fingerprints,
|
||||
"toolRounds": tool_rounds,
|
||||
|
|
@ -805,7 +806,7 @@ mod tests {
|
|||
use epiphany_core::EpiphanyRuntimeJobStatus;
|
||||
use epiphany_core::EpiphanyWorkerLaunchDocument;
|
||||
use epiphany_core::RuntimeSpineHeartbeatJobOptions;
|
||||
use epiphany_core::runtime_job_snapshot;
|
||||
use epiphany_core::runtime_job;
|
||||
use epiphany_core::runtime_worker_launch_request;
|
||||
use epiphany_tool_adapter::EpiphanyToolInvocationIntent;
|
||||
use tempfile::tempdir;
|
||||
|
|
@ -836,29 +837,13 @@ mod tests {
|
|||
.expect("typed model-pass failure");
|
||||
assert_eq!(failure.failure_kind, failure_kind);
|
||||
assert_eq!(failure.model_request_id, request_id);
|
||||
let outer = runtime_job_snapshot(store, outer_job_id)?.expect("outer worker snapshot");
|
||||
assert_eq!(
|
||||
outer
|
||||
.result
|
||||
.expect("outer worker result")
|
||||
.decision_context_id
|
||||
.as_deref(),
|
||||
Some(failure.decision_context_id.as_str())
|
||||
);
|
||||
let transport = runtime_job_snapshot(store, &failure.runtime_job_id)?
|
||||
.expect("model transport snapshot");
|
||||
let outer = runtime_job(store, outer_job_id)?.expect("outer worker job");
|
||||
assert_eq!(outer.status, EpiphanyRuntimeJobStatus::Failed);
|
||||
let transport = runtime_job(store, &failure.runtime_job_id)?.expect("model transport job");
|
||||
assert!(matches!(
|
||||
transport.job.status,
|
||||
transport.status,
|
||||
EpiphanyRuntimeJobStatus::Completed | EpiphanyRuntimeJobStatus::Failed
|
||||
));
|
||||
assert!(
|
||||
transport
|
||||
.result
|
||||
.expect("model transport result")
|
||||
.decision_context_id
|
||||
.is_none(),
|
||||
"generic model transport cannot own decision authority"
|
||||
);
|
||||
let mut cache = epiphany_core::runtime_spine_cache(store)?;
|
||||
cache.pull_all_backing_stores()?;
|
||||
assert_eq!(
|
||||
|
|
@ -1285,9 +1270,8 @@ mod tests {
|
|||
)?;
|
||||
|
||||
assert_eq!(status["status"], "tool-loop-stalled");
|
||||
let snapshot = runtime_job_snapshot(&store, "worker-job-loop")?.expect("worker snapshot");
|
||||
assert_eq!(snapshot.job.status, EpiphanyRuntimeJobStatus::Failed);
|
||||
assert_eq!(snapshot.result.expect("worker result").verdict, "failed");
|
||||
let job = runtime_job(&store, "worker-job-loop")?.expect("worker job");
|
||||
assert_eq!(job.status, EpiphanyRuntimeJobStatus::Failed);
|
||||
let mut cache = epiphany_core::runtime_spine_cache(&store)?;
|
||||
cache.pull_all_backing_stores()?;
|
||||
assert_eq!(
|
||||
|
|
@ -1390,14 +1374,12 @@ mod tests {
|
|||
.as_str()
|
||||
.is_some_and(|summary| summary.contains("tool adapter exploded"))
|
||||
);
|
||||
let snapshot =
|
||||
runtime_job_snapshot(&store, "worker-job-runtime-error")?.expect("worker snapshot");
|
||||
assert_eq!(snapshot.job.status, EpiphanyRuntimeJobStatus::Failed);
|
||||
let result = snapshot.result.expect("worker result");
|
||||
assert_eq!(result.verdict, "failed");
|
||||
let context_id = result
|
||||
.decision_context_id
|
||||
.expect("model-backed runtime failure must retain its context");
|
||||
let job = runtime_job(&store, "worker-job-runtime-error")?.expect("worker job");
|
||||
assert_eq!(job.status, EpiphanyRuntimeJobStatus::Failed);
|
||||
let failure =
|
||||
epiphany_core::model_pass_failure_for_request(&store, "request-runtime-error")?
|
||||
.expect("model-backed runtime failure must retain its typed owner");
|
||||
let context_id = failure.decision_context_id;
|
||||
let mut cache = epiphany_core::runtime_spine_cache(&store)?;
|
||||
cache.pull_all_backing_stores()?;
|
||||
assert_eq!(
|
||||
|
|
@ -1478,10 +1460,8 @@ mod tests {
|
|||
assert_eq!(status["status"], "tool-round-limit");
|
||||
assert_eq!(status["pendingToolIntentIds"][0], pending_intent_id);
|
||||
assert_ne!(status["status"], "tool-loop-stalled");
|
||||
let snapshot =
|
||||
runtime_job_snapshot(&store, "worker-job-round-limit")?.expect("worker snapshot");
|
||||
assert_eq!(snapshot.job.status, EpiphanyRuntimeJobStatus::Failed);
|
||||
assert_eq!(snapshot.result.expect("worker result").verdict, "failed");
|
||||
let job = runtime_job(&store, "worker-job-round-limit")?.expect("worker job");
|
||||
assert_eq!(job.status, EpiphanyRuntimeJobStatus::Failed);
|
||||
let mut cache = epiphany_core::runtime_spine_cache(&store)?;
|
||||
cache.pull_all_backing_stores()?;
|
||||
assert_eq!(
|
||||
|
|
|
|||
|
|
@ -8,14 +8,13 @@ use anyhow::Context;
|
|||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use chrono::SecondsFormat;
|
||||
use epiphany_core::EpiphanyRuntimeJobStatus;
|
||||
use epiphany_core::EpiphanyRuntimeReorientWorkerResult;
|
||||
use epiphany_core::EpiphanyRuntimeRoleWorkerResult;
|
||||
use epiphany_core::EpiphanyRuntimeWorkerLaunchRequest;
|
||||
use epiphany_core::EpiphanyWorkerLaunchDocument;
|
||||
use epiphany_core::RuntimeSpineInitOptions;
|
||||
use epiphany_core::RuntimeSpineJobOptions;
|
||||
use epiphany_core::RuntimeSpineJobResultOptions;
|
||||
use epiphany_core::complete_runtime_job;
|
||||
use epiphany_core::initialize_runtime_spine;
|
||||
use epiphany_core::open_runtime_model_execution;
|
||||
use epiphany_core::put_runtime_reorient_worker_result;
|
||||
|
|
@ -23,6 +22,7 @@ use epiphany_core::put_runtime_role_worker_result;
|
|||
use epiphany_core::put_runtime_tool_execution_intent;
|
||||
use epiphany_core::runtime_identity;
|
||||
use epiphany_core::runtime_spine_cache;
|
||||
use epiphany_core::terminalize_runtime_job;
|
||||
use epiphany_model_adapter::EpiphanyModelInputItem;
|
||||
use epiphany_model_adapter::EpiphanyModelReceipt;
|
||||
use epiphany_model_adapter::EpiphanyModelRequest;
|
||||
|
|
@ -93,7 +93,6 @@ pub struct EpiphanyOpenAiRuntimeRunSummary {
|
|||
pub event_count: usize,
|
||||
pub verdict: String,
|
||||
pub summary: String,
|
||||
pub result_id: String,
|
||||
pub receipt_id: Option<String>,
|
||||
pub tool_intent_ids: Vec<String>,
|
||||
}
|
||||
|
|
@ -192,19 +191,16 @@ pub fn record_model_turn_events(
|
|||
provider_request.request_id
|
||||
)
|
||||
};
|
||||
let result_id = format!("result-openai-{}", options.job_id);
|
||||
complete_runtime_job(
|
||||
terminalize_runtime_job(
|
||||
store_path,
|
||||
RuntimeSpineJobResultOptions {
|
||||
result_id: result_id.clone(),
|
||||
job_id: options.job_id.clone(),
|
||||
completed_at: now(),
|
||||
verdict: verdict.to_string(),
|
||||
summary: summary.clone(),
|
||||
next_safe_move: "Review typed OpenAI receipt before accepting downstream state."
|
||||
.to_string(),
|
||||
decision_context_id: None,
|
||||
&options.job_id,
|
||||
if verdict == "pass" {
|
||||
EpiphanyRuntimeJobStatus::Completed
|
||||
} else {
|
||||
EpiphanyRuntimeJobStatus::Failed
|
||||
},
|
||||
&now(),
|
||||
&provider_request.request_id,
|
||||
)?;
|
||||
|
||||
Ok(EpiphanyOpenAiRuntimeRunSummary {
|
||||
|
|
@ -215,7 +211,6 @@ pub fn record_model_turn_events(
|
|||
event_count: events.len(),
|
||||
verdict: verdict.to_string(),
|
||||
summary,
|
||||
result_id,
|
||||
receipt_id: receipt.map(|item| item.request_id),
|
||||
tool_intent_ids: tool_intents
|
||||
.into_iter()
|
||||
|
|
@ -388,7 +383,7 @@ pub fn complete_worker_job_from_assistant_text(
|
|||
openai_request_id: &str,
|
||||
openai_summary: &EpiphanyOpenAiRuntimeRunSummary,
|
||||
assistant_text: &str,
|
||||
) -> Result<epiphany_core::EpiphanyRuntimeJobResult> {
|
||||
) -> Result<()> {
|
||||
let decision_context =
|
||||
epiphany_core::seal_model_decision_context(store_path.as_ref(), openai_request_id)?;
|
||||
let launch_document = launch_request.launch_document()?;
|
||||
|
|
@ -414,14 +409,7 @@ pub fn complete_worker_job_from_assistant_text(
|
|||
.unwrap_or("structured output was absent")
|
||||
)
|
||||
};
|
||||
let next_safe_move = if contract_failed {
|
||||
"Repair the worker prompt/output-schema boundary before relaunching; no typed role result was admitted."
|
||||
.to_string()
|
||||
} else {
|
||||
"Inspect provider/tool transport and the sealed model-pass failure before relaunching."
|
||||
.to_string()
|
||||
};
|
||||
return fail_model_backed_worker_job(
|
||||
fail_model_backed_worker_job(
|
||||
store_path,
|
||||
&launch_request.job_id,
|
||||
openai_request_id,
|
||||
|
|
@ -431,51 +419,18 @@ pub fn complete_worker_job_from_assistant_text(
|
|||
"output_contract_failure"
|
||||
},
|
||||
summary,
|
||||
next_safe_move,
|
||||
);
|
||||
)?;
|
||||
return Ok(());
|
||||
}
|
||||
let verdict = if openai_failed || contract_failed {
|
||||
"failed".to_string()
|
||||
} else {
|
||||
parsed
|
||||
.as_ref()
|
||||
.and_then(WorkerResultIngress::verdict)
|
||||
.unwrap_or_else(|| "completed".to_string())
|
||||
};
|
||||
let summary = if openai_failed {
|
||||
format!("Worker model request {openai_request_id} failed before producing usable output.")
|
||||
} else if let Some(error) = parse_error.as_deref() {
|
||||
format!(
|
||||
"Worker model response failed declared output contract {}: {error}",
|
||||
launch_request.output_contract_id
|
||||
)
|
||||
} else {
|
||||
parsed
|
||||
.as_ref()
|
||||
.and_then(WorkerResultIngress::summary)
|
||||
.unwrap_or_else(|| "Worker completed without a structured summary.".to_string())
|
||||
};
|
||||
let next_safe_move = if contract_failed {
|
||||
"Repair the worker prompt/output-schema boundary before relaunching; no typed role result was admitted."
|
||||
.to_string()
|
||||
} else {
|
||||
parsed
|
||||
.as_ref()
|
||||
.and_then(WorkerResultIngress::next_safe_move)
|
||||
.unwrap_or_else(|| {
|
||||
"Review the typed worker runtime result before accepting state.".to_string()
|
||||
})
|
||||
};
|
||||
let mut evidence_refs = parsed
|
||||
.as_ref()
|
||||
.map(WorkerResultIngress::evidence_ids)
|
||||
.unwrap_or_default();
|
||||
evidence_refs.push(format!("openai-request:{openai_request_id}"));
|
||||
let mut artifact_refs = parsed
|
||||
let artifact_refs = parsed
|
||||
.as_ref()
|
||||
.map(WorkerResultIngress::artifact_refs)
|
||||
.unwrap_or_default();
|
||||
artifact_refs.push(format!("openai-result:{}", openai_summary.result_id));
|
||||
let result_id = format!("result-worker-{}", launch_request.job_id);
|
||||
let completed_at = now();
|
||||
if let Some(parsed) = parsed.as_ref() {
|
||||
|
|
@ -519,37 +474,19 @@ pub fn complete_worker_job_from_assistant_text(
|
|||
}
|
||||
}
|
||||
}
|
||||
complete_runtime_job(
|
||||
store_path,
|
||||
RuntimeSpineJobResultOptions {
|
||||
result_id,
|
||||
job_id: launch_request.job_id.clone(),
|
||||
completed_at,
|
||||
verdict,
|
||||
summary,
|
||||
next_safe_move,
|
||||
decision_context_id: Some(decision_context.context_id),
|
||||
},
|
||||
)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn fail_worker_job(
|
||||
store_path: impl AsRef<Path>,
|
||||
job_id: &str,
|
||||
summary: String,
|
||||
next_safe_move: String,
|
||||
) -> Result<epiphany_core::EpiphanyRuntimeJobResult> {
|
||||
complete_runtime_job(
|
||||
) -> Result<epiphany_core::EpiphanyRuntimeJob> {
|
||||
terminalize_runtime_job(
|
||||
store_path,
|
||||
RuntimeSpineJobResultOptions {
|
||||
result_id: format!("result-worker-{job_id}"),
|
||||
job_id: job_id.to_string(),
|
||||
completed_at: now(),
|
||||
verdict: "failed".to_string(),
|
||||
summary,
|
||||
next_safe_move,
|
||||
decision_context_id: None,
|
||||
},
|
||||
job_id,
|
||||
EpiphanyRuntimeJobStatus::Failed,
|
||||
&now(),
|
||||
&format!("worker-runtime-failure-{job_id}"),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -559,8 +496,7 @@ pub fn fail_model_backed_worker_job(
|
|||
terminal_request_id: &str,
|
||||
failure_kind: &str,
|
||||
summary: String,
|
||||
next_safe_move: String,
|
||||
) -> Result<epiphany_core::EpiphanyRuntimeJobResult> {
|
||||
) -> Result<epiphany_core::EpiphanyModelPassFailure> {
|
||||
let context =
|
||||
epiphany_core::seal_model_decision_context(store_path.as_ref(), terminal_request_id)?;
|
||||
let failure = epiphany_core::terminalize_model_pass_failure_session(
|
||||
|
|
@ -573,24 +509,30 @@ pub fn fail_model_backed_worker_job(
|
|||
},
|
||||
)?;
|
||||
let launch = load_worker_launch_request(store_path.as_ref(), job_id)?;
|
||||
if epiphany_core::runtime_role_worker_result(store_path.as_ref(), job_id)?.is_none()
|
||||
let role_result = epiphany_core::runtime_role_worker_result(store_path.as_ref(), job_id)?;
|
||||
if role_result.is_none()
|
||||
&& let Some(role_failure) =
|
||||
failed_frontier_planning_role_result(&launch, &summary, &context.context_id)?
|
||||
{
|
||||
epiphany_core::put_runtime_role_worker_result(store_path.as_ref(), &role_failure)?;
|
||||
return Ok(failure);
|
||||
}
|
||||
complete_runtime_job(
|
||||
store_path,
|
||||
RuntimeSpineJobResultOptions {
|
||||
result_id: format!("result-worker-{job_id}"),
|
||||
job_id: job_id.to_string(),
|
||||
completed_at: now(),
|
||||
verdict: "failed".to_string(),
|
||||
summary,
|
||||
next_safe_move,
|
||||
decision_context_id: Some(failure.decision_context_id),
|
||||
},
|
||||
)
|
||||
if role_result.is_none() {
|
||||
terminalize_runtime_job(
|
||||
store_path.as_ref(),
|
||||
job_id,
|
||||
EpiphanyRuntimeJobStatus::Failed,
|
||||
&failure.failed_at,
|
||||
&failure.failure_id,
|
||||
)?;
|
||||
} else if epiphany_core::runtime_job(store_path.as_ref(), job_id)?
|
||||
.is_none_or(|job| job.status != EpiphanyRuntimeJobStatus::Failed)
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"model-backed worker failure lost typed result terminality"
|
||||
));
|
||||
}
|
||||
Ok(failure)
|
||||
}
|
||||
|
||||
pub fn ensure_openai_runtime_ready(options: &EpiphanyOpenAiRuntimeOptions) -> Result<()> {
|
||||
|
|
@ -1293,33 +1235,6 @@ enum WorkerResultIngress {
|
|||
}
|
||||
|
||||
impl WorkerResultIngress {
|
||||
fn verdict(&self) -> Option<String> {
|
||||
match self {
|
||||
WorkerResultIngress::Role(result) => clean_optional_string(result.verdict.as_deref()),
|
||||
WorkerResultIngress::Reorient(result) => clean_optional_string(result.mode.as_deref()),
|
||||
}
|
||||
}
|
||||
|
||||
fn summary(&self) -> Option<String> {
|
||||
match self {
|
||||
WorkerResultIngress::Role(result) => clean_optional_string(result.summary.as_deref()),
|
||||
WorkerResultIngress::Reorient(result) => {
|
||||
clean_optional_string(result.summary.as_deref())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn next_safe_move(&self) -> Option<String> {
|
||||
match self {
|
||||
WorkerResultIngress::Role(result) => {
|
||||
clean_optional_string(result.next_safe_move.as_deref())
|
||||
}
|
||||
WorkerResultIngress::Reorient(result) => {
|
||||
clean_optional_string(result.next_safe_move.as_deref())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn evidence_ids(&self) -> Vec<String> {
|
||||
match self {
|
||||
WorkerResultIngress::Role(result) => clean_string_vec(&result.evidence_ids),
|
||||
|
|
@ -2039,7 +1954,7 @@ mod tests {
|
|||
use super::*;
|
||||
use epiphany_core::EpiphanyWorkerLaunchDocument;
|
||||
use epiphany_core::RuntimeSpineHeartbeatJobOptions;
|
||||
use epiphany_core::runtime_job_snapshot;
|
||||
use epiphany_core::runtime_job;
|
||||
use epiphany_openai_adapter::EpiphanyOpenAiModelReceipt;
|
||||
use sha2::{Digest, Sha256};
|
||||
use tempfile::tempdir;
|
||||
|
|
@ -2981,9 +2896,8 @@ mod tests {
|
|||
assert!(cache.get::<EpiphanyModelReceipt>("req-1")?.is_some());
|
||||
assert!(cache.get::<EpiphanyOpenAiModelRequest>("req-1")?.is_some());
|
||||
assert_eq!(
|
||||
runtime_job_snapshot(&store, &options.job_id)?
|
||||
runtime_job(&store, &options.job_id)?
|
||||
.expect("snapshot")
|
||||
.job
|
||||
.status,
|
||||
epiphany_core::EpiphanyRuntimeJobStatus::Completed
|
||||
);
|
||||
|
|
@ -3146,18 +3060,22 @@ mod tests {
|
|||
event_count: 1,
|
||||
verdict: "failed".to_string(),
|
||||
summary: "Provider refused the model pass.".to_string(),
|
||||
result_id: "result-openai-worker-worker-job-1".to_string(),
|
||||
receipt_id: None,
|
||||
tool_intent_ids: Vec::new(),
|
||||
};
|
||||
let provider_failure = complete_worker_job_from_assistant_text(
|
||||
complete_worker_job_from_assistant_text(
|
||||
&provider_failure_store,
|
||||
&launch_request,
|
||||
&model_request.request_id,
|
||||
&provider_failure_summary,
|
||||
"",
|
||||
)?;
|
||||
assert_eq!(provider_failure.verdict, "failed");
|
||||
assert_eq!(
|
||||
runtime_job(&provider_failure_store, &worker_job_id)?
|
||||
.expect("provider failure worker job")
|
||||
.status,
|
||||
EpiphanyRuntimeJobStatus::Failed
|
||||
);
|
||||
assert_eq!(
|
||||
epiphany_core::model_pass_failure_for_request(
|
||||
&provider_failure_store,
|
||||
|
|
@ -3180,14 +3098,19 @@ mod tests {
|
|||
receipt_id: Some(model_request.request_id.clone()),
|
||||
..provider_failure_summary.clone()
|
||||
};
|
||||
let contract_failure = complete_worker_job_from_assistant_text(
|
||||
complete_worker_job_from_assistant_text(
|
||||
&contract_failure_store,
|
||||
&launch_request,
|
||||
&model_request.request_id,
|
||||
&contract_failure_summary,
|
||||
"not the declared structured contract",
|
||||
)?;
|
||||
assert_eq!(contract_failure.verdict, "failed");
|
||||
assert_eq!(
|
||||
runtime_job(&contract_failure_store, &worker_job_id)?
|
||||
.expect("contract failure worker job")
|
||||
.status,
|
||||
EpiphanyRuntimeJobStatus::Failed
|
||||
);
|
||||
assert_eq!(
|
||||
epiphany_core::model_pass_failure_for_request(
|
||||
&contract_failure_store,
|
||||
|
|
@ -3210,7 +3133,6 @@ mod tests {
|
|||
event_count: 2,
|
||||
verdict: "pass".to_string(),
|
||||
summary: "OpenAI model request completed.".to_string(),
|
||||
result_id: "result-openai-worker-worker-job-1".to_string(),
|
||||
receipt_id: Some(model_request.request_id.clone()),
|
||||
tool_intent_ids: Vec::new(),
|
||||
};
|
||||
|
|
@ -3226,7 +3148,7 @@ mod tests {
|
|||
"repoModelOperations": []
|
||||
})
|
||||
.to_string();
|
||||
let result = complete_worker_job_from_assistant_text(
|
||||
complete_worker_job_from_assistant_text(
|
||||
&store,
|
||||
&launch_request,
|
||||
&model_request.request_id,
|
||||
|
|
@ -3234,13 +3156,6 @@ mod tests {
|
|||
&assistant_text,
|
||||
)?;
|
||||
|
||||
assert_eq!(result.job_id, worker_job_id);
|
||||
assert_eq!(result.verdict, "checkpoint-ready");
|
||||
assert_eq!(result.summary, "Mapped.");
|
||||
assert_eq!(
|
||||
result.next_safe_move,
|
||||
"Review the runtime-owned Body model."
|
||||
);
|
||||
let runtime_evidence_id = format!("openai-request:{}", model_request.request_id);
|
||||
let typed_result = epiphany_core::runtime_role_worker_result(&store, &worker_job_id)?
|
||||
.expect("typed role worker result");
|
||||
|
|
@ -3252,18 +3167,15 @@ mod tests {
|
|||
);
|
||||
assert_eq!(
|
||||
typed_result.artifact_refs,
|
||||
vec![
|
||||
"artifact:model".to_string(),
|
||||
format!("openai-result:{}", openai_summary.result_id)
|
||||
]
|
||||
vec!["artifact:model".to_string()]
|
||||
);
|
||||
assert!(typed_result.repo_model_mutation_proposal()?.is_none());
|
||||
assert!(
|
||||
runtime_job_snapshot(&store, &worker_job_id)?
|
||||
runtime_job(&store, &worker_job_id)?
|
||||
.expect("snapshot")
|
||||
.result
|
||||
.is_none(),
|
||||
"structured worker decisions must not persist a generic result mirror"
|
||||
.status
|
||||
== EpiphanyRuntimeJobStatus::Completed,
|
||||
"typed worker admission must atomically terminalize its runtime job"
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -603,17 +603,12 @@ mod tests {
|
|||
"interpreter" => r#"{"schemaVersion":"epiphany.persona_interpreter_effect_set.v0","effects":[{"kind":"say","channel_id":"aquarium","reply_to_message_id":"m1","content":"The native conversational nerve is being connected, and I can show the receipts.","speech_act":"status","register":"concise","target_audience":"the addressed Discord room","safety_notes":[]}]}"#.to_string(),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
epiphany_core::complete_runtime_job(
|
||||
epiphany_core::terminalize_runtime_job(
|
||||
store_path,
|
||||
epiphany_core::RuntimeSpineJobResultOptions {
|
||||
result_id: format!("persona-{stage}-{turn_id}-transport-result"),
|
||||
job_id: format!("persona-{stage}-{turn_id}"),
|
||||
completed_at: "2026-08-14T00:00:01Z".into(),
|
||||
verdict: "completed".into(),
|
||||
summary: format!("Persona {stage} test transport completed"),
|
||||
next_safe_move: "Seal the stage decision context".into(),
|
||||
decision_context_id: None,
|
||||
},
|
||||
&format!("persona-{stage}-{turn_id}"),
|
||||
epiphany_core::EpiphanyRuntimeJobStatus::Completed,
|
||||
"2026-08-14T00:00:01Z",
|
||||
&request.request_id,
|
||||
)?;
|
||||
Ok(output)
|
||||
})
|
||||
|
|
|
|||
Reference in a new issue