From 6805b25b9d6e611fc89e978439bbd59001440110 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 25 Apr 2026 10:30:00 +0100 Subject: [PATCH] Harden direct Epiphany update validation --- notes/epiphany-current-algorithmic-map.md | 28 ++- notes/epiphany-fork-implementation-plan.md | 2 + notes/fresh-workspace-handoff.md | 10 +- state/evidence.jsonl | 2 + state/map.yaml | 3 +- tools/epiphany_phase5_smoke.py | 91 ++++++++ .../codex/codex-rs/core/src/codex_thread.rs | 217 ++++++++++++++++++ 7 files changed, 336 insertions(+), 17 deletions(-) diff --git a/notes/epiphany-current-algorithmic-map.md b/notes/epiphany-current-algorithmic-map.md index 21eb3a22..67eabde7 100644 --- a/notes/epiphany-current-algorithmic-map.md +++ b/notes/epiphany-current-algorithmic-map.md @@ -20,7 +20,7 @@ The spine exists in eleven live paths: - explicit distillation proposals: app-server routes read-only `thread/epiphany/distill` through a loaded-thread handler into `epiphany-core` so one explicit observation can become a patch candidate without mutating state; tool/command/shell/model sources now get typed evidence kinds and bounded salient-output summaries instead of dumping raw output into durable state in [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4173) and [distillation.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/distillation.rs:28). - explicit map/churn proposals: app-server routes read-only `thread/epiphany/propose` through a loaded-thread handler into `epiphany-core` so verified observations with code refs and accepting recent evidence can be selected explicitly or auto-selected as a bounded path cluster, prioritize the strongest selected observation, focus or extend architecture graph nodes, rescue unanchored graph nodes through strict semantic overlap, carry linked dataflow nodes and incident graph edges into the frontier, update churn candidates with match-kind-aware map-delta judgment and pressure, and still avoid mutation until promotion in [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4244) and [proposal.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/proposal.rs:115). - explicit promotion gates: app-server routes `thread/epiphany/promote` through a loaded-thread handler into `epiphany-core` policy evaluation, rejects failed verifier evidence without mutation, applies accepted candidates through the same durable update path, and now treats medium/high/expanded/broadening/semantic churn deltas as needing explicit rationale plus stronger verifier evidence whose kind is token-matched rather than substring-matched in [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4316) and [promotion.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/promotion.rs:33). -- explicit state updates: app-server routes `thread/epiphany/update` through a loaded `CodexThread` update method that mutates live `SessionState`, bumps the revision, and persists an immediate `RolloutItem::EpiphanyState` snapshot in [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4416) and [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:373). +- explicit state updates: app-server routes `thread/epiphany/update` through a loaded `CodexThread` update method that rejects malformed appended observation/evidence graph records, mutates live `SessionState` only after validation, bumps the revision, and persists an immediate `RolloutItem::EpiphanyState` snapshot in [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4436), [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:374), and [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:552). - live state notifications and write responses: app-server declares experimental `thread/epiphany/stateUpdated` and emits it with the updated typed state, typed `source`, event-level `revision`, and typed `changedFields` after successful direct updates and accepted promotions, but not after rejected promotions; direct `thread/epiphany/update` and accepted `thread/epiphany/promote` responses now expose the same revision/change metadata, and accepted promotions always report `Evidence` because verifier evidence is appended even when the patch evidence list is empty, in [common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:1097), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:3992), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4058), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4069), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4379), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4464), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:10509), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:10552). - 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:4046), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4122), [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:438), and [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:456). @@ -128,7 +128,7 @@ This is the same flow in the language Epiphany is supposed to make the model car | Distillation | One explicit observation can be normalized into a typed observation/evidence patch, but not promoted automatically. | The clerk drafts a ledger entry in pencil before anyone is allowed to ink it. | | Proposal | Verified observations with code refs and accepting recent evidence can produce a candidate graph frontier/churn patch without writing it. The caller can provide ids, or the proposal engine can choose a small ready path cluster, then reuse existing map nodes, focus linked context, and report pressure from the actual map delta. | The clerk overlays tracing paper on the old blueprint before drawing a new wall through the plumbing, choosing only the relevant marked pages before measuring how much load the sketch would put on the frame. | | Promotion | A verifier-backed gate can reject a proposal without mutation or send it through the durable update path. | The foreman stamps the pencil draft before the clerk reaches for the red pen. | -| State updates | A loaded thread can accept explicit typed patches that append observations/evidence and replace bounded map/scratch/churn fields. | The clerk finally has the red pen, but still writes only on the ledger page the form allows. | +| State updates | A loaded thread can accept explicit typed patches that append validated observations/evidence and replace bounded map/scratch/churn fields. Malformed appended evidence graph records are rejected before mutation. | The clerk finally has the red pen, but the ledger refuses orphan receipts before the ink touches paper. | | State responses and notifications | Successful direct updates and accepted promotions return the landed revision and changed-field labels to the caller, then publish the updated typed state to app-server clients with source, revision, and changed-field labels saying which control-plane door caused it and which ledger sections changed. | The clerk hands the filing receipt to the person at the counter, then rings the little bell for the room; both say which page number landed and which tabs were touched. | ## Flow 1: State Shape @@ -582,26 +582,30 @@ The app-server handler: 2. reads the current reference turn id when one exists. 3. starts from the live `SessionState.epiphany_state` or a default empty state. 4. enforces `expectedRevision` when supplied. -5. applies typed replacements, prepends new observations/evidence, increments `revision`, and records `last_updated_turn_id`. -6. writes the new state back into live `SessionState`. -7. immediately persists `RolloutItem::EpiphanyState`. -8. flushes the rollout durability barrier. +5. validates appended evidence records have nonempty id/kind/status/summary, do not duplicate ids in the patch, and do not reuse existing durable evidence ids. +6. validates appended observations have nonempty id/summary/source kind/status, do not duplicate ids in the patch, do not reuse existing durable observation ids, and cite at least one evidence id that already exists or is appended in the same patch. +7. rejects invalid append patches before `SessionState`, rollout, response metadata, or notification side effects. +8. applies typed replacements, prepends new observations/evidence, increments `revision`, and records `last_updated_turn_id`. +9. writes the new state back into live `SessionState`. +10. immediately persists `RolloutItem::EpiphanyState`. +11. flushes the rollout durability barrier. The replay helpers now also accept an out-of-band Epiphany snapshot before the first real user turn, so a seed/update written through this path is not lost just because no model turn has happened yet. Code refs: -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4416) -- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4494) +- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4436) +- [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4507) - [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:100) -- [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:373) -- [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:543) +- [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:374) +- [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:552) +- [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:645) - [session/rollout_reconstruction.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/session/rollout_reconstruction.rs:45) - [epiphany-core/src/rollout.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/rollout.rs:18) ### Output -The response contains the updated `epiphanyState`, response-level `revision`, and response-level `changedFields`. The durable side effect is a rollout `EpiphanyState` snapshot. The live side effect is a `thread/epiphany/stateUpdated` notification carrying `source: "update"`, event-level `revision`, typed `changedFields`, and the same updated state to app-server clients. +The response contains the updated `epiphanyState`, response-level `revision`, and response-level `changedFields`. The durable side effect is a rollout `EpiphanyState` snapshot. The live side effect is a `thread/epiphany/stateUpdated` notification carrying `source: "update"`, event-level `revision`, typed `changedFields`, and the same updated state to app-server clients. Invalid append patches return an invalid-request error, leave revision unchanged, and emit no state update notification. ### Invariant @@ -921,7 +925,7 @@ Current tests cover the landed flows at useful seams: - retrieval ranking, fallback, stale manifest detection, and mocked Qdrant/Ollama indexing in `epiphany-core`. - app-server protocol serde for `thread/epiphany/retrieve`, `thread/epiphany/index`, `thread/epiphany/distill`, `thread/epiphany/propose`, `thread/epiphany/promote`, `thread/epiphany/update`, and `thread/epiphany/stateUpdated`. - app-server mapping of core retrieval/index summaries into protocol responses. -- reusable app-server smoke for the richer Phase 5 chain in `tools/epiphany_phase5_smoke.py`, including update/promote response metadata, `thread/epiphany/stateUpdated` notifications with source, revision, changed-field checks, the verifier-only promotion edge where `Evidence` changes because verifier evidence is appended, and an explicit zero-notification assertion for rejected promotions. +- reusable app-server smoke for the richer Phase 5 chain in `tools/epiphany_phase5_smoke.py`, including update/promote response metadata, `thread/epiphany/stateUpdated` notifications with source, revision, changed-field checks, the verifier-only promotion edge where `Evidence` changes because verifier evidence is appended, invalid direct update rejection without mutation or notification, and explicit zero-notification assertions for rejected promotions. Useful commands: diff --git a/notes/epiphany-fork-implementation-plan.md b/notes/epiphany-fork-implementation-plan.md index 45185730..732da857 100644 --- a/notes/epiphany-fork-implementation-plan.md +++ b/notes/epiphany-fork-implementation-plan.md @@ -31,6 +31,7 @@ This note tracks Epiphany as a fork of Codex with an opinionated modeling archit - a first live typed-state notification slice: experimental `thread/epiphany/stateUpdated` fires after successful direct `thread/epiphany/update` and accepted `thread/epiphany/promote`, carrying the updated `epiphanyState`, typed `source`, event-level `revision`, and typed `changedFields` while rejected promotions remain silent and non-mutating; accepted promotions always report `evidence` when verifier evidence is appended - a direct write-response hardening slice: successful `thread/epiphany/update` and accepted `thread/epiphany/promote` responses now include response-level `revision` and `changedFields`, matching the notification metadata without forcing the initiating caller to wait for or diff the live event - a rejected-promotion silence smoke hardening slice: the reusable Phase 5 app-server smoke now asserts rejected `thread/epiphany/promote` calls do not emit `thread/epiphany/stateUpdated`, preserving the "no mutation, no bell" contract +- a direct-update integrity hardening slice: `thread/epiphany/update` now validates appended observation/evidence graph records before mutation, rejects empty/duplicate/reused append ids and missing evidence references, and the reusable smoke asserts invalid direct updates leave revision unchanged with no `thread/epiphany/stateUpdated` notification - current phase: post-Phase-5 live typed state/read-surface hardening The next job is no longer to prove the retriever exists, sketch the persistent follow-up in prose, invent the first red-pen path, build the first observation proposal surface, make promotion notice broken map/churn replacements, ship the first read-only map/churn proposal surface, teach proposal to avoid duplicating already-mapped code surfaces, make proposal frontier focus follow existing graph links, make selected observations evidence-backed with non-haunted churn pressure, rescue unanchored graph nodes with strict semantic matching, let proposal choose a bounded ready observation set when ids are omitted, make proposal pressure understand match kinds, make the distiller summarize noisy source output, make source-output salience prefer final results over generic warnings, make promotion notice risky deltas, make expansion freshness resistant to low-pressure underreporting, prevent substring verifier-kind accidents, prove that richer chain over app-server by hand, add the first live state notification after successful writes, or make that notification say which revision and state sections changed. Those parts are landed or live-smoked. The next job is to use the reusable smoke harness as a guardrail before adding the next smallest source-grounded notification/read/proposal/promotion rule, and to keep `thread/epiphany/retrieve`, `thread/epiphany/distill`, and `thread/epiphany/propose` out of the durable-writer business. @@ -251,6 +252,7 @@ Current bounded shape of that follow-up: - accepted `thread/epiphany/promote` responses now also carry response-level `revision` and `changedFields`; rejected promotion responses omit revision/change metadata and still carry reasons plus no state - the richer app-server smoke now asserts direct update responses/notifications publish revision/changed-fields `1`/`observations,evidence`, verifier-only accepted promotion responses/notifications publish `2`/`observations,evidence`, and accepted graph/churn promotion responses/notifications publish `3`/`graphs,graphFrontier,observations,evidence,churn` - the richer app-server smoke also asserts rejected promotion attempts leave `rejectedPromotionNotificationCount` at `0` +- the richer app-server smoke now also asserts malformed direct `thread/epiphany/update` observation/evidence appends return an invalid-request error, leave revision at `2`, and leave `invalidDirectUpdateNotificationCount` at `0` Follow-up addition now landed after the update surface: diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 3539a101..47349d5d 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -37,6 +37,7 @@ Recent anchor commits: - current slice - fixed accepted promotion notifications so `changedFields` always includes `evidence` when verifier evidence is appended, even if the accepted patch had no patch evidence - current slice - added response-level `revision` and `changedFields` to successful `thread/epiphany/update` and accepted `thread/epiphany/promote` responses - current slice - hardened the reusable Phase 5 smoke so rejected promotions explicitly prove `thread/epiphany/stateUpdated` stays silent +- current slice - hardened direct `thread/epiphany/update` so malformed appended observations/evidence are rejected before mutation and the reusable smoke proves invalid direct updates stay silent Do not trust this note for the exact current HEAD; use `git log --oneline -1` if you need the live commit. @@ -94,12 +95,13 @@ Current verified typed state/promotion layer: - experimental `thread/epiphany/stateUpdated` notifications after successful direct updates and accepted promotions, with typed `source` values of `update` or `promote`, event-level `revision`, and typed `changedFields` - response-level `revision` and `changedFields` on successful `thread/epiphany/update` and accepted `thread/epiphany/promote` - typed patch shape for observations, evidence, objective, subgoals, invariants, graphs, graph frontier/checkpoint, scratch, churn, and mode +- direct `thread/epiphany/update` validation for appended observations/evidence: append records need nonempty identity fields, patch ids cannot duplicate or reuse durable ids, and observations must cite existing or same-patch evidence ids before the durable writer mutates state - deterministic observation/evidence proposal generation in `epiphany-core` - observation distillation now keeps noisy tool/command/shell/model output bounded by selecting salient output lines, prioritizing final result/failure/error/finished lines above generic warnings, and defaulting evidence kind to `tool-output` or `model-output` when the caller did not provide one - deterministic map/churn proposal generation in `epiphany-core`, now with first-pass graph-node reuse by exact code-ref, same-path overlap, or deterministic path-node id before new candidate nodes are created, strict semantic reuse for unanchored architecture nodes, linked frontier focus through graph links and named incident edges, evidence-backed selected observations via accepting `recent_evidence`, selected-observation prioritization, automatic bounded observation selection when ids are omitted, and match-kind-aware churn pressure derived from exact-ref refinement, same-path broadening, deterministic-node reuse, semantic anchoring, or new candidate surfaces - verifier-backed promotion policy evaluation in `epiphany-core`, now rejecting risky churn deltas unless they carry explicit warning rationale and strong verifier evidence kind; graph expansion is risky even if a patch understates `diff_pressure`, and strong verifier kinds are token-matched instead of substring-matched - core `CodexThread.epiphany_update_state(...)` applies the patch to live `SessionState`, bumps revision, persists `RolloutItem::EpiphanyState`, and flushes rollout -- app-server now returns response-level `revision` and `changedFields` from successful direct update and accepted promotion calls, and emits `thread/epiphany/stateUpdated` after the direct update path and after accepted promotion return an updated state; notifications identify their `source`, expose event-level `revision`, list typed `changedFields`, and the richer smoke now explicitly proves rejected promotions still do not mutate state or emit an update notification +- app-server now returns response-level `revision` and `changedFields` from successful direct update and accepted promotion calls, and emits `thread/epiphany/stateUpdated` after the direct update path and after accepted promotion return an updated state; notifications identify their `source`, expose event-level `revision`, list typed `changedFields`, and the richer smoke now explicitly proves rejected promotions plus invalid direct updates still do not mutate state or emit an update notification - replay helpers in both `codex-core` and `epiphany-core` accept an out-of-band Epiphany snapshot before the first real user turn so seed/update snapshots survive resume - retrieval remains read-only and indexing remains the only persistent semantic write path @@ -207,7 +209,7 @@ What is wired right now: - `thread/epiphany/propose` is the first read-only map/churn proposal surface; it uses caller-supplied observation ids or auto-selects a bounded coherent path cluster from verified observations with accepting `recent_evidence` and code refs, focuses existing architecture graph nodes when refs overlap, creates new candidate path nodes only for unmapped surfaces, follows graph links into related architecture/dataflow nodes, marks named incident graph edges active, derives churn pressure from the proposal shape, and returns replacement graphs/frontier/churn for explicit promotion - `thread/epiphany/promote` is the first explicit promotion gate; it rejects failed verifier evidence without mutation and applies accepted candidates through the update path - `thread/epiphany/promote` now has a first richer map/churn safety layer: state replacement patches must carry explicit observations and patch evidence, and subgoal/invariant/graph/frontier/checkpoint/churn structure is validated before the durable update path is called -- `thread/epiphany/update` is the first explicit durable Epiphany state write surface; it rejects empty patches, supports optional revision matching, appends observations/evidence, replaces bounded typed fields, increments state revision, and persists immediately +- `thread/epiphany/update` is the first explicit durable Epiphany state write surface; it rejects empty patches, supports optional revision matching, validates appended observations/evidence, appends valid observations/evidence, replaces bounded typed fields, increments state revision, and persists immediately - `thread/epiphany/stateUpdated` is the first live typed-state notification surface; it fires only after successful `thread/epiphany/update` and accepted `thread/epiphany/promote`, carrying the full updated `epiphanyState`, event-level `revision`, typed `changedFields`, plus `source: "update"` or `source: "promote"`; the direct update/promote responses also return `revision` and `changedFields` - live hydrated `thread.epiphanyState` reads now backfill a lightweight retrieval summary when the thread already has Epiphany state but no persisted retrieval summary yet - basic protocol/core/app-server unit tests were added for the new types and mapping layer @@ -372,7 +374,7 @@ If a future session wakes up from compaction and starts bluffing, this is the pa - proposal churn now distinguishes exact-ref refinements from same-path broadening, deterministic-node reuse, semantic unanchored-node reuse, and new candidate surfaces before setting graph freshness and diff pressure - distillation now summarizes noisy tool/command/shell/model output into salient typed evidence rather than preserving raw output sludge as the summary, and final result/failure/error/finished lines outrank generic warnings unless warning is the only central signal - promotion now rejects medium/high/expanded/broadening/semantic/update churn deltas that lack a warning, carry weak generic verifier evidence, or rely on substring verifier-kind accidents such as `contest` - - richer Phase 5 app-server smoke is now reproducible through `tools/epiphany_phase5_smoke.py`; it verifies `shell-tool` distillation to `tool-output`, read-only proposal, update notification source/revision/changed-fields `update`/1/`observations,evidence`, verifier-only accepted promotion notification source/revision/changed-fields `promote`/2/`observations,evidence`, risky-churn rejection without warning, expanded-low-pressure rejection, substring verifier-kind rejection, weak verifier-kind rejection, accepted promotion only with warning plus strong verifier evidence, and graph/churn promote notification source/revision/changed-fields `promote`/3/`graphs,graphFrontier,observations,evidence,churn` + - richer Phase 5 app-server smoke is now reproducible through `tools/epiphany_phase5_smoke.py`; it verifies `shell-tool` distillation to `tool-output`, read-only proposal, update notification source/revision/changed-fields `update`/1/`observations,evidence`, verifier-only accepted promotion notification source/revision/changed-fields `promote`/2/`observations,evidence`, invalid direct update rejection with unchanged revision and no state update notification, risky-churn rejection without warning, expanded-low-pressure rejection, substring verifier-kind rejection, weak verifier-kind rejection, accepted promotion only with warning plus strong verifier evidence, and graph/churn promote notification source/revision/changed-fields `promote`/3/`graphs,graphFrontier,observations,evidence,churn` - the Epiphany algorithmic map has been semantically audited flow-by-flow against the cited code; stale line anchors were fixed, and the current typed spine still describes a coherent machine - the next bounded follow-up should use the richer smoke harness as a guardrail before the next source-grounded proposal/promotion hardening slice - There is now a first live `thread/epiphany/stateUpdated` notification seam for successful update/promote writes; it includes source, revision, and changed-field metadata, but there is still no broader watcher/job/specialist event stream. @@ -522,4 +524,4 @@ cmd /c "\"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxi The repo is in a good state. -Phase 1, Phase 2, the minimal Phase 3 typed read surface, Phase 4 retrieval/indexing/core-extraction, and the current Phase 5 distill/propose/promote/update baseline are landed and verified. `vendor/codex` is first-class in the parent repo now, with the heavier Epiphany organs living in `epiphany-core`. Successful direct updates and accepted promotions now return response-level revision/changed-field metadata and emit experimental `thread/epiphany/stateUpdated` notifications carrying the updated typed state, source labels, event-level revision, and typed changed fields; accepted promotion responses/notifications include `evidence` whenever verifier evidence is appended, even when patch evidence was empty. Read-only distillation now summarizes noisy tool/model output into typed evidence and ranks final result/error/finished lines above generic warnings, read-only proposal can auto-select a bounded evidence-backed observation cluster and report match-kind-aware map-delta pressure, promotion rejects risky deltas without warning plus strong verifier evidence, expansion freshness cannot bypass warning requirements by claiming low pressure, and verifier kinds are token-matched so `contest` does not pass as `test`. The current Epiphany algorithmic map has been source-audited against the code flow it describes. The richer Phase 5 chain is now live-smoked through app-server by `tools/epiphany_phase5_smoke.py`, including update response/notification revision/changed-fields `1`/`observations,evidence`, verifier-only accepted promotion response/notification changed-fields `2`/`observations,evidence`, expanded-low-pressure and substring-verifier rejection checks, explicit rejected-promotion notification silence with `rejectedPromotionNotificationCount: 0`, accepted graph/churn promotion, and promote response/notification revision/changed-fields `3`/`graphs,graphFrontier,observations,evidence,churn`. The next clean move is the next bounded live typed-state/read-surface hardening slice, with that smoke harness as a guardrail; not GUI paint, watcher magic, or re-proving retrieval. Pre-compaction persistence is now an explicit design rule, not a lucky habit. +Phase 1, Phase 2, the minimal Phase 3 typed read surface, Phase 4 retrieval/indexing/core-extraction, and the current Phase 5 distill/propose/promote/update baseline are landed and verified. `vendor/codex` is first-class in the parent repo now, with the heavier Epiphany organs living in `epiphany-core`. Successful direct updates and accepted promotions now return response-level revision/changed-field metadata and emit experimental `thread/epiphany/stateUpdated` notifications carrying the updated typed state, source labels, event-level revision, and typed changed fields; accepted promotion responses/notifications include `evidence` whenever verifier evidence is appended, even when patch evidence was empty. Direct updates now reject malformed appended observations/evidence before mutation, including missing evidence references, duplicate append ids, and durable id reuse. Read-only distillation now summarizes noisy tool/model output into typed evidence and ranks final result/error/finished lines above generic warnings, read-only proposal can auto-select a bounded evidence-backed observation cluster and report match-kind-aware map-delta pressure, promotion rejects risky deltas without warning plus strong verifier evidence, expansion freshness cannot bypass warning requirements by claiming low pressure, and verifier kinds are token-matched so `contest` does not pass as `test`. The current Epiphany algorithmic map has been source-audited against the code flow it describes. The richer Phase 5 chain is now live-smoked through app-server by `tools/epiphany_phase5_smoke.py`, including update response/notification revision/changed-fields `1`/`observations,evidence`, verifier-only accepted promotion response/notification changed-fields `2`/`observations,evidence`, invalid direct update rejection with `invalidDirectUpdateNotificationCount: 0` and unchanged revision `2`, expanded-low-pressure and substring-verifier rejection checks, explicit rejected-promotion notification silence with `rejectedPromotionNotificationCount: 0`, accepted graph/churn promotion, and promote response/notification revision/changed-fields `3`/`graphs,graphFrontier,observations,evidence,churn`. The next clean move is the next bounded live typed-state/read-surface hardening slice, with that smoke harness as a guardrail; not GUI paint, watcher magic, or re-proving retrieval. Pre-compaction persistence is now an explicit design rule, not a lucky habit. diff --git a/state/evidence.jsonl b/state/evidence.jsonl index eeed9ac0..414ee9f9 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -146,3 +146,5 @@ {"ts": "2026-04-25T07:59:14+00:00", "type": "verification", "status": "ok", "note": "Verified direct write-response metadata hardening with py_compile tools/epiphany_phase5_smoke.py, cargo fmt -p codex-app-server-protocol -p codex-app-server, cargo test -p codex-app-server-protocol --lib thread_epiphany, cargo test -p codex-app-server --lib epiphany_promote_changed_fields_reports_appended_verifier_evidence, cargo test -p codex-app-server --lib map_epiphany_, cargo run -p codex-app-server-protocol --bin write_schema_fixtures, full cargo test -p codex-app-server-protocol, detached app-server rebuild exit 0, and tools/epiphany_phase5_smoke.py. Smoke observed matching response/notification revisions and changedFields for update, verifier-only promote, and graph/churn promote."} {"ts": "2026-04-25T08:13:36+00:00", "type": "verification", "status": "ok", "note": "Verified Compact-Rehydrate-Reorient-Continue continuity after response-level write metadata slice. Branch main is clean/synced at 4ff1d3c; state/map.yaml, fresh-workspace-handoff, Epiphany algorithmic map, implementation plan, git log, and evidence tail agree that successful update/promote responses and stateUpdated notifications now expose revision/changedFields, while automatic CRRC coordination remains a documented non-flow. Next action remains the next bounded live typed-state/read-surface hardening slice; keep retrieve/distill/propose read-only and accepted writes routed through update/promote."} {"ts": "2026-04-25T08:23:35+00:00", "type": "verification", "status": "ok", "note": "Hardened Phase 5 smoke coverage for rejected promotion silence. The reusable app-server smoke now asserts rejected thread/epiphany/promote calls emit no thread/epiphany/stateUpdated notifications and records rejectedPromotionNotificationCount: 0, after reverting an Aetheria-example-only retrieval filter that was not part of the active task."} +{"ts": "2026-04-25T09:29:33+00:00", "type": "implementation", "status": "ok", "note": "Hardened direct thread/epiphany/update integrity validation in codex-core: appended evidence now requires nonempty id/kind/status/summary, patch ids cannot duplicate or reuse durable ids, and appended observations must cite existing or same-patch evidence before mutation."} +{"ts": "2026-04-25T09:29:33+00:00", "type": "verification", "status": "ok", "note": "Verified direct-update integrity slice: py_compile tools/epiphany_phase5_smoke.py passed; cargo test -p codex-core --lib epiphany_update passed 4 tests; rebuilt codex-app-server; tools/epiphany_phase5_smoke.py passed with invalidDirectUpdateNotificationCount 0 and invalidDirectUpdateRevisionAfterReject 2."} diff --git a/state/map.yaml b/state/map.yaml index a2ee626e..4b5b92ba 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -112,6 +112,7 @@ accepted_design: - harden accepted-promotion notification accuracy: because accepted `thread/epiphany/promote` always appends verifier evidence to durable state, promotion notifications must include `evidence` in `changedFields` even when the submitted patch evidence list was empty - harden direct write responses: successful `thread/epiphany/update` and accepted `thread/epiphany/promote` responses now include response-level `revision` and `changedFields`, matching the live notification metadata for initiating callers - harden rejected-promotion notification silence: the richer Phase 5 app-server smoke now asserts rejected `thread/epiphany/promote` calls do not emit `thread/epiphany/stateUpdated` + - harden direct update integrity: `thread/epiphany/update` now rejects malformed appended observations/evidence before durable persistence, including empty append record fields, duplicate append ids, durable id reuse, and observations that cite missing evidence ids; invalid direct updates leave revision unchanged and emit no state update notification rejected_paths: - name: pinned_map_only @@ -128,5 +129,5 @@ rejected_paths: reason: audited candidates were either terminal-only, stale/aspirational, or incoherent wrappers; the comparison clones were removed from vendor to avoid building on untrusted drift current_status: - summary: Workspace initialized with protocol files, typed state, handoff notes, architecture maps, and a rolling implementation plan against vendored Codex. Phase 1 durable state, Phase 2 prompt integration, the minimal Phase 3 typed read surface, and Phase 4 retrieval/indexing/core-extraction are landed on `main`. Phase 5 semantic distillation/promotion/proposal is now active and chewed enough for the first live typed-state stream seam: the current baseline includes explicit Qdrant indexing with BM25 fallback, typed `thread/epiphany/update`, read-only `thread/epiphany/distill`, read-only `thread/epiphany/propose`, verifier-backed `thread/epiphany/promote`, response-level `revision` and `changedFields` on successful direct updates and accepted promotions, experimental `thread/epiphany/stateUpdated` notifications after successful direct updates and accepted promotions with typed `source` values of `update` or `promote`, event-level `revision`, typed `changedFields`, structural map/churn promotion validation, source-output-aware distillation with result/error/finished lines prioritized over generic warnings, graph-node reuse, linked frontier focus, evidence-backed proposal selection, selected-observation prioritization, strict unanchored-node semantic reuse, automatic bounded observation selection, match-kind-aware map-delta churn pressure, risky-delta promotion policy in `epiphany-core`, expansion-freshness promotion hardening so new map surfaces cannot bypass warning requirements by claiming low pressure, token-aware verifier-kind matching so substring accidents cannot satisfy strong verifier evidence, a reusable richer Phase 5 app-server smoke harness, and thin vendored Codex host seams. Promotion responses and notifications now include `evidence` in `changedFields` whenever accepted promotion appends verifier evidence, even if the patch evidence list was empty. The richer smoke now verifies source-output distillation, read-only proposal, update response/notification revision/changed-fields `1`/`observations,evidence`, verifier-only accepted promotion response/notification `2`/`observations,evidence`, risky-delta rejection, expanded-low-pressure rejection, weak-verifier rejection, substring-verifier rejection, rejected-promotion notification silence with `rejectedPromotionNotificationCount: 0`, accepted graph/churn promotion, and graph/churn promote response/notification revision/changed-fields `3`/`graphs,graphFrontier,observations,evidence,churn` through the app-server seam. The Windows app-server stack-pressure regression was narrowed to test-thread stack size; repo-local Cargo config sets `RUST_MIN_STACK=67108864`, and boxed-future request-dispatch experiments were removed after config-only verification passed. The repo also has source-available/commercial licensing plus a CLA gate for external contributions. + summary: Workspace initialized with protocol files, typed state, handoff notes, architecture maps, and a rolling implementation plan against vendored Codex. Phase 1 durable state, Phase 2 prompt integration, the minimal Phase 3 typed read surface, and Phase 4 retrieval/indexing/core-extraction are landed on `main`. Phase 5 semantic distillation/promotion/proposal is now active and chewed enough for the first live typed-state stream seam: the current baseline includes explicit Qdrant indexing with BM25 fallback, typed `thread/epiphany/update`, read-only `thread/epiphany/distill`, read-only `thread/epiphany/propose`, verifier-backed `thread/epiphany/promote`, response-level `revision` and `changedFields` on successful direct updates and accepted promotions, experimental `thread/epiphany/stateUpdated` notifications after successful direct updates and accepted promotions with typed `source` values of `update` or `promote`, event-level `revision`, typed `changedFields`, structural map/churn promotion validation, direct-update observation/evidence integrity validation, source-output-aware distillation with result/error/finished lines prioritized over generic warnings, graph-node reuse, linked frontier focus, evidence-backed proposal selection, selected-observation prioritization, strict unanchored-node semantic reuse, automatic bounded observation selection, match-kind-aware map-delta churn pressure, risky-delta promotion policy in `epiphany-core`, expansion-freshness promotion hardening so new map surfaces cannot bypass warning requirements by claiming low pressure, token-aware verifier-kind matching so substring accidents cannot satisfy strong verifier evidence, a reusable richer Phase 5 app-server smoke harness, and thin vendored Codex host seams. Promotion responses and notifications now include `evidence` in `changedFields` whenever accepted promotion appends verifier evidence, even if the patch evidence list was empty. The richer smoke now verifies source-output distillation, read-only proposal, update response/notification revision/changed-fields `1`/`observations,evidence`, verifier-only accepted promotion response/notification `2`/`observations,evidence`, invalid direct update rejection with `invalidDirectUpdateNotificationCount: 0` and unchanged revision `2`, risky-delta rejection, expanded-low-pressure rejection, weak-verifier rejection, substring-verifier rejection, rejected-promotion notification silence with `rejectedPromotionNotificationCount: 0`, accepted graph/churn promotion, and graph/churn promote response/notification revision/changed-fields `3`/`graphs,graphFrontier,observations,evidence,churn` through the app-server seam. The Windows app-server stack-pressure regression was narrowed to test-thread stack size; repo-local Cargo config sets `RUST_MIN_STACK=67108864`, and boxed-future request-dispatch experiments were removed after config-only verification passed. The repo also has source-available/commercial licensing plus a CLA gate for external contributions. next_action: Continue the next bounded live typed-state/read-surface hardening slice from the now-notified update/promote seam; keep retrieval/distillation/proposal read-only, keep accepted writes routed through promotion/update, and avoid GUI, watcher, or specialist-agent machinery. diff --git a/tools/epiphany_phase5_smoke.py b/tools/epiphany_phase5_smoke.py index c7f71269..26489806 100644 --- a/tools/epiphany_phase5_smoke.py +++ b/tools/epiphany_phase5_smoke.py @@ -108,6 +108,24 @@ class AppServerClient: return None return self._wait_for(request_id) + def send_expect_error( + self, + method: str, + params: dict[str, Any] | None = None, + ) -> dict[str, Any]: + msg: dict[str, Any] = {"method": method} + request_id = self.next_id + self.next_id += 1 + msg["id"] = request_id + if params is not None: + msg["params"] = params + + self._record("sent", msg) + assert self.proc is not None and self.proc.stdin is not None + self.proc.stdin.write(json.dumps(msg, separators=(",", ":")) + "\n") + self.proc.stdin.flush() + return self._wait_for_error(request_id) + def _wait_for(self, request_id: int, timeout: float = 45.0) -> dict[str, Any]: assert self.proc is not None deadline = time.time() + timeout @@ -130,6 +148,26 @@ class AppServerClient: return result raise TimeoutError(f"timed out waiting for response {request_id}") + def _wait_for_error(self, request_id: int, timeout: float = 45.0) -> dict[str, Any]: + assert self.proc is not None + deadline = time.time() + timeout + while time.time() < deadline: + if self.proc.poll() is not None: + raise RuntimeError( + f"app-server exited with {self.proc.returncode} before response {request_id}" + ) + try: + msg = self.messages.get(timeout=0.5) + except queue.Empty: + continue + if msg.get("id") != request_id: + continue + error = msg.get("error") + if not isinstance(error, dict): + raise RuntimeError(f"request {request_id} unexpectedly succeeded: {msg!r}") + return error + raise TimeoutError(f"timed out waiting for error response {request_id}") + def wait_for_notification( self, method: str, @@ -388,6 +426,54 @@ def run_smoke(args: argparse.Namespace) -> dict[str, Any]: "verifier-only promote notification should include appended verifier evidence", ) + invalid_direct_update_notification_start = len(client.notifications) + invalid_direct_update_error = client.send_expect_error( + "thread/epiphany/update", + { + "threadId": thread_id, + "expectedRevision": 2, + "patch": { + "observations": [ + { + "id": "obs-phase5-invalid-direct-update", + "summary": "Invalid direct update should not bypass evidence integrity", + "source_kind": "smoke", + "status": "ok", + "evidence_ids": ["ev-phase5-missing-direct-update"], + } + ] + }, + }, + ) + invalid_direct_update_message = str(invalid_direct_update_error.get("message", "")) + require( + "invalid epiphany update patch" in invalid_direct_update_message, + "invalid direct update should return update validation error", + ) + require( + "cites missing evidence id" in invalid_direct_update_message, + "invalid direct update should name the missing evidence id", + ) + client.require_no_notification( + "thread/epiphany/stateUpdated", + start_index=invalid_direct_update_notification_start, + ) + invalid_direct_update_notification_count = client.count_notifications( + "thread/epiphany/stateUpdated", + start_index=invalid_direct_update_notification_start, + ) + read_after_invalid_direct_update = client.send( + "thread/read", {"threadId": thread_id, "includeTurns": False} + ) + assert read_after_invalid_direct_update is not None + require( + read_after_invalid_direct_update["thread"] + .get("epiphanyState", {}) + .get("revision") + == 2, + "invalid direct update should not mutate state", + ) + propose = client.send("thread/epiphany/propose", {"threadId": thread_id}) assert propose is not None proposal_patch = propose["patch"] @@ -624,6 +710,11 @@ def run_smoke(args: argparse.Namespace) -> dict[str, Any]: "verifierOnlyPromoteChangedFields": verifier_only_notification["params"][ "changedFields" ], + "invalidDirectUpdateMessage": invalid_direct_update_message, + "invalidDirectUpdateNotificationCount": invalid_direct_update_notification_count, + "invalidDirectUpdateRevisionAfterReject": read_after_invalid_direct_update["thread"] + .get("epiphanyState", {}) + .get("revision"), "proposalExpectedRevision": propose["expectedRevision"], "proposalObservationId": proposal_patch["observations"][0]["id"], "proposalChurn": proposal_patch["churn"], diff --git a/vendor/codex/codex-rs/core/src/codex_thread.rs b/vendor/codex/codex-rs/core/src/codex_thread.rs index a38fa2a0..1da77d2f 100644 --- a/vendor/codex/codex-rs/core/src/codex_thread.rs +++ b/vendor/codex/codex-rs/core/src/codex_thread.rs @@ -50,6 +50,7 @@ use codex_protocol::user_input::UserInput; use codex_utils_absolute_path::AbsolutePathBuf; use rmcp::model::ReadResourceRequestParams; use std::collections::HashMap; +use std::collections::HashSet; use std::path::PathBuf; use tokio::sync::Mutex; use tokio::sync::watch; @@ -401,6 +402,14 @@ impl CodexThread { ))); } + let validation_errors = epiphany_state_update_validation_errors(&next_state, &update); + if !validation_errors.is_empty() { + return Err(CodexErr::InvalidRequest(format!( + "invalid epiphany update patch: {}", + validation_errors.join("; ") + ))); + } + apply_epiphany_state_update(&mut next_state, update, reference_turn_id.clone()); self.codex .session @@ -540,6 +549,99 @@ impl CodexThread { } } +fn epiphany_state_update_validation_errors( + state: &EpiphanyThreadState, + update: &EpiphanyStateUpdate, +) -> Vec { + let mut errors = Vec::new(); + let mut known_evidence_ids: HashSet<&str> = state + .recent_evidence + .iter() + .filter_map(|evidence| nonempty_id(&evidence.id)) + .collect(); + let existing_evidence_ids = known_evidence_ids.clone(); + let existing_observation_ids: HashSet<&str> = state + .observations + .iter() + .filter_map(|observation| nonempty_id(&observation.id)) + .collect(); + + let mut patch_evidence_ids = HashSet::new(); + for evidence in &update.evidence { + require_nonempty_update(&evidence.id, "patch.evidence.id", &mut errors); + require_nonempty_update(&evidence.kind, "patch.evidence.kind", &mut errors); + require_nonempty_update(&evidence.status, "patch.evidence.status", &mut errors); + require_nonempty_update(&evidence.summary, "patch.evidence.summary", &mut errors); + if !evidence.id.is_empty() && !patch_evidence_ids.insert(evidence.id.as_str()) { + errors.push(format!("duplicate evidence id {:?}", evidence.id)); + } + if existing_evidence_ids.contains(evidence.id.as_str()) { + errors.push(format!( + "evidence id {:?} already exists in Epiphany state", + evidence.id + )); + } + if let Some(id) = nonempty_id(&evidence.id) { + known_evidence_ids.insert(id); + } + } + + let mut patch_observation_ids = HashSet::new(); + for observation in &update.observations { + require_nonempty_update(&observation.id, "patch.observations.id", &mut errors); + require_nonempty_update( + &observation.summary, + "patch.observations.summary", + &mut errors, + ); + require_nonempty_update( + &observation.source_kind, + "patch.observations.source_kind", + &mut errors, + ); + require_nonempty_update( + &observation.status, + "patch.observations.status", + &mut errors, + ); + if !observation.id.is_empty() && !patch_observation_ids.insert(observation.id.as_str()) { + errors.push(format!("duplicate observation id {:?}", observation.id)); + } + if existing_observation_ids.contains(observation.id.as_str()) { + errors.push(format!( + "observation id {:?} already exists in Epiphany state", + observation.id + )); + } + if observation.evidence_ids.is_empty() { + errors.push(format!( + "observation {:?} must cite at least one evidence id", + observation.id + )); + } + for evidence_id in &observation.evidence_ids { + if !known_evidence_ids.contains(evidence_id.as_str()) { + errors.push(format!( + "observation {:?} cites missing evidence id {:?}", + observation.id, evidence_id + )); + } + } + } + + errors +} + +fn nonempty_id(id: &str) -> Option<&str> { + if id.is_empty() { None } else { Some(id) } +} + +fn require_nonempty_update(value: &str, label: &str, errors: &mut Vec) { + if value.trim().is_empty() { + errors.push(format!("{label} must not be empty")); + } +} + fn apply_epiphany_state_update( state: &mut EpiphanyThreadState, update: EpiphanyStateUpdate, @@ -594,6 +696,27 @@ fn prepend_recent(items: &mut Vec, mut new_items: Vec) { mod epiphany_update_tests { use super::*; + fn evidence(id: &str) -> EpiphanyEvidenceRecord { + EpiphanyEvidenceRecord { + id: id.to_string(), + kind: "verification".to_string(), + status: "ok".to_string(), + summary: "Evidence summary".to_string(), + code_refs: Vec::new(), + } + } + + fn observation(id: &str, evidence_ids: Vec<&str>) -> EpiphanyObservation { + EpiphanyObservation { + id: id.to_string(), + summary: "Observation summary".to_string(), + source_kind: "smoke".to_string(), + status: "ok".to_string(), + code_refs: Vec::new(), + evidence_ids: evidence_ids.into_iter().map(str::to_string).collect(), + } + } + #[test] fn apply_epiphany_state_update_replaces_typed_fields_and_prepends_evidence() { let mut state = EpiphanyThreadState { @@ -642,6 +765,100 @@ mod epiphany_update_tests { Some("low") ); } + + #[test] + fn validate_epiphany_state_update_accepts_observation_linked_to_existing_evidence() { + let state = EpiphanyThreadState { + recent_evidence: vec![evidence("ev-existing")], + ..Default::default() + }; + let update = EpiphanyStateUpdate { + observations: vec![observation("obs-new", vec!["ev-existing"])], + ..Default::default() + }; + + assert!(epiphany_state_update_validation_errors(&state, &update).is_empty()); + } + + #[test] + fn validate_epiphany_state_update_rejects_observation_with_missing_evidence() { + let update = EpiphanyStateUpdate { + observations: vec![observation("obs-new", vec!["ev-missing"])], + ..Default::default() + }; + + let errors = + epiphany_state_update_validation_errors(&EpiphanyThreadState::default(), &update); + + assert!( + errors + .iter() + .any(|error| error.contains("cites missing evidence id")) + ); + } + + #[test] + fn validate_epiphany_state_update_rejects_empty_and_duplicate_append_ids() { + let state = EpiphanyThreadState { + observations: vec![observation("obs-existing", vec!["ev-existing"])], + recent_evidence: vec![evidence("ev-existing")], + ..Default::default() + }; + let update = EpiphanyStateUpdate { + observations: vec![ + observation("obs-existing", vec!["ev-new"]), + observation("obs-dup", vec!["ev-new"]), + observation("obs-dup", vec!["ev-new"]), + EpiphanyObservation { + id: String::new(), + ..observation("unused", vec!["ev-new"]) + }, + ], + evidence: vec![ + evidence("ev-existing"), + evidence("ev-new"), + evidence("ev-new"), + EpiphanyEvidenceRecord { + id: String::new(), + ..evidence("unused") + }, + ], + ..Default::default() + }; + + let errors = epiphany_state_update_validation_errors(&state, &update); + + assert!( + errors + .iter() + .any(|error| error.contains("evidence id \"ev-existing\" already exists")) + ); + assert!( + errors + .iter() + .any(|error| error.contains("duplicate evidence id \"ev-new\"")) + ); + assert!( + errors + .iter() + .any(|error| error.contains("observation id \"obs-existing\" already exists")) + ); + assert!( + errors + .iter() + .any(|error| error.contains("duplicate observation id \"obs-dup\"")) + ); + assert!( + errors + .iter() + .any(|error| error.contains("patch.evidence.id must not be empty")) + ); + assert!( + errors + .iter() + .any(|error| error.contains("patch.observations.id must not be empty")) + ); + } } fn pending_message_input_item(message: &ResponseItem) -> CodexResult {