Repository navigation
feat: revalidate cached chat history with cursor deltas - #125606
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 18, 2026, 3:38 AM ET / 07:38 UTC. ClawSweeper reviewWhat this changesAdds cursor-based delta responses to chat history requests and uses them to revalidate cached Control UI transcripts without refetching a full tail page. Merge readinessKeep open. This fresh, maintainer-authored feature is not on current main; the inspected Gateway, protocol, and Control UI paths are coherent, but its persisted transcript-state risk warrants a rebase and exact-head validation before landing. Priority: P2 Review scores
Verification
How this fits togetherThe Control UI stores recent chat snapshots, then asks the Gateway to revalidate them. The Gateway reads the SQLite transcript projection and returns replayable message deltas or a reset that returns the client to the existing full-history fetch. flowchart LR
A[Cached chat snapshot] --> B[Control UI history request]
B --> C[Gateway transcript projection]
C --> D{Cursor valid and bounded?}
D -->|Yes| E[Replayable message deltas]
D -->|No| F[Reset response]
E --> G[Shared chat reducer]
F --> H[Full tail history fetch]
G --> I[Updated cached snapshot]
H --> I
Decision needed
Why: The change persists transcript cursors and replays durable messages across cache, Gateway, and UI boundaries; maintainer judgment is needed on the final merged upgrade surface. Before merge
Agent review detailsSecurityNone. PR surfaceSource +626, Tests +886, Docs +1, Other +83. Total +1596 across 31 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land the additive cursor protocol only after its reset-to-tail fallback and replayed transcript state remain correct on a rebased current-main head. Do we have a high-confidence way to reproduce the issue? Not applicable as a bug report. The PR body provides a concrete isolated-Gateway/WebSocket verification route, and the inspected tests exercise cursor, reset, and replay behavior. Is this the best way to solve the issue? Yes, provisionally: the additive cursor plus reset-to-existing-tail-fetch path reuses the canonical history and reducer flows; final confidence requires the rebased exact-head checks. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 9ad1c0c68204. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
Land-ready at ClawSweeper rank-up move:
Proof completed:
Known local-only gap: the macOS tooling Vitest shard hit its documented 900-second no-output timeout on this loaded host and was stopped during the automatic retry. Exact-head CI is the platform authority and passed the corresponding lanes. |
|
Merged via squash.
|
What Problem This Solves
Revalidating a cached session transcript refetched the full approximately 100-message tail even when the client was already current. That cost 5–16 KB on small sessions and hundreds of KB on real sessions because the history API had no forward catch-up direction.
Why This Change Was Made
This adds Codex-app-server-style cursor catch-up to the existing
chat.historyandchat.startupmethods rather than introducing another RPC. Tail pages now return an opaquedeltaCursor, reusing the raw-delta codec's generation and last-sequence fence. Cursor requests return a closed union withkind: "delta"orkind: "reset".Delta messages are projected through the same shared payload builder as live
session.messagebroadcasts, so their wire payloads are byte-identical. The Control UI replays catch-up messages through the same reducer used by live events, persists the cursor with the session snapshot, and re-warms prefetched sessions with cursor requests. A generation change after compaction or reset, an unknown cursor, or a client more than 200 projected events behind returnsreset; the client then performs today's normal cursor-less tail fetch instead of surfacing an error. This is an additive protocol change and old clients are unaffected.User Impact
Cached-session revalidation and background prefetch shrink from full tail pages to approximately 1 KB deltas, or approximately 200 bytes when already current. Recently used sessions stay warm at a fraction of the traffic. CLI-imported sessions and cursor resets degrade to the existing full-tail flow.
The v1 tradeoff is deliberate: clients do not loop through more than 200 missed events, so far-behind cursors reset. A pane's cold open also still performs a full fetch under the existing network-wins rule. Looping and cold-open reuse are named follow-up opportunities.
Evidence
Focused post-rebase suites:
pnpm ui:buildpassed, including Control UI performance budgets.Live verification used an isolated dev Gateway and captured WebSocket frames. The rig showed a first-touch full fetch followed by cursor-based reopens; cold-reload prefetch converged after CLI-injected turns; compaction produced
resetand recovered through a cursor-less refetch; and delta responses were approximately 1 KB versus 5–16 KB full tail pages, with already-current responses approximately 200 bytes.That live pass found two bugs which were fixed failing-test-first: an append-miss stub could clobber a persisted snapshot (a pre-existing bug class tracked in #125128), and a WAL race could advance the delta cursor past the last projected event. The final tests cover both repairs in their owning boundaries.
There is no visual UI change: rendered transcripts are identical. This is wire-level transcript revalidation, so the relevant evidence is captured frames, live convergence/reset behavior, and focused tests rather than screenshots.