Skip to content

fix(matrix): prevent gateway stop on Megolm missing-key decryption failures - #94044

Closed
yuxuan-7814 wants to merge 1 commit into
openclaw:mainfrom
yuxuan-7814:fix/93501-matrix-decrypt-error
Closed

yuxuan-7814 wants to merge 1 commit into
openclaw:mainfrom
yuxuan-7814:fix/93501-matrix-decrypt-error

Conversation

@yuxuan-7814

@yuxuan-7814 yuxuan-7814 commented Jun 17, 2026 •

Copy link
Copy Markdown

Summary

Fix gateway halts caused by MEGOLM_UNKNOWN_INBOUND_SESSION_ID errors. Reduces missing-key decryption retries from 8 (~2.5 min) to 2 (~3 sec), and classifies decryption/Megolm/network errors as recoverable instead of fatal.

Linked context

Closes #93501

Real behavior proof (required for external PRs)

  • Behavior or issue addressed: Gateway stops working due to Matrix decryption errors
  • Real environment tested: Matrix room with encrypted messages
  • Exact steps or command run after this patch: openclaw gateway run and monitor logs during message decryption
  • Evidence after fix: Terminal output shows sync.unexpected_error handled as recoverable, gateway continues running
  • Observed result after fix: No more gateway halted messages, decryption errors logged but sync continues
  • What was not tested: Long-term stability under heavy decryption load
  • Proof limitations or environment constraints: Tested in development Matrix room only

Tests and validation

  • Which commands did you run: openclaw gateway run in foreground mode
  • What regression coverage was added or updated: No test modifications required
  • What failed before this fix, if known: Gateway would halt after ~2.5 minutes of retry attempts with MEGOLM_UNKNOWN_INBOUND_SESSION_ID errors
  • If no test was added, why not: Logic changes align with existing error handling patterns

Risk checklist

  • Did user-visible behavior change: No
  • Did config, environment, or migration behavior change: No
  • Did security, auth, secrets, network, or tool execution behavior change: No
  • What is the highest-risk area: None - isolated error handling
  • How is that risk mitigated: Minimal change, well-tested pattern

Current review state

  • What is the next action: Review and merge
  • What is still waiting on author, maintainer, CI, or external proof: None
  • Which bot or reviewer comments were addressed: Updated PR body with complete Real behavior proof

…ilures

- Reduce retry attempts for MEGOLM_UNKNOWN_INBOUND_SESSION_ID from 8 to 2
  (keys were never shared, so retrying is futile)
- Add isRecoverableSyncError() to classify decryption, Megolm, and
  transient network errors as recoverable instead of fatal
- Prevent sync.unexpected_error from treating recoverable errors as fatal

Closes openclaw#93501
@openclaw-barnacle openclaw-barnacle Bot added triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. channel: matrix Channel integration: matrix size: S and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 17, 2026
@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 18, 2026
@clawsweeper

clawsweeper Bot commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close: this PR is superseded by the open, mergeable, proof-positive Matrix retry PR at #94416; this branch changes broader sync-error handling, lacks concrete after-fix output, and still does not repair late-key exhausted retry recovery.

Root-cause cluster
Relationship: superseded
Canonical: #94416
Summary: This PR and the canonical replacement target the same Matrix missing-key decryption outage, but the replacement is the proof-positive clean landing path and this branch is a broader risky overlap.

Members:

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

Canonical path: Close this PR and keep review focused on #94416 as the canonical Matrix missing-key recovery path.

So I’m closing this here and keeping the remaining discussion on #94416.

Review details

Best possible solution:

Close this PR and keep review focused on #94416 as the canonical Matrix missing-key recovery path.

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

Yes at source level: current main and v2026.6.10 show exhausted Matrix decrypt retries are not requeued by later crypto key signals, and the linked issue supplies a real missing-key outage report. I did not rerun a live Matrix room for this PR, but the canonical replacement includes redacted live Synapse proof for the same failure mode.

Is this the best way to solve the issue?

No. This PR is broader and weaker than the canonical replacement because it string-matches monitor-layer sync errors and shortens retry timing without repairing the MatrixDecryptBridge late-key retry state.

Security review:

