Skip to content

perf(chat): keep personal account startup off the writer queue - #167447

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-chat-startup-tail-20260919
Oct 8, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-chat-startup-tail-20260919

Conversation

@steipete

@steipete steipete commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

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.history handlers: 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:

Personal-account startup Before avg / p95 After avg / p95 Samples per build
Idle, warm 16.60 / 24.26 6.15 / 14.62 30
256 background writer operations 211.05 / 269.65 8.10 / 11.05 20
Account-summary stage under writer load 200.45 / 257.25 1.28 / 2.07 20

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, profile openclaw-check, base 6070074dabf6b45f74d4039590cd307640317862:

  • Temporary handler rig (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.
  • Occupied-writer regression on unchanged production source: failed because startup waited until the unrelated write exhausted its SQLite lock wait. Candidate: passed, including successful settlement of that write.
  • Changed tests (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.
  • Sibling tests: 139 passed across 10 files (96.04 s total wrapper wall time). Export-name collision guard: passed. Eager-import / PR-wrapper source closure: 20 passed (26.47 s wrapper wall). Initial changed-file checks passed core types and 21 test graphs, then caught a fixture-only hostname literal widening. Corrected to the relay contract’s literal type; final core typecheck and all 27 test type graphs passed. The final changed-file gate stops at an inherited Knip finding: src/talk/client-voice-session-store.ts: ClientVoiceToolEffect (also reported through the voiceSessionStore namespace). Running node --import ./scripts/tsx.mjs scripts/check-deadcode-exports.mts after removing the entire candidate patch and verifying a clean baseline reproduced exactly the same finding (exit 1). The full pnpm build passed (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.
  • Independent review through P2 on the final staged source: scoped-clean.

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-diff reports the commit unchanged. The same dead-export failure reproduced on this clean base. Both focused test files then passed at the exact published head 0d4eaf76b810f82e941863f0da10d251f55ac9f5: 22 tests, 81.78 s Vitest wall / 85.55 s wrapper wall on the Linux rig.

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.
@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: S labels Oct 8, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 8, 2026
@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR moves personal account summary reads to the existing independent database reader while preserving ownership checks and synchronous SDK compatibility.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch preserves established contracts and has useful real-worker harness evidence, with limited end-to-end confidence.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored area change is outside the external-contributor proof gate. Supplied Testbox evidence exercises the summary reader through synthetic startup/history handlers and real SQLite workers, showing reduced writer-load latency; it remains in-process harness evidence. Source inspection verifies unchanged persisted formats, schemas, settings, and migration behavior.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Opening a chat with a personal account can wait behind unrelated database writes before displaying its account label.
Reason: The reported measurements identify a concrete queueing bottleneck. The established area owner's proposal reuses the existing reader and preserves account output and authority contracts.

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
Reviewed head: 0d4eaf76b810f82e941863f0da10d251f55ac9f5

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied handler rig does not exercise personal-account startup through a client connected to a running Gateway.
Agent review details

How this fits together

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

Technical review

Best 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

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Introduced cutover: The pinned introduced diff moves account summaries to the existing reader and removes the summary writer command; unrelated base-only voice changes are excluded. (src/state/user-model-account-operations.ts:174, 0d4eaf76b810)
  • Still necessary on current main: Fetched main still implements summary reads through the shared-state writer operation. The relevant account owners and publication callers have no changes since the merge base. (src/state/user-model-account-operations.ts:173, 7b17e7b7bf81)
  • Single ownership query: The worker runs the shared summary query inside a deferred transaction. It checks resolved ownership and returns account metadata without credentials; the synchronous adapter consumes the same query. (src/state/user-model-accounts.ts:299, 0d4eaf76b810)
  • Publication guards preserved: Chat publication rechecks account-link authority, the selected account, and the requester after awaiting the summary. Personal selection retains identity and live-connection checks; account mutations retain transaction and commit admission. (src/gateway/server-methods/chat-account-selection.ts:39, 0d4eaf76b810)
  • Meaningful concurrency regression: The added test holds a foreign SQLite writer, queues a real worker mutation, and requires startup to return the personal account label before releasing the writer, then checks successful write settlement. Existing identity-change coverage is adapted to the real reader. (src/gateway/server-methods/chat-metadata-runtime.personal-accounts.test.ts:36, 0d4eaf76b810)
  • Supplied performance and regression evidence: The complete PR body reports synthetic chat.startup/chat.history handler runs using real SQLite workers: startup under 256 background writes improved from 211.05 to 8.10 milliseconds on average. It reports the occupied-writer regression failing on unchanged production source and passing on the candidate, with 22 focused tests passing at the published head. It explicitly excludes running-Gateway, browser, and live-provider proof. No tests were executed during this read-only review. (0d4eaf76b810)

PR surface

Source +38, Tests +72, Docs +7. Total +117 across 11 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 8 61 23 +38
Tests 2 91 19 +72
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 159 42 +117

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The measured bottleneck affects personal-account startup under writer load without evidence of an urgent production outage.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-08T20:45:59.625Z sha 0d4eaf7 :: needs maintainer review before merge. :: none

Reviewed October 8, 2026, 4:55 PM ET / 20:55 UTC (Revision 2).

@steipete
steipete marked this pull request as ready for review October 8, 2026 20:49
@steipete
steipete enabled auto-merge (squash) October 8, 2026 20:50
@steipete
steipete merged commit cfe61f2 into main Oct 8, 2026
215 of 218 checks passed
@steipete
steipete deleted the steipete/perf-micro-chat-startup-tail-20260919 branch October 8, 2026 20:59
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 9, 2026
…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.
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 gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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