Plan Phase 2 prompt integration

This commit is contained in:
Meta Vens 2026-04-23 23:28:10 +01:00
commit c823815811
4 changed files with 254 additions and 156 deletions

View file

@ -1,173 +1,215 @@
# Codex Epiphany Phase 1 Implementation Plan
# Codex Epiphany Phase 2 Implementation Plan
This is the actionable implementation note for the first Epiphany patch slice against the real `openai/codex` tree vendored under `vendor/codex`.
This is the actionable implementation note for the second Epiphany patch slice against the real `openai/codex` tree now vendored directly under `vendor/codex`.
Phase 1 is deliberately **internal/dev-usable**, not user-facing. The goal is to give Codex a real durable Epiphany state seam in core, keep the app usable, and prove replay/persistence before touching prompts, presets, protocol notifications, or GUI reflection.
Phase 1 landed in parent commit `2042687e3035c5a86d7f6aa66306d87abcc10f2d`. The durable state seam exists. Codex can now persist and replay structured Epiphany thread state. The next job is to make that state actually matter to the turn loop without pretending we already have GUI, retrieval, or operator ergonomics solved.
## Summary
Land Phase 1 as an **additive core slice** that persists and rehydrates structured Epiphany thread state without changing normal Codex behavior.
Land Phase 2 as a **prompt-integration slice** that derives a compact Epiphany summary from `SessionState.epiphany_state` and injects it into the developer-context path during turn construction.
After this slice:
- non-Epiphany sessions still behave exactly as they do now
- the app remains usable because existing clients ignore the new metadata
- Epiphany state can be exercised and validated through automated core/rollout/resume tests
- Epiphany state affects model behavior instead of just sitting in rollout
- resumed Epiphany sessions carry their structured understanding back into the prompt path
- normal non-Epiphany sessions still behave exactly as they do now
This slice does **not** include:
This slice still does **not** include:
- prompt integration
- app-server notifications
- GUI surfaces
- collaboration-mode presets
- mutation gates
- app-server notifications or typed read/update RPCs
- retrieval indexing
- specialist-agent orchestration
- watcher-driven semantic invalidation
- observation promotion heuristics
- specialist-agent scheduling
- public operator UX
## Phase 2 Principle
The activation rule for Phase 2 should stay brutally simple:
- if `SessionState.epiphany_state` is `Some`, the session is Epiphany-active
- if it is `None`, nothing new is injected
That is enough for internal/dev use. Do not invent a new public toggle, preset, or protocol field in this slice.
## Key Changes
### 1. Add minimal durable Epiphany protocol types
### 1. Add a dedicated Epiphany prompt fragment renderer
Touch:
- `vendor/codex/codex-rs/protocol/src/protocol.rs`
- `vendor/codex/codex-rs/core/src/context/mod.rs`
- `vendor/codex/codex-rs/core/src/context/epiphany_state_instructions.rs` (new)
Add:
Add a new contextual fragment, tentatively:
- `EpiphanyThreadState`
- `EpiphanyStateItem { turn_id: Option<String>, state: EpiphanyThreadState }`
- `RolloutItem::EpiphanyState(EpiphanyStateItem)`
- `EpiphanyStateInstructions`
Phase 1 schema should stay minimal but sufficient:
Pattern it after other developer-scoped context fragments such as collaboration-mode and permissions instructions.
Responsibilities:
- render a compact, deterministic textual summary from `EpiphanyThreadState`
- wrap it in its own clear developer marker block such as `<epiphany_state> ... </epiphany_state>`
- include light instruction text that tells the model how to treat the state:
- use it as the current structured thread understanding
- do not silently redefine it
- surface mismatches or gaps before broad edits
Do **not** dump raw JSON into the prompt.
### 2. Keep the summary bounded and intentionally selective
The renderer should include only the parts that help the model stay oriented during a turn.
Include:
- `revision`
- `objective`
- `active_subgoal_id`
- `subgoals`
- `invariants`
- `graphs`
- a bounded list of nearby `subgoals`
- a bounded list of `invariants`
- a compact `graphs` summary centered on the frontier
- `graph_frontier`
- `graph_checkpoint`
- `scratch`
- `observations`
- `recent_evidence`
- recent `observations`
- recent `recent_evidence`
- `churn`
- `mode`
- `last_updated_turn_id`
Defer these to later phases:
Default Phase 2 shaping rules:
- `agents`
- `jobs`
- `retrieval`
- separate append-only evidence/checkpoint rollout items
- separate turn intent rollout item
- any new `EventMsg` variants
- prefer frontier and checkpoint over whole-graph dumping
- prefer active and recent records over exhaustive history
- cap list lengths aggressively
- keep code refs line-anchored when rendered, but do not spam them everywhere
- omit empty sections entirely
All new protocol types should derive the same serialization/schema traits as neighboring rollout types.
Phase 2 should **not** naively dump full scratch content. Scratch is volatile and can turn the prompt back into sludge. If scratch is rendered at all, keep it to a tiny active-summary form.
### 2. Store Epiphany state in `SessionState`
### 3. Inject the Epiphany summary during initial context construction
Touch:
- `vendor/codex/codex-rs/core/src/state/session.rs`
- `vendor/codex/codex-rs/core/src/session/mod.rs`
The integration point is:
- `Session::build_initial_context`
Add:
- `epiphany_state: Option<EpiphanyThreadState>` to `SessionState`
- simple getter/setter helpers on session state
- a read of `self.epiphany_state().await`
- conditional rendering of `EpiphanyStateInstructions` when the state exists
- insertion into `developer_sections`
Persistence rule:
Recommended placement:
- persist one `RolloutItem::EpiphanyState(...)` per real user turn
- write it immediately after the `TurnContextItem` baseline is persisted
- skip the write when `epiphany_state` is `None`
- after collaboration-mode instructions
- before realtime/personality/apps/skills/plugin additions
Do not change prompt assembly or tool behavior in this slice.
That keeps the Epiphany state near the top-level task discipline instead of burying it behind auxiliary capability chatter.
### 3. Rehydrate Epiphany state on resume and fork
Do **not** change:
- `TurnContext`
- rollout protocol
- tool routing
- token accounting rules
unless a small mechanical adjustment becomes unavoidable during implementation.
### 4. Treat prompt integration as read-only in this slice
Phase 2 is about **consuming** Epiphany state during turns, not teaching the model to rewrite canon by itself.
So in this slice:
- the model reads Epiphany state
- the existing persistence seam remains the storage mechanism
- no automatic state mutation from assistant output happens yet
If state updates are needed during testing, use the internal/dev hooks that already exist from Phase 1.
### 5. Add prompt-facing tests, not just persistence tests
Touch:
- `vendor/codex/codex-rs/core/src/session/rollout_reconstruction.rs`
- the session-start/resume path that consumes `RolloutReconstruction`
- `vendor/codex/codex-rs/core/src/session/tests.rs`
- `vendor/codex/codex-rs/core/src/session/snapshots/` (if a new snapshot is needed)
- optionally `vendor/codex/codex-rs/core/src/context/epiphany_state_instructions.rs` local tests
Extend reconstruction to carry:
Add at least:
- `epiphany_state: Option<EpiphanyThreadState>`
1. `build_initial_context_includes_epiphany_state_block_when_present`
- seed `SessionState.epiphany_state`
- call `build_initial_context`
- verify the developer bundle includes the Epiphany block
Replay rule:
2. `build_initial_context_omits_epiphany_state_block_when_absent`
- verify normal sessions stay unchanged
- the newest surviving `EpiphanyStateItem` wins
- rollback must discard Epiphany snapshots from rolled-back turns
- compaction must not erase the latest surviving snapshot
3. one bounded-rendering test
- prove the renderer prefers frontier/recent items and omits empty sections
Treat `EpiphanyStateItem` as turn-scoped metadata in the same reverse scan that already respects rollback and compaction boundaries.
4. one snapshot-style request/context test
- similar in spirit to the existing fork/context snapshot coverage
- confirm Epiphany state appears where expected in the built prompt
### 4. Update rollout readers to tolerate the new variant
If practical, add one resume-oriented assertion:
Adding a `RolloutItem` variant will create exhaustiveness fallout across the repo. Update those sites explicitly instead of letting it turn into whack-a-mole.
- reconstruct a session from rollout with Epiphany state
- build initial context
- verify the injected Epiphany block survives replay and resume
At minimum touch:
## Public Interfaces
- `vendor/codex/codex-rs/app-server-protocol/src/protocol/thread_history.rs`
- `vendor/codex/codex-rs/rollout/src/policy.rs`
- `vendor/codex/codex-rs/rollout/src/metadata.rs`
- `vendor/codex/codex-rs/rollout/src/list.rs`
- `vendor/codex/codex-rs/rollout/src/recorder.rs`
- any additional exhaustive `RolloutItem` matches in `core`, `tui`, `exec`, and `protocol`
Phase 2 should still avoid public surface churn.
Phase 1 behavior at those call sites:
No new:
- thread-history/UI builders should ignore `EpiphanyState`
- rollout metadata/listing code should treat it as non-rendered metadata
- existing user-visible thread rendering must stay unchanged
- protocol events
- app-server notifications
- GUI methods
- public activation controls
## Test Plan
### Protocol and schema
- serde round-trip for `EpiphanyThreadState`
- serde round-trip for `EpiphanyStateItem`
- any protocol/schema snapshots updated for the new `RolloutItem` variant
### Core persistence
- a session with populated Epiphany state writes `RolloutItem::EpiphanyState`
- a session with `None` Epiphany state writes nothing extra
- the Epiphany rollout item appears after the turn-context baseline for the turn
### Replay correctness
- resume restores the newest surviving Epiphany snapshot
- rollback drops snapshots from discarded turns
- compaction keeps the latest surviving Epiphany snapshot available after reconstruction
### Compatibility
- `app-server-protocol` thread reconstruction still builds the same visible turn history
- rollout list/metadata readers still work with mixed old/new rollout files
- untouched user flows remain unchanged in tests
### Compile-fallout coverage
- build/test the touched crates so all exhaustive `RolloutItem` matches are updated in one pass
This is still an internal/dev-usable slice.
## Assumptions
- Phase 1 is **internal/dev-usable**, not operator-usable or GUI-visible.
- "Testable after Phase 1" means persistence/replay behavior is verifiable through automated tests and internal session wiring, not that users can activate Epiphany from the UI yet.
- Phase 1 keeps evidence and checkpoint data embedded inside the baseline Epiphany snapshot instead of splitting them into separate rollout item variants.
- Prompt integration, app-server typed updates, GUI scene loading, retrieval, jobs, and specialist-agent scheduling are later slices.
- The existence of `SessionState.epiphany_state` is sufficient as the Phase 2 activation signal.
- The Epiphany prompt block belongs in the developer-context path, not as a user message.
- Prompt integration should remain compact and deterministic; this slice is not permission to stuff the entire map back into one giant haunted string.
- Phase 2 is still safe to ship without GUI changes because non-Epiphany sessions remain untouched.
## Test Plan
### Core behavior
- Epiphany-active sessions inject a developer-scoped Epiphany summary
- non-Epiphany sessions do not
- resumed sessions with persisted Epiphany state inject the latest surviving summary
### Rendering discipline
- empty fields do not create empty sections
- bounded sections truncate deterministically
- frontier/gap/evidence ordering is stable
### Compatibility
- existing prompt/context tests continue to pass for non-Epiphany paths
- no new rollout compatibility fallout should appear because Phase 2 consumes existing state only
## Immediate Next Step After This Plan
Implement the protocol/core/replay slice only:
Implement the smallest useful prompt path only:
1. add the minimal protocol types
2. wire `SessionState`
3. persist one snapshot per real user turn
4. restore it through rollout reconstruction
5. patch exhaustive `RolloutItem` matches
6. add replay/persistence tests before moving on
1. add `EpiphanyStateInstructions`
2. inject it from `Session::build_initial_context` when `epiphany_state` exists
3. add omission/inclusion tests
4. add one snapshot proving the prompt shape
Do not start with GUI. Do not start with retrieval. Do not start teaching the model to rewrite canon from its own prose.