Extract Epiphany runtime result adapters

This commit is contained in:
Meta Vens 2026-05-13 01:46:38 +01:00
commit c68abb2efa
6 changed files with 266 additions and 246 deletions

View file

@ -446,13 +446,16 @@ mutation support helpers for completed-result loading, accept patch rendering,
patch validation, and changed-field derivation into
`vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_mutation_routes.rs`,
taking the processor to about 15,819 lines.
The fourteenth cut moved runtime-spine result snapshot/adaptation helpers into
`vendor/codex/codex-rs/app-server/src/codex_message_processor/epiphany_runtime_results.rs`,
taking the processor to about 15,587 lines.
Also: MCP itself is allowed to be JSON. The target is not "replace MCP JSON";
the target is an Epiphany-owned boundary that speaks typed Epiphany
intent/result/receipt documents internally and normal MCP JSON-RPC externally.
Continue with the actual whale-carcass cut: move coordinator automation,
result snapshot plumbing, and remaining runtime authority out of
pre-compaction intervention orchestration, and remaining runtime authority out of
`codex_message_processor.rs` into Epiphany-owned app-server modules, moving
logic further into `epiphany-core` whenever it owns real policy. Success is a
visibly smaller `codex_message_processor.rs`, not merely nicer payload names. Do

View file

@ -62,6 +62,6 @@ Rule: JSON is allowed at external schema/wire boundaries. Inside Epiphany, live
3. Done: replace role `statePatch` JSON with typed map/planning/graph patch documents. `EpiphanyRoleFindingInterpretation` now carries `EpiphanyRoleStatePatchDocument`; app-server maps it to the legacy protocol patch without JSON round-tripping.
4. Done: replace runtime job result JSON projections. Runtime-spine results now project through typed role/reorient interpreters instead of `runtime_job_result_to_role_json` and `runtime_job_result_to_reorient_json`.
5. Done: replace app-server launch protocol `input_json` / `output_schema_json` with typed launch documents and `output_contract_id`.
6. Continue the whale-carcass cut: the first cuts moved Epiphany launch doctrine and protocol-to-core launch document mapping into `epiphany_launch.rs`, role/reorient result projection into `epiphany_results.rs`, scene projection into `epiphany_scene.rs`, freshness/reorientation mapping into `epiphany_reorient.rs`, context/planning/graph-query projection into `epiphany_context.rs`, jobs projection into `epiphany_jobs.rs`, retrieve projection into `epiphany_retrieve.rs`, pressure/pre-compaction checkpoint projection into `epiphany_pressure.rs`, CRRC/coordinator/role-board projection plus acceptance/evidence signal helpers into `epiphany_coordinator.rs`, Epiphany JSON-RPC route handling under `codex_message_processor/` split into read/proposal routes and mutation/launch/accept/index routes, and mutation support helpers into `epiphany_mutation_routes.rs`, reducing `codex_message_processor.rs` from about 21,263 to 15,819 lines. Next move coordinator automation/result snapshot plumbing and remaining runtime authority out of the processor; success means the processor keeps shrinking and ownership gets clearer, not merely better typed.
6. Continue the whale-carcass cut: the first cuts moved Epiphany launch doctrine and protocol-to-core launch document mapping into `epiphany_launch.rs`, role/reorient result projection into `epiphany_results.rs`, scene projection into `epiphany_scene.rs`, freshness/reorientation mapping into `epiphany_reorient.rs`, context/planning/graph-query projection into `epiphany_context.rs`, jobs projection into `epiphany_jobs.rs`, retrieve projection into `epiphany_retrieve.rs`, pressure/pre-compaction checkpoint projection into `epiphany_pressure.rs`, CRRC/coordinator/role-board projection plus acceptance/evidence signal helpers into `epiphany_coordinator.rs`, Epiphany JSON-RPC route handling under `codex_message_processor/` split into read/proposal routes and mutation/launch/accept/index routes, mutation support helpers into `epiphany_mutation_routes.rs`, and runtime-spine result snapshot/adaptation helpers into `epiphany_runtime_results.rs`, reducing `codex_message_processor.rs` from about 21,263 to 15,587 lines. Next move coordinator automation and pre-compaction intervention orchestration out of the processor; success means the processor keeps shrinking and ownership gets clearer, not merely better typed.
7. Seal MCP payloads behind an Epiphany boundary that speaks typed Epiphany documents internally and MCP JSON externally.
8. Audit heartbeat cognition values and either type them or explicitly expire them.

