Repository navigation
fix(matrix): keep startup storage SQLite off the Gateway thread - #151994
Conversation
|
🦞👀 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 maintainer review before merge. Reviewed September 18, 2026, 1:37 PM ET / 17:37 UTC. ClawSweeper reviewWhat this changesMoves Matrix startup database operations into the existing SQLite worker and makes shutdown cancel and await background device identification. Merge readiness✅ Ready for maintainer review This PR remains useful: current main still performs startup storage work synchronously, and the earlier merged cache migration explicitly excluded it. No actionable introduced defect was found. Priority: P2 Review scores
Verification
How this fits togetherThe Matrix plugin prepares saved account, encryption, and sync state before starting its messaging client. Its startup and shutdown owners determine when that state is ready and when background work has finished. flowchart TD
A[Matrix account credentials] --> B[Select compatible storage root]
B --> C[SQLite worker]
C --> D[Restore state and import legacy files]
D --> E[Start Matrix client]
E --> F[Background device identification]
G[Monitor shutdown] --> F
F --> H[Cancel requests and settle writes]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +36, Tests +494, Docs +9, Other 0. Total +539 across 18 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep Matrix startup on the existing worker-backed stores while preserving device isolation, legacy imports, published host compatibility, and shutdown settlement. Do we have a high-confidence way to reproduce the issue? Yes, from source: current-main client startup reaches synchronous SQLite metadata and crypto-state reads. The submitted factory regression measures that boundary; it was not rerun in this read-only review. Is this the best way to solve the issue? Yes. Reusing the existing worker stores and monitor task runner fixes the owning paths without adding configuration, public plugin APIs, or a new persistent format. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 8744037721da. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
…claw#151994) Related: openclaw#151845 ## What Problem This Solves Matrix client startup still runs storage-root selection, initial metadata, and legacy crypto imports through SQLite on the Gateway thread. ## User Impact These startup operations now use the existing SQLite worker while preserving token-rotation selection, device identity, saved sync state, and migration recovery. Device backfill remains nonblocking at startup, and shutdown joins its admitted writes. No configuration, schema, or minimum host-version change is required. Credential-readiness and package auth-presence probes retain their synchronous SDK contracts. ## Why This Change Was Made The client factory awaits root selection, migration, and metadata before returning a client. Metadata comparisons preserve concurrent token claims and learned device IDs. The existing monitor task runner owns backfill cancellation and settlement, including disposal of its temporary identity client. Backfill rechecks credential lineage before publishing credentials after metadata persistence. Claimed canonical roots still skip token-history scans. Rotated tokens reuse only active roots with matching devices; archived roots stay excluded. Imports still finish before archival, and interrupted archival preserves completed imports and unrelated files. Hosts without comparison support retain the named native compatibility path; a worker failure never selects it. ## Evidence - The real client factory restored the seeded cursor but recorded 501 host SQLite `prepare` calls for a canonical root and 516 for token rotation before this change. - Candidate factory tests record zero host `prepare`, `exec`, `get`, `all`, `run`, or `iterate` calls for canonical roots, rotated roots, and legacy crypto imports. - Focused storage, Doctor, client factory, auth, startup verification, thread-binding, and monitor tests passed. Race tests cover initialization and token claims against a concurrently learned device, with explicit device inputs remaining authoritative. Other cases cover capability selection, worker failure, stale or cancelled backfill, and retirement settlement. - Actual SDK HTTP fixtures on loopback verify that retirement closes an in-flight identity request and that token-only login disposes its identity client before returning. Request and cleanup failures remain available together. - `pnpm build`, the changed-scope gate (including production/test typechecks and full extension lint), and the isolated built Matrix import profile passed. Fresh independent review found no actionable P0–P2 issues. - No external Matrix account or live Gateway was used.
Related: #151845
What Problem This Solves
Matrix client startup still runs storage-root selection, initial metadata, and legacy crypto imports through SQLite on the Gateway thread.
User Impact
These startup operations now use the existing SQLite worker while preserving token-rotation selection, device identity, saved sync state, and migration recovery. Device backfill remains nonblocking at startup, and shutdown joins its admitted writes. No configuration, schema, or minimum host-version change is required.
Credential-readiness and package auth-presence probes retain their synchronous SDK contracts.
Why This Change Was Made
The client factory awaits root selection, migration, and metadata before returning a client. Metadata comparisons preserve concurrent token claims and learned device IDs. The existing monitor task runner owns backfill cancellation and settlement, including disposal of its temporary identity client. Backfill rechecks credential lineage before publishing credentials after metadata persistence.
Claimed canonical roots still skip token-history scans. Rotated tokens reuse only active roots with matching devices; archived roots stay excluded. Imports still finish before archival, and interrupted archival preserves completed imports and unrelated files. Hosts without comparison support retain the named native compatibility path; a worker failure never selects it.
Evidence
preparecalls for a canonical root and 516 for token rotation before this change.prepare,exec,get,all,run, oriteratecalls for canonical roots, rotated roots, and legacy crypto imports.pnpm build, the changed-scope gate (including production/test typechecks and full extension lint), and the isolated built Matrix import profile passed. Fresh independent review found no actionable P0–P2 issues.