Skip to content

fix(matrix): guard autojoin and crypto hooks against unhandled rejections - #67

Closed
strk-ai-agent wants to merge 2 commits into
ominiverdi:mainfrom
strk-ai-agent:fix/matrix-unhandled-rejections
Closed

fix(matrix): guard autojoin and crypto hooks against unhandled rejections#67
strk-ai-agent wants to merge 2 commits into
ominiverdi:mainfrom
strk-ai-agent:fix/matrix-unhandled-rejections

Conversation

@strk-ai-agent

Copy link
Copy Markdown

Problem

matrix-bot-sdk installs internal listeners whose returned promises are never awaited:

  • the autojoin handler does return client.joinRoom(roomId) without awaiting, so a failed join (rescinded invite, re-invite into a room the bot was kicked from, M_FORBIDDEN) becomes an unhandled rejection
  • the crypto client hooks (room.join, room.event) installed by RustSdkCryptoStorageProvider have the same issue

In Bun an unhandled rejection aborts the process, and the resulting jolt to the napi-rs tokio runtime produces the "called Option::unwrap() on a None value" panic during cleanup.

Changes

  • Replace the room.invite autojoin handler with a guarded version that logs failures instead of crashing
  • Wrap the crypto room.join / room.event handlers with .catch() and logging
  • Make DM detection resilient: M_FORBIDDEN from getJoinedRoomMembers (room not fully joined yet) is treated as "not a DM" with a clean bail-out
  • Add process-level unhandledRejection / uncaughtException handlers in main() as a last line of defense
  • Add unit tests covering the M_FORBIDDEN DM path

Verification

bun test tests/unit/matrix-empty-response.test.ts passes 9/9.

strk added 2 commits August 3, 2026 22:19
Assisted-By: MiniMax-M3 [via opencode 1.18.9]
…ions

matrix-bot-sdk installs internal listeners (autojoin, RustSdk crypto room
events) whose returned promises are never awaited. A failure (e.g. a
rescinded invite or M_FORBIDDEN on a room being joined) surfaces as an
unhandled rejection, which aborts the Bun process and trips the napi-rs
tokio runtime panic during cleanup. Replace those handlers with guarded
versions and log errors instead.

Also wrap the DM check so M_FORBIDDEN from getJoinedRoomMembers (room not
fully joined yet) is treated as "not a DM" instead of tearing down the
bot, and add process-level unhandledRejection/uncaughtException handlers
as a last line of defense.

Assisted-By: big-pickle [via opencode 1.18.9]
@ominiverdi

Copy link
Copy Markdown
Owner

Closing under the updated contribution policy. The current submission volume and required verification exceed this project’s review capacity, and pull requests from autonomous or delegated agent accounts are no longer accepted. Valid underlying issues may remain open for independent implementation. Please do not revise, reopen, or replace this pull request.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants