2026-04-24 00:41:16 +01:00
# Codex Epiphany Phase 4 Implementation Plan
2026-04-23 22:01:17 +01:00
2026-04-23 23:48:52 +01:00
## Status
2026-04-24 03:22:30 +01:00
Updated on 2026-04-24 after landing the first bounded Phase 4 slice on `main` :
2026-04-23 23:48:52 +01:00
2026-04-24 00:41:16 +01:00
- Phase 1 durable Epiphany thread state
- Phase 2 prompt integration
- a minimal Phase 3 typed client read surface via `Thread.epiphanyState`
2026-04-24 02:45:02 +01:00
- a verified Phase 4 slice 1 query-time hybrid retriever across protocol, core, app-server protocol, and app-server
2026-04-23 23:48:52 +01:00
2026-04-24 02:45:02 +01:00
The next job is no longer to prove the retriever exists. That part is done. The next job is to keep the landing zone honest: do not casually turn `thread/epiphany/retrieve` into a durable Epiphany-state writer just because the state object has a `retrieval` field, and do not regress into another blob-shaped persistent semantic store when the time comes to add one.
2026-04-23 22:01:17 +01:00
## Summary
2026-04-24 00:41:16 +01:00
Land Phase 4 as a **bounded internal retrieval slice ** :
- add typed retrieval state and shard/index summaries to Epiphany state
- add one additive app-server retrieval query surface for loaded threads
- support hybrid retrieval from day one:
- exact/path/symbol/lexical results
- semantic chunk results
- keep the slice internal/dev-usable first
2026-04-23 22:01:17 +01:00
After this slice:
2026-04-24 00:41:16 +01:00
- Epiphany can ask structured repo questions through one typed surface
- GUI work has a real data source later
- retrieval can evolve without making prompt text or shell transcripts the canonical knowledge path
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
This slice should still avoid:
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
- watcher-driven invalidation
- automatic observation promotion
- GUI implementation
2026-04-23 23:28:10 +01:00
- specialist-agent scheduling
2026-04-24 00:41:16 +01:00
- user-facing activation flows
2026-04-23 23:28:10 +01:00
2026-04-24 00:41:16 +01:00
## Phase 4 Principle
2026-04-23 23:28:10 +01:00
2026-04-24 00:41:16 +01:00
Do not build "vector search" as a separate novelty organ off to the side.
2026-04-23 23:28:10 +01:00
2026-04-24 00:41:16 +01:00
Build a **hybrid repo retrieval subsystem ** with one typed query shape and one typed result shape. Exact lookup and semantic lookup should be different modes of the same machine, not rival religions.
2026-04-23 22:01:17 +01:00
2026-04-24 02:45:02 +01:00
## Recovered bounded decision
After rehydrating from the repo state and the lone dirty working-tree diff, the first bounded Phase 4 slice should be:
- query-time
- loaded-thread-first
- read-only
- hybrid from day one
Concrete choice for the first implementation:
- reuse existing `codex_file_search` substrate for exact/path-ish lookup
- use workspace-local BM25 chunk search as the initial semantic backend
- defer embeddings, vector stores, persistent indexing, and watcher-driven invalidation
Updated follow-up direction after landing the verified slice:
- keep the BM25 implementation as the proven baseline/fallback
- for the first persistent semantic backend, prefer Qdrant over JSON/blob/postgres-thrash designs, but do not make it a hard requirement for basic Epiphany use
- do not turn retrieval into vector-only soup; exact/path lookup remains first-class and BM25 remains useful as bootstrap/control/fallback when Qdrant is unavailable
Preflight note:
- use tracked source as the corpus estimate, not raw working-tree disk usage
- at `vendor/codex` HEAD `d45ab10` , tracked `codex-rs` source is `3642` files / `31.09 MB`
- raw working-tree size under `codex-rs` can be heavily inflated by build artifacts and will lie to the design
2026-04-24 03:22:30 +01:00
Current landed implementation note:
2026-04-24 02:45:02 +01:00
- the protocol scaffold still exists in `vendor/codex/codex-rs/protocol/src/protocol.rs`
- it is now wired through the working tree across:
- `core/src/epiphany_retrieval.rs`
- `core/src/codex_thread.rs`
- `core/src/session/tests.rs`
- `app-server-protocol/src/protocol/common.rs`
- `app-server-protocol/src/protocol/v2.rs`
- `app-server-protocol/src/export.rs`
- `app-server/src/codex_message_processor.rs`
2026-04-24 03:22:30 +01:00
- the slice is now formatted, verified, committed, and pushed on `main` :
2026-04-24 02:45:02 +01:00
- `cargo fmt --all` passed
- targeted no-run compile for `codex-core` , `codex-app-server-protocol` , and `codex-app-server` passed
- targeted Phase 4 tests passed in core, app-server protocol, and app-server
- full `cargo test -p codex-app-server-protocol` passed after regenerating stable schema fixtures
- stable schema fixtures are the safe checked-in state for this slice; `write_schema_fixtures --experimental` rewrites the same tree and cannot be left behind as the repo state
2026-04-23 22:01:17 +01:00
## Key Changes
2026-04-24 00:41:16 +01:00
### 1. Extend Epiphany state with retrieval metadata
2026-04-23 22:01:17 +01:00
Touch:
2026-04-24 00:41:16 +01:00
- `vendor/codex/codex-rs/protocol/src/protocol.rs`
2026-04-23 23:28:10 +01:00
2026-04-24 00:41:16 +01:00
Add minimal retrieval metadata to `EpiphanyThreadState` , for example:
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
- `retrieval`
- `workspace_root`
- `index_revision`
- `status`
- `semantic_available`
- `last_indexed_at`
- `shards`
- `dirty_paths`
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
Keep this metadata summary-focused. Do not dump raw embeddings, giant posting lists, or per-file sludge into thread state.
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
### 2. Add a core retrieval facade
2026-04-23 22:01:17 +01:00
Touch:
2026-04-24 00:41:16 +01:00
- `vendor/codex/codex-rs/core/src/`
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
Add a focused retrieval module, tentatively:
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
- `epiphany_retrieval.rs`
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
Responsibilities:
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
- accept a loaded thread plus query params
- resolve the relevant workspace root
- run exact retrieval and semantic retrieval behind one interface
- return typed ranked results with file paths, line anchors, excerpts, and retrieval mode metadata
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
Result types should be explicit and bounded:
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
- exact hits
- semantic hits
- optional graph-linked ids later
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
Do not make the first cut depend on prompt parsing or transcript scraping.
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
### 3. Keep the first semantic backend small and local
2026-04-23 22:01:17 +01:00
2026-04-24 02:45:02 +01:00
The first semantic backend should be workspace-local BM25 chunk retrieval built at query time over the tracked source corpus.
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
Requirements:
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
- keep chunk text line-anchored and path-aware
2026-04-24 02:45:02 +01:00
- keep the implementation bounded enough to understand in one sitting
- track retrieval/index freshness metadata explicitly in typed state
- do not introduce a monolithic persistent blob just to feel sophisticated
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
If the first semantic backend needs to be intentionally narrow, that is fine. A small honest subsystem beats a magical blob with terrible write behavior.
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
### 4. Add one additive app-server query surface
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-24 00:41:16 +01:00
- `vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs`
- `vendor/codex/codex-rs/app-server/src/codex_message_processor.rs`
- `vendor/codex/codex-rs/app-server/README.md`
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
Add one typed method for retrieval, tentatively:
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
- `thread/epiphany/retrieve`
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
Suggested request fields:
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
- `threadId`
- `query`
- optional `cwd`
- optional `modes` or `preferSemantic`
- optional `limit`
- optional `pathPrefixes`
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
Suggested response fields:
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
- `query`
- `indexSummary`
- `results`
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
Keep it additive and read-only. No write/update/index-control methods yet unless they turn out to be mechanically unavoidable.
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
### 5. Reuse existing exact-search substrate where practical
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
Codex already has fuzzy/exact-ish repo search substrate. Reuse what is useful instead of building a second exact-search toy from scratch.
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
But do not confuse that with the whole answer. Phase 4 exists because exact file search alone is not enough.
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
### 6. Test the machine, not just the types
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
Add tests for:
2026-04-23 23:28:10 +01:00
2026-04-24 00:41:16 +01:00
1. protocol serde for the new retrieval request/response shapes
2. core ranking/merging behavior for mixed exact + semantic results
3. app-server handling for the new request
4. retrieval metadata inclusion in `EpiphanyThreadState`
5. a smoke test that proves semantic retrieval can find a concept that exact-name search would miss
2026-04-23 23:28:10 +01:00
2026-04-24 00:41:16 +01:00
## Assumptions
2026-04-23 23:28:10 +01:00
2026-04-24 00:41:16 +01:00
- Phase 4 is still internal/dev-usable only.
- Retrieval should be thread/workspace aware, not a global cross-repo soup.
- The first retrieval slice can be read-only.
- Watcher-driven invalidation belongs later; this slice only needs enough metadata to admit freshness honestly.
2026-04-23 22:01:17 +01:00
## Immediate Next Step After This Plan
2026-04-24 03:22:30 +01:00
Treat the current retrieval baseline as real and only grow it when the next bounded follow-up is ready:
2026-04-23 23:28:10 +01:00
2026-04-24 03:22:30 +01:00
1. treat the current verified-and-landed query-time hybrid retriever as the Phase 4 slice 1 baseline
2026-04-24 02:45:02 +01:00
2. do not add durable retrieval-summary writes from `thread/epiphany/retrieve` without a clean out-of-band rollout/update semantic
3. if a later follow-up is needed, keep it tight:
- retrieval freshness/persistence semantics
- probably a dedicated Epiphany update path
- Qdrant-backed persistent semantic indexing as the preferred backend, with BM25 fallback for no-Qdrant or degraded mode
- not GUI work
- not watcher-driven invalidation
2026-04-23 22:01:17 +01:00
2026-04-24 00:41:16 +01:00
Do not start with GUI. Do not start with automatic graph invalidation. Do not pretend shell transcripts are a retrieval strategy.