Skip to content

fix(matrix): recover encryption in previously joined rooms - #115688

Merged
fuller-stack-dev merged 10 commits into
openclaw:mainfrom
AlexSCFraser:fix/matrix-post-crypto-room-reprocessing
Sep 17, 2026
Merged

fuller-stack-dev merged 10 commits into
openclaw:mainfrom
AlexSCFraser:fix/matrix-post-crypto-room-reprocessing

Conversation

@AlexSCFraser

@AlexSCFraser AlexSCFraser commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Closes #115637

What Problem This Solves

Fixes outbound replies failing in previously joined encrypted Matrix rooms when a resumed sync has no local encryption state.

User Impact

Affected rooms recover encrypted sending during startup. Encryption remains opt-in, and unknown or failed encryption state never permits a plaintext fallback. No configuration or storage migration is required.

Why This Change Was Made

Reconcile the homeserver's joined-room set after crypto initialization and sync readiness, using the installed SDK's real encryption-event handling. Recovery has a bounded request pool and startup deadline; cancellation stops new work, and shutdown waits for admitted crypto replay before closing the backend. Temporary joined-room discovery failures log skipped recovery without taking healthy cached encrypted rooms offline; cancellation, authentication failures, and invalid room lists still fail. Remove the obsolete no-op preparation path.

Original report and candidate: Alex Fraser (@AlexSCFraser). This updates the existing contributor PR and preserves its history.

Evidence

  • Real Synapse 1.161.0, OpenClaw Gateway/plugin host, and Matrix SDK 42.3.0: two already-joined encrypted rooms failed before the repair with Cannot encrypt event in unconfigured room; both sent m.room.encrypted afterward and an independent SDK recipient decrypted both messages.
  • The failure fixture deliberately removed encryption events from the disposable persisted cache while preserving its incremental-sync cursor and crypto store. A healthy-cache encryption-disabled → encryption-enabled restart already worked on current source; this proof does not claim naturally occurring cache loss on current Synapse.
  • Installed-SDK tests cover joined/invited/left rooms, missing and unsupported state, bounded large room sets, cancellation, authority changes, and late replay. Startup tests cover initialization/replay deadlines and backend-teardown ordering; the regression cases fail on the original startup owner.

All 209 affected Matrix tests passed, including actual-SDK startup regressions for temporary discovery failure, fatal authentication errors, cancellation, and fail-closed sending from unrecovered rooms. The 503/429/connection regressions fail before the follow-up repair. The upstream Slack typing prerequisite is incorporated and full test typechecking passed. The final full build and independent P0–P2 review passed. Real Synapse acceptance was repeated with the final production source: both rooms again sent encrypted wire events and the independent recipient decrypted both messages. Final changed-file lint passed with zero warnings/errors; prior production typechecking, dead-code and architecture checks also passed. Exact-head CI remains required before landing.

The original contributor disclosed AI assistance and live Continuwuity validation; the current-source evidence above was independently rerun for this revision.

After initRustCrypto() completes, already-joined encrypted rooms
never get their encryptors configured because incremental sync
doesn't re-send m.room.encryption state events. This causes
outbound messages to fail with 'Cannot encrypt event in
unconfigured room' or fall back to plaintext.

Fix: scan joined rooms after initial sync and retroactively
configure encryptors for any room with encryption state on the
server.

Closes openclaw#115637
@openclaw-barnacle openclaw-barnacle Bot added channel: matrix Channel integration: matrix size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 29, 2026
@AlexSCFraser AlexSCFraser changed the title fix(matrix): configure encryptors for rooms joined before crypto init [AI-assisted] fix(matrix): configure encryptors for rooms joined before crypto init Jul 29, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jul 29, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 29, 2026
@clawsweeper

clawsweeper Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 17, 2026, 2:40 AM ET / 06:40 UTC (Revision 13).

ClawSweeper review

What this changes

The Matrix plugin restores missing encryption state for previously joined rooms during startup, with bounded requests, cancellation, and coordinated shutdown.

Merge readiness

✅ Ready for maintainer review

This remains a useful fix absent from current main and the latest release. The earlier actionable findings are resolved, the supplied real-server evidence supports recovery, and no blocking patch defect was found.

Priority: P1
Reviewed head: 6e3720a9433bc25dbc4cf641a49880c2a78528b0

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Strong real-server observations, direct SDK contract alignment, and focused lifecycle regressions support a clean review.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The captured Synapse run exercised the real Gateway/plugin startup and send path: two rooms with deliberately missing cached encryption state failed before recovery, then emitted encrypted events successfully decrypted by an independent recipient. Acceptance was repeated with final production source; the latest commit only strengthens a test assertion.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured Synapse run exercised the real Gateway/plugin startup and send path: two rooms with deliberately missing cached encryption state failed before recovery, then emitted encrypted events successfully decrypted by an independent recipient. Acceptance was repeated with final production source; the latest commit only strengthens a test assertion.
Evidence reviewed 12 items Recovery belongs to startup: Startup invokes reconciliation after crypto initialization and sync readiness. A shared startup promise retains admitted work, and shutdown joins it before stopping the crypto backend.
Earlier findings addressed: Recovery uses authoritative joined rooms, four workers, abort checks, and membership revalidation. Temporary discovery failures preserve healthy cached rooms; authentication failures and malformed room lists remain errors. The new tests cover these cases and shutdown ordering.
Current main still lacks recovery: The pinned current-main startup path initializes crypto and waits for sync but does not replay missing room-encryption events.
Findings None None.
Security None None.

How this fits together

The Matrix plugin connects OpenClaw conversations to a Matrix homeserver. Its startup owner initializes encryption and synchronizes room state before outbound replies pass through encrypted-send checks.

flowchart TD
  A[Saved room state] --> B[Initialize crypto and sync]
  C[Homeserver joined rooms] --> D[Bounded encryption recovery]
  B --> D
  D --> E[Encrypted-send checks]
  E --> F[Encrypted Matrix reply]
  E --> G[Reject unready room]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +181, Tests +470. Total +651 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 6 339 158 +181
Tests 5 491 21 +470
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 830 179 +651

Review metrics

Metric Value Why it matters
Production versus test growth Production +339/-158 (net +181); tests +491/-21 (net +470) Production growth supports bounded recovery and lifecycle ownership; tests cover recovery failures, cancellation, and teardown.
Recovery bounds 4 workers; 60-second default startup recovery budget These limits bound homeserver request fanout and caller waiting while shutdown still joins admitted crypto replay.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #115637
Summary: This PR is the active recovery candidate for the paired production issue; the related QA readiness work addresses a separate boundary.

Members:

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

Technical review

Best possible solution:

Keep room-encryption recovery in the Matrix startup owner, preserving fail-closed sending and shutdown ownership of admitted crypto work.

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

Yes, for the missing-cache-state scenario: source and supplied Synapse observations establish failure with an intact cursor and crypto store but absent encryption events. This review did not execute it, and the healthy-cache encryption-toggle trigger was not reproduced on current Synapse.

Is this the best way to solve the issue?

Yes. Startup reconciliation uses the SDK's existing encryption-event owner and avoids adding repair work to every send; the obsolete preparation no-op and its callers are removed together.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P1: Missing room-encryption state can prevent replies in existing encrypted Matrix conversations.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured Synapse run exercised the real Gateway/plugin startup and send path: two rooms with deliberately missing cached encryption state failed before recovery, then emitted encrypted events successfully decrypted by an independent recipient. Acceptance was repeated with final production source; the latest commit only strengthens a test assertion.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured Synapse run exercised the real Gateway/plugin startup and send path: two rooms with deliberately missing cached encryption state failed before recovery, then emitted encrypted events successfully decrypted by an independent recipient. Acceptance was repeated with final production source; the latest commit only strengthens a test assertion.

Evidence

What I checked:

Likely related people:

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

History

Review history (12 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-04T07:13:53.785Z sha 256dd7f :: needs changes before merge. :: [P2] Bound post-sync room-state requests | [P2] Restrict the scan to joined rooms
  • reviewed 2026-08-12T09:17:34.009Z sha 256dd7f :: needs changes before merge. :: [P2] Bound reconciliation to authoritative joined rooms
  • reviewed 2026-08-22T01:55:35.653Z sha 256dd7f :: needs changes before merge. :: [P2] Reconcile authoritative joined rooms with a bounded pool
  • reviewed August 28, 2026, 1:18 AM ET / 05:18 UTC sha unknown :: needs changes before merge. :: [P2] Limit reconciliation to joined rooms and make it abort-aware
  • reviewed September 5, 2026, 4:02 AM ET / 08:02 UTC sha unknown :: blocked before merge. :: [P2] Bound room reconciliation and propagate startup cancellation
  • reviewed 2026-09-17T06:10:22.839Z sha 6a3220b :: blocked before merge. :: [P1] Preserve best-effort startup when joined-room discovery fails
  • reviewed 2026-09-17T06:20:36.794Z sha cacd296 :: blocked before merge. :: [P1] Preserve best-effort startup when joined-room discovery fails
  • reviewed 2026-09-17T06:29:02.843Z sha 3ab16f2 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 4, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. and removed P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 28, 2026
@clawsweeper clawsweeper Bot added the rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. label Aug 28, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Sep 5, 2026
@fuller-stack-dev fuller-stack-dev self-assigned this Sep 17, 2026
Reconcile joined-room encryption after sync readiness with the real SDK
contract, bounded requests, cancellation, and lifecycle-owned teardown.
Preserve encrypted-send fail-closed behavior and remove no-op preparation.

Retain the original contributor history while integrating current main.

Co-authored-by: Alex Fraser <[email protected]>
@fuller-stack-dev fuller-stack-dev changed the title [AI-assisted] fix(matrix): configure encryptors for rooms joined before crypto init fix(matrix): recover encryption in previously joined rooms Sep 17, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 17, 2026
Preserve healthy encrypted startup on transient discovery failure while retaining cancellation, fatal authentication errors, and fail-closed sends.
@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 17, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Sep 17, 2026
@fuller-stack-dev
fuller-stack-dev merged commit dfb9ca9 into openclaw:main Sep 17, 2026
104 of 106 checks passed
@fuller-stack-dev

Copy link
Copy Markdown
Member

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 18, 2026
…115688)

* fix(matrix): configure encryptors for rooms joined before crypto init

After initRustCrypto() completes, already-joined encrypted rooms
never get their encryptors configured because incremental sync
doesn't re-send m.room.encryption state events. This causes
outbound messages to fail with 'Cannot encrypt event in
unconfigured room' or fall back to plaintext.

Fix: scan joined rooms after initial sync and retroactively
configure encryptors for any room with encryption state on the
server.

Closes openclaw#115637

* fix: add explicit any cast for fake event object

* fix: cast crypto to any for onCryptoEvent type

* fix: avoid explicit any, use typed interface cast instead

* fix(matrix): tolerate temporary joined-room discovery failure

Preserve healthy encrypted startup on transient discovery failure while retaining cancellation, fatal authentication errors, and fail-closed sends.

* test(matrix): inspect fetch request URLs explicitly

---------

Co-authored-by: Jason (Json) <[email protected]>
Co-authored-by: Alex Fraser <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: matrix Channel integration: matrix P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: L 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.

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

2 participants