Skip to content

fix(matrix): keep startup storage SQLite off the Gateway thread - #151994

Merged
steipete merged 1 commit into
mainfrom
codex/matrix-storage-root-worker-20260918
Sep 18, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/matrix-storage-root-worker-20260918

Conversation

@steipete

Copy link
Copy Markdown
Contributor

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

  • 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.

@clawsweeper

clawsweeper Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: matrix Channel integration: matrix size: XL maintainer Maintainer-authored PR labels Sep 18, 2026
@steipete
steipete marked this pull request as ready for review September 18, 2026 17:30
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 18, 2026
@clawsweeper

clawsweeper Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 18, 2026, 1:37 PM ET / 17:37 UTC.

ClawSweeper review

What this changes

Moves 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
Reviewed head: 2c44c8ddd9a47409416a1f1411be788bdf1dbac3

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with relevant concurrency and compatibility coverage and no blocking finding.
Proof confidence 🌊 off-meta tidepool Not applicable: The host identifies this as maintainer-authored, so the external-contributor proof gate does not apply. Submitted evidence covers the real factory’s SQLite boundary and real Matrix HTTP cancellation on loopback; no external Matrix account or live Gateway was exercised.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The host identifies this as maintainer-authored, so the external-contributor proof gate does not apply. Submitted evidence covers the real factory’s SQLite boundary and real Matrix HTTP cancellation on loopback; no external Matrix account or live Gateway was exercised.
Evidence reviewed 7 items Current main still needs the change: At the fetched main revision, startup metadata uses openSyncKeyedStore and crypto-state scoring remains synchronous. The PR converts these private operations and their callers to awaited worker-backed access.
Related merged work is distinct: The supplied GitHub record verifies #151845 merged. Its body explicitly leaves storage-root selection and initial metadata for separate work, so it does not supersede this PR.
Storage compatibility and concurrency: Metadata mutations recompute their values after comparison conflicts, retain learned device IDs when initialization supplies none, and select native compatibility only when comparison methods are unavailable. Existing namespaces, record formats, and root-selection rules remain intact.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +36, Tests +494, Docs +9, Other 0. Total +539 across 18 files.

View PR surface stats
Area Files Added Removed Net
Source 8 319 283 +36
Tests 8 586 92 +494
Docs 1 11 2 +9
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 18 917 378 +539

Review metrics

Metric Value Why it matters
Production versus test growth Production net +36 lines; tests net +493 lines Production growth supports request cleanup and concurrency handling; test growth covers factory execution, migration recovery, and lifecycle races.

Stored data model

Persistent data-model change detected: durable storage schema: extensions/matrix/src/matrix/client/storage.ts, migration/backfill/repair: extensions/matrix/src/matrix/monitor/index.ts, unknown-data-model-change: extensions/matrix/src/matrix/client/storage.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Technical review

Best 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.

Labels

Label changes:

  • add P2: This is a bounded Matrix startup responsiveness and lifecycle repair without evidence of an urgent widespread outage.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The host identifies this as maintainer-authored, so the external-contributor proof gate does not apply. Submitted evidence covers the real factory’s SQLite boundary and real Matrix HTTP cancellation on loopback; no external Matrix account or live Gateway was exercised.

Label justifications:

  • P2: This is a bounded Matrix startup responsiveness and lifecycle repair without evidence of an urgent widespread outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The host identifies this as maintainer-authored, so the external-contributor proof gate does not apply. Submitted evidence covers the real factory’s SQLite boundary and real Matrix HTTP cancellation on loopback; no external Matrix account or live Gateway was exercised.

Evidence

What I checked:

  • Current main still needs the change: At the fetched main revision, startup metadata uses openSyncKeyedStore and crypto-state scoring remains synchronous. The PR converts these private operations and their callers to awaited worker-backed access. (extensions/matrix/src/matrix/client/storage.ts:43, 8744037721da)
  • Related merged work is distinct: The supplied GitHub record verifies fix(matrix): keep sync-cache SQLite off the Gateway thread #151845 merged. Its body explicitly leaves storage-root selection and initial metadata for separate work, so it does not supersede this PR. (3a2dbb6f034c)
  • Storage compatibility and concurrency: Metadata mutations recompute their values after comparison conflicts, retain learned device IDs when initialization supplies none, and select native compatibility only when comparison methods are unavailable. Existing namespaces, record formats, and root-selection rules remain intact. (extensions/matrix/src/matrix/client/storage.ts:481, 2c44c8ddd9a4)
  • Factory and upgrade coverage: The factory regression covers fresh, canonical, rotated-token, and legacy-import roots while asserting zero host SQLite calls. Storage tests retain archive-failure recovery and add concurrent-device and capability-fallback cases. The captured PR body reports these checks passed; this review did not execute tests. (extensions/matrix/src/matrix/client/create-client.storage.test.ts:56, 2c44c8ddd9a4)
  • Cancellation reaches the transport owner: The monitor admits backfill through its existing task runner. The identity helper joins temporary-client disposal, and the loopback fixture exercises the real Matrix client with a pending HTTP response and observes connection closure on retirement. (extensions/matrix/src/matrix/client/backfill.test.ts:75, 2c44c8ddd9a4)
  • Credential authority remains with the existing writer: Backfill rechecks credential lineage after metadata persistence. The unchanged credential writer also rejects logout tombstones and replacement credentials inside its comparison loop, preserving the final-write checks. (extensions/matrix/src/matrix/credentials.ts:48, 2c44c8ddd9a4)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Ben Badejo: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 33c350a into main Sep 18, 2026
236 checks passed
@steipete
steipete deleted the codex/matrix-storage-root-worker-20260918 branch September 18, 2026 18:54
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 19, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: matrix Channel integration: matrix docs Improvements or additions to documentation maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant