Skip to content

fix(matrix): isolate per-event failures in _dispatch_sync gather - #57643

Closed
Que0x wants to merge 1 commit into
NousResearch:mainfrom
Que0x:fix/matrix-dispatch-sync-return-exceptions
Closed

fix(matrix): isolate per-event failures in _dispatch_sync gather#57643
Que0x wants to merge 1 commit into
NousResearch:mainfrom
Que0x:fix/matrix-dispatch-sync-return-exceptions

Conversation

@Que0x

@Que0x Que0x commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

_dispatch_sync gathers the mautrix per-event handler tasks with a bare
asyncio.gather(*tasks). Without return_exceptions=True, the first handler
that raises aborts the gather, so the sibling events in the same sync response
are dropped unprocessed
— the exception propagates to the sync loop, which
logs one "sync error" and moves on to the next batch. The invite/redaction
gathers a few lines above already use return_exceptions=True.

Use return_exceptions=True and log each failing handler, so one bad event no
longer takes out the rest of its batch and per-event failures stay visible.

Changes

  • plugins/platforms/matrix/adapter.py_dispatch_sync gathers with
    return_exceptions=True and logs any handler exceptions.
  • tests/gateway/test_matrix.py — add TestMatrixDispatchSyncIsolation.

Tests

pytest tests/gateway/test_matrix.py::TestMatrixDispatchSyncIsolation -q
→ 1 passed

A sync batch with one failing + one succeeding handler no longer raises, the
good handler still runs, and the failure is logged. Mutation-verified: reverting
the change re-raises RuntimeError out of _dispatch_sync.

`_dispatch_sync` gathers the mautrix per-event handler tasks with a bare
`asyncio.gather(*tasks)`. Without `return_exceptions=True`, the first handler
that raises aborts the gather, so the sibling events in the same sync response
are dropped unprocessed — the exception propagates up to the sync loop, which
logs a single "sync error" and moves on. The invite/redaction gathers a few
lines above already use `return_exceptions=True`.

Use `return_exceptions=True` and log each failing handler, so one bad event no
longer takes out the rest of its batch and per-event failures stay visible.

Regression test: a batch with one failing and one succeeding handler no longer
raises, the good handler still runs, and the failure is logged (mutation-
verified — reverting re-raises RuntimeError out of _dispatch_sync).
@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery platform/matrix Matrix adapter (E2EE) sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages P1 High — major feature broken, no workaround labels Jul 3, 2026
@teknium1

teknium1 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Merged via PR #57660 — your commit was cherry-picked onto current main with your authorship preserved in git log (rebase-merge). Thanks for the fix!

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

Labels

comp/gateway Gateway runner, session dispatch, delivery P1 High — major feature broken, no workaround platform/matrix Matrix adapter (E2EE) sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants