Repository navigation
fix: prevent SQLite lock races in chat metadata tests - #166520
Conversation
Setup upserts can leave automatic maintenance holding the WAL write lock while it waits for the host's admission grant. Raw fixture writes on that same host can then block the grant. Drain setup-owned database work before warming exact or full caches, and assert that the fixture has no asynchronous database resources left.\n\nThe lock window reproduces on both Bun pins and Node 24/26. No production SQLite policy changes.
|
🦞👀 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 changes before merge. Reviewed October 7, 2026, 4:31 AM ET / 08:31 UTC (Revision 2). ClawSweeper reviewWhat this changesThe PR drains setup-owned database work before warming chat metadata caches and asserts that no asynchronous database resources remain. Merge readiness⛔ Needs changes before merge - 1 item remains Keep open: this is a focused, useful fixture repair that current main does not contain. No introduced correctness or security defect was found; the prior flake-qualification requirement remains outstanding. Priority: P2 Review scores
Verification
How this fits togetherGateway chat metadata supplies session-specific commands and model choices to clients. These tests mutate SQLite session rows during metadata preparation to verify cache freshness and access checks. flowchart TD
A[Seed session rows] --> B[Drain setup database work]
B --> C[Reopen database and warm caches]
C --> D[Prepare chat metadata]
D --> E[Mutate session rows]
E --> F[Check freshness and access]
F --> G[Return metadata or reject changed access]
Before merge
Agent review detailsSecurityNone. PR surfaceTests +3. Total +3 across 1 file. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep raw-write cache coverage deterministic through the existing database lifecycle owner, without changing production locking, retries, or metadata authorization. Do we have a high-confidence way to reproduce the issue? Yes: the recorded maintenance-admission probe identifies the lock cycle, and current main retains the undrained fixture setup. This review inspected the source but did not execute a current-main reproduction. Is this the best way to solve the issue? Yes: draining setup work before cache capture repairs the fixture's lifecycle boundary while preserving its intentional raw writes and freshness checks. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 66d898f6662a. 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
HistoryReview history (1 earlier review cycle)
|
|
Accepting the deterministic proof for this one-file fixture repair. The controlled maintenance window reproduces the same WAL write-lock failure on Bun 667c, Bun fc53, Node 24, and Node 26. Removing only the drain makes the new lifecycle regression fail on next Bun and Node 24; the drained fixture passes all 89 cases on all four runtimes, with final main-based proof also green on both Bun pins and Node 24. This directly checks the unsafe ordering rather than relying on nondeterministic repetitions. Additional repetition evidence will come from the planned Gateway-methods admission qualification: the original owner, including this file, will run five times per runtime on the next pin with this fix included. A separate 20 standalone / 3 shard campaign is not required for this fixture-only repair; the deterministic proof is accepted, and the planned qualification avoids duplicate CI spend. No whole-owner qualification is claimed by this PR; the fixture repair is ready to land. |
|
Merged via squash.
|
Main now drains setup maintenance before warming the metadata caches. Remove the redundant write-admission wrapper and retain the raw fixture mutation covered by the upstream fix in #166520.
…penclaw#166520) Drain setup-owned session maintenance before warming the chat metadata fixture's exact or full cache, and assert that asynchronous database resources have settled. This prevents raw fixture SQL from blocking the host admission grant needed by a maintenance worker holding the WAL write lock. The controlled lock window reproduces across both Bun pins and Node 24/26. The negative control fails without the drain, and the complete fixed fixture passes 89/89 across all four runtimes. Final main-based Node/Bun proof, changed-file checks, independent review, and exact-head CI passed. Production SQLite policies are unchanged. Fixes openclaw#166505.
Closes #166505.
What Problem This Solves
Fixes SQLite lock races in the
chat.metadataexact/full cache tests when fixture seed writes leave automatic maintenance active.User Impact
No production behavior changes. The metadata tests reliably exercise their intended raw-write and external-connection invalidation boundaries. Whole-owner Bun CI qualification remains a separate step.
Why This Change Was Made
Automatic maintenance can hold
BEGIN IMMEDIATEwhile awaiting a host admission grant. The fixture's synchronous raw SQL blocks that same host while waiting for the maintenance writer's WAL lock. The retained connection waits its existing 5000 ms; a separately opened external connection has SQLite's default zero timeout and fails immediately. A controlled Linux probe reproduced both outcomes on both Bun pins and Node 24/26.Drain setup-owned database work before reopening and warming either cache, using the same lifecycle boundary already present in this file's second test group. Assert that setup leaves no asynchronous database resources. Raw SQL, the foreign handle, and the existing metadata/authorization assertions remain intact; no timeout, retry, skip, or production change is introduced. This does not establish a link to the Windows/Feishu reply-loss report in #157939.
Evidence
497de2e869: untouched 667c run failed raw sibling/exact and sibling cache replacement/exact with error 5 after about 5.68 seconds. The first isolated next-pin and Node controls passed, confirming timing dependence rather than proving a fix.667c4ab22c, Bunfc53bf8c0f, Node 24.21.0, and Node 26.10.0 all fail the retained raw write after about 5006 ms and the zero-timeout external write in under 1 ms. WAL/normal mode and the separate maintenance handle are confirmed in the trace.191ebcef6aa14+ this patch): 89/89 on both Bun pins and Node 24, with matching candidate file checksum. Process wall time: 97.6 s (667c), 95.3 s (next), 144.6 s (Node 24).node scripts/check-changed.mjs -- src/gateway/server-methods/chat-metadata-session-writes.test.tspassed, including typecheck/lint and repository guards;git diff --checkpassed. Independent autoreview found no actionable issues.The focused command used the repository wrapper:
node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway-methods.config.ts src/gateway/server-methods/chat-metadata-session-writes.test.ts --maxWorkers=1, withOPENCLAW_VITEST_RUNTIME=bunand the verified fork binary onPATHfor Bun runs, isolated state, and the same eight-CPU envelope.