Skip to content

perf(sessions): coalesce branch list reads before restoration - #155678

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-branches-list-restore-order-20260919
Sep 22, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-branches-list-restore-order-20260919

Conversation

@steipete

@steipete steipete commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

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-17 run failed in the existing session-delivery-clock-jump.integration.test.ts while 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 head 8a626aca5286a63c7ff25d941a53488c9eff22ee; the CI and security gates passed. Squash auto-merge completed as b476ed92ba176bf714050c21a2b1648bcfda91d3 without 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.

Measurement Before p50 / p90 (ms) After p50 / p90 (ms)
Branch accessor, warm cache hit 0.141 / 0.209 0.107 / 0.169
Branch accessor, three concurrent cache misses (whole group) 4.933 / 6.871 1.987 / 4.145
sessions.title.prepare, warm handler overhead 0.546 / 0.954 0.543 / 0.992
computer.status, warm handler overhead 0.00394 / 0.00637 0.00371 / 0.00482

Warm 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, profile openclaw-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 used node scripts/run-vitest.mjs with the branch, branch-summary, cold-lifecycle, sessions-rewind, sessions-rewind.storage, and temporary phase files, with --maxWorkers=1.
  • tbx_01m34a0zjh0t9h7m88wqg1be6t (run): final pnpm test src/config/sessions/lane110-branches.perf.test.ts src/config/sessions/session-accessor.sqlite-branches.test.ts --maxWorkers=1 passed 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.
  • Independent review through P2 is clean after preserving final lifecycle validation on cache hits and adding a deterministic lifecycle-race regression. Coalesced close/revocation, lifecycle replacement, caller mutation isolation, existing append/rewrite/replacement invalidation, cold restoration, and incognito behavior are covered.

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-changed selected unrelated differences against the hydration checkout's newer origin/main and 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 included run-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 had deliveryStartedAt, 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-testbox lease tbx_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's scripts/ci-run-node-test-shard.mts with the captured group plan.
  • Same lease: isolated delivery test with the process constrained to two CPUs passed. Startup 24.871s; claim release 26.398s; settlement 31.313s from fixture start; one provider request. Command: 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-testbox lease tbx_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.mts with 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: S maintainer Maintainer-authored PR labels Sep 22, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 22, 2026
@clawsweeper

clawsweeper Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 22, 2026, 7:03 AM ET / 11:03 UTC.

ClawSweeper review

What this changes

The 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
Reviewed head: 8a626aca5286a63c7ff25d941a53488c9eff22ee

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with meaningful lifecycle regressions and no blocking defects found in source review.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored PR is exempt from external-contributor proof requirements. Its captured evidence describes synthetic runs through the branch accessor and workers, with explicit deployment limits; no stored-data contract changes require migration proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored PR is exempt from external-contributor proof requirements. Its captured evidence describes synthetic runs through the branch accessor and workers, with explicit deployment limits; no stored-data contract changes require migration proof.
Evidence reviewed 8 items Pinned introduced change: Reviewed the complete merge-base-to-head patch. It adds an in-flight map keyed by database identity, connection incarnation, session lifecycle, and transcript watermark; entries are removed on settlement.
Current-main necessity: Current main still enters restoration before checking the summary cache and independently dispatches concurrent misses. The proposed optimization is absent.
Latest-release comparison: The v2026.9.5 accessor also invokes restoration before cache lookup and has no pending-read coalescing.
Findings None None.
Security None None.

How this fits together

Chat 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +20, Tests +52, Docs +3. Total +75 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 60 40 +20
Tests 1 62 10 +52
Docs 1 8 5 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 130 55 +75

Review metrics

None.

Technical review

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

Labels

Label changes:

  • add P2: This is a bounded performance improvement for concurrent chat viewers, with no demonstrated urgent outage.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer-authored PR is exempt from external-contributor proof requirements. Its captured evidence describes synthetic runs through the branch accessor and workers, with explicit deployment limits; no stored-data contract changes require migration proof.

Label justifications:

  • P2: This is a bounded performance improvement for concurrent chat viewers, with no demonstrated urgent outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer-authored PR is exempt from external-contributor proof requirements. Its captured evidence describes synthetic runs through the branch accessor and workers, with explicit deployment limits; no stored-data contract changes require migration proof.

Evidence

What I checked:

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

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 enabled auto-merge (squash) September 22, 2026 11:37
@steipete
steipete merged commit b476ed9 into main Sep 22, 2026
354 of 356 checks passed
@steipete
steipete deleted the steipete/perf-micro-branches-list-restore-order-20260919 branch September 22, 2026 11:51
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant