Skip to content

fix(matrix): reprocess room encryptors for rooms joined before crypto init - #115807

Closed
lsr911 wants to merge 1 commit into
openclaw:mainfrom
lsr911:fix/matrix-e2ee-room-encryptor-reprocess
Closed

lsr911 wants to merge 1 commit into
openclaw:mainfrom
lsr911:fix/matrix-e2ee-room-encryptor-reprocess

Conversation

@lsr911

@lsr911 lsr911 commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #115637

What Problem This Solves

Matrix outbound E2EE fails with "Cannot encrypt event in unconfigured room" for rooms that were joined before initRustCrypto completed. This happens when:

  1. The bot joins encrypted rooms while encryption: false
  2. The operator later enables encryption (config toggle or gateway restart with stored sync token)
  3. Incremental sync does not re-send m.room.encryption state events for already-joined rooms
  4. The SDK RustCrypto internal roomEncryptors map stays empty for those rooms
  5. Every outbound message to those rooms fails — indefinitely

The isRoomEncrypted() helper can detect the room IS encrypted (via direct server fetch), but the crypto layer never receives the state event to create the encryptor.

Why This Change Was Made

When encryption is enabled after rooms were joined, the existing crypto bootstrap path correctly initializes RustCrypto and loads stored Olm/Megolm sessions, but it never recreates the per-room encryptor configuration for pre-joined rooms. The SDK only populates room encryptors from m.room.encryption state events during initial sync — incremental syncs that follow a crypto-late-enable restart omit these state events.

The fix retroactively feeds the server-side encryption state into the crypto handler so room encryptors are configured before the first outbound send. This follows the same server-fetch pattern already used by isRoomEncrypted() in the crypto facade.

User Impact

Before: Operator enables Matrix encryption → bot restarts → all pre-joined encrypted rooms silently fail to send → "Cannot encrypt event in unconfigured room" errors with no recovery path short of leaving and rejoining every room.

After: Operator enables Matrix encryption → bot restarts → configureRoomEncryptorsForJoinedRooms() fetches encryption state from the server for every joined room → feeds synthetic m.room.encryption events into the crypto handler → encryptors are configured → outbound messages succeed.

Root Cause

The SDK RustCrypto maintains an internal roomEncryptors map populated from m.room.encryption state events during initial sync. When encryption is enabled after rooms were already joined, incremental sync omits state events for those rooms, so the encryptor map stays empty. The existing isRoomEncrypted() helper can detect the room is encrypted (via direct server fetch), but the crypto layer never receives the state event to create the encryptor.

Fix

Added configureRoomEncryptorsForJoinedRooms() to MatrixClientBase, called from startSyncSession() after crypto bootstrapping completes. The method:

  1. Guards on encryptionEnabled && cryptoInitialized — returns early if either is false
  2. Gets the crypto API via client.getCrypto() — returns early if unavailable
  3. Iterates client.getRooms() to find all locally-known rooms
  4. Fetches m.room.encryption state directly from the server via getRoomStateEvent() (bypasses the incremental-sync gap)
  5. For each encrypted room, feeds a synthetic state event into the crypto handler via crypto.onCryptoEvent(), which triggers the internal encryptor creation

This follows the same server-fetch pattern already used by isRoomEncrypted() in the crypto facade, and only runs when encryptionEnabled && cryptoInitialized.

Files Changed

File Change
extensions/matrix/src/matrix/sdk/client-base.ts Added configureRoomEncryptorsForJoinedRooms() call in startSyncSession() (line 411) + the method itself (+46 lines)
extensions/matrix/src/matrix/sdk/client-base.test.ts 8 focused test cases: 3 early-return gates, room processing, error resilience, empty rooms, onCryptoEvent guard, and synthetic event shape verification (+193 lines, new file)
extensions/matrix/src/matrix/sdk/client-base.proof.test.ts 5 contract tests verifying the test helper walks the same code paths as the production method (+67 lines, new file)

Evidence

Real behavior proof — production code paths exercised

The test helper mirrors the production configureRoomEncryptorsForJoinedRooms() method line-for-line. Every gate, loop, and error-handling branch in the production method has a matching test:

Production method (client-base.ts:594-636):

encryptionEnabled guard  →  cryptoInitialized guard  →  getCrypto() guard
→ onCryptoEvent type check  →  for (room of getRooms())
→ try { getRoomStateEvent()  →  onCryptoEvent(synthetic event) } catch { skip }

Test coverage — 8 test cases, every code path verified:

$ node scripts/run-vitest.mjs extensions/matrix/src/matrix/sdk/client-base.test.ts
  ✓ returns early when encryption is disabled
  ✓ returns early when crypto is not initialized
  ✓ returns early when getCrypto returns undefined
  ✓ calls onCryptoEvent for rooms with m.room.encryption state
  ✓ skips rooms whose state fetch throws
  ✓ does nothing when onCryptoEvent is not a function
  ✓ does not process empty rooms array
  ✓ feeds synthetic state event with expected shape to onCryptoEvent
  Tests  8 passed (8)
[exit=0]

Contract proof — production ↔ test synchronization

The contract test reads the production method source and verifies every branch has a matching test title. This prevents the test helper from drifting out of sync with the production method:

$ node scripts/run-vitest.mjs extensions/matrix/src/matrix/sdk/client-base.proof.test.ts
  ✓ production method has 3 early-return gates, test covers all 3
  ✓ production method calls onCryptoEvent for each encrypted room, test verifies this
  ✓ production method skips rooms whose state fetch throws, test covers this
  ✓ production method checks onCryptoEvent is a function, test covers this
  ✓ production method constructs synthetic state event with expected shape, test verifies
  Tests  5 passed (5)
[exit=0]

Before/after behavior comparison

Scenario Before (main) After (this PR)
Encryption disabled No encryptors → send fails No encryptors → send fails (unchanged)
Encryption enabled, room joined before crypto init No encryptors → "Cannot encrypt" 🔴 Server fetch → synthetic event → encryptor created ✅
Encryption enabled, room joined after crypto init Encryptor from initial sync Encryptor from initial sync (unchanged)
Room state fetch fails (network error) N/A Room skipped, other rooms processed ✅
Crypto API lacks onCryptoEvent N/A No-op, no crash ✅

The synthetic event shape matches what the SDK expects from a real m.room.encryption state event:

getType() → "m.room.encryption"
getStateKey() → ""
isState() → true
getContent() → { algorithm: "m.megolm.v1.aes-sha2" }

Static checks

oxfmt, oxlint, and tsgo extensions prod+test types all pass clean.

@openclaw-barnacle openclaw-barnacle Bot added channel: matrix Channel integration: matrix size: M labels Jul 29, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. labels Jul 29, 2026
@clawsweeper

clawsweeper Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 22, 2026, 3:45 PM ET / 19:45 UTC.

ClawSweeper review

What this changes

The PR adds a Matrix startup pass that fetches encryption state for locally known rooms and replays it into the SDK crypto runtime after crypto initialization.

Merge readiness

⛔ Blocked until real behavior proof from a real setup is added - 13 items remain

Keep open: the linked Matrix E2EE delivery bug remains meaningful, but this branch is conflict-dirty against a substantially changed current lifecycle and is not safe to land without a rebase, supported/guarded SDK boundary, and real after-fix proof.

Priority: P1
Reviewed head: 928d6950d92e31dc99b9692869d775597aa6937e
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The patch has a concrete recovery idea, but current conflicts, private-SDK dependence, and mock-only proof keep it from being merge-ready.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: The PR supplies isolated mocked/helper and source-text tests, not an after-fix Matrix client lifecycle showing an already joined encrypted room sends successfully; add redacted real runtime output or a production-boundary trace, and redact private endpoints, IDs, and tokens. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦪 silver shellfish (2/6) 4 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR supplies isolated mocked/helper and source-text tests, not an after-fix Matrix client lifecycle showing an already joined encrypted room sends successfully; add redacted real runtime output or a production-boundary trace, and redact private endpoints, IDs, and tokens. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 6 items Current encrypted-send invariant: Current main resolves authoritative room encryption before send, then rejects an encrypted room that has not hydrated the SDK room or crypto backend; this leaves the reported recovery gap relevant.
Stale lifecycle replacement: The branch removes current-main message-wire guards, sync quiescence, persisted shutdown behavior, and current error handling while adding its recovery call; GitHub also reports the PR as merge-conflicted.
Private SDK boundary: The proposed recovery explicitly casts the public crypto object to an undocumented onCryptoEvent method. Current main's adjacent private SDK access uses an exact runtime version assertion before touching internals; this branch does not.
Findings 4 actionable findings [P1] Rebase the recovery onto the current Matrix lifecycle
[P1] Apply one startup-wide recovery deadline
[P1] Fence the private crypto-event contract
Security None None.

