Repository navigation
perf(sqlite): batch placement and session metadata reads - #166053
Conversation
Collect placement facts in one statement per batch, carry Board presence in exact-entry reads, and reuse ACP rows under the admitted connection revision. Keep snapshot consistency, foreign-commit freshness, native integer range checks, and transaction-held ownership validation while removing repeated reads.
|
🦞👀 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. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 6:38 AM ET / 10:38 UTC (Revision 4). ClawSweeper reviewWhat this changesThe PR reduces repeated SQLite reads by batching worker-placement facts, caching unchanged ACP session metadata, combining Board presence with session reads, and reusing supplied writer handles. Merge readiness✅ Ready for maintainer review The optimization remains useful and distinct from merged sibling work. No actionable correctness or security defect was found in the introduced diff; the supplied runtime evidence supports the performance claim. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw reads shared control-plane and per-agent SQLite state while preparing chat turns and worker recovery. These readers supply session metadata, Board membership, and placement facts to existing runtime owners. flowchart TD
A[Chat turns and recovery] --> B[Existing database owners]
B --> C[Admission and freshness checks]
C --> D[Placement snapshot batches]
C --> E[ACP metadata reuse]
C --> F[Session and Board reads]
D --> G[Current runtime facts]
E --> G
F --> G
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +354, Tests +243, Docs +15. Total +612 across 19 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep the optimization within the existing read, revision, and transaction owners while preserving snapshot consistency and final write-authority checks. Do we have a high-confidence way to reproduce the issue? Not applicable as a bug reproduction: source confirms repeated reads on current main, and the supplied matched runtime campaign measures their reduction. No tests or target code were executed during this read-only review. Is this the best way to solve the issue? Yes. The patch reduces work through existing owners, preserves snapshot and invalidation contracts, and introduces no competing persistence or configuration surface. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against dea0ebb68779. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles) |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
…6053) Collect placement facts in one statement per batch, carry Board presence in exact-entry reads, and reuse ACP rows under the admitted connection revision. Keep snapshot consistency, foreign-commit freshness, native integer range checks, and transaction-held ownership validation while removing repeated reads.
What Problem This Solves
Problem: Warmed chat turns repeat shared-state and session metadata reads even when their connection revision is unchanged or their related facts can be selected together. On the pinned base, the shared campaign workload executes a median 2,740.8 SQLite statements per warmed turn across all threads.
Solution
BEGIN, removing its duplicate pre-transaction ownership read.The JSON projection preserves native rejection of unsafe SQLite integers. Current caller authority, physical store ownership, FIFO writes, and accepted-work settlement remain with their existing owners.
Impact
88.4 fewer statements per warmed turn (3.2%), with unchanged normal behavior. No schema, index, persistent-cache, retention, durability, or environment-name additions. Production LOC: +457 / −103 / net +354, across 10 files.
The SDK diff adds no entrypoints or direct exports. Two reachable implementation declarations gain compatible additions: the optional Board presence/read option and a placement row decoder. Existing calls remain compatible; the reviewed diff digest is
0a6019b8(130 dependent closure hashes).Evidence
Baseline
20306571364c5b8df244fba15e88727b2b7c7a0e→ candidate8ad5047fc0437cfbc599cc1569a8de9f0129f9ca. Three fresh fixtures per revision on the same restored harness, Node 26.10.0 / SQLite 3.53.4, with identical workload/observer/analyzer hashes. Counts include successful native statements on the Gateway, workers, and helper processes; these are statement counts, not latency measurements.Both calibrations produced 8 native calls, 2 prepares, 7 successful statements, and zero failures independently on the main thread and a worker. Every fixture completed all 13 top-level turns, the child turn, control-plane RPCs, cron, compaction, and clean shutdown with no fixture children remaining. Failed native attempts were confined to retried shutdown
BEGIN IMMEDIATEcontention: before 2/0/1, after 1/1/0; none occurred in the measured turn or compaction phases.EXPLAIN QUERY PLANretains indexed placement lookups and the existingboard_tabscovering index. No index addition was needed.Validation:
pnpm test … --maxWorkers=1, including zero-caller-thread-SQL boundaries, foreign commits, pinned snapshots, schema replacement, lifecycle binding, exact-key error isolation, and unsafe-integer refusal.node scripts/check-changed.mjspassed, including core and all 27 selected test typecheck groups;pnpm deadcode:knippassed; Madge and runtime import checks both report 0 cycles.Test cost and validation caveats
Measured command wall times include compilation and import costs on a heavily loaded host: initial focused group 378.6 s; expanded import/owner group 977.6 s; placement/ownership/ACP/exact-entry group 789.8 s; final Board/ACP/cron group 492.1 s; isolated archive import 158.6 s. Earlier fixture failures were repaired and their owning suites passed. The archive import suite hit its 180 s setup deadline in the expanded group and passed in isolation; no timeout was increased and no flake fix is claimed.
Final valid Vitest test-execution totals for materially changed files (excluding shared compile/import overhead):
session-meta-read.cache.test.tssession-accessor.sqlite-exact-read.test.tssession-entry-read.worker.test.tsplacement-move-schema.test.tsplacement-read-projection.worker.test.tsplacement-store.turn-claim-closure.test.tsopenclaw-state-db-injected-admission.test.tsopenclaw-state-ownership.test.tsThe longer existing suites exercise native worker admission, revocation, snapshots, and settlement; a mocked kernel would not prove those boundaries. Added cases reuse their existing fixtures and add no timers, polling, or per-test Gateway boots. Hosted CI seconds are pending the PR run.
The campaign remains above its <500/<200 targets. Schema/quarantine, transaction-envelope, participant/main-key, and transcript-watermark reductions remain separate work. Coordination/overlap: #166041, #165984 (placement test changes on newer main), #165680, #165552, #165885, #165895, #165890, #165901, #165859, #165894, #165904, #165921, and #162433. This PR is being landed through the native maintainer workflow under explicit maintainer direction.
Landing integration
Merged main
1e8b7a3623bca9dc8b83babbea1c3b001c1012d7, including sibling #166041, without conflicts ina57268275bc537a8befb048f46c4b9458754ea7a. The introduced scope remains 19 files. Fresh independent P2 autoreview and completed exact-head ClawSweeper review found no actionable defects. The measurements above remain evidence for the original measured head.Post-integration proof passed: core production typechecking, all 27 core test-type groups, and Madge (zero cycles). The SDK API comparison completed with digest
afaea76f: no entrypoint or direct export changes, 130 dependent closure changes, and the same two compatible additive declaration changes as the original report. The released-tag check preserves existing call shapes; the optional internal read argument adds no required capability or deprecation.Focused validation covered 117 distinct cases. The eight-file run passed 60 cases and timed out one Doctor case at its existing 120-second deadline (991.13s command wall time); the remaining two session files passed 56 cases (241.54s). The unchanged selected Doctor replay passed in 115.855s against that 120s limit (397.61s including preparation). The unauthorized rejection completes before the broad authorized preflight; the delay is in unchanged Doctor/plugin migration discovery. Its exact import/worker/scheduling cost remains uncertain. No timeout, assertion, or source change was made, and the replay is not claimed as a flake fix.
Integrated CI 37447469826 repeats two independently proven main failures: 15 Windows path-emulation cases in
src/state/openclaw-state-db.paths.windows.test.ts(job 112216278412), and 8 Windows inventory-migration cases insrc/state/openclaw-state-db-schema-repair.windows.test.ts(job 112216278891). The same cases failed earlier in scheduled main run 37437741118, jobs 112183782598 and 112183782443. All 16 relevant test/owner/setup inputs are unchanged between the tested main parent and PR merge tree. Five isolated runs of each file on the approved head and merge base passed on Node 26/macOS with--maxWorkers=1(230 cases); those passes do not establish a Linux CI fix.The successful fail-fast monitor cancelled 60 sibling jobs; their coverage remains unrun. The native inherited-failure admin route is explicitly authorized for this landing. Its evidence binds the exact head, run/attempt, failed cases, baseline logs, all cancellations, and tested merge
b42ccaa42ba4d94a514637618e2c27892c26aa91. Localgit merge-treeexactly reproduces that merge's tree. The original-head run 37443691750 had the same two failures and a downstream monitor timeout; it is historical evidence only.