Repository navigation
perf(sessions): coalesce branch list reads before restoration - #155678
Conversation
|
Codex review: needs maintainer review before merge. Reviewed September 22, 2026, 7:03 AM ET / 11:03 UTC. ClawSweeper reviewWhat this changesThe PR shares concurrent chat branch-list reads, checks cached summaries before restoration, and adds lifecycle regression coverage and storage documentation. Merge readiness✅ Ready for maintainer review Keep open: the optimization remains useful on current main, and the reviewed patch has no blocking correctness findings. Priority: P2 Review scores
Verification
How this fits togetherChat viewers request branch summaries through the Gateway. The session accessor coordinates cached results, SQLite transcript workers, and cold-storage restoration before returning branch details. flowchart TD
A[Chat viewers] --> B[Gateway branch request]
B --> C[Validate session and cache]
C -->|Cache miss| D[Shared transcript worker read]
D -->|Cold transcript| E[Existing archive restoration]
E --> D
C -->|Cache hit| F[Validate lifecycle and clone results]
D --> F
F --> G[Branch lists]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +20, Tests +52, Docs +3. Total +75 across 3 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep branch-read coalescing inside the existing accessor while preserving worker snapshots, caller lifecycle validation, and archive-owned restoration. Do we have a high-confidence way to reproduce the issue? Yes, from source: simultaneous uncached branch requests on current main dispatch separate worker reads, and warm hits still enter restoration. This review did not execute that path. Is this the best way to solve the issue? Yes. The patch extends the existing cache owner, preserves final lifecycle checks, and avoids introducing a competing restoration or persistence mechanism. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d5fc539e7498. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
What Problem This Solves
Opening the same chat in several viewers queues duplicate branch-list reads, and even valid summary-cache hits enter the cold-restoration path.
User Impact
Branch lists avoid redundant work while preserving their contents, ordering, lifecycle checks, and independent result objects. No configuration, schema, stored-data, or update behavior changes.
Why This Change Was Made
Check the existing identity/watermark-bound cache first, coalesce in-flight misses by database claim, session lifecycle, and transcript watermark, and restore only when the transcript worker reports cold storage. Restoration retains the existing archive worker and its commit authority. Pending reads are removed on settlement; the existing 64-entry summary cache is unchanged. Net production growth: 20 lines.
Evidence
CI shard rerun passed: the original
checks-node-compact-large-17run failed in the existingsession-delivery-clock-jump.integration.test.tswhile waiting for a dispatched delivery claim to settle within 15 seconds. This fixture does not call the branch-list accessor. After three prior green Testbox replays, the maintainer explicitly authorized one rerun of that job. Attempt 2 passed on the unchanged head8a626aca5286a63c7ff25d941a53488c9eff22ee; the CI and security gates passed. Squash auto-merge completed asb476ed92ba176bf714050c21a2b1648bcfda91d3without a rebase or source change. These passing runs do not prove a repair. No timeout, assertion, delivery code, or retry policy was changed. A fresh independent Codex autoreview through P2 is also clean.Paired synthetic comparison against
55995369eca380466fb87a0f08fba89dee91093b: 100 alternating before/after samples in one process, using the same session and worker pool, with golden output equality. Concurrent-miss samples invalidate the host summary cache before each group; the worker remains warm.sessions.title.prepare, warm handler overheadcomputer.status, warm handler overheadWarm branch p50 improves 24%; the concurrent group improves 60%. The original regression issued three worker reads; the candidate issues one. Fifty warm hits previously called the restoration owner fifty times; the candidate calls it zero times.
Title preparation already consumes the supplied draft rather than a transcript. Computer status already shares pending preparation and retains a generation-checked runtime; 251 status calls, including 50 concurrent calls, started one synthetic process. Neither side endpoint changed. Their rig mocks isolated model completion and native process readiness, so these timings exclude provider admission/auth/network inference, managed desktop acquisition, and native startup. Branch timings exclude Gateway queueing and production load; no deployment was performed. Existing exact session/watermark metadata reads remain synchronous.
Validation used provider
blacksmith-testbox, profileopenclaw-check:tbx_01m34931f103srtpjakpj3gfzx(run): the original regression failed as expected; 111 branch/summary/cold-lifecycle/Gateway RPC cases and both side-phase cases passed after the optimization. Commands usednode scripts/run-vitest.mjswith the branch, branch-summary, cold-lifecycle, sessions-rewind, sessions-rewind.storage, and temporary phase files, with--maxWorkers=1.tbx_01m34a0zjh0t9h7m88wqg1be6t(run): finalpnpm test src/config/sessions/lane110-branches.perf.test.ts src/config/sessions/session-accessor.sqlite-branches.test.ts --maxWorkers=1passed all 20 cases in 44.93s wall including worker compilation. The changed branch file has 19 cases totaling about 10.7s test time. This run supplies the paired branch numbers above.The first lease needed dependency installation and later hit full-sync timeouts; it was retired and replaced, with only one active lease. An initial unpinned
check-changedselected unrelated differences against the hydration checkout's newerorigin/mainand failed their line-count ratchets. The final check uses the actual base SHA and the three intended paths. Temporary measurement rigs are excluded from the PR.The pinned check (
node scripts/check-changed.mjs --base 55995369eca380466fb87a0f08fba89dee91093b --head 55995369eca380466fb87a0f08fba89dee91093b -- <three changed paths>) completed core typechecking, all 25 test typecheck shards, ratchets, formatting, config-doc validation, and dead-export checks. It then found an import-name shadow in the new test; that import was renamed. The failed lint and every remaining planned guard passed when rerun directly, reusing the completed checks for this mechanical rename. Both new regressions passed again (19.79s command wall, 1.37s test time combined). This final run includedrun-oxlint.mjs, the native-state schema guard, database-first/media/sidecar/import-cycle guards, and webhook/pairing guards. All Testbox leases are stopped.CI failure investigation and replay evidence
The failed job tested merge commit
bd1cd7a53e9be7f7b4bf7aeea1a8c0824d7fb61a. Its database-worker shard passed 319 cases and failed one in 359.44s. The remaining row haddeliveryStartedAt, zero retries, and no acknowledgement/settlement marker; the failed queue assertion ran before the chat-marker assertion, so the log does not establish whether a reply arrived.blacksmith-testboxleasetbx_01m34d2qsxr974wcqarkh9ga90: replayed the exact merge commit and recorded 23-file group with the effective CI setting of two Vitest workers. All 325 cases passed; database-worker shard 179.17s, delivery case 13.337s overall. Command: the repository'sscripts/ci-run-node-test-shard.mtswith the captured group plan.taskset -c <two allowed CPUs> pnpm test src/gateway/session-delivery-clock-jump.integration.test.ts --maxWorkers=1. Only temporary phase logging was added in the disposable remote checkout; assertions and timeouts stayed unchanged.blacksmith-testboxleasetbx_01m34dykp2ws95fmzf3qza52rz: the full recorded group constrained to two CPUs also passed all 325 cases. Database-worker shard 209.94s; delivery startup 8.423s, release 9.825s, settlement 15.705s; one provider request. Command:taskset -c <two allowed CPUs> node --import ./scripts/tsx.mjs scripts/ci-run-node-test-shard.mtswith the captured group plan.Two intervening replay attempts failed during Blacksmith full sync before tests began; the lease was replaced. A main-thread/worker clock-skew hypothesis was investigated, but no applicable failing lease path or causal link was established. The original CI stall remains unexplained after this bounded investigation. The performance patch is unchanged, and the diagnostic scripts/logging are not part of the PR. ClawSweeper also found no blocking correctness findings on the pushed head.