Add Epiphany MVP coordinator

This commit is contained in:
Meta Vens 2026-04-28 18:43:46 +01:00
commit b7f4a03ff8
16 changed files with 1773 additions and 31 deletions

View file

@ -75,10 +75,12 @@ The landed machine now has:
- read-only Phase 6 reorient-worker result read-back through `thread/epiphany/reorientResult`
- explicit Phase 6 reorient-worker finding acceptance through `thread/epiphany/reorientAccept`
- read-only Phase 6 CRRC coordinator recommendation through `thread/epiphany/crrc`
- read-only Phase 6 fixed-lane MVP coordinator recommendation through `thread/epiphany/coordinator`, composing roles, pressure, reorient, CRRC, role results, and reorient result without mutation
- read-only Phase 6 role ownership through `thread/epiphany/roles`, projecting implementation, modeling/checkpoint, verification/review, and reorientation lanes from typed state plus jobs/CRRC/result signals
- explicit Phase 6 role launch/read-back through `thread/epiphany/roleLaunch` and read-only `thread/epiphany/roleResult`, limited to fixed modeling/checkpoint and verification/review templates over the existing job-control seam
- first Phase 6 dogfood operator view through `tools/epiphany_mvp_status.py`
- first auditable Phase 6 dogfood runner through `tools/epiphany_mvp_dogfood.py`, producing local status snapshots, raw app-server transcript, final status artifacts, vanilla-reference output, and comparison notes
- first auditable Phase 6 fixed-lane coordinator runner through `tools/epiphany_mvp_coordinator.py`, producing coordinator summary, JSONL steps, rendered snapshots, transcript, stderr, and final next-action artifacts while keeping semantic findings review-gated by default
- first auditable Phase 6 live-specialist runner through `tools/epiphany_mvp_live_specialist.py`, proving `roleLaunch -> agent_jobs worker -> report_agent_job_result -> roleResult` without manual backend completion
- live Phase 6 reorientation app-server smoke coverage in `tools/epiphany_phase6_reorient_smoke.py`
- live Phase 6 reorient-launch app-server smoke coverage in `tools/epiphany_phase6_reorient_launch_smoke.py`
@ -108,6 +110,7 @@ These boundaries are more important than the individual method names:
- `thread/epiphany/pressure` is a context-pressure reflection, not an automatic compactor, scheduler, or CRRC coordinator.
- `thread/epiphany/reorient` is a bounded policy verdict, not an automatic runtime coordinator, scheduler, compactor, or hidden state writer.
- `thread/epiphany/crrc` is a read-only coordinator recommendation over existing signals, not a scheduler, launch button, acceptance gate, compactor, or hidden state writer.
- `thread/epiphany/coordinator` is a read-only fixed-lane MVP policy projection over existing signals, not a scheduler, launcher, acceptance gate, compactor, or hidden state writer.
- `thread/epiphany/roles` is a read-only role ownership projection, not a specialist scheduler, marketplace, launcher, acceptance gate, or second job backend.
- `thread/epiphany/roleLaunch` is a bounded authority surface for fixed modeling/checkpoint and verification/review templates, not a broad scheduler or specialist marketplace.
- `thread/epiphany/roleResult` is a read-only result projection, not a promotion gate, state writer, scheduler, or hidden continuation trigger.
@ -185,24 +188,30 @@ specialist-agent role; it watches context pressure and continuity, persists
state, triggers compact/rehydrate/reorient behavior, and may launch a bounded
reorient-worker specialist when semantic regathering is needed.
The read-back, acceptance, coordinator, first dogfood-view, first
The read-back, acceptance, CRRC recommendation, first dogfood-view, fixed-lane
coordinator, first
harness-native role ownership, and first fixed role specialist launch/result
blockers are now landed as
`thread/epiphany/reorientResult`, `thread/epiphany/reorientAccept`,
`thread/epiphany/crrc`, `tools/epiphany_mvp_status.py`, and
`thread/epiphany/crrc`, `tools/epiphany_mvp_status.py`,
`thread/epiphany/coordinator`, `tools/epiphany_mvp_coordinator.py`, and
`thread/epiphany/roles`, `thread/epiphany/roleLaunch`, and
`thread/epiphany/roleResult`. A human can now ask the harness what it believes,
what it recommends, which role lane owns the next visible work, explicitly
launch modeling/checkpoint or verification/review workers, and read their
findings back without reading Rust. The first auditable dogfood pass then added
what it recommends, which role lane owns the next visible work, which fixed-lane
action should happen next, explicitly launch modeling/checkpoint or
verification/review workers, and read their findings back without reading Rust.
The first auditable dogfood pass then added
`tools/epiphany_mvp_dogfood.py`, rendered modeling/verification findings in the
status view, and fixed CRRC's repeat-acceptance recommendation after
`reorientAccept`. The live-specialist runner then proved the real worker path by
launching a modeling/checkpoint specialist, letting it inspect the smoke
workspace, report through `report_agent_job_result`, and return a completed
`checkpoint-ready` finding through `roleResult`. The next MVP question is human
operator testing, not another imagined organ: use the landed loop and artifact
bundle, then fix only concrete blockers.
`checkpoint-ready` finding through `roleResult`. The coordinator runner then
proved the sequence-locked MVP policy across cold start, clean checkpoint,
modeling, verification, CRRC drift/reorient, and high-pressure compact/dry-run
paths. The next MVP question is human operator testing, not another imagined
organ: use the landed coordinator/status/artifact loop, then fix only concrete
blockers.
## Phase 6 Direction
@ -210,9 +219,9 @@ Phase 6 should grow observable harness state outward from the typed spine.
Useful candidates:
1. Put the CLI MVP in front of a human operator through status/artifact review, then fix concrete usability blockers.
1. Put the fixed-lane coordinator MVP in front of a human operator through status/artifact review, then fix concrete usability blockers.
2. Keep accepted worker findings review-gated; do not convert acceptance into automatic promotion of arbitrary worker output.
3. Design the smallest fixed-lane coordinator that can recommend or launch the next modeling, implementation, verification, or CRRC-automation handoff without becoming a broad ambient dispatcher.
3. After the coordinator artifacts prove the policy, add only limited safe-boundary CRRC automation: compact/resume/reorient or launch a bounded reorient-worker when the coordinator says it is safe, without silently accepting semantic findings.
Do not spend Phase 6 polishing Phase 5 out of anxiety. The Phase 5 smoke harness
is a regression guardrail, not a ritual drum circle for summoning more tiny
@ -227,7 +236,7 @@ These remain later work:
- richer evidence and graph-shard inspection beyond the landed targeted context read
- richer role ergonomics after the fixed single-user coordinator proves useful
- mutation gates that warn or block broad writes when map freshness is stale
- automatic CRRC runtime coordination on top of the landed typed context-pressure telemetry
- broader CRRC runtime coordination beyond the narrow safe-boundary actions proved by the MVP coordinator
- GUI workflows for graph, evidence, job, invariant, and frontier steering
Do not start these from vibes. Each one needs a source-grounded slice plan and a
@ -283,6 +292,12 @@ Before modifying explicit role launch/read-back behavior, run:
& 'C:\Users\Meta\.cache\codex-runtimes\codex-primary-runtime\dependencies\python\python.exe' '.\tools\epiphany_phase6_role_smoke.py'
```
Before modifying the fixed-lane MVP coordinator endpoint or runner, run:
```powershell
& 'C:\Users\Meta\.cache\codex-runtimes\codex-primary-runtime\dependencies\python\python.exe' '.\tools\epiphany_mvp_coordinator_smoke.py'
```
On this Windows machine, use:
```powershell

View file

