diff --git a/notes/epiphany-current-algorithmic-map.md b/notes/epiphany-current-algorithmic-map.md index 71458774..79d53198 100644 --- a/notes/epiphany-current-algorithmic-map.md +++ b/notes/epiphany-current-algorithmic-map.md @@ -29,6 +29,7 @@ The spine exists in twenty-four live paths: - freshness reflection: app-server declares experimental read-only `thread/epiphany/freshness`, reads the same live/stored thread view used by scene/jobs/context, fills live retrieval state for loaded threads, and derives one bounded retrieval/graph freshness lens plus, for loaded threads, watcher-backed invalidation inputs with watched root, changed paths, mapped graph-node hits, active-frontier hits, and revision/source identity without mutating, scheduling, notifying, or performing automatic semantic invalidation in [common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:350), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4167), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4259), [epiphany_invalidation.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/epiphany_invalidation.rs:19), [epiphany_invalidation.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/epiphany_invalidation.rs:67), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4219), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:11073). - targeted context reflection: app-server declares experimental read-only `thread/epiphany/context`, reads the same live/stored Epiphany state view used by scene/jobs, and derives a bounded state shard containing selected graph nodes/edges, links, active frontier, checkpoint, the full durable investigation-checkpoint packet, observations, direct evidence, linked evidence, and missing requested ids without retrieval, proposal, promotion, notification, mutation, or persistence in [common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:355), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4253), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4261), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:11152). - context-pressure reflection: core token telemetry carries `model_auto_compact_token_limit` beside total/last usage and `model_context_window`; app-server declares experimental read-only `thread/epiphany/pressure`, reads live token usage or the latest stored rollout `TokenCount`, and derives `unknown`/`low`/`elevated`/`high`/`critical` pressure plus a non-acting compaction-prep recommendation without mutating Epiphany state or scheduling compaction in [protocol.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/protocol/src/protocol.rs:2237), [turn_context.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/session/turn_context.rs:103), [session/mod.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/session/mod.rs:2716), [common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:360), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4361), [token_usage_replay.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor/token_usage_replay.rs:75), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4306), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:11028). +- pre-compaction checkpoint intervention: app-server `TokenCount` handling now checks the same pressure mapper, and for loaded Epiphany threads crossing `shouldPrepareCompaction` it steers the active turn once with a bounded CRRC checkpoint directive to bank working context before compaction/reorientation. The per-turn dedupe bit lives in listener `ThreadState`, and the intervention uses existing turn steering rather than a new scheduler in [bespoke_event_handling.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/bespoke_event_handling.rs:1467), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:15405), and [thread_state.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/thread_state.rs:144). - 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). - CRRC coordinator recommendation: app-server declares experimental read-only `thread/epiphany/crrc`, reuses the same pressure/freshness/watcher/reorientation mapping plus the fixed `reorient-worker` binding and result read-back helper, recognizes already accepted reorientation findings so an accepted result is not recommended for acceptance again, and returns one bounded recommendation such as continue, prepare checkpoint, launch worker, wait, review, accept, or regather manually without mutating, launching, accepting, compacting, notifying, scheduling, or silently continuing work 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:4661), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4546). - role ownership projection: app-server declares experimental read-only `thread/epiphany/roles`, reuses the same state/jobs/pressure/reorient/result/CRRC signals as the coordinator loop, and projects implementation, modeling/checkpoint, verification/review, and reorientation lanes with owner roles, status, linked jobs, authority scopes, and recommended scene actions without launching, scheduling, accepting, compacting, notifying, or mutating state in [common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:350), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4161), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4310). @@ -1266,6 +1267,41 @@ The response is a read-only gauge. The Phase 6 pressure smoke proved that a fres Pressure projection is read-only. It does not start compaction, perform CRRC, checkpoint source gathering, mutate `SessionState`, append rollout items, or emit state notifications. It is a pressure gauge, not an emergency crew with a clipboard addiction. +## Flow 16A: Pre-Compaction Checkpoint Intervention + +### Input + +The core session emits `EventMsg::TokenCount` while a turn is active. + +### Plain-language role + +This is the first CRRC mid-work intervention. It catches the moment pressure has +crossed the existing compaction-prep line but before the turn has ended, and it +tells the active agent to bank what it has learned instead of letting compaction +turn fresh working context into decorative smoke. + +### Mechanism + +The app-server event handler: + +1. clones the `TokenUsageInfo` from the `TokenCount` event before forwarding the normal token-usage notification. +2. maps it through the same pressure helper used by `thread/epiphany/pressure`. +3. ignores unknown/low/elevated pressure and acts only when `shouldPrepareCompaction` is true. +4. requires a loaded thread with existing Epiphany state. +5. records one intervention per active turn id in listener `ThreadState`. +6. uses existing turn steering with the expected active turn id to inject a bounded CRRC directive. + +The directive tells the agent to stop broad implementation, persist the active +working context into checkpoint/scratch/map/evidence as appropriate, say when the +checkpoint is banked, and stop for CRRC compaction/reorientation. + +### Invariant + +This intervention does not mutate Epiphany state itself, accept semantic +findings, promote evidence, launch arbitrary specialists, or continue +implementation. It is a shove toward persistence, not a new little emperor with +a queue. + ## Flow 17: Reorientation Policy Control Flow ### Input @@ -1308,7 +1344,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, 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 broad 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, can steer active loaded turns once at the compaction-prep threshold to bank working context, returns a read-only reorientation verdict, can explicitly launch one bounded reorientation worker, read that worker's result back through a reviewable surface, explicitly accept completed findings into typed state, and can auto-run only the narrow coordinator-approved compact/reorient-worker launch actions at turn completion. Semantic launch/acceptance policy and next-step execution remain explicit rather than ambient scheduler behavior. - no automatic watcher-driven graph or semantic invalidation. - no code-intelligence graph. - no broad specialist-agent scheduler or marketplace; only fixed manual modeling/checkpoint and verification/review role templates exist. diff --git a/notes/epiphany-fork-implementation-plan.md b/notes/epiphany-fork-implementation-plan.md index 51ae260c..51a9dfb7 100644 --- a/notes/epiphany-fork-implementation-plan.md +++ b/notes/epiphany-fork-implementation-plan.md @@ -113,7 +113,7 @@ These boundaries are more important than the individual method names: - `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. - Native CRRC automation may act only at safe turn-complete boundaries and only for coordinator-approved `compactRehydrateReorient` and `launchReorientWorker` actions. It must not auto-launch modeling or verification, auto-accept semantic findings, promote evidence, edit implementation code, or silently continue after unresolved drift. -- Turn-complete-only CRRC automation is conservative but incomplete. The MVP still needs pre-compaction checkpoint intervention so the harness can interrupt or steer the active agent into banking scratch/checkpoint/map/evidence before compaction erases learned but unexternalized working context. +- Pre-compaction checkpoint intervention may steer an active loaded Epiphany turn once at the token-count boundary when pressure reaches the existing `shouldPrepareCompaction` threshold. The steering directive is allowed to ask the agent to bank scratch/checkpoint/map/evidence before compaction/reorientation; it must not auto-accept semantic findings, promote evidence, launch arbitrary workers, or continue implementation after unresolved drift. - `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. @@ -213,10 +213,12 @@ workspace, report through `report_agent_job_result`, and return a completed proved the sequence-locked MVP policy across cold start, clean checkpoint, modeling, verification, CRRC drift/reorient, and high-pressure compact/dry-run paths. Native CRRC automation then wired the proved policy into turn-complete -safe boundaries for compact and fixed reorient-worker launch only. The next MVP -question is sharper: add the smallest pre-compaction checkpoint intervention so -active work can be persisted before compaction, then dogfood the -coordinator/status/artifact loop and fix only concrete blockers. +safe boundaries for compact and fixed reorient-worker launch only. The first +pre-compaction checkpoint intervention is now also landed: token-count pressure +events steer active loaded Epiphany turns once at the `shouldPrepareCompaction` +threshold so working context can be banked before compaction. The next MVP +question is sharper: dogfood the coordinator/status/pre-compaction loop and fix +only concrete blockers. ## Phase 6 Direction @@ -224,9 +226,9 @@ Phase 6 should grow observable harness state outward from the typed spine. Useful candidates: -1. Put the fixed-lane coordinator MVP in front of a human operator through status/artifact review, then fix concrete usability blockers. +1. Put the fixed-lane coordinator and pre-compaction checkpoint loop 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. Add pre-compaction checkpoint intervention before dogfooding long work: detect rising pressure before the hard cliff, interrupt or steer into a bounded persistence pass, then compact/resume/reorient. +3. Keep pre-compaction intervention narrow: steer once at `shouldPrepareCompaction`, then let explicit checkpointing, compact/resume/reorient, and review gates do their jobs. 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 @@ -241,7 +243,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 -- broader CRRC runtime coordination beyond the landed narrow safe-boundary compact and fixed reorient-worker launch actions +- broader CRRC runtime coordination beyond the landed narrow safe-boundary compact, fixed reorient-worker launch, and pre-compaction checkpoint steering actions - 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 diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 5103caaa..53889b5d 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -32,7 +32,7 @@ Do not trust this file for the exact live HEAD. Always check git. - `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. - Native CRRC automation is now landed only at turn-complete safe boundaries. It may submit `Op::Compact` for coordinator-approved `compactRehydrateReorient`, and it may launch the fixed `reorient-worker` for coordinator-approved `launchReorientWorker`. It does not auto-launch modeling/verification, accept findings, promote evidence, edit implementation code, or keep going after reviewable semantic output. -- This is not the full CRRC design. Turn-complete-only automation can still miss the important failure mode where the active agent has learned something during work but has not yet externalized it before compaction. The next CRRC slice should add a pre-compaction checkpoint intervention: detect rising pressure before the hard cliff, interrupt or steer the agent into a bounded persistence pass, then compact/resume/reorient only after scratch/checkpoint/map/evidence are banked as needed. +- Pre-compaction checkpoint intervention is now landed. On token-count events for loaded Epiphany threads, when pressure reaches the existing `shouldPrepareCompaction` threshold, the harness steers the active turn once with a CRRC checkpoint directive so the agent banks working context before compaction/reorientation. This is still bounded steering, not automatic semantic acceptance, a broad scheduler, or implementation continuation. - `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. @@ -89,6 +89,7 @@ The current spine: - read-only CRRC next-action recommendation through `thread/epiphany/crrc` - read-only fixed-lane MVP action recommendation through `thread/epiphany/coordinator` - limited turn-complete CRRC automation for coordinator-approved compact and fixed reorient-worker launch actions +- token-count pre-compaction checkpoint intervention for loaded Epiphany turns at the `shouldPrepareCompaction` threshold - 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` @@ -290,13 +291,13 @@ 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 fixed-lane coordinator MVP is testable, but the CRRC story is not complete. -Limited safe-boundary CRRC execution is wired for compact and fixed -reorient-worker launch actions, but it only acts after a turn ends. The next -real organ is pre-compaction checkpoint intervention: when pressure rises before -the hard cliff, interrupt or steer the active agent into a bounded persistence -pass so learned working context is banked before compaction. After that, compact, -resume, and reorient. CRRC is not a specialist-agent persona; the +The fixed-lane coordinator MVP is testable, and the first pre-compaction CRRC +intervention is now wired. Limited safe-boundary CRRC execution still handles +compact and fixed reorient-worker launch actions after a turn ends; the +token-count hook now handles the earlier danger zone by steering active loaded +turns once when `shouldPrepareCompaction` is reached. The next real move is +dogfooding the coordinator/status/pre-compaction loop on real local work and +fixing concrete MVP blockers. 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, automatic semantic acceptance path, or GUI-as-source-of-truth. @@ -314,7 +315,7 @@ are now guardrails, not the next organs. - automatic observation promotion - broad specialist-agent scheduling beyond the fixed single-user role lanes - GUI-as-source-of-truth -- broad runtime CRRC execution beyond the landed safe-boundary compact and fixed reorient-worker launch actions +- broad runtime CRRC execution beyond the landed safe-boundary compact, fixed reorient-worker launch, and pre-compaction checkpoint steering actions - Epiphany-owned long-running job execution beyond the current runtime `agent_jobs` seam - broad event stream beyond the landed state update notification diff --git a/state/evidence.jsonl b/state/evidence.jsonl index eec0b0c4..becfc9b7 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -62,3 +62,4 @@ {"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."} {"ts": "2026-04-28T18:56:47+01:00", "type": "implementation", "status": "ok", "note": "Landed limited native CRRC automation at turn-complete safe boundaries. It reuses the read-only coordinator policy and only auto-runs compactRehydrateReorient via Op::Compact or launchReorientWorker via the fixed reorient-worker job binding; modeling, verification, semantic acceptance, evidence promotion, implementation edits, and hidden continuation remain review-gated or manual. Focused coordinator automation assertions, job-progress event handling, coordinator smoke, status smoke, role smoke, and reorient-launch smoke passed."} {"ts": "2026-04-29T02:35:26+01:00", "type": "design", "status": "ok", "note": "Corrected the CRRC MVP target: turn-complete-only automation is insufficient because compaction can lose learned but unexternalized working context. The next CRRC slice should detect rising pressure before the hard cliff, interrupt or steer the active agent into a bounded persistence/checkpoint pass, then compact/resume/reorient after scratch/checkpoint/map/evidence are banked as needed."} +{"ts": "2026-04-29T15:15:06+01:00", "type": "implementation", "status": "ok", "note": "Landed the smallest pre-compaction checkpoint intervention: TokenCount handling maps pressure through the existing gauge and, for loaded Epiphany threads at shouldPrepareCompaction, steers the active turn once with a bounded CRRC directive to bank checkpoint/scratch/map/evidence before compaction or reorientation. It does not mutate state directly, accept findings, launch arbitrary specialists, or continue implementation. Focused app-server tests plus coordinator/status/reorient/role smokes passed; a stale scene expected-actions assertion was corrected to include the already-landed coordinator action."} diff --git a/state/map.yaml b/state/map.yaml index de534dcd..0ccc2b5e 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -12,8 +12,9 @@ objective: explicit typed models of the codebase, active goal, evidence, and change machinery they are working on. current: > - Dogfood the landed Phase 6 MVP coordinator and limited CRRC safe-boundary - automation on real local work before adding larger organs. + Dogfood the landed Phase 6 MVP coordinator, limited CRRC safe-boundary + automation, and pre-compaction checkpoint intervention on real local work + before adding larger organs. constraints: - No frontier-scale training budget. @@ -54,7 +55,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, coordinator, and reorientResult. - - Dogfood the landed Phase 6 coordinator and limited safe-boundary CRRC automation before adding larger organs. + - Dogfood the landed Phase 6 coordinator, limited safe-boundary CRRC automation, and pre-compaction checkpoint intervention before adding larger organs. - Preserve review gates for semantic findings; automatic CRRC may compact or launch the fixed reorient-worker, but not accept or promote. - Keep persistent project state ruthlessly distilled so rehydration strengthens the next turn instead of bloating it. @@ -86,7 +87,7 @@ accepted_design: - `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. - Limited native CRRC automation is now wired only at turn-complete safe boundaries: it can submit a compact operation when the read-only coordinator recommends `compactRehydrateReorient`, and it can launch the fixed `reorient-worker` when the coordinator recommends `launchReorientWorker`. It does not auto-launch modeling or verification, auto-accept findings, promote evidence, edit implementation code, or continue after reviewable semantic results. - - Turn-complete-only CRRC automation is not enough for the full Epiphany design. The next CRRC primitive must detect rising pressure before the hard compaction cliff and interrupt or steer the active agent into an explicit persistence/checkpoint pass so learned-but-unspoken working context is banked into scratch/checkpoint/map/evidence before compaction can sand it off. + - Pre-compaction checkpoint intervention is now wired at token-count boundaries: when a loaded Epiphany thread crosses the existing `shouldPrepareCompaction` pressure threshold during an active turn, the harness steers the active agent once for that turn with a bounded CRRC directive to bank scratch/checkpoint/map/evidence before compaction/reorientation. This is still steering, not semantic acceptance, broad scheduling, or automatic implementation continuation. - `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. @@ -124,6 +125,7 @@ landed_baseline: - 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. - Phase 6 safe-boundary CRRC automation: turn-complete automation limited to coordinator-approved compact and fixed reorient-worker launch actions. + - Phase 6 pre-compaction checkpoint intervention: token-count pressure hook that steers active turns once when `shouldPrepareCompaction` is reached so working context is banked before compaction. 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. @@ -159,5 +161,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, coordinator, reorient launch/result/accept, explicit modeling/checkpoint and verification/review role launch/result templates, MVP status, dogfood runner, coordinator runner, live specialist runner, and limited safe-boundary CRRC automation are landed. The coordinator endpoint and runner make fixed-lane modeling, verification, implementation continuation, and CRRC handoffs explicit through review-gated artifacts; native automation currently only compacts or launches the fixed reorient-worker at turn-complete boundaries when the coordinator says it can auto-run. That is conservative but incomplete: full CRRC needs a pre-compaction checkpoint intervention before active working memory is lost. Implementation remains main-agent work; CRRC remains workflow automation, not a specialist persona. - next_action: Design and implement the smallest pre-compaction checkpoint intervention: when pressure is rising before the hard compaction cliff, interrupt or steer the active agent into a bounded persistence pass that writes scratch/checkpoint/map/evidence as needed, then compact/resume/reorient. Keep semantic acceptance review-gated, 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, live specialist runner, limited safe-boundary CRRC automation, and pre-compaction checkpoint intervention are landed. Native CRRC can now steer an active loaded Epiphany turn once when token pressure reaches `shouldPrepareCompaction`, asking the agent to bank working context before compaction; turn-complete automation can still compact or launch the fixed reorient-worker when the coordinator says it can auto-run. Implementation remains main-agent work; CRRC remains workflow automation, not a specialist persona. + next_action: Dogfood the coordinator/status/pre-compaction loop on real local work and fix only concrete blockers that prevent a usable single-user MVP. Keep semantic acceptance review-gated, and do not build a broad ambient dispatcher, GUI-as-source-of-truth, arbitrary specialist marketplace, or alternate job backend for the MVP. diff --git a/vendor/codex/codex-rs/app-server/src/bespoke_event_handling.rs b/vendor/codex/codex-rs/app-server/src/bespoke_event_handling.rs index 16c1c6ea..ccb59b99 100644 --- a/vendor/codex/codex-rs/app-server/src/bespoke_event_handling.rs +++ b/vendor/codex/codex-rs/app-server/src/bespoke_event_handling.rs @@ -1,5 +1,6 @@ use crate::codex_message_processor::ApiVersion; use crate::codex_message_processor::maybe_run_epiphany_coordinator_automation_for_turn_boundary; +use crate::codex_message_processor::maybe_run_epiphany_pre_compaction_checkpoint_intervention_for_token_count; use crate::codex_message_processor::read_rollout_items_from_rollout; use crate::codex_message_processor::read_summary_from_rollout; use crate::codex_message_processor::summary_to_thread; @@ -1464,8 +1465,22 @@ pub(crate) async fn apply_bespoke_event_handling( .await; } EventMsg::TokenCount(token_count_event) => { - handle_token_count_event(conversation_id, event_turn_id, token_count_event, &outgoing) - .await; + let token_usage_info = token_count_event.info.clone(); + handle_token_count_event( + conversation_id, + event_turn_id.clone(), + token_count_event, + &outgoing, + ) + .await; + maybe_run_epiphany_pre_compaction_checkpoint_intervention_for_token_count( + conversation_id, + event_turn_id, + conversation, + token_usage_info, + &thread_state, + ) + .await; } EventMsg::Error(ev) => { thread_watch_manager 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 dbd0cdcf..b69e6ebd 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 @@ -14664,6 +14664,34 @@ fn map_epiphany_pressure(info: Option<&CoreTokenUsageInfo>) -> ThreadEpiphanyPre } } +fn should_run_epiphany_pre_compaction_checkpoint_intervention( + pressure: &ThreadEpiphanyPressure, +) -> bool { + pressure.status == ThreadEpiphanyPressureStatus::Ready && pressure.should_prepare_compaction +} + +fn render_epiphany_pre_compaction_checkpoint_intervention( + pressure: &ThreadEpiphanyPressure, +) -> String { + let usage = match ( + pressure.used_tokens, + pressure.remaining_tokens, + pressure.ratio_per_mille, + ) { + (Some(used), Some(remaining), Some(ratio)) => format!( + "{used} tokens used, {remaining} remaining, {}.{}% of the selected limit", + ratio / 10, + ratio % 10 + ), + (Some(used), _, _) => format!("{used} tokens used"), + _ => "token usage known only as a pressure threshold crossing".to_string(), + }; + format!( + "Epiphany CRRC pre-compaction checkpoint intervention: context pressure is {} ({usage}). Stop broad implementation now and bank the active working context before compaction. Persist a bounded checkpoint/scratch update with the current objective, files or seams inspected, important findings, unresolved questions, and the next safe move. Add distilled evidence only if this changes future belief. After the checkpoint is banked, say so plainly and stop for CRRC compaction/reorientation; do not continue implementation past unresolved drift.", + pressure_level_label(pressure.level), + ) +} + fn map_epiphany_reorient( state: Option<&EpiphanyThreadState>, pressure: &ThreadEpiphanyPressure, @@ -15374,6 +15402,52 @@ pub(crate) async fn maybe_run_epiphany_coordinator_automation_for_turn_boundary( } } +pub(crate) async fn maybe_run_epiphany_pre_compaction_checkpoint_intervention_for_token_count( + thread_id: ThreadId, + turn_id: String, + thread: Arc, + token_usage_info: Option, + thread_state: &Arc>, +) { + let pressure = map_epiphany_pressure(token_usage_info.as_ref()); + if !should_run_epiphany_pre_compaction_checkpoint_intervention(&pressure) { + return; + } + if thread.epiphany_state().await.is_none() { + return; + } + if !thread_state + .lock() + .await + .record_epiphany_checkpoint_intervention(&turn_id) + { + return; + } + + let text = render_epiphany_pre_compaction_checkpoint_intervention(&pressure); + match thread + .steer_input( + vec![CoreInputItem::Text { + text, + text_elements: Vec::new(), + }], + Some(&turn_id), + None, + ) + .await + { + Ok(_) => {} + Err(SteerInputError::NoActiveTurn(_)) + | Err(SteerInputError::ExpectedTurnMismatch { .. }) + | Err(SteerInputError::ActiveTurnNotSteerable { .. }) + | Err(SteerInputError::EmptyInput) => { + warn!( + "failed to steer Epiphany pre-compaction checkpoint intervention for {thread_id}" + ); + } + } +} + async fn load_epiphany_job_launcher_snapshots( state_db_ctx: Option<&StateDbHandle>, state: Option<&EpiphanyThreadState>, @@ -17503,6 +17577,7 @@ mod tests { ThreadEpiphanySceneAction::Context, ThreadEpiphanySceneAction::Jobs, ThreadEpiphanySceneAction::Roles, + ThreadEpiphanySceneAction::Coordinator, ThreadEpiphanySceneAction::RoleLaunch, ThreadEpiphanySceneAction::RoleResult, ThreadEpiphanySceneAction::JobLaunch, @@ -17754,6 +17829,40 @@ mod tests { assert!(!pressure.should_prepare_compaction); } + #[test] + fn pre_compaction_checkpoint_intervention_uses_compaction_prep_threshold() { + let elevated = map_epiphany_pressure(Some(&CoreTokenUsageInfo { + total_token_usage: codex_protocol::protocol::TokenUsage { + total_tokens: 89, + ..Default::default() + }, + last_token_usage: codex_protocol::protocol::TokenUsage::default(), + model_context_window: None, + model_auto_compact_token_limit: Some(100), + })); + let high = map_epiphany_pressure(Some(&CoreTokenUsageInfo { + total_token_usage: codex_protocol::protocol::TokenUsage { + total_tokens: 90, + ..Default::default() + }, + last_token_usage: codex_protocol::protocol::TokenUsage::default(), + model_context_window: None, + model_auto_compact_token_limit: Some(100), + })); + + assert!(!should_run_epiphany_pre_compaction_checkpoint_intervention( + &elevated + )); + assert!(should_run_epiphany_pre_compaction_checkpoint_intervention( + &high + )); + + let prompt = render_epiphany_pre_compaction_checkpoint_intervention(&high); + assert!(prompt.contains("pre-compaction checkpoint intervention")); + assert!(prompt.contains("bank the active working context")); + assert!(prompt.contains("do not continue implementation")); + } + #[test] fn map_epiphany_reorient_regathers_without_state() { let pressure = map_epiphany_pressure(None); diff --git a/vendor/codex/codex-rs/app-server/src/thread_state.rs b/vendor/codex/codex-rs/app-server/src/thread_state.rs index f399a72c..046af324 100644 --- a/vendor/codex/codex-rs/app-server/src/thread_state.rs +++ b/vendor/codex/codex-rs/app-server/src/thread_state.rs @@ -66,6 +66,7 @@ pub(crate) struct ThreadState { listener_command_tx: Option>, current_turn_history: ThreadHistoryBuilder, last_epiphany_jobs_by_job_id: HashMap, + last_epiphany_checkpoint_intervention_turn_id: Option, listener_thread: Option>, } @@ -139,6 +140,18 @@ impl ThreadState { } changed } + + pub(crate) fn record_epiphany_checkpoint_intervention(&mut self, turn_id: &str) -> bool { + if self + .last_epiphany_checkpoint_intervention_turn_id + .as_deref() + == Some(turn_id) + { + return false; + } + self.last_epiphany_checkpoint_intervention_turn_id = Some(turn_id.to_string()); + true + } } pub(crate) async fn resolve_server_request_on_thread_listener(