Skip to content

perf(boards): reduce read latency under host load - #166403

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-board-get-latency-20260919
Oct 7, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-board-get-latency-20260919

Conversation

@steipete

@steipete steipete commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

board.get opens a write-capable SQLite publication for every durable snapshot, including empty boards. Repeated host/worker handshakes amplify event-loop delays. Widget-document reads pay the same cost.

User Impact

Faster Board reads under host load, with unchanged response shapes and per-principal authorization. No schema, stored-data, configuration, or update migration is required.

Why This Change Was Made

Move the existing read kernels into the retained session-history read worker and delete the writer backend's read mode. Preserve writer FIFO consumption, logical and physical identity checks, native mutation fencing, and live Gateway authority before disclosure. Retain canonical and requested paths so closing either revokes an alias-backed reader. External consumer promises release the FIFO before settling; incognito keeps its existing owner.

The reader owns connection admission and retirement. Each operation reads a fresh coherent SQLite snapshot; no result cache is added. Freshly decoded snapshots no longer receive another deep copy.

A small test-only CI repair replaces a type namespace with an equivalent inline module type query in the existing exact-allowlist mock. The original syntax caused seven false Knip findings for live auth-profile exports. All production exports and scanner rules remain intact.

Evidence

Real board.get handler, identical synthetic SQLite fixtures, Linux x64 / Node 26.8.1, 100 warm calls per row. Four widgets contain 127,004 stored HTML bytes; responses contain metadata only. Pressure adds 10 ms of synchronous host work between worker replies.

Fixture Before mean / p99 After mean / p99
Empty, ordinary 5.59 / 10.23 ms 3.28 / 18.79 ms
Four widgets, ordinary 8.25 / 13.45 ms 2.97 / 9.18 ms
Empty, host pressure 88.06 / 101.93 ms 11.28 / 51.23 ms
Four widgets, host pressure 87.19 / 93.32 ms 13.43 / 27.25 ms

The pressured empty read went from about eight host-work turns per request to fewer than one on average. Ordinary cold reads were 1,489 → 668 ms empty and 1,222 → 593 ms populated. The rig was shared: ordinary empty-board p99 worsened, and pressured candidate maxima reached about 200 ms. The timed fixture starts at the handler; network and Gateway request admission are outside these numbers. Production latency still needs deployment measurement.

Validation: 77 tests across eight Board/Gateway/history-reader files passed on the authorized Linux rig fallback (401.22 s wall); pnpm build passed (7m 37.6s). Blacksmith Testbox tbx_01m4a42mhardevcc2hy4rmrbdn, profile openclaw-check, passed the 25-test Board worker file (46.84 s wrapper wall / 29.11 s Vitest; 74.458 s remote command including verification). Final-head Testbox tbx_01m4a7m2jdg99q27caxj1xg28a passed all 19 Gateway boundary/ownership/shutdown cases (90.63 s wrapper wall / 88.13 s Vitest; 114.582 s remote command). These replace the earlier rig Gateway runs as the final Gateway proof. The two exact-allowlist cases passed (14.27 s wrapper wall). Independent P0–P2 reviews passed for both the implementation and CI repair.

The full changed gate passed production checks and all 27 test typecheck projects, then exposed the inherited Knip failure. The exact seven findings reproduced on the unchanged parent. After the typing repair, staged checks, all three Knip scans, original Board lint, and every remaining schema/storage/import/webhook/pairing guard passed on the same Testbox. No skip flags or baseline exceptions were used. Both new regressions have negative controls: the original writer-publication read fails its guard; omitting alias registration permits disclosure after canonical close, while the corrected reader rejects it.

Production LOC: +8 net (+127 / -119). Board-specific runtime shrinks by 69 lines; two typed request/reply operations with captured database identity and their admitted dispatch add 77 lines to the existing reader. That transport contract accounts for the growth. The old read publication, execution capture/cleanup, and redundant copy are removed completely.

Commands and provenance

Testbox verified the source SHA and changed-file bytes before execution. The initial two leases queued; the first disappeared and the second was stopped before a head change. The third lease above ran the Board/check proof, and the fourth ran the final-head Gateway proof. Both were stopped after proof.

node scripts/run-vitest.mjs src/boards/sqlite-board-store.worker.test.ts --maxWorkers=1
node scripts/check-changed.mjs --base 27ba9720f2c5bad0326fee928ddb562340e0517d --head f1087c72b166bb8489f731c2c2b165c897c720f0
node --import tsx scripts/check-deadcode-exports.mts # unchanged-parent reproduction
node scripts/run-vitest.mjs src/auto-reply/reply/model-selection.exact-allowlist.test.ts --maxWorkers=1
node scripts/check-changed.mjs --staged # CI repair: passed

