Skip to content

fix(matrix): keep bot discovery off the Gateway thread - #152122

Merged
steipete merged 8 commits into
mainfrom
codex/matrix-monitor-bot-readiness-20260918
Sep 22, 2026
Merged

steipete merged 8 commits into
mainfrom
codex/matrix-monitor-bot-readiness-20260918

Conversation

@steipete

@steipete steipete commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Related: #151994

What Problem This Solves

Matrix monitor startup reads other bot accounts' stored credentials through SQLite on the Gateway thread. Moving those reads to the worker also needs to preserve Windows environment lookup and keep later reads on the state directory selected when discovery began.

User Impact

Bot discovery awaits the existing SQLite worker, preserves bot filtering decisions, and settles an active read before cancelled startup returns. It does not start another sibling read, acquire a client, or install handlers after cancellation. No configuration, schema, or minimum host-version change is required.

Why This Change Was Made

The monitor prepares account authentication facts against the original environment before storage yields. Matrix's credential owner captures the resolved state directory and supervisor setting once, then the existing loader reads selected account keys serially. This preserves Windows case-insensitive lookup without introducing a new host SDK export; the runtime APIs used here already exist in the supported 2026.9.4 host.

Each identity uses one credential observation. Default-account selection, environment precedence, token and homeserver matching, self-exclusion, and revocation handling remain intact. Public account-readiness and package auth-presence probes retain their synchronous contracts.

Evidence

Current head 374d8137ceeccac46a8afa9d6d7b2cc88d709c4f carries the reviewed Matrix change onto main 96482375236d829b6e39dddc61467e7f8d5f1bce. All seven code and worker-catalog postimages remain byte-identical to the qualified 9a139984bdf4be91d00e23f0e0f1b666d7dc3551 source. The storage documentation cleanly combines current main additions, and all eight ordered feature deltas remain exact.

Fresh current-source validation passed 88 focused account, credential and monitor cases across five files, including main's additional persisted-auth case. Real monitor ingress recorded zero calls to all six measured host SQLite methods for matching credentials, changed tokens, changed homeservers and revoked credentials. Cancellation joins the active read before startup returns and starts no later sibling read, client or handler. Six Doctor declaration/closure cases also passed. The full changed-file gate passed, including production/test typechecks, formatting, typed lint, plugin boundaries, storage guards, zero dead exports and zero runtime import cycles. Fresh independent review of the complete staged change is clean through P2; the reviewers did not execute tests.

The original real-SQLite regression still provides the causal failure: the old collector lost both expected bot identities under case-insensitive environment lookup. The qualified repair passes that case, both POSIX controls, and environment changes between reads without redirecting the credential source. Windows environment behavior is modeled on macOS; no native Windows execution, external Matrix account or operator Gateway is claimed. The supported 2026.9.4 runtime APIs remain unchanged; no new SDK export or host-version floor is introduced.

The prior exact-head CI run 35688151973 failed shared catalog cleanup and Slack lint checks; its logs are retained. This source integration carries current main's canonical repairs. Fresh exact-head hosted CI and native preparation remain required before landing. No new distributable-build claim is attached to this carry.

The earlier Doctor failure was repaired on main by e99e75e2e60a48875d63f6d84a3db4882ca00252, already retained in this ancestry. The subsequent exact-head run 35715269599 failed UI typechecking in test merge 6715f31529685e4d4382c168391b44eb3409f755: newer main imported the tooling shim without its declaration file. This carry includes main's canonical declaration fix 80b9608a25e191a17e1466d750c2f76a38a38507; current-source UI typechecking passes. No duplicate Doctor or declaration implementation was added. Fresh exact-head CI and native preparation remain pending.

@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: M maintainer Maintainer-authored PR labels Sep 18, 2026
@steipete
steipete marked this pull request as ready for review September 18, 2026 19:56
@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 22, 2026, 8:59 AM ET / 12:59 UTC (Revision 8).

ClawSweeper review

What this changes

Moves Matrix startup’s bot-account discovery onto the existing SQLite worker while preserving credential matching, environment selection, and cancellation.

Merge readiness

✅ Ready for maintainer review

The fix remains necessary: current main and the latest release still perform synchronous credential reads during bot discovery. No actionable introduced defect was found; the patch is suitable for the normal review and CI gates.

Priority: P2
Reviewed head: 374d8137ceeccac46a8afa9d6d7b2cc88d709c4f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with useful boundary coverage, preserved compatibility, and no identified blocking defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate. Its reported monitor runs exercise real SQLite credential discovery with mocked Matrix transport; native Windows and external Matrix execution are explicitly unclaimed. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate. Its reported monitor runs exercise real SQLite credential discovery with mocked Matrix transport; native Windows and external Matrix execution are explicitly unclaimed. No stored-data contract changes.
Evidence reviewed 8 items Introduced change: The pinned base-to-head delta changes Matrix discovery, credential-source capture, focused tests, worker-test registration, and storage documentation. It introduces no dependency, schema, configuration, or public SDK change.
Still necessary on main: Fetched main retains the synchronous collector, including synchronous readiness and stored-identity reads. The central change is not already implemented there.
Latest-release comparison: The accounts source at the supplied v2026.9.5 release commit also retains synchronous bot discovery. GitHub's contents API supplied this blob after local historical-object access failed.
Findings None None.
Security None None.

How this fits together

Matrix startup identifies other configured bot accounts from configuration and stored credentials. Those identities feed inbound message filtering and bot-loop protection before the client begins processing messages.

flowchart TD
  A[Account configuration and environment] --> B[Prepare account facts]
  B --> C[Read credentials through SQLite worker]
  C --> D[Match bot identities]
  D --> E{Startup cancelled?}
  E -->|Yes| F[Return after active read settles]
  E -->|No| G[Start client and install message filters]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +37, Tests +301, Docs +4. Total +342 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 3 85 48 +37
Tests 4 309 8 +301
Docs 1 5 1 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 399 57 +342

Review metrics

None.

Technical review

Best possible solution:

Keep bot discovery on the existing credential worker while retaining one credential observation per identity and settling admitted reads before cancelled startup returns.

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

Yes, from source: current-main bot discovery calls synchronous credential lookups during monitor startup. The added monitor test targets that boundary, but no tests were executed in this read-only review.

Is this the best way to solve the issue?

Yes. Reusing the existing async credential loader and shared readiness rules is a narrow repair that preserves public APIs and stored-data formats.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded Matrix startup reliability fix that removes synchronous SQLite work from the Gateway thread.
  • 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 maintainer-authored PR is exempt from the external-contributor proof gate. Its reported monitor runs exercise real SQLite credential discovery with mocked Matrix transport; native Windows and external Matrix execution are explicitly unclaimed. No stored-data contract changes.

Evidence

What I checked:

  • Introduced change: The pinned base-to-head delta changes Matrix discovery, credential-source capture, focused tests, worker-test registration, and storage documentation. It introduces no dependency, schema, configuration, or public SDK change. (extensions/matrix/src/matrix/accounts.ts:109, 374d8137ceec)
  • Still necessary on main: Fetched main retains the synchronous collector, including synchronous readiness and stored-identity reads. The central change is not already implemented there. (extensions/matrix/src/matrix/accounts.ts:112, cf8c5724cbca)
  • Latest-release comparison: The accounts source at the supplied v2026.9.5 release commit also retains synchronous bot discovery. GitHub's contents API supplied this blob after local historical-object access failed. (extensions/matrix/src/matrix/accounts.ts:113, ec9c1a13db89)
  • Review continuity: All seven code and worker-catalog files are unchanged from the previous reviewed head. The supplied previous completed review contains no findings or published rank-up moves. The stale test merge was not used to infer removal of current-main behavior. (374d8137ceec)
  • Cancellation and storage ownership: Discovery prepares authentication facts before yielding, captures the resolved storage selectors, reads selected account keys serially, and stops admitting sibling reads after cancellation. Monitor startup checks cancellation before client acquisition. The existing decoder, namespace, account keys, and synchronous public readiness contract remain intact. (extensions/matrix/src/matrix/monitor/index.ts:188, 374d8137ceec)
  • Focused boundary coverage: The added monitor cases use real account resolution and credential storage with mocked surrounding Matrix transport. They check matching, changed-token, changed-homeserver, and revoked records against six host SQLite methods, plus cancellation settlement. Credential tests model Windows case-insensitive lookup and environment changes between reads. The captured body reports 88 passing focused cases; this reviewer did not execute them or claim native Windows or external Matrix proof. (extensions/matrix/src/matrix/monitor/index.credentials.test.ts:89, 374d8137ceec)

Likely related people:

  • 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 (7 earlier review cycles)
  • reviewed 2026-09-18T20:03:20.466Z sha 186b820 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-19T00:28:24.966Z sha 06aee21 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-19T04:38:43.522Z sha 8c967a4 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-19T04:56:29.303Z sha 8c967a4 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-22T04:53:12.468Z sha 1a3a2b5 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-22T09:51:48.131Z sha 89249df :: needs maintainer review before merge. :: none
  • reviewed 2026-09-22T10:26:45.965Z sha 9a13998 :: needs maintainer review before merge. :: none

Prepare account authentication against native environment lookups before asynchronous reads. Capture the resolved credential state directory and supervisor setting once through existing host APIs, preserving Windows lookup behavior and the supported host floor without expanding the SDK.
Preserve the qualified worker-backed bot discovery and native environment
lookup while retaining current history-limit normalization, credential
presence coverage, and worker-test registrations.

The eight feature deltas are unchanged from the reviewed public head.
Validation: 88 focused cases, six Doctor cases, full changed-file checks,
and independent P2 review passed on the reconciled source. Exact-head
hosted CI and native preparation remain pending.
@steipete
steipete requested review from a team as code owners September 22, 2026 09:08
@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord channel: googlechat Channel integration: googlechat channel: imessage Channel integration: imessage channel: line Channel integration: line channel: mattermost Channel integration: mattermost channel: msteams Channel integration: msteams channel: nextcloud-talk Channel integration: nextcloud-talk channel: nostr Channel integration: nostr channel: signal Channel integration: signal channel: slack Channel integration: slack channel: telegram Channel integration: telegram channel: tlon Channel integration: tlon labels Sep 22, 2026
Merge main 9a472a9 so the Matrix candidate itself contains the retained-agent
Doctor fix e99e75e. The reopened CI run used an older merge with the pre-fix
Doctor owner, despite the corrected eight-file PR projection.

All eight Matrix feature postimages are unchanged. Fresh 88-case runtime
proof, full changed-file checks, six Doctor contract cases and independent
P2 review pass. The unchanged Doctor owner/test hashes match the retained
main proof. Exact-head hosted CI remains required before native preparation.
Merge current main to include the canonical tsx CLI shim declaration repair
required by the hosted test merge. Preserve all eight Matrix feature deltas
and newer main changes; no duplicate declaration or Doctor repair.
@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 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: 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