Move runtime result decoding into core
This commit is contained in:
parent
33d7991152
commit
e8b5f4a15f
5 changed files with 412 additions and 259 deletions
|
|
@ -7,285 +7,30 @@ use epiphany_core::EpiphanyReceiptEffectKind;
|
|||
use epiphany_core::EpiphanyReorientFindingInterpretation;
|
||||
use epiphany_core::EpiphanyRoleFindingInterpretation;
|
||||
use epiphany_core::EpiphanyRoleResultRoleId;
|
||||
use epiphany_core::EpiphanyRuntimeJobResult;
|
||||
use epiphany_core::EpiphanyRuntimeJobSnapshot;
|
||||
use epiphany_core::EpiphanyRuntimeJobStatus;
|
||||
use epiphany_core::MIND_GATEWAY_REVIEW_TYPE;
|
||||
use epiphany_core::interpret_runtime_reorient_worker_result;
|
||||
use epiphany_core::interpret_runtime_role_worker_result;
|
||||
use epiphany_core::runtime_job_snapshot;
|
||||
use epiphany_core::runtime_reorient_worker_result;
|
||||
use epiphany_core::runtime_role_worker_result;
|
||||
use epiphany_core::runtime_worker_launch_request;
|
||||
use epiphany_state_model::EpiphanyRuntimeLink;
|
||||
use epiphany_state_model::EpiphanyThreadState;
|
||||
|
||||
use crate::error::EpiphanyBridgeError;
|
||||
use crate::error::Result as BridgeResult;
|
||||
use crate::results::render_core_reorient_result_note;
|
||||
use crate::results::render_core_role_result_note;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct EpiphanyRoleResultSnapshot {
|
||||
pub status: CoreEpiphanyCoordinatorRoleResultStatus,
|
||||
pub finding: Option<EpiphanyRoleFindingInterpretation>,
|
||||
pub note: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct EpiphanyReorientResultSnapshot {
|
||||
pub status: CoreEpiphanyCrrcResultStatus,
|
||||
pub finding: Option<EpiphanyReorientFindingInterpretation>,
|
||||
pub note: String,
|
||||
}
|
||||
pub type EpiphanyRoleResultSnapshot = epiphany_core::EpiphanyCoordinatorRoleResultSnapshot;
|
||||
pub type EpiphanyReorientResultSnapshot = epiphany_core::EpiphanyCoordinatorReorientResultSnapshot;
|
||||
|
||||
pub fn load_core_epiphany_role_result_from_runtime_spine_job(
|
||||
job_id: &str,
|
||||
runtime_store_path: Option<&Path>,
|
||||
role_id: EpiphanyRoleResultRoleId,
|
||||
) -> EpiphanyRoleResultSnapshot {
|
||||
let Some(runtime_store_path) = runtime_store_path else {
|
||||
return EpiphanyRoleResultSnapshot {
|
||||
status: CoreEpiphanyCoordinatorRoleResultStatus::Pending,
|
||||
finding: None,
|
||||
note: "Heartbeat activation owns this role specialist; no loaded runtime-spine store is available yet."
|
||||
.to_string(),
|
||||
};
|
||||
};
|
||||
let snapshot = match runtime_job_snapshot(runtime_store_path, job_id) {
|
||||
Ok(Some(snapshot)) => snapshot,
|
||||
Ok(None) => {
|
||||
return EpiphanyRoleResultSnapshot {
|
||||
status: CoreEpiphanyCoordinatorRoleResultStatus::Pending,
|
||||
finding: None,
|
||||
note: format!(
|
||||
"Heartbeat runtime job {:?} has not reported typed state yet.",
|
||||
job_id
|
||||
),
|
||||
};
|
||||
}
|
||||
Err(err) => {
|
||||
return EpiphanyRoleResultSnapshot {
|
||||
status: CoreEpiphanyCoordinatorRoleResultStatus::BackendUnavailable,
|
||||
finding: None,
|
||||
note: format!(
|
||||
"Failed to read heartbeat runtime-spine job {:?}: {err}",
|
||||
job_id
|
||||
),
|
||||
};
|
||||
}
|
||||
};
|
||||
let status = map_runtime_role_result_status(&snapshot);
|
||||
let finding = match status {
|
||||
CoreEpiphanyCoordinatorRoleResultStatus::Completed => {
|
||||
match runtime_role_worker_result(runtime_store_path, job_id) {
|
||||
Ok(Some(result)) => Some(interpret_runtime_role_worker_result(role_id, &result)),
|
||||
Ok(None) => {
|
||||
return EpiphanyRoleResultSnapshot {
|
||||
status: CoreEpiphanyCoordinatorRoleResultStatus::BackendUnavailable,
|
||||
finding: None,
|
||||
note: format!(
|
||||
"Heartbeat runtime job {:?} completed without an EpiphanyRuntimeRoleWorkerResult typed document; generic lifecycle receipts are not reviewable findings.",
|
||||
job_id
|
||||
),
|
||||
};
|
||||
}
|
||||
Err(err) => {
|
||||
return EpiphanyRoleResultSnapshot {
|
||||
status: CoreEpiphanyCoordinatorRoleResultStatus::BackendUnavailable,
|
||||
finding: None,
|
||||
note: format!(
|
||||
"Failed to read typed role worker result for heartbeat runtime job {:?}: {err}",
|
||||
job_id
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
CoreEpiphanyCoordinatorRoleResultStatus::Failed
|
||||
| CoreEpiphanyCoordinatorRoleResultStatus::Cancelled => snapshot
|
||||
.result
|
||||
.as_ref()
|
||||
.map(interpret_runtime_role_lifecycle_failure),
|
||||
_ => None,
|
||||
};
|
||||
let item_error = finding
|
||||
.as_ref()
|
||||
.and_then(|finding| finding.job_error.as_deref());
|
||||
let note = render_core_role_result_note(role_id, status, finding.as_ref(), item_error);
|
||||
EpiphanyRoleResultSnapshot {
|
||||
status,
|
||||
finding,
|
||||
note,
|
||||
}
|
||||
epiphany_core::read_runtime_role_result(runtime_store_path, job_id, role_id)
|
||||
}
|
||||
|
||||
pub fn load_core_epiphany_reorient_result_from_runtime_spine_job(
|
||||
job_id: &str,
|
||||
runtime_store_path: Option<&Path>,
|
||||
) -> EpiphanyReorientResultSnapshot {
|
||||
let Some(runtime_store_path) = runtime_store_path else {
|
||||
return EpiphanyReorientResultSnapshot {
|
||||
status: CoreEpiphanyCrrcResultStatus::Pending,
|
||||
finding: None,
|
||||
note: "Heartbeat activation owns this reorientation worker; no loaded runtime-spine store is available yet."
|
||||
.to_string(),
|
||||
};
|
||||
};
|
||||
let snapshot = match runtime_job_snapshot(runtime_store_path, job_id) {
|
||||
Ok(Some(snapshot)) => snapshot,
|
||||
Ok(None) => {
|
||||
return EpiphanyReorientResultSnapshot {
|
||||
status: CoreEpiphanyCrrcResultStatus::Pending,
|
||||
finding: None,
|
||||
note: format!(
|
||||
"Heartbeat runtime job {:?} has not reported typed state yet.",
|
||||
job_id
|
||||
),
|
||||
};
|
||||
}
|
||||
Err(err) => {
|
||||
return EpiphanyReorientResultSnapshot {
|
||||
status: CoreEpiphanyCrrcResultStatus::BackendUnavailable,
|
||||
finding: None,
|
||||
note: format!(
|
||||
"Failed to read heartbeat runtime-spine job {:?}: {err}",
|
||||
job_id
|
||||
),
|
||||
};
|
||||
}
|
||||
};
|
||||
let status = map_runtime_reorient_result_status(&snapshot);
|
||||
let finding = match status {
|
||||
CoreEpiphanyCrrcResultStatus::Completed => {
|
||||
match runtime_reorient_worker_result(runtime_store_path, job_id) {
|
||||
Ok(Some(result)) => Some(interpret_runtime_reorient_worker_result(&result)),
|
||||
Ok(None) => {
|
||||
return EpiphanyReorientResultSnapshot {
|
||||
status: CoreEpiphanyCrrcResultStatus::BackendUnavailable,
|
||||
finding: None,
|
||||
note: format!(
|
||||
"Heartbeat runtime job {:?} completed without an EpiphanyRuntimeReorientWorkerResult typed document; generic lifecycle receipts are not reviewable findings.",
|
||||
job_id
|
||||
),
|
||||
};
|
||||
}
|
||||
Err(err) => {
|
||||
return EpiphanyReorientResultSnapshot {
|
||||
status: CoreEpiphanyCrrcResultStatus::BackendUnavailable,
|
||||
finding: None,
|
||||
note: format!(
|
||||
"Failed to read typed reorientation worker result for heartbeat runtime job {:?}: {err}",
|
||||
job_id
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
CoreEpiphanyCrrcResultStatus::Failed | CoreEpiphanyCrrcResultStatus::Cancelled => snapshot
|
||||
.result
|
||||
.as_ref()
|
||||
.map(interpret_runtime_reorient_lifecycle_failure),
|
||||
_ => None,
|
||||
};
|
||||
let item_error = finding
|
||||
.as_ref()
|
||||
.and_then(|finding| finding.job_error.as_deref());
|
||||
let note = render_core_reorient_result_note(status, finding.as_ref(), item_error);
|
||||
EpiphanyReorientResultSnapshot {
|
||||
status,
|
||||
finding,
|
||||
note,
|
||||
}
|
||||
}
|
||||
|
||||
fn interpret_runtime_role_lifecycle_failure(
|
||||
result: &EpiphanyRuntimeJobResult,
|
||||
) -> EpiphanyRoleFindingInterpretation {
|
||||
EpiphanyRoleFindingInterpretation {
|
||||
verdict: Some(result.verdict.clone()),
|
||||
summary: Some(result.summary.clone()),
|
||||
next_safe_move: empty_string_as_none(&result.next_safe_move),
|
||||
checkpoint_summary: None,
|
||||
scratch_summary: None,
|
||||
files_inspected: Vec::new(),
|
||||
frontier_node_ids: Vec::new(),
|
||||
evidence_ids: result.evidence_refs.clone(),
|
||||
artifact_refs: result.artifact_refs.clone(),
|
||||
runtime_result_id: Some(result.result_id.clone()),
|
||||
runtime_job_id: Some(result.job_id.clone()),
|
||||
open_questions: Vec::new(),
|
||||
evidence_gaps: Vec::new(),
|
||||
risks: Vec::new(),
|
||||
state_patch: None,
|
||||
self_patch: None,
|
||||
self_persistence: None,
|
||||
job_error: Some(result.summary.clone()),
|
||||
item_error: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn interpret_runtime_reorient_lifecycle_failure(
|
||||
result: &EpiphanyRuntimeJobResult,
|
||||
) -> EpiphanyReorientFindingInterpretation {
|
||||
EpiphanyReorientFindingInterpretation {
|
||||
mode: None,
|
||||
summary: Some(result.summary.clone()),
|
||||
next_safe_move: empty_string_as_none(&result.next_safe_move),
|
||||
checkpoint_still_valid: None,
|
||||
files_inspected: Vec::new(),
|
||||
frontier_node_ids: Vec::new(),
|
||||
evidence_ids: result.evidence_refs.clone(),
|
||||
artifact_refs: result.artifact_refs.clone(),
|
||||
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 empty_string_as_none(value: &str) -> Option<String> {
|
||||
(!value.trim().is_empty()).then(|| value.to_string())
|
||||
}
|
||||
|
||||
fn map_runtime_role_result_status(
|
||||
snapshot: &EpiphanyRuntimeJobSnapshot,
|
||||
) -> CoreEpiphanyCoordinatorRoleResultStatus {
|
||||
match snapshot.job.status {
|
||||
EpiphanyRuntimeJobStatus::Queued => CoreEpiphanyCoordinatorRoleResultStatus::Pending,
|
||||
EpiphanyRuntimeJobStatus::Running | EpiphanyRuntimeJobStatus::WaitingForReview => {
|
||||
CoreEpiphanyCoordinatorRoleResultStatus::Running
|
||||
}
|
||||
EpiphanyRuntimeJobStatus::Completed => {
|
||||
if snapshot.result.is_some() {
|
||||
CoreEpiphanyCoordinatorRoleResultStatus::Completed
|
||||
} else {
|
||||
CoreEpiphanyCoordinatorRoleResultStatus::Pending
|
||||
}
|
||||
}
|
||||
EpiphanyRuntimeJobStatus::Failed => CoreEpiphanyCoordinatorRoleResultStatus::Failed,
|
||||
EpiphanyRuntimeJobStatus::Cancelled => CoreEpiphanyCoordinatorRoleResultStatus::Cancelled,
|
||||
}
|
||||
}
|
||||
|
||||
fn map_runtime_reorient_result_status(
|
||||
snapshot: &EpiphanyRuntimeJobSnapshot,
|
||||
) -> CoreEpiphanyCrrcResultStatus {
|
||||
match snapshot.job.status {
|
||||
EpiphanyRuntimeJobStatus::Queued => CoreEpiphanyCrrcResultStatus::Pending,
|
||||
EpiphanyRuntimeJobStatus::Running | EpiphanyRuntimeJobStatus::WaitingForReview => {
|
||||
CoreEpiphanyCrrcResultStatus::Running
|
||||
}
|
||||
EpiphanyRuntimeJobStatus::Completed => {
|
||||
if snapshot.result.is_some() {
|
||||
CoreEpiphanyCrrcResultStatus::Completed
|
||||
} else {
|
||||
CoreEpiphanyCrrcResultStatus::Pending
|
||||
}
|
||||
}
|
||||
EpiphanyRuntimeJobStatus::Failed => CoreEpiphanyCrrcResultStatus::Failed,
|
||||
EpiphanyRuntimeJobStatus::Cancelled => CoreEpiphanyCrrcResultStatus::Cancelled,
|
||||
}
|
||||
epiphany_core::read_runtime_reorient_result(runtime_store_path, job_id)
|
||||
}
|
||||
|
||||
pub async fn load_core_epiphany_role_result_snapshot(
|
||||
|
|
|
|||
|
|
@ -1,8 +1,23 @@
|
|||
use crate::EpiphanyCoordinatorRoleResultStatus;
|
||||
use crate::EpiphanyCrrcResultStatus;
|
||||
use crate::EpiphanyReorientFindingInterpretation;
|
||||
use crate::EpiphanyRoleFindingInterpretation;
|
||||
use crate::EpiphanyRoleResultRoleId;
|
||||
use crate::EpiphanyRoleSelfPersistenceReview;
|
||||
use crate::EpiphanyRoleSelfPersistenceStatus;
|
||||
use crate::EpiphanyRuntimeJobResult;
|
||||
use crate::EpiphanyRuntimeJobSnapshot;
|
||||
use crate::EpiphanyRuntimeJobStatus;
|
||||
use crate::EpiphanyStateUpdate;
|
||||
use crate::EpiphanyStateUpdatedField;
|
||||
use crate::apply_epiphany_state_update;
|
||||
use crate::epiphany_state_update_validation_errors;
|
||||
use crate::interpret_runtime_reorient_worker_result;
|
||||
use crate::interpret_runtime_role_worker_result;
|
||||
use crate::load_thread_state;
|
||||
use crate::runtime_job_snapshot;
|
||||
use crate::runtime_reorient_worker_result;
|
||||
use crate::runtime_role_worker_result;
|
||||
use crate::write_thread_state;
|
||||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
|
|
@ -28,6 +43,20 @@ pub struct EpiphanyCoordinatorStateApplied {
|
|||
pub state: EpiphanyThreadState,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct EpiphanyCoordinatorRoleResultSnapshot {
|
||||
pub status: EpiphanyCoordinatorRoleResultStatus,
|
||||
pub finding: Option<EpiphanyRoleFindingInterpretation>,
|
||||
pub note: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct EpiphanyCoordinatorReorientResultSnapshot {
|
||||
pub status: EpiphanyCrrcResultStatus,
|
||||
pub finding: Option<EpiphanyReorientFindingInterpretation>,
|
||||
pub note: String,
|
||||
}
|
||||
|
||||
impl EpiphanyCoordinatorService {
|
||||
pub fn new(
|
||||
thread_state_store: impl Into<PathBuf>,
|
||||
|
|
@ -72,6 +101,372 @@ impl EpiphanyCoordinatorService {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn read_runtime_role_result(
|
||||
runtime_store_path: Option<&Path>,
|
||||
job_id: &str,
|
||||
role_id: EpiphanyRoleResultRoleId,
|
||||
) -> EpiphanyCoordinatorRoleResultSnapshot {
|
||||
let Some(runtime_store_path) = runtime_store_path else {
|
||||
return role_snapshot(
|
||||
role_id,
|
||||
EpiphanyCoordinatorRoleResultStatus::Pending,
|
||||
None,
|
||||
Some(
|
||||
"Heartbeat activation owns this role specialist; no loaded runtime-spine store is available yet.",
|
||||
),
|
||||
);
|
||||
};
|
||||
let snapshot = match runtime_job_snapshot(runtime_store_path, job_id) {
|
||||
Ok(Some(snapshot)) => snapshot,
|
||||
Ok(None) => {
|
||||
return role_snapshot(
|
||||
role_id,
|
||||
EpiphanyCoordinatorRoleResultStatus::Pending,
|
||||
None,
|
||||
Some(&format!(
|
||||
"Heartbeat runtime job {job_id:?} has not reported typed state yet."
|
||||
)),
|
||||
);
|
||||
}
|
||||
Err(error) => {
|
||||
return role_snapshot(
|
||||
role_id,
|
||||
EpiphanyCoordinatorRoleResultStatus::BackendUnavailable,
|
||||
None,
|
||||
Some(&format!(
|
||||
"Failed to read heartbeat runtime-spine job {job_id:?}: {error}"
|
||||
)),
|
||||
);
|
||||
}
|
||||
};
|
||||
let status = role_result_status(&snapshot);
|
||||
let finding = match status {
|
||||
EpiphanyCoordinatorRoleResultStatus::Completed => {
|
||||
match runtime_role_worker_result(runtime_store_path, job_id) {
|
||||
Ok(Some(result)) => Some(interpret_runtime_role_worker_result(role_id, &result)),
|
||||
Ok(None) => {
|
||||
return role_snapshot(
|
||||
role_id,
|
||||
EpiphanyCoordinatorRoleResultStatus::BackendUnavailable,
|
||||
None,
|
||||
Some(&format!(
|
||||
"Heartbeat runtime job {job_id:?} completed without an EpiphanyRuntimeRoleWorkerResult typed document; generic lifecycle receipts are not reviewable findings."
|
||||
)),
|
||||
);
|
||||
}
|
||||
Err(error) => {
|
||||
return role_snapshot(
|
||||
role_id,
|
||||
EpiphanyCoordinatorRoleResultStatus::BackendUnavailable,
|
||||
None,
|
||||
Some(&format!(
|
||||
"Failed to read typed role worker result for heartbeat runtime job {job_id:?}: {error}"
|
||||
)),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
EpiphanyCoordinatorRoleResultStatus::Failed
|
||||
| EpiphanyCoordinatorRoleResultStatus::Cancelled => snapshot
|
||||
.result
|
||||
.as_ref()
|
||||
.map(interpret_role_lifecycle_failure),
|
||||
_ => None,
|
||||
};
|
||||
role_snapshot(role_id, status, finding, None)
|
||||
}
|
||||
|
||||
pub fn read_runtime_reorient_result(
|
||||
runtime_store_path: Option<&Path>,
|
||||
job_id: &str,
|
||||
) -> EpiphanyCoordinatorReorientResultSnapshot {
|
||||
let Some(runtime_store_path) = runtime_store_path else {
|
||||
return reorient_snapshot(
|
||||
EpiphanyCrrcResultStatus::Pending,
|
||||
None,
|
||||
Some(
|
||||
"Heartbeat activation owns this reorientation worker; no loaded runtime-spine store is available yet.",
|
||||
),
|
||||
);
|
||||
};
|
||||
let snapshot = match runtime_job_snapshot(runtime_store_path, job_id) {
|
||||
Ok(Some(snapshot)) => snapshot,
|
||||
Ok(None) => {
|
||||
return reorient_snapshot(
|
||||
EpiphanyCrrcResultStatus::Pending,
|
||||
None,
|
||||
Some(&format!(
|
||||
"Heartbeat runtime job {job_id:?} has not reported typed state yet."
|
||||
)),
|
||||
);
|
||||
}
|
||||
Err(error) => {
|
||||
return reorient_snapshot(
|
||||
EpiphanyCrrcResultStatus::BackendUnavailable,
|
||||
None,
|
||||
Some(&format!(
|
||||
"Failed to read heartbeat runtime-spine job {job_id:?}: {error}"
|
||||
)),
|
||||
);
|
||||
}
|
||||
};
|
||||
let status = reorient_result_status(&snapshot);
|
||||
let finding = match status {
|
||||
EpiphanyCrrcResultStatus::Completed => {
|
||||
match runtime_reorient_worker_result(runtime_store_path, job_id) {
|
||||
Ok(Some(result)) => Some(interpret_runtime_reorient_worker_result(&result)),
|
||||
Ok(None) => {
|
||||
return reorient_snapshot(
|
||||
EpiphanyCrrcResultStatus::BackendUnavailable,
|
||||
None,
|
||||
Some(&format!(
|
||||
"Heartbeat runtime job {job_id:?} completed without an EpiphanyRuntimeReorientWorkerResult typed document; generic lifecycle receipts are not reviewable findings."
|
||||
)),
|
||||
);
|
||||
}
|
||||
Err(error) => {
|
||||
return reorient_snapshot(
|
||||
EpiphanyCrrcResultStatus::BackendUnavailable,
|
||||
None,
|
||||
Some(&format!(
|
||||
"Failed to read typed reorientation worker result for heartbeat runtime job {job_id:?}: {error}"
|
||||
)),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
EpiphanyCrrcResultStatus::Failed | EpiphanyCrrcResultStatus::Cancelled => snapshot
|
||||
.result
|
||||
.as_ref()
|
||||
.map(interpret_reorient_lifecycle_failure),
|
||||
_ => None,
|
||||
};
|
||||
reorient_snapshot(status, finding, None)
|
||||
}
|
||||
|
||||
fn role_snapshot(
|
||||
role_id: EpiphanyRoleResultRoleId,
|
||||
status: EpiphanyCoordinatorRoleResultStatus,
|
||||
finding: Option<EpiphanyRoleFindingInterpretation>,
|
||||
note_override: Option<&str>,
|
||||
) -> EpiphanyCoordinatorRoleResultSnapshot {
|
||||
let note = note_override.map(str::to_string).unwrap_or_else(|| {
|
||||
render_role_result_note(
|
||||
role_id,
|
||||
status,
|
||||
finding.as_ref(),
|
||||
finding
|
||||
.as_ref()
|
||||
.and_then(|finding| finding.job_error.as_deref()),
|
||||
)
|
||||
});
|
||||
EpiphanyCoordinatorRoleResultSnapshot {
|
||||
status,
|
||||
finding,
|
||||
note,
|
||||
}
|
||||
}
|
||||
|
||||
fn reorient_snapshot(
|
||||
status: EpiphanyCrrcResultStatus,
|
||||
finding: Option<EpiphanyReorientFindingInterpretation>,
|
||||
note_override: Option<&str>,
|
||||
) -> EpiphanyCoordinatorReorientResultSnapshot {
|
||||
let note = note_override.map(str::to_string).unwrap_or_else(|| {
|
||||
render_reorient_result_note(
|
||||
status,
|
||||
finding.as_ref(),
|
||||
finding
|
||||
.as_ref()
|
||||
.and_then(|finding| finding.job_error.as_deref()),
|
||||
)
|
||||
});
|
||||
EpiphanyCoordinatorReorientResultSnapshot {
|
||||
status,
|
||||
finding,
|
||||
note,
|
||||
}
|
||||
}
|
||||
|
||||
fn interpret_role_lifecycle_failure(
|
||||
result: &EpiphanyRuntimeJobResult,
|
||||
) -> EpiphanyRoleFindingInterpretation {
|
||||
EpiphanyRoleFindingInterpretation {
|
||||
verdict: Some(result.verdict.clone()),
|
||||
summary: Some(result.summary.clone()),
|
||||
next_safe_move: nonempty(&result.next_safe_move),
|
||||
checkpoint_summary: None,
|
||||
scratch_summary: None,
|
||||
files_inspected: Vec::new(),
|
||||
frontier_node_ids: Vec::new(),
|
||||
evidence_ids: result.evidence_refs.clone(),
|
||||
artifact_refs: result.artifact_refs.clone(),
|
||||
runtime_result_id: Some(result.result_id.clone()),
|
||||
runtime_job_id: Some(result.job_id.clone()),
|
||||
open_questions: Vec::new(),
|
||||
evidence_gaps: Vec::new(),
|
||||
risks: Vec::new(),
|
||||
state_patch: None,
|
||||
self_patch: None,
|
||||
self_persistence: None,
|
||||
job_error: Some(result.summary.clone()),
|
||||
item_error: None,
|
||||
}
|
||||
}
|
||||
|
||||
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: result.evidence_refs.clone(),
|
||||
artifact_refs: result.artifact_refs.clone(),
|
||||
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 role_result_status(
|
||||
snapshot: &EpiphanyRuntimeJobSnapshot,
|
||||
) -> EpiphanyCoordinatorRoleResultStatus {
|
||||
match snapshot.job.status {
|
||||
EpiphanyRuntimeJobStatus::Queued => EpiphanyCoordinatorRoleResultStatus::Pending,
|
||||
EpiphanyRuntimeJobStatus::Running | EpiphanyRuntimeJobStatus::WaitingForReview => {
|
||||
EpiphanyCoordinatorRoleResultStatus::Running
|
||||
}
|
||||
EpiphanyRuntimeJobStatus::Completed if snapshot.result.is_some() => {
|
||||
EpiphanyCoordinatorRoleResultStatus::Completed
|
||||
}
|
||||
EpiphanyRuntimeJobStatus::Completed => EpiphanyCoordinatorRoleResultStatus::Pending,
|
||||
EpiphanyRuntimeJobStatus::Failed => EpiphanyCoordinatorRoleResultStatus::Failed,
|
||||
EpiphanyRuntimeJobStatus::Cancelled => EpiphanyCoordinatorRoleResultStatus::Cancelled,
|
||||
}
|
||||
}
|
||||
|
||||
fn reorient_result_status(snapshot: &EpiphanyRuntimeJobSnapshot) -> EpiphanyCrrcResultStatus {
|
||||
match snapshot.job.status {
|
||||
EpiphanyRuntimeJobStatus::Queued => EpiphanyCrrcResultStatus::Pending,
|
||||
EpiphanyRuntimeJobStatus::Running | EpiphanyRuntimeJobStatus::WaitingForReview => {
|
||||
EpiphanyCrrcResultStatus::Running
|
||||
}
|
||||
EpiphanyRuntimeJobStatus::Completed if snapshot.result.is_some() => {
|
||||
EpiphanyCrrcResultStatus::Completed
|
||||
}
|
||||
EpiphanyRuntimeJobStatus::Completed => EpiphanyCrrcResultStatus::Pending,
|
||||
EpiphanyRuntimeJobStatus::Failed => EpiphanyCrrcResultStatus::Failed,
|
||||
EpiphanyRuntimeJobStatus::Cancelled => EpiphanyCrrcResultStatus::Cancelled,
|
||||
}
|
||||
}
|
||||
|
||||
fn render_role_result_note(
|
||||
role_id: EpiphanyRoleResultRoleId,
|
||||
status: EpiphanyCoordinatorRoleResultStatus,
|
||||
finding: Option<&EpiphanyRoleFindingInterpretation>,
|
||||
item_error: Option<&str>,
|
||||
) -> String {
|
||||
match status {
|
||||
EpiphanyCoordinatorRoleResultStatus::Completed => finding.map_or_else(
|
||||
|| format!("{role_id:?} role specialist completed, but no structured result was recorded."),
|
||||
|finding| {
|
||||
let next = finding.next_safe_move.as_deref().unwrap_or("not supplied");
|
||||
let self_note = render_self_persistence_note(finding.self_persistence.as_ref())
|
||||
.map(|note| format!(" {note}"))
|
||||
.unwrap_or_default();
|
||||
if let Some(error) = finding.item_error.as_deref().or(item_error) {
|
||||
format!("{role_id:?} role specialist completed, but the finding needs repair: {error}. Next safe move: {next}.{self_note}")
|
||||
} else {
|
||||
format!("{role_id:?} role specialist completed. Next safe move: {next}.{self_note}")
|
||||
}
|
||||
},
|
||||
),
|
||||
EpiphanyCoordinatorRoleResultStatus::Failed => item_error
|
||||
.map(|error| format!("{role_id:?} role specialist failed: {error}"))
|
||||
.unwrap_or_else(|| format!("{role_id:?} role specialist failed.")),
|
||||
EpiphanyCoordinatorRoleResultStatus::Cancelled => format!("{role_id:?} role specialist was cancelled before producing a result."),
|
||||
EpiphanyCoordinatorRoleResultStatus::Running => format!("{role_id:?} role specialist is still running."),
|
||||
EpiphanyCoordinatorRoleResultStatus::Pending => format!("{role_id:?} role specialist has not produced a result yet."),
|
||||
EpiphanyCoordinatorRoleResultStatus::MissingState => "No authoritative Epiphany state exists for this thread.".to_string(),
|
||||
EpiphanyCoordinatorRoleResultStatus::MissingBinding => "No matching Epiphany role specialist binding exists.".to_string(),
|
||||
EpiphanyCoordinatorRoleResultStatus::BackendUnavailable => "The bound runtime backend is unavailable.".to_string(),
|
||||
EpiphanyCoordinatorRoleResultStatus::BackendMissing => "The bound runtime backend job or item is missing.".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
fn render_self_persistence_note(
|
||||
review: Option<&EpiphanyRoleSelfPersistenceReview>,
|
||||
) -> Option<String> {
|
||||
let review = review?;
|
||||
match review.status {
|
||||
EpiphanyRoleSelfPersistenceStatus::Missing => None,
|
||||
EpiphanyRoleSelfPersistenceStatus::Accepted => Some(format!(
|
||||
"Self persistence request is acceptable for {}.",
|
||||
review
|
||||
.target_agent_id
|
||||
.as_deref()
|
||||
.unwrap_or("the role memory file")
|
||||
)),
|
||||
EpiphanyRoleSelfPersistenceStatus::Rejected => Some(format!(
|
||||
"Self persistence request was refused: {}.",
|
||||
if review.reasons.is_empty() {
|
||||
"no reason recorded".to_string()
|
||||
} else {
|
||||
review.reasons.join("; ")
|
||||
}
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
fn render_reorient_result_note(
|
||||
status: EpiphanyCrrcResultStatus,
|
||||
finding: Option<&EpiphanyReorientFindingInterpretation>,
|
||||
item_error: Option<&str>,
|
||||
) -> String {
|
||||
match status {
|
||||
EpiphanyCrrcResultStatus::Completed => finding.map_or_else(
|
||||
|| "Reorientation worker completed, but no structured result was recorded.".to_string(),
|
||||
|finding| {
|
||||
format!(
|
||||
"Reorientation worker completed. Next safe move: {}",
|
||||
finding.next_safe_move.as_deref().unwrap_or("not supplied")
|
||||
)
|
||||
},
|
||||
),
|
||||
EpiphanyCrrcResultStatus::Failed => item_error
|
||||
.map(|error| format!("Reorientation worker failed: {error}"))
|
||||
.unwrap_or_else(|| "Reorientation worker failed.".to_string()),
|
||||
EpiphanyCrrcResultStatus::Cancelled => {
|
||||
"Reorientation worker was cancelled before producing a result.".to_string()
|
||||
}
|
||||
EpiphanyCrrcResultStatus::Running => "Reorientation worker is still running.".to_string(),
|
||||
EpiphanyCrrcResultStatus::Pending => {
|
||||
"Reorientation worker has not produced a result yet.".to_string()
|
||||
}
|
||||
EpiphanyCrrcResultStatus::MissingState => {
|
||||
"No authoritative Epiphany state exists for this thread.".to_string()
|
||||
}
|
||||
EpiphanyCrrcResultStatus::MissingBinding => {
|
||||
"No matching Epiphany reorientation worker binding exists.".to_string()
|
||||
}
|
||||
EpiphanyCrrcResultStatus::BackendUnavailable => {
|
||||
"The bound runtime backend is unavailable.".to_string()
|
||||
}
|
||||
EpiphanyCrrcResultStatus::BackendMissing => {
|
||||
"The bound runtime backend job or item is missing.".to_string()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn nonempty(value: &str) -> Option<String> {
|
||||
(!value.trim().is_empty()).then(|| value.to_string())
|
||||
}
|
||||
|
||||
pub fn apply_coordinator_state_update_to_state(
|
||||
current_state: &EpiphanyThreadState,
|
||||
update: EpiphanyStateUpdate,
|
||||
|
|
|
|||
|
|
@ -119,9 +119,13 @@ pub use agent_utterance_state::AgentUtteranceValue;
|
|||
pub use agent_utterance_state::WEKSA_UTTERANCE_HANDOFF_SCHEMA_VERSION;
|
||||
pub use agent_utterance_state::derive_agent_utterance_state;
|
||||
pub use continuity_gateway::*;
|
||||
pub use coordinator_service::EpiphanyCoordinatorReorientResultSnapshot;
|
||||
pub use coordinator_service::EpiphanyCoordinatorRoleResultSnapshot;
|
||||
pub use coordinator_service::EpiphanyCoordinatorService;
|
||||
pub use coordinator_service::EpiphanyCoordinatorStateApplied;
|
||||
pub use coordinator_service::apply_coordinator_state_update_to_state;
|
||||
pub use coordinator_service::read_runtime_reorient_result;
|
||||
pub use coordinator_service::read_runtime_role_result;
|
||||
pub use cultcache_rs::CacheBackingStore;
|
||||
pub use cultcache_rs::CultCache;
|
||||
pub use cultcache_rs::CultCacheEnvelope;
|
||||
|
|
|
|||
|
|
@ -651,6 +651,15 @@ binary still use the compatibility nervous system. Move those authorities next
|
|||
and do not call the service complete while `AppServerClient` remains in the
|
||||
coordinator.
|
||||
|
||||
Second native cut moves runtime result decoding into the same core service:
|
||||
role and reorientation lifecycle status, typed worker-result loading, failed or
|
||||
cancelled finding projection, and operator note rendering no longer belong to
|
||||
`epiphany-codex-bridge::runtime_results`. The bridge retains compatibility type
|
||||
aliases and delegates job readback to core. Native coordinator tests and all
|
||||
eight bridge library tests pass, including typed-result enforcement and failed
|
||||
lifecycle projection. Binding selection and acceptance choreography still live
|
||||
in the bridge and remain the next extraction seam.
|
||||
|
||||
Bridge identity correction from 2026-06-22: Epiphany owns swarm execution,
|
||||
repo Body work, branch-local lanes, memory, evidence, and Persona cognition.
|
||||
Bifrost owns GameCult identity, governed crossings into GitHub/Discord/Reddit
|
||||
|
|
|
|||
Binary file not shown.
Reference in a new issue