Repository navigation
perf(sessions): yield during SQLite entry write contention - #160801
Conversation
Keep the Gateway event loop responsive while session-entry patches wait for another SQLite writer. Reuse begin-only asynchronous admission with zero native busy waiting, retaining FIFO ordering, connection custody, commit revalidation, and non-replay of admitted writes. No schema or configuration 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: blocked before merge. Reviewed September 28, 2026, 8:48 PM ET / September 29, 2026, 00:48 UTC (Revision 2). ClawSweeper reviewWhat this changesSession-entry patches yield while waiting for a SQLite write lock, with regression tests, a transaction guard update, a Slack test-fixture adjustment, and database-access documentation. Merge readiness⛔ Blocked before merge - 4 items remain Current main still makes session-entry patches wait synchronously for a SQLite writer, so this PR remains useful. A supported rollback-journal case can now fail at commit under read contention, which blocks merge. Priority: P2 Review scores
Verification
How this fits togetherGateway and channel activity updates session entries in an agent’s SQLite database. The session writer queue orders those updates, and committed changes are published to session state. flowchart LR
A[Session patch request] --> B[Session writer queue]
B --> D[SQLite write admission]
C[Competing SQLite connection] --> D
D --> E[Revalidate rows and authority]
E --> F[Commit entry change]
F --> G[Publish session state]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +71, Tests +89, Docs +10, Other +1. Total +171 across 8 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Keep yielding for BEGIN admission while preserving the existing bounded commit behavior on rollback-journal storage, then prove both journal modes with real connections through the session patch path. Do we have a high-confidence way to reproduce the issue? Yes. The old write path and the reported two-connection Testbox comparison provide a high-confidence contention scenario, although this read-only review did not execute it locally. Is this the best way to solve the issue? No, not yet. Yielding at BEGIN addresses the event-loop stall, but the zero timeout through COMMIT needs a rollback-journal compatibility repair. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 4f993f287f3f. LabelsLabel changes:
Label justifications:
EvidenceAcceptance criteria:
What 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)
|
Name yielding admission separately from retired async-transaction APIs and register its synchronous callback with the source guard. Make the Slack Stop-owner fixture await its competing committed session write instead of depending on updater microtask ordering.
Follow up #160801. Keep BEGIN admission yielding while restoring the original native timeout before the synchronous write and COMMIT, so session patches retain their bounded chance to commit after a rollback-journal reader finishes.
…160801) * perf(sessions): yield during SQLite entry write contention Keep the Gateway event loop responsive while session-entry patches wait for another SQLite writer. Reuse begin-only asynchronous admission with zero native busy waiting, retaining FIFO ordering, connection custody, commit revalidation, and non-replay of admitted writes. No schema or configuration changes. * fix(sessions): enforce synchronous callbacks during yielding admission Name yielding admission separately from retired async-transaction APIs and register its synchronous callback with the source guard. Make the Slack Stop-owner fixture await its competing committed session write instead of depending on updater microtask ordering.
Follow up openclaw#160801. Keep BEGIN admission yielding while restoring the original native timeout before the synchronous write and COMMIT, so session patches retain their bounded chance to commit after a rollback-journal reader finishes.
What Problem This Solves
Session-entry patches can stall unrelated Gateway requests while SQLite synchronously waits for another connection's write transaction.
User Impact
The Gateway can service its event loop while an entry patch waits for SQLite admission. The existing admission deadline remains in place, so a sufficiently long competing transaction can still make the patch fail. No configuration, schema, durability, or update migration changes.
Why This Change Was Made
Ordinary and lifecycle-target entry patches use the existing asynchronous BEGIN-admission primitive, with a zero native busy timeout through commit. Only a failed
BEGIN IMMEDIATEmay retry. The existing session writer queue retains FIFO order through publication. Each attempt retains and rechecks its original connection; the admitted transaction revalidates prepared rows and current caller authority. Admitted writes and publications never replay.The helper is explicitly registered with the synchronous-callback source guard. Retired async-transaction APIs remain banned. A Slack Stop-owner fixture now awaits its competing real session write at the existing async routing boundary; its previous assumption about updater/commit timing failed under the yielding path. All Stop-ownership assertions remain unchanged, and Slack production code is unchanged.
The change adds 71 net core production lines and one guard-registration line. Transcript snapshot writes, other synchronous lifecycle writes, and synchronous entry reads remain outside this cutover.
Evidence
A real second SQLite connection holds the agent-store write lock; the caller's next event-loop turn releases it. The measurement caps native waiting at 250 ms to bound the negative control:
All remote proof used
blacksmith-testbox, profileopenclaw-check:tbx_01m3n3bsyannhvrmc7nyhwv48y(run): pinned source/file hashes; held-lock comparison; 58 session tests and 29 transaction tests passed. Core typecheck, formatting, line-cap/assertion guards, and dependency checks passed.tbx_01m3n535ya5p3za673w066n515(run): changed-test typecheck (agents-sessions), targeted lint, schema/storage guards, import-cycle and unused-export checks passed.tbx_01m3n7m0zbbt6e8d69w5qrqh18(run): 46 focused session/guard tests passed after the CI corrections, the actual SQLite transaction-boundary check passed, and its negative control failed before registering the synchronous callback. The original 32-file Slack group reproduced the CI failure; the corrected group passed 3 times (1,013 tests each), followed by 20 clean standalone runs of the 34-test Slack file.Focused commands use
node scripts/run-vitest.mjswith the entry revalidation, entry admission, environment-capture, and SQLite transaction test files; guard proof usespnpm lint:tmp:sqlite-transaction-boundaryandtest/scripts/check-sqlite-transaction-boundary.test.ts. Slack group replay preserves the CI selection and concurrency throughscripts/ci-run-node-test-shard.mts.Measured costs with
pnpm test <file> --maxWorkers=1: entry revalidation 40.25 s wall / 37 tests (cold compiler dominates; test execution about 4 s); environment capture 6.32 s / 4 tests; guard 1.47 s / 5 tests; Slack agent events 30.70 s cold and 11.46–15.59 s warm / 34 tests. Native contention proof needs real connections and uses an event-loop barrier rather than sleeps or timing assertions.The aggregate changed check on the pinned base stops on the inherited environment-name budget violation (477/476), fixed on current main by #160756. The remaining selected checks were run separately; no budget was changed. Initial CI also timed out in the unchanged shared-state worktree recovery case
recovers clean CRLF from worktree-autocrlf, missing=true. Its original two-plan Node replay passed all 58 files / 974 tests; the timeout's cause remains unresolved and no fix is claimed for it.Independent Codex autoreview is scoped-clean with no actionable P0–P2 findings, including the guard correction and Slack fixture ordering. No production load campaign or live Gateway mutation was performed.
Final CI passed on
6770dfb0b4abed12b93f76c88ffed70e482794ed: run 36504259471, 21 min 36 s workflow wall time. All task-owned Testbox leases are stopped.Rollback-journal compatibility follow-up: #160887 removes the redundant timeout override so BEGIN keeps yielding while admitted writes and COMMIT retain the original bounded wait. It includes a red/green native reader-contention proof.