Binary file not shown.

View file

@ -278,5 +278,5 @@ rejected_paths:
reason: making Epiphany cleaner inside Codex still preserves the wrong organ; Codex must be starved down to OpenAI subscription auth/model transport, while Epiphany data and subsystem communication move to typed CultCache/CultNet.
current_status:
summary: The Codex starvation pass has five typing receipts plus thirteen real ownership cuts: Epiphany launch doctrine/prompt/builders and protocol-to-core launch document mapping moved into `vendor/codex/codex-rs/app-server/src/epiphany_launch.rs`, role/reorient result projection/note rendering moved into `vendor/codex/codex-rs/app-server/src/epiphany_results.rs`, scene projection moved into `vendor/codex/codex-rs/app-server/src/epiphany_scene.rs`, freshness/reorientation input mapping moved into `vendor/codex/codex-rs/app-server/src/epiphany_reorient.rs`, context/planning/graph-query projection moved into `vendor/codex/codex-rs/app-server/src/epiphany_context.rs`, jobs projection moved into `vendor/codex/codex-rs/app-server/src/epiphany_jobs.rs`, retrieve projection moved into `vendor/codex/codex-rs/app-server/src/epiphany_retrieve.rs`, pressure/pre-compaction checkpoint projection moved into `vendor/codex/codex-rs/app-server/src/epiphany_pressure.rs`, CRRC/coordinator/role-board projection plus acceptance/evidence signal helpers moved into `vendor/codex/codex-rs/app-server/src/epiphany_coordinator.rs`, the Epiphany JSON-RPC route-handler cluster moved under `vendor/codex/codex-rs/app-server/src/codex_message_processor/`, that cluster split into read/proposal routes versus mutation/launch/accept/index routes, and mutation support helpers for completed-result loading, accept patch rendering, patch validation, and changed-field derivation moved into `epiphany_mutation_routes.rs`. The processor is down from about 21,263 lines to 15,819 lines. This is progress, not absolution: the route modules still have parent-internal visibility and mutation authority still lives in the Codex adapter layer. MCP itself is correctly JSON at its protocol edge; the target is typed Epiphany intent/result/receipt wrappers around MCP, not replacing MCP JSON.
next_action: Continue the actual whale-carcass cut: move coordinator automation/result snapshot plumbing and remaining runtime authority out of `codex_message_processor.rs`, then replace route-module parent visibility with explicit typed service boundaries. Success metric remains a visibly smaller processor and clearer ownership, not merely typed payloads.
summary: The Codex starvation pass has five typing receipts plus fourteen real ownership cuts: Epiphany launch doctrine/prompt/builders and protocol-to-core launch document mapping moved into `vendor/codex/codex-rs/app-server/src/epiphany_launch.rs`, role/reorient result projection/note rendering moved into `vendor/codex/codex-rs/app-server/src/epiphany_results.rs`, scene projection moved into `vendor/codex/codex-rs/app-server/src/epiphany_scene.rs`, freshness/reorientation input mapping moved into `vendor/codex/codex-rs/app-server/src/epiphany_reorient.rs`, context/planning/graph-query projection moved into `vendor/codex/codex-rs/app-server/src/epiphany_context.rs`, jobs projection moved into `vendor/codex/codex-rs/app-server/src/epiphany_jobs.rs`, retrieve projection moved into `vendor/codex/codex-rs/app-server/src/epiphany_retrieve.rs`, pressure/pre-compaction checkpoint projection moved into `vendor/codex/codex-rs/app-server/src/epiphany_pressure.rs`, CRRC/coordinator/role-board projection plus acceptance/evidence signal helpers moved into `vendor/codex/codex-rs/app-server/src/epiphany_coordinator.rs`, the Epiphany JSON-RPC route-handler cluster moved under `vendor/codex/codex-rs/app-server/src/codex_message_processor/`, that cluster split into read/proposal routes versus mutation/launch/accept/index routes, mutation support helpers moved into `epiphany_mutation_routes.rs`, and runtime-spine result snapshot/adaptation helpers moved into `epiphany_runtime_results.rs`. The processor is down from about 21,263 lines to 15,587 lines. This is progress, not absolution: the route modules still have parent-internal visibility and mutation authority still lives in the Codex adapter layer. MCP itself is correctly JSON at its protocol edge; the target is typed Epiphany intent/result/receipt wrappers around MCP, not replacing MCP JSON.
next_action: Continue the actual whale-carcass cut: move coordinator automation and pre-compaction intervention orchestration out of `codex_message_processor.rs`, then replace route-module parent visibility with explicit typed service boundaries. Success metric remains a visibly smaller processor and clearer ownership, not merely typed payloads.

