From 289ab31e6448deb081424bf3d28a9d36b28d2ed6 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 28 Apr 2026 11:27:57 +0100 Subject: [PATCH] Add Epiphany reorient result acceptance --- notes/epiphany-core-harness-surfaces.md | 29 +- notes/epiphany-current-algorithmic-map.md | 9 +- notes/epiphany-fork-implementation-plan.md | 19 +- notes/fresh-workspace-handoff.md | 12 +- state/evidence.jsonl | 1 + state/map.yaml | 6 +- .../epiphany_phase6_reorient_launch_smoke.py | 66 ++- .../schema/json/ServerNotification.json | 3 +- .../codex_app_server_protocol.schemas.json | 4 +- .../codex_app_server_protocol.v2.schemas.json | 4 +- ...hreadEpiphanyStateUpdatedNotification.json | 3 +- .../v2/ThreadEpiphanySceneAction.ts | 2 +- .../v2/ThreadEpiphanyStateUpdatedSource.ts | 2 +- .../src/protocol/common.rs | 119 +++++ .../app-server-protocol/src/protocol/v2.rs | 32 ++ .../app-server/src/codex_message_processor.rs | 433 ++++++++++++++++++ 16 files changed, 707 insertions(+), 37 deletions(-) diff --git a/notes/epiphany-core-harness-surfaces.md b/notes/epiphany-core-harness-surfaces.md index a8de15d0..99c60a52 100644 --- a/notes/epiphany-core-harness-surfaces.md +++ b/notes/epiphany-core-harness-surfaces.md @@ -50,6 +50,7 @@ The rule is: | `thread/epiphany/jobInterrupt` | bounded authority write | landed, live-smoked | Interrupts the current backend adapter for a bound launcher job, clears backend identity from the durable `jobBinding`, and emits `stateUpdated` with source `jobInterrupt`. | | `thread/epiphany/reorientLaunch` | bounded authority write | landed, live-smoked | Consumes the read-only reorientation verdict and launches one fixed `reorient-worker` job with explicit resume/regather scope over the current backend adapter. | | `thread/epiphany/reorientResult` | read-only result read-back | landed, live-smoked | Reads the fixed or requested reorient-worker binding through the current backend adapter and projects completed worker output as a reviewable finding without promotion or mutation. | +| `thread/epiphany/reorientAccept` | explicit acceptance write | landed, live-smoked | Requires a completed reorient-worker result, then appends accepted observation/evidence and optionally updates scratch/checkpoint with a distinct state update source. | | `thread/epiphany/jobsUpdated` | notification | landed | Emits changed launcher-bound job snapshots for real runtime progress events when the mapped payload actually changes. | | `thread/epiphany/scene` | read-only reflection | landed, live-smoked | Compact client scene derived from authoritative Epiphany state, including checkpoint summary reflection. | | `thread/epiphany/jobs` | read-only reflection | landed, live-smoked | Derived indexing, remap, verification, and specialist-progress slots from typed state and retrieval summaries, with durable launcher metadata plus live backend overlay when a real owner exists. | @@ -69,6 +70,7 @@ Durable Epiphany state may change through: - `thread/epiphany/jobLaunch` - `thread/epiphany/jobInterrupt` - `thread/epiphany/reorientLaunch` +- `thread/epiphany/reorientAccept` - normal rollout persistence of the current live `EpiphanyThreadState` The following must stay read-only: @@ -140,8 +142,6 @@ Metaphor is compression after source context. It is not decoration for guesses. These are not landed yet: - richer evidence-range and graph-shard inspection beyond the landed context shard -- bounded acceptance/promotion of reviewed reorient-worker findings into typed - observations, scratch/checkpoint updates, or continuation packets - automatic watcher-driven graph/retrieval/invariant invalidation policy on top of the landed freshness reflection - automatic tool-output observation promotion - typed turn intent before broad mutation @@ -178,10 +178,10 @@ Out of scope for the MVP: - a second job backend unless the current `agent_jobs` adapter blocks read-back or interruption -The first read-back blocker is landed. The current MVP blocker is the -acceptance path after read-back: the harness can inspect a worker finding, but -it still needs a bounded way to turn an accepted finding into typed state or the -next continuation packet. +The first read-back and acceptance blockers are landed. The current MVP blocker +is bounded CRRC coordination: deciding when the harness should recommend or +request the landed pressure -> verdict -> launch -> result -> accept loop +without becoming an ambient scheduler. ## Job And Progress Surface Direction @@ -215,6 +215,14 @@ inspected files, frontier ids, evidence ids, and raw result. It does not promote the finding, mutate typed state, schedule follow-up work, or continue the task for the agent. +The first explicit acceptance surface over that finding is also landed as +`thread/epiphany/reorientAccept`. It requires a completed reorient-worker +result, appends an accepted observation and evidence record, and can explicitly +bank the finding into scratch or the durable investigation checkpoint when the +caller asks for those writes. It emits `thread/epiphany/stateUpdated` with +source `reorientAccept`; it does not accept pending work, auto-promote arbitrary +worker output, launch follow-up jobs, or silently continue implementation. + The first live bound-runtime progress notification is also landed as `thread/epiphany/jobsUpdated`. It rides existing `agent_job_progress:{json}` background events from the runtime job runner, resolves matching launcher @@ -343,10 +351,11 @@ prompt/scene/context reflection, the first bounded policy verdict now exists as the thin job seam, one explicit `thread/epiphany/reorientLaunch` consumer can act on that verdict without becoming a hidden scheduler, and `thread/epiphany/reorientResult` can read that worker's finding back for human -or client review. What does not exist yet is the acceptance/promotion path that -turns reviewed findings into typed state or a continuation packet, nor the -automatic runtime coordinator that decides when to launch the worker. Automatic -CRRC still needs explicit runtime policy, bounded job ownership, clean stopping +or client review, and `thread/epiphany/reorientAccept` can explicitly bank an +accepted finding into typed observation/evidence plus optional scratch or +checkpoint state. What does not exist yet is the automatic runtime coordinator +that decides when to launch the worker or request acceptance. Automatic CRRC +still needs explicit runtime policy, bounded job ownership, clean stopping rules, and honest result plumbing instead of vibes with a clipboard. Compaction should squeeze scratch, not the map. diff --git a/notes/epiphany-current-algorithmic-map.md b/notes/epiphany-current-algorithmic-map.md index 73c6fd5e..f8efec25 100644 --- a/notes/epiphany-current-algorithmic-map.md +++ b/notes/epiphany-current-algorithmic-map.md @@ -10,7 +10,7 @@ The important question for this file is not "what is Epiphany supposed to become Current Epiphany is a forked Codex harness with a typed modeling spine. -The spine exists in twenty live paths: +The spine exists in twenty-one live paths: - protocol state shape: `EpiphanyThreadState`, `RolloutItem::EpiphanyState`, retrieval summaries, and prompt tags live in [protocol.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/protocol/src/protocol.rs:103). - in-memory session state: `SessionState` stores an optional `EpiphanyThreadState`, and `Session` exposes thin async accessors over it in [state/session.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/state/session.rs:36) and [session/mod.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/session/mod.rs:1240). @@ -32,6 +32,7 @@ The spine exists in twenty live paths: - reorientation policy: app-server declares experimental read-only `thread/epiphany/reorient`, reuses the same live/stored thread view plus mapped pressure/freshness/watcher signals, and derives a bounded `resume`/`regather` verdict with checkpoint-path/frontier reasons without mutating, compacting, scheduling, notifying, or continuing work in [common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:365), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4514), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4394), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:11424). - reorientation launch: app-server now declares experimental `thread/epiphany/reorientLaunch`, requires a loaded thread plus durable investigation checkpoint, consumes the live reorientation verdict, and launches one fixed `reorient-worker` binding through the existing job-control seam with explicit resume-versus-regather scope, checkpoint-derived payload, and structured-output expectations instead of pretending CRRC suddenly grew a scheduler in [common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:370), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4575), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4519). - reorientation result read-back: app-server now declares experimental read-only `thread/epiphany/reorientResult`, defaults to the fixed `reorient-worker` binding, resolves that binding through the current `agent_jobs` backend when available, reads the single backend item result, and projects a reviewable finding with mode, summary, next safe move, checkpoint-validity flag, inspected files, frontier ids, evidence ids, raw result, and any job/item errors without mutating state, promoting evidence, or scheduling follow-up work in [common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:374), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4610), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4684). +- reorientation finding acceptance: app-server now declares experimental `thread/epiphany/reorientAccept`, requires a loaded thread and a completed `reorient-worker` backend result, appends accepted observation/evidence records, optionally banks the finding into scratch and the durable investigation checkpoint, persists through the normal typed update path, and emits `thread/epiphany/stateUpdated` with source `reorientAccept` without accepting pending work, auto-promoting arbitrary worker output, launching follow-up work, or silently continuing implementation in [common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:378), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4635), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4885). - retrieval/indexing: app-server routes `thread/epiphany/retrieve` and `thread/epiphany/index` through loaded `CodexThread` host methods into `epiphany-core` in [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4356), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4432), [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:467), and [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:449). The thick Epiphany-owned implementation is mostly outside vendored Codex now: @@ -84,6 +85,8 @@ flowchart TD QR --> QRL["thread/epiphany/reorientLaunch can explicitly consume that verdict"] QRL --> QRLR["thread/epiphany/reorientResult reads back worker findings"] QRLR --> Q + QRLR --> QRLA["thread/epiphany/reorientAccept can bank reviewed findings"] + QRLA --> J A --> R["thread/epiphany/retrieve requires loaded thread"] A --> S["thread/epiphany/index requires loaded thread"] A --> AA["thread/epiphany/distill requires loaded thread"] @@ -1296,7 +1299,7 @@ These are deliberately not shipped yet: - no broad live Epiphany event stream beyond `thread/epiphany/stateUpdated` for successful update/promote writes. - no automatic evidence promotion from tool output; the current distill/propose/promote path still requires explicit verifier-backed calls. -- no automatic Compact-Rehydrate-Reorient-Continue coordinator; current code preserves and rehydrates valid Epiphany snapshots across resume/rollback/compaction, exposes context pressure, carries a durable investigation checkpoint packet, returns a read-only reorientation verdict, can explicitly launch one bounded reorientation worker, and can read that worker's result back through a reviewable surface, but runtime launch policy and next-step execution are still explicit rather than ambient scheduler behavior. +- no automatic Compact-Rehydrate-Reorient-Continue coordinator; current code preserves and rehydrates valid Epiphany snapshots across resume/rollback/compaction, exposes context pressure, carries a durable investigation checkpoint packet, returns a read-only reorientation verdict, can explicitly launch one bounded reorientation worker, read that worker's result back through a reviewable surface, and explicitly accept completed findings into typed state, but runtime launch/acceptance policy and next-step execution are still explicit rather than ambient scheduler behavior. - no automatic watcher-driven graph or semantic invalidation. - no code-intelligence graph. - no specialist-agent scheduler. @@ -1326,7 +1329,7 @@ stored Epiphany state -> successful writes emit thread/epiphany/stateUpdated ``` -The current remaining missing organ is not the red pen, not the first chewing motion, not the first state-change bell, not the first client-shaped scene, not the first job/progress reflection, not the first live bound-job notification, not the first freshness lens, not the first watcher-backed invalidation read, not the first targeted graph/evidence context read, not the first context-pressure gauge, not the first durable investigation checkpoint packet, not the first bounded reorientation verdict, not the first thin launcher seam, not the first explicit launch/interrupt authority surface over that seam, not the first runtime consumer that can act on the reorientation verdict without becoming a hidden tyrant, and no longer the first read-back surface for that worker's findings. Those exist. Proposal now has the first bits of map memory, focus, and selection hygiene: it can auto-select a bounded evidence-backed observation cluster when ids are omitted, requires accepting recent evidence behind selected observations, prioritizes stronger selected observations for proposal wording, reuses existing architecture nodes by concrete code-ref/path/id checks before creating new path nodes, can rescue unanchored graph nodes through strict unique semantic overlap, follows graph links and incident edges into the frontier, and reports match-kind-aware churn pressure from the actual proposal shape. Distillation now also has the first source-output-aware teeth for tool/model summaries. Promotion now notices risky deltas instead of just checking the shape of the envelope, treats graph expansion as risky even if the patch tries to mumble "low pressure" while dragging a new wall into the blueprint, token-matches strong verifier kinds so `contest` cannot sneak past as `test`, and validates investigation checkpoints against known evidence before the packet can be inked. Successful update/promote writes now emit `thread/epiphany/stateUpdated` with `source: "update"` or `source: "promote"`, event-level revision, and typed changed fields so clients no longer need to poll blindly, infer the cause from timing, or diff the whole state to know which top-level sections moved. Runtime `agent_job_progress` background events now also emit `thread/epiphany/jobsUpdated` with changed bound-job payloads so clients no longer need to poll `thread/epiphany/jobs` just to watch one real owner move, the bound jobs now reflect launcher id, authority scope, and backend kind/job id instead of treating raw runtime pointers as the architecture, `jobLaunch` / `jobInterrupt` can create or tear down those bindings without pretending reflection is authority, `reorientLaunch` can launch one fixed `reorient-worker` job from the checkpoint verdict without turning the verdict itself into a writer, and `reorientResult` can read the worker's structured output back as a reviewable finding without promoting it. The scene, jobs, freshness, context, pressure, reorient, and reorient-result surfaces give clients compact or bounded read-only views without making the GUI/client authoritative, scene/context surface the checkpoint packet back out without becoming writers, freshness surfaces watcher telemetry without becoming a hidden worker, and reorient now turns those signals into an explicit wakeup verdict that one explicit launch surface can consume on purpose. The remaining missing organs are a second backend if `agent_jobs` stops being enough, a promotion/distillation path for accepted worker findings, a bounded CRRC coordinator that decides when to use the landed launch/read-back path, and eventually role-scoped specialist ownership without silently auto-promoting anything. +The current remaining missing organ is not the red pen, not the first chewing motion, not the first state-change bell, not the first client-shaped scene, not the first job/progress reflection, not the first live bound-job notification, not the first freshness lens, not the first watcher-backed invalidation read, not the first targeted graph/evidence context read, not the first context-pressure gauge, not the first durable investigation checkpoint packet, not the first bounded reorientation verdict, not the first thin launcher seam, not the first explicit launch/interrupt authority surface over that seam, not the first runtime consumer that can act on the reorientation verdict without becoming a hidden tyrant, not the first read-back surface for that worker's findings, and no longer the first explicit acceptance write for completed findings. Those exist. Proposal now has the first bits of map memory, focus, and selection hygiene: it can auto-select a bounded evidence-backed observation cluster when ids are omitted, requires accepting recent evidence behind selected observations, prioritizes stronger selected observations for proposal wording, reuses existing architecture nodes by concrete code-ref/path/id checks before creating new path nodes, can rescue unanchored graph nodes through strict unique semantic overlap, follows graph links and incident edges into the frontier, and reports match-kind-aware churn pressure from the actual proposal shape. Distillation now also has the first source-output-aware teeth for tool/model summaries. Promotion now notices risky deltas instead of just checking the shape of the envelope, treats graph expansion as risky even if the patch tries to mumble "low pressure" while dragging a new wall into the blueprint, token-matches strong verifier kinds so `contest` cannot sneak past as `test`, and validates investigation checkpoints against known evidence before the packet can be inked. Successful update/promote writes now emit `thread/epiphany/stateUpdated` with `source: "update"` or `source: "promote"`, event-level revision, and typed changed fields so clients no longer need to poll blindly, infer the cause from timing, or diff the whole state to know which top-level sections moved. Runtime `agent_job_progress` background events now also emit `thread/epiphany/jobsUpdated` with changed bound-job payloads so clients no longer need to poll `thread/epiphany/jobs` just to watch one real owner move, the bound jobs now reflect launcher id, authority scope, and backend kind/job id instead of treating raw runtime pointers as the architecture, `jobLaunch` / `jobInterrupt` can create or tear down those bindings without pretending reflection is authority, `reorientLaunch` can launch one fixed `reorient-worker` job from the checkpoint verdict without turning the verdict itself into a writer, `reorientResult` can read the worker's structured output back as a reviewable finding without promoting it, and `reorientAccept` can explicitly bank a completed finding into typed observation/evidence plus optional scratch/checkpoint state. The scene, jobs, freshness, context, pressure, reorient, and reorient-result surfaces give clients compact or bounded read-only views without making the GUI/client authoritative, scene/context surface the checkpoint packet back out without becoming writers, freshness surfaces watcher telemetry without becoming a hidden worker, and reorient now turns those signals into an explicit wakeup verdict that one explicit launch surface can consume on purpose. The remaining missing organs are a second backend if `agent_jobs` stops being enough, a bounded CRRC coordinator that decides when to use the landed launch/read-back/acceptance path, and eventually role-scoped specialist ownership without silently auto-promoting anything. ```text model/tool observations diff --git a/notes/epiphany-fork-implementation-plan.md b/notes/epiphany-fork-implementation-plan.md index 2d7ee8a1..9bbc6dcf 100644 --- a/notes/epiphany-fork-implementation-plan.md +++ b/notes/epiphany-fork-implementation-plan.md @@ -73,6 +73,7 @@ The landed machine now has: - read-only Phase 6 CRRC reorientation policy through `thread/epiphany/reorient` - bounded Phase 6 reorient-guided worker launch through `thread/epiphany/reorientLaunch` - read-only Phase 6 reorient-worker result read-back through `thread/epiphany/reorientResult` +- explicit Phase 6 reorient-worker finding acceptance through `thread/epiphany/reorientAccept` - 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` - live Phase 6 job-control app-server smoke coverage in `tools/epiphany_phase6_job_control_smoke.py` @@ -94,6 +95,7 @@ These boundaries are more important than the individual method names: - `thread/epiphany/jobLaunch` and `thread/epiphany/jobInterrupt` are bounded authority surfaces over durable `jobBindings` plus the current backend adapter, not a hidden scheduler, queue, or second runtime. - `thread/epiphany/reorientLaunch` is a bounded runtime consumer over the reorientation verdict, not automatic CRRC, a hidden queue, or permission to keep working after drift without an explicit launch. - `thread/epiphany/reorientResult` is a read-only result read-back surface, not a promotion gate, state writer, scheduler, or hidden continuation trigger. +- `thread/epiphany/reorientAccept` is an explicit acceptance write for completed reorient-worker findings, not automatic promotion, scheduling, or permission to continue without review. - `thread/epiphany/freshness` is a derived reflection, not automatic watcher-driven invalidation, a mutation gate, or a hidden refresh scheduler. - `thread/epiphany/context` is a targeted reflection, not a state writer or hidden proposal engine. - `thread/epiphany/pressure` is a context-pressure reflection, not an automatic compactor, scheduler, or CRRC coordinator. @@ -134,7 +136,7 @@ and notify typed state. It can. The next unknowns are: -- how accepted reorient-worker findings should become typed observations, scratch/checkpoint updates, or continuation packets without auto-promoting them +- how much automatic CRRC coordination belongs once pressure, verdict, launch, result read-back, and explicit acceptance all exist - how the landed watcher-backed invalidation telemetry should be consumed without turning freshness into a secret worker - how much automatic CRRC coordination belongs in runtime once pressure, freshness, watcher, checkpoint, and reorientation signals all exist - whether future bounded CRRC consumers should keep reusing the landed `agent_jobs` backend through the explicit job-control seam or start defining a second backend contract @@ -168,11 +170,12 @@ marketplace, broad ambient scheduling, automatic promotion of every tool observation, a GUI-first workflow, or a second job backend unless the current `agent_jobs` seam blocks the product loop. -The immediate read-back blocker is now landed as `thread/epiphany/reorientResult`. -The next MVP blocker is the review/acceptance step after read-back: completed -worker findings are inspectable, but the harness still needs a bounded path that -turns an accepted finding into typed observations, scratch/checkpoint updates, -or a continuation packet without silently promoting it. +The read-back and acceptance blockers are now landed as +`thread/epiphany/reorientResult` and `thread/epiphany/reorientAccept`. The next +MVP blocker is bounded CRRC coordination: the harness can measure pressure, +return a reorientation verdict, launch a worker, read its result, and explicitly +accept the finding, but it still lacks the small policy surface that decides +when to recommend or request that loop. ## Phase 6 Direction @@ -180,8 +183,8 @@ Phase 6 should grow observable harness state outward from the typed spine. Useful candidates: -1. Decide how accepted reorient-worker findings should flow into typed state or the next continuation packet without bypassing review. -2. Decide how much automatic CRRC coordination belongs now that pressure, freshness, watcher, checkpoint, reorient, explicit job control, and one explicit reorient-launch consumer all exist. +1. Decide how much bounded CRRC coordination belongs now that pressure, freshness, watcher, checkpoint, reorient, explicit job control, reorient launch, result read-back, and explicit acceptance all exist. +2. Keep accepted worker findings review-gated; do not convert acceptance into automatic promotion of arbitrary worker output. 3. Add targeted scene/jobs/context/pressure/reorient fields only when a client or smoke exposes a real gap. Do not spend Phase 6 polishing Phase 5 out of anxiety. The Phase 5 smoke harness diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 5860f349..74858a44 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -28,7 +28,7 @@ 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/freshness`, `thread/epiphany/context`, `thread/epiphany/pressure`, `thread/epiphany/reorient`, and `thread/epiphany/reorientResult`; 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` 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, reorient turns checkpoint plus freshness/pressure/watcher signals into a read-only resume-versus-regather verdict, `thread/epiphany/reorientLaunch` is the first explicit runtime consumer over that verdict, and `thread/epiphany/reorientResult` reads the launched worker output back as a reviewable finding without mutation or promotion. +- Phase 6 has read-only `thread/epiphany/scene`, `thread/epiphany/jobs`, `thread/epiphany/freshness`, `thread/epiphany/context`, `thread/epiphany/pressure`, `thread/epiphany/reorient`, and `thread/epiphany/reorientResult`; 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` 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, reorient turns checkpoint plus freshness/pressure/watcher signals into a read-only resume-versus-regather verdict, `thread/epiphany/reorientLaunch` is the first explicit runtime consumer over that verdict, `thread/epiphany/reorientResult` reads the launched worker output back as a reviewable finding without mutation or promotion, and `thread/epiphany/reorientAccept` explicitly banks completed findings into accepted observation/evidence plus optional scratch/checkpoint state. - Durable in-flight investigation checkpointing is now landed in authoritative typed state, writable through `thread/epiphany/update` or accepted `thread/epiphany/promote`, rendered into the prompt, and reflected through scene/context. - The repo is an Epiphany fork of Codex, not a Codex preset. - `vendor/codex` is tracked directly, not a submodule. @@ -65,6 +65,7 @@ The current spine: - explicit launch/interrupt authority through `thread/epiphany/jobLaunch` and `thread/epiphany/jobInterrupt` - bounded reorient-guided worker launch through `thread/epiphany/reorientLaunch` - read-only reorient-worker result read-back through `thread/epiphany/reorientResult` +- explicit reorient-worker finding acceptance through `thread/epiphany/reorientAccept` - thin launcher metadata in durable `jobBindings` - live bound-job progress notification through `thread/epiphany/jobsUpdated` - read-only compact reflection through `thread/epiphany/scene` @@ -99,7 +100,7 @@ The exact current control flow is documented in - `thread/epiphany/pressure` is read-only. - `thread/epiphany/reorient` is read-only. - `thread/epiphany/reorientResult` is read-only. -- Durable typed state writes go through `thread/epiphany/update`, accepted `thread/epiphany/promote`, or the bounded `thread/epiphany/jobLaunch`, `thread/epiphany/jobInterrupt`, and `thread/epiphany/reorientLaunch` authority surfaces when they mutate `jobBindings`. +- Durable typed state writes go through `thread/epiphany/update`, accepted `thread/epiphany/promote`, `thread/epiphany/reorientAccept`, or the bounded `thread/epiphany/jobLaunch`, `thread/epiphany/jobInterrupt`, and `thread/epiphany/reorientLaunch` authority surfaces when they mutate `jobBindings`. - `thread/epiphany/index` writes the retrieval catalog, not durable Epiphany understanding. - GUI/client surfaces reflect and steer typed state; they do not become the source of truth. - Do not restart Phase 5 hardening without a concrete regression. @@ -233,10 +234,9 @@ work even though read-only job ownership/progress reflection now has a real runtime seam, the thin launcher boundary is landed, and one explicit reorient-guided launch surface can now consume the verdict on purpose. -When the user asks to continue, the next likely organ is the bounded acceptance -path after `thread/epiphany/reorientResult`: accepted worker findings should -become typed observations, scratch/checkpoint updates, or a continuation packet -without automatic promotion. +When the user asks to continue, the next likely organ is bounded CRRC +coordination over the landed pressure, verdict, launch, result, and accept +loop. Keep it explicit and narrow; do not build a broad hidden scheduler. Live `thread/epiphany/scene`, `thread/epiphany/jobs`, `thread/epiphany/freshness`, `thread/epiphany/context`, diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 00d6059c..7ef697c5 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -49,3 +49,4 @@ {"ts": "2026-04-26T15:55:45+00:00", "type": "verification", "status": "ok", "note": "Phase 6 explicit thread/epiphany/jobLaunch and thread/epiphany/jobInterrupt authority landed over the thin launcher seam. The control path now falls back to a direct sqlite state runtime for loaded ephemeral threads, launches or cancels the current agent_jobs backend without turning jobs reflection into a scheduler, and preserves a blocked specialist slot with explicit relaunch reason after interrupt. Focused codex-core epiphany_state_update tests, app-server mapper plus jobsUpdated notification tests, app-server-protocol thread_epiphany and schema fixture checks, cargo build -p codex-app-server, and tools/epiphany_phase6_job_control_smoke.py plus tools/epiphany_phase6_jobs_smoke.py and tools/epiphany_phase6_scene_smoke.py passed."} {"ts": "2026-04-26T16:30:40+00:00", "type": "verification", "status": "ok", "note": "Phase 6 thread/epiphany/reorientLaunch landed as the first bounded runtime consumer over the read-only reorientation verdict. It launches one fixed reorient-worker binding through the existing agent_jobs-backed job-control seam with explicit resume/regather scope, checkpoint-derived payload, and no automatic CRRC or hidden scheduler. Focused app-server-protocol thread_epiphany and schema fixture checks, app-server map_epiphany tests, cargo build -p codex-app-server, and tools/epiphany_phase6_scene_smoke.py, tools/epiphany_phase6_reorient_smoke.py, tools/epiphany_phase6_reorient_launch_smoke.py, and tools/epiphany_phase6_job_control_smoke.py passed."} {"ts": "2026-04-28T09:59:40+00:00", "type": "verification", "status": "ok", "note": "Phase 6 thread/epiphany/reorientResult landed as a read-only read-back surface for fixed or requested reorient-worker bindings. It resolves the current agent_jobs backend item and projects completed worker output as a reviewable finding with mode, summary, next safe move, checkpoint validity, inspected files, frontier/evidence ids, raw result, and errors without mutation, promotion, scheduling, or hidden continuation. Focused protocol/app-server tests, schema fixture regeneration/checks, app-server build, and tools/epiphany_phase6_reorient_launch_smoke.py passed with resume and regather result read-back assertions."} +{"ts": "2026-04-28T10:27:16+00:00", "type": "verification", "status": "ok", "note": "Phase 6 thread/epiphany/reorientAccept landed as the explicit acceptance write after reorientResult. It requires a completed reorient-worker backend result, appends accepted observation/evidence records, optionally updates scratch and investigation checkpoint state, and emits stateUpdated with source reorientAccept without accepting pending work, auto-promoting arbitrary worker output, launching follow-up jobs, or silently continuing. Focused protocol/app-server tests, schema fixture regeneration/checks, app-server build, and tools/epiphany_phase6_reorient_launch_smoke.py passed with launch, read-back, and acceptance assertions."} diff --git a/state/map.yaml b/state/map.yaml index 3b1fd460..44cddd30 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -82,6 +82,7 @@ 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/reorientLaunch` is the first bounded runtime consumer over the reorientation verdict: it launches one fixed `reorient-worker` job through the existing job-control seam with explicit resume-versus-regather scope, authority, and checkpoint-derived payload, without making `thread/epiphany/reorient` a writer or turning CRRC into an ambient scheduler. - `thread/epiphany/reorientResult` is the first bounded read-back surface for that worker: it reads the fixed or requested reorient-worker binding through the current `agent_jobs` backend and projects completed output as a reviewable finding without mutation, promotion, scheduling, or hidden continuation. + - `thread/epiphany/reorientAccept` is the first explicit acceptance write for completed reorient-worker findings: it appends accepted observation/evidence records, can optionally update scratch and investigation checkpoint state, and emits `stateUpdated` with source `reorientAccept` without accepting pending work or launching follow-up work. - Epiphany safety doctrine is to separate cognition from actuation, keep authority explicit, make interruption sacred, stage capability release, and treat operator misuse as a normal design input rather than a rude hypothetical. - Epiphany is built in the open, but publication mode is not one-size-fits-all: use FOSS where viable, source-available licensing where economics or capability risk demand it, and commercial terms where organizations extract real enterprise value. - `thread/epiphany/jobLaunch` and `thread/epiphany/jobInterrupt` are the first bounded authority surfaces over the thin job seam: they mutate durable `job_bindings`, create or cancel the current `agent_jobs` backend binding, and preserve explicit launcher identity and interruption without turning `thread/epiphany/jobs` into a scheduler. @@ -101,6 +102,7 @@ landed_baseline: - Phase 5: typed update/distill/propose/promote/read/notification control plane. - Phase 6: read-only scene, job/progress, freshness with watcher-backed invalidation inputs, targeted context, context-pressure, and reorientation policy surfaces, plus durable investigation checkpointing for compaction-safe planning, live bound-job progress notifications, a thin launcher seam in durable job bindings, explicit launch/interrupt authority over that seam, and a bounded reorient-guided worker launch surface. - Phase 6 read-back: read-only reorient-worker result reflection through `thread/epiphany/reorientResult`. + - Phase 6 acceptance: explicit reorient-worker finding acceptance through `thread/epiphany/reorientAccept`. 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. @@ -131,5 +133,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, freshness, targeted context, context-pressure reflection, watcher-backed invalidation inputs, durable investigation checkpointing, bounded CRRC reorientation policy, live bound-job progress notifications, a thin launcher seam in durable `job_bindings`, explicit `thread/epiphany/jobLaunch` / `thread/epiphany/jobInterrupt` authority over that seam, bounded `thread/epiphany/reorientLaunch`, and read-only `thread/epiphany/reorientResult` are landed. `job_bindings` now carry Epiphany-owned launcher metadata such as launcher id, authority scope, and backend kind/job id, while still tolerating the older runtime-agent-job pointer as a compatibility alias. `thread/epiphany/jobs` overlays that launcher seam onto real runtime `agent_jobs` progress for bound work, including runtime/backend job id, worker thread ids, and progress counts, without becoming a scheduler. `thread/epiphany/jobsUpdated` now translates runtime `agent_job_progress:{json}` background events into changed launcher-bound payloads only when the mapped job state actually changes, so clients can watch real owners move without polling the jobs read surface. The launch/interrupt control path still uses direct state-runtime fallback when a loaded ephemeral thread does not already carry a live sqlite handle, so authoritative bindings and runtime snapshots stay aligned instead of pretending the backend vanished. `thread/epiphany/reorient` consumes checkpoint, freshness, watcher, and pressure signals to return a read-only `resume` versus `regather` verdict with explicit checkpoint-path/frontier reasons. `thread/epiphany/reorientLaunch` explicitly launches one fixed `reorient-worker` job with resume-or-regather scope, checkpoint-derived payload, and bounded structured output expectations. `thread/epiphany/reorientResult` now reads that worker output back from the current `agent_jobs` backend as a reviewable finding with mode, summary, next safe move, checkpoint validity, inspected files, frontier ids, evidence ids, raw result, and errors, without mutating state, promoting evidence, scheduling work, or silently continuing. Focused protocol/app-server tests, schema fixture regeneration/checks, app-server build, and the live reorient-launch smoke cover the launch/read-back seam. Investigation checkpoints still live in authoritative typed state, flow through the prompt, and reflect through scene/context without adding a second writer or fake scheduler. Persistent state was cut down so map, handoff, plan, harness surfaces, scratch, and evidence each carry one job instead of becoming a Jenga tower; evidence is now a distilled ledger rather than an activity feed. The global AGENTS Epiphany core command says persistent state is the agent's mind and explicitly permits the agent to ask for self-modification when memory or workflow makes it worse. The continuity goal is to bank the fire before the dark so compaction becomes less like death and more like sleep. - next_action: Continue toward the MVP by adding the bounded acceptance path after `thread/epiphany/reorientResult`: accepted worker findings should become typed observations, scratch/checkpoint updates, or a continuation packet without automatic promotion. Automatic runtime CRRC and broad specialist scheduling remain future work; do not restart the completed pressure, freshness, watcher-invalidation, investigation-checkpoint, reorientation, jobs-binding, jobsUpdated, thin-launcher-seam, job-control, reorient-launch, or reorient-result slice unless a concrete regression appears. + 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, freshness, targeted context, context-pressure reflection, watcher-backed invalidation inputs, durable investigation checkpointing, bounded CRRC reorientation policy, live bound-job progress notifications, a thin launcher seam in durable `job_bindings`, explicit `thread/epiphany/jobLaunch` / `thread/epiphany/jobInterrupt` authority over that seam, bounded `thread/epiphany/reorientLaunch`, read-only `thread/epiphany/reorientResult`, and explicit `thread/epiphany/reorientAccept` are landed. `job_bindings` now carry Epiphany-owned launcher metadata such as launcher id, authority scope, and backend kind/job id, while still tolerating the older runtime-agent-job pointer as a compatibility alias. `thread/epiphany/jobs` overlays that launcher seam onto real runtime `agent_jobs` progress for bound work, including runtime/backend job id, worker thread ids, and progress counts, without becoming a scheduler. `thread/epiphany/jobsUpdated` now translates runtime `agent_job_progress:{json}` background events into changed launcher-bound payloads only when the mapped job state actually changes, so clients can watch real owners move without polling the jobs read surface. The launch/interrupt control path still uses direct state-runtime fallback when a loaded ephemeral thread does not already carry a live sqlite handle, so authoritative bindings and runtime snapshots stay aligned instead of pretending the backend vanished. `thread/epiphany/reorient` consumes checkpoint, freshness, watcher, and pressure signals to return a read-only `resume` versus `regather` verdict with explicit checkpoint-path/frontier reasons. `thread/epiphany/reorientLaunch` explicitly launches one fixed `reorient-worker` job with resume-or-regather scope, checkpoint-derived payload, and bounded structured output expectations. `thread/epiphany/reorientResult` reads that worker output back from the current `agent_jobs` backend as a reviewable finding with mode, summary, next safe move, checkpoint validity, inspected files, frontier ids, evidence ids, raw result, and errors, without mutating state, promoting evidence, scheduling work, or silently continuing. `thread/epiphany/reorientAccept` requires a completed worker result, appends accepted observation/evidence records, can explicitly update scratch and investigation checkpoint state, and emits `stateUpdated` with source `reorientAccept` without accepting pending work, auto-promoting arbitrary output, or launching follow-up work. Focused protocol/app-server tests, schema fixture regeneration/checks, app-server build, and the live reorient-launch smoke cover the launch/read-back/accept seam. Investigation checkpoints still live in authoritative typed state, flow through the prompt, and reflect through scene/context without adding a second writer or fake scheduler. Persistent state was cut down so map, handoff, plan, harness surfaces, scratch, and evidence each carry one job instead of becoming a Jenga tower; evidence is now a distilled ledger rather than an activity feed. The global AGENTS Epiphany core command says persistent state is the agent's mind and explicitly permits the agent to ask for self-modification when memory or workflow makes it worse. The continuity goal is to bank the fire before the dark so compaction becomes less like death and more like sleep. + next_action: Continue toward the MVP by adding bounded CRRC coordination over the landed pressure, reorient verdict, launch, result read-back, and explicit acceptance loop. Automatic broad specialist scheduling remains future work; do not restart the completed pressure, freshness, watcher-invalidation, investigation-checkpoint, reorientation, jobs-binding, jobsUpdated, thin-launcher-seam, job-control, reorient-launch, reorient-result, or reorient-accept slice unless a concrete regression appears. diff --git a/tools/epiphany_phase6_reorient_launch_smoke.py b/tools/epiphany_phase6_reorient_launch_smoke.py index 21b2afa5..a8476184 100644 --- a/tools/epiphany_phase6_reorient_launch_smoke.py +++ b/tools/epiphany_phase6_reorient_launch_smoke.py @@ -422,11 +422,70 @@ def run_smoke(args: argparse.Namespace) -> dict[str, Any]: "regather result should expose the raw worker result for review", ) + accept_notification_start = len(client.notifications) + accepted = client.send( + "thread/epiphany/reorientAccept", + { + "threadId": thread_id, + "expectedRevision": 4, + "bindingId": BINDING_ID, + "updateScratch": True, + "updateInvestigationCheckpoint": True, + }, + ) + assert accepted is not None + require( + accepted["revision"] == 5, + "accepting a reorient finding should advance the durable revision", + ) + require( + accepted["changedFields"] + == ["observations", "evidence", "scratch", "investigationCheckpoint"], + "accepting a reorient finding should only mutate the accepted state fields", + ) + require( + accepted["finding"]["rawResult"] == regather_result_payload, + "acceptance should preserve the reviewed worker finding", + ) + require( + accepted["epiphanyState"]["observations"][0]["id"] + == accepted["acceptedObservationId"], + "acceptance should prepend the accepted observation", + ) + require( + accepted["epiphanyState"]["recent_evidence"][0]["id"] + == accepted["acceptedEvidenceId"], + "acceptance should prepend the accepted evidence", + ) + require( + accepted["acceptedEvidenceId"] + in accepted["epiphanyState"]["investigation_checkpoint"]["evidence_ids"], + "acceptance should link accepted evidence into the checkpoint when requested", + ) + require( + accepted["epiphanyState"]["scratch"]["next_probe"] + == "Review the reorientation finding before continuing implementation.", + "acceptance should bank the worker next safe move into scratch when requested", + ) + accept_notification = client.wait_for_notification( + "thread/epiphany/stateUpdated", + start_index=accept_notification_start, + timeout=15.0, + ) + require( + accept_notification["params"]["source"] == "reorientAccept", + "acceptance should emit a distinct state update source", + ) + require( + accept_notification["params"]["revision"] == 5, + "acceptance notification should expose revision 5", + ) + final_read = client.send("thread/read", {"threadId": thread_id, "includeTurns": False}) assert final_read is not None require( - final_read["thread"]["epiphanyState"]["revision"] == 4, - "reorient launch smoke should leave the final revision at 4", + final_read["thread"]["epiphanyState"]["revision"] == 5, + "reorient launch smoke should leave the final revision at 5 after acceptance", ) result = { @@ -443,6 +502,9 @@ def run_smoke(args: argparse.Namespace) -> dict[str, Any]: "resumeResultStatus": resume_result["status"], "regatherResultStatus": regather_result["status"], "regatherNextSafeMove": regather_result["finding"]["nextSafeMove"], + "acceptRevision": accepted["revision"], + "acceptedObservationId": accepted["acceptedObservationId"], + "acceptedEvidenceId": accepted["acceptedEvidenceId"], "checkpointChangedPaths": regather_launch["decision"]["checkpointChangedPaths"], "finalReadRevision": final_read["thread"]["epiphanyState"]["revision"], } diff --git a/vendor/codex/codex-rs/app-server-protocol/schema/json/ServerNotification.json b/vendor/codex/codex-rs/app-server-protocol/schema/json/ServerNotification.json index 56150530..56055e2f 100644 --- a/vendor/codex/codex-rs/app-server-protocol/schema/json/ServerNotification.json +++ b/vendor/codex/codex-rs/app-server-protocol/schema/json/ServerNotification.json @@ -4124,7 +4124,8 @@ "update", "promote", "jobLaunch", - "jobInterrupt" + "jobInterrupt", + "reorientAccept" ], "type": "string" }, diff --git a/vendor/codex/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json b/vendor/codex/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json index 5cdd32ed..4a97b14e 100644 --- a/vendor/codex/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json +++ b/vendor/codex/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.schemas.json @@ -16064,6 +16064,7 @@ "reorient", "reorientLaunch", "reorientResult", + "reorientAccept", "propose", "promote", "update" @@ -16462,7 +16463,8 @@ "update", "promote", "jobLaunch", - "jobInterrupt" + "jobInterrupt", + "reorientAccept" ], "type": "string" }, diff --git a/vendor/codex/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json b/vendor/codex/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json index 1fe9e102..23c7df78 100644 --- a/vendor/codex/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json +++ b/vendor/codex/codex-rs/app-server-protocol/schema/json/codex_app_server_protocol.v2.schemas.json @@ -13951,6 +13951,7 @@ "reorient", "reorientLaunch", "reorientResult", + "reorientAccept", "propose", "promote", "update" @@ -14349,7 +14350,8 @@ "update", "promote", "jobLaunch", - "jobInterrupt" + "jobInterrupt", + "reorientAccept" ], "type": "string" }, diff --git a/vendor/codex/codex-rs/app-server-protocol/schema/json/v2/ThreadEpiphanyStateUpdatedNotification.json b/vendor/codex/codex-rs/app-server-protocol/schema/json/v2/ThreadEpiphanyStateUpdatedNotification.json index bc1276fc..c6f405c7 100644 --- a/vendor/codex/codex-rs/app-server-protocol/schema/json/v2/ThreadEpiphanyStateUpdatedNotification.json +++ b/vendor/codex/codex-rs/app-server-protocol/schema/json/v2/ThreadEpiphanyStateUpdatedNotification.json @@ -907,7 +907,8 @@ "update", "promote", "jobLaunch", - "jobInterrupt" + "jobInterrupt", + "reorientAccept" ], "type": "string" } diff --git a/vendor/codex/codex-rs/app-server-protocol/schema/typescript/v2/ThreadEpiphanySceneAction.ts b/vendor/codex/codex-rs/app-server-protocol/schema/typescript/v2/ThreadEpiphanySceneAction.ts index e73f201e..a13fd132 100644 --- a/vendor/codex/codex-rs/app-server-protocol/schema/typescript/v2/ThreadEpiphanySceneAction.ts +++ b/vendor/codex/codex-rs/app-server-protocol/schema/typescript/v2/ThreadEpiphanySceneAction.ts @@ -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" | "jobLaunch" | "jobInterrupt" | "freshness" | "pressure" | "reorient" | "reorientLaunch" | "reorientResult" | "propose" | "promote" | "update"; +export type ThreadEpiphanySceneAction = "index" | "retrieve" | "distill" | "context" | "jobs" | "jobLaunch" | "jobInterrupt" | "freshness" | "pressure" | "reorient" | "reorientLaunch" | "reorientResult" | "reorientAccept" | "propose" | "promote" | "update"; diff --git a/vendor/codex/codex-rs/app-server-protocol/schema/typescript/v2/ThreadEpiphanyStateUpdatedSource.ts b/vendor/codex/codex-rs/app-server-protocol/schema/typescript/v2/ThreadEpiphanyStateUpdatedSource.ts index 9cb60223..5bb98e4d 100644 --- a/vendor/codex/codex-rs/app-server-protocol/schema/typescript/v2/ThreadEpiphanyStateUpdatedSource.ts +++ b/vendor/codex/codex-rs/app-server-protocol/schema/typescript/v2/ThreadEpiphanyStateUpdatedSource.ts @@ -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 ThreadEpiphanyStateUpdatedSource = "update" | "promote" | "jobLaunch" | "jobInterrupt"; +export type ThreadEpiphanyStateUpdatedSource = "update" | "promote" | "jobLaunch" | "jobInterrupt" | "reorientAccept"; diff --git a/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs b/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs index cb0847d1..2a0b0701 100644 --- a/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs +++ b/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs @@ -376,6 +376,11 @@ client_request_definitions! { params: v2::ThreadEpiphanyReorientResultParams, response: v2::ThreadEpiphanyReorientResultResponse, }, + #[experimental("thread/epiphany/reorientAccept")] + ThreadEpiphanyReorientAccept => "thread/epiphany/reorientAccept" { + params: v2::ThreadEpiphanyReorientAcceptParams, + response: v2::ThreadEpiphanyReorientAcceptResponse, + }, #[experimental("thread/epiphany/index")] ThreadEpiphanyIndex => "thread/epiphany/index" { params: v2::ThreadEpiphanyIndexParams, @@ -2495,6 +2500,104 @@ mod tests { Ok(()) } + #[test] + fn serialize_thread_epiphany_reorient_accept_response() -> Result<()> { + let response = ClientResponse::ThreadEpiphanyReorientAccept { + request_id: RequestId::Integer(10), + response: v2::ThreadEpiphanyReorientAcceptResponse { + revision: 6, + changed_fields: vec![ + v2::ThreadEpiphanyStateUpdatedField::Observations, + v2::ThreadEpiphanyStateUpdatedField::Evidence, + v2::ThreadEpiphanyStateUpdatedField::Scratch, + ], + epiphany_state: codex_protocol::protocol::EpiphanyThreadState { + revision: 6, + observations: vec![codex_protocol::protocol::EpiphanyObservation { + id: "obs-reorient-1".to_string(), + summary: "Accepted resume reorientation result.".to_string(), + source_kind: "reorient_result".to_string(), + status: "accepted".to_string(), + evidence_ids: vec!["ev-reorient-1".to_string()], + ..Default::default() + }], + recent_evidence: vec![codex_protocol::protocol::EpiphanyEvidenceRecord { + id: "ev-reorient-1".to_string(), + kind: "reorient_result".to_string(), + status: "accepted".to_string(), + summary: "Checkpoint remains source-grounded.".to_string(), + ..Default::default() + }], + ..Default::default() + }, + binding_id: "reorient-worker".to_string(), + accepted_observation_id: "obs-reorient-1".to_string(), + accepted_evidence_id: "ev-reorient-1".to_string(), + finding: v2::ThreadEpiphanyReorientFinding { + mode: Some("resume".to_string()), + summary: Some("Checkpoint remains source-grounded.".to_string()), + next_safe_move: Some("Continue the bounded slice.".to_string()), + checkpoint_still_valid: Some(true), + files_inspected: Vec::new(), + frontier_node_ids: Vec::new(), + evidence_ids: Vec::new(), + job_error: None, + item_error: None, + raw_result: json!({ + "mode": "resume", + "summary": "Checkpoint remains source-grounded.", + "nextSafeMove": "Continue the bounded slice." + }), + }, + }, + }; + + assert_eq!(response.id(), &RequestId::Integer(10)); + assert_eq!(response.method(), "thread/epiphany/reorientAccept"); + assert_eq!( + json!({ + "method": "thread/epiphany/reorientAccept", + "id": 10, + "response": { + "revision": 6, + "changedFields": ["observations", "evidence", "scratch"], + "epiphanyState": { + "revision": 6, + "observations": [{ + "id": "obs-reorient-1", + "summary": "Accepted resume reorientation result.", + "source_kind": "reorient_result", + "status": "accepted", + "evidence_ids": ["ev-reorient-1"] + }], + "recent_evidence": [{ + "id": "ev-reorient-1", + "kind": "reorient_result", + "status": "accepted", + "summary": "Checkpoint remains source-grounded." + }] + }, + "bindingId": "reorient-worker", + "acceptedObservationId": "obs-reorient-1", + "acceptedEvidenceId": "ev-reorient-1", + "finding": { + "mode": "resume", + "summary": "Checkpoint remains source-grounded.", + "nextSafeMove": "Continue the bounded slice.", + "checkpointStillValid": true, + "rawResult": { + "mode": "resume", + "summary": "Checkpoint remains source-grounded.", + "nextSafeMove": "Continue the bounded slice." + } + } + } + }), + serde_json::to_value(&response)?, + ); + Ok(()) + } + #[test] fn serialize_thread_epiphany_retrieve_response() -> Result<()> { let response = ClientResponse::ThreadEpiphanyRetrieve { @@ -3740,6 +3843,22 @@ mod tests { assert_eq!(reason, Some("thread/epiphany/reorientResult")); } + #[test] + fn thread_epiphany_reorient_accept_is_marked_experimental() { + let request = ClientRequest::ThreadEpiphanyReorientAccept { + request_id: RequestId::Integer(1), + params: v2::ThreadEpiphanyReorientAcceptParams { + thread_id: "thr_123".to_string(), + expected_revision: Some(5), + binding_id: Some("reorient-worker".to_string()), + update_scratch: true, + update_investigation_checkpoint: false, + }, + }; + let reason = crate::experimental_api::ExperimentalApi::experimental_reason(&request); + assert_eq!(reason, Some("thread/epiphany/reorientAccept")); + } + #[test] fn thread_epiphany_index_is_marked_experimental() { let request = ClientRequest::ThreadEpiphanyIndex { diff --git a/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs b/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs index 3e0a7815..bd493258 100644 --- a/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs +++ b/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs @@ -4004,6 +4004,7 @@ pub enum ThreadEpiphanySceneAction { Reorient, ReorientLaunch, ReorientResult, + ReorientAccept, Propose, Promote, Update, @@ -4623,6 +4624,36 @@ pub struct ThreadEpiphanyReorientResultResponse { pub note: String, } +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export_to = "v2/")] +pub struct ThreadEpiphanyReorientAcceptParams { + pub thread_id: String, + #[serde(default)] + #[ts(optional = nullable)] + pub expected_revision: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + #[ts(optional = nullable)] + pub binding_id: Option, + #[serde(default, skip_serializing_if = "std::ops::Not::not")] + pub update_scratch: bool, + #[serde(default, skip_serializing_if = "std::ops::Not::not")] + pub update_investigation_checkpoint: bool, +} + +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)] +#[serde(rename_all = "camelCase")] +#[ts(export_to = "v2/")] +pub struct ThreadEpiphanyReorientAcceptResponse { + pub revision: u64, + pub changed_fields: Vec, + pub epiphany_state: CoreEpiphanyThreadState, + pub binding_id: String, + pub accepted_observation_id: String, + pub accepted_evidence_id: String, + pub finding: ThreadEpiphanyReorientFinding, +} + #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS)] #[serde(rename_all = "camelCase")] #[ts(export_to = "v2/")] @@ -4912,6 +4943,7 @@ pub enum ThreadEpiphanyStateUpdatedSource { Promote, JobLaunch, JobInterrupt, + ReorientAccept, } #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)] diff --git a/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs b/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs index 19bbafc6..c19d8952 100644 --- a/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs +++ b/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs @@ -190,6 +190,8 @@ use codex_app_server_protocol::ThreadEpiphanyPromoteParams; use codex_app_server_protocol::ThreadEpiphanyPromoteResponse; use codex_app_server_protocol::ThreadEpiphanyProposeParams; use codex_app_server_protocol::ThreadEpiphanyProposeResponse; +use codex_app_server_protocol::ThreadEpiphanyReorientAcceptParams; +use codex_app_server_protocol::ThreadEpiphanyReorientAcceptResponse; use codex_app_server_protocol::ThreadEpiphanyReorientAction; use codex_app_server_protocol::ThreadEpiphanyReorientCheckpointStatus; use codex_app_server_protocol::ThreadEpiphanyReorientDecision; @@ -416,12 +418,17 @@ use codex_protocol::protocol::ConversationAudioParams; use codex_protocol::protocol::ConversationStartParams; use codex_protocol::protocol::ConversationStartTransport; use codex_protocol::protocol::ConversationTextParams; +use codex_protocol::protocol::EpiphanyCodeRef; +use codex_protocol::protocol::EpiphanyEvidenceRecord; +use codex_protocol::protocol::EpiphanyInvestigationCheckpoint; use codex_protocol::protocol::EpiphanyInvestigationDisposition; use codex_protocol::protocol::EpiphanyJobBackendKind as CoreEpiphanyJobBackendKind; use codex_protocol::protocol::EpiphanyJobBinding; use codex_protocol::protocol::EpiphanyJobKind as CoreEpiphanyJobKind; +use codex_protocol::protocol::EpiphanyObservation; use codex_protocol::protocol::EpiphanyRetrievalState; use codex_protocol::protocol::EpiphanyRetrievalStatus; +use codex_protocol::protocol::EpiphanyScratchPad; use codex_protocol::protocol::EpiphanyThreadState; use codex_protocol::protocol::EventMsg; use codex_protocol::protocol::GitInfo as CoreGitInfo; @@ -1099,6 +1106,10 @@ impl CodexMessageProcessor { self.thread_epiphany_reorient_result(to_connection_request_id(request_id), params) .await; } + ClientRequest::ThreadEpiphanyReorientAccept { request_id, params } => { + self.thread_epiphany_reorient_accept(to_connection_request_id(request_id), params) + .await; + } ClientRequest::ThreadEpiphanyIndex { request_id, params } => { self.thread_epiphany_index(to_connection_request_id(request_id), params) .await; @@ -4923,6 +4934,194 @@ impl CodexMessageProcessor { .await; } + async fn thread_epiphany_reorient_accept( + &self, + request_id: ConnectionRequestId, + params: ThreadEpiphanyReorientAcceptParams, + ) { + let ThreadEpiphanyReorientAcceptParams { + thread_id, + expected_revision, + binding_id, + update_scratch, + update_investigation_checkpoint, + } = params; + let binding_id = binding_id.unwrap_or_else(|| EPIPHANY_REORIENT_LAUNCH_BINDING_ID.into()); + + 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 = match self.thread_manager.get_thread(thread_uuid).await { + Ok(thread) => thread, + Err(_) => { + self.send_invalid_request_error( + request_id, + format!("thread not loaded: {thread_uuid}"), + ) + .await; + return; + } + }; + let Some(state) = loaded_thread.epiphany_state().await else { + self.send_invalid_request_error( + request_id, + "cannot accept a reorientation finding without authoritative Epiphany state" + .to_string(), + ) + .await; + return; + }; + if let Some(expected_revision) = expected_revision + && state.revision != expected_revision + { + self.send_invalid_request_error( + request_id, + format!( + "epiphany state revision mismatch: expected {expected_revision}, found {}", + state.revision + ), + ) + .await; + return; + } + + let finding = match load_completed_epiphany_reorient_finding( + loaded_thread.as_ref(), + &state, + binding_id.as_str(), + ) + .await + { + Ok(finding) => finding, + Err(CodexErr::InvalidRequest(message)) => { + self.send_invalid_request_error(request_id, message).await; + return; + } + Err(err) => { + self.send_internal_error( + request_id, + format!("failed to accept Epiphany reorientation finding: {err}"), + ) + .await; + return; + } + }; + + if update_investigation_checkpoint && state.investigation_checkpoint.is_none() { + self.send_invalid_request_error( + request_id, + "cannot update investigation checkpoint because this thread has no durable checkpoint" + .to_string(), + ) + .await; + return; + } + + let accepted_evidence_id = format!("ev-reorient-{}", Uuid::new_v4()); + let accepted_observation_id = format!("obs-reorient-{}", Uuid::new_v4()); + let code_refs = reorient_finding_code_refs(&finding); + let evidence = EpiphanyEvidenceRecord { + id: accepted_evidence_id.clone(), + kind: "reorient_result".to_string(), + status: "accepted".to_string(), + summary: reorient_finding_summary(&finding), + code_refs: code_refs.clone(), + }; + let observation = EpiphanyObservation { + id: accepted_observation_id.clone(), + summary: reorient_finding_observation_summary(&finding), + source_kind: "reorient_result".to_string(), + status: "accepted".to_string(), + code_refs: code_refs.clone(), + evidence_ids: vec![accepted_evidence_id.clone()], + }; + + let scratch = update_scratch.then(|| reorient_finding_scratch(&binding_id, &finding)); + let investigation_checkpoint = if update_investigation_checkpoint { + state.investigation_checkpoint.as_ref().map(|checkpoint| { + reorient_finding_investigation_checkpoint( + checkpoint, + accepted_evidence_id.as_str(), + code_refs.as_slice(), + &finding, + ) + }) + } else { + None + }; + + let mut changed_fields = vec![ + ThreadEpiphanyStateUpdatedField::Observations, + ThreadEpiphanyStateUpdatedField::Evidence, + ]; + if scratch.is_some() { + changed_fields.push(ThreadEpiphanyStateUpdatedField::Scratch); + } + if investigation_checkpoint.is_some() { + changed_fields.push(ThreadEpiphanyStateUpdatedField::InvestigationCheckpoint); + } + + let epiphany_state = match loaded_thread + .epiphany_update_state(EpiphanyStateUpdate { + expected_revision, + scratch, + investigation_checkpoint, + observations: vec![observation], + evidence: vec![evidence], + ..Default::default() + }) + .await + { + Ok(state) => { + client_visible_live_thread_epiphany_state(loaded_thread.as_ref(), state).await + } + Err(CodexErr::InvalidRequest(message)) => { + self.send_invalid_request_error(request_id, message).await; + return; + } + Err(err) => { + self.send_internal_error( + request_id, + format!("failed to apply Epiphany reorientation finding: {err}"), + ) + .await; + return; + } + }; + + self.outgoing + .send_response( + request_id, + ThreadEpiphanyReorientAcceptResponse { + revision: epiphany_state.revision, + changed_fields: changed_fields.clone(), + epiphany_state: epiphany_state.clone(), + binding_id: binding_id.clone(), + accepted_observation_id, + accepted_evidence_id, + finding, + }, + ) + .await; + self.outgoing + .send_server_notification(ServerNotification::ThreadEpiphanyStateUpdated( + ThreadEpiphanyStateUpdatedNotification { + thread_id: thread_uuid.to_string(), + source: ThreadEpiphanyStateUpdatedSource::ReorientAccept, + revision: epiphany_state.revision, + changed_fields, + epiphany_state, + }, + )) + .await; + } + async fn thread_epiphany_retrieve( &self, request_id: ConnectionRequestId, @@ -11716,6 +11915,7 @@ fn epiphany_scene_available_actions( } if reorient_binding_present { actions.push(ThreadEpiphanySceneAction::ReorientResult); + actions.push(ThreadEpiphanySceneAction::ReorientAccept); } actions.push(ThreadEpiphanySceneAction::Update); if state_present { @@ -11950,6 +12150,176 @@ fn render_epiphany_reorient_result_note( } } +async fn load_completed_epiphany_reorient_finding( + thread: &CodexThread, + state: &EpiphanyThreadState, + binding_id: &str, +) -> CodexResult { + let binding = state + .job_bindings + .iter() + .find(|binding| binding.id == binding_id) + .ok_or_else(|| { + CodexErr::InvalidRequest(format!( + "epiphany reorientation binding {:?} was not found", + binding_id + )) + })?; + let agent_job_id = binding_agent_jobs_job_id(binding).ok_or_else(|| { + CodexErr::InvalidRequest(format!( + "epiphany reorientation binding {:?} is not backed by agent_jobs", + binding_id + )) + })?; + let state_db_ctx = thread.epiphany_state_runtime().await.ok_or_else(|| { + CodexErr::InvalidRequest( + "sqlite state db is unavailable for Epiphany reorientation result acceptance" + .to_string(), + ) + })?; + let agent_job = state_db_ctx + .get_agent_job(agent_job_id) + .await + .map_err(|err| CodexErr::Fatal(format!("failed to read Epiphany backend job: {err}")))? + .ok_or_else(|| { + CodexErr::InvalidRequest(format!( + "bound agent_jobs backend job {:?} was not found", + agent_job_id + )) + })?; + let item = state_db_ctx + .get_agent_job_item(agent_job_id, binding_id) + .await + .map_err(|err| { + CodexErr::Fatal(format!( + "failed to read Epiphany backend job item for {binding_id:?}: {err}" + )) + })? + .ok_or_else(|| { + CodexErr::InvalidRequest(format!( + "bound agent_jobs backend item {:?} was not found", + binding_id + )) + })?; + let status = map_epiphany_reorient_result_status(agent_job.status, item.status); + if status != ThreadEpiphanyReorientResultStatus::Completed { + return Err(CodexErr::InvalidRequest(format!( + "cannot accept reorientation result while worker status is {:?}", + status + ))); + } + let result = item.result_json.ok_or_else(|| { + CodexErr::InvalidRequest( + "cannot accept completed reorientation worker because no result_json was recorded" + .to_string(), + ) + })?; + Ok(map_epiphany_reorient_finding( + result, + agent_job.last_error, + item.last_error, + )) +} + +fn reorient_finding_summary(finding: &ThreadEpiphanyReorientFinding) -> String { + let summary = finding + .summary + .clone() + .unwrap_or_else(|| "Reorientation worker returned a structured finding.".to_string()); + if let Some(next_safe_move) = finding.next_safe_move.as_deref() { + format!("{summary} Next safe move: {next_safe_move}") + } else { + summary + } +} + +fn reorient_finding_observation_summary(finding: &ThreadEpiphanyReorientFinding) -> String { + let mode = finding.mode.as_deref().unwrap_or("unknown"); + let validity = match finding.checkpoint_still_valid { + Some(true) => "checkpoint still valid", + Some(false) => "checkpoint requires regather", + None => "checkpoint validity not reported", + }; + format!( + "Accepted {mode} reorientation result: {validity}. {}", + reorient_finding_summary(finding) + ) +} + +fn reorient_finding_code_refs(finding: &ThreadEpiphanyReorientFinding) -> Vec { + finding + .files_inspected + .iter() + .filter(|path| !path.trim().is_empty()) + .map(|path| EpiphanyCodeRef { + path: PathBuf::from(path), + start_line: None, + end_line: None, + symbol: None, + note: Some("Inspected by accepted reorientation worker.".to_string()), + }) + .collect() +} + +fn reorient_finding_scratch( + binding_id: &str, + finding: &ThreadEpiphanyReorientFinding, +) -> EpiphanyScratchPad { + let mode = finding.mode.as_deref().unwrap_or("unknown"); + let checkpoint_validity = match finding.checkpoint_still_valid { + Some(true) => "valid", + Some(false) => "invalid", + None => "unknown", + }; + EpiphanyScratchPad { + summary: finding.summary.clone(), + hypothesis: Some(format!( + "Accepted {mode} reorientation finding from {binding_id}; checkpoint validity is {checkpoint_validity}." + )), + next_probe: finding.next_safe_move.clone(), + notes: vec![format!( + "Files inspected: {}", + if finding.files_inspected.is_empty() { + "none reported".to_string() + } else { + finding.files_inspected.join(", ") + } + )], + } +} + +fn reorient_finding_investigation_checkpoint( + checkpoint: &EpiphanyInvestigationCheckpoint, + evidence_id: &str, + code_refs: &[EpiphanyCodeRef], + finding: &ThreadEpiphanyReorientFinding, +) -> EpiphanyInvestigationCheckpoint { + let mut checkpoint = checkpoint.clone(); + checkpoint.summary = finding.summary.clone().or(checkpoint.summary); + checkpoint.next_action = finding.next_safe_move.clone().or(checkpoint.next_action); + checkpoint.disposition = match finding.checkpoint_still_valid { + Some(false) => EpiphanyInvestigationDisposition::RegatherRequired, + _ => EpiphanyInvestigationDisposition::ResumeReady, + }; + if !checkpoint + .evidence_ids + .iter() + .any(|existing| existing == evidence_id) + { + checkpoint.evidence_ids.push(evidence_id.to_string()); + } + for code_ref in code_refs { + if !checkpoint + .code_refs + .iter() + .any(|existing| existing.path == code_ref.path) + { + checkpoint.code_refs.push(code_ref.clone()); + } + } + checkpoint +} + fn epiphany_code_ref_json( code_ref: &codex_protocol::protocol::EpiphanyCodeRef, ) -> serde_json::Value { @@ -15723,6 +16093,69 @@ mod tests { ); } + #[test] + fn reorient_finding_acceptance_builds_scratch_and_checkpoint_update() { + let finding = ThreadEpiphanyReorientFinding { + mode: Some("regather".to_string()), + summary: Some("The old checkpoint no longer matches source.".to_string()), + next_safe_move: Some("Re-read src/lib.rs before editing.".to_string()), + checkpoint_still_valid: Some(false), + files_inspected: vec!["src/lib.rs".to_string()], + frontier_node_ids: vec!["node-1".to_string()], + evidence_ids: Vec::new(), + job_error: None, + item_error: None, + raw_result: serde_json::json!({ + "mode": "regather", + "summary": "The old checkpoint no longer matches source.", + "nextSafeMove": "Re-read src/lib.rs before editing.", + "checkpointStillValid": false + }), + }; + + let scratch = reorient_finding_scratch("reorient-worker", &finding); + assert_eq!( + scratch.summary.as_deref(), + Some("The old checkpoint no longer matches source.") + ); + assert_eq!( + scratch.next_probe.as_deref(), + Some("Re-read src/lib.rs before editing.") + ); + assert!( + scratch + .hypothesis + .as_deref() + .is_some_and(|text| text.contains("checkpoint validity is invalid")) + ); + + let checkpoint = EpiphanyInvestigationCheckpoint { + checkpoint_id: "ix-1".to_string(), + kind: "source_gathering".to_string(), + disposition: EpiphanyInvestigationDisposition::ResumeReady, + focus: "Old focus".to_string(), + ..Default::default() + }; + let code_refs = reorient_finding_code_refs(&finding); + let updated = reorient_finding_investigation_checkpoint( + &checkpoint, + "ev-reorient-1", + &code_refs, + &finding, + ); + + assert_eq!( + updated.disposition, + EpiphanyInvestigationDisposition::RegatherRequired + ); + assert_eq!(updated.evidence_ids, vec!["ev-reorient-1"]); + assert_eq!(updated.code_refs[0].path, PathBuf::from("src/lib.rs")); + assert_eq!( + updated.next_action.as_deref(), + Some("Re-read src/lib.rs before editing.") + ); + } + #[test] fn map_epiphany_context_projects_targeted_shard_without_mutation() { let state = codex_protocol::protocol::EpiphanyThreadState {