2026-04-23 23:28:10 +01:00
# Codex Epiphany Phase 2 Implementation Plan
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
This is the actionable implementation note for the second Epiphany patch slice against the real `openai/codex` tree now vendored directly under `vendor/codex` .
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
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.
2026-04-23 22:01:17 +01:00
## Summary
2026-04-23 23:28:10 +01:00
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.
2026-04-23 22:01:17 +01:00
After this slice:
2026-04-23 23:28:10 +01:00
- 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
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
This slice still does **not ** include:
2026-04-23 22:01:17 +01:00
- GUI surfaces
2026-04-23 23:28:10 +01:00
- app-server notifications or typed read/update RPCs
2026-04-23 22:01:17 +01:00
- retrieval indexing
2026-04-23 23:28:10 +01:00
- 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.
2026-04-23 22:01:17 +01:00
## Key Changes
2026-04-23 23:28:10 +01:00
### 1. Add a dedicated Epiphany prompt fragment renderer
2026-04-23 22:01:17 +01:00
Touch:
2026-04-23 23:28:10 +01:00
- `vendor/codex/codex-rs/core/src/context/mod.rs`
- `vendor/codex/codex-rs/core/src/context/epiphany_state_instructions.rs` (new)
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
Add a new contextual fragment, tentatively:
- `EpiphanyStateInstructions`
Pattern it after other developer-scoped context fragments such as collaboration-mode and permissions instructions.
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
Responsibilities:
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
- 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:
2026-04-23 22:01:17 +01:00
- `revision`
- `objective`
- `active_subgoal_id`
2026-04-23 23:28:10 +01:00
- a bounded list of nearby `subgoals`
- a bounded list of `invariants`
- a compact `graphs` summary centered on the frontier
2026-04-23 22:01:17 +01:00
- `graph_frontier`
- `graph_checkpoint`
2026-04-23 23:28:10 +01:00
- recent `observations`
- recent `recent_evidence`
2026-04-23 22:01:17 +01:00
- `churn`
- `mode`
- `last_updated_turn_id`
2026-04-23 23:28:10 +01:00
Default Phase 2 shaping rules:
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
- 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
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
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.
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
### 3. Inject the Epiphany summary during initial context construction
2026-04-23 22:01:17 +01:00
Touch:
- `vendor/codex/codex-rs/core/src/session/mod.rs`
2026-04-23 23:28:10 +01:00
The integration point is:
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
- `Session::build_initial_context`
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
Add:
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
- a read of `self.epiphany_state().await`
- conditional rendering of `EpiphanyStateInstructions` when the state exists
- insertion into `developer_sections`
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
Recommended placement:
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
- after collaboration-mode instructions
- before realtime/personality/apps/skills/plugin additions
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
That keeps the Epiphany state near the top-level task discipline instead of burying it behind auxiliary capability chatter.
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
Do **not ** change:
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
- `TurnContext`
- rollout protocol
- tool routing
- token accounting rules
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
unless a small mechanical adjustment becomes unavoidable during implementation.
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
### 4. Treat prompt integration as read-only in this slice
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
Phase 2 is about **consuming ** Epiphany state during turns, not teaching the model to rewrite canon by itself.
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
So in this slice:
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
- the model reads Epiphany state
- the existing persistence seam remains the storage mechanism
- no automatic state mutation from assistant output happens yet
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
If state updates are needed during testing, use the internal/dev hooks that already exist from Phase 1.
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
### 5. Add prompt-facing tests, not just persistence tests
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
Touch:
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
- `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
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
Add at least:
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
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
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
2. `build_initial_context_omits_epiphany_state_block_when_absent`
- verify normal sessions stay unchanged
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
3. one bounded-rendering test
- prove the renderer prefers frontier/recent items and omits empty sections
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
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
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
If practical, add one resume-oriented assertion:
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
- reconstruct a session from rollout with Epiphany state
- build initial context
- verify the injected Epiphany block survives replay and resume
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
## Public Interfaces
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
Phase 2 should still avoid public surface churn.
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
No new:
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
- protocol events
- app-server notifications
- GUI methods
- public activation controls
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
This is still an internal/dev-usable slice.
2026-04-23 22:01:17 +01:00
## Assumptions
2026-04-23 23:28:10 +01:00
- 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
2026-04-23 22:01:17 +01:00
## Immediate Next Step After This Plan
2026-04-23 23:28:10 +01:00
Implement the smallest useful prompt path only:
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
2026-04-23 22:01:17 +01:00
2026-04-23 23:28:10 +01:00
Do not start with GUI. Do not start with retrieval. Do not start teaching the model to rewrite canon from its own prose.