Add native coordinator interruption

This commit is contained in:
Meta Vens 2026-07-12 00:46:53 +01:00
commit a6965012a6
8 changed files with 236 additions and 9 deletions

View file

@ -195,7 +195,10 @@ impl Args {
fn run_status(args: &Args) -> Result<Value> {
if args.interrupt_binding.is_some() {
return run_codex_interrupt(args);
return match args.source {
StatusSource::Native => run_native_interrupt(args),
StatusSource::Codex => run_codex_interrupt(args),
};
}
match args.source {
StatusSource::Native => run_native_status(args),
@ -203,6 +206,46 @@ fn run_status(args: &Args) -> Result<Value> {
}
}
fn run_native_interrupt(args: &Args) -> Result<Value> {
let thread_id = args
.thread_id
.as_ref()
.ok_or_else(|| anyhow!("--interrupt-binding requires --thread-id"))?;
let binding_id = args
.interrupt_binding
.as_ref()
.ok_or_else(|| anyhow!("--interrupt-binding requires a binding id"))?;
let store = absolute_path(&args.thread_state_store)?;
let runtime_store = absolute_path(&args.runtime_store)?;
if store != runtime_store {
return Err(anyhow!(
"native interruption requires one unified thread/runtime store"
));
}
let service = epiphany_core::EpiphanyCoordinatorService::new(&store, &runtime_store);
let state = service
.state()?
.ok_or_else(|| anyhow!("cannot interrupt without native coordinator state"))?;
let result = service.interrupt_job(
thread_id,
&state,
epiphany_core::EpiphanyJobInterruptRequest {
expected_revision: Some(state.revision),
binding_id: binding_id.clone(),
reason: args.interrupt_reason.clone(),
},
)?;
Ok(json!({
"source": "native",
"threadId": thread_id,
"bindingId": result.binding_id,
"revision": result.epiphany_state.revision,
"cancelRequested": result.cancel_requested,
"interruptedThreadIds": result.interrupted_thread_ids,
"epiphanyState": result.epiphany_state,
}))
}
fn run_codex_interrupt(args: &Args) -> Result<Value> {
if args.source != StatusSource::Codex {
return Err(anyhow!(
@ -1865,6 +1908,61 @@ fn home_dir() -> PathBuf {
.unwrap_or_else(|| PathBuf::from("."))
}
#[cfg(test)]
mod native_interrupt_tests {
use super::*;
use epiphany_state_model::{EpiphanyJobBinding, EpiphanyJobKind};
#[test]
fn default_status_interrupt_uses_native_coordinator_state() -> Result<()> {
let temp = tempfile::tempdir()?;
let store = temp.path().join("status-interrupt.cc");
let service = epiphany_core::EpiphanyCoordinatorService::new(&store, &store);
service.apply_state_update(
"thread-1",
epiphany_core::EpiphanyStateUpdate {
expected_revision: Some(0),
job_bindings: Some(vec![EpiphanyJobBinding {
id: "modeling-worker".to_string(),
kind: EpiphanyJobKind::Specialist,
scope: "model".to_string(),
owner_role: "modeling".to_string(),
authority_scope: Some("model".to_string()),
linked_subgoal_ids: Vec::new(),
linked_graph_node_ids: Vec::new(),
blocking_reason: None,
}]),
..Default::default()
},
None,
)?;
let args = Args {
source: StatusSource::Native,
app_server: PathBuf::new(),
codex_home: PathBuf::new(),
thread_id: Some("thread-1".to_string()),
cwd: temp.path().to_path_buf(),
thread_state_store: store.clone(),
runtime_store: store,
ephemeral: true,
json: true,
result: None,
transcript: PathBuf::new(),
stderr: PathBuf::new(),
interrupt_binding: Some("modeling-worker".to_string()),
interrupt_reason: Some("native status proof".to_string()),
};
let result = run_status(&args)?;
assert_eq!(result["source"], "native");
assert_eq!(result["cancelRequested"], false);
assert_eq!(
result["epiphanyState"]["job_bindings"][0]["blocking_reason"],
"native status proof"
);
Ok(())
}
}
pub fn absolute_path(path: &Path) -> Result<PathBuf> {
if path.is_absolute() {
Ok(path.to_path_buf())

View file

@ -0,0 +1,108 @@
use crate::*;
use anyhow::{Result, anyhow};
use epiphany_state_model::EpiphanyThreadState;
use std::path::Path;
pub fn interrupt_coordinator_job(
store: &Path,
thread_id: &str,
state: &EpiphanyThreadState,
request: EpiphanyJobInterruptRequest,
) -> Result<EpiphanyJobInterruptResult> {
if request.binding_id.trim().is_empty() {
return Err(anyhow!(
"epiphany job interrupt binding_id must be non-empty"
));
}
if let Some(expected) = request.expected_revision
&& expected != state.revision
{
return Err(anyhow!(
"epiphany state revision mismatch: expected {expected}, found {}",
state.revision
));
}
let binding_index = state
.job_bindings
.iter()
.position(|binding| binding.id == request.binding_id)
.ok_or_else(|| {
anyhow!(
"epiphany job binding {:?} was not found",
request.binding_id
)
})?;
let reason = request
.reason
.as_deref()
.map(str::trim)
.filter(|reason| !reason.is_empty())
.unwrap_or(
"No active heartbeat turn is currently bound; launch explicitly to resume specialist work.",
);
let applied = apply_coordinator_state_update(
store,
thread_id,
EpiphanyStateUpdate {
expected_revision: request.expected_revision,
job_bindings: Some(clear_epiphany_job_binding_backend(
state.job_bindings.clone(),
binding_index,
reason,
)),
..Default::default()
},
None,
)?;
Ok(EpiphanyJobInterruptResult {
epiphany_state: applied.state,
binding_id: request.binding_id,
cancel_requested: false,
interrupted_thread_ids: Vec::new(),
})
}
#[cfg(test)]
mod tests {
use super::*;
use epiphany_state_model::EpiphanyJobBinding;
#[test]
fn native_interrupt_updates_the_canonical_binding_once() -> Result<()> {
let temp = tempfile::tempdir()?;
let store = temp.path().join("interrupt.cc");
let state = EpiphanyThreadState {
job_bindings: vec![EpiphanyJobBinding {
id: "modeling-worker".to_string(),
kind: epiphany_state_model::EpiphanyJobKind::Specialist,
scope: "model".to_string(),
owner_role: "modeling".to_string(),
authority_scope: Some("model".to_string()),
linked_subgoal_ids: Vec::new(),
linked_graph_node_ids: Vec::new(),
blocking_reason: None,
}],
..Default::default()
};
let result = interrupt_coordinator_job(
&store,
"thread-1",
&state,
EpiphanyJobInterruptRequest {
expected_revision: Some(0),
binding_id: "modeling-worker".to_string(),
reason: Some("operator interrupted".to_string()),
},
)?;
assert_eq!(result.epiphany_state.revision, 1);
assert_eq!(
result.epiphany_state.job_bindings[0]
.blocking_reason
.as_deref(),
Some("operator interrupted")
);
assert!(!result.cancel_requested);
assert_eq!(read_coordinator_state(&store)?, Some(result.epiphany_state));
Ok(())
}
}

View file

@ -1,6 +1,8 @@
use crate::EpiphanyCoordinatorReorientResultSnapshot;
use crate::EpiphanyCoordinatorRoleResultSnapshot;
use crate::EpiphanyCoordinatorStateApplied;
use crate::EpiphanyJobInterruptRequest;
use crate::EpiphanyJobInterruptResult;
use crate::EpiphanyJobLaunchRequest;
use crate::EpiphanyJobLaunchResult;
use crate::EpiphanyNativeReorientAcceptance;
@ -11,6 +13,7 @@ use crate::accept_coordinator_reorient_finding;
use crate::accept_coordinator_role_finding;
use crate::apply_coordinator_state_update;
use crate::commit_coordinator_job_launch;
use crate::interrupt_coordinator_job;
use crate::plan_coordinator_job_launch;
use crate::read_coordinator_state;
use crate::read_reorient_result_snapshot;
@ -161,6 +164,15 @@ impl EpiphanyCoordinatorService {
update_investigation_checkpoint,
)
}
pub fn interrupt_job(
&self,
thread_id: &str,
state: &EpiphanyThreadState,
request: EpiphanyJobInterruptRequest,
) -> Result<EpiphanyJobInterruptResult> {
interrupt_coordinator_job(&self.thread_state_store, thread_id, state, request)
}
}
#[cfg(test)]
@ -170,7 +182,7 @@ mod tests {
let source = include_str!("coordinator_service.rs");
let production = source.split("#[cfg(test)]").next().unwrap_or(source);
assert!(
production.lines().count() < 175,
production.lines().count() < 190,
"coordinator facade regrew into a host brain"
);
for forbidden in [

View file

@ -3,6 +3,7 @@ mod agent_memory;
mod agent_utterance_state;
mod continuity_gateway;
mod coordinator_acceptance;
mod coordinator_interrupt;
mod coordinator_launch;
mod coordinator_launch_context;
mod coordinator_results;
@ -146,6 +147,7 @@ pub use coordinator_acceptance::reorient_acceptance_claimed_effects;
pub use coordinator_acceptance::role_acceptance_claimed_effects;
pub use coordinator_acceptance::role_acceptance_enforceable_receipts;
pub use coordinator_acceptance::state_update_from_role_patch;
pub use coordinator_interrupt::interrupt_coordinator_job;
pub use coordinator_launch::EpiphanyCoordinatorJobLaunchPlan;
pub use coordinator_launch::commit_coordinator_job_launch;
pub use coordinator_launch::plan_coordinator_job_launch;

View file

@ -1878,9 +1878,12 @@ survives there. The route-vocabulary audit is complete: active worker contracts
now name typed coordinator capabilities and Mind-admitted `statePatch` cargo;
status defaults to native; remaining Rust occurrences are explicit `--codex`
compatibility, phase-6 app-server contract smokes, negative tests, or a
historical-input fixture. The next live CLI fault is `--interrupt-binding`,
which still refuses native source and must route through the native coordinator
service before Codex interruption is demoted to explicit compatibility only.
historical-input fixture. Native `--interrupt-binding` is now live:
`interrupt_coordinator_job` owns revision/binding validation and canonical
binding mutation, while status reports `cancelRequested=false` honestly. A
focused core test and status-command test prove the transition. Explicit
`--codex` retains compatibility. The bridge still duplicates interruption
choreography; delegate it to `EpiphanyCoordinatorService::interrupt_job` next.
## Immediate Re-entry Instruction

View file

@ -264,6 +264,10 @@ now describe typed coordinator capabilities and Mind-admitted `statePatch`
cargo. `epiphany-mvp-status` defaults to native state; its route calls exist only
behind explicit `--codex` compatibility. `epiphany-phase6-*-smoke` binaries are
compatibility contract probes, coordinator source occurrences are negative
tests, and the distillation occurrence is a historical-input test fixture. The
live status gap is interruption: `--interrupt-binding` still requires the
explicit Codex source instead of a native coordinator operation.
tests, and the distillation occurrence is a historical-input test fixture.
Interruption now has a native owner. `interrupt_coordinator_job` validates the
binding and revision, records the operator reason through the canonical state
owner, and reports `cancelRequested=false` rather than inventing backend
cancellation. `epiphany-mvp-status --interrupt-binding` uses this path by
default; `--codex` selects the compatibility route explicitly. The bridge still
contains its older interruption choreography and should delegate next.

Binary file not shown.

View file

@ -659,4 +659,4 @@ current_status:
- Service lifecycle receipt history is now event-only: `load_epiphany_cultmesh_daemon_service_lifecycle_receipts` filters out the `epiphany-local/daemon-service-lifecycle-receipt/latest` mirror, while `load_latest_epiphany_cultmesh_daemon_service_lifecycle_receipt` remains the latest-state reader. Focused unit test `service_lifecycle_receipt_history_excludes_latest_mirror` proves two per-receipt writes return exactly two history records and latest points at the second. Fresh smoke `verse-query-lifecycle-history-filter-smoke` and live overview/triage `local-20260618-145632-497-efac6f0d` / `local-20260618-145632-321-867947af` prove compact swarm sights still expose service lifecycle attention plus the present elevated runbook artifact without daemon pokes or service mutation. Do not use a broad unscoped cargo test filter for this check on Windows; it fans out across bin harnesses and hit a broken pipe during this pass.
- `epiphany-verse-query seed-compact` is the compact seed receipt for wrappers and read-only rites. The older `seed` command still prints the full local Verse context for explicit debugging, but compact wrapper modes now avoid full `seed`/final `query` readback after the combined overview proof exposed Windows debug stack overflow from full-context serialization pressure.
last_completed_repo_swarm_cut: Huginn live-fire has crossed the first real repo Body from Persona pressure to branch-local Hands commit and Soul/Mind closure, and now has repeatable closure and redacted-public-proof mouths. On `E:\Projects\Huginn` branch `epiphany/huginn/first-awakening`, `tools/epiphany_local_run.ps1 -Mode repo-persona-intake` accepted item `huginn-inspection-readback-livefire`, Weksa/Persona intake remained sealed, and `epiphany-work derive-plan` lowered it to model-authored safe family `repo.status_section` for `README.md` only. `tools/epiphany_local_run.ps1 -Mode repo-swarm-run` advanced four bounded pulses: run-from-plan, adopt-from-plan, execute-from-plan, and close-from-execute. Huginn commit `e9b07c38fceabbdc89ea35c2156326c80c0393a2` updated only `README.md`; closure receipt `.epiphany\work\work-close-huginn-inspection-readback-livefire.json` records status `closed`, Soul verdict `passed`, Mind state commit `repo-work-close-huginn-inspection-readback-livefire-mind-commit`, safe family `repo.status_section`, path scope `README.md`, Bifrost publication gate, and `privateStateExposed=false`. Verification also ran Huginn's TypeScript compiler through concrete Node path: `C:\Program Files\nodejs\node.exe E:\Projects\Huginn\node_modules\typescript\bin\tsc -p tsconfig.json` passed. Native verifier `epiphany-repo-livefire-closure-smoke --workspace E:\Projects\Huginn --item huginn-inspection-readback-livefire --expected-path README.md --expected-family repo.status_section --expected-gate awaiting-publication --expected-blocker bifrost-publication-missing` checks closure receipt, Mind map entry, overview gate/blocker, authority seals, and `git show` changed paths, returning `status=ok`, `soulVerdict=passed`, `publicationGate=Bifrost`, and `privateStateExposed=false`. Wrapper `tools/epiphany_local_run.ps1 -Mode repo-livefire-closure -Workspace E:\Projects\Huginn -RepoWorkItem huginn-inspection-readback-livefire -SkipBuild` exposes the same read-only proof through the local operator mouth; artifact `local-20260621-190156-803-2f85ba15` printed commit, path, gate, blocker, Soul verdict, Mind commit receipt, and `privateStateExposed=False` without push, merge, publication, or target mutation. New wrapper `tools/epiphany_local_run.ps1 -Mode repo-work-public-proof -Workspace E:\Projects\Huginn -RepoWorkItem huginn-inspection-readback-livefire -SkipBuild` exports the redacted proof bundle and repo-local Verse index without publishing; artifact `local-20260621-190645-345-4555b1dc` wrote `.epiphany\public\proof-bundles\repo-work-public-proof-huginn-inspection-readback-livefire.json`, proof id `repo-work-public-proof-huginn-inspection-readback-livefire`, SHA-256 `857545b199f3e37eb06c2e757e5cfc201958e46667bb1f8403fd333a22620f63`, nine artifact rows, zero publication rows, and `privateStateExposed=False`. Gjallar readback `local-20260621-190701-140-b9519ec6` sees the `REPO-WORK-PUBLIC-PROOF` row and action row from Huginn's repo-local Verse with the same SHA-256 while Bifrost publication remains missing. Launcher compact modes are now named compact operator-context modes instead of read-only modes, and `bifrost-public-proof` summaries print item, target public Verse, room, proof SHA-256, review receipts, and credit receipts so publication receipts are auditable without claiming upstream sync.
next_action: Implement native `epiphany-mvp-status --interrupt-binding` over `EpiphanyCoordinatorService`, then keep `--codex` interruption as explicit compatibility only. Route vocabulary is absent from active worker contracts and native role/status projections; remaining source occurrences are classified compatibility probes, negative tests, or historical fixtures.
next_action: Delete the compatibility bridge's duplicate interruption choreography by delegating it to `EpiphanyCoordinatorService::interrupt_job`, then source-guard the bridge against regrowing binding mutation policy. Native status interruption is live by default; `--codex` is explicit compatibility.