@ -28,8 +28,9 @@ Do not trust this file for the exact live HEAD. Always check git.
- Do not copy exact branch or HEAD from this note. Run `git status --short --branch` and `git log --oneline -5`.
- Phase 1 through Phase 5 are complete enough.
- Phase 6 has read-only `thread/epiphany/scene`, `thread/epiphany/jobs`, `thread/epiphany/roles`, `thread/epiphany/freshness`, `thread/epiphany/context`, `thread/epiphany/pressure`, `thread/epiphany/reorient`, `thread/epiphany/crrc`, `thread/epiphany/reorientResult`, and `thread/epiphany/roleResult`; durable `jobBindings` now act as a thin Epiphany-owned launcher seam with launcher id, authority scope, and backend kind/job id, `thread/epiphany/jobLaunch` / `thread/epiphany/jobInterrupt` / `thread/epiphany/roleLaunch` now provide explicit bounded authority over that seam, jobs can overlay it onto live runtime `agent_jobs` progress for loaded threads, and `thread/epiphany/jobsUpdated` now translates live `agent_job_progress:{json}` background events into changed launcher-bound notifications without polling or scheduling. Freshness carries watcher-backed invalidation inputs, roles project implementation/modeling/verification/reorientation ownership from existing signals without becoming a scheduler, `roleLaunch` can launch only fixed modeling/checkpoint or verification/review specialists, `roleResult` reads those outputs back as reviewable findings without mutation, reorient turns checkpoint plus freshness/pressure/watcher signals into a read-only resume-versus-regather verdict, `thread/epiphany/reorientLaunch` is the explicit runtime consumer over that verdict, `thread/epiphany/reorientResult` reads the launched worker output back as a reviewable finding without mutation or promotion, `thread/epiphany/reorientAccept` explicitly banks completed findings into accepted observation/evidence plus optional scratch/checkpoint state, and `thread/epiphany/crrc` recommends the next explicit CRRC action without launching, accepting, compacting, scheduling, or mutating.
- Phase 6 has read-only `thread/epiphany/scene`, `thread/epiphany/jobs`, `thread/epiphany/roles`, `thread/epiphany/freshness`, `thread/epiphany/context`, `thread/epiphany/pressure`, `thread/epiphany/reorient`, `thread/epiphany/crrc`, `thread/epiphany/coordinator`, `thread/epiphany/reorientResult`, and `thread/epiphany/roleResult`; durable `jobBindings` now act as a thin Epiphany-owned launcher seam with launcher id, authority scope, and backend kind/job id, `thread/epiphany/jobLaunch` / `thread/epiphany/jobInterrupt` / `thread/epiphany/roleLaunch` now provide explicit bounded authority over that seam, jobs can overlay it onto live runtime `agent_jobs` progress for loaded threads, and `thread/epiphany/jobsUpdated` now translates live `agent_job_progress:{json}` background events into changed launcher-bound notifications without polling or scheduling. Freshness carries watcher-backed invalidation inputs, roles project implementation/modeling/verification/reorientation ownership from existing signals without becoming a scheduler, `roleLaunch` can launch only fixed modeling/checkpoint or verification/review specialists, `roleResult` reads those outputs back as reviewable findings without mutation, reorient turns checkpoint plus freshness/pressure/watcher signals into a read-only resume-versus-regather verdict, `thread/epiphany/reorientLaunch` is the explicit runtime consumer over that verdict, `thread/epiphany/reorientResult` reads the launched worker output back as a reviewable finding without mutation or promotion, `thread/epiphany/reorientAccept` explicitly banks completed findings into accepted observation/evidence plus optional scratch/checkpoint state, `thread/epiphany/crrc` recommends the next explicit CRRC action without launching, accepting, compacting, scheduling, or mutating, and `thread/epiphany/coordinator` composes those signals into a fixed-lane MVP action recommendation without becoming a writer.
- `tools/epiphany_mvp_status.py` is the first dogfood operator view. It starts or reads a thread through app-server and prints scene, pressure, reorient, jobs, roles, modeling/verification role result read-backs, reorient result, and CRRC recommendation as text or JSON.
- `tools/epiphany_mvp_coordinator.py` is the first auditable fixed-lane coordinator runner. It starts or reads a thread through app-server, follows the harness-native coordinator action, can auto-launch modeling, verification, or reorient-worker jobs, keeps semantic findings review-gated by default, and writes summary, steps, rendered snapshots, transcript, stderr, and final next-action artifacts under `.epiphany-dogfood/coordinator` or a caller-provided artifact directory.
- `tools/epiphany_mvp_dogfood.py` is the first auditable dogfood runner. It drives a bounded state/role/CRRC/reorientation loop and writes local artifacts under `.epiphany-dogfood/mvp-loop`, including raw app-server transcript, rendered snapshots, final status, vanilla-reference prompt/output, and comparison notes.
- `tools/epiphany_mvp_live_specialist.py` is the first auditable live-specialist runner. It launches a real role specialist through `thread/epiphany/roleLaunch`, lets the spawned worker report through `report_agent_job_result`, reads it back through `thread/epiphany/roleResult`, and writes local artifacts under `.epiphany-dogfood/live-specialist`.
- Internal `agent_job:` workers now get the reporting tool independent of the user-facing CSV spawn feature, and ephemeral worker sessions can initialize the sqlite state runtime on demand so specialist reports land in the shared backend.
@ -84,6 +85,7 @@ The current spine:
- read-only context-pressure reflection through `thread/epiphany/pressure`
- read-only CRRC reorientation policy through `thread/epiphany/reorient`
- read-only CRRC next-action recommendation through `thread/epiphany/crrc`
- read-only fixed-lane MVP action recommendation through `thread/epiphany/coordinator`
- durable investigation checkpoint packet through typed state, prompt, scene, and context
- live scene app-server smoke through `tools/epiphany_phase6_scene_smoke.py`
- live jobs app-server smoke through `tools/epiphany_phase6_jobs_smoke.py`
@ -94,6 +96,7 @@ The current spine:
- live reorientation app-server smoke through `tools/epiphany_phase6_reorient_smoke.py`
- live reorient-guided worker launch smoke through `tools/epiphany_phase6_reorient_launch_smoke.py`
- live MVP operator status smoke through `tools/epiphany_mvp_status_smoke.py`
- live MVP coordinator smoke through `tools/epiphany_mvp_coordinator_smoke.py`
- live job-control app-server smoke through `tools/epiphany_phase6_job_control_smoke.py`
- live specialist MVP pass through `tools/epiphany_mvp_live_specialist.py`
@ -112,6 +115,7 @@ The exact current control flow is documented in
- `thread/epiphany/pressure` is read-only.
- `thread/epiphany/reorient` is read-only.
- `thread/epiphany/crrc` is read-only.
- `thread/epiphany/coordinator` is read-only.
- `thread/epiphany/roles` is read-only.
- `thread/epiphany/roleResult` is read-only.
- `thread/epiphany/reorientResult` is read-only.
@ -186,6 +190,12 @@ The same smoke now also covers the read-only `thread/epiphany/crrc`
coordinator recommendation over continue, wait, accept, interrupt, and relaunch
states.
For the fixed-lane MVP coordinator endpoint and runner, run:
```powershell
& 'C:\Users\Meta\.cache\codex-runtimes\codex-primary-runtime\dependencies\python\python.exe' '.\tools\epiphany_mvp_coordinator_smoke.py'
```
For the first MVP operator status view, run:
```powershell
@ -277,23 +287,24 @@ The first live-specialist pass has also run. It produced
inspected the smoke workspace, called `report_agent_job_result`, and
`roleResult` projected a completed `checkpoint-ready` finding.
The CLI MVP is now testable. Put it in front of a human operator through
`tools/epiphany_mvp_status.py`, `.epiphany-dogfood/mvp-loop`, and
`.epiphany-dogfood/live-specialist`. Fix concrete blockers in that operator
loop. The next likely organ is a narrow auditable coordinator for the
fixed single-user lanes: modeling/checkpoint tells implementation where the map
says to look, verification/review tells modeling where the map is insufficient
or stale, and CRRC automation watches context pressure/continuity so work is
persisted, compacted, rehydrated, reoriented, or regathered at the right time.
CRRC is not a specialist-agent persona; the reorient-worker it may launch is the
specialist. Do not turn that coordinator into a broad hidden dispatcher,
arbitrary marketplace, alternate job backend, or GUI-as-source-of-truth.
The fixed-lane coordinator MVP is now testable. Put it in front of a human
operator through `tools/epiphany_mvp_coordinator.py`,
`tools/epiphany_mvp_status.py`, `.epiphany-dogfood/coordinator`,
`.epiphany-dogfood/mvp-loop`, and `.epiphany-dogfood/live-specialist`. Fix
concrete blockers in that operator loop. The next likely organ, after real
operator artifacts justify it, is limited safe-boundary CRRC execution that can
compact/resume/reorient or launch a bounded reorient-worker when the read-only
coordinator says it is safe. CRRC is not a specialist-agent persona; the
reorient-worker it may launch is the specialist. Do not turn the coordinator
into a broad hidden dispatcher, arbitrary marketplace, alternate job backend, or
GUI-as-source-of-truth.
Live `thread/epiphany/scene`, `thread/epiphany/jobs`, `thread/epiphany/roles`,
`thread/epiphany/freshness`, `thread/epiphany/context`,
`thread/epiphany/pressure`, `thread/epiphany/reorient`,
`thread/epiphany/crrc`, and `tools/epiphany_mvp_status.py` smokes are now
guardrails, not the next organs.
`thread/epiphany/crrc`, `thread/epiphany/coordinator`,
`tools/epiphany_mvp_status.py`, and `tools/epiphany_mvp_coordinator.py` smokes
are now guardrails, not the next organs.
## Not Yet

View file

@ -59,3 +59,4 @@
{"ts": "2026-04-28T16:33:43+00:00", "type": "implementation", "status": "ok", "note": "Landed live-specialist MVP execution: internal agent_job workers now expose report_agent_job_result independently of the CSV front door, ephemeral workers can initialize sqlite state runtime on demand, and tools/epiphany_mvp_live_specialist.py proved roleLaunch -> agent_jobs worker -> report_agent_job_result -> roleResult with auditable artifacts under .epiphany-dogfood/live-specialist."}
{"ts": "2026-04-28T16:52:18+00:00", "type": "implementation", "status": "ok", "note": "Clarified MVP direction: marketplace and alternate job backend are not active concerns; the scheduler-shaped need is a narrow auditable fixed-lane role coordinator over modeling, implementation, verification, and CRRC handoffs, not a broad ambient dispatcher."}
{"ts": "2026-04-28T16:56:56+00:00", "type": "design", "status": "ok", "note": "Clarified CRRC architecture: CRRC is harness workflow automation that watches context pressure and continuity, persists/checkpoints, triggers compact-rehydrate-reorient behavior, and may launch a bounded reorient-worker specialist; CRRC itself is not a specialist-agent persona."}
{"ts": "2026-04-28T18:33:53+01:00", "type": "implementation", "status": "ok", "note": "Landed the fixed-lane Epiphany MVP coordinator: read-only thread/epiphany/coordinator composes roles, pressure, reorient, CRRC, role results, and reorient result into review-gated action recommendations, and tools/epiphany_mvp_coordinator.py drives the same policy through app-server APIs with auditable artifacts. Coordinator smoke covered cold prepareCheckpoint, clean continueImplementation, modeling review, verification review, source-drift reorient review, high-pressure compact/dry-run, and complete artifact bundles."}

View file

@ -12,8 +12,8 @@ objective:
explicit typed models of the codebase, active goal, evidence, and change
machinery they are working on.
current: >
Grow Phase 6 from the landed typed state spine toward a dogfoodable MVP
without letting GUI/client state become authoritative.
Prove the Phase 6 MVP through the landed fixed-lane coordinator and
auditable operator artifacts before adding limited CRRC automation.
constraints:
- No frontier-scale training budget.
@ -53,7 +53,7 @@ data_flow:
active_subgoals:
- 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, scene, jobs, roles, roleResult, freshness, context, pressure, reorient, crrc, and reorientResult.
- Preserve read-only boundaries for retrieve, distill, propose, scene, jobs, roles, roleResult, freshness, context, pressure, reorient, crrc, coordinator, and reorientResult.
- Extend Phase 6 coordination only where it makes role dependencies explicit and auditable without becoming a broad ambient dispatcher.
- Put the dogfooded MVP loop in front of a human operator before adding larger organs.
- Keep persistent project state ruthlessly distilled so rehydration strengthens the next turn instead of bloating it.
@ -83,6 +83,8 @@ accepted_design:
- `thread/epiphany/reorient` is the first bounded CRRC policy surface: it derives a read-only `resume` versus `regather` verdict from checkpoint, freshness, watcher, and pressure signals without mutating state, compacting, scheduling, or silently continuing work.
- `thread/epiphany/crrc` is the first bounded CRRC coordinator recommendation surface: it composes pressure, the reorientation verdict, fixed reorient-worker binding/result status, finding read-back, and available actions into one read-only recommendation without launching, accepting, compacting, scheduling, or mutating state.
- A narrow auditable coordinator is likely central to the MVP because implementation, modeling/checkpoint, verification/review, and CRRC automation depend on each other's signals. CRRC itself is harness workflow automation, not a specialist-agent role: it watches pressure/continuity, ensures persistence, triggers compaction/rehydration/reorientation when needed, and may launch a bounded reorient-worker specialist when semantic regathering is required.
- `thread/epiphany/coordinator` is the first harness-native fixed-lane coordinator surface: it composes roles, pressure, reorient, CRRC, roleResult, and reorientResult into a read-only action recommendation with target role, source signals, review requirements, automation eligibility, reason, and current lane summaries without mutating state or launching work.
- `tools/epiphany_mvp_coordinator.py` is the first auditable coordinator runner: it drives the fixed single-user lanes through app-server APIs, may auto-launch modeling, verification, or reorient-worker jobs, keeps semantic findings review-gated by default, and writes coordinator summaries, JSONL steps, rendered snapshots, transcript, stderr, and final next-action artifacts.
- `tools/epiphany_mvp_status.py` is the first dogfood operator view: it starts or reads a thread through app-server and renders scene, pressure, reorient, jobs, role result read-backs, reorient result, CRRC recommendation, and MVP role lanes as text or JSON without becoming a state store.
- `thread/epiphany/roles` is the first harness-native role ownership surface: it projects implementation, modeling/checkpoint, verification/review, and reorientation lanes from authoritative typed state, bound jobs, pressure/reorient/CRRC, and worker result status without launching, scheduling, accepting, compacting, or mutating state.
- `thread/epiphany/roleLaunch` and `thread/epiphany/roleResult` are the first explicit role-scoped specialist templates: modeling/checkpoint and verification/review can be launched through fixed bindings over the existing job-control seam and read back as reviewable findings, while implementation stays owned by the main coding agent and reorientation stays on the CRRC-specific launch/result path.
@ -118,6 +120,7 @@ landed_baseline:
- Phase 6 live specialist runner: auditable real worker loop over roleLaunch, agent_jobs worker execution, report_agent_job_result, roleResult, status rendering, and transcript artifacts.
- Phase 6 role ownership: read-only `thread/epiphany/roles` over implementation, modeling/checkpoint, verification/review, and reorientation lanes.
- Phase 6 role specialists: explicit `thread/epiphany/roleLaunch` and read-only `thread/epiphany/roleResult` templates for modeling/checkpoint and verification/review.
- Phase 6 coordinator: read-only `thread/epiphany/coordinator` plus `tools/epiphany_mvp_coordinator.py` and smoke coverage for the fixed-lane MVP loop.
guardrails:
- Use `tools/epiphany_phase5_smoke.py` before modifying update, distill, propose, promote, read-projection, or notification behavior.
- Use `tools/epiphany_phase6_scene_smoke.py` before modifying scene projection behavior.
@ -132,6 +135,7 @@ landed_baseline:
- Use `tools/epiphany_phase6_reorient_launch_smoke.py` before modifying the bounded reorient-worker result read-back surface.
- Use `tools/epiphany_phase6_reorient_launch_smoke.py` before modifying the read-only CRRC coordinator recommendation surface.
- Use `tools/epiphany_mvp_status_smoke.py` before modifying the MVP operator status view.
- Use `tools/epiphany_mvp_coordinator_smoke.py` before modifying the fixed-lane MVP coordinator endpoint or runner.
- Use `tools/epiphany_phase6_role_smoke.py` before modifying explicit role launch/read-back behavior.
- Use `tools/epiphany_mvp_live_specialist.py` before claiming live specialist execution still works end to end.
- Use focused scene/jobs/context/pressure/reorient/protocol/schema checks for reflection-only changes.
@ -152,5 +156,5 @@ rejected_paths:
reason: persistent state that accumulates every local truth becomes memory cruft and weakens rehydration
current_status:
summary: Phase 1 durable state, Phase 2 prompt integration, Phase 3 typed read, Phase 4 retrieval/indexing, Phase 5 update/distill/propose/promote/read/notification, and Phase 6 read-only scene, jobs, roles, freshness, targeted context, pressure, reorient, CRRC, reorient launch/result/accept, explicit modeling/checkpoint and verification/review role launch/result templates, first dogfood MVP status, auditable MVP dogfood runner, and live specialist MVP runner are landed. The live specialist runner proved a real modeling specialist can launch, inspect, report through `report_agent_job_result`, and be read back through `roleResult`; the earlier deterministic dogfood runner exercised state, role launch/result, CRRC drift, reorient launch/result/accept, rendered status snapshots, and Vanilla Codex comparison. Implementation remains main-agent work; reorientation remains on the CRRC-specific launch/result path. Persistent state remains distilled; evidence is a belief ledger, not an activity feed.
next_action: Treat the CLI MVP as testable, then design the smallest narrow coordinator that makes modeling, implementation, verification, and CRRC automation handoffs explicit over the existing `agent_jobs` seam. Do not turn CRRC into a specialist persona, and do not build a broad ambient dispatcher, GUI-as-source-of-truth, arbitrary specialist marketplace, or alternate job backend for the MVP.
summary: Phase 1 durable state, Phase 2 prompt integration, Phase 3 typed read, Phase 4 retrieval/indexing, Phase 5 update/distill/propose/promote/read/notification, and Phase 6 read-only scene, jobs, roles, freshness, targeted context, pressure, reorient, CRRC, coordinator, reorient launch/result/accept, explicit modeling/checkpoint and verification/review role launch/result templates, MVP status, dogfood runner, coordinator runner, and live specialist runner are landed. The coordinator endpoint and runner now make fixed-lane modeling, verification, implementation continuation, and CRRC handoffs explicit through review-gated artifacts over the existing app-server/job seam. Implementation remains main-agent work; CRRC remains workflow automation, not a specialist persona. Persistent state remains distilled; evidence is a belief ledger, not an activity feed.
next_action: Dogfood the fixed-lane coordinator on real local work through `tools/epiphany_mvp_coordinator.py` and its artifact bundle. Fix concrete operator-loop blockers only; defer limited automatic CRRC safe-boundary execution until the coordinator artifacts prove the policy, and do not build a broad ambient dispatcher, GUI-as-source-of-truth, arbitrary specialist marketplace, or alternate job backend for the MVP.

View file

@ -0,0 +1,510 @@
from __future__ import annotations
import argparse
import json
import os
import shutil
import time
from pathlib import Path
from typing import Any
from epiphany_mvp_status import DEFAULT_APP_SERVER
from epiphany_mvp_status import collect_status
from epiphany_mvp_status import render_status
from epiphany_phase5_smoke import AppServerClient
from epiphany_phase5_smoke import ROOT
from epiphany_phase5_smoke import require
from epiphany_phase6_reorient_launch_smoke import BINDING_ID as REORIENT_BINDING_ID
from epiphany_phase6_reorient_launch_smoke import complete_reorient_backend_job
from epiphany_phase6_reorient_smoke import prepare_workspace
from epiphany_phase6_reorient_smoke import reorient_patch
from epiphany_phase6_role_smoke import MODELING_BINDING_ID
from epiphany_phase6_role_smoke import VERIFICATION_BINDING_ID
from epiphany_phase6_role_smoke import complete_role_backend_job
DEFAULT_ARTIFACT_DIR = ROOT / ".epiphany-dogfood" / "coordinator"
DEFAULT_CODEX_HOME = Path(os.environ.get("CODEX_HOME", Path.home() / ".codex"))
TERMINAL_ROLE_STATUSES = {"completed", "failed", "cancelled"}
TERMINAL_REORIENT_STATUSES = {"completed", "failed", "cancelled"}
STOP_ACTIONS = {
"prepareCheckpoint",
"reviewReorientResult",
"regatherManually",
"reviewModelingResult",
"reviewVerificationResult",
"continueImplementation",
}
def reset_artifact_dir(path: Path) -> None:
root = (ROOT / ".epiphany-dogfood").resolve()
resolved = path.resolve()
if resolved == root or root not in resolved.parents:
raise ValueError(f"refusing to delete non-dogfood artifact dir: {path}")
if path.exists():
shutil.rmtree(path)
path.mkdir(parents=True, exist_ok=True)
def write_json(path: Path, value: Any) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(json.dumps(value, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
def write_text(path: Path, value: str) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(value, encoding="utf-8")
def append_jsonl(path: Path, value: Any) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
with path.open("a", encoding="utf-8") as handle:
handle.write(json.dumps(value, ensure_ascii=False) + "\n")
def state_revision(status: dict[str, Any]) -> int | None:
state = status.get("read", {}).get("thread", {}).get("epiphanyState")
if isinstance(state, dict):
revision = state.get("revision")
if isinstance(revision, int):
return revision
scene_revision = status.get("scene", {}).get("scene", {}).get("revision")
return scene_revision if isinstance(scene_revision, int) else None
def coordinator_from_status(status: dict[str, Any]) -> dict[str, Any]:
coordinator = status.get("coordinator")
if isinstance(coordinator, dict):
return coordinator
recommendation = status["crrc"]["recommendation"]
return {
"action": recommendation["action"],
"targetRole": None,
"recommendedSceneAction": recommendation.get("recommendedSceneAction"),
"requiresReview": recommendation["action"] in {"acceptReorientResult", "reviewReorientResult"},
"canAutoRun": recommendation["action"] == "launchReorientWorker",
"reason": recommendation["reason"],
"sourceSignals": {},
"roles": status["roles"]["roles"],
"note": "local fallback from CRRC recommendation",
}
def collect_coordinator_status(
client: AppServerClient,
*,
thread_id: str,
cwd: Path,
ephemeral: bool,
) -> dict[str, Any]:
status = collect_status(client, thread_id=thread_id, cwd=cwd, ephemeral=ephemeral)
status["coordinator"] = client.send(
"thread/epiphany/coordinator", {"threadId": thread_id}
)
return status
def wait_for_role_result(
client: AppServerClient,
*,
thread_id: str,
role_id: str,
timeout_seconds: int,
poll_seconds: float,
) -> dict[str, Any]:
deadline = time.time() + timeout_seconds
latest: dict[str, Any] | None = None
while time.time() < deadline:
latest = client.send(
"thread/epiphany/roleResult",
{"threadId": thread_id, "roleId": role_id},
)
assert latest is not None
if latest.get("status") in TERMINAL_ROLE_STATUSES:
return latest
time.sleep(poll_seconds)
assert latest is not None
return latest
def wait_for_reorient_result(
client: AppServerClient,
*,
thread_id: str,
timeout_seconds: int,
poll_seconds: float,
) -> dict[str, Any]:
deadline = time.time() + timeout_seconds
latest: dict[str, Any] | None = None
while time.time() < deadline:
latest = client.send(
"thread/epiphany/reorientResult",
{"threadId": thread_id, "bindingId": REORIENT_BINDING_ID},
)
assert latest is not None
if latest.get("status") in TERMINAL_REORIENT_STATUSES:
return latest
time.sleep(poll_seconds)
assert latest is not None
return latest
def launch_role(
client: AppServerClient,
*,
thread_id: str,
role_id: str,
expected_revision: int | None,
max_runtime_seconds: int,
) -> dict[str, Any]:
payload: dict[str, Any] = {
"threadId": thread_id,
"roleId": role_id,
"maxRuntimeSeconds": max_runtime_seconds,
}
if expected_revision is not None:
payload["expectedRevision"] = expected_revision
launch = client.send("thread/epiphany/roleLaunch", payload)
assert launch is not None
return launch
def launch_reorient(
client: AppServerClient,
*,
thread_id: str,
expected_revision: int | None,
max_runtime_seconds: int,
) -> dict[str, Any]:
payload: dict[str, Any] = {
"threadId": thread_id,
"maxRuntimeSeconds": max_runtime_seconds,
}
if expected_revision is not None:
payload["expectedRevision"] = expected_revision
launch = client.send("thread/epiphany/reorientLaunch", payload)
assert launch is not None
return launch
def maybe_complete_role_backend(
args: argparse.Namespace,
launch: dict[str, Any],
*,
role_id: str,
) -> dict[str, Any] | None:
if not args.test_complete_backend:
return None
backend_job_id = launch.get("job", {}).get("backendJobId")
if not backend_job_id:
return None
binding_id = MODELING_BINDING_ID if role_id == "modeling" else VERIFICATION_BINDING_ID
verdict = "checkpoint-ready" if role_id == "modeling" else "pass"
return complete_role_backend_job(
args.codex_home.resolve(),
backend_job_id,
binding_id=binding_id,
role_id=role_id,
verdict=verdict,
)
def maybe_complete_reorient_backend(
args: argparse.Namespace,
launch: dict[str, Any],
) -> dict[str, Any] | None:
if not args.test_complete_backend:
return None
backend_job_id = launch.get("job", {}).get("backendJobId")
if not backend_job_id:
return None
return complete_reorient_backend_job(
args.codex_home.resolve(),
backend_job_id,
mode="regather",
)
def run_coordinator(args: argparse.Namespace) -> dict[str, Any]:
app_server = args.app_server.resolve()
if not app_server.exists():
raise FileNotFoundError(f"codex app-server binary not found: {app_server}")
artifact_dir = args.artifact_dir.resolve()
reset_artifact_dir(artifact_dir)
transcript_path = artifact_dir / "epiphany-transcript.jsonl"
stderr_path = artifact_dir / "epiphany-server.stderr.log"
steps_path = artifact_dir / "coordinator-steps.jsonl"
cwd = args.cwd.resolve()
codex_home = args.codex_home.resolve()
codex_home.mkdir(parents=True, exist_ok=True)
if args.bootstrap_smoke_state:
cwd = artifact_dir / "workspace"
prepare_workspace(cwd)
steps: list[dict[str, Any]] = []
snapshots: list[str] = []
final_status: dict[str, Any] | None = None
final_action: dict[str, Any] | None = None
with AppServerClient(app_server, codex_home, transcript_path, stderr_path) as client:
client.send(
"initialize",
{
"clientInfo": {
"name": "epiphany-mvp-coordinator",
"title": "Epiphany MVP Coordinator",
"version": "0.1.0",
},
"capabilities": {"experimentalApi": True},
},
)
client.send("initialized", expect_response=False)
if args.thread_id is None:
started = client.send(
"thread/start",
{"cwd": str(cwd), "ephemeral": args.ephemeral},
)
assert started is not None
thread_id = started["thread"]["id"]
else:
thread_id = args.thread_id
if args.bootstrap_smoke_state:
update = client.send(
"thread/epiphany/update",
{"threadId": thread_id, "expectedRevision": 0, "patch": reorient_patch()},
)
assert update is not None
if args.simulate_source_drift:
client.send("thread/epiphany/freshness", {"threadId": thread_id})
watched = cwd / "src" / "reorient_target.rs"
watched.write_text(
"pub fn reorient_target() -> &'static str {\n \"after\"\n}\n",
encoding="utf-8",
)
time.sleep(0.5)
for index in range(args.max_steps):
status = collect_coordinator_status(
client,
thread_id=thread_id,
cwd=cwd,
ephemeral=args.ephemeral,
)
coordinator = coordinator_from_status(status)
action = coordinator["action"]
if args.simulate_high_pressure and index == 0:
action = "compactRehydrateReorient"
coordinator = {
**coordinator,
"action": action,
"canAutoRun": True,
"requiresReview": False,
"reason": "Simulated high pressure requested by smoke test.",
}
snapshot_name = f"step-{index:02d}-{action}.txt"
write_text(artifact_dir / snapshot_name, render_status(status))
snapshots.append(snapshot_name)
step: dict[str, Any] = {
"index": index,
"action": action,
"coordinator": coordinator,
"stateRevision": state_revision(status),
"events": [],
}
steps.append(step)
final_status = status
final_action = coordinator
if args.mode == "plan":
append_jsonl(steps_path, step)
break
if action in STOP_ACTIONS and not args.auto_review:
append_jsonl(steps_path, step)
break
revision = state_revision(status)
if action == "launchModeling":
launch = launch_role(
client,
thread_id=thread_id,
role_id="modeling",
expected_revision=revision,
max_runtime_seconds=args.max_runtime_seconds,
)
step["events"].append({"type": "roleLaunch", "roleId": "modeling", "launch": launch})
completed = maybe_complete_role_backend(args, launch, role_id="modeling")
if completed is not None:
step["events"].append({"type": "testCompleteBackend", "payload": completed})
result = wait_for_role_result(
client,
thread_id=thread_id,
role_id="modeling",
timeout_seconds=args.timeout_seconds,
poll_seconds=args.poll_seconds,
)
step["events"].append({"type": "roleResult", "roleId": "modeling", "result": result})
if not args.auto_review:
final_action = {"action": "reviewModelingResult", "reason": result.get("note")}
append_jsonl(steps_path, step)
break
append_jsonl(steps_path, step)
continue
if action == "launchVerification":
launch = launch_role(
client,
thread_id=thread_id,
role_id="verification",
expected_revision=revision,
max_runtime_seconds=args.max_runtime_seconds,
)
step["events"].append({"type": "roleLaunch", "roleId": "verification", "launch": launch})
completed = maybe_complete_role_backend(args, launch, role_id="verification")
if completed is not None:
step["events"].append({"type": "testCompleteBackend", "payload": completed})
result = wait_for_role_result(
client,
thread_id=thread_id,
role_id="verification",
timeout_seconds=args.timeout_seconds,
poll_seconds=args.poll_seconds,
)
step["events"].append(
{"type": "roleResult", "roleId": "verification", "result": result}
)
if not args.auto_review:
final_action = {"action": "reviewVerificationResult", "reason": result.get("note")}
append_jsonl(steps_path, step)
break
append_jsonl(steps_path, step)
continue
if action == "launchReorientWorker":
launch = launch_reorient(
client,
thread_id=thread_id,
expected_revision=revision,
max_runtime_seconds=args.max_runtime_seconds,
)
step["events"].append({"type": "reorientLaunch", "launch": launch})
completed = maybe_complete_reorient_backend(args, launch)
if completed is not None:
step["events"].append({"type": "testCompleteBackend", "payload": completed})
result = wait_for_reorient_result(
client,
thread_id=thread_id,
timeout_seconds=args.timeout_seconds,
poll_seconds=args.poll_seconds,
)
step["events"].append({"type": "reorientResult", "result": result})
if not args.auto_review:
final_action = {"action": "reviewReorientResult", "reason": result.get("note")}
append_jsonl(steps_path, step)
break
append_jsonl(steps_path, step)
continue
if action == "compactRehydrateReorient":
if args.dry_compact:
step["events"].append({"type": "dryCompact", "threadId": thread_id})
append_jsonl(steps_path, step)
continue
compact = client.send("thread/compact/start", {"threadId": thread_id})
step["events"].append({"type": "compactStart", "response": compact})
try:
notification = client.wait_for_notification(
"thread/compacted", timeout=args.timeout_seconds
)
step["events"].append({"type": "compacted", "notification": notification})
except TimeoutError as exc:
step["events"].append({"type": "compactWaitTimeout", "error": str(exc)})
final_action = {
"action": "reviewReorientResult",
"reason": "Compaction did not finish before timeout.",
}
append_jsonl(steps_path, step)
break
resumed = client.send("thread/resume", {"threadId": thread_id})
step["events"].append({"type": "resume", "response": resumed})
append_jsonl(steps_path, step)
continue
if action in STOP_ACTIONS:
append_jsonl(steps_path, step)
break
append_jsonl(steps_path, step)
if final_status is None:
final_status = collect_coordinator_status(
client, thread_id=thread_id, cwd=cwd, ephemeral=args.ephemeral
)
final_rendered = render_status(final_status)
summary = {
"objective": "Coordinate the Epiphany MVP lanes over existing app-server APIs.",
"artifactDir": str(artifact_dir),
"codexHome": str(codex_home),
"workspace": str(cwd),
"threadId": final_status["threadId"] if final_status else args.thread_id,
"mode": args.mode,
"steps": steps,
"snapshots": snapshots,
"finalAction": final_action,
"finalStatus": final_status,
"artifactManifest": [
"coordinator-summary.json",
"coordinator-steps.jsonl",
"coordinator-final-status.json",
"coordinator-final-status.txt",
"coordinator-final-action.txt",
"epiphany-transcript.jsonl",
"epiphany-server.stderr.log",
*snapshots,
],
}
write_json(artifact_dir / "coordinator-summary.json", summary)
write_json(artifact_dir / "coordinator-final-status.json", final_status)
write_text(artifact_dir / "coordinator-final-status.txt", final_rendered)
write_text(
artifact_dir / "coordinator-final-action.txt",
json.dumps(final_action, indent=2, ensure_ascii=False) + "\n",
)
return summary
def main() -> int:
parser = argparse.ArgumentParser(
description="Run an auditable fixed-lane Epiphany MVP coordinator."
)
parser.add_argument("--app-server", type=Path, default=DEFAULT_APP_SERVER)
parser.add_argument("--thread-id")
parser.add_argument("--cwd", type=Path, default=ROOT)
parser.add_argument("--codex-home", type=Path, default=DEFAULT_CODEX_HOME)
parser.add_argument("--artifact-dir", type=Path, default=DEFAULT_ARTIFACT_DIR)
parser.add_argument("--mode", choices=["plan", "run"], default="plan")
parser.add_argument("--max-steps", type=int, default=4)
parser.add_argument("--poll-seconds", type=float, default=5.0)
parser.add_argument("--timeout-seconds", type=int, default=240)
parser.add_argument("--max-runtime-seconds", type=int, default=180)
parser.add_argument("--ephemeral", action=argparse.BooleanOptionalAction, default=True)
parser.add_argument("--auto-review", action="store_true")
parser.add_argument("--test-complete-backend", action="store_true")
parser.add_argument("--bootstrap-smoke-state", action="store_true")
parser.add_argument("--simulate-high-pressure", action="store_true")
parser.add_argument("--simulate-source-drift", action="store_true")
parser.add_argument("--dry-compact", action="store_true")
args = parser.parse_args()
result = run_coordinator(args)
print(json.dumps(result, indent=2, ensure_ascii=False))
return 0
if __name__ == "__main__":
raise SystemExit(main())

View file

@ -0,0 +1,195 @@
from __future__ import annotations
import argparse
import json
import shutil
from pathlib import Path
from types import SimpleNamespace
from typing import Any
from epiphany_mvp_coordinator import DEFAULT_APP_SERVER
from epiphany_mvp_coordinator import run_coordinator
from epiphany_phase5_smoke import ROOT
from epiphany_phase5_smoke import require
DEFAULT_ARTIFACT_ROOT = ROOT / ".epiphany-dogfood" / "coordinator-smoke"
def reset_artifact_root(path: Path) -> None:
root = (ROOT / ".epiphany-dogfood").resolve()
resolved = path.resolve()
if resolved == root or root not in resolved.parents:
raise ValueError(f"refusing to delete non-dogfood artifact root: {path}")
if path.exists():
shutil.rmtree(path)
path.mkdir(parents=True, exist_ok=True)
def coordinator_args(
*,
app_server: Path,
artifact_root: Path,
name: str,
mode: str = "plan",
bootstrap_smoke_state: bool = False,
simulate_source_drift: bool = False,
simulate_high_pressure: bool = False,
dry_compact: bool = False,
auto_review: bool = False,
max_steps: int = 4,
) -> argparse.Namespace:
artifact_dir = artifact_root / name
return SimpleNamespace(
app_server=app_server,
thread_id=None,
cwd=ROOT,
codex_home=artifact_dir / "codex-home",
artifact_dir=artifact_dir,
mode=mode,
max_steps=max_steps,
poll_seconds=0.1,
timeout_seconds=20,
max_runtime_seconds=30,
ephemeral=True,
auto_review=auto_review,
test_complete_backend=True,
bootstrap_smoke_state=bootstrap_smoke_state,
simulate_high_pressure=simulate_high_pressure,
simulate_source_drift=simulate_source_drift,
dry_compact=dry_compact,
)
def require_artifacts(summary: dict[str, Any]) -> None:
artifact_dir = Path(summary["artifactDir"])
for name in (
"coordinator-summary.json",
"coordinator-steps.jsonl",
"coordinator-final-status.json",
"coordinator-final-status.txt",
"coordinator-final-action.txt",
"epiphany-transcript.jsonl",
"epiphany-server.stderr.log",
):
require((artifact_dir / name).exists(), f"missing coordinator artifact {name}")
def run_smoke(args: argparse.Namespace) -> dict[str, Any]:
app_server = args.app_server.resolve()
if not app_server.exists():
raise FileNotFoundError(f"codex app-server binary not found: {app_server}")
artifact_root = args.artifact_root.resolve()
reset_artifact_root(artifact_root)
cold = run_coordinator(
coordinator_args(app_server=app_server, artifact_root=artifact_root, name="cold")
)
require(
cold["finalAction"]["action"] == "prepareCheckpoint",
"cold start should stop at prepareCheckpoint",
)
require_artifacts(cold)
modeling = run_coordinator(
coordinator_args(
app_server=app_server,
artifact_root=artifact_root,
name="modeling",
mode="run",
bootstrap_smoke_state=True,
max_steps=1,
)
)
require(
modeling["finalAction"]["action"] == "reviewModelingResult",
"modeling run should stop with a reviewable modeling result",
)
require_artifacts(modeling)
verification = run_coordinator(
coordinator_args(
app_server=app_server,
artifact_root=artifact_root,
name="verification",
mode="run",
bootstrap_smoke_state=True,
auto_review=True,
max_steps=3,
)
)
require(
verification["steps"][-1]["action"] == "reviewVerificationResult",
"auto-review smoke should drive through verification and stop at review",
)
require_artifacts(verification)
drift = run_coordinator(
coordinator_args(
app_server=app_server,
artifact_root=artifact_root,
name="drift",
mode="run",
bootstrap_smoke_state=True,
simulate_source_drift=True,
max_steps=1,
)
)
require(
drift["finalAction"]["action"] == "reviewReorientResult",
"source drift should launch reorient worker and stop for review",
)
require_artifacts(drift)
pressure = run_coordinator(
coordinator_args(
app_server=app_server,
artifact_root=artifact_root,
name="pressure",
mode="run",
bootstrap_smoke_state=True,
simulate_high_pressure=True,
dry_compact=True,
max_steps=1,
)
)
require(
pressure["steps"][0]["action"] == "compactRehydrateReorient",
"simulated high pressure should select compact/rehydrate/reorient",
)
require(
pressure["steps"][0]["events"][0]["type"] == "dryCompact",
"dry compact smoke should record the compaction action",
)
require_artifacts(pressure)
result = {
"artifactRoot": str(artifact_root),
"coldAction": cold["finalAction"]["action"],
"modelingAction": modeling["finalAction"]["action"],
"verificationAction": verification["steps"][-1]["action"],
"driftAction": drift["finalAction"]["action"],
"pressureAction": pressure["steps"][0]["action"],
}
(artifact_root / "coordinator-smoke-summary.json").write_text(
json.dumps(result, indent=2, ensure_ascii=False) + "\n",
encoding="utf-8",
)
return result
def main() -> int:
parser = argparse.ArgumentParser(
description="Smoke the auditable Epiphany MVP coordinator over fixed lanes."
)
parser.add_argument("--app-server", type=Path, default=DEFAULT_APP_SERVER)
parser.add_argument("--artifact-root", type=Path, default=DEFAULT_ARTIFACT_ROOT)
args = parser.parse_args()
result = run_smoke(args)
print(json.dumps(result, indent=2, ensure_ascii=False))
return 0
if __name__ == "__main__":
raise SystemExit(main())

View file

@ -83,6 +83,7 @@ def collect_status(
}
reorient_result = client.send("thread/epiphany/reorientResult", {"threadId": thread_id})
crrc = client.send("thread/epiphany/crrc", {"threadId": thread_id})
coordinator = client.send("thread/epiphany/coordinator", {"threadId": thread_id})
status = {
"threadId": thread_id,
@ -95,6 +96,7 @@ def collect_status(
"roleResults": role_results,
"reorientResult": reorient_result,
"crrc": crrc,
"coordinator": coordinator,
}
return status
@ -110,6 +112,7 @@ def render_status(status: dict[str, Any]) -> str:
roles = status["roles"]["roles"]
role_results = status.get("roleResults") or {}
recommendation = crrc["recommendation"]
coordinator = status.get("coordinator") or {}
checkpoint = scene.get("investigationCheckpoint") or {}
lines = [
@ -121,6 +124,7 @@ def render_status(status: dict[str, Any]) -> str:
f"- action: {recommendation['action']}",
f"- scene action: {maybe(recommendation.get('recommendedSceneAction'))}",
f"- reason: {recommendation['reason']}",
f"- coordinator: {maybe(coordinator.get('action'))} ({maybe(coordinator.get('targetRole'))})",
"",
"Continuity",
(

View file

@ -15105,6 +15105,57 @@
],
"type": "string"
},
"ThreadEpiphanyCoordinatorAction": {
"enum": [
"prepareCheckpoint",
"compactRehydrateReorient",
"launchReorientWorker",
"waitForReorientWorker",
"reviewReorientResult",
"regatherManually",
"launchModeling",
"reviewModelingResult",
"launchVerification",
"reviewVerificationResult",
"continueImplementation"
],
"type": "string"
},
"ThreadEpiphanyCoordinatorSignals": {
"properties": {
"crrcAction": {
"$ref": "#/definitions/v2/ThreadEpiphanyCrrcAction"
},
"modelingResultStatus": {
"$ref": "#/definitions/v2/ThreadEpiphanyRoleResultStatus"
},
"pressureLevel": {
"$ref": "#/definitions/v2/ThreadEpiphanyPressureLevel"
},
"reorientAction": {
"$ref": "#/definitions/v2/ThreadEpiphanyReorientAction"
},
"reorientResultStatus": {
"$ref": "#/definitions/v2/ThreadEpiphanyReorientResultStatus"
},
"shouldPrepareCompaction": {
"type": "boolean"
},
"verificationResultStatus": {
"$ref": "#/definitions/v2/ThreadEpiphanyRoleResultStatus"
}
},
"required": [
"crrcAction",
"modelingResultStatus",
"pressureLevel",
"reorientAction",
"reorientResultStatus",
"shouldPrepareCompaction",
"verificationResultStatus"
],
"type": "object"
},
"ThreadEpiphanyCrrcAction": {
"enum": [
"continue",
@ -16260,6 +16311,7 @@
"context",
"jobs",
"roles",
"coordinator",
"roleLaunch",
"roleResult",
"jobLaunch",

View file

@ -12992,6 +12992,57 @@
],
"type": "string"
},
"ThreadEpiphanyCoordinatorAction": {
"enum": [
"prepareCheckpoint",
"compactRehydrateReorient",
"launchReorientWorker",
"waitForReorientWorker",
"reviewReorientResult",
"regatherManually",
"launchModeling",
"reviewModelingResult",
"launchVerification",
"reviewVerificationResult",
"continueImplementation"
],
"type": "string"
},
"ThreadEpiphanyCoordinatorSignals": {
"properties": {
"crrcAction": {
"$ref": "#/definitions/ThreadEpiphanyCrrcAction"
},
"modelingResultStatus": {
"$ref": "#/definitions/ThreadEpiphanyRoleResultStatus"
},
"pressureLevel": {
"$ref": "#/definitions/ThreadEpiphanyPressureLevel"
},
"reorientAction": {
"$ref": "#/definitions/ThreadEpiphanyReorientAction"
},
"reorientResultStatus": {
"$ref": "#/definitions/ThreadEpiphanyReorientResultStatus"
},
"shouldPrepareCompaction": {
"type": "boolean"
},
"verificationResultStatus": {
"$ref": "#/definitions/ThreadEpiphanyRoleResultStatus"
}
},
"required": [
"crrcAction",
"modelingResultStatus",
"pressureLevel",
"reorientAction",
"reorientResultStatus",
"shouldPrepareCompaction",
"verificationResultStatus"
],
"type": "object"
},
"ThreadEpiphanyCrrcAction": {
"enum": [
"continue",
@ -14147,6 +14198,7 @@
"context",
"jobs",
"roles",
"coordinator",
"roleLaunch",
"roleResult",
"jobLaunch",

View file

@ -0,0 +1,5 @@
// GENERATED CODE! DO NOT MODIFY BY HAND!
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type ThreadEpiphanyCoordinatorAction = "prepareCheckpoint" | "compactRehydrateReorient" | "launchReorientWorker" | "waitForReorientWorker" | "reviewReorientResult" | "regatherManually" | "launchModeling" | "reviewModelingResult" | "launchVerification" | "reviewVerificationResult" | "continueImplementation";

View file

@ -0,0 +1,10 @@
// GENERATED CODE! DO NOT MODIFY BY HAND!
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { ThreadEpiphanyCrrcAction } from "./ThreadEpiphanyCrrcAction";
import type { ThreadEpiphanyPressureLevel } from "./ThreadEpiphanyPressureLevel";
import type { ThreadEpiphanyReorientAction } from "./ThreadEpiphanyReorientAction";
import type { ThreadEpiphanyReorientResultStatus } from "./ThreadEpiphanyReorientResultStatus";
import type { ThreadEpiphanyRoleResultStatus } from "./ThreadEpiphanyRoleResultStatus";
export type ThreadEpiphanyCoordinatorSignals = { pressureLevel: ThreadEpiphanyPressureLevel, shouldPrepareCompaction: boolean, reorientAction: ThreadEpiphanyReorientAction, crrcAction: ThreadEpiphanyCrrcAction, modelingResultStatus: ThreadEpiphanyRoleResultStatus, verificationResultStatus: ThreadEpiphanyRoleResultStatus, reorientResultStatus: ThreadEpiphanyReorientResultStatus, };

View file

@ -2,4 +2,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type ThreadEpiphanySceneAction = "index" | "retrieve" | "distill" | "context" | "jobs" | "roles" | "roleLaunch" | "roleResult" | "jobLaunch" | "jobInterrupt" | "freshness" | "pressure" | "reorient" | "crrc" | "reorientLaunch" | "reorientResult" | "reorientAccept" | "propose" | "promote" | "update";
export type ThreadEpiphanySceneAction = "index" | "retrieve" | "distill" | "context" | "jobs" | "roles" | "coordinator" | "roleLaunch" | "roleResult" | "jobLaunch" | "jobInterrupt" | "freshness" | "pressure" | "reorient" | "crrc" | "reorientLaunch" | "reorientResult" | "reorientAccept" | "propose" | "promote" | "update";

View file

@ -321,6 +321,8 @@ export type { ThreadEpiphanyContext } from "./ThreadEpiphanyContext";
export type { ThreadEpiphanyContextMissing } from "./ThreadEpiphanyContextMissing";
export type { ThreadEpiphanyContextSource } from "./ThreadEpiphanyContextSource";
export type { ThreadEpiphanyContextStateStatus } from "./ThreadEpiphanyContextStateStatus";
export type { ThreadEpiphanyCoordinatorAction } from "./ThreadEpiphanyCoordinatorAction";
export type { ThreadEpiphanyCoordinatorSignals } from "./ThreadEpiphanyCoordinatorSignals";
export type { ThreadEpiphanyCrrcAction } from "./ThreadEpiphanyCrrcAction";
export type { ThreadEpiphanyCrrcRecommendation } from "./ThreadEpiphanyCrrcRecommendation";
export type { ThreadEpiphanyFreshnessSource } from "./ThreadEpiphanyFreshnessSource";

View file

@ -351,6 +351,11 @@ client_request_definitions! {
params: v2::ThreadEpiphanyRolesParams,
response: v2::ThreadEpiphanyRolesResponse,
},
#[experimental("thread/epiphany/coordinator")]
ThreadEpiphanyCoordinator => "thread/epiphany/coordinator" {
params: v2::ThreadEpiphanyCoordinatorParams,
response: v2::ThreadEpiphanyCoordinatorResponse,
},
#[experimental("thread/epiphany/roleLaunch")]
ThreadEpiphanyRoleLaunch => "thread/epiphany/roleLaunch" {
params: v2::ThreadEpiphanyRoleLaunchParams,
@ -1742,6 +1747,7 @@ mod tests {
v2::ThreadEpiphanySceneAction::Context,
v2::ThreadEpiphanySceneAction::Jobs,
v2::ThreadEpiphanySceneAction::Roles,
v2::ThreadEpiphanySceneAction::Coordinator,
v2::ThreadEpiphanySceneAction::RoleLaunch,
v2::ThreadEpiphanySceneAction::RoleResult,
v2::ThreadEpiphanySceneAction::JobLaunch,
@ -1846,6 +1852,7 @@ mod tests {
"context",
"jobs",
"roles",
"coordinator",
"roleLaunch",
"roleResult",
"jobLaunch",
@ -2012,6 +2019,89 @@ mod tests {
Ok(())
}
#[test]
fn serialize_thread_epiphany_coordinator_response() -> Result<()> {
let response = ClientResponse::ThreadEpiphanyCoordinator {
request_id: RequestId::Integer(8),
response: v2::ThreadEpiphanyCoordinatorResponse {
thread_id: "thr_123".to_string(),
source: v2::ThreadEpiphanyRolesSource::Live,
state_status: v2::ThreadEpiphanyReorientStateStatus::Ready,
state_revision: Some(4),
action: v2::ThreadEpiphanyCoordinatorAction::LaunchModeling,
target_role: Some(v2::ThreadEpiphanyRoleId::Modeling),
recommended_scene_action: Some(v2::ThreadEpiphanySceneAction::RoleLaunch),
requires_review: false,
can_auto_run: true,
reason: "The modeling/checkpoint lane is ready.".to_string(),
source_signals: v2::ThreadEpiphanyCoordinatorSignals {
pressure_level: v2::ThreadEpiphanyPressureLevel::Low,
should_prepare_compaction: false,
reorient_action: v2::ThreadEpiphanyReorientAction::Resume,
crrc_action: v2::ThreadEpiphanyCrrcAction::Continue,
modeling_result_status: v2::ThreadEpiphanyRoleResultStatus::MissingBinding,
verification_result_status: v2::ThreadEpiphanyRoleResultStatus::MissingBinding,
reorient_result_status: v2::ThreadEpiphanyReorientResultStatus::MissingBinding,
},
roles: vec![v2::ThreadEpiphanyRoleLane {
id: v2::ThreadEpiphanyRoleId::Modeling,
title: "Modeling / Checkpoint".to_string(),
owner_role: "epiphany-modeler".to_string(),
status: v2::ThreadEpiphanyRoleStatus::Ready,
note: "Checkpoint ready.".to_string(),
jobs: Vec::new(),
authority_scopes: vec!["thread/epiphany/roleLaunch".to_string()],
recommended_action: Some(v2::ThreadEpiphanySceneAction::RoleLaunch),
}],
note: "Coordinator is read-only.".to_string(),
},
};
assert_eq!(response.id(), &RequestId::Integer(8));
assert_eq!(response.method(), "thread/epiphany/coordinator");
assert_eq!(
json!({
"method": "thread/epiphany/coordinator",
"id": 8,
"response": {
"threadId": "thr_123",
"source": "live",
"stateStatus": "ready",
"stateRevision": 4,
"action": "launchModeling",
"targetRole": "modeling",
"recommendedSceneAction": "roleLaunch",
"requiresReview": false,
"canAutoRun": true,
"reason": "The modeling/checkpoint lane is ready.",
"sourceSignals": {
"pressureLevel": "low",
"shouldPrepareCompaction": false,
"reorientAction": "resume",
"crrcAction": "continue",
"modelingResultStatus": "missingBinding",
"verificationResultStatus": "missingBinding",
"reorientResultStatus": "missingBinding"
},
"roles": [
{
"id": "modeling",
"title": "Modeling / Checkpoint",
"ownerRole": "epiphany-modeler",
"status": "ready",
"note": "Checkpoint ready.",
"authorityScopes": ["thread/epiphany/roleLaunch"],
"recommendedAction": "roleLaunch"
}
],
"note": "Coordinator is read-only."
}
}),
serde_json::to_value(&response)?,
);
Ok(())
}
#[test]
fn serialize_thread_epiphany_role_launch_response() -> Result<()> {
let response = ClientResponse::ThreadEpiphanyRoleLaunch {
@ -4211,6 +4301,18 @@ mod tests {
assert_eq!(reason, Some("thread/epiphany/roles"));
}
#[test]
fn thread_epiphany_coordinator_is_marked_experimental() {
let request = ClientRequest::ThreadEpiphanyCoordinator {
request_id: RequestId::Integer(1),
params: v2::ThreadEpiphanyCoordinatorParams {
thread_id: "thr_123".to_string(),
},
};
let reason = crate::experimental_api::ExperimentalApi::experimental_reason(&request);
assert_eq!(reason, Some("thread/epiphany/coordinator"));
}
#[test]
fn thread_epiphany_role_launch_is_marked_experimental() {
let request = ClientRequest::ThreadEpiphanyRoleLaunch {

View file

@ -3998,6 +3998,7 @@ pub enum ThreadEpiphanySceneAction {
Context,
Jobs,
Roles,
Coordinator,
RoleLaunch,
RoleResult,
JobLaunch,
@ -4303,6 +4304,68 @@ pub enum ThreadEpiphanyRoleResultStatus {
Cancelled,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct ThreadEpiphanyCoordinatorParams {
pub thread_id: String,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct ThreadEpiphanyCoordinatorResponse {
pub thread_id: String,
pub source: ThreadEpiphanyRolesSource,
pub state_status: ThreadEpiphanyReorientStateStatus,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional = nullable)]
pub state_revision: Option<u64>,
pub action: ThreadEpiphanyCoordinatorAction,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional = nullable)]
pub target_role: Option<ThreadEpiphanyRoleId>,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional = nullable)]
pub recommended_scene_action: Option<ThreadEpiphanySceneAction>,
pub requires_review: bool,
pub can_auto_run: bool,
pub reason: String,
pub source_signals: ThreadEpiphanyCoordinatorSignals,
pub roles: Vec<ThreadEpiphanyRoleLane>,
pub note: String,
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub enum ThreadEpiphanyCoordinatorAction {
PrepareCheckpoint,
CompactRehydrateReorient,
LaunchReorientWorker,
WaitForReorientWorker,
ReviewReorientResult,
RegatherManually,
LaunchModeling,
ReviewModelingResult,
LaunchVerification,
ReviewVerificationResult,
ContinueImplementation,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct ThreadEpiphanyCoordinatorSignals {
pub pressure_level: ThreadEpiphanyPressureLevel,
pub should_prepare_compaction: bool,
pub reorient_action: ThreadEpiphanyReorientAction,
pub crrc_action: ThreadEpiphanyCrrcAction,
pub modeling_result_status: ThreadEpiphanyRoleResultStatus,
pub verification_result_status: ThreadEpiphanyRoleResultStatus,
pub reorient_result_status: ThreadEpiphanyReorientResultStatus,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]

View file

@ -154,6 +154,10 @@ use codex_app_server_protocol::ThreadEpiphanyContextParams;
use codex_app_server_protocol::ThreadEpiphanyContextResponse;
use codex_app_server_protocol::ThreadEpiphanyContextSource;
use codex_app_server_protocol::ThreadEpiphanyContextStateStatus;
use codex_app_server_protocol::ThreadEpiphanyCoordinatorAction;
use codex_app_server_protocol::ThreadEpiphanyCoordinatorParams;
use codex_app_server_protocol::ThreadEpiphanyCoordinatorResponse;
use codex_app_server_protocol::ThreadEpiphanyCoordinatorSignals;
use codex_app_server_protocol::ThreadEpiphanyCrrcAction;
use codex_app_server_protocol::ThreadEpiphanyCrrcParams;
use codex_app_server_protocol::ThreadEpiphanyCrrcRecommendation;
@ -1102,6 +1106,10 @@ impl CodexMessageProcessor {
self.thread_epiphany_roles(to_connection_request_id(request_id), params)
.await;
}
ClientRequest::ThreadEpiphanyCoordinator { request_id, params } => {
self.thread_epiphany_coordinator(to_connection_request_id(request_id), params)
.await;
}
ClientRequest::ThreadEpiphanyRoleLaunch { request_id, params } => {
self.thread_epiphany_role_launch(to_connection_request_id(request_id), params)
.await;
@ -4468,6 +4476,216 @@ impl CodexMessageProcessor {
self.outgoing.send_response(request_id, response).await;
}
async fn thread_epiphany_coordinator(
&self,
request_id: ConnectionRequestId,
params: ThreadEpiphanyCoordinatorParams,
) {
let ThreadEpiphanyCoordinatorParams { thread_id } = params;
let thread_uuid = match ThreadId::from_string(&thread_id) {
Ok(id) => id,
Err(err) => {
self.send_invalid_request_error(request_id, format!("invalid thread id: {err}"))
.await;
return;
}
};
let loaded_thread = self.thread_manager.get_thread(thread_uuid).await.ok();
let loaded = loaded_thread.is_some();
let thread = match self.read_thread_view(thread_uuid, false).await {
Ok(thread) => thread,
Err(ThreadReadViewError::InvalidRequest(message)) => {
self.send_invalid_request_error(request_id, message).await;
return;
}
Err(ThreadReadViewError::Internal(message)) => {
self.send_internal_error(request_id, message).await;
return;
}
};
let retrieval_override = if let Some(loaded_thread) = loaded_thread.as_ref() {
Some(loaded_thread.epiphany_retrieval_state().await)
} else {
None
};
let watcher_snapshot = if let Some(loaded_thread) = loaded_thread.as_ref() {
let config_snapshot = loaded_thread.config_snapshot().await;
self.epiphany_invalidation_manager
.ensure_thread_watch(&thread_id, &config_snapshot.cwd)
.await;
Some(
self.epiphany_invalidation_manager
.snapshot(&thread_id)
.await,
)
} else {
None
};
let (source, token_usage_info) = if let Some(loaded_thread) = loaded_thread.as_ref() {
(
ThreadEpiphanyRolesSource::Live,
loaded_thread.token_usage_info().await,
)
} else {
let token_usage_info = match thread.path.as_deref() {
Some(path) => latest_token_usage_info_from_rollout_path(path).await,
None => None,
};
(ThreadEpiphanyRolesSource::Stored, token_usage_info)
};
let (state_revision, retrieval, graph, watcher) = map_epiphany_freshness(
thread.epiphany_state.as_ref(),
retrieval_override.as_ref(),
watcher_snapshot.as_ref(),
);
let pressure = map_epiphany_pressure(token_usage_info.as_ref());
let (state_status, decision) = map_epiphany_reorient(
thread.epiphany_state.as_ref(),
&pressure,
&retrieval,
&graph,
&watcher,
);
let mut state_db_ctx = if let Some(loaded_thread) = loaded_thread.as_ref() {
loaded_thread.epiphany_state_runtime().await
} else {
None
};
if state_db_ctx.is_none() {
state_db_ctx = open_state_db_for_direct_thread_lookup(&self.config).await;
}
let job_resolution = load_epiphany_job_launcher_snapshots(
state_db_ctx.as_ref(),
thread.epiphany_state.as_ref(),
)
.await;
let jobs = map_epiphany_jobs(
thread.epiphany_state.as_ref(),
retrieval_override.as_ref(),
&job_resolution,
);
let reorient_job = jobs
.iter()
.find(|job| job.id == EPIPHANY_REORIENT_LAUNCH_BINDING_ID)
.cloned();
let (reorient_result_status, reorient_finding, _) = load_epiphany_reorient_result_snapshot(
thread.epiphany_state.as_ref(),
state_db_ctx.as_ref(),
EPIPHANY_REORIENT_LAUNCH_BINDING_ID,
)
.await;
let checkpoint_present = thread
.epiphany_state
.as_ref()
.and_then(|state| state.investigation_checkpoint.as_ref())
.is_some();
let recommendation = map_epiphany_crrc_recommendation(
loaded,
state_status,
&pressure,
&decision,
reorient_result_status,
checkpoint_present,
reorient_finding.is_some(),
reorient_finding.as_ref().is_some_and(|finding| {
thread
.epiphany_state
.as_ref()
.is_some_and(|state| epiphany_reorient_finding_already_accepted(state, finding))
}),
);
let roles = map_epiphany_roles(
thread.epiphany_state.as_ref(),
&jobs,
&decision,
&pressure,
&recommendation,
reorient_result_status,
reorient_job.as_ref(),
);
let (modeling_result_status, _, _) = if let Some(state) = thread.epiphany_state.as_ref() {
load_epiphany_role_result_snapshot(
state,
state_db_ctx.as_ref(),
ThreadEpiphanyRoleId::Modeling,
EPIPHANY_MODELING_ROLE_BINDING_ID,
)
.await
} else {
(
ThreadEpiphanyRoleResultStatus::MissingState,
None,
"No authoritative Epiphany state exists for this thread.".to_string(),
)
};
let (verification_result_status, _, _) = if let Some(state) = thread.epiphany_state.as_ref()
{
load_epiphany_role_result_snapshot(
state,
state_db_ctx.as_ref(),
ThreadEpiphanyRoleId::Verification,
EPIPHANY_VERIFICATION_ROLE_BINDING_ID,
)
.await
} else {
(
ThreadEpiphanyRoleResultStatus::MissingState,
None,
"No authoritative Epiphany state exists for this thread.".to_string(),
)
};
let source_signals = ThreadEpiphanyCoordinatorSignals {
pressure_level: pressure.level,
should_prepare_compaction: pressure.should_prepare_compaction,
reorient_action: decision.action,
crrc_action: recommendation.action,
modeling_result_status,
verification_result_status,
reorient_result_status,
};
let coordinator = map_epiphany_coordinator(
state_status,
checkpoint_present,
&pressure,
&recommendation,
&roles,
&source_signals,
);
let note = format!(
"Coordinator is read-only. It recommends {:?} from CRRC {:?}, pressure {:?}, modeling {:?}, verification {:?}, and reorient {:?}.",
coordinator.action,
recommendation.action,
pressure.level,
modeling_result_status,
verification_result_status,
reorient_result_status,
);
let response = ThreadEpiphanyCoordinatorResponse {
thread_id,
source,
state_status,
state_revision,
action: coordinator.action,
target_role: coordinator.target_role,
recommended_scene_action: coordinator.recommended_scene_action,
requires_review: coordinator.requires_review,
can_auto_run: coordinator.can_auto_run,
reason: coordinator.reason,
source_signals,
roles,
note,
};
self.outgoing.send_response(request_id, response).await;
}
async fn thread_epiphany_role_launch(
&self,
request_id: ConnectionRequestId,
@ -12488,6 +12706,7 @@ fn epiphany_scene_available_actions(
ThreadEpiphanySceneAction::Context,
ThreadEpiphanySceneAction::Jobs,
ThreadEpiphanySceneAction::Roles,
ThreadEpiphanySceneAction::Coordinator,
ThreadEpiphanySceneAction::RoleLaunch,
ThreadEpiphanySceneAction::RoleResult,
ThreadEpiphanySceneAction::JobLaunch,
@ -13282,6 +13501,221 @@ fn map_epiphany_crrc_recommendation(
)
}
struct EpiphanyCoordinatorDecision {
action: ThreadEpiphanyCoordinatorAction,
target_role: Option<ThreadEpiphanyRoleId>,
recommended_scene_action: Option<ThreadEpiphanySceneAction>,
requires_review: bool,
can_auto_run: bool,
reason: String,
}
fn map_epiphany_coordinator(
state_status: ThreadEpiphanyReorientStateStatus,
checkpoint_present: bool,
pressure: &ThreadEpiphanyPressure,
recommendation: &ThreadEpiphanyCrrcRecommendation,
roles: &[ThreadEpiphanyRoleLane],
signals: &ThreadEpiphanyCoordinatorSignals,
) -> EpiphanyCoordinatorDecision {
let build = |action,
target_role,
recommended_scene_action,
requires_review,
can_auto_run,
reason: &str| EpiphanyCoordinatorDecision {
action,
target_role,
recommended_scene_action,
requires_review,
can_auto_run,
reason: reason.to_string(),
};
if state_status == ThreadEpiphanyReorientStateStatus::Missing || !checkpoint_present {
return build(
ThreadEpiphanyCoordinatorAction::PrepareCheckpoint,
Some(ThreadEpiphanyRoleId::Modeling),
Some(ThreadEpiphanySceneAction::Update),
false,
false,
"Authoritative state or investigation checkpoint is missing; prepare a checkpoint before coordination can continue.",
);
}
match recommendation.action {
ThreadEpiphanyCrrcAction::WaitForReorientWorker => {
return build(
ThreadEpiphanyCoordinatorAction::WaitForReorientWorker,
Some(ThreadEpiphanyRoleId::Reorientation),
Some(ThreadEpiphanySceneAction::ReorientResult),
false,
false,
"A CRRC reorient worker is already in flight; wait for the bounded result.",
);
}
ThreadEpiphanyCrrcAction::AcceptReorientResult
| ThreadEpiphanyCrrcAction::ReviewReorientResult => {
return build(
ThreadEpiphanyCoordinatorAction::ReviewReorientResult,
Some(ThreadEpiphanyRoleId::Reorientation),
recommendation.recommended_scene_action,
true,
false,
"A CRRC reorientation finding needs human review before continuation.",
);
}
ThreadEpiphanyCrrcAction::RegatherManually => {
return build(
ThreadEpiphanyCoordinatorAction::RegatherManually,
Some(ThreadEpiphanyRoleId::Reorientation),
recommendation.recommended_scene_action,
true,
false,
"CRRC cannot safely continue automatically; manual regathering is required.",
);
}
ThreadEpiphanyCrrcAction::PrepareCheckpoint
| ThreadEpiphanyCrrcAction::LaunchReorientWorker
| ThreadEpiphanyCrrcAction::Continue => {}
}
if pressure.should_prepare_compaction {
return build(
ThreadEpiphanyCoordinatorAction::CompactRehydrateReorient,
Some(ThreadEpiphanyRoleId::Reorientation),
Some(ThreadEpiphanySceneAction::Reorient),
false,
true,
"Context pressure crossed the preparation threshold; compact, rehydrate, and reorient before more implementation work.",
);
}
if recommendation.action == ThreadEpiphanyCrrcAction::LaunchReorientWorker {
return build(
ThreadEpiphanyCoordinatorAction::LaunchReorientWorker,
Some(ThreadEpiphanyRoleId::Reorientation),
Some(ThreadEpiphanySceneAction::ReorientLaunch),
false,
true,
"CRRC says continuity needs a bounded reorient worker before safe continuation.",
);
}
if signals.verification_result_status == ThreadEpiphanyRoleResultStatus::Completed {
return build(
ThreadEpiphanyCoordinatorAction::ReviewVerificationResult,
Some(ThreadEpiphanyRoleId::Verification),
Some(ThreadEpiphanySceneAction::RoleResult),
true,
false,
"A verification/review finding is complete and must be reviewed before continuation.",
);
}
if signals.modeling_result_status == ThreadEpiphanyRoleResultStatus::Completed {
return build(
ThreadEpiphanyCoordinatorAction::LaunchVerification,
Some(ThreadEpiphanyRoleId::Verification),
Some(ThreadEpiphanySceneAction::RoleLaunch),
false,
true,
"Modeling/checkpoint guidance is available; run verification before implementation continues.",
);
}
if role_status(roles, ThreadEpiphanyRoleId::Modeling).is_some_and(|status| {
matches!(
status,
ThreadEpiphanyRoleStatus::Ready | ThreadEpiphanyRoleStatus::Needed
)
}) && matches!(
signals.modeling_result_status,
ThreadEpiphanyRoleResultStatus::MissingBinding
| ThreadEpiphanyRoleResultStatus::BackendMissing
| ThreadEpiphanyRoleResultStatus::Cancelled
| ThreadEpiphanyRoleResultStatus::Failed
) {
return build(
ThreadEpiphanyCoordinatorAction::LaunchModeling,
Some(ThreadEpiphanyRoleId::Modeling),
Some(ThreadEpiphanySceneAction::RoleLaunch),
false,
true,
"The modeling/checkpoint lane is ready and no current modeling finding is available.",
);
}
if matches!(
signals.modeling_result_status,
ThreadEpiphanyRoleResultStatus::Pending | ThreadEpiphanyRoleResultStatus::Running
) {
return build(
ThreadEpiphanyCoordinatorAction::ReviewModelingResult,
Some(ThreadEpiphanyRoleId::Modeling),
Some(ThreadEpiphanySceneAction::RoleResult),
false,
false,
"A modeling/checkpoint specialist is already running; wait for its result.",
);
}
if role_status(roles, ThreadEpiphanyRoleId::Verification).is_some_and(|status| {
matches!(
status,
ThreadEpiphanyRoleStatus::Ready | ThreadEpiphanyRoleStatus::Needed
)
}) && matches!(
signals.verification_result_status,
ThreadEpiphanyRoleResultStatus::MissingBinding
| ThreadEpiphanyRoleResultStatus::BackendMissing
| ThreadEpiphanyRoleResultStatus::Cancelled
| ThreadEpiphanyRoleResultStatus::Failed
) {
return build(
ThreadEpiphanyCoordinatorAction::LaunchVerification,
Some(ThreadEpiphanyRoleId::Verification),
Some(ThreadEpiphanySceneAction::RoleLaunch),
false,
true,
"The verification/review lane is ready and no current verification finding is available.",
);
}
if matches!(
signals.verification_result_status,
ThreadEpiphanyRoleResultStatus::Pending | ThreadEpiphanyRoleResultStatus::Running
) {
return build(
ThreadEpiphanyCoordinatorAction::ReviewVerificationResult,
Some(ThreadEpiphanyRoleId::Verification),
Some(ThreadEpiphanySceneAction::RoleResult),
false,
false,
"A verification/review specialist is already running; wait for its result.",
);
}
build(
ThreadEpiphanyCoordinatorAction::ContinueImplementation,
Some(ThreadEpiphanyRoleId::Implementation),
None,
false,
false,
"CRRC is clear and no specialist lane is currently blocking implementation.",
)
}
fn role_status(
roles: &[ThreadEpiphanyRoleLane],
role_id: ThreadEpiphanyRoleId,
) -> Option<ThreadEpiphanyRoleStatus> {
roles
.iter()
.find(|role| role.id == role_id)
.map(|role| role.status)
}
fn epiphany_reorient_finding_already_accepted(
state: &EpiphanyThreadState,
finding: &ThreadEpiphanyReorientFinding,
@ -17736,6 +18170,288 @@ mod tests {
assert_eq!(roles[3].status, ThreadEpiphanyRoleStatus::Ready);
}
fn base_coordinator_roles() -> Vec<ThreadEpiphanyRoleLane> {
vec![
coordinator_role(
ThreadEpiphanyRoleId::Implementation,
ThreadEpiphanyRoleStatus::Ready,
),
coordinator_role(
ThreadEpiphanyRoleId::Modeling,
ThreadEpiphanyRoleStatus::Ready,
),
coordinator_role(
ThreadEpiphanyRoleId::Verification,
ThreadEpiphanyRoleStatus::Ready,
),
coordinator_role(
ThreadEpiphanyRoleId::Reorientation,
ThreadEpiphanyRoleStatus::Ready,
),
]
}
fn coordinator_role(
id: ThreadEpiphanyRoleId,
status: ThreadEpiphanyRoleStatus,
) -> ThreadEpiphanyRoleLane {
ThreadEpiphanyRoleLane {
id,
title: format!("{id:?}"),
owner_role: format!("{id:?}"),
status,
note: "test lane".to_string(),
jobs: Vec::new(),
authority_scopes: Vec::new(),
recommended_action: None,
}
}
fn coordinator_signals(
crrc_action: ThreadEpiphanyCrrcAction,
reorient_result_status: ThreadEpiphanyReorientResultStatus,
modeling_result_status: ThreadEpiphanyRoleResultStatus,
verification_result_status: ThreadEpiphanyRoleResultStatus,
) -> ThreadEpiphanyCoordinatorSignals {
ThreadEpiphanyCoordinatorSignals {
pressure_level: ThreadEpiphanyPressureLevel::Low,
should_prepare_compaction: false,
reorient_action: ThreadEpiphanyReorientAction::Resume,
crrc_action,
modeling_result_status,
verification_result_status,
reorient_result_status,
}
}
#[test]
fn map_epiphany_coordinator_prepares_missing_checkpoint() {
let pressure = map_epiphany_pressure(None);
let recommendation = ThreadEpiphanyCrrcRecommendation {
action: ThreadEpiphanyCrrcAction::PrepareCheckpoint,
recommended_scene_action: Some(ThreadEpiphanySceneAction::Update),
reason: "checkpoint missing".to_string(),
};
let roles = base_coordinator_roles();
let signals = coordinator_signals(
ThreadEpiphanyCrrcAction::PrepareCheckpoint,
ThreadEpiphanyReorientResultStatus::MissingBinding,
ThreadEpiphanyRoleResultStatus::MissingBinding,
ThreadEpiphanyRoleResultStatus::MissingBinding,
);
let decision = map_epiphany_coordinator(
ThreadEpiphanyReorientStateStatus::Ready,
false,
&pressure,
&recommendation,
&roles,
&signals,
);
assert_eq!(
decision.action,
ThreadEpiphanyCoordinatorAction::PrepareCheckpoint
);
assert!(!decision.can_auto_run);
}
#[test]
fn map_epiphany_coordinator_compacts_at_pressure_threshold() {
let pressure = map_epiphany_pressure(Some(&CoreTokenUsageInfo {
total_token_usage: codex_protocol::protocol::TokenUsage {
total_tokens: 92,
..Default::default()
},
last_token_usage: codex_protocol::protocol::TokenUsage::default(),
model_context_window: Some(200),
model_auto_compact_token_limit: Some(100),
}));
let recommendation = ThreadEpiphanyCrrcRecommendation {
action: ThreadEpiphanyCrrcAction::Continue,
recommended_scene_action: Some(ThreadEpiphanySceneAction::Reorient),
reason: "continue".to_string(),
};
let roles = base_coordinator_roles();
let signals = coordinator_signals(
ThreadEpiphanyCrrcAction::Continue,
ThreadEpiphanyReorientResultStatus::MissingBinding,
ThreadEpiphanyRoleResultStatus::MissingBinding,
ThreadEpiphanyRoleResultStatus::MissingBinding,
);
let decision = map_epiphany_coordinator(
ThreadEpiphanyReorientStateStatus::Ready,
true,
&pressure,
&recommendation,
&roles,
&signals,
);
assert_eq!(
decision.action,
ThreadEpiphanyCoordinatorAction::CompactRehydrateReorient
);
assert!(decision.can_auto_run);
}
#[test]
fn map_epiphany_coordinator_launches_reorient_worker_from_crrc() {
let pressure = map_epiphany_pressure(None);
let recommendation = ThreadEpiphanyCrrcRecommendation {
action: ThreadEpiphanyCrrcAction::LaunchReorientWorker,
recommended_scene_action: Some(ThreadEpiphanySceneAction::ReorientLaunch),
reason: "regather".to_string(),
};
let roles = base_coordinator_roles();
let signals = coordinator_signals(
ThreadEpiphanyCrrcAction::LaunchReorientWorker,
ThreadEpiphanyReorientResultStatus::MissingBinding,
ThreadEpiphanyRoleResultStatus::MissingBinding,
ThreadEpiphanyRoleResultStatus::MissingBinding,
);
let decision = map_epiphany_coordinator(
ThreadEpiphanyReorientStateStatus::Ready,
true,
&pressure,
&recommendation,
&roles,
&signals,
);
assert_eq!(
decision.action,
ThreadEpiphanyCoordinatorAction::LaunchReorientWorker
);
assert_eq!(
decision.target_role,
Some(ThreadEpiphanyRoleId::Reorientation)
);
assert!(decision.can_auto_run);
}
#[test]
fn map_epiphany_coordinator_reviews_reorient_result() {
let pressure = map_epiphany_pressure(None);
let recommendation = ThreadEpiphanyCrrcRecommendation {
action: ThreadEpiphanyCrrcAction::AcceptReorientResult,
recommended_scene_action: Some(ThreadEpiphanySceneAction::ReorientAccept),
reason: "review".to_string(),
};
let roles = base_coordinator_roles();
let signals = coordinator_signals(
ThreadEpiphanyCrrcAction::AcceptReorientResult,
ThreadEpiphanyReorientResultStatus::Completed,
ThreadEpiphanyRoleResultStatus::MissingBinding,
ThreadEpiphanyRoleResultStatus::MissingBinding,
);
let decision = map_epiphany_coordinator(
ThreadEpiphanyReorientStateStatus::Ready,
true,
&pressure,
&recommendation,
&roles,
&signals,
);
assert_eq!(
decision.action,
ThreadEpiphanyCoordinatorAction::ReviewReorientResult
);
assert!(decision.requires_review);
}
#[test]
fn map_epiphany_coordinator_runs_modeling_then_verification_then_continue() {
let pressure = map_epiphany_pressure(None);
let recommendation = ThreadEpiphanyCrrcRecommendation {
action: ThreadEpiphanyCrrcAction::Continue,
recommended_scene_action: Some(ThreadEpiphanySceneAction::Reorient),
reason: "continue".to_string(),
};
let roles = base_coordinator_roles();
let missing = coordinator_signals(
ThreadEpiphanyCrrcAction::Continue,
ThreadEpiphanyReorientResultStatus::MissingBinding,
ThreadEpiphanyRoleResultStatus::MissingBinding,
ThreadEpiphanyRoleResultStatus::MissingBinding,
);
let launch_modeling = map_epiphany_coordinator(
ThreadEpiphanyReorientStateStatus::Ready,
true,
&pressure,
&recommendation,
&roles,
&missing,
);
assert_eq!(
launch_modeling.action,
ThreadEpiphanyCoordinatorAction::LaunchModeling
);
let modeling_done = coordinator_signals(
ThreadEpiphanyCrrcAction::Continue,
ThreadEpiphanyReorientResultStatus::MissingBinding,
ThreadEpiphanyRoleResultStatus::Completed,
ThreadEpiphanyRoleResultStatus::MissingBinding,
);
let launch_verification = map_epiphany_coordinator(
ThreadEpiphanyReorientStateStatus::Ready,
true,
&pressure,
&recommendation,
&roles,
&modeling_done,
);
assert_eq!(
launch_verification.action,
ThreadEpiphanyCoordinatorAction::LaunchVerification
);
let verification_done = coordinator_signals(
ThreadEpiphanyCrrcAction::Continue,
ThreadEpiphanyReorientResultStatus::MissingBinding,
ThreadEpiphanyRoleResultStatus::Completed,
ThreadEpiphanyRoleResultStatus::Completed,
);
let review_verification = map_epiphany_coordinator(
ThreadEpiphanyReorientStateStatus::Ready,
true,
&pressure,
&recommendation,
&roles,
&verification_done,
);
assert_eq!(
review_verification.action,
ThreadEpiphanyCoordinatorAction::ReviewVerificationResult
);
assert!(review_verification.requires_review);
let reviewed = coordinator_signals(
ThreadEpiphanyCrrcAction::Continue,
ThreadEpiphanyReorientResultStatus::MissingBinding,
ThreadEpiphanyRoleResultStatus::BackendMissing,
ThreadEpiphanyRoleResultStatus::BackendMissing,
);
let continue_implementation = map_epiphany_coordinator(
ThreadEpiphanyReorientStateStatus::Ready,
true,
&pressure,
&recommendation,
&[],
&reviewed,
);
assert_eq!(
continue_implementation.action,
ThreadEpiphanyCoordinatorAction::ContinueImplementation
);
}
#[test]
fn build_epiphany_role_launch_request_uses_fixed_mvp_templates() {
let state = codex_protocol::protocol::EpiphanyThreadState {