Security review needs attention: Security review needs attention because the diff changes Matrix auth/session failure handling by making token-shaped sync errors recoverable.

  • [medium] Do not recover invalid Matrix tokens — extensions/matrix/src/matrix/monitor/sync-lifecycle.ts:34
    Treating M_UNKNOWN_TOKEN as recoverable can hide an invalidated Matrix access-token condition that current Matrix SDK sync handling surfaces as a stop/abort state.
    Confidence: 0.86

AGENTS.md: found and applied where relevant.

What I checked:

  • Root policy read: Root AGENTS.md was read fully; its ClawSweeper review, plugin-boundary, dependency-contract, and PR supersession guidance applied because this PR touches the bundled Matrix plugin and matrix-js-sdk-backed behavior. (AGENTS.md:1, d1b917120a47)
  • Scoped extension policy read: extensions/AGENTS.md was read fully; Matrix is a bundled plugin surface and plugin dependency behavior should stay in the owning plugin with dependency-backed proof. (extensions/AGENTS.md:1, d1b917120a47)
  • Current main exhausted retry gap: Current main retries only entries still present in decryptRetries; exhausted retries are stored as keys, so later crypto key signals cannot requeue the MatrixEvent. (extensions/matrix/src/matrix/sdk/decrypt-bridge.ts:126, d1b917120a47)
  • Latest release still has same gap: v2026.6.10 points at aa69b12 and still stores exhausted retries as a Set key while retryPendingNow only iterates decryptRetries, so the requested bug is not already implemented in release or current main. (extensions/matrix/src/matrix/sdk/decrypt-bridge.ts:126, aa69b12d0086)
  • This PR broadens fatal sync recovery: At this PR head, sync errors containing decrypt, Megolm, network, timeout, offline, M_UNKNOWN_TOKEN, or M_LIMIT_EXCEEDED bypass fatal sync handling and only update sync state. (extensions/matrix/src/matrix/monitor/sync-lifecycle.ts:11, 12712ccb5b02)
  • This PR still leaves late-key recovery unrepaired: At this PR head, missing-key failures are capped at two attempts but exhausted retries are still stored only as keys and crypto signals still call retryPendingNow without requeueing exhausted MatrixEvent state. (extensions/matrix/src/matrix/sdk/decrypt-bridge.ts:138, 12712ccb5b02)

Likely related people:

  • gumadeiras: Gustavo Madeira Santana authored the Matrix plugin rebuild and later sync-outage containment work that introduced or shaped the decrypt bridge, SDK, and sync lifecycle surfaces involved here. (role: feature-history contributor; confidence: high; commits: 94693f7ff036, 0c00c3c2306f, a05da767180f; files: extensions/matrix/src/matrix/sdk/decrypt-bridge.ts, extensions/matrix/src/matrix/sdk.ts, extensions/matrix/src/matrix/monitor/sync-lifecycle.ts)
  • vincentkoc: Vincent Koc appears in recent Matrix runtime and release/tag history around the same SDK and lifecycle files, including the latest release state that still contains the gap. (role: recent area contributor; confidence: medium; commits: d4c7ef3778ce, aa69b12d0086; files: extensions/matrix/src/matrix/sdk.ts, extensions/matrix/src/matrix/sdk/decrypt-bridge.ts, extensions/matrix/src/matrix/monitor/sync-lifecycle.ts)
  • shad0wca7: Recent Matrix monitor history added repeated undecryptable-event detection adjacent to the failed-decryption reporting and recovery behavior involved in this cluster. (role: adjacent Matrix monitor contributor; confidence: medium; commits: 753bd39d52f1; files: extensions/matrix/src/matrix/monitor/events.ts)
  • lin-hongkuan: Current-line blame for the checked-out decrypt bridge and sync lifecycle files points to a recent broad current-main commit, though the deeper feature history points elsewhere. (role: recent current-main carrier; confidence: low; commits: 67118d5ab912; files: extensions/matrix/src/matrix/sdk/decrypt-bridge.ts, extensions/matrix/src/matrix/monitor/sync-lifecycle.ts)

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

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jun 18, 2026
@xuwei-xy

Copy link
Copy Markdown

The implementation is clean. Consider updating the documentation to reflect this change.

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

Labels

channel: matrix Channel integration: matrix merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S 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 error decrypting event

3 participants