The remaining original gate commands ran directly: changed-file oxlint, native state schema version, database-first legacy stores, media download helpers, runtime sidecar loaders, import cycles, webhook body order, pairing-store grouping, and pairing account scope. All passed.

Rig focused command:

node scripts/run-vitest.mjs src/boards/sqlite-board-store.worker.test.ts src/boards/board-store.test.ts src/boards/board-store.native.test.ts src/boards/sqlite-board-store.incognito.test.ts src/gateway/board-store.test.ts src/gateway/server-methods/board.runtime-boundaries.test.ts src/gateway/server-close.board.test.ts src/config/sessions/session-transcript-worker-readers.test.ts --maxWorkers=1
pnpm build

Measurements and rig proof used base 4e9a106d1a2. Testbox checked the rebased source and the staged CI repair. Both final commits preserve the reviewed patch IDs. Earlier rig changed-check runs were stopped when superseded; they are not claimed as passing gates. Final-head CI run 37567730575 passed on bb5e0f3f68c59abe5994e5878a7ba128055080f8; CodeQL, critical quality, OpenGrep, and security review also passed. All Testbox leases are stopped/gone, and both task-owned rig worktrees are removed.

@clawsweeper

clawsweeper Bot commented Oct 7, 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: L labels Oct 7, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 Oct 7, 2026
@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 11:44 PM ET / October 7, 2026, 03:44 UTC (Revision 2).

ClawSweeper review

What this changes

Board snapshots and widget documents use the retained session-history reader to reduce database handshakes, with updated boundary tests, architecture documentation, and a test-only typing repair.

Warning

SQLite table change

This PR modifies persisted SQLite tables in src/boards/sqlite-board-store.ts. Prefer a design that avoids changing persisted SQLite tables. Migration or upgrade compatibility proof is recorded, but maintainers should still confirm that the schema change is necessary.

Merge readiness

✅ Ready for maintainer review

The optimization remains useful on current main, and no blocking patch defect was found. The earlier migration-proof concern does not apply: the patch preserves the stored format and existing read kernels.

Priority: P2
Reviewed head: bb5e0f3f68c59abe5994e5878a7ba128055080f8

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, maintainable optimization with useful handler measurements, meaningful boundary coverage, and no identified blocking defect.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The captured before/after board.get measurements exercise the changed Board store and real SQLite reader on Linux under ordinary and injected host load, showing substantially lower pressured latency. Boundary regressions supplement this evidence. Source inspection verifies unchanged stored formats and kernels, so no data migration is required.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured before/after board.get measurements exercise the changed Board store and real SQLite reader on Linux under ordinary and injected host load, showing substantially lower pressured latency. Boundary regressions supplement this evidence. Source inspection verifies unchanged stored formats and kernels, so no data migration is required.
Evidence reviewed 10 items Introduced read path: The introduced path retains canonical and requested database paths, joins the existing writer FIFO, checks physical identity, reader revocation, and native mutations, then starts consumption. External consumer promises settle outside the FIFO.
Verified no-migration case: The new worker operations invoke the unchanged Board read kernels inside a deferred read transaction. No schema, serialized row format, persistence writer, config default, or migration changes are introduced; missing Board tables retain their existing empty-read behavior. This resolves the previous review's generic upgrade-proof concern.
Disclosure safeguards: The unchanged Gateway handler checks request authority after the snapshot await, after sandbox startup awaits, before ticket issuance, and immediately before responding. The patch does not introduce a transferable authorization value or expand permitted principals.
Findings None None.
Security None None.

How this fits together

Boards stores session widgets in per-agent SQLite databases. Gateway requests read snapshots and documents through the Board store, then apply current authorization before returning data or issuing view tickets.

flowchart TD
  A[Gateway Board request] --> B[Capture session and database]
  B --> C[Shared writer FIFO]
  C --> D[Retained read worker]
  D --> E[Coherent SQLite snapshot]
  E --> F[Identity and authority checks]
  F --> G[Snapshot or widget document]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +8, Tests +123, Docs +2. Total +133 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 5 127 119 +8
Tests 4 210 87 +123
Docs 1 9 7 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 346 213 +133

Review metrics

Metric Value Why it matters
Production versus test growth production +8 net, tests +123 net The small production increase is justified by two typed operations in the existing reader while removing the former Board read publication.

Stored data model

Persistent data-model change detected: unknown-data-model-change: src/boards/sqlite-board-store.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Technical review

Best possible solution:

