Skip to content

refactor(matrix): run credential and crypto snapshot storage in workers - #149548

Merged
steipete merged 2 commits into
mainfrom
codex/matrix-storage-async-callers-20260915
Sep 16, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/matrix-storage-async-callers-20260915

Conversation

@steipete

@steipete steipete commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Matrix authentication and periodic crypto snapshots still run SQLite operations on the Gateway thread despite having asynchronous callers.

User Impact

These runtime paths can wait for SQLite without blocking other Gateway work. Credential revocation, token-root continuity, snapshot contents, and shutdown persistence retain their existing behavior. No configuration or migration is required.

Why This Change Was Made

Runtime credential reads use the existing asynchronous keyed store. Credential updates and token-root claims use its observed-row comparison contract, recomputing only after an explicit conflict; unknown write failures are never replayed. The published Matrix host floor includes 2026.9.4, which predates comparisons, so that host retains its existing synchronous update path. The fallback can retire when Matrix raises its declared host minimum to include comparison support.

Crypto snapshots reuse the existing asynchronous generation codec under the same cross-process lock used by runtime persistence and Doctor. The client carries its captured state runtime through shutdown, and the lock remains held through chunk writes, metadata publication, and obsolete-chunk cleanup. The duplicate synchronous snapshot codec is removed.

Synchronous account/auth descriptors, root selection, startup metadata, recovery-key callbacks, and the sync cache's multi-row codec remain outside this cut. The recovery-key cache callback has a concrete void contract in matrix-js-sdk; its Promise-based getter remains a separate follow-up. The sync cache's lock belongs to one client instance and cannot safely authorize a cross-client asynchronous generation rewrite.

Evidence

Focused synthetic proof passed: 245 Matrix tests covering credentials, auth, storage roots, thread bindings, crypto snapshots, SDK shutdown, and Doctor migration. Production and test typechecks, lint, unused-export scans, plugin/storage boundaries, and import-cycle checks passed. The initial thread-pool failures were resolved by routing the two newly worker-backed test files through the existing fork lane; no broker guard was weakened.

Independent review found no actionable P0–P2 issues. Both targeted controls failed at the intended assertions against the original owners, then passed on the restored candidate; the final patch hash was verified after restoration. No real Matrix server, account credentials, or operator state was used.

