Repository navigation
docs(agents): database access belongs in worker threads - #154189
Conversation
Peter's directive: readers use the read-only worker scope, writers the SQLite worker broker; the Gateway main thread only awaits results and installs published facts. Boot admission, migrations, Doctor/CLI one-shots, and lock primitives remain the synchronous exceptions. Existing synchronous main-thread access is legacy to migrate when touched, never to extend. Context: Team profiles on 2026-09-20 showed 47% of main-thread time blocked in synchronous state-database write coordination from request and timer paths.
|
Codex review: needs maintainer review before merge. Reviewed September 20, 2026, 8:16 PM ET / September 21, 2026, 00:16 UTC. ClawSweeper reviewWhat this changesAdds contributor guidance requiring database work off the Gateway main thread, with explicit synchronous exceptions and migration guidance for legacy paths. Merge readiness✅ Ready for maintainer review Keep open with no blocking findings. The policy clarification remains useful, matches the existing worker architecture, and is absent from the reviewed main revision. The maintainer label also precludes automatic closure. Priority: P3 Review scores
Verification
How this fits togetherThe Gateway coordinates requests and background tasks that access SQLite state. Worker owners perform database operations and return results for the Gateway to publish. flowchart LR
A[Requests and background tasks] --> B[Gateway]
B --> C[Read worker scope]
B --> D[SQLite worker broker]
C --> E[SQLite databases]
D --> E
E --> F[Results returned to Gateway]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceDocs +1. Total +1 across 1 file. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep the worker-placement rule in the root contributor guidance while preserving detailed lifecycle and authority contracts with their storage owners. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR documents engineering policy; the motivating production profiling claims were not independently reproduced. Is this the best way to solve the issue? Yes. A root guidance bullet is a narrow way to establish the shared rule while leaving concrete database migrations to their existing owners. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 68def4154c7c. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
) Peter's directive: readers use the read-only worker scope, writers the SQLite worker broker; the Gateway main thread only awaits results and installs published facts. Boot admission, migrations, Doctor/CLI one-shots, and lock primitives remain the synchronous exceptions. Existing synchronous main-thread access is legacy to migrate when touched, never to extend. Context: Team profiles on 2026-09-20 showed 47% of main-thread time blocked in synchronous state-database write coordination from request and timer paths.
What Problem This Solves
The Gateway main thread still performs synchronous SQLite work on request, event, and timer paths. On team.openclaw.ai (2026-09-20) profiles showed 47% of main-thread time blocked inside the exclusive state-database coordinator from
ensureProfileForEmailand the exec-approvals timer, and earlier the same day 84% in a synchronous task-registry refresh.User Impact
Docs only. Establishes the rule that database access runs in worker threads (readers through the read-only worker scope, writers through the SQLite worker broker), with boot admission, migrations, Doctor/CLI one-shots, and lock primitives as the only synchronous exceptions, and that existing synchronous main-thread access is legacy to migrate when touched.
Why This Change Was Made
Maintainer directive (Peter, 2026-09-20): database access always in workers; legacy code and design get migrated. The rule lives with the other runtime safeguards in AGENTS.md so every lane that touches a synchronous path migrates it instead of extending it.
Evidence
git diff --checkclean; one bullet added under "Runtime and code safeguards". No code changes.