Retain one read-worker owner for durable Board reads while preserving existing kernels, FIFO consumption, and live disclosure checks.

Do we have a high-confidence way to reproduce the issue?

Not applicable as a correctness-bug reproduction; the supplied real-handler benchmark establishes a concrete latency scenario, and current-main source confirms the extra publication handshakes.

Is this the best way to solve the issue?

Yes. Reusing the existing read owner and kernels removes the measured overhead without adding a competing cache or changing persistent data.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 30d563e262aa.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded Board latency improvement with measured benefits under host pressure and no established urgent regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured before/after board.get measurements exercise the changed Board store and real SQLite reader on Linux under ordinary and injected host load, showing substantially lower pressured latency. Boundary regressions supplement this evidence. Source inspection verifies unchanged stored formats and kernels, so no data migration is required.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured before/after board.get measurements exercise the changed Board store and real SQLite reader on Linux under ordinary and injected host load, showing substantially lower pressured latency. Boundary regressions supplement this evidence. Source inspection verifies unchanged stored formats and kernels, so no data migration is required.

Evidence

What I checked:

  • Introduced read path: The introduced path retains canonical and requested database paths, joins the existing writer FIFO, checks physical identity, reader revocation, and native mutations, then starts consumption. External consumer promises settle outside the FIFO. (src/boards/sqlite-board-store.ts:509, bb5e0f3f68c5)
  • Verified no-migration case: The new worker operations invoke the unchanged Board read kernels inside a deferred read transaction. No schema, serialized row format, persistence writer, config default, or migration changes are introduced; missing Board tables retain their existing empty-read behavior. This resolves the previous review's generic upgrade-proof concern. (src/config/sessions/session-history-read-operation.worker.ts:104, bb5e0f3f68c5)
  • Disclosure safeguards: The unchanged Gateway handler checks request authority after the snapshot await, after sandbox startup awaits, before ticket issuance, and immediately before responding. The patch does not introduce a transferable authorization value or expand permitted principals. (src/gateway/server-methods/board.ts:123, bb5e0f3f68c5)
  • Regression and lifecycle coverage: Inspected tests cover read-only publication, target changes, native mutation, canonical-close revocation through an alias, queued read/write ordering, shared-store routing, and Gateway shutdown. The supplied body records passing runs and negative controls; this read-only review did not execute tests. (src/boards/sqlite-board-store.worker.test.ts:663, bb5e0f3f68c5)
  • Real handler measurements: The captured PR body reports the real board.get handler on Linux x64 / Node 26.8.1 using identical SQLite fixtures and 100 warm calls per scenario. Under injected host pressure, empty-board mean latency fell from 88.06 to 11.28 ms and populated-board mean from 87.19 to 13.43 ms. Network admission was excluded, ordinary empty-board p99 worsened, and deployment latency remains outside these claims.
  • Current-main necessity: Fetched main still uses the write-capable Board read publication and its execution/cleanup handshakes. The proposed retained Board reader remains distinct work. (src/boards/sqlite-board-store.ts:511, 30d563e262aa)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; 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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-07T02:51:43.158Z sha f1087c7 :: blocked before merge. :: none

Serve durable Board snapshots and widget documents through the retained session history reader. Preserve writer FIFO consumption, live authority, physical identity, and close revocation while removing the write-capable read publication and redundant snapshot copy.
Use an inline module type query in the exact-allowlist pass-through mock. The type-only namespace triggered seven false full-tree Knip findings for live fallback exports. The same failure reproduced on the unchanged parent; the corrected test, export scans, and changed checks pass.
@steipete
steipete force-pushed the steipete/perf-micro-board-get-latency-20260919 branch from f1087c7 to bb5e0f3 Compare October 7, 2026 03:37
@steipete
steipete marked this pull request as ready for review October 7, 2026 03:39
@steipete
steipete enabled auto-merge (squash) October 7, 2026 03:41
@steipete
steipete merged commit 0be7509 into main Oct 7, 2026
198 of 200 checks passed
@steipete
steipete deleted the steipete/perf-micro-board-get-latency-20260919 branch October 7, 2026 03:48
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 7, 2026
* perf(boards): reduce read latency under host load

Serve durable Board snapshots and widget documents through the retained session history reader. Preserve writer FIFO consumption, live authority, physical identity, and close revocation while removing the write-capable read publication and redundant snapshot copy.

* test(models): avoid false unused auth runtime exports

Use an inline module type query in the exact-allowlist pass-through mock. The type-only namespace triggered seven false full-tree Knip findings for live fallback exports. The same failure reproduced on the unchanged parent; the corrected test, export scans, and changed checks pass.
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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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