Repository navigation
fix(state): serialize audit writes through shared owner - #125316
jesse-merhi wants to merge 2 commits into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
/clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Codex review: found issues before merge. Reviewed August 20, 2026, 8:14 PM ET / August 21, 2026, 00:14 UTC. ClawSweeper reviewWhat this changesThe PR replaces the audit worker’s separate SQLite connection with a bounded in-process queue that writes through the shared state-database owner. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readinessKeep open for maintainer handling: the protected maintainer PR is conflict-dirty, its central shared-owner change is already on current main through #126154, and the prior P1 event-loop blocker remains unresolved. Priority: P1 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherGateway audit producers enqueue metadata without waiting; the queue later persists it through the process-owned shared SQLite connection. Gateway shutdown unsubscribes audit producers and drains the queue before closing shared state. flowchart LR
A[Gateway audit producers] --> B[Bounded audit queue]
B --> C[Queue drain]
C --> D[Shared state database owner]
D --> E[SQLite audit records]
F[Gateway shutdown] --> B
F --> D
Decision needed
Why: The current shared-owner design removes a duplicate connection but cannot make synchronous DatabaseSync commits nonblocking; choosing the durable owner boundary affects the canonical main implementation. Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +106, Tests +426, Docs +6, Other -4. Total +534 across 64 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the single shared-state owner, but restore an off-loop persistence boundary for audit work and prove a deliberately slow successful write cannot delay the Gateway loop. Do we have a high-confidence way to reproduce the issue? Yes, from source: enqueue an audit record and make its successful immediate transaction slow; the queue drain executes that transaction synchronously on the Gateway event loop. The existing test only verifies fast failure under a held lock. Is this the best way to solve the issue? No. A single shared connection addresses competing writers, but the current queue does not keep successful SQLite work off the Gateway loop; the persistence boundary needs an off-loop design and regression proof. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 500fd2cac91e. LabelsLabel 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 (4 earlier review cycles)
|
|
/clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Summary
The Gateway audit worker opened a second writable connection to
openclaw.sqlite. Under concurrent main-agent turns, that gave SQLite two independent WAL/checkpoint owners in one process—the remaining writer-ownership gap after #123674.This change removes the worker and drains audit metadata through one bounded, process-owned queue backed by the process's cached shared-state connection.
What changed
There is no schema-version change.
Practical proof
An isolated real SQLite run opened the cached owner, queued one audit event, drained the writer, then queried the same owner:
{"dataVersionBefore":2,"dataVersionAfter":2,"rows":1,"quickCheck":"ok"}data_versionremaining unchanged proves the write committed through the existing cached connection rather than a second connection. The event persisted and SQLite's integrity check remained clean.A second isolated run held a competing
BEGIN IMMEDIATElock while the real queue accepted an event, measured event-loop responsiveness, released the lock, drained shutdown, and inspected the database after closing the cached owner:{"eventLoopTimerMs":50,"rows":1,"ownerOpenAfterShutdown":false,"quickCheck":"ok"}This demonstrates the lifecycle Clawsweeper flagged for maintainer confirmation: lock contention did not block the event loop, the accepted event persisted after retry, shutdown left no cached owner open, and the database remained healthy.
Validation
pnpm tsgo:core;pnpm tsgo:scripts;pnpm docs:list;Fixes #123327.
Related: #117262. Complements the external-writer fix in #123674 by removing the remaining in-process audit writer.