CI follow-up: the registered Matrix loopback fixture now runs in the existing host-broker process lane and joins SQLite worker cleanup before deleting its temporary state. All 27 registered read, revocation, and denial cases passed. The branch also carries the canonical alias-wrapper fixture repair from main (#149477); its 12 delegation/refusal checks passed. The original Matrix runtime patch and older-host fallback remain unchanged.

Exact-head CI passed on eb35874265e250b1a2f46e683f945925c2f5259e, including the required openclaw/ci-gate.

@clawsweeper

clawsweeper Bot commented Sep 16, 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.

@steipete
steipete marked this pull request as ready for review September 16, 2026 00:37
@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: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 16, 2026
@clawsweeper

clawsweeper Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 15, 2026, 10:57 PM ET / September 16, 2026, 02:57 UTC (Revision 3).

ClawSweeper review

What this changes

Moves Matrix credential operations and encryption-state snapshots onto existing SQLite workers while preserving older-host compatibility and shutdown persistence.

Merge readiness

⛔ Blocked before merge - 1 item remains

This remains useful work: current main still performs these operations synchronously. No actionable introduced defect was found, and the prior migration blocker is unsupported because the stored representation and public contracts remain unchanged.

Priority: P2
Reviewed head: eb35874265e250b1a2f46e683f945925c2f5259e

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused refactor with meaningful regression coverage, preserved compatibility, and no actionable correctness finding.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied repository context identifies this as maintainer-authored internal work, so the external-contributor proof gate does not apply. Synthetic SQLite and lifecycle coverage supports the changed owners; it is not claimed as a live Matrix-server run, and no unresolved material authority change requires additional final-effect proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied repository context identifies this as maintainer-authored internal work, so the external-contributor proof gate does not apply. Synthetic SQLite and lifecycle coverage supports the changed owners; it is not claimed as a live Matrix-server run, and no unresolved material authority change requires additional final-effect proof.
Evidence reviewed 9 items Pinned introduction and clean checkout: Reviewed the merge-base-to-head changes at the supplied original head. The alias-wrapper repair belongs to the merge base, not this PR's introduced changes. The final working-tree status was clean, and diff whitespace validation passed.
Current main still needs the change: Current-main credential updates still call the synchronous store, and snapshot reads and writes still use the synchronous codec. No verified merged replacement for this work was established.
Existing storage compatibility contract: The SDK documentation explicitly states that synchronous and asynchronous interfaces use the same plugin-scoped data and require no migration. It documents optional observed-row comparisons and permits recomputation only after explicit conflicts. The patch follows that contract without changing schemas, namespaces, snapshot versions, or public exports; therefore the previous review's generic migration-proof blocker does not apply.
Findings None None.
Security None None.

How this fits together

The Matrix plugin stores account credentials and encryption snapshots in OpenClaw’s SQLite state stores. Authentication, periodic saves, and shutdown use this state to preserve account identity and encrypted conversations across restarts.

flowchart TD
  A[Matrix authentication] --> B[Account credential store]
  B --> C{Comparison support available}
  C -->|Yes| D[SQLite workers]
  C -->|Older host| E[Synchronous compatibility path]
  F[Periodic save or shutdown] --> G[Locked snapshot persistence]
  G --> D
  D --> H[Existing durable Matrix state]
  E --> H
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +54, Tests +51. Total +105 across 18 files.

View PR surface stats
Area Files Added Removed Net
Source 9 181 127 +54
Tests 9 119 68 +51
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 18 300 195 +105

Review metrics

Metric Value Why it matters
Production versus test growth Production net +54 lines; tests and test support net +51 lines Production growth provides conflict-safe worker updates and published-host compatibility while removing the duplicate synchronous snapshot codec.

Stored data model

Persistent data-model change detected: durable storage schema: extensions/matrix/src/matrix/client/storage.ts, unknown-data-model-change: extensions/matrix/src/matrix/client/storage.ts, unknown-data-model-change: extensions/matrix/src/matrix/sdk/idb-persistence.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Use the existing worker-backed stores and shared snapshot codec while retaining atomic credential checks, supported-host fallbacks, and shutdown settlement.

Do we have a high-confidence way to reproduce the issue?

Not applicable as a discrete bug reproduction: this refactor addresses source-confirmed synchronous SQLite work; no Gateway latency measurement was performed during review.

Is this the best way to solve the issue?

Yes. Reusing the existing asynchronous store and snapshot codec is a narrow solution that preserves the documented storage contract and supported older hosts.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 42c55f596602.

Labels

Label justifications:

  • P2: This is a bounded Matrix runtime responsiveness improvement with no demonstrated urgent user 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 supplied repository context identifies this as maintainer-authored internal work, so the external-contributor proof gate does not apply. Synthetic SQLite and lifecycle coverage supports the changed owners; it is not claimed as a live Matrix-server run, and no unresolved material authority change requires additional final-effect proof.

Evidence

What I checked:

  • Pinned introduction and clean checkout: Reviewed the merge-base-to-head changes at the supplied original head. The alias-wrapper repair belongs to the merge base, not this PR's introduced changes. The final working-tree status was clean, and diff whitespace validation passed. (eb35874265e2)
  • Current main still needs the change: Current-main credential updates still call the synchronous store, and snapshot reads and writes still use the synchronous codec. No verified merged replacement for this work was established. (extensions/matrix/src/matrix/credentials.ts:27, 42c55f596602)
  • Existing storage compatibility contract: The SDK documentation explicitly states that synchronous and asynchronous interfaces use the same plugin-scoped data and require no migration. It documents optional observed-row comparisons and permits recomputation only after explicit conflicts. The patch follows that contract without changing schemas, namespaces, snapshot versions, or public exports; therefore the previous review's generic migration-proof blocker does not apply. Public docs: docs/plugins/sdk-runtime/state-and-system.md. (docs/plugins/sdk-runtime/state-and-system.md:164, eb35874265e2)
  • Published older-host contract checked: The v2026.9.4 store contract exposes asynchronous lookup/register/entries/delete and synchronous update, but lacks observe/compareAndApply. Both new conditional-update callers check those optional capabilities and retain their existing synchronous behavior. The release resolves to the recorded release SHA. (src/plugin-state/plugin-state-store.types.ts:13, 3a9d69db306c)
  • Credential conflicts preserve revocation: Backfill and activity updates recompute against the current row after an explicit conflict, preserving revocation markers and newer authentication lineage; unknown failures propagate without replay. The extended test revokes credentials immediately before the real comparison operation and verifies that no credentials are resurrected. (extensions/matrix/src/matrix/credentials.ts:103, eb35874265e2)
  • Snapshot format and publication remain owned: Runtime persistence now reuses Doctor's existing asynchronous generation codec. Chunk construction, metadata publication order, digest validation, and obsolete-chunk cleanup remain unchanged; persistence awaits the complete operation while holding the existing cross-process lock. (extensions/matrix/src/matrix/crypto-state-store.ts:248, eb35874265e2)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; 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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-16T00:43:19.503Z sha 5adde8b0735423a2cff756c5e74c8d5bcfff4b99 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-16T02:24:01.531Z sha eb35874 :: blocked before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added channel: matrix Channel integration: matrix size: M maintainer Maintainer-authored PR labels Sep 16, 2026
@steipete
steipete force-pushed the codex/matrix-storage-async-callers-20260915 branch from 5adde8b to eb35874 Compare September 16, 2026 02:13
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 16, 2026
@steipete
steipete merged commit 66aee49 into main Sep 16, 2026
156 of 157 checks passed
@steipete
steipete deleted the codex/matrix-storage-async-callers-20260915 branch September 16, 2026 03:37
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: matrix Channel integration: matrix 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: M 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