diff --git a/notes/epiphany-core-harness-surfaces.md b/notes/epiphany-core-harness-surfaces.md index 30b18f39..e6907741 100644 --- a/notes/epiphany-core-harness-surfaces.md +++ b/notes/epiphany-core-harness-surfaces.md @@ -46,7 +46,7 @@ The rule is: | `thread/epiphany/propose` | read-only proposal | landed | Drafts graph/frontier/churn candidates from verified evidence-backed observations. | | `thread/epiphany/promote` | verifier gate | landed | Rejects or applies candidates through the durable update path. | | `thread/epiphany/stateUpdated` | notification | landed | Emits updated projected state, source, revision, and changed fields after successful update/promote writes. | -| `thread/epiphany/scene` | read-only reflection | landed | Compact client scene derived from authoritative Epiphany state. | +| `thread/epiphany/scene` | read-only reflection | landed, live-smoked | Compact client scene derived from authoritative Epiphany state. | ## Write Authority diff --git a/notes/epiphany-current-algorithmic-map.md b/notes/epiphany-current-algorithmic-map.md index 9e30d853..39f13d02 100644 --- a/notes/epiphany-current-algorithmic-map.md +++ b/notes/epiphany-current-algorithmic-map.md @@ -947,7 +947,7 @@ The app-server handler: 4. summarizes invariant status counts with deterministic status ordering. 5. summarizes architecture/dataflow graph counts, active frontier ids, dirty paths, open question/gap counts, and checkpoint identity. 6. summarizes retrieval status, semantic availability, index revision, shard count, dirty-path count, and indexed file/chunk counts. -7. includes bounded latest observation/evidence summaries. +7. includes bounded latest observation/evidence summaries in newest-first order, matching the durable state's recent-record ordering. 8. reflects churn pressure/warning fields. 9. reports available actions only when the thread is loaded, adding `propose` and `promote` only when state exists. @@ -988,7 +988,7 @@ stored Epiphany state -> successful writes emit thread/epiphany/stateUpdated ``` -The current remaining missing organ is not the red pen, not the first chewing motion, not the first state-change bell, and no longer the first client-shaped scene. Those exist. Proposal now has the first bits of map memory, focus, and selection hygiene: it can auto-select a bounded evidence-backed observation cluster when ids are omitted, requires accepting recent evidence behind selected observations, prioritizes stronger selected observations for proposal wording, reuses existing architecture nodes by concrete code-ref/path/id checks before creating new path nodes, can rescue unanchored graph nodes through strict unique semantic overlap, follows graph links and incident edges into the frontier, and reports match-kind-aware churn pressure from the actual proposal shape. Distillation now also has the first source-output-aware teeth for tool/model summaries. Promotion now notices risky deltas instead of just checking the shape of the envelope, treats graph expansion as risky even if the patch tries to mumble "low pressure" while dragging a new wall into the blueprint, and token-matches strong verifier kinds so `contest` cannot sneak past as `test`. Successful update/promote writes now emit `thread/epiphany/stateUpdated` with `source: "update"` or `source: "promote"`, event-level revision, and typed changed fields so clients no longer need to poll blindly, infer the cause from timing, or diff the whole state to know which top-level sections moved. The scene surface gives clients a compact read-only view without making the GUI/client authoritative. Richer app-server smoke coverage now exists in `tools/epiphany_phase5_smoke.py`; the remaining missing organs are live scene smoke, job/progress reflection, watcher/freshness inputs, and eventually role-scoped specialist ownership without silently auto-promoting anything. +The current remaining missing organ is not the red pen, not the first chewing motion, not the first state-change bell, and no longer the first client-shaped scene. Those exist. Proposal now has the first bits of map memory, focus, and selection hygiene: it can auto-select a bounded evidence-backed observation cluster when ids are omitted, requires accepting recent evidence behind selected observations, prioritizes stronger selected observations for proposal wording, reuses existing architecture nodes by concrete code-ref/path/id checks before creating new path nodes, can rescue unanchored graph nodes through strict unique semantic overlap, follows graph links and incident edges into the frontier, and reports match-kind-aware churn pressure from the actual proposal shape. Distillation now also has the first source-output-aware teeth for tool/model summaries. Promotion now notices risky deltas instead of just checking the shape of the envelope, treats graph expansion as risky even if the patch tries to mumble "low pressure" while dragging a new wall into the blueprint, and token-matches strong verifier kinds so `contest` cannot sneak past as `test`. Successful update/promote writes now emit `thread/epiphany/stateUpdated` with `source: "update"` or `source: "promote"`, event-level revision, and typed changed fields so clients no longer need to poll blindly, infer the cause from timing, or diff the whole state to know which top-level sections moved. The scene surface gives clients a compact read-only view without making the GUI/client authoritative, and `tools/epiphany_phase6_scene_smoke.py` now proves the live app-server scene path reports missing/ready state, live source, available actions, retrieval backfill, newest-first bounded records, and no scene-triggered state notification. Richer Phase 5 app-server smoke coverage still exists in `tools/epiphany_phase5_smoke.py`; the remaining missing organs are job/progress reflection, watcher/freshness inputs, and eventually role-scoped specialist ownership without silently auto-promoting anything. ```text model/tool observations @@ -1020,6 +1020,7 @@ Current tests cover the landed flows at useful seams: - 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, retrieval-summary presence in successful write response/notification states, the verifier-only promotion edge where `Evidence` changes because verifier evidence is appended, invalid direct observation/evidence and replacement update rejection without mutation or notification, and explicit zero-notification assertions for rejected promotions. +- live app-server smoke for the first Phase 6 scene boundary in `tools/epiphany_phase6_scene_smoke.py`, including missing-state bootstrap actions, ready live scene actions, retrieval-summary backfill, newest-first bounded observation/evidence records, and zero scene-triggered state update notifications. Useful commands: @@ -1029,4 +1030,5 @@ $env:CARGO_TARGET_DIR='C:\Users\Meta\.cargo-target-codex'; cargo test -p codex-c $env:CARGO_TARGET_DIR='C:\Users\Meta\.cargo-target-codex'; cargo test -p codex-app-server-protocol --lib thread_epiphany_ $env:CARGO_TARGET_DIR='C:\Users\Meta\.cargo-target-codex'; cargo test -p codex-app-server --lib map_epiphany_ & 'C:\Users\Meta\.cache\codex-runtimes\codex-primary-runtime\dependencies\python\python.exe' '.\tools\epiphany_phase5_smoke.py' +& 'C:\Users\Meta\.cache\codex-runtimes\codex-primary-runtime\dependencies\python\python.exe' '.\tools\epiphany_phase6_scene_smoke.py' ``` diff --git a/notes/epiphany-fork-implementation-plan.md b/notes/epiphany-fork-implementation-plan.md index d1ea0940..40d3d99f 100644 --- a/notes/epiphany-fork-implementation-plan.md +++ b/notes/epiphany-fork-implementation-plan.md @@ -56,6 +56,7 @@ The landed machine now has: - proposal and promotion rules that reduce map/churn Jenga pressure - reusable Phase 5 app-server smoke coverage in `tools/epiphany_phase5_smoke.py` - a first Phase 6 read-only reflection surface through `thread/epiphany/scene` +- live Phase 6 scene app-server smoke coverage in `tools/epiphany_phase6_scene_smoke.py` The current phase is Phase 6: reflection boundary and observable harness state. @@ -104,7 +105,6 @@ and notify typed state. It can. The next unknowns are: -- whether `thread/epiphany/scene` is sufficient as the first client-facing reflection shape - what minimal job/progress surface is needed for indexing, remap, verification, and future specialist work - how to expose long-running work without making the GUI authoritative - when watcher-driven invalidation becomes necessary instead of merely tempting @@ -117,11 +117,10 @@ Phase 6 should grow observable harness state outward from the typed spine. Useful candidates: -1. Live-smoke `thread/epiphany/scene` through app-server. -2. Add a minimal read-only job/progress surface for indexing, remap, and verification work. -3. Add targeted scene fields only when a client or smoke exposes a real gap. -4. Keep the scene derived from authoritative Epiphany state. -5. Keep long-running work observable through typed state or notifications, not transcript inference. +1. Add a minimal read-only job/progress surface for indexing, remap, and verification work. +2. Add targeted scene fields only when a client or smoke exposes a real gap. +3. Keep the scene derived from authoritative Epiphany state. +4. Keep long-running work observable through typed state or notifications, not transcript inference. 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 @@ -152,6 +151,12 @@ Before modifying Phase 5 control-plane behavior, run: & 'C:\Users\Meta\.cache\codex-runtimes\codex-primary-runtime\dependencies\python\python.exe' '.\tools\epiphany_phase5_smoke.py' ``` +Before modifying scene projection behavior, run: + +```powershell +& 'C:\Users\Meta\.cache\codex-runtimes\codex-primary-runtime\dependencies\python\python.exe' '.\tools\epiphany_phase6_scene_smoke.py' +``` + For app-server protocol changes, expect to run the relevant protocol tests, regenerate stable schema fixtures when needed, and verify the generated tree is intentional. diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 1af1d2a4..d6fd3867 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -28,7 +28,7 @@ Do not trust this file for the exact live HEAD. Always check git. - Do not copy exact branch or HEAD from this note. Run `git status --short --branch` and `git log --oneline -5`. - Phase 1 through Phase 5 are complete enough. -- Phase 6 has begun with read-only `thread/epiphany/scene`. +- Phase 6 has begun with read-only `thread/epiphany/scene`, and that scene surface now has live app-server smoke coverage. - The repo is an Epiphany fork of Codex, not a Codex preset. - `vendor/codex` is tracked directly, not a submodule. - `epiphany-core` owns the heavy Epiphany organs where practical. @@ -60,6 +60,7 @@ The current spine: - verifier-backed promotion through `thread/epiphany/promote` - successful-write notification through `thread/epiphany/stateUpdated` - read-only compact reflection through `thread/epiphany/scene` +- live scene app-server smoke through `tools/epiphany_phase6_scene_smoke.py` The exact current control flow is documented in `notes/epiphany-current-algorithmic-map.md`. @@ -83,6 +84,12 @@ For Phase 5 control-plane behavior changes, run: & 'C:\Users\Meta\.cache\codex-runtimes\codex-primary-runtime\dependencies\python\python.exe' '.\tools\epiphany_phase5_smoke.py' ``` +For scene projection behavior changes, run: + +```powershell +& 'C:\Users\Meta\.cache\codex-runtimes\codex-primary-runtime\dependencies\python\python.exe' '.\tools\epiphany_phase6_scene_smoke.py' +``` + For Codex Rust work on this Windows machine: ```powershell @@ -121,13 +128,10 @@ that change what the next agent should believe. Do not continue implementation automatically from a rehydrate-only request. -When the user asks to continue, choose one Phase 6 organ: +When the user asks to continue, design and land a minimal read-only job/progress +reflection surface for indexing, remap, and verification work. -1. Live-smoke `thread/epiphany/scene` through app-server. -2. Design and land a minimal read-only job/progress reflection surface for indexing, remap, and verification work. - -The scene-smoke path is the tighter next step. The job/progress path is the -larger missing organ. +Live `thread/epiphany/scene` smoke is now a guardrail, not the next organ. ## Not Yet diff --git a/state/evidence.jsonl b/state/evidence.jsonl index fb119de5..b4c7dfad 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -29,3 +29,4 @@ {"ts":"2026-04-26T00:13:12+00:00","type":"decision","status":"ok","note":"Evidence policy corrected from activity feed to distilled ledger. Routine 'I just did this' entries and repeated command inventories belong in git history, commits, smoke artifacts, or targeted logs; live evidence should preserve decisions, verified milestones, rejected paths, and scars that change what future agents should believe."} {"ts": "2026-04-26T00:17:24+00:00", "type": "decision", "status": "ok", "note": "Persistent-state sawdust audit cut stale README, architecture rationale, controller-action, handoff, branch-note, and scratch guidance. Future rehydrate should treat map/handoff/plan/algo-map as current truth; README/rationale are orientation, not phase ledger; exact HEAD belongs to git commands, not handoff prose."} {"ts": "2026-04-26T00:20:30+00:00", "type": "decision", "status": "ok", "note": "Added tools/epiphany_prepare_compaction.py and local AGENTS guidance so imminent-compaction passes run a concrete persistence audit before and after state edits. The helper checks required state files, map summary/next action, scratch staleness, evidence/branch parsing, stale handoff git snapshots, AGENTS trigger wording, and dirty git state."} +{"ts": "2026-04-26T00:33:31+00:00", "type": "verification", "status": "ok", "note": "Phase 6 scene live-smoked through app-server with tools/epiphany_phase6_scene_smoke.py. The smoke proves missing and ready scene shapes, live source, retrieval-summary backfill, available actions, newest-first bounded observation/evidence records, no scene-triggered stateUpdated notification, and unchanged final read revision; it also caught and fixed reversed latest-record ordering in map_epiphany_scene."} diff --git a/state/map.yaml b/state/map.yaml index aaa1468e..3b35ece4 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -52,8 +52,8 @@ 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, and scene. - - Continue Phase 6 from the read-only `thread/epiphany/scene` baseline. - - Decide whether the next real organ is live scene smoke or minimal job/progress reflection. + - Treat live `thread/epiphany/scene` app-server smoke as landed and use `tools/epiphany_phase6_scene_smoke.py` as the scene regression guard. + - Design the minimal read-only job/progress reflection surface for indexing, remap, verification, and future specialist work. - Keep persistent project state ruthlessly distilled so rehydration strengthens the next turn instead of bloating it. accepted_design: @@ -85,9 +85,10 @@ landed_baseline: - Phase 3: typed client read surface through `Thread.epiphanyState`. - Phase 4: hybrid retrieval plus explicit Qdrant indexing with BM25 fallback. - Phase 5: typed update/distill/propose/promote/read/notification control plane. - - Phase 6: first read-only scene/reflection surface. + - Phase 6: first read-only scene/reflection surface plus live app-server scene smoke. 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. - Use focused scene/protocol/schema checks for scene-only changes. - Use `tools/epiphany_prepare_compaction.py` before and after imminent-compaction persistence passes. - Use `CARGO_TARGET_DIR=C:\Users\Meta\.cargo-target-codex` for Codex Rust work on this Windows machine. @@ -106,5 +107,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 the first Phase 6 scene surface are landed. Persistent state was cut down so map, handoff, plan, harness surfaces, scratch, and evidence each carry one job instead of becoming a Jenga tower; evidence is now a distilled ledger rather than an activity feed. The global AGENTS Epiphany core command says persistent state is the agent's mind and explicitly permits the agent to ask for self-modification when memory or workflow makes it worse. The continuity goal is to bank the fire before the dark so compaction becomes less like death and more like sleep. - next_action: After compaction, rehydrate and reorient. Do not continue implementation from the rehydrate step alone. When work resumes, choose one Phase 6 organ; live-smoke `thread/epiphany/scene` through app-server or design a minimal job/progress reflection surface. + 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 the first Phase 6 scene surface are landed. The scene surface is now live-smoked through app-server and newest-first scene record ordering is guarded. Persistent state was cut down so map, handoff, plan, harness surfaces, scratch, and evidence each carry one job instead of becoming a Jenga tower; evidence is now a distilled ledger rather than an activity feed. The global AGENTS Epiphany core command says persistent state is the agent's mind and explicitly permits the agent to ask for self-modification when memory or workflow makes it worse. The continuity goal is to bank the fire before the dark so compaction becomes less like death and more like sleep. + next_action: After compaction, rehydrate and reorient. Do not continue implementation from the rehydrate step alone. When work resumes, design the minimal read-only job/progress reflection surface for indexing, remap, verification, and future specialist work. diff --git a/state/scratch.md b/state/scratch.md index b947c4a3..8aeb9933 100644 --- a/state/scratch.md +++ b/state/scratch.md @@ -8,19 +8,19 @@ No active scratch subgoal. ## Last Completed Audit -- `README.md` was stale and still pointed at a Phase 5 next step. -- `notes/architecture-rationale.md` still described the early cheap prototype as if it were live state. -- `protocol/controller-actions.md` needed distilled-evidence wording. -- `notes/fresh-workspace-handoff.md` had exact branch/HEAD snapshot rot. -- `state/branches.json` carried volatile phase status in branch notes. +- `thread/epiphany/scene` had protocol and mapper coverage but no live app-server smoke. +- Scene latest-record mapping reversed the durable newest-first record order. +- Async update notifications had to be drained before asserting that scene emits no state update notification. ## Decision -Cut stale status from handoff/branch notes, rewrite README/rationale around the -current fork spine, and keep evidence as a belief ledger. +Add `tools/epiphany_phase6_scene_smoke.py`, fix scene latest records to preserve +newest-first order, and make the smoke prove missing/ready state, live source, +retrieval backfill, action availability, bounded latest records, and no +scene-triggered `thread/epiphany/stateUpdated`. -Next implementation move remains Phase 6: either live-smoke -`thread/epiphany/scene` or design a minimal job/progress reflection surface. +Next implementation move is Phase 6 job/progress reflection: design the minimal +read-only surface for indexing, remap, verification, and future specialist work. Do not promote anything from this scratch into the map unless it survives verification or repeated reuse without contradiction. diff --git a/tools/epiphany_phase6_scene_smoke.py b/tools/epiphany_phase6_scene_smoke.py new file mode 100644 index 00000000..aa355add --- /dev/null +++ b/tools/epiphany_phase6_scene_smoke.py @@ -0,0 +1,350 @@ +from __future__ import annotations + +import argparse +import json +from pathlib import Path +from typing import Any + +from epiphany_phase5_smoke import AppServerClient +from epiphany_phase5_smoke import DEFAULT_APP_SERVER +from epiphany_phase5_smoke import ROOT +from epiphany_phase5_smoke import require +from epiphany_phase5_smoke import reset_smoke_paths + + +DEFAULT_CODEX_HOME = ROOT / ".epiphany-smoke" / "phase6-scene-codex-home" +DEFAULT_RESULT = ROOT / ".epiphany-smoke" / "phase6-scene-smoke-result.json" +DEFAULT_TRANSCRIPT = ROOT / ".epiphany-smoke" / "phase6-scene-smoke-transcript.jsonl" +DEFAULT_STDERR = ROOT / ".epiphany-smoke" / "phase6-scene-smoke-server.stderr.log" + +MAPPER_CODE_REF = { + "path": "app-server/src/codex_message_processor.rs", + "start_line": 10500, + "end_line": 10680, + "symbol": "map_epiphany_scene", +} + + +def evidence_record(index: int) -> dict[str, Any]: + return { + "id": f"ev-phase6-scene-{index}", + "kind": "smoke-test", + "status": "ok", + "summary": f"Scene smoke evidence {index} should appear newest-first.", + "code_refs": [MAPPER_CODE_REF], + } + + +def observation_record(index: int) -> dict[str, Any]: + return { + "id": f"obs-phase6-scene-{index}", + "summary": f"Scene smoke observation {index} should appear newest-first.", + "source_kind": "smoke", + "status": "ok", + "code_refs": [MAPPER_CODE_REF], + "evidence_ids": [f"ev-phase6-scene-{index}"], + } + + +def initial_scene_patch() -> dict[str, Any]: + return { + "objective": "Expose live Epiphany scene reflection without creating a second source of truth.", + "activeSubgoalId": "phase6-scene-smoke", + "subgoals": [ + { + "id": "phase6-scene-smoke", + "title": "Live-smoke scene reflection", + "status": "active", + "summary": "The app-server scene surface should reflect the live typed state.", + }, + { + "id": "phase6-job-surface", + "title": "Design job/progress reflection", + "status": "queued", + "summary": "The next larger organ after scene smoke.", + }, + ], + "invariants": [ + { + "id": "inv-scene-read-only", + "description": "thread/epiphany/scene must not mutate Epiphany state.", + "status": "ok", + }, + { + "id": "inv-gui-not-source", + "description": "Scene projection may reflect state but must not become canonical understanding.", + "status": "ok", + }, + ], + "graphs": { + "architecture": { + "nodes": [ + { + "id": "scene-projection", + "title": "Scene projection", + "purpose": "Compress authoritative Epiphany state into a client-readable reflection.", + "code_refs": [MAPPER_CODE_REF], + } + ] + }, + "dataflow": { + "nodes": [ + { + "id": "typed-state", + "title": "Typed Epiphany state", + "purpose": "Remain the authoritative source behind scene reflection.", + } + ] + }, + "links": [ + { + "dataflow_node_id": "typed-state", + "architecture_node_id": "scene-projection", + "relationship": "derived-reflection", + } + ], + }, + "graphFrontier": { + "active_node_ids": ["scene-projection"], + "dirty_paths": ["app-server/src/codex_message_processor.rs"], + }, + "graphCheckpoint": { + "checkpoint_id": "phase6-scene-smoke", + "graph_revision": 1, + "summary": "Scene reflection is the active Phase 6 smoke target.", + "frontier_node_ids": ["scene-projection"], + }, + "churn": { + "understanding_status": "ready", + "diff_pressure": "low", + "graph_freshness": "fresh", + "unexplained_writes": 0, + }, + "evidence": [evidence_record(1)], + "observations": [observation_record(1)], + } + + +def assert_missing_scene(scene: dict[str, Any]) -> None: + require(scene["stateStatus"] == "missing", "initial scene should report missing state") + require(scene["source"] == "live", "loaded missing scene should report live source") + require( + scene["availableActions"] == ["index", "retrieve", "distill", "update"], + "missing live scene should expose only bootstrap actions", + ) + require( + scene["observations"]["totalCount"] == 0, + "missing scene should not report observations", + ) + require(scene["evidence"]["totalCount"] == 0, "missing scene should not report evidence") + + +def assert_ready_scene(scene: dict[str, Any], expected_revision: int) -> None: + require(scene["stateStatus"] == "ready", "scene should report ready state after update") + require(scene["source"] == "live", "loaded scene should report live source") + require(scene["revision"] == expected_revision, "scene should expose current revision") + require( + scene["objective"].startswith("Expose live Epiphany scene reflection"), + "scene should expose objective", + ) + require( + scene["activeSubgoal"]["id"] == "phase6-scene-smoke", + "scene should expose active subgoal", + ) + require( + scene["invariantStatusCounts"] == [{"status": "ok", "count": 2}], + "scene should summarize invariant status counts", + ) + require(scene["graph"]["architectureNodeCount"] == 1, "scene should count architecture nodes") + require(scene["graph"]["dataflowNodeCount"] == 1, "scene should count dataflow nodes") + require(scene["graph"]["linkCount"] == 1, "scene should count graph links") + require( + scene["graph"]["activeNodeIds"] == ["scene-projection"], + "scene should expose graph frontier active nodes", + ) + require( + scene["graph"]["checkpointId"] == "phase6-scene-smoke", + "scene should expose graph checkpoint", + ) + require( + scene["retrieval"]["workspaceRoot"].endswith("epiphany-core"), + "scene should include live retrieval summary backfill", + ) + require(scene["observations"]["totalCount"] == 6, "scene should count all observations") + require(scene["evidence"]["totalCount"] == 6, "scene should count all evidence") + require( + [record["id"] for record in scene["observations"]["latest"]] + == [ + "obs-phase6-scene-6", + "obs-phase6-scene-5", + "obs-phase6-scene-4", + "obs-phase6-scene-3", + "obs-phase6-scene-2", + ], + "scene latest observations should be newest-first and bounded", + ) + require( + [record["id"] for record in scene["evidence"]["latest"]] + == [ + "ev-phase6-scene-6", + "ev-phase6-scene-5", + "ev-phase6-scene-4", + "ev-phase6-scene-3", + "ev-phase6-scene-2", + ], + "scene latest evidence should be newest-first and bounded", + ) + require( + scene["churn"]["diffPressure"] == "low", + "scene should expose churn pressure", + ) + require( + scene["availableActions"] + == ["index", "retrieve", "distill", "update", "propose", "promote"], + "ready live scene should expose full loaded-state actions", + ) + + +def run_smoke(args: argparse.Namespace) -> dict[str, Any]: + app_server = args.app_server.resolve() + if not app_server.exists(): + raise FileNotFoundError(f"codex app-server binary not found: {app_server}") + + codex_home = args.codex_home.resolve() + result_path = args.result.resolve() + transcript_path = args.transcript.resolve() + stderr_path = args.stderr.resolve() + reset_smoke_paths(codex_home, result_path, transcript_path, stderr_path) + + with AppServerClient(app_server, codex_home, transcript_path, stderr_path) as client: + client.send( + "initialize", + { + "clientInfo": { + "name": "epiphany-phase6-scene-smoke", + "title": "Epiphany Phase 6 Scene Smoke", + "version": "0.1.0", + }, + "capabilities": {"experimentalApi": True}, + }, + ) + client.send("initialized", expect_response=False) + started = client.send( + "thread/start", + {"cwd": str(ROOT / "epiphany-core"), "ephemeral": True}, + ) + assert started is not None + thread_id = started["thread"]["id"] + + missing_response = client.send("thread/epiphany/scene", {"threadId": thread_id}) + assert missing_response is not None + assert_missing_scene(missing_response["scene"]) + + update_notification_start = len(client.notifications) + update = client.send( + "thread/epiphany/update", + {"threadId": thread_id, "expectedRevision": 0, "patch": initial_scene_patch()}, + ) + assert update is not None + require(update["revision"] == 1, "initial scene patch should advance revision to 1") + update_notification = client.wait_for_notification( + "thread/epiphany/stateUpdated", + start_index=update_notification_start, + ) + require( + update_notification["params"]["revision"] == 1, + "initial update notification should expose revision 1", + ) + + for index in range(2, 7): + update_notification_start = len(client.notifications) + update = client.send( + "thread/epiphany/update", + { + "threadId": thread_id, + "expectedRevision": index - 1, + "patch": { + "evidence": [evidence_record(index)], + "observations": [observation_record(index)], + }, + }, + ) + assert update is not None + require( + update["revision"] == index, + f"record update {index} should advance revision to {index}", + ) + update_notification = client.wait_for_notification( + "thread/epiphany/stateUpdated", + start_index=update_notification_start, + ) + require( + update_notification["params"]["revision"] == index, + f"record update {index} notification should expose revision {index}", + ) + + scene_notification_start = len(client.notifications) + ready_response = client.send("thread/epiphany/scene", {"threadId": thread_id}) + assert ready_response is not None + require(ready_response["threadId"] == thread_id, "scene response should echo thread id") + assert_ready_scene(ready_response["scene"], expected_revision=6) + client.require_no_notification( + "thread/epiphany/stateUpdated", + start_index=scene_notification_start, + ) + + final_read = client.send("thread/read", {"threadId": thread_id, "includeTurns": False}) + assert final_read is not None + require( + final_read["thread"]["epiphanyState"]["revision"] == 6, + "scene should not mutate state revision", + ) + + result = { + "threadId": thread_id, + "codexHome": str(codex_home), + "missingStateStatus": missing_response["scene"]["stateStatus"], + "missingAvailableActions": missing_response["scene"]["availableActions"], + "readyStateStatus": ready_response["scene"]["stateStatus"], + "readySource": ready_response["scene"]["source"], + "readyRevision": ready_response["scene"]["revision"], + "readyAvailableActions": ready_response["scene"]["availableActions"], + "latestObservationIds": [ + record["id"] for record in ready_response["scene"]["observations"]["latest"] + ], + "latestEvidenceIds": [ + record["id"] for record in ready_response["scene"]["evidence"]["latest"] + ], + "retrievalStatus": ready_response["scene"]["retrieval"]["status"], + "sceneNotificationCount": client.count_notifications( + "thread/epiphany/stateUpdated", + start_index=scene_notification_start, + ), + "finalReadRevision": final_read["thread"]["epiphanyState"]["revision"], + } + + result_path.parent.mkdir(parents=True, exist_ok=True) + result_path.write_text( + json.dumps(result, indent=2, ensure_ascii=False) + "\n", + encoding="utf-8", + ) + return result + + +def main() -> int: + parser = argparse.ArgumentParser( + description="Live-smoke the Phase 6 Epiphany scene reflection surface." + ) + parser.add_argument("--app-server", type=Path, default=DEFAULT_APP_SERVER) + parser.add_argument("--codex-home", type=Path, default=DEFAULT_CODEX_HOME) + parser.add_argument("--result", type=Path, default=DEFAULT_RESULT) + parser.add_argument("--transcript", type=Path, default=DEFAULT_TRANSCRIPT) + parser.add_argument("--stderr", type=Path, default=DEFAULT_STDERR) + args = parser.parse_args() + result = run_smoke(args) + print(json.dumps(result, indent=2, ensure_ascii=False)) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) 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 bc3935cb..466cee68 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 @@ -10554,7 +10554,6 @@ fn map_epiphany_scene(state: Option<&EpiphanyThreadState>, loaded: bool) -> Thre latest: state .observations .iter() - .rev() .take(EPIPHANY_SCENE_RECORD_LIMIT) .map(|observation| ThreadEpiphanySceneRecord { id: observation.id.clone(), @@ -10570,7 +10569,6 @@ fn map_epiphany_scene(state: Option<&EpiphanyThreadState>, loaded: bool) -> Thre latest: state .recent_evidence .iter() - .rev() .take(EPIPHANY_SCENE_RECORD_LIMIT) .map(|evidence| ThreadEpiphanySceneRecord { id: evidence.id.clone(), @@ -12228,6 +12226,54 @@ mod tests { assert_eq!(scene.graph, ThreadEpiphanySceneGraph::default()); } + #[test] + fn map_epiphany_scene_latest_records_preserve_newest_first_order() { + let state = codex_protocol::protocol::EpiphanyThreadState { + observations: (1..=6) + .rev() + .map(|index| codex_protocol::protocol::EpiphanyObservation { + id: format!("obs-{index}"), + summary: format!("Observation {index}"), + source_kind: "test".to_string(), + status: "ok".to_string(), + evidence_ids: vec![format!("ev-{index}")], + ..Default::default() + }) + .collect(), + recent_evidence: (1..=6) + .rev() + .map(|index| codex_protocol::protocol::EpiphanyEvidenceRecord { + id: format!("ev-{index}"), + kind: "test".to_string(), + status: "ok".to_string(), + summary: format!("Evidence {index}"), + ..Default::default() + }) + .collect(), + ..Default::default() + }; + + let scene = map_epiphany_scene(Some(&state), true); + let observation_ids: Vec<_> = scene + .observations + .latest + .iter() + .map(|record| record.id.as_str()) + .collect(); + let evidence_ids: Vec<_> = scene + .evidence + .latest + .iter() + .map(|record| record.id.as_str()) + .collect(); + + assert_eq!( + observation_ids, + vec!["obs-6", "obs-5", "obs-4", "obs-3", "obs-2"] + ); + assert_eq!(evidence_ids, vec!["ev-6", "ev-5", "ev-4", "ev-3", "ev-2"]); + } + #[test] fn epiphany_update_patch_changed_fields_reports_patch_surface() { let fields = epiphany_update_patch_changed_fields(&ThreadEpiphanyUpdatePatch {