Move heartbeat job opening into runtime spine

This commit is contained in:
Meta Vens 2026-05-13 06:02:39 +01:00
commit 8311abe01a
7 changed files with 118 additions and 41 deletions

View file

@ -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;

View file

@ -320,6 +320,20 @@ pub struct RuntimeSpineJobResultOptions {
pub artifact_refs: Vec<String>,
}
#[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<Path>,
options: RuntimeSpineHeartbeatJobOptions,
) -> Result<EpiphanyRuntimeJob> {
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<Path>,
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()?;

View file

@ -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

View file

@ -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.

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, seventeen 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`, and the first native runtime caller in `epiphany-openai-runtime`. The bridge owns Codex-facing Epiphany adapters for scene, jobs, context/planning/graph query, retrieval, result projection, runtime-spine result adaptation, launch/prompt doctrine, mutation document mechanics, 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 and mutation orchestration. The processor is about 10,339 lines, `epiphany_mutation_routes.rs` is about 1,071 lines, and `epiphany_state_helpers.rs` is down to a 19-line rollout-state loader. `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`, and maps deltas/completion into typed stream events and receipts. `epiphany-openai-runtime` writes OpenAI status/request/stream-event/receipt records plus runtime sessions/jobs/results/events into `epiphany-core::runtime_spine_cache`, and its smoke proves the route without network. `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 live callers move.
next_action: Continue Codex starvation by moving live model-turn callers from `thread/epiphany/*` JSON-RPC / `codex_message_processor.rs` onto `epiphany-openai-runtime` or the same native CultNet contract. Then shrink the surviving Codex dependency surface to credential refresh, provider/model routing, and the smallest OpenAI Responses call required for Codex subscription compatibility. Do not add Codex app-server, apps, skills, marketplace, or new Epiphany JSON-RPC dependencies.
summary: The Codex starvation pass has five typing receipts, seventeen 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`, and a native heartbeat runtime job opener in `epiphany-core`. The bridge owns Codex-facing Epiphany adapters for scene, jobs, context/planning/graph query, retrieval, result projection, runtime-spine result adaptation, launch/prompt doctrine, mutation document mechanics, 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 and mutation orchestration. The processor is about 10,339 lines, `epiphany_mutation_routes.rs` is about 1,071 lines, and `epiphany_state_helpers.rs` is down to a 19-line rollout-state loader. `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`, and maps deltas/completion into typed stream events and receipts. `epiphany-openai-runtime` writes OpenAI status/request/stream-event/receipt records plus runtime sessions/jobs/results/events into `epiphany-core::runtime_spine_cache`, and its smoke proves the route without network. `epiphany-core::open_runtime_spine_heartbeat_job` now owns the initialize-runtime/ensure-session/create-job sequence that vendored `CodexThread::epiphany_launch_job` used to perform inline. `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 live callers move.
next_action: Continue Codex starvation by moving more launch/mutation ownership out of vendored `codex_core::CodexThread` and `codex_message_processor.rs`: next extract job-launch validation/binding/runtime-link state mechanics into `epiphany-core` or `epiphany-codex-bridge`, leaving Codex as persistence/JSON-RPC compatibility only. Then move live model-turn callers onto `epiphany-openai-runtime` or the same native CultNet contract and shrink the surviving Codex dependency surface to credential refresh, provider/model routing, and the smallest OpenAI Responses call required for Codex subscription compatibility.

View file

@ -57,12 +57,8 @@ use codex_protocol::protocol::W3cTraceContext;
use codex_protocol::user_input::UserInput;
use codex_utils_absolute_path::AbsolutePathBuf;
use epiphany_core::EpiphanyWorkerLaunchDocument;
use epiphany_core::RuntimeSpineInitOptions;
use epiphany_core::RuntimeSpineJobOptions;
use epiphany_core::RuntimeSpineSessionOptions;
use epiphany_core::create_runtime_job;
use epiphany_core::ensure_runtime_session;
use epiphany_core::initialize_runtime_spine;
use epiphany_core::RuntimeSpineHeartbeatJobOptions;
use epiphany_core::open_runtime_spine_heartbeat_job;
use rmcp::model::ReadResourceRequestParams;
use std::collections::HashMap;
use std::collections::HashSet;
@ -878,56 +874,28 @@ fn open_epiphany_runtime_spine_job(
backend_job_id: &str,
) -> 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()
))