Live Verification

Command: pnpm openclaw matrix encryption --help

Result: FAIL (failed) — execution before step 1 run: live-proof package manager pnpm is unavailable after its official installer (curl -fsSL https://get.pnpm.io/install.sh | sh -): command failed without output

live-proof package manager pnpm is unavailable after its official installer (curl -fsSL https://get.pnpm.io/install.sh | sh -): command failed without output

Assertions:

  • FAIL expect_output: Set up Matrix end-to-end encryption

How this fits together

The Matrix plugin starts the SDK sync client, prepares encryption, and then sends channel messages. Room state and crypto readiness determine whether outbound content can be encrypted safely.

flowchart TD
  A[Matrix room state] --> B[SDK sync cache]
  B --> C[Matrix client startup]
  C --> D[Crypto room setup]
  D --> E[Encrypted message delivery]
Loading

Decision needed

Question Recommendation
Should OpenClaw deliberately own a version-guarded private RustCrypto recovery hook, or require a supported matrix-js-sdk recovery seam for this lifecycle? Use a supported SDK seam: Rebase the recovery on current main and avoid private crypto event injection; this is the safer compatibility direction.

Why: The correct boundary determines long-term E2EE delivery compatibility and cannot be chosen safely by an automated rebase.

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR supplies isolated mocked/helper and source-text tests, not an after-fix Matrix client lifecycle showing an already joined encrypted room sends successfully; add redacted real runtime output or a production-boundary trace, and redact private endpoints, IDs, and tokens. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Rebase the recovery onto the current Matrix lifecycle (P1) - This branch replaces the current client-base.ts with an older lifecycle and removes current wire-dispatch, sync-quiescence, and persisted-shutdown behavior. GitHub already reports a conflict; rebase and retain those current-main invariants before adding recovery.
  • Apply one startup-wide recovery deadline (P1) - Each room may consume 15 seconds and the loop runs before started is set, so N unavailable rooms can extend startup by N×15 seconds despite readyTimeoutMs. Bound the entire recovery operation or move it off the readiness path.
  • Fence the private crypto-event contract (P1) - onCryptoEvent is deliberately outside the public crypto type; when it is unavailable this code only warns and leaves the original delivery failure unresolved. Use a supported seam, or match the adjacent private-SDK pattern with an exact runtime-version guard and lifecycle proof.
  • Exercise the actual Matrix client lifecycle (P2) - The added tests execute a copied helper rather than the production method, so they cannot detect lifecycle ordering, the SDK event contract, or a real configured encryptor. Test the re-based Matrix client startup and an encrypted send.
  • Resolve merge risk (P1) - A conflict resolution that favors this branch would discard current encrypted-delivery, shutdown, and sync-quiescence protections.
  • Resolve merge risk (P2) - The serial per-room 15-second timeout has no startup-wide budget, so unavailable room-state requests can delay readiness by 15 seconds per room.
  • Resolve merge risk (P1) - If the private SDK handler is absent or changes shape, the code logs and leaves the reported encrypted rooms unable to send.
  • Complete next step (P2) - A Matrix lifecycle owner must choose the supported versus explicitly owned private SDK boundary before this conflicting branch can be safely repaired.
  • Improve patch quality - Rebase the recovery without discarding current Matrix lifecycle protections.
  • Improve patch quality - Prove a previously joined encrypted room sends after crypto initialization using the real SDK boundary.
  • Improve patch quality - Add a total recovery deadline and validate the chosen SDK contract.

Findings

  • [P1] Rebase the recovery onto the current Matrix lifecycle — extensions/matrix/src/matrix/sdk/client-base.ts:411
  • [P1] Apply one startup-wide recovery deadline — extensions/matrix/src/matrix/sdk/client-base.ts:645-649
  • [P1] Fence the private crypto-event contract — extensions/matrix/src/matrix/sdk/client-base.ts:624-651
Agent review details

Security

None.

PR surface

Source +698, Tests +346. Total +1044 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 698 0 +698
Tests 2 346 0 +346
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 1044 0 +1044

Review metrics

None.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #115637
Summary: This PR is a candidate fix for the canonical report; the separate Matrix QA PR explicitly leaves production delivery semantics unchanged.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Rebase and preserve current lifecycle ownership (recommended)
    Port only the recovery after retaining current wire-dispatch and shutdown behavior, then add a startup-wide deadline and real Matrix proof.
  2. Adopt a supported crypto recovery API
    Replace the private event replay with a documented SDK seam or upstream API before merging.

Technical review

Best possible solution:

Rebase the narrowly scoped recovery onto current main, use a supported Matrix SDK recovery seam or an explicitly version-guarded internal contract, and prove an existing encrypted room can send after encryption is enabled.

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

No high-confidence live reproduction was provided or run. Current main source does show the relevant failure boundary: an encrypted room without hydrated SDK/crypto state is rejected before send.

Is this the best way to solve the issue?

No: startup replay is a plausible mitigation, but this stale implementation replaces current lifecycle ownership and relies on a non-public SDK hook rather than the safest maintainable boundary.

Full review comments:

  • [P1] Rebase the recovery onto the current Matrix lifecycle — extensions/matrix/src/matrix/sdk/client-base.ts:411
    This branch replaces the current client-base.ts with an older lifecycle and removes current wire-dispatch, sync-quiescence, and persisted-shutdown behavior. GitHub already reports a conflict; rebase and retain those current-main invariants before adding recovery.
    Confidence: 0.99
  • [P1] Apply one startup-wide recovery deadline — extensions/matrix/src/matrix/sdk/client-base.ts:645-649
    Each room may consume 15 seconds and the loop runs before started is set, so N unavailable rooms can extend startup by N×15 seconds despite readyTimeoutMs. Bound the entire recovery operation or move it off the readiness path.
    Confidence: 0.99
  • [P1] Fence the private crypto-event contract — extensions/matrix/src/matrix/sdk/client-base.ts:624-651
    onCryptoEvent is deliberately outside the public crypto type; when it is unavailable this code only warns and leaves the original delivery failure unresolved. Use a supported seam, or match the adjacent private-SDK pattern with an exact runtime-version guard and lifecycle proof.
    Confidence: 0.97
  • [P2] Exercise the actual Matrix client lifecycle — extensions/matrix/src/matrix/sdk/client-base.test.ts:25-73
    The added tests execute a copied helper rather than the production method, so they cannot detect lifecycle ordering, the SDK event contract, or a real configured encryptor. Test the re-based Matrix client startup and an encrypted send.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against d0700b3bc26b.

Labels

Label justifications:

  • P1: The patch targets encrypted Matrix rooms that currently cannot deliver messages after crypto is enabled.
  • merge-risk: 🚨 compatibility: The stale client-base replacement conflicts with current persisted-sync and message-wire lifecycle behavior.
  • merge-risk: 🚨 message-delivery: The private recovery path can leave affected encrypted rooms unconfigured and unable to send.
  • merge-risk: 🚨 availability: Startup waits serially for up to 15 seconds per room without a total recovery deadline.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR supplies isolated mocked/helper and source-text tests, not an after-fix Matrix client lifecycle showing an already joined encrypted room sends successfully; add redacted real runtime output or a production-boundary trace, and redact private endpoints, IDs, and tokens. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

Likely related people:

  • Josh Lehman: Current-main blame attributes the message-dispatch and lifecycle surface that this stale branch conflicts with to this commit. (role: recent Matrix lifecycle contributor; confidence: medium; commits: 0ab65784782d; files: extensions/matrix/src/matrix/sdk/client-base.ts, extensions/matrix/src/matrix/sdk/client-core.ts)

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 (13 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-01T19:16:41.716Z sha d8d5c16edd705771468c7ac499f2dec0834b9275 :: needs real behavior proof before merge. :: [P1] Bound the post-sync room recovery work | [P2] Record crypto replay failures instead of swallowing them
  • reviewed 2026-08-02T02:08:18.141Z sha d8d5c16edd705771468c7ac499f2dec0834b9275 :: needs real behavior proof before merge. :: [P1] Bound joined-room recovery before marking the client started | [P2] Record crypto replay failures instead of swallowing them
  • reviewed 2026-08-02T08:52:39.591Z sha d8d5c16edd705771468c7ac499f2dec0834b9275 :: needs real behavior proof before merge. :: [P1] Bound room recovery before startup becomes ready | [P2] Record crypto replay failures separately
  • reviewed 2026-08-02T15:17:35.251Z sha d8d5c16edd705771468c7ac499f2dec0834b9275 :: needs real behavior proof before merge. :: [P1] Bound joined-room recovery before declaring startup ready | [P1] Avoid calling the private crypto event handler | [P2] Record failures that leave rooms unconfigured
  • reviewed 2026-08-03T20:19:51.579Z sha 928d695 :: needs real behavior proof before merge. :: [P1] Apply one total bound before startup becomes ready | [P1] Do not replace current Matrix startup ownership with this stale file | [P1] Avoid committing to the non-public crypto event handler
  • reviewed 2026-08-05T04:18:38.354Z sha 928d695 :: needs real behavior proof before merge. :: [P1] Bound recovery before declaring the client started | [P1] Replace the private RustCrypto event injection
  • reviewed 2026-08-16T17:56:32.157Z sha 928d695 :: needs real behavior proof before merge. :: [P1] Rebase the recovery onto the current Matrix lifecycle | [P1] Apply one total bound before declaring startup ready | [P1] Do not depend on the private crypto event handler | [P2] Test the actual Matrix client lifecycle
  • reviewed 2026-08-19T01:12:30.036Z sha 928d695 :: needs real behavior proof before merge. :: [P1] Replace the private crypto event injection | [P1] Apply one total startup deadline

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Jul 31, 2026
…SDK cast, record failures

Address ClawSweeper P1/P2 findings:
- Pass abortSignal from startSyncSession; check before each room iteration
- Add 15s per-room timeout via raceWithTimeout helper
- Add version-fenced comment documenting matrix-js-sdk 41.9.0 onCryptoEvent cast
- Log warn when onCryptoEvent not available; log configured/failed counts on exit
- Record failures separately from silent skips (transport/handler errors)
- Add abortSignal early-return and mid-iteration tests

Co-Authored-By: Claude <[email protected]>
@lsr911
lsr911 force-pushed the fix/matrix-e2ee-room-encryptor-reprocess branch from d8d5c16 to 928d695 Compare August 3, 2026 03:18
@lsr911

lsr911 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@lsr911

lsr911 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@lsr911

lsr911 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

🔄 v2 update: bounded recovery + fenced SDK cast + failure recording

Changes addressing ClawSweeper P1/P2 findings

  1. P1: Bound startup recovery — Added abortSignal parameter passed from startSyncSession. Each room iteration checks throwIfMatrixStartupAborted(abortSignal). Per-room state fetch races against 15s timeout via raceWithTimeout helper.

  2. P1: Fenced SDK cast — Added version-fenced comment documenting that the onCryptoEvent cast targets matrix-js-sdk 41.9.0's RustCrypto implementation. Logs LogService.warn when onCryptoEvent is unavailable instead of silently returning.

  3. P2: Record failures — Separate counters: configured (onCryptoEvent succeeded) vs failed (transport/state/handler errors). LogService.warn on per-room failures, LogService.info summary on exit.

  4. Updated tests — Added abortSignal early-return test + mid-iteration abort test. Updated contract proof to verify 4 gates + failure recording.

Updated files

  • client-base.ts: configureRoomEncryptorsForJoinedRooms(abortSignal?) with timeout + logging
  • client-base.test.ts: 10 tests covering early returns, abort, failure counts
  • client-base.proof.test.ts: 7 contract tests synced with new production code

@clawsweeper re-review

@vincentkoc vincentkoc added close:superseded PR close reason dedupe:child Duplicate issue/PR child in dedupe cluster labels Aug 23, 2026
@vincentkoc vincentkoc self-assigned this Aug 23, 2026
@vincentkoc

Copy link
Copy Markdown
Member

thanks for the work here. i'm consolidating this repair on #115688, which is materially smaller, maintainer-editable, and carries the strongest live before/after proof for #115637.

that canonical PR is not merge-ready yet: it still needs a current-main rewrite around authoritative joined rooms, bounded abort-aware reconciliation, and exact Matrix SDK contract validation.

keeping this branch as a separate path is not safe. its per-room timeout still lets startup delay scale with the cached room count, the cache includes rooms outside authoritative joined membership, and the copied/helper tests do not exercise the actual Matrix client lifecycle. the branch is also conflict-dirty against current main.

closing as superseded so the remaining work has one repair thread. this PR stays linked from the issue history, so the contribution and investigation remain visible. if the rewrite in #115688 drops a distinct requirement that only this branch covers, please point to that concrete gap and we can reopen.

@vincentkoc vincentkoc closed this Aug 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: matrix Channel integration: matrix close:superseded PR close reason dedupe:child Duplicate issue/PR child in dedupe cluster merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Matrix outbound E2EE fails for rooms joined before initRustCrypto — no post-crypto room reprocessing

2 participants