View file

@ -1,5 +1,6 @@
mod epiphany_mutation_routes;
mod epiphany_read_routes;
mod epiphany_runtime_results;
use self::epiphany_mutation_routes::epiphany_job_launch_changed_fields;
use self::epiphany_mutation_routes::epiphany_promote_changed_fields;
@ -10,6 +11,15 @@ use self::epiphany_mutation_routes::reorient_finding_code_refs;
use self::epiphany_mutation_routes::reorient_finding_investigation_checkpoint;
use self::epiphany_mutation_routes::reorient_finding_scratch;
use self::epiphany_mutation_routes::role_finding_summary;
use self::epiphany_runtime_results::latest_epiphany_runtime_link_for_binding;
use self::epiphany_runtime_results::load_epiphany_reorient_result_from_runtime_spine_job;
use self::epiphany_runtime_results::load_epiphany_reorient_result_snapshot;
use self::epiphany_runtime_results::load_epiphany_role_result_from_runtime_spine_job;
use self::epiphany_runtime_results::load_epiphany_role_result_snapshot;
use self::epiphany_runtime_results::reorient_finding_runtime_job_id;
use self::epiphany_runtime_results::reorient_finding_runtime_result_id;
use self::epiphany_runtime_results::role_finding_runtime_job_id;
use self::epiphany_runtime_results::role_finding_runtime_result_id;
use crate::bespoke_event_handling::apply_bespoke_event_handling;
use crate::bespoke_event_handling::maybe_emit_hook_prompt_item_completed;
use crate::command_exec::CommandExecManager;
@ -10250,248 +10260,6 @@ fn epiphany_imagination_finding_has_reviewable_state_patch(
.is_some_and(|patch| imagination_role_accept_patch_errors(patch).is_empty())
}
fn role_finding_runtime_result_id(finding: &ThreadEpiphanyRoleFinding) -> Option<String> {
finding.runtime_result_id.clone()
}
fn role_finding_runtime_job_id(finding: &ThreadEpiphanyRoleFinding) -> Option<String> {
finding.runtime_job_id.clone()
}
fn reorient_finding_runtime_result_id(finding: &ThreadEpiphanyReorientFinding) -> Option<String> {
finding.runtime_result_id.clone()
}
fn reorient_finding_runtime_job_id(finding: &ThreadEpiphanyReorientFinding) -> Option<String> {
finding.runtime_job_id.clone()
}
fn load_epiphany_role_result_from_runtime_spine_job(
job_id: &str,
runtime_store_path: Option<&Path>,
role_id: ThreadEpiphanyRoleId,
) -> (
ThreadEpiphanyRoleResultStatus,
Option<ThreadEpiphanyRoleFinding>,
String,
) {
let Some(runtime_store_path) = runtime_store_path else {
return (
ThreadEpiphanyRoleResultStatus::Pending,
None,
"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 (
ThreadEpiphanyRoleResultStatus::Pending,
None,
format!(
"Heartbeat runtime job {:?} has not reported typed state yet.",
job_id
),
);
}
Err(err) => {
return (
ThreadEpiphanyRoleResultStatus::BackendUnavailable,
None,
format!(
"Failed to read heartbeat runtime-spine job {:?}: {err}",
job_id
),
);
}
};
let status = map_runtime_role_result_status(&snapshot);
let finding = snapshot.result.as_ref().map(|result| {
map_protocol_role_finding(
role_id,
interpret_role_runtime_job_result(map_core_role_result_role_id(role_id), result),
)
});
let note = render_epiphany_role_result_note(role_id, status, finding.as_ref(), None);
(status, finding, note)
}
fn load_epiphany_reorient_result_from_runtime_spine_job(
job_id: &str,
runtime_store_path: Option<&Path>,
) -> (
ThreadEpiphanyReorientResultStatus,
Option<ThreadEpiphanyReorientFinding>,
String,
) {
let Some(runtime_store_path) = runtime_store_path else {
return (
ThreadEpiphanyReorientResultStatus::Pending,
None,
"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 (
ThreadEpiphanyReorientResultStatus::Pending,
None,
format!(
"Heartbeat runtime job {:?} has not reported typed state yet.",
job_id
),
);
}
Err(err) => {
return (
ThreadEpiphanyReorientResultStatus::BackendUnavailable,
None,
format!(
"Failed to read heartbeat runtime-spine job {:?}: {err}",
job_id
),
);
}
};
let status = map_runtime_reorient_result_status(&snapshot);
let finding = snapshot
.result
.as_ref()
.map(|result| map_protocol_reorient_finding(interpret_reorient_runtime_job_result(result)));
let note = render_epiphany_reorient_result_note(status, finding.as_ref(), None);
(status, finding, note)
}
fn map_runtime_role_result_status(
snapshot: &EpiphanyRuntimeJobSnapshot,
) -> ThreadEpiphanyRoleResultStatus {
match snapshot.job.status {
EpiphanyRuntimeJobStatus::Queued => ThreadEpiphanyRoleResultStatus::Pending,
EpiphanyRuntimeJobStatus::Running | EpiphanyRuntimeJobStatus::WaitingForReview => {
ThreadEpiphanyRoleResultStatus::Running
}
EpiphanyRuntimeJobStatus::Completed => {
if snapshot.result.is_some() {
ThreadEpiphanyRoleResultStatus::Completed
} else {
ThreadEpiphanyRoleResultStatus::Pending
}
}
EpiphanyRuntimeJobStatus::Failed => ThreadEpiphanyRoleResultStatus::Failed,
EpiphanyRuntimeJobStatus::Cancelled => ThreadEpiphanyRoleResultStatus::Cancelled,
}
}
fn map_runtime_reorient_result_status(
snapshot: &EpiphanyRuntimeJobSnapshot,
) -> ThreadEpiphanyReorientResultStatus {
match snapshot.job.status {
EpiphanyRuntimeJobStatus::Queued => ThreadEpiphanyReorientResultStatus::Pending,
EpiphanyRuntimeJobStatus::Running | EpiphanyRuntimeJobStatus::WaitingForReview => {
ThreadEpiphanyReorientResultStatus::Running
}
EpiphanyRuntimeJobStatus::Completed => {
if snapshot.result.is_some() {
ThreadEpiphanyReorientResultStatus::Completed
} else {
ThreadEpiphanyReorientResultStatus::Pending
}
}
EpiphanyRuntimeJobStatus::Failed => ThreadEpiphanyReorientResultStatus::Failed,
EpiphanyRuntimeJobStatus::Cancelled => ThreadEpiphanyReorientResultStatus::Cancelled,
}
}
async fn load_epiphany_role_result_snapshot(
state: &EpiphanyThreadState,
runtime_store_path: Option<&Path>,
role_id: ThreadEpiphanyRoleId,
binding_id: &str,
) -> (
ThreadEpiphanyRoleResultStatus,
Option<ThreadEpiphanyRoleFinding>,
String,
) {
if let Some(link) = latest_epiphany_runtime_link_for_binding(state, binding_id) {
return load_epiphany_role_result_from_runtime_spine_job(
link.runtime_job_id.as_str(),
runtime_store_path,
role_id,
);
}
if !state
.job_bindings
.iter()
.any(|binding| binding.id == binding_id)
{
return (
ThreadEpiphanyRoleResultStatus::MissingBinding,
None,
"No matching Epiphany role specialist binding exists.".to_string(),
);
}
(
ThreadEpiphanyRoleResultStatus::BackendUnavailable,
None,
"Role binding has no runtime-spine job id; launch a runtime-linked role worker for typed results.".to_string(),
)
}
async fn load_epiphany_reorient_result_snapshot(
state: Option<&EpiphanyThreadState>,
runtime_store_path: Option<&Path>,
binding_id: &str,
) -> (
ThreadEpiphanyReorientResultStatus,
Option<ThreadEpiphanyReorientFinding>,
String,
) {
let Some(state) = state else {
return (
ThreadEpiphanyReorientResultStatus::MissingState,
None,
"No authoritative Epiphany state exists for this thread.".to_string(),
);
};
if let Some(link) = latest_epiphany_runtime_link_for_binding(state, binding_id) {
return load_epiphany_reorient_result_from_runtime_spine_job(
link.runtime_job_id.as_str(),
runtime_store_path,
);
}
if !state
.job_bindings
.iter()
.any(|binding| binding.id == binding_id)
{
return (
ThreadEpiphanyReorientResultStatus::MissingBinding,
None,
"No matching Epiphany reorientation worker binding exists.".to_string(),
);
}
(
ThreadEpiphanyReorientResultStatus::BackendUnavailable,
None,
"Reorientation binding has no runtime-spine job id; launch a runtime-linked reorient worker for typed results.".to_string(),
)
}
fn latest_epiphany_runtime_link_for_binding<'a>(
state: &'a EpiphanyThreadState,
binding_id: &str,
) -> Option<&'a EpiphanyRuntimeLink> {
state
.runtime_links
.iter()
.find(|link| link.binding_id == binding_id && !link.runtime_job_id.trim().is_empty())
}
pub(crate) async fn maybe_run_epiphany_coordinator_automation_for_turn_boundary(
thread_id: ThreadId,
thread: Arc<CodexThread>,

View file

@ -0,0 +1,249 @@
use super::*;
pub(super) fn role_finding_runtime_result_id(
finding: &ThreadEpiphanyRoleFinding,
) -> Option<String> {
finding.runtime_result_id.clone()
}
pub(super) fn role_finding_runtime_job_id(finding: &ThreadEpiphanyRoleFinding) -> Option<String> {
finding.runtime_job_id.clone()
}
pub(super) fn reorient_finding_runtime_result_id(
finding: &ThreadEpiphanyReorientFinding,
) -> Option<String> {
finding.runtime_result_id.clone()
}
pub(super) fn reorient_finding_runtime_job_id(
finding: &ThreadEpiphanyReorientFinding,
) -> Option<String> {
finding.runtime_job_id.clone()
}
pub(super) fn load_epiphany_role_result_from_runtime_spine_job(
job_id: &str,
runtime_store_path: Option<&Path>,
role_id: ThreadEpiphanyRoleId,
) -> (
ThreadEpiphanyRoleResultStatus,
Option<ThreadEpiphanyRoleFinding>,
String,
) {
let Some(runtime_store_path) = runtime_store_path else {
return (
ThreadEpiphanyRoleResultStatus::Pending,
None,
"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 (
ThreadEpiphanyRoleResultStatus::Pending,
None,
format!(
"Heartbeat runtime job {:?} has not reported typed state yet.",
job_id
),
);
}
Err(err) => {
return (
ThreadEpiphanyRoleResultStatus::BackendUnavailable,
None,
format!(
"Failed to read heartbeat runtime-spine job {:?}: {err}",
job_id
),
);
}
};
let status = map_runtime_role_result_status(&snapshot);
let finding = snapshot.result.as_ref().map(|result| {
map_protocol_role_finding(
role_id,
interpret_role_runtime_job_result(map_core_role_result_role_id(role_id), result),
)
});
let note = render_epiphany_role_result_note(role_id, status, finding.as_ref(), None);
(status, finding, note)
}
pub(super) fn load_epiphany_reorient_result_from_runtime_spine_job(
job_id: &str,
runtime_store_path: Option<&Path>,
) -> (
ThreadEpiphanyReorientResultStatus,
Option<ThreadEpiphanyReorientFinding>,
String,
) {
let Some(runtime_store_path) = runtime_store_path else {
return (
ThreadEpiphanyReorientResultStatus::Pending,
None,
"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 (
ThreadEpiphanyReorientResultStatus::Pending,
None,
format!(
"Heartbeat runtime job {:?} has not reported typed state yet.",
job_id
),
);
}
Err(err) => {
return (
ThreadEpiphanyReorientResultStatus::BackendUnavailable,
None,
format!(
"Failed to read heartbeat runtime-spine job {:?}: {err}",
job_id
),
);
}
};
let status = map_runtime_reorient_result_status(&snapshot);
let finding = snapshot
.result
.as_ref()
.map(|result| map_protocol_reorient_finding(interpret_reorient_runtime_job_result(result)));
let note = render_epiphany_reorient_result_note(status, finding.as_ref(), None);
(status, finding, note)
}
fn map_runtime_role_result_status(
snapshot: &EpiphanyRuntimeJobSnapshot,
) -> ThreadEpiphanyRoleResultStatus {
match snapshot.job.status {
EpiphanyRuntimeJobStatus::Queued => ThreadEpiphanyRoleResultStatus::Pending,
EpiphanyRuntimeJobStatus::Running | EpiphanyRuntimeJobStatus::WaitingForReview => {
ThreadEpiphanyRoleResultStatus::Running
}
EpiphanyRuntimeJobStatus::Completed => {
if snapshot.result.is_some() {
ThreadEpiphanyRoleResultStatus::Completed
} else {
ThreadEpiphanyRoleResultStatus::Pending
}
}
EpiphanyRuntimeJobStatus::Failed => ThreadEpiphanyRoleResultStatus::Failed,
EpiphanyRuntimeJobStatus::Cancelled => ThreadEpiphanyRoleResultStatus::Cancelled,
}
}
fn map_runtime_reorient_result_status(
snapshot: &EpiphanyRuntimeJobSnapshot,
) -> ThreadEpiphanyReorientResultStatus {
match snapshot.job.status {
EpiphanyRuntimeJobStatus::Queued => ThreadEpiphanyReorientResultStatus::Pending,
EpiphanyRuntimeJobStatus::Running | EpiphanyRuntimeJobStatus::WaitingForReview => {
ThreadEpiphanyReorientResultStatus::Running
}
EpiphanyRuntimeJobStatus::Completed => {
if snapshot.result.is_some() {
ThreadEpiphanyReorientResultStatus::Completed
} else {
ThreadEpiphanyReorientResultStatus::Pending
}
}
EpiphanyRuntimeJobStatus::Failed => ThreadEpiphanyReorientResultStatus::Failed,
EpiphanyRuntimeJobStatus::Cancelled => ThreadEpiphanyReorientResultStatus::Cancelled,
}
}
pub(super) async fn load_epiphany_role_result_snapshot(
state: &EpiphanyThreadState,
runtime_store_path: Option<&Path>,
role_id: ThreadEpiphanyRoleId,
binding_id: &str,
) -> (
ThreadEpiphanyRoleResultStatus,
Option<ThreadEpiphanyRoleFinding>,
String,
) {
if let Some(link) = latest_epiphany_runtime_link_for_binding(state, binding_id) {
return load_epiphany_role_result_from_runtime_spine_job(
link.runtime_job_id.as_str(),
runtime_store_path,
role_id,
);
}
if !state
.job_bindings
.iter()
.any(|binding| binding.id == binding_id)
{
return (
ThreadEpiphanyRoleResultStatus::MissingBinding,
None,
"No matching Epiphany role specialist binding exists.".to_string(),
);
}
(
ThreadEpiphanyRoleResultStatus::BackendUnavailable,
None,
"Role binding has no runtime-spine job id; launch a runtime-linked role worker for typed results.".to_string(),
)
}
pub(super) async fn load_epiphany_reorient_result_snapshot(
state: Option<&EpiphanyThreadState>,
runtime_store_path: Option<&Path>,
binding_id: &str,
) -> (
ThreadEpiphanyReorientResultStatus,
Option<ThreadEpiphanyReorientFinding>,
String,
) {
let Some(state) = state else {
return (
ThreadEpiphanyReorientResultStatus::MissingState,
None,
"No authoritative Epiphany state exists for this thread.".to_string(),
);
};
if let Some(link) = latest_epiphany_runtime_link_for_binding(state, binding_id) {
return load_epiphany_reorient_result_from_runtime_spine_job(
link.runtime_job_id.as_str(),
runtime_store_path,
);
}
if !state
.job_bindings
.iter()
.any(|binding| binding.id == binding_id)
{
return (
ThreadEpiphanyReorientResultStatus::MissingBinding,
None,
"No matching Epiphany reorientation worker binding exists.".to_string(),
);
}
(
ThreadEpiphanyReorientResultStatus::BackendUnavailable,
None,
"Reorientation binding has no runtime-spine job id; launch a runtime-linked reorient worker for typed results.".to_string(),
)
}
pub(super) fn latest_epiphany_runtime_link_for_binding<'a>(
state: &'a EpiphanyThreadState,
binding_id: &str,
) -> Option<&'a EpiphanyRuntimeLink> {
state
.runtime_links
.iter()
.find(|link| link.binding_id == binding_id && !link.runtime_job_id.trim().is_empty())
}