Stop duplicating structured worker decisions
This commit is contained in:
parent
c2be631ec1
commit
8eaa96c5d6
6 changed files with 50 additions and 43 deletions
|
|
@ -42,7 +42,7 @@ pub fn read_runtime_reorient_result(
|
|||
);
|
||||
}
|
||||
};
|
||||
let status = reorient_result_status(&snapshot);
|
||||
let status = reorient_result_status(&snapshot.job.status);
|
||||
let finding = match status {
|
||||
EpiphanyCrrcResultStatus::Completed => {
|
||||
match runtime_reorient_worker_result(runtime_store_path, job_id) {
|
||||
|
|
@ -116,13 +116,10 @@ fn interpret_reorient_lifecycle_failure(
|
|||
}
|
||||
}
|
||||
|
||||
fn reorient_result_status(snapshot: &EpiphanyRuntimeJobSnapshot) -> EpiphanyCrrcResultStatus {
|
||||
match snapshot.job.status {
|
||||
fn reorient_result_status(status: &EpiphanyRuntimeJobStatus) -> EpiphanyCrrcResultStatus {
|
||||
match status {
|
||||
EpiphanyRuntimeJobStatus::Queued => EpiphanyCrrcResultStatus::Pending,
|
||||
EpiphanyRuntimeJobStatus::Completed if snapshot.result.is_some() => {
|
||||
EpiphanyCrrcResultStatus::Completed
|
||||
}
|
||||
EpiphanyRuntimeJobStatus::Completed => EpiphanyCrrcResultStatus::Pending,
|
||||
EpiphanyRuntimeJobStatus::Completed => EpiphanyCrrcResultStatus::Completed,
|
||||
EpiphanyRuntimeJobStatus::Failed => EpiphanyCrrcResultStatus::Failed,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2658,7 +2658,6 @@ mod tests {
|
|||
decision: Some(crate::EpiphanyArchivedRuntimeWorkerDecision {
|
||||
decision_context_id: context.context_id.clone(),
|
||||
role_result: None,
|
||||
job_results: vec![terminal_result],
|
||||
}),
|
||||
};
|
||||
archive_cache.put(&archived.job_id, &archived)?;
|
||||
|
|
|
|||
|
|
@ -1023,6 +1023,13 @@ mod tests {
|
|||
decision_context_id: Some(context.context_id.clone()),
|
||||
},
|
||||
)?;
|
||||
assert!(
|
||||
crate::runtime_job_snapshot(&store, &job_id)?
|
||||
.expect("reorientation job snapshot")
|
||||
.result
|
||||
.is_none(),
|
||||
"typed reorientation decisions must not persist a generic result mirror"
|
||||
);
|
||||
|
||||
cache.pull_all_backing_stores()?;
|
||||
cache.put(
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ pub const COORDINATOR_RUN_RECEIPT_TYPE: &str = "epiphany.coordinator_run_receipt
|
|||
pub const RUNTIME_IDENTITY_KEY: &str = "self";
|
||||
pub const RUNTIME_SWARM_BINDING_KEY: &str = "runtime-swarm-binding";
|
||||
pub const RUNTIME_SWARM_BINDING_SCHEMA_VERSION: &str = "epiphany.runtime.swarm_binding.v1";
|
||||
pub const RUNTIME_SPINE_SCHEMA_VERSION: &str = "epiphany.runtime_spine.v43";
|
||||
pub const RUNTIME_SPINE_SCHEMA_VERSION: &str = "epiphany.runtime_spine.v44";
|
||||
pub const EPIPHANY_RUNTIME_ROOT_SESSION_ID: &str = "epiphany-main";
|
||||
#[derive(Clone, Debug, PartialEq, DatabaseEntry)]
|
||||
#[cultcache(type = "epiphany.runtime.identity", schema = "EpiphanyRuntimeIdentity")]
|
||||
|
|
@ -234,7 +234,7 @@ pub struct EpiphanyRuntimeWorkerProcessClaim {
|
|||
|
||||
#[derive(Clone, Debug, PartialEq, DatabaseEntry)]
|
||||
#[cultcache(
|
||||
type = "epiphany.runtime.archived_worker_attempt.v2",
|
||||
type = "epiphany.runtime.archived_worker_attempt.v3",
|
||||
schema = "EpiphanyArchivedRuntimeWorkerAttempt"
|
||||
)]
|
||||
pub struct EpiphanyArchivedRuntimeWorkerAttempt {
|
||||
|
|
@ -256,7 +256,6 @@ pub struct EpiphanyArchivedRuntimeWorkerAttempt {
|
|||
pub struct EpiphanyArchivedRuntimeWorkerDecision {
|
||||
pub decision_context_id: String,
|
||||
pub role_result: Option<EpiphanyRuntimeRoleWorkerResult>,
|
||||
pub job_results: Vec<EpiphanyRuntimeJobResult>,
|
||||
}
|
||||
|
||||
impl EpiphanyArchivedRuntimeWorkerAttempt {
|
||||
|
|
@ -286,17 +285,6 @@ impl EpiphanyArchivedRuntimeWorkerAttempt {
|
|||
&decision.decision_context_id,
|
||||
"archived worker decision context id",
|
||||
)?;
|
||||
if decision.job_results.is_empty()
|
||||
|| decision.job_results.iter().any(|result| {
|
||||
result.job_id != self.job_id
|
||||
|| result.decision_context_id.as_deref()
|
||||
!= Some(decision.decision_context_id.as_str())
|
||||
})
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"archived worker decision lost its exact generic result family"
|
||||
));
|
||||
}
|
||||
match &decision.role_result {
|
||||
Some(result)
|
||||
if fulfilled
|
||||
|
|
@ -8210,12 +8198,9 @@ fn archive_runtime_worker_attempt(
|
|||
if let Some(context_id) = decision_context_id.as_deref() {
|
||||
require_worker_decision_context(&cache, context_id, job_id)?;
|
||||
}
|
||||
let mut archived_job_results = worker_job_results.clone();
|
||||
archived_job_results.sort_by(|left, right| left.result_id.cmp(&right.result_id));
|
||||
let decision = decision_context_id.map(|context_id| EpiphanyArchivedRuntimeWorkerDecision {
|
||||
decision_context_id: context_id,
|
||||
role_result: role_result.clone(),
|
||||
job_results: archived_job_results,
|
||||
});
|
||||
let mut deletions = snapshot
|
||||
.iter()
|
||||
|
|
@ -8754,11 +8739,41 @@ pub fn complete_runtime_job(
|
|||
next_safe_move: options.next_safe_move,
|
||||
decision_context_id: options.decision_context_id,
|
||||
};
|
||||
let role = cache.get::<EpiphanyRuntimeRoleWorkerResult>(&result.job_id)?;
|
||||
let reorient = cache.get::<EpiphanyRuntimeReorientWorkerResult>(&result.job_id)?;
|
||||
let (structured_result_id, structured_result_envelope) = match (&role, &reorient) {
|
||||
(Some(_), Some(_)) => {
|
||||
return Err(anyhow!(
|
||||
"runtime worker job has both role and reorientation terminal outcomes"
|
||||
));
|
||||
}
|
||||
(Some(result), None) => (
|
||||
Some(result.result_id.clone()),
|
||||
Some(
|
||||
cache
|
||||
.get_envelope::<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,
|
||||
cache.prepare_entry(&result.result_id, &result)?.0,
|
||||
];
|
||||
let mut writes = vec![cache.prepare_entry(&job.job_id, &job)?.0];
|
||||
if let Some(envelope) = structured_result_envelope {
|
||||
expected.push(envelope.clone());
|
||||
writes.push(envelope);
|
||||
}
|
||||
if structured_result_id.is_none() {
|
||||
writes.push(cache.prepare_entry(&result.result_id, &result)?.0);
|
||||
}
|
||||
let claim_id = worker_process_claim_id(&result.job_id);
|
||||
if let Some(claim) = cache.get::<EpiphanyRuntimeWorkerProcessClaim>(&claim_id)? {
|
||||
match crate::WorkerProcessStatus::parse(&claim.status)? {
|
||||
|
|
@ -8772,17 +8787,7 @@ pub fn complete_runtime_job(
|
|||
.cloned()
|
||||
.ok_or_else(|| anyhow!("runtime worker completion lost its claim envelope"))?;
|
||||
let mut terminal = claim;
|
||||
let role = cache.get::<EpiphanyRuntimeRoleWorkerResult>(&result.job_id)?;
|
||||
let reorient = cache.get::<EpiphanyRuntimeReorientWorkerResult>(&result.job_id)?;
|
||||
if role.is_some() && reorient.is_some() {
|
||||
return Err(anyhow!(
|
||||
"runtime worker job has both role and reorientation terminal outcomes"
|
||||
));
|
||||
}
|
||||
if let Some(terminal_result_id) = role
|
||||
.map(|result| result.result_id)
|
||||
.or_else(|| reorient.map(|result| result.result_id))
|
||||
{
|
||||
if let Some(terminal_result_id) = structured_result_id {
|
||||
terminal.status = crate::WorkerProcessStatus::TerminalResult.as_str().into();
|
||||
terminal.terminal_authority_id = Some(terminal_result_id);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -24,8 +24,6 @@ use epiphany_openai_adapter::{
|
|||
use epiphany_openai_runtime::DEFAULT_CODEX_CONNECTOR_ENDPOINT;
|
||||
use epiphany_openai_runtime::DEFAULT_PROVIDER_REQUEST_TIMEOUT;
|
||||
use epiphany_openai_runtime::EpiphanyOpenAiRuntimeOptions;
|
||||
#[cfg(test)]
|
||||
use epiphany_openai_runtime::OPENAI_RUNTIME_ROLE;
|
||||
use epiphany_openai_runtime::append_requested_public_source_receipts;
|
||||
use epiphany_openai_runtime::assistant_text_from_model_events;
|
||||
use epiphany_openai_runtime::build_tool_followup_model_request;
|
||||
|
|
|
|||
|
|
@ -3262,7 +3262,8 @@ mod tests {
|
|||
runtime_job_snapshot(&store, &worker_job_id)?
|
||||
.expect("snapshot")
|
||||
.result
|
||||
.is_some()
|
||||
.is_none(),
|
||||
"structured worker decisions must not persist a generic result mirror"
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue