Repository navigation
perf(sessions): cache branch summaries behind a transcript watermark - #114412
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed July 27, 2026, 3:35 AM ET / 07:35 UTC. ClawSweeper reviewWhat this changesThis PR caches SQLite-derived session branch summaries using transcript watermarks so repeated branch-list requests avoid reparsing an unchanged full transcript. Merge readiness⛔ Blocked until real behavior proof from a real setup is added - 4 items remain Keep this PR open for protected maintainer review and after-fix real behavior proof. The cache design is plausibly bounded and the supplied focused tests cover important invalidation cases, but the PR body provides only tests and a before-change production measurement—not a real post-change run demonstrating both cache reuse and transcript-mutation refresh behavior. Priority: P2 Review scores
Verification
How this fits togetherThe session accessor derives branch dropdown data from each agent session’s SQLite transcript, which the Control UI requests while changing sessions. This PR adds an in-process cache between that transcript read path and callers, checking a transcript sequence and rewrite generation before returning cloned cached summaries. flowchart LR
A[Control UI session switch] --> B[Session branches request]
B --> C[SQLite branch summary service]
C --> D{Transcript watermark unchanged?}
D -->|yes| E[Return cloned cached summary]
D -->|no| F[Read transcript events]
F --> G[Compute branch summaries]
G --> H[Store cache entry]
H --> E
Before merge
Agent review detailsSecurityNone. PR surfaceSource +88, Tests +173. Total +261 across 2 files. View PR surface stats
Review metricsNone. Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the 32-entry watermark-validated cache only if a redacted live run proves unchanged transcripts reuse the cached result and append, rewind, switch, and fork paths immediately return refreshed branch summaries without changing the response contract. Do we have a high-confidence way to reproduce the issue? No high-confidence independent reproduction was completed: the supplied production timing data identifies the slow path and the PR’s focused tests exercise it, but the read-only shell sandbox prevented direct current-main source and runtime inspection. Is this the best way to solve the issue? Unclear. A watermark-validated bounded cache is a maintainable approach if every transcript mutation shares its validity model, but the supplied evidence needs an after-fix real run to establish that the proposed boundary is the best safe fix. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against d4ed57bc8847. LabelsLabel changes:
Label 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
|
|
Merged via squash.
|
What Problem This Solves
sessions.branches.liston production (team.openclaw.ai) averaged 1459ms across 791 calls in a 24.6h window.listSqliteSessionBranchesloaded andJSON.parsed every transcript event row for the session, then scanned the full tree — on every request, synchronously — even though the Control UI calls this on every session switch and the branch summary almost never changes between calls.Why This Change Was Made
Branch listing must not scale with transcript size on every request. This adds a module-local, 32-entry LRU of computed
SessionBranchSummary[]keyed by database path + sessionId, validated by a cheap two-query watermark (max(seq)ontranscript_eventsplus thetranscript_rewrite_watermarksgeneration — the same validity model the visible-message delta API uses). Appends advancemax(seq); rewrites and replacements rotate the generation, so any transcript change forces a recompute. Successful rewind/switch/fork mutations in the same module additionally invalidate affected session entries post-commit as same-module hygiene. Returned summaries are cloned so callers cannot mutate cached state. Response shape, ordering, and headline logic are byte-identical.User Impact
Session switching in the Control UI stops paying a full-transcript parse for the branch dropdown; repeat listings return in single-digit milliseconds. No behavior change.
Evidence
sessions.branches.listn=791, avg 1459ms, max 3735ms; context in fix(gateway): stop fabricating assistant agent id "main" before roster resolution #114257 (comment)node scripts/run-vitest.mjs src/config/sessions/session-accessor.sqlite-message-cut.test.ts— 19/19, with new regressions: cache reuse skips the event load, append invalidates, rewind/switch/fork invalidate, caller mutation isolation, cross-session isolation@openclaw/session-url-contractworktree error); autoreview (Codex gpt-5.6-sol, xhigh) clean, "patch is correct (0.9)"