Repository navigation
perf(chat): keep personal account startup off the writer queue - #167447
Conversation
Read committed personal-account summaries through the shared-state reader, removing the summary writer command while retaining ownership and current requester checks. Keep the synchronous SDK adapter on the same query. A synthetic 5,000-session rig with large transcripts reduced startup under 256 finite background writes from 211 ms average / 270 ms p95 to 8 ms / 11 ms. Add an occupied-writer regression and retain identity-merge proof.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR moves personal account summary reads to the existing independent database reader while preserving ownership checks and synchronous SDK compatibility. Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR addresses a remaining, measured startup bottleneck with an owner-backed change. No actionable correctness or security defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe Gateway prepares personal account labels when opening chats or selecting accounts. It reads committed SQLite data and publishes the summary after checking the current requester and account ownership. flowchart TD
A[Chat startup or account selection] --> B[Capture requester and database identity]
B --> C[Existing database read worker]
C --> D[Committed account data]
D --> E[Ownership checked summary]
E --> F[Recheck requester and authority]
F --> G[Publish label or reject stale request]
Technical reviewBest possible solution: Use the existing independent reader for committed account summaries, retaining current publication guards and the released synchronous adapter. Do we have a high-confidence way to reproduce the issue? Yes: current-main source places summary reads on the writer queue, and the supplied baseline/candidate regression exercises startup while that queue is occupied. This review did not execute the scenario. Is this the best way to solve the issue? Yes: the existing read worker absorbs the operation without adding a cache or competing query owner, while preserving the synchronous SDK contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 7b17e7b7bf81. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +38, Tests +72, Docs +7. Total +117 across 11 files. Added test files: 0. View PR surface stats
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed October 8, 2026, 4:55 PM ET / 20:55 UTC (Revision 2). |
…law#167447) Read committed personal-account summaries through the shared-state reader, removing the summary writer command while retaining ownership and current requester checks. Keep the synchronous SDK adapter on the same query. A synthetic 5,000-session rig with large transcripts reduced startup under 256 finite background writes from 211 ms average / 270 ms p95 to 8 ms / 11 ms. Add an occupied-writer regression and retain identity-merge proof.
What Problem This Solves
Opening a chat pinned to a personal model account waits behind unrelated shared-state writes just to display the account label. A cold summary read can also open the writer actor solely for this read.
User Impact
Chat startup and asynchronous personal account selection read committed account summaries independently of the writer queue. Account ownership, requester changes, profile merges, and source-generation validation still apply. No schema, stored-data, configuration, or upgrade changes.
Why This Change Was Made
The personal catalog already uses the shared-state read worker. Move its account summary there too and remove the summary writer command. Both async and synchronous reads use one ownership-checked query; the synchronous SDK link/select adapter remains supported until the next SDK major, as documented in
model-account-connect.ts.Production LOC: +38 (61 added, 23 removed). The existing worker transport requires typed command/result, validation, byte accounting, and dispatch; the documented synchronous SDK contract requires the native adapter. No new cache, worker, or competing query implementation.
Evidence
Synthetic rig through the actual
chat.startup/chat.historyhandlers: 5,000 other sessions, four 10,000-message transcripts, UI bounds of 80 messages / 256 KiB. Runs use real metadata projection, SQLite readers, and finite queued writes; no injected latency or deadlock. Measurements in milliseconds:Startup under writer load improves 26× on average. History under that load remains fast: 9.74 / 17.14 before and 7.42 / 12.42 after. Cold personal startup was 682.8 → 30.3 ms (one sample per build). Shared-runner idle timings vary; the writer-queue separation is the reproducible dominant improvement.
The UI already overlaps independent work and preserves subscribe-before-history ordering. For pinned accounts the handler starts metadata alongside pending-input/history reads, but metadata serially waits for the account summary. This removes that dominant wait at the state-read owner.
The baseline/candidate rig, tests, types, and build ran on Blacksmith Testbox
tbx_01m4ef8xae6e123jv2kx3akxzj, profileopenclaw-check, base6070074dabf6b45f74d4039590cd307640317862:node scripts/run-vitest.mjs src/gateway/server-methods/chat-startup-lane670.test.ts --maxWorkers=1): before and after passed; temporary fixture removed afterward. The first writer-load attempt lacked the fixture's required write-admission callback; it was corrected before the reported measurements.node scripts/run-vitest.mjs src/gateway/server-methods/chat-metadata-runtime.personal-accounts.test.ts src/gateway/model-account-connect.worker.test.ts --maxWorkers=1): 22 passed, 52.51 s wall including cold compiled-worker preparation. Test execution: 3.59 s personal-account metadata; 7.90 s account-worker suite. The new regression takes 1.02 s and requires the real read/write worker composition.src/talk/client-voice-session-store.ts: ClientVoiceToolEffect(also reported through thevoiceSessionStorenamespace). Runningnode --import ./scripts/tsx.mjs scripts/check-deadcode-exports.mtsafter removing the entire candidate patch and verifying a clean baseline reproduced exactly the same finding (exit 1). The fullpnpm buildpassed (6m 4.1s). Remaining downstream lint and all native-schema, database-store, media, sidecar, import-cycle, webhook, and pairing guards passed on the Linux rig (Ubuntu, Node 26.8.1, pnpm 12.5.1). Testbox had completed its lifetime before that final command; AWS and Hetzner admission both hit the shared fleet limit, so the authorized rig fallback finished the checks. Runtime bytes and measured production code are unchanged.This synthetic handler rig does not reproduce a production deadlock or establish that all seconds-long startup samples have this cause. No live provider calls, production state, or browser rendering were involved. Production attribution needs post-deployment telemetry. GitHub CI run 37842291152 passed on the exact published head: 586 s wall, 53 successful / 25 intentionally skipped checks. The selected Node jobs total 3,714 job-seconds (65–353 s each), including setup and broader selected suites; this is not the incremental cost of the two changed files.
The branch was rebased without changing the patch onto
524145e8be85901216150218df0b81bf88bb390e;git range-diffreports the commit unchanged. The same dead-export failure reproduced on this clean base. Both focused test files then passed at the exact published head0d4eaf76b810f82e941863f0da10d251f55ac9f5: 22 tests, 81.78 s Vitest wall / 85.55 s wrapper wall on the Linux rig.