From 8311abe01a8e5d190d523c7f9a7acf8b40d51860 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 13 May 2026 06:02:39 +0100 Subject: [PATCH] Move heartbeat job opening into runtime spine --- epiphany-core/src/lib.rs | 2 + epiphany-core/src/runtime_spine.rs | 93 ++++++++++++++++++ notes/codex-auth-spine-inventory.md | 6 ++ notes/fresh-workspace-handoff.md | 8 ++ state/ledgers.msgpack | Bin 82444 -> 82800 bytes state/map.yaml | 4 +- .../codex/codex-rs/core/src/codex_thread.rs | 46 ++------- 7 files changed, 118 insertions(+), 41 deletions(-) diff --git a/epiphany-core/src/lib.rs b/epiphany-core/src/lib.rs index 3fdd1d38..7ab86f64 100644 --- a/epiphany-core/src/lib.rs +++ b/epiphany-core/src/lib.rs @@ -106,6 +106,7 @@ pub use runtime_spine::RUNTIME_JOB_TYPE; pub use runtime_spine::RUNTIME_SESSION_TYPE; pub use runtime_spine::RUNTIME_SPINE_SCHEMA_VERSION; pub use runtime_spine::RuntimeSpineEventOptions; +pub use runtime_spine::RuntimeSpineHeartbeatJobOptions; pub use runtime_spine::RuntimeSpineInitOptions; pub use runtime_spine::RuntimeSpineJobOptions; pub use runtime_spine::RuntimeSpineJobResultOptions; @@ -116,6 +117,7 @@ pub use runtime_spine::create_runtime_job; pub use runtime_spine::create_runtime_session; 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::runtime_hello_frame; pub use runtime_spine::runtime_job_snapshot; pub use runtime_spine::runtime_schema_catalog_response; diff --git a/epiphany-core/src/runtime_spine.rs b/epiphany-core/src/runtime_spine.rs index ed9b6fd2..b9528584 100644 --- a/epiphany-core/src/runtime_spine.rs +++ b/epiphany-core/src/runtime_spine.rs @@ -320,6 +320,20 @@ pub struct RuntimeSpineJobResultOptions { pub artifact_refs: Vec, } +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct RuntimeSpineHeartbeatJobOptions { + pub runtime_id: String, + pub display_name: String, + pub session_id: String, + pub objective: String, + pub coordinator_note: String, + pub job_id: String, + pub role: String, + pub binding_id: String, + pub authority_scope: String, + pub created_at: String, +} + #[derive(Clone, Debug, PartialEq)] pub struct EpiphanyRuntimeJobSnapshot { pub job: EpiphanyRuntimeJob, @@ -496,6 +510,53 @@ pub fn create_runtime_job( Ok(job) } +pub fn open_runtime_spine_heartbeat_job( + store_path: impl AsRef, + options: RuntimeSpineHeartbeatJobOptions, +) -> Result { + validate_non_empty(&options.runtime_id, "runtime id")?; + validate_non_empty(&options.display_name, "display name")?; + validate_non_empty(&options.session_id, "session id")?; + validate_non_empty(&options.objective, "objective")?; + validate_non_empty(&options.job_id, "job id")?; + validate_non_empty(&options.role, "role")?; + validate_non_empty(&options.binding_id, "binding id")?; + validate_non_empty(&options.authority_scope, "authority scope")?; + validate_non_empty(&options.created_at, "created at")?; + let store_path = store_path.as_ref(); + initialize_runtime_spine( + store_path, + RuntimeSpineInitOptions { + runtime_id: options.runtime_id, + display_name: options.display_name, + created_at: options.created_at.clone(), + }, + )?; + ensure_runtime_session( + store_path, + RuntimeSpineSessionOptions { + session_id: options.session_id.clone(), + objective: options.objective, + created_at: options.created_at.clone(), + coordinator_note: options.coordinator_note, + }, + )?; + create_runtime_job( + store_path, + RuntimeSpineJobOptions { + job_id: options.job_id, + session_id: options.session_id, + role: options.role, + created_at: options.created_at, + summary: format!( + "Heartbeat activation queued for binding {} with authority {}.", + options.binding_id, options.authority_scope + ), + artifact_refs: Vec::new(), + }, + ) +} + pub fn runtime_job_snapshot( store_path: impl AsRef, job_id: &str, @@ -1403,6 +1464,38 @@ mod tests { Ok(()) } + #[test] + fn runtime_spine_opens_heartbeat_job_from_single_typed_call() -> Result<()> { + let temp = tempdir()?; + let store = temp.path().join("runtime.msgpack"); + + let job = open_runtime_spine_heartbeat_job( + &store, + RuntimeSpineHeartbeatJobOptions { + runtime_id: "epiphany-test".to_string(), + display_name: "Epiphany Test".to_string(), + session_id: "epiphany-main".to_string(), + objective: "Run heartbeat worker.".to_string(), + coordinator_note: "Test launch.".to_string(), + job_id: "heartbeat-job-1".to_string(), + role: "modeling".to_string(), + binding_id: "modeling-checkpoint-worker".to_string(), + authority_scope: "modeling".to_string(), + created_at: "2026-05-06T00:02:00Z".to_string(), + }, + )?; + + assert_eq!(job.job_id, "heartbeat-job-1"); + assert_eq!(job.session_id, "epiphany-main"); + assert_eq!(job.role, "modeling"); + let status = runtime_spine_status(&store)?; + assert_eq!(status.sessions, 1); + assert_eq!(status.jobs, 1); + assert_eq!(status.open_jobs, 1); + assert_eq!(status.events, 1); + Ok(()) + } + #[test] fn runtime_spine_emits_cultnet_hello_frame() -> Result<()> { let temp = tempdir()?; diff --git a/notes/codex-auth-spine-inventory.md b/notes/codex-auth-spine-inventory.md index 0480f166..f841b912 100644 --- a/notes/codex-auth-spine-inventory.md +++ b/notes/codex-auth-spine-inventory.md @@ -159,6 +159,12 @@ Codex-backed transport through the typed spine; its `smoke` command proves the CultCache route without touching the network. This is the first native caller for the advertised OpenAI CultNet contract. +The heartbeat/specialist runtime job opener has been moved to +`epiphany-core::open_runtime_spine_heartbeat_job`. Vendored Codex may still +call it while the app-server compatibility route survives, but the +initialize-runtime, ensure-session, and create-job sequence is now native +runtime-spine machinery rather than Codex thread machinery. + The bad news is useful: the current spine still drags in `codex-api` and its large transport dependency stack. That is tolerable as a sealed compatibility reliquary, but not as the final shape. The next purification should shrink the diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 4deff996..c5ff5117 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -588,6 +588,14 @@ storage route without network. The next cut is to move live callers from Codex app-server JSON-RPC onto this runtime route, then carve down the `codex-api` dependency weight. +The runtime-spine job-opening mechanism for heartbeat/specialist launches has +also been pulled into `epiphany-core` as `open_runtime_spine_heartbeat_job`. +Vendored `codex_core::CodexThread::epiphany_launch_job` still validates, +persists, and updates Codex thread state, but it no longer owns the +initialize-session-open-job sequence. That is a small cut, but a real ownership +move: native runtime lifecycle belongs to the runtime spine, not the Codex +thread wrapper. + 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. diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index 0a0ed1fba8b23ad15e8ecdd5da7e1ef62847fbc8..9817128a0285a50d3cc416c288d18714367f4088 100644 GIT binary patch delta 321 zcmY+Aze)o^5QkYIU}a-rB@C!t)|{tFaTXdM$IIOllYM%#p-pER8_hdr(BZ3 z^zSSU>-#W5lUWzyIyS@0ZthTJVC)#QDhdXlBN*jrgn?I-=zt9SYRC4$jw@8?kSA5p z70Lywfrf|f7$qY!S<}!V)}yQh2dHypNb@$Fprbwo_CG`L$e!z CodexResult<()> { let now = chrono::Utc::now().to_rfc3339_opts(chrono::SecondsFormat::Secs, true); - initialize_runtime_spine( + open_runtime_spine_heartbeat_job( store_path, - RuntimeSpineInitOptions { + RuntimeSpineHeartbeatJobOptions { runtime_id: "epiphany-local".to_string(), display_name: "Epiphany Local".to_string(), - created_at: now.clone(), - }, - ) - .map_err(|err| { - CodexErr::Fatal(format!( - "failed to initialize Epiphany runtime spine {}: {err}", - store_path.display() - )) - })?; - ensure_runtime_session( - store_path, - RuntimeSpineSessionOptions { session_id: "epiphany-main".to_string(), objective: state .objective .clone() .filter(|objective| !objective.trim().is_empty()) .unwrap_or_else(|| "Epiphany heartbeat activation".to_string()), - created_at: now.clone(), coordinator_note: "App-server launch opened this typed runtime session.".to_string(), - }, - ) - .map_err(|err| { - CodexErr::Fatal(format!( - "failed to ensure Epiphany runtime session in {}: {err}", - store_path.display() - )) - })?; - create_runtime_job( - store_path, - RuntimeSpineJobOptions { job_id: backend_job_id.to_string(), - session_id: "epiphany-main".to_string(), role: request.owner_role.clone(), + binding_id: request.binding_id.clone(), + authority_scope: request.authority_scope.clone(), created_at: now, - summary: format!( - "Heartbeat activation queued for binding {} with authority {}.", - request.binding_id, request.authority_scope - ), - artifact_refs: Vec::new(), }, ) .map_err(|err| { CodexErr::Fatal(format!( - "failed to open Epiphany runtime job {:?} in {}: {err}", + "failed to open Epiphany runtime spine job {:?} in {}: {err}", backend_job_id, store_path.display() ))