Store typed worker result documents

This commit is contained in:
Meta Vens 2026-05-13 08:42:13 +01:00
commit ea1d3c2e82
10 changed files with 473 additions and 25 deletions

View file

@ -14,7 +14,11 @@ use epiphany_core::EpiphanyRuntimeJobSnapshot;
use epiphany_core::EpiphanyRuntimeJobStatus;
use epiphany_core::interpret_reorient_runtime_job_result;
use epiphany_core::interpret_role_runtime_job_result;
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 crate::results::map_core_role_result_role_id;
use crate::results::map_protocol_reorient_finding;
@ -22,9 +26,7 @@ use crate::results::map_protocol_role_finding;
use crate::results::render_epiphany_reorient_result_note;
use crate::results::render_epiphany_role_result_note;
pub fn role_finding_runtime_result_id(
finding: &ThreadEpiphanyRoleFinding,
) -> Option<String> {
pub fn role_finding_runtime_result_id(finding: &ThreadEpiphanyRoleFinding) -> Option<String> {
finding.runtime_result_id.clone()
}
@ -38,9 +40,7 @@ pub fn reorient_finding_runtime_result_id(
finding.runtime_result_id.clone()
}
pub fn reorient_finding_runtime_job_id(
finding: &ThreadEpiphanyReorientFinding,
) -> Option<String> {
pub fn reorient_finding_runtime_job_id(finding: &ThreadEpiphanyReorientFinding) -> Option<String> {
finding.runtime_job_id.clone()
}
@ -85,12 +85,37 @@ pub fn load_epiphany_role_result_from_runtime_spine_job(
}
};
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 finding = if status == ThreadEpiphanyRoleResultStatus::Completed {
match runtime_role_worker_result(runtime_store_path, job_id) {
Ok(Some(result)) => Some(map_protocol_role_finding(
role_id,
interpret_runtime_role_worker_result(
map_core_role_result_role_id(role_id),
&result,
),
)),
Ok(None) => 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,
),
)
}),
Err(_) => 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,
),
)
}),
}
} else {
None
};
let note = render_epiphany_role_result_note(role_id, status, finding.as_ref(), None);
(status, finding, note)
}
@ -135,10 +160,21 @@ pub fn load_epiphany_reorient_result_from_runtime_spine_job(
}
};
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 finding = if status == ThreadEpiphanyReorientResultStatus::Completed {
match runtime_reorient_worker_result(runtime_store_path, job_id) {
Ok(Some(result)) => Some(map_protocol_reorient_finding(
interpret_runtime_reorient_worker_result(&result),
)),
Ok(None) => snapshot.result.as_ref().map(|result| {
map_protocol_reorient_finding(interpret_reorient_runtime_job_result(result))
}),
Err(_) => snapshot.result.as_ref().map(|result| {
map_protocol_reorient_finding(interpret_reorient_runtime_job_result(result))
}),
}
} else {
None
};
let note = render_epiphany_reorient_result_note(status, finding.as_ref(), None);
(status, finding, note)
}

View file

@ -96,6 +96,8 @@ pub use runtime_spine::EpiphanyRuntimeJob;
pub use runtime_spine::EpiphanyRuntimeJobResult;
pub use runtime_spine::EpiphanyRuntimeJobSnapshot;
pub use runtime_spine::EpiphanyRuntimeJobStatus;
pub use runtime_spine::EpiphanyRuntimeReorientWorkerResult;
pub use runtime_spine::EpiphanyRuntimeRoleWorkerResult;
pub use runtime_spine::EpiphanyRuntimeSession;
pub use runtime_spine::EpiphanyRuntimeSessionStatus;
pub use runtime_spine::EpiphanyRuntimeSpineStatus;
@ -105,6 +107,10 @@ pub use runtime_spine::RUNTIME_IDENTITY_KEY;
pub use runtime_spine::RUNTIME_IDENTITY_TYPE;
pub use runtime_spine::RUNTIME_JOB_RESULT_TYPE;
pub use runtime_spine::RUNTIME_JOB_TYPE;
pub use runtime_spine::RUNTIME_REORIENT_WORKER_RESULT_SCHEMA_VERSION;
pub use runtime_spine::RUNTIME_REORIENT_WORKER_RESULT_TYPE;
pub use runtime_spine::RUNTIME_ROLE_WORKER_RESULT_SCHEMA_VERSION;
pub use runtime_spine::RUNTIME_ROLE_WORKER_RESULT_TYPE;
pub use runtime_spine::RUNTIME_SESSION_TYPE;
pub use runtime_spine::RUNTIME_SPINE_SCHEMA_VERSION;
pub use runtime_spine::RUNTIME_WORKER_LAUNCH_REQUEST_SCHEMA_VERSION;
@ -125,8 +131,12 @@ pub use runtime_spine::ensure_runtime_session;
pub use runtime_spine::initialize_runtime_spine;
pub use runtime_spine::open_runtime_spine_heartbeat_job;
pub use runtime_spine::plan_runtime_spine_heartbeat_launch;
pub use runtime_spine::put_runtime_reorient_worker_result;
pub use runtime_spine::put_runtime_role_worker_result;
pub use runtime_spine::runtime_hello_frame;
pub use runtime_spine::runtime_job_snapshot;
pub use runtime_spine::runtime_reorient_worker_result;
pub use runtime_spine::runtime_role_worker_result;
pub use runtime_spine::runtime_schema_catalog_response;
pub use runtime_spine::runtime_spine_cache;
pub use runtime_spine::runtime_spine_status;
@ -251,6 +261,8 @@ pub use surfaces::interpret_reorient_finding;
pub use surfaces::interpret_reorient_runtime_job_result;
pub use surfaces::interpret_role_finding;
pub use surfaces::interpret_role_runtime_job_result;
pub use surfaces::interpret_runtime_reorient_worker_result;
pub use surfaces::interpret_runtime_role_worker_result;
pub use surfaces::modeling_role_state_patch_policy_errors;
pub use surfaces::recommend_coordinator_action;
pub use surfaces::recommend_crrc_action;

View file

@ -40,6 +40,8 @@ pub const RUNTIME_IDENTITY_TYPE: &str = "epiphany.runtime.identity";
pub const RUNTIME_SESSION_TYPE: &str = "epiphany.runtime.session";
pub const RUNTIME_JOB_TYPE: &str = "epiphany.runtime.job";
pub const RUNTIME_WORKER_LAUNCH_REQUEST_TYPE: &str = "epiphany.runtime.worker_launch_request";
pub const RUNTIME_ROLE_WORKER_RESULT_TYPE: &str = "epiphany.runtime.role_worker_result";
pub const RUNTIME_REORIENT_WORKER_RESULT_TYPE: &str = "epiphany.runtime.reorient_worker_result";
pub const RUNTIME_JOB_RESULT_TYPE: &str = "epiphany.runtime.job_result";
pub const RUNTIME_EVENT_TYPE: &str = "epiphany.runtime.event";
pub const OPENAI_ADAPTER_STATUS_TYPE: &str = "epiphany.openai_adapter_status.v0";
@ -69,6 +71,10 @@ pub const RUNTIME_IDENTITY_KEY: &str = "self";
pub const RUNTIME_SPINE_SCHEMA_VERSION: &str = "epiphany.runtime_spine.v0";
pub const RUNTIME_WORKER_LAUNCH_REQUEST_SCHEMA_VERSION: &str =
"epiphany.runtime.worker_launch_request.v0";
pub const RUNTIME_ROLE_WORKER_RESULT_SCHEMA_VERSION: &str =
"epiphany.runtime.role_worker_result.v0";
pub const RUNTIME_REORIENT_WORKER_RESULT_SCHEMA_VERSION: &str =
"epiphany.runtime.reorient_worker_result.v0";
pub const OPENAI_ADAPTER_STATUS_SCHEMA_VERSION: &str = "epiphany.openai_adapter_status.v0";
pub const OPENAI_MODEL_REQUEST_SCHEMA_VERSION: &str = "epiphany.openai_model_request.v0";
pub const OPENAI_MODEL_STREAM_EVENT_SCHEMA_VERSION: &str = "epiphany.openai_model_stream_event.v0";
@ -230,6 +236,105 @@ impl EpiphanyRuntimeWorkerLaunchRequest {
}
}
#[derive(Clone, Debug, PartialEq, DatabaseEntry)]
#[cultcache(
type = "epiphany.runtime.role_worker_result",
schema = "EpiphanyRuntimeRoleWorkerResult"
)]
pub struct EpiphanyRuntimeRoleWorkerResult {
#[cultcache(key = 0)]
pub schema_version: String,
#[cultcache(key = 1)]
pub result_id: String,
#[cultcache(key = 2)]
pub job_id: String,
#[cultcache(key = 3)]
pub role_id: String,
#[cultcache(key = 4)]
pub verdict: String,
#[cultcache(key = 5)]
pub summary: String,
#[cultcache(key = 6)]
pub next_safe_move: String,
#[cultcache(key = 7, default)]
pub checkpoint_summary: Option<String>,
#[cultcache(key = 8, default)]
pub scratch_summary: Option<String>,
#[cultcache(key = 9, default)]
pub files_inspected: Vec<String>,
#[cultcache(key = 10, default)]
pub frontier_node_ids: Vec<String>,
#[cultcache(key = 11, default)]
pub evidence_ids: Vec<String>,
#[cultcache(key = 12, default)]
pub artifact_refs: Vec<String>,
#[cultcache(key = 13, default)]
pub open_questions: Vec<String>,
#[cultcache(key = 14, default)]
pub evidence_gaps: Vec<String>,
#[cultcache(key = 15, default)]
pub risks: Vec<String>,
#[cultcache(key = 16, default)]
pub state_patch_msgpack: Option<Vec<u8>>,
#[cultcache(key = 17, default)]
pub self_patch_msgpack: Option<Vec<u8>>,
#[cultcache(key = 18, default)]
pub item_error: Option<String>,
#[cultcache(key = 19, default)]
pub metadata: BTreeMap<String, String>,
}
impl EpiphanyRuntimeRoleWorkerResult {
pub fn state_patch(&self) -> Result<Option<crate::EpiphanyRoleStatePatchDocument>> {
decode_optional_msgpack(
self.state_patch_msgpack.as_deref(),
"role worker statePatch",
)
}
pub fn self_patch(&self) -> Result<Option<crate::AgentSelfPatch>> {
decode_optional_msgpack(self.self_patch_msgpack.as_deref(), "role worker selfPatch")
}
}
#[derive(Clone, Debug, PartialEq, DatabaseEntry)]
#[cultcache(
type = "epiphany.runtime.reorient_worker_result",
schema = "EpiphanyRuntimeReorientWorkerResult"
)]
pub struct EpiphanyRuntimeReorientWorkerResult {
#[cultcache(key = 0)]
pub schema_version: String,
#[cultcache(key = 1)]
pub result_id: String,
#[cultcache(key = 2)]
pub job_id: String,
#[cultcache(key = 3)]
pub mode: String,
#[cultcache(key = 4)]
pub summary: String,
#[cultcache(key = 5)]
pub next_safe_move: String,
#[cultcache(key = 6, default)]
pub checkpoint_still_valid: Option<bool>,
#[cultcache(key = 7, default)]
pub files_inspected: Vec<String>,
#[cultcache(key = 8, default)]
pub frontier_node_ids: Vec<String>,
#[cultcache(key = 9, default)]
pub evidence_ids: Vec<String>,
#[cultcache(key = 10, default)]
pub artifact_refs: Vec<String>,
#[cultcache(key = 11, default)]
pub open_questions: Vec<String>,
#[cultcache(key = 12, default)]
pub continuity_risks: Vec<String>,
#[cultcache(key = 13, default)]
pub item_error: Option<String>,
#[cultcache(key = 14, default)]
pub metadata: BTreeMap<String, String>,
}
#[derive(Clone, Debug, PartialEq, DatabaseEntry)]
#[cultcache(
type = "epiphany.runtime.job_result",
@ -424,6 +529,8 @@ pub fn runtime_spine_cache(store_path: impl AsRef<Path>) -> Result<CultCache> {
cache.register_entry_type::<EpiphanyRuntimeSession>()?;
cache.register_entry_type::<EpiphanyRuntimeJob>()?;
cache.register_entry_type::<EpiphanyRuntimeWorkerLaunchRequest>()?;
cache.register_entry_type::<EpiphanyRuntimeRoleWorkerResult>()?;
cache.register_entry_type::<EpiphanyRuntimeReorientWorkerResult>()?;
cache.register_entry_type::<EpiphanyRuntimeJobResult>()?;
cache.register_entry_type::<EpiphanyRuntimeEvent>()?;
cache.register_entry_type::<EpiphanyOpenAiAdapterStatus>()?;
@ -737,6 +844,52 @@ pub fn runtime_job_snapshot(
Ok(Some(EpiphanyRuntimeJobSnapshot { job, result }))
}
pub fn put_runtime_role_worker_result(
store_path: impl AsRef<Path>,
result: &EpiphanyRuntimeRoleWorkerResult,
) -> Result<()> {
validate_non_empty(&result.job_id, "role worker result job id")?;
validate_non_empty(&result.result_id, "role worker result id")?;
validate_non_empty(&result.role_id, "role worker result role id")?;
let mut cache = runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
cache.put(&result.job_id, result)?;
Ok(())
}
pub fn runtime_role_worker_result(
store_path: impl AsRef<Path>,
job_id: &str,
) -> Result<Option<EpiphanyRuntimeRoleWorkerResult>> {
validate_non_empty(job_id, "role worker result job id")?;
let mut cache = runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
cache.get::<EpiphanyRuntimeRoleWorkerResult>(job_id)
}
pub fn put_runtime_reorient_worker_result(
store_path: impl AsRef<Path>,
result: &EpiphanyRuntimeReorientWorkerResult,
) -> Result<()> {
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")?;
let mut cache = runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
cache.put(&result.job_id, result)?;
Ok(())
}
pub fn runtime_reorient_worker_result(
store_path: impl AsRef<Path>,
job_id: &str,
) -> Result<Option<EpiphanyRuntimeReorientWorkerResult>> {
validate_non_empty(job_id, "reorient worker result job id")?;
let mut cache = runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
cache.get::<EpiphanyRuntimeReorientWorkerResult>(job_id)
}
pub fn complete_runtime_job(
store_path: impl AsRef<Path>,
options: RuntimeSpineJobResultOptions,
@ -1168,6 +1321,28 @@ fn epiphany_mutation_contracts() -> Vec<CultNetDocumentMutationContract> {
"Worker launch requests are typed task-intent documents; runtime jobs are lifecycle receipts, not the source of work intent.",
],
),
mutation_contract(
RUNTIME_ROLE_WORKER_RESULT_TYPE,
RUNTIME_ROLE_WORKER_RESULT_SCHEMA_VERSION,
vec![CultNetDocumentOperation::Snapshot],
CultNetMutationAuthority::ReadOnly,
vec![],
vec![],
vec![
"Role worker results preserve the typed finding payload; generic runtime job results are lifecycle receipts.",
],
),
mutation_contract(
RUNTIME_REORIENT_WORKER_RESULT_TYPE,
RUNTIME_REORIENT_WORKER_RESULT_SCHEMA_VERSION,
vec![CultNetDocumentOperation::Snapshot],
CultNetMutationAuthority::ReadOnly,
vec![],
vec![],
vec![
"Reorient worker results preserve continuity findings separately from generic runtime lifecycle receipts.",
],
),
mutation_contract(
RUNTIME_JOB_RESULT_TYPE,
RUNTIME_SPINE_SCHEMA_VERSION,
@ -1508,6 +1683,17 @@ fn encode_worker_launch_document(document: &EpiphanyWorkerLaunchDocument) -> Res
rmp_serde::to_vec_named(document).context("failed to encode worker launch document MessagePack")
}
fn decode_optional_msgpack<T>(payload: Option<&[u8]>, label: &str) -> Result<Option<T>>
where
T: for<'de> Deserialize<'de>,
{
payload
.map(|payload| {
rmp_serde::from_slice(payload).with_context(|| format!("failed to decode {label}"))
})
.transpose()
}
fn validate_heartbeat_launch_options(
state: &EpiphanyThreadState,
options: &RuntimeSpineHeartbeatLaunchPlanOptions,

View file

@ -107,6 +107,8 @@ pub use role_result::interpret_reorient_finding;
pub use role_result::interpret_reorient_runtime_job_result;
pub use role_result::interpret_role_finding;
pub use role_result::interpret_role_runtime_job_result;
pub use role_result::interpret_runtime_reorient_worker_result;
pub use role_result::interpret_runtime_role_worker_result;
pub use role_result::modeling_role_state_patch_policy_errors;
pub use role_result::review_role_self_patch;
pub use role_result::role_self_memory_target;

View file

@ -222,6 +222,71 @@ pub fn interpret_role_runtime_job_result(
}
}
pub fn interpret_runtime_role_worker_result(
role_id: EpiphanyRoleResultRoleId,
result: &crate::EpiphanyRuntimeRoleWorkerResult,
) -> EpiphanyRoleFindingInterpretation {
let state_patch_result = result.state_patch();
let self_patch_result = result.self_patch();
let state_patch = state_patch_result
.as_ref()
.ok()
.and_then(|patch| patch.clone());
let self_patch = self_patch_result
.as_ref()
.ok()
.and_then(|patch| patch.clone());
let item_error = merge_item_error(
result.item_error.clone(),
state_patch_result.as_ref().err().map(ToString::to_string),
);
let item_error = merge_item_error(
item_error,
self_patch_result.as_ref().err().map(ToString::to_string),
);
EpiphanyRoleFindingInterpretation {
verdict: Some(result.verdict.clone()),
summary: Some(result.summary.clone()),
next_safe_move: empty_string_as_none(&result.next_safe_move),
checkpoint_summary: result.checkpoint_summary.clone(),
scratch_summary: result.scratch_summary.clone(),
files_inspected: result.files_inspected.clone(),
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()),
runtime_job_id: Some(result.job_id.clone()),
open_questions: result.open_questions.clone(),
evidence_gaps: result.evidence_gaps.clone(),
risks: result.risks.clone(),
state_patch: state_patch.clone(),
self_patch,
self_persistence: None,
job_error: None,
item_error: match role_id {
EpiphanyRoleResultRoleId::Modeling => merge_item_error(
item_error,
modeling_role_state_patch_error(
&serde_json::Value::Null,
state_patch.as_ref(),
None,
),
),
EpiphanyRoleResultRoleId::Imagination => merge_item_error(
item_error,
imagination_role_state_patch_error(
&serde_json::Value::Null,
state_patch.as_ref(),
None,
),
),
EpiphanyRoleResultRoleId::Implementation
| EpiphanyRoleResultRoleId::Verification
| EpiphanyRoleResultRoleId::Reorientation => item_error,
},
}
}
pub fn interpret_reorient_runtime_job_result(
result: &EpiphanyRuntimeJobResult,
) -> EpiphanyReorientFindingInterpretation {
@ -241,6 +306,25 @@ pub fn interpret_reorient_runtime_job_result(
}
}
pub fn interpret_runtime_reorient_worker_result(
result: &crate::EpiphanyRuntimeReorientWorkerResult,
) -> EpiphanyReorientFindingInterpretation {
EpiphanyReorientFindingInterpretation {
mode: Some(result.mode.clone()),
summary: Some(result.summary.clone()),
next_safe_move: Some(result.next_safe_move.clone()),
checkpoint_still_valid: result.checkpoint_still_valid,
files_inspected: result.files_inspected.clone(),
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()),
runtime_job_id: Some(result.job_id.clone()),
job_error: None,
item_error: result.item_error.clone(),
}
}
pub fn build_role_acceptance_bundle(
binding_id: &str,
role: EpiphanyRoleAcceptanceFinding,

View file

@ -16,6 +16,7 @@ codex-login = { path = "../vendor/codex/codex-rs/login" }
epiphany-core = { path = "../epiphany-core" }
epiphany-openai-adapter = { path = "../epiphany-openai-adapter" }
epiphany-openai-codex-spine = { path = "../epiphany-openai-codex-spine" }
rmp-serde = "1"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

View file

@ -8,6 +8,8 @@ use anyhow::anyhow;
use chrono::SecondsFormat;
use codex_login::AuthCredentialsStoreMode;
use codex_login::AuthManager;
use epiphany_core::EpiphanyRuntimeReorientWorkerResult;
use epiphany_core::EpiphanyRuntimeRoleWorkerResult;
use epiphany_core::EpiphanyRuntimeWorkerLaunchRequest;
use epiphany_core::EpiphanyWorkerLaunchDocument;
use epiphany_core::RuntimeSpineEventOptions;
@ -20,6 +22,8 @@ use epiphany_core::complete_runtime_job;
use epiphany_core::create_runtime_job;
use epiphany_core::ensure_runtime_session;
use epiphany_core::initialize_runtime_spine;
use epiphany_core::put_runtime_reorient_worker_result;
use epiphany_core::put_runtime_role_worker_result;
use epiphany_core::runtime_spine_cache;
use epiphany_core::runtime_spine_status;
use epiphany_openai_adapter::EpiphanyOpenAiAdapterStatus;
@ -357,10 +361,34 @@ pub fn complete_worker_job_from_assistant_text(
.map(|value| string_array_field(value, "artifactRefs"))
.unwrap_or_default();
artifact_refs.push(format!("openai-result:{}", openai_summary.result_id));
let result_id = format!("result-worker-{}", launch_request.job_id);
if let Some(parsed) = parsed.as_ref() {
match launch_request.launch_document()? {
EpiphanyWorkerLaunchDocument::Role(document) => {
let typed_result = role_worker_result_from_value(
launch_request,
&document.role_id,
&result_id,
parsed,
artifact_refs.clone(),
);
put_runtime_role_worker_result(store_path.as_ref(), &typed_result)?;
}
EpiphanyWorkerLaunchDocument::Reorient(_) => {
let typed_result = reorient_worker_result_from_value(
launch_request,
&result_id,
parsed,
artifact_refs.clone(),
);
put_runtime_reorient_worker_result(store_path.as_ref(), &typed_result)?;
}
}
}
complete_runtime_job(
store_path,
RuntimeSpineJobResultOptions {
result_id: format!("result-worker-{}", launch_request.job_id),
result_id,
job_id: launch_request.job_id.clone(),
completed_at: now(),
verdict,
@ -537,6 +565,99 @@ fn worker_output_contract_text(document: &EpiphanyWorkerLaunchDocument) -> &'sta
}
}
fn role_worker_result_from_value(
launch_request: &EpiphanyRuntimeWorkerLaunchRequest,
role_id: &str,
result_id: &str,
value: &Value,
artifact_refs: Vec<String>,
) -> EpiphanyRuntimeRoleWorkerResult {
let (state_patch_msgpack, state_patch_error) = encode_optional_value_field::<
epiphany_core::EpiphanyRoleStatePatchDocument,
>(value, "statePatch");
let (self_patch_msgpack, self_patch_error) =
encode_optional_value_field::<epiphany_core::AgentSelfPatch>(value, "selfPatch");
EpiphanyRuntimeRoleWorkerResult {
schema_version: epiphany_core::RUNTIME_ROLE_WORKER_RESULT_SCHEMA_VERSION.to_string(),
result_id: result_id.to_string(),
job_id: launch_request.job_id.clone(),
role_id: string_field(value, "roleId").unwrap_or_else(|| role_id.to_string()),
verdict: string_field(value, "verdict").unwrap_or_else(|| "completed".to_string()),
summary: string_field(value, "summary")
.unwrap_or_else(|| "Worker completed without a structured summary.".to_string()),
next_safe_move: string_field(value, "nextSafeMove").unwrap_or_else(|| {
"Review the typed worker runtime result before accepting state.".to_string()
}),
checkpoint_summary: string_field(value, "checkpointSummary"),
scratch_summary: string_field(value, "scratchSummary"),
files_inspected: string_array_field(value, "filesInspected"),
frontier_node_ids: string_array_field(value, "frontierNodeIds"),
evidence_ids: string_array_field(value, "evidenceIds"),
artifact_refs,
open_questions: string_array_field(value, "openQuestions"),
evidence_gaps: string_array_field(value, "evidenceGaps"),
risks: string_array_field(value, "risks"),
state_patch_msgpack,
self_patch_msgpack,
item_error: merge_optional_errors(state_patch_error, self_patch_error),
metadata: std::collections::BTreeMap::new(),
}
}
fn reorient_worker_result_from_value(
launch_request: &EpiphanyRuntimeWorkerLaunchRequest,
result_id: &str,
value: &Value,
artifact_refs: Vec<String>,
) -> EpiphanyRuntimeReorientWorkerResult {
EpiphanyRuntimeReorientWorkerResult {
schema_version: epiphany_core::RUNTIME_REORIENT_WORKER_RESULT_SCHEMA_VERSION.to_string(),
result_id: result_id.to_string(),
job_id: launch_request.job_id.clone(),
mode: string_field(value, "mode").unwrap_or_else(|| "regather".to_string()),
summary: string_field(value, "summary").unwrap_or_else(|| {
"Reorient worker completed without a structured summary.".to_string()
}),
next_safe_move: string_field(value, "nextSafeMove").unwrap_or_else(|| {
"Review the typed reorient runtime result before accepting state.".to_string()
}),
checkpoint_still_valid: value.get("checkpointStillValid").and_then(Value::as_bool),
files_inspected: string_array_field(value, "filesInspected"),
frontier_node_ids: string_array_field(value, "frontierNodeIds"),
evidence_ids: string_array_field(value, "evidenceIds"),
artifact_refs,
open_questions: string_array_field(value, "openQuestions"),
continuity_risks: string_array_field(value, "continuityRisks"),
item_error: None,
metadata: std::collections::BTreeMap::new(),
}
}
fn encode_optional_value_field<T>(value: &Value, key: &str) -> (Option<Vec<u8>>, Option<String>)
where
T: serde::Serialize + serde::de::DeserializeOwned,
{
let Some(field) = value.get(key).cloned() else {
return (None, None);
};
match serde_json::from_value::<T>(field) {
Ok(document) => match rmp_serde::to_vec_named(&document) {
Ok(payload) => (Some(payload), None),
Err(err) => (None, Some(format!("failed to encode {key}: {err}"))),
},
Err(err) => (None, Some(format!("failed to parse {key}: {err}"))),
}
}
fn merge_optional_errors(left: Option<String>, right: Option<String>) -> Option<String> {
match (left, right) {
(Some(left), Some(right)) => Some(format!("{left}; {right}")),
(Some(left), None) => Some(left),
(None, Some(right)) => Some(right),
(None, None) => None,
}
}
fn parse_assistant_json_object(text: &str) -> Result<Value> {
let trimmed = text.trim();
let candidate = trimmed
@ -742,6 +863,11 @@ mod tests {
assert_eq!(result.summary, "Mapped.");
assert_eq!(result.next_safe_move, "Review the patch.");
assert!(result.evidence_refs.contains(&"ev-1".to_string()));
let typed_result = epiphany_core::runtime_role_worker_result(&store, "worker-job-1")?
.expect("typed role worker result");
assert_eq!(typed_result.verdict, "checkpoint-ready");
assert_eq!(typed_result.files_inspected, vec!["src/lib.rs".to_string()]);
assert_eq!(typed_result.artifact_refs, result.artifact_refs);
assert!(
runtime_job_snapshot(&store, "worker-job-1")?
.expect("snapshot")

View file

@ -588,12 +588,13 @@ results, and runtime events into the native runtime spine. Its `model-turn`
command calls the Codex-backed typed transport; its `smoke` command proves the
storage route without network. Its `run-worker` command now reads a durable
`EpiphanyRuntimeWorkerLaunchRequest` by runtime job id, builds a typed OpenAI
model request, calls the native runtime route, and completes the original
heartbeat/specialist runtime job without Codex worker execution. The remaining
result wound is deliberate and named: rich role/reorient output is still parsed
from model-edge JSON into generic job-result fields. The next cut is a
first-class typed runtime worker result document plus roleResult/reorientResult
readback through that document, then carving down the `codex-api` dependency
model request, calls the native runtime route, persists typed
`EpiphanyRuntimeRoleWorkerResult` or `EpiphanyRuntimeReorientWorkerResult`
documents, and completes the original heartbeat/specialist runtime job without
Codex worker execution. `roleResult` and `reorientResult` now prefer those typed
worker result documents and use generic job summaries only as legacy fallback.
The next cut is wiring coordinator/heartbeat automation to invoke `run-worker`
for launched runtime job ids, then carving down the `codex-api` dependency
weight.
The runtime-spine job-opening mechanism for heartbeat/specialist launches has

Binary file not shown.

View file

@ -279,5 +279,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, eighteen processor cuts, a real physical extraction in `epiphany-codex-bridge`, a source-grounded Codex auth spine inventory, the native `epiphany-openai-adapter` document boundary, a buildable Codex auth/model wrapper in `epiphany-openai-codex-spine`, the first native runtime caller in `epiphany-openai-runtime`, native heartbeat launch planning/job opening in `epiphany-core`, native state-update contract/validation/application in `epiphany-core`, and the route-facing mutation service in `epiphany-codex-bridge`. The bridge owns Codex-facing Epiphany adapters for scene, jobs, context/planning/graph query, retrieval/indexing projection, result projection, runtime-spine result adaptation, launch/prompt doctrine, mutation document mechanics, mutation service update/promote/role-accept/reorient-accept/role-launch/reorient-launch/job-launch/job-interrupt application, live-state projection, pressure/pre-compaction rendering, freshness/reorientation projection, CRRC/coordinator/role-board projection, and acceptance/evidence signal helpers. Vendored app-server now retains only `epiphany_invalidation.rs` as a root Epiphany module because watcher lifecycle is still app-server machinery; `codex_message_processor.rs` still contains route dispatch, JSON-RPC response shaping, watcher registration/snapshotting, and notification emission. The processor is about 10,339 lines, `epiphany_mutation_routes.rs` is about 691 lines after the route-load/notification helper cut and index projection move, `epiphany_state_helpers.rs` is down to a 19-line rollout-state loader, and `codex_thread.rs` is about 1,425 lines after state-update law moved native. `epiphany-openai-adapter` defines CultCache `DatabaseEntry` request/event/receipt/auth-status documents with no Codex app-server or generic JSON dependency. `epiphany-openai-codex-spine` projects `AuthManager` / `CodexAuth` into typed `EpiphanyOpenAiAdapterStatus`, maps typed `EpiphanyOpenAiModelRequest` into Codex API `ResponsesApiRequest`, resolves auth/provider through keeper Codex crates, opens HTTP Responses streams through `codex-api`, maps deltas / completion into typed stream events and receipts, and no longer directly depends on `codex-app-server-protocol` just to name auth mode. `epiphany-openai-runtime` writes OpenAI status/request/stream-event/receipt records plus runtime sessions/jobs/results/events into `epiphany-core::runtime_spine_cache`, can emit the assistant text artifact for legacy result consumers, is now the default executor for startup-only repo birth specialists, and now has `run-worker` to load a durable `EpiphanyRuntimeWorkerLaunchRequest`, call the typed OpenAI runtime, and complete the original heartbeat/specialist runtime job without Codex worker execution; `codex exec` survives only as explicit fallback in repo-birth startup. `epiphany-core::plan_runtime_spine_heartbeat_launch` validates launch contracts/conflicts and projects durable job bindings/runtime links; `epiphany-core::open_runtime_spine_heartbeat_job` owns the initialize-runtime/ensure-session/create-job sequence and now persists `EpiphanyRuntimeWorkerLaunchRequest` CultCache records keyed by runtime job id, with indexed kind/contract fields plus MessagePack-encoded typed launch documents instead of discarding work intent after queue receipt creation; `epiphany-core::EpiphanyStateUpdate`, `epiphany_state_update_validation_errors`, and `apply_epiphany_state_update` own state-update document shape and mutation law while `codex-core` calls them for compatibility. Vendored `CodexThread::epiphany_launch_job` is now mostly revision check, persistence validation, launch request handoff, and rollout/session writeback for the compatibility route. `epiphany-runtime-spine` advertises OpenAI adapter status/model-request/stream-event/receipt CultNet schemas and mutation contracts, so the native caller now has a real storage route instead of only JSON-RPC. MCP itself is correctly JSON at its protocol edge; the target is typed Epiphany intent/result/receipt wrappers around MCP, not replacing MCP JSON. The current OpenAI spine still pulls `codex-api` and a large transport dependency stack, so its next cut is dependency starvation after richer live callers move.
next_action: Promote worker role/reorient outputs from model-edge JSON into first-class typed runtime worker result CultCache documents, teach roleResult/reorientResult to read those documents instead of lossy generic runtime job summaries, then shrink the surviving Codex dependency surface to credential refresh, provider/model routing, and the smallest OpenAI Responses call required for Codex subscription compatibility.
summary: The Codex starvation pass has five typing receipts, eighteen processor cuts, a real physical extraction in `epiphany-codex-bridge`, a source-grounded Codex auth spine inventory, the native `epiphany-openai-adapter` document boundary, a buildable Codex auth/model wrapper in `epiphany-openai-codex-spine`, the first native runtime caller in `epiphany-openai-runtime`, native heartbeat launch planning/job opening in `epiphany-core`, native state-update contract/validation/application in `epiphany-core`, and the route-facing mutation service in `epiphany-codex-bridge`. The bridge owns Codex-facing Epiphany adapters for scene, jobs, context/planning/graph query, retrieval/indexing projection, result projection, runtime-spine result adaptation, launch/prompt doctrine, mutation document mechanics, mutation service update/promote/role-accept/reorient-accept/role-launch/reorient-launch/job-launch/job-interrupt application, live-state projection, pressure/pre-compaction rendering, freshness/reorientation projection, CRRC/coordinator/role-board projection, and acceptance/evidence signal helpers. Vendored app-server now retains only `epiphany_invalidation.rs` as a root Epiphany module because watcher lifecycle is still app-server machinery; `codex_message_processor.rs` still contains route dispatch, JSON-RPC response shaping, watcher registration/snapshotting, and notification emission. The processor is about 10,339 lines, `epiphany_mutation_routes.rs` is about 691 lines after the route-load/notification helper cut and index projection move, `epiphany_state_helpers.rs` is down to a 19-line rollout-state loader, and `codex_thread.rs` is about 1,425 lines after state-update law moved native. `epiphany-openai-adapter` defines CultCache `DatabaseEntry` request/event/receipt/auth-status documents with no Codex app-server or generic JSON dependency. `epiphany-openai-codex-spine` projects `AuthManager` / `CodexAuth` into typed `EpiphanyOpenAiAdapterStatus`, maps typed `EpiphanyOpenAiModelRequest` into Codex API `ResponsesApiRequest`, resolves auth/provider through keeper Codex crates, opens HTTP Responses streams through `codex-api`, maps deltas / completion into typed stream events and receipts, and no longer directly depends on `codex-app-server-protocol` just to name auth mode. `epiphany-openai-runtime` writes OpenAI status/request/stream-event/receipt records plus runtime sessions/jobs/results/events into `epiphany-core::runtime_spine_cache`, can emit the assistant text artifact for legacy result consumers, is now the default executor for startup-only repo birth specialists, and now has `run-worker` to load a durable `EpiphanyRuntimeWorkerLaunchRequest`, call the typed OpenAI runtime, persist typed `EpiphanyRuntimeRoleWorkerResult` / `EpiphanyRuntimeReorientWorkerResult` documents, and complete the original heartbeat/specialist runtime job without Codex worker execution; `codex exec` survives only as explicit fallback in repo-birth startup. `epiphany-core::plan_runtime_spine_heartbeat_launch` validates launch contracts/conflicts and projects durable job bindings/runtime links; `epiphany-core::open_runtime_spine_heartbeat_job` owns the initialize-runtime/ensure-session/create-job sequence and now persists `EpiphanyRuntimeWorkerLaunchRequest` CultCache records keyed by runtime job id, with indexed kind/contract fields plus MessagePack-encoded typed launch documents instead of discarding work intent after queue receipt creation; `roleResult` and `reorientResult` now prefer typed worker result documents and fall back only to generic job summaries for older receipts; `epiphany-core::EpiphanyStateUpdate`, `epiphany_state_update_validation_errors`, and `apply_epiphany_state_update` own state-update document shape and mutation law while `codex-core` calls them for compatibility. Vendored `CodexThread::epiphany_launch_job` is now mostly revision check, persistence validation, launch request handoff, and rollout/session writeback for the compatibility route. `epiphany-runtime-spine` advertises OpenAI adapter status/model-request/stream-event/receipt CultNet schemas and mutation contracts, so the native caller now has a real storage route instead of only JSON-RPC. MCP itself is correctly JSON at its protocol edge; the target is typed Epiphany intent/result/receipt wrappers around MCP, not replacing MCP JSON. The current OpenAI spine still pulls `codex-api` and a large transport dependency stack, so its next cut is dependency starvation after richer live callers move.
next_action: Wire coordinator/heartbeat automation to invoke `epiphany-openai-runtime run-worker` for launched runtime job ids, then shrink the surviving Codex dependency surface to credential refresh, provider/model routing, and the smallest OpenAI Responses call required for Codex subscription compatibility.