Skip to content

perf(sessions): cache branch summaries behind a transcript watermark - #114412

Merged
steipete merged 1 commit into
mainfrom
perf/session-branches-summary-cache
Jul 27, 2026
Merged

steipete merged 1 commit into
mainfrom
perf/session-branches-summary-cache

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

sessions.branches.list on production (team.openclaw.ai) averaged 1459ms across 791 calls in a 24.6h window. listSqliteSessionBranches loaded and JSON.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) on transcript_events plus the transcript_rewrite_watermarks generation — the same validity model the visible-message delta API uses). Appends advance max(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

  • Production journal (24.6h): sessions.branches.list n=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
  • tsgo core lane clean (only the known pre-existing @openclaw/session-url-contract worktree error); autoreview (Codex gpt-5.6-sol, xhigh) clean, "patch is correct (0.9)"

@steipete
steipete marked this pull request as ready for review July 27, 2026 07:30
@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Jul 27, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jul 27, 2026
@clawsweeper

clawsweeper Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 27, 2026, 3:35 AM ET / 07:35 UTC.

ClawSweeper review

What this changes

This 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
Reviewed head: d2b0f80214d80e2e65532cb0c30beaf49f0ef96d

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The focused regression coverage is useful, but real after-fix behavior proof is still missing for this derived-session-state cache.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The body reports focused tests and a pre-change production latency baseline, but it does not show a real after-fix cache-hit and invalidation sequence; add redacted live output or logs before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The body reports focused tests and a pre-change production latency baseline, but it does not show a real after-fix cache-hit and invalidation sequence; add redacted live output or logs before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 4 items Proposed cache boundary: The supplied PR diff changes the SQLite message-cut session accessor and its focused tests; it adds a module-local bounded cache keyed by database path and session id, plus watermark reads before cache reuse.
Focused invalidation coverage: The PR body reports regressions for cache reuse, append invalidation, rewind/switch/fork invalidation, caller mutation isolation, and cross-session isolation in the session-accessor test file.
Proof gap: The submitted evidence includes a production before-measurement and focused tests, but no redacted after-fix live output showing a cache hit followed by correct refresh after a transcript mutation.
Findings None None.
Security None None.

How this fits together

The 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
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The body reports focused tests and a pre-change production latency baseline, but it does not show a real after-fix cache-hit and invalidation sequence; add redacted live output or logs before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - This changes cached derived session state; before merge, a real run should demonstrate a cache hit and then a correct refresh after append plus a rewrite-style mutation, so stale branch summaries cannot escape the tested path.
  • Resolve merge risk (P1) - The maintainer label is protected under repository policy, so this PR needs explicit maintainer handling rather than automated cleanup.
  • Complete next step (P2) - A protected maintainer-labeled PR needs maintainer review, and only the contributor can supply the missing after-fix evidence from the relevant runtime setup.
Agent review details

Security

None.

PR surface

Source +88, Tests +173. Total +261 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 93 5 +88
Tests 1 175 2 +173
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 268 7 +261

Review metrics

None.

Stored data model

Persistent data-model change detected: serialized state: src/config/sessions/session-accessor.sqlite-message-cut.test.ts, serialized state: src/config/sessions/session-accessor.sqlite-message-cut.ts, unknown-data-model-change: src/config/sessions/session-accessor.sqlite-message-cut.test.ts, unknown-data-model-change: src/config/sessions/session-accessor.sqlite-message-cut.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Add live cache and invalidation proof (recommended)
    Capture redacted after-fix output for an initial list, a repeated cache-hit list, and refreshed lists after transcript mutations before merging.
  2. Accept the residual cache risk
    A maintainer may merge based on the focused tests and production baseline while accepting that the submitted evidence does not show the full after-fix runtime sequence.

Technical review

Best 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.

Labels

Label changes:

  • add P2: This is a bounded session-performance improvement for a frequently used Control UI path, with no supplied evidence of an urgent correctness regression.
  • add merge-risk: 🚨 session-state: The PR introduces a cache for branch summaries derived from persisted transcript state, so an incomplete watermark or mutation boundary could return stale session information.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The body reports focused tests and a pre-change production latency baseline, but it does not show a real after-fix cache-hit and invalidation sequence; add redacted live output or logs before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Label justifications:

  • P2: This is a bounded session-performance improvement for a frequently used Control UI path, with no supplied evidence of an urgent correctness regression.
  • merge-risk: 🚨 session-state: The PR introduces a cache for branch summaries derived from persisted transcript state, so an incomplete watermark or mutation boundary could return stale session information.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The body reports focused tests and a pre-change production latency baseline, but it does not show a real after-fix cache-hit and invalidation sequence; add redacted live output or logs before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Proposed cache boundary: The supplied PR diff changes the SQLite message-cut session accessor and its focused tests; it adds a module-local bounded cache keyed by database path and session id, plus watermark reads before cache reuse. (src/config/sessions/session-accessor.sqlite-message-cut.ts:64, d2b0f80214d8)
  • Focused invalidation coverage: The PR body reports regressions for cache reuse, append invalidation, rewind/switch/fork invalidation, caller mutation isolation, and cross-session isolation in the session-accessor test file. (src/config/sessions/session-accessor.sqlite-message-cut.test.ts:1, d2b0f80214d8)
  • Proof gap: The submitted evidence includes a production before-measurement and focused tests, but no redacted after-fix live output showing a cache hit followed by correct refresh after a transcript mutation. (d2b0f80214d8)
  • Related context is distinct: The linked merged PR supplies the production-journal context cited by this PR, but it fixes Control UI assistant identity resolution rather than session branch-summary computation. (bb55d44840df)

Likely related people:

  • steipete: The supplied context attributes the production timing investigation and proposed session-cache implementation to this contributor; current-main feature-history ownership could not be independently verified in the read-only sandbox. (role: performance investigation contributor; confidence: low; commits: d2b0f80214d8; files: src/config/sessions/session-accessor.sqlite-message-cut.ts, src/config/sessions/session-accessor.sqlite-message-cut.test.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Add redacted live output showing an initial branch list, a fast unchanged repeat, and correct recomputation after append and rewrite-style mutations.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 9b17119 into main Jul 27, 2026
217 of 226 checks passed
@steipete
steipete deleted the perf/session-branches-summary-cache branch July 27, 2026 08:24
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant