Repository navigation
perf(sqlite): trim reader admission and transaction envelopes - #166074
Conversation
Share the first agent admission probe and shared-state read scope, use single-statement transcript snapshots, and reuse existing read transactions. Fuse hot/cold watermark queries and avoid redundant busy-timeout restoration and inherited-deadline probes. Preserve foreign-commit freshness, pinned snapshots, write FIFO and live authority. No schema, index, retention, durability, or SDK contract changes.
Keep the combined watermark query private in its original declaration owner. Retain the one-statement snapshot while leaving the hot-only module and indirectly reachable SDK signatures unchanged.
|
🦞👀 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 changes before merge. Reviewed October 6, 2026, 7:30 AM ET / 11:30 UTC (Revision 3). ClawSweeper reviewWhat this changesThe PR reduces SQLite freshness probes and transaction bookkeeping for session reads while preserving existing snapshots and write-admission behavior. Merge readiness⛔ Needs changes before merge - 1 item remains This PR retains useful optimizations beyond the merged sibling work. Source review found no actionable correctness or security defect; the previously identified validation prerequisite remains unfinished in the captured evidence. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw stores session transcripts and metadata in per-agent SQLite databases. Readers supply history and freshness information to chat processing, while transaction helpers coordinate writes and lock admission. flowchart TD
A[Chat and history requests] --> B[Agent database admission]
B --> C[Session readers]
C --> D{Read shape}
D --> E[Single statement snapshot]
D --> F[Composite transaction snapshot]
E --> G[Transcript and metadata results]
F --> G
Before merge
Agent review detailsSecurityNone. PR surfaceSource -2, Tests +98, Docs +10. Total +106 across 18 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep admission and snapshot decisions with their existing owners, eliminating redundant controls while preserving consistency, stored data, and lock budgets. Do we have a high-confidence way to reproduce the issue? Not applicable as a bug reproduction: this is a performance optimization, and source inspection establishes the redundant controls it removes. Is this the best way to solve the issue? Yes. The patch reuses existing admission and snapshot owners, retains transactions for composite reads, and introduces no competing cache or persistence contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f19013d9deec. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
Preserve the landed combined transcript watermark query and cold/hot precedence coverage while retaining statement snapshots, shared freshness scopes, and the original write deadline policy. Post-integration P2 review is scoped-clean; core production types, formatting, and import-cycle checks pass.
Preserve the shared-state admission and operation freshness scope now owned by main. Keep the remaining transaction-envelope changes and their regression coverage. Fresh P2 review is scoped-clean; focused state and entry-reader tests pass.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Include the existing main fix for the inherited canonical-schema rejection in the Copilot rollback test. The PR delta remains the same 18 reader and transaction-envelope files; the merge is conflict-free and fresh P2 review is scoped-clean.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
…aw#166074) * perf(sqlite): trim reader admission and transaction envelopes Share the first agent admission probe and shared-state read scope, use single-statement transcript snapshots, and reuse existing read transactions. Fuse hot/cold watermark queries and avoid redundant busy-timeout restoration and inherited-deadline probes. Preserve foreign-commit freshness, pinned snapshots, write FIFO and live authority. No schema, index, retention, durability, or SDK contract changes. * fix(sqlite): preserve reachable watermark SDK declarations Keep the combined watermark query private in its original declaration owner. Retain the one-statement snapshot while leaving the hot-only module and indirectly reachable SDK signatures unchanged.
What Problem This Solves
Chat turns execute avoidable SQLite freshness probes and transaction controls. New agent readers probe freshness twice during admission, point transcript reads open explicit transactions, and pure nested transcript reads create savepoints inside an existing snapshot.
User Impact
Session reads do less SQLite bookkeeping while preserving stored data, consistency, and write-admission guarantees.
Why This Change Was Made
Share the initial agent-admission probe, use statement snapshots for point statistics, mutation clocks, pending archives and retained watermarks, and let pure transcript readers join the caller's transaction. Restore temporary busy policy once after write admission and reuse inherited lock deadlines without an unused timeout query.
Main already owns the combined hot/cold watermark query (#166041) and the shared-state admission/query freshness scope (#166053). Integration preserves those implementations and removes their duplicate production hunks from this PR. General write transactions retain BEGIN IMMEDIATE, rollback savepoints, FIFO, live transaction/commit authority, original lock budgets, and accepted-write settlement.
No schema, index, persistent cache, retention, durability, worker service, environment name, or SDK contract changes. Updates and persisted-state admission policy are unchanged; no published-driver migration cell is required.
Evidence
Current candidate:
146a71a92f308b2a6acd5a105116c4a4eb3f2f5c, integrated with mainb2fab204731e3e4e3f3bab2d46d910115494ad3fusing merge commits. Both watermark conflicts preserve main's combined query and cold/hot precedence coverage. The later state-reader conflict preserves main's result wrapping around the same synchronous freshness scope.node scripts/run-vitest.mjs <focused paths> --maxWorkers=1, 791.37 s wall); 57 additional transaction/import tests passed in 44.47 s. This includes runtime-process-build-graph, get-reply/history/reconciliation import closures, deadline/restoration, peer-commit freshness, WAL snapshots, archive settlement, FIFO and authority revocation.v2026.10.1-beta.1: exported signatures, sync/async behavior, parameters, callback shapes and export availability are unchanged, including reachablerunSqliteImmediateTransactionandopenOpenClawAgentDatabaseReadOnly. No compatibility adapter or deprecation record is required. The generated exact-base/head API comparison completed successfully in 1,560.20 s and reports no Plugin SDK API changes (digestff7b090f); no acknowledgement waiver or normalizer change was used.The three requested phase medians improve; the historical first-turn regression is absent in this matched comparison.
busy_timeoutmedians are first turn 173→163, warmed turn 93.1→94.4, and compaction 31→31; no aggregate warmed busy-timeout reduction is claimed. Warmed main/worker/helper medians are 7.1/3,054.0/32.0→8.7/2,961.0/30.8 (component medians need not sum to the median total). All target phases have zero execution/prepare errors. Each side records three unsuccessful BEGIN IMMEDIATE attempts during successful shutdowns, excluded by the fixed observer contract. All fixture processes exited and tracked source stayed clean. The campaign remains above its 500-statements-per-warmed-turn target.Hosted CI on
51d4370failed the Copilot journal rollback fixture before its intended failure injection: the persistentfail_copilot_tool_resulttrigger violated canonical schema admission. The test blob is identical on baseline and candidate (a5bfc8c7f524170449ec705504152c5d2836bcd2); main already fixed it inb2fab204731e3using the existing worker-local TEMP fault fixture while retaining the injected-error and complete-group rollback assertions. This integration includes that fix. CI run 37453164206 had one failed test job plus the aggregate gate and 62 fail-fast cancellations; those cancellations are not passing coverage. No CI rerun or admin exception was used. The earlier PR-description check failure was corrected by matching the current template headings, and its replacement check passed.Current-head CI run 37456193481 reported a 30-second agent.wait client timeout in the startup-recovery WebChat test; 68 jobs passed and 16 were cancelled by fail-fast. The same failure independently occurs in scheduled main job 112247264184, at the same line 323 / caller 329 with CLIENT_TIMEOUT, method agent.wait, timeoutMs 30000 and requestSent true. Its 54.811-second test duration is below the outer budget. Sixteen causal test/wait/queue/client paths are byte-identical across the actual CI baseline, PR, tested merge, scheduled main and inspected current main.
The race predates this PR: #165156 used a terminal wait to synchronize queue insertion; #165996 correctly made that insertion nonterminal. An early waiter is therefore not awakened by queue registration, and its client deadline can precede the equal server deadline while the test deliberately holds recovery. Five serial local file runs on each revision were completed without edits: PR run 3 reproduced the exact CI error; four other PR runs and all five baseline runs exceeded the outer 90-second budget under host load, sometimes with 11 skills watchers reported during teardown. Those outer timeouts are inconclusive, not matching main reproductions. The scheduled-main log supplies independent inheritance proof.
This failure is qualified for the explicitly authorized native inherited-failure route. The evidence binds run attempt 1, actual checkout e889011859eb3561a81a9f19c536ce9fd67f396e (parents ace67a3 / 146a71a), the single failed test job, its aggregate gate, and all 16 monitor-caused cancellations. Cancelled work is not passing coverage. No CI rerun was requested. A separate fixture follow-up can use the existing dispatch-settlement observer before the queued-state probe; no larger timeout or weaker assertion is needed.
The prior local large-graph timeout remains unexplained. The unchanged case passed on Linux Testbox in 1.864 s as part of 76 passing tests (run 37436198513); that replay is not claimed as a fix. No timeout or assertion was relaxed.
Historical pre-integration measurement
Original baseline
4304c49a8ea76, candidatef54374536873c; three fresh fixtures and ten warmed turns per revision. Median all-thread SQL executions: warmed turn 2,733.4 → 2,636.4; first turn 6,840 → 6,927; compaction 902 → 844; full workload 52,658 → 51,345. First-turn and aggregate busy-timeout counts increased, so no first-turn improvement is claimed from those samples. The completed matched integration measurements above replace this historical comparison for landing.Campaign overlaps include #165680, #165552, #165885, #165895, #165890, #165901, #165859, #165894, #165904, #165921, #162433, #166041, #166053 and #166054. Hunks remain focused on reader/transaction envelopes and preserve landed sibling behavior. The original base includes #165804's unrelated cleanup. Release-note context: reduce redundant SQLite admission and transaction work during session reads without changing stored data or concurrency guarantees.