Repair runtime link authority in MVP loop

This commit is contained in:
Meta Vens 2026-05-28 20:30:51 +01:00
commit f996274a29
7 changed files with 211 additions and 30 deletions

View file

@ -27,9 +27,11 @@ use epiphany_core::evaluate_promotion;
use epiphany_core::open_runtime_spine_heartbeat_job;
use epiphany_core::plan_runtime_spine_heartbeat_launch;
use epiphany_core::replace_or_append_epiphany_job_binding;
use epiphany_core::runtime_job_snapshot;
use epiphany_state_model::EpiphanyEvidenceRecord;
use epiphany_state_model::EpiphanyJobKind as CoreEpiphanyJobKind;
use epiphany_state_model::EpiphanyRetrievalState;
use epiphany_state_model::EpiphanyRuntimeLink;
use epiphany_state_model::EpiphanyThreadState;
use crate::cultnet::EpiphanySurfaceSource;
@ -205,11 +207,21 @@ pub async fn launch_epiphany_job_on_thread(
// documents into Codex's JSON-RPC thread shell until CultNet owns the route.
let current_state = thread.epiphany_state().await.unwrap_or_default();
validate_expected_revision(request.expected_revision, current_state.revision)?;
let runtime_store = thread.epiphany_runtime_spine_store_path().await;
let completed_prior_link = terminal_runtime_link_for_binding(
&current_state,
request.binding_id.as_str(),
runtime_store.as_path(),
)?;
let mut planning_state = current_state.clone();
if let Some(link) = completed_prior_link.clone() {
planning_state.runtime_links.insert(0, link);
}
let launcher_job_id = format!("epiphany-heartbeat-launch-{}", Uuid::new_v4());
let backend_job_id = Uuid::new_v4().to_string();
let launch_plan = plan_runtime_spine_heartbeat_launch(
&current_state,
&planning_state,
RuntimeSpineHeartbeatLaunchPlanOptions {
binding_id: request.binding_id.clone(),
kind: request.kind,
@ -227,23 +239,22 @@ pub async fn launch_epiphany_job_on_thread(
},
)
.map_err(|err| EpiphanyBridgeError::InvalidRequest(err.to_string()))?;
let runtime_store = thread.epiphany_runtime_spine_store_path().await;
open_epiphany_runtime_spine_job(
runtime_store.as_path(),
&current_state,
&request,
backend_job_id.as_str(),
)?;
let next_job_bindings = replace_or_append_epiphany_job_binding(
current_state.job_bindings.clone(),
launch_plan.binding,
);
let mut runtime_links = Vec::new();
runtime_links.push(launch_plan.runtime_link.clone());
if let Some(link) = completed_prior_link {
runtime_links.push(link);
}
let validation_errors = epiphany_state_update_validation_errors(
&current_state,
&EpiphanyStateUpdate {
job_bindings: Some(next_job_bindings.clone()),
runtime_links: vec![launch_plan.runtime_link.clone()],
runtime_links: runtime_links.clone(),
..Default::default()
},
);
@ -253,13 +264,19 @@ pub async fn launch_epiphany_job_on_thread(
validation_errors.join("; ")
)));
}
open_epiphany_runtime_spine_job(
runtime_store.as_path(),
&planning_state,
&request,
backend_job_id.as_str(),
)?;
let epiphany_state = apply_epiphany_state_update_to_thread(
thread,
EpiphanyStateUpdate {
expected_revision: request.expected_revision,
job_bindings: Some(next_job_bindings),
runtime_links: vec![launch_plan.runtime_link],
runtime_links,
..Default::default()
},
)
@ -273,6 +290,36 @@ pub async fn launch_epiphany_job_on_thread(
})
}
fn terminal_runtime_link_for_binding(
state: &EpiphanyThreadState,
binding_id: &str,
runtime_store: &Path,
) -> BridgeResult<Option<EpiphanyRuntimeLink>> {
let Some(link) = state
.runtime_links
.iter()
.find(|link| link.binding_id == binding_id && !link.runtime_job_id.trim().is_empty())
else {
return Ok(None);
};
if link.runtime_result_id.is_some() {
return Ok(None);
}
let Some(snapshot) = runtime_job_snapshot(runtime_store, link.runtime_job_id.as_str())
.map_err(|err| EpiphanyBridgeError::Fatal(err.to_string()))?
else {
return Ok(None);
};
let Some(result) = snapshot.result else {
return Ok(None);
};
let mut terminal = link.clone();
terminal.id = format!("{}-{}", link.id, result.result_id);
terminal.surface = "runtimeResult".to_string();
terminal.runtime_result_id = Some(result.result_id);
Ok(Some(terminal))
}
pub async fn interrupt_epiphany_job_on_thread(
thread: &impl EpiphanyMutationHost,
request: EpiphanyJobInterruptRequest,

View file

@ -2780,10 +2780,10 @@ fn validate_heartbeat_launch_options(
.job_bindings
.iter()
.find(|binding| binding.id == options.binding_id);
let existing_runtime_link = state.runtime_links.iter().find(|link| {
let latest_runtime_link = state.runtime_links.iter().find(|link| {
link.binding_id == options.binding_id && !link.runtime_job_id.trim().is_empty()
});
if existing_runtime_link.is_some()
if latest_runtime_link.is_some_and(|link| link.runtime_result_id.is_none())
&& existing_binding.is_none_or(|binding| binding.blocking_reason.is_none())
{
return Err(anyhow!(
@ -3165,6 +3165,79 @@ mod tests {
assert_eq!(launch_plan.runtime_link.role_id, "epiphany-modeler");
}
#[test]
fn heartbeat_launch_allows_replacement_after_terminal_runtime_link() {
let mut state = EpiphanyThreadState::default();
state.runtime_links.push(EpiphanyRuntimeLink {
id: "runtime-link-modeling-checkpoint-worker-old".to_string(),
binding_id: "modeling-checkpoint-worker".to_string(),
surface: "runtimeResult".to_string(),
role_id: "epiphany-modeler".to_string(),
authority_scope: "epiphany.role.modeling".to_string(),
runtime_job_id: "old-turn".to_string(),
runtime_result_id: Some("result-old-turn".to_string()),
linked_subgoal_ids: Vec::new(),
linked_graph_node_ids: Vec::new(),
});
state.runtime_links.push(EpiphanyRuntimeLink {
id: "runtime-link-modeling-checkpoint-worker-stale-active".to_string(),
binding_id: "modeling-checkpoint-worker".to_string(),
surface: "jobLaunch".to_string(),
role_id: "epiphany-modeler".to_string(),
authority_scope: "epiphany.role.modeling".to_string(),
runtime_job_id: "stale-turn".to_string(),
runtime_result_id: None,
linked_subgoal_ids: Vec::new(),
linked_graph_node_ids: Vec::new(),
});
let launch_plan = plan_runtime_spine_heartbeat_launch(
&state,
RuntimeSpineHeartbeatLaunchPlanOptions {
binding_id: "modeling-checkpoint-worker".to_string(),
kind: EpiphanyJobKind::Specialist,
scope: "role-scoped modeling/checkpoint maintenance".to_string(),
owner_role: "epiphany-modeler".to_string(),
authority_scope: "epiphany.role.modeling".to_string(),
linked_subgoal_ids: Vec::new(),
linked_graph_node_ids: Vec::new(),
instruction: "Model the target before implementation.".to_string(),
launch_document: EpiphanyWorkerLaunchDocument::Role(
crate::EpiphanyRoleWorkerLaunchDocument {
thread_id: "thread-1".to_string(),
role_id: "modeling".to_string(),
state_revision: 7,
objective: None,
active_subgoal_id: None,
active_subgoals: Vec::new(),
active_graph_node_ids: Vec::new(),
investigation_checkpoint: None,
scratch: None,
invariants: Vec::new(),
graphs: None,
recent_evidence: Vec::new(),
recent_observations: Vec::new(),
graph_frontier: None,
graph_checkpoint: None,
planning: None,
churn: None,
},
),
output_contract_id: crate::ROLE_WORKER_OUTPUT_CONTRACT_ID.to_string(),
organ_launch_contract: crate::default_launch_organ_contract(
"epiphany.role.modeling",
"role",
crate::ROLE_WORKER_OUTPUT_CONTRACT_ID,
),
max_runtime_seconds: Some(60),
runtime_job_id: "new-turn".to_string(),
},
)
.expect("terminal runtime links should not block replacement launch");
assert_eq!(launch_plan.runtime_link.runtime_job_id, "new-turn");
}
#[test]
fn runtime_spine_emits_cultnet_hello_frame() -> Result<()> {
let temp = tempdir()?;

View file

@ -634,12 +634,12 @@ pub fn recommend_coordinator_action(
{
if !input.modeling_result_reviewable {
return build(
EpiphanyCoordinatorAction::LaunchModeling,
EpiphanyCoordinatorAction::ReviewModelingResult,
Some(EpiphanyCoordinatorRoleId::Modeling),
Some(EpiphanyCoordinatorSceneAction::RoleLaunch),
Some(EpiphanyCoordinatorSceneAction::RoleResult),
false,
true,
"The completed modeling/checkpoint finding is not reviewable because it has no acceptable statePatch; relaunch modeling with the typed patch contract before verification or implementation continues.",
false,
"The completed modeling/checkpoint finding has no acceptable statePatch; inspect the finding instead of relaunching the same lane.",
);
}
return build(
@ -1187,18 +1187,18 @@ mod tests {
);
assert!(!review_failed_modeling.can_auto_run);
let relaunch_unreviewable_modeling =
recommend_coordinator_action(EpiphanyCoordinatorInput {
signals: EpiphanyCoordinatorSignals {
modeling_result_status: EpiphanyCoordinatorRoleResultStatus::Completed,
verification_result_status: EpiphanyCoordinatorRoleResultStatus::MissingBinding,
},
..input()
});
let review_unreviewable_modeling = recommend_coordinator_action(EpiphanyCoordinatorInput {
signals: EpiphanyCoordinatorSignals {
modeling_result_status: EpiphanyCoordinatorRoleResultStatus::Completed,
verification_result_status: EpiphanyCoordinatorRoleResultStatus::MissingBinding,
},
..input()
});
assert_eq!(
relaunch_unreviewable_modeling.action,
EpiphanyCoordinatorAction::LaunchModeling
review_unreviewable_modeling.action,
EpiphanyCoordinatorAction::ReviewModelingResult
);
assert!(!review_unreviewable_modeling.can_auto_run);
let launch_verification = recommend_coordinator_action(EpiphanyCoordinatorInput {
signals: EpiphanyCoordinatorSignals {

View file

@ -141,7 +141,7 @@ fn overlay_job_binding(
return job;
}
if runtime_link.is_some() {
if runtime_link.is_some_and(|link| link.runtime_result_id.is_none()) {
job.status = EpiphanyJobStatus::Pending;
job.blocking_reason = None;
job.progress_note =
@ -149,6 +149,14 @@ fn overlay_job_binding(
return job;
}
if runtime_link.is_some() {
job.status = EpiphanyJobStatus::Completed;
job.blocking_reason = None;
job.progress_note =
Some("Epiphany heartbeat runtime result is ready for review.".to_string());
return job;
}
job
}
@ -501,4 +509,57 @@ mod tests {
Some("Queued for Epiphany heartbeat activation through runtime_links.")
);
}
#[test]
fn terminal_runtime_link_owns_binding_over_stale_active_history() {
let state = EpiphanyThreadState {
job_bindings: vec![EpiphanyJobBinding {
id: "binding-1".to_string(),
kind: EpiphanyJobKind::Specialist,
scope: "modeling".to_string(),
owner_role: "body".to_string(),
authority_scope: Some("epiphany.role.modeling".to_string()),
linked_subgoal_ids: Vec::new(),
linked_graph_node_ids: Vec::new(),
blocking_reason: None,
}],
runtime_links: vec![
EpiphanyRuntimeLink {
id: "link-terminal".to_string(),
binding_id: "binding-1".to_string(),
surface: "runtimeResult".to_string(),
role_id: "modeling".to_string(),
authority_scope: "epiphany.role.modeling".to_string(),
runtime_job_id: "runtime-job-1".to_string(),
runtime_result_id: Some("result-1".to_string()),
linked_subgoal_ids: Vec::new(),
linked_graph_node_ids: Vec::new(),
},
EpiphanyRuntimeLink {
id: "link-stale-active".to_string(),
binding_id: "binding-1".to_string(),
surface: "jobLaunch".to_string(),
role_id: "modeling".to_string(),
authority_scope: "epiphany.role.modeling".to_string(),
runtime_job_id: "runtime-job-1".to_string(),
runtime_result_id: None,
linked_subgoal_ids: Vec::new(),
linked_graph_node_ids: Vec::new(),
},
],
..Default::default()
};
let jobs = derive_jobs(EpiphanyJobsInput {
state: Some(&state),
retrieval_override: None,
});
let binding = jobs.iter().find(|job| job.id == "binding-1").unwrap();
assert_eq!(binding.status, EpiphanyJobStatus::Completed);
assert_eq!(
binding.progress_note.as_deref(),
Some("Epiphany heartbeat runtime result is ready for review.")
);
}
}

View file

@ -34,7 +34,7 @@ remembers doctrine; the branch remembers the blade.
- Do not copy exact branch or HEAD from this note. Run `git status --short --branch` and `git log --oneline -5`.
- The repo now has a one-command local operator path: `.\tools\epiphany_local_run.ps1`. Default mode is `smoke`; it builds the retained Codex app-server compatibility edge, builds native Epiphany operator binaries, runs the coordinator smoke, and writes launcher artifacts under `.epiphany-run/` plus coordinator artifacts under `.epiphany-dogfood/`. `-Mode status` is now Epiphany-native: it builds only Epiphany operator binaries, reads `state/thread-state.msgpack` when present, derives status through `epiphany-core`, and does not start or require `codex-app-server`. Use `-Mode plan` or `-Mode run -MaxSteps 4` for the raw bridge-equipped coordinator entrypoints; use `-Mode mvp -FaceInput "<operator request>" -MaxSteps 4` for the local product cycle that projects Face's character turn, writes a Face/Aquarium bubble, bootstraps a minimal local checkpoint for fresh threads, runs the coordinator with auto-tools, then runs heartbeat sleep/dream maintenance. Live plan/run/mvp modes use the workspace `state/runtime-spine.msgpack`, because CodexThread launch writes worker requests there; the run bundle remains artifact evidence, not runtime lifecycle authority. Add `-ThreadId <id>` and `-Workspace <path>` to inspect or continue an existing thread. `status`, `plan`, and `smoke` do not spend model calls; `run` and `mvp` build and use `epiphany-openai-runtime`. Coordinator workers now launch detached and are polled through runtime-spine instead of blocking the coordinator. MVP runs are non-ephemeral by default so `-ThreadId <id>` can resume and poll later. `-MaxRuntimeSeconds <n>` is passed into worker runtime; timeout writes a failed worker receipt and exits. Failed modeling now blocks downstream verification until the failed result is reviewed.
- Current Mom-ready status: the normal MVP pass reaches Face -> coordinator -> detached runtime -> heartbeat sleep, and the modeling worker can now complete through the ChatGPT subscription transport. The failure was a stack of violated observability/runtime invariants: worker prompts prepended the whole shared persistent-memory rite, Responses frame liveness was invisible until completion, and the runtime tried to persist hundreds of text deltas before completing the worker job. Role/reorient workers now get a compact Epiphany worker boundary instead of full persistent memory; runtime-spine records sampled raw Responses frame kinds with small previews; contiguous reasoning/text deltas compact before durable storage; and a 60-second live proof completed both `openai-worker-2fe38dcd-d99e-4c73-9a58-afcc81f851c7` and worker job `2fe38dcd-d99e-4c73-9a58-afcc81f851c7` with modeling verdict `regather-needed`. Next cut should run the status/acceptance path against that completed modeling result and verify the coordinator advances into verification rather than leaving late detached completion invisible.
- Current Mom-ready status: the normal MVP pass reaches Face -> coordinator -> detached runtime -> heartbeat sleep, and modeling workers now complete through the ChatGPT subscription transport. The first failure was a stack of violated observability/runtime invariants: worker prompts prepended the whole shared persistent-memory rite, Responses frame liveness was invisible until completion, and the runtime tried to persist hundreds of text deltas before completing the worker job. Role/reorient workers now get a compact Epiphany worker boundary instead of full persistent memory; runtime-spine records sampled raw Responses frame kinds with small previews; contiguous reasoning/text deltas compact before durable storage; and live proofs completed `2fe38dcd-d99e-4c73-9a58-afcc81f851c7`, `241e3851-e3ea-4877-a63b-0d2bbd96a7e2`, and `85149a26-6975-403f-ac93-092b717c5825` instead of timing out. The second failure was stale lifecycle authority: completed runtime jobs remained as unresolved `runtime_links`, replacement launches treated historical active links as current, and one bad validation path opened an orphan job before rejecting the state patch. Latest-link-wins is now the runtime-link invariant, terminal links project completed jobs, stale active history cannot veto replacement, launch validation happens before opening runtime jobs, and completed-but-unreviewable modeling findings stop for review instead of relaunching the same lane. The remaining concrete blocker is architectural: the MVP coordinator has no executable Eyes/source-gather lane. A modeler can return `regather-needed`, but it cannot inspect the missing stream-storage source itself; choose between adding a real research/Eyes specialist lane or routing this regather to the main implementation agent with explicit statePatch banking.
- Local operator runs now write typed CultMesh intent/receipt documents to `.epiphany-run/cultmesh/operator-runs.ccmp` through `epiphany-operator-run`. The wrapper writes intent before acting and a completion receipt after success; this is the local consent/trace rail, not a hidden scheduler queue.
- Status-mode local runs now also write a native CultMesh operator snapshot to `.epiphany-run/cultmesh/operator-snapshots.ccmp` through `epiphany-operator-snapshot`. That snapshot distills the operator-safe MVP status artifact into typed fields such as thread id, state status, coordinator action, CRRC action, reorient action, available actions, and artifact refs; it does not preserve the raw JSON status blob as internal state.
- `epiphany-mvp-status --source native` is the current provider-neutral status boundary. It projects scene, pressure, jobs, roles, planning, reorient, CRRC, coordinator status, and runtime-linked worker lifecycle from native core surfaces. It reads runtime-spine job/result receipts for linked jobs so failed workers show as failed in role results, jobs, roles, and coordinator source signals, while successful semantic findings still require typed role/reorient worker result documents. Keep future pluggable model-provider work behind launch/result/runtime documents; do not let provider choice leak into status, prompt authority, scheduler policy, or durable `EpiphanyThreadState`.

Binary file not shown.

View file

@ -72,7 +72,7 @@ active_subgoals:
- Use `notes/epiphany-cultmesh-dreaming-roadmap.md` as the design authority for distributed Epiphany dreaming. Public dreams are separately authored typed documents distributed through CultMesh/CultNet; private state remains local and cannot be shared by flipping a visibility flag. Foreign dreams are external thought weather until a reviewed local adoption receipt digests them into memory, planning, doctrine, or governance.
- CultMesh is now the preferred ergonomic Rust abstraction over CultCache and CultNet for Epiphany-owned local database surfaces. The Rust substrate is repo-contained under `vendor/cultcache-rs`, `vendor/cultnet-rs`, and `vendor/cultmesh-rs`; the old `E:\Projects\CultLib\crates\*` path is dead in this checkout and must not be reintroduced as a compile-time dependency. Future local Verse/dream/status work should start at CultMesh unless it is explicitly polishing CultMesh internals. Preserve the three-Verse boundary: `epiphany-internal` for private sub-agent typed state, `gamecult-local` for trusted LAN/Yggdrasil-tunnel GameCult project sharing, and `epiphany-global` for untrusted public dreams plus topic-specific threaded public rooms for Face posts.
- The active priority is Codex starvation and CultNet liberation. Use `notes/codex-starvation-and-cultnet-liberation-plan.md` as the directive and `notes/codex-auth-spine-inventory.md` as the source-grounded keeper list for the retained OpenAI subscription auth/model transport bridge. Classify all Epiphany-relevant JSON contamination, define the native CultNet runtime boundary, keep worker launch/result/selfPatch cargo as typed documents, evacuate Epiphany operator/state/process authority from Codex JSON-RPC, wrap MCP's unavoidable JSON protocol edge in typed Epiphany intent/result/receipt documents, and keep cutting until Epiphany can run its own state and processes without `codex_message_processor.rs` except for bridge compatibility.
- The next Codex-starvation slice is post-worker result acceptance/status hardening after the Mom-ready modeling worker proof. The quarantined Codex MCP spine may execute typed tool intents and emit typed receipts; the model runtime can build and run provider-neutral follow-up turns from those receipts; coordinator run mode passes the quarantined tool adapter into worker runtime with auto-tools enabled by default; worker runtime now enforces max-runtime with one timeout close primitive for both tokio timeout and watchdog paths; inner `openai-worker-*` jobs are opened before async auth/stream waits and sealed with their outer worker on timeout; native status/roles/jobs/coordinator surfaces project failed runtime-linked jobs as terminal without Codex prompt or scheduler authority; direct tiny model-turn transport succeeds; worker requests record request metrics, transport readiness, and sampled raw Responses frame kinds; worker prompts no longer prepend the full shared persistent-memory rite; stream deltas compact before durable storage; and a 60-second live MVP proof completed both the OpenAI runtime job and modeling worker job instead of timing out.
- The next Codex-starvation slice is the Eyes/source-gathering fork exposed by the Mom-ready MVP proof. The quarantined Codex MCP spine may execute typed tool intents and emit typed receipts; the model runtime can build and run provider-neutral follow-up turns from those receipts; coordinator run mode passes the quarantined tool adapter into worker runtime with auto-tools enabled by default; worker runtime now enforces max-runtime with one timeout close primitive for both tokio timeout and watchdog paths; inner `openai-worker-*` jobs are opened before async auth/stream waits and sealed with their outer worker on timeout; native status/roles/jobs/coordinator surfaces project failed and completed runtime-linked jobs as terminal without Codex prompt or scheduler authority; direct tiny model-turn transport succeeds; worker requests record request metrics, transport readiness, and sampled raw Responses frame kinds; worker prompts no longer prepend the full shared persistent-memory rite; stream deltas compact before durable storage; live MVP modeling workers complete instead of timing out; stale completed runtime links no longer block replacement launches; jobLaunch validates before opening runtime jobs; and completed-but-unreviewable modeling findings now stop for review instead of relaunching the same blind lane. The remaining blocker is structural: the MVP coordinator has no executable Eyes/source-gather lane, so a modeler that returns `regather-needed` cannot inspect the missing source itself.
- The May 2026 teardown/rebuild migration in `notes/epiphany-ideal-architecture-rebuild-plan.md` is closed unless a concrete regression reopens it. Preserve the new foundation: Epiphany view/coordinator policy lives in `epiphany-core`, runtime-spine owns job/result lifecycle identity through `runtime_links`, duplicate acceptance is receipt-keyed, public findings stay typed/sealed, view expansion requires a core contract, and app-server remains routing/adaptation rather than a second policy throne.
- Treat Phase 5 update/distill/propose/promote/read/notification as complete enough unless a concrete regression appears.
- Preserve read-only boundaries for retrieve, distill, propose, freshness, context, graphQuery, roleResult, reorientResult, and the canonical view lenses for scene, jobs, roles, planning, pressure, reorient, crrc, and coordinator.
@ -569,4 +569,4 @@ current_status:
materializes complete MCP-shaped model tool calls as typed tool invocation
intents, and the Codex MCP spine can consume those intents from the mixed
runtime-spine store and emit typed success/failure receipts.
next_action: Run the Mom-ready MVP status/acceptance path against the completed modeling worker result and verify the coordinator advances through verification without treating late worker completion as invisible. Use `epiphany-runtime-spine list-jobs`, `list-events`, and `list-model-requests` to keep lifecycle, stream, and request-size invariants visible.
next_action: Decide and implement the Eyes/source-gathering fork before another MVP automation pass: either add a real research/Eyes specialist lane that can gather the missing stream-storage source and return a reviewable statePatch, or route regather-needed modeling findings to the main implementation agent for supervised source inspection and manual statePatch banking. Do not relaunch modeling as a substitute for source access.