Skip to content

fix(matrix): stop retry loop on token introspection auth errors - #57150

Open
tianma-if wants to merge 1 commit into
NousResearch:mainfrom
tianma-if:codex/fix-matrix-introspection-auth-loop
Open

fix(matrix): stop retry loop on token introspection auth errors#57150
tianma-if wants to merge 1 commit into
NousResearch:mainfrom
tianma-if:codex/fix-matrix-introspection-auth-loop

Conversation

@tianma-if

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes the Matrix sync loop so mautrix token introspection failures are treated as permanent auth errors instead of transient sync errors retried forever.

The adapter already stopped on 401/403/unauthorized/forbidden and unknown-token responses; this adds the observed Unable to introspect the access token failure mode to the same classification and shares that classification between returned sync error objects and thrown exceptions.

Related Issue

Fixes #56532

Type of Change

  • Bug fix
  • Tests
  • New feature
  • Documentation
  • Refactor

Changes

  • Adds a small Matrix permanent-auth marker helper.
  • Classifies Unable to introspect the access token as a permanent auth condition.
  • Keeps transient sync exceptions retryable.
  • Adds a regression test that verifies the introspection failure stops after one sync attempt.

How to Test

  • .venv/bin/python -m pip install aiohttp (local test dependency needed by existing Mattermost tests in the same file)
  • .venv/bin/python -m pytest tests/gateway/test_ws_auth_retry.py -q
  • .venv/bin/python -m ruff check plugins/platforms/matrix/adapter.py tests/gateway/test_ws_auth_retry.py
  • scripts/run_tests.sh tests/gateway/test_ws_auth_retry.py -q
  • pytest tests/ -q

Platform: macOS, Python 3.13, local .venv.

@alt-glitch alt-glitch added type/bug Something isn't working comp/plugins Plugin system and bundled plugins platform/matrix Matrix adapter (E2EE) P3 Low — cosmetic, nice to have sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages labels Jul 2, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Competing with #56547 for the same issue #56532. #56547 adds "introspect" to the exception-path one-liner only; this PR (#57150) is a superset — it factors a shared _PERMANENT_AUTH_ERROR_MARKERS helper and applies it to both the SyncError-object path and the thrown-exception path in _sync_loop. Related, not a duplicate (same code site, broader coverage). Flagging the pair for a maintainer to pick.

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for covering the Matrix sync retry failure. The premise remains live on current main: plugins/platforms/matrix/adapter.py:2335-2348 retries exceptions unless their text contains 401, 403, unauthorized, or forbidden, so the reported introspection message reaches the five-second retry branch.

Problems

  • The new test covers the thrown-exception path, but the helper is also wired into the returned sync-object path. The existing object-path test at tests/gateway/test_ws_auth_retry.py:115-153 protects only M_UNKNOWN_TOKEN, not the new introspection marker.

Suggested changes

  • Add a returned-object regression with .message = "Unable to introspect the access token" and assert one sync call.
  • Reconcile this marker classifier with related #57375 before salvage; its review discussion identifies a false-positive risk in the existing raw substring classification.

Automated hermes-sweeper review.

@@ -187,6 +187,41 @@ async def run():
asyncio.run(run())
assert call_count == 1

def test_introspection_auth_error_stops_loop(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a companion regression that returns a sync-result object with message = "Unable to introspect the access token". This PR also routes returned objects through the new helper, while this test only exercises the exception branch.

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

Labels

comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have platform/matrix Matrix adapter (E2EE) sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform 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.

[Bug]:[Matrix] Gateway enters permanent sync retry loop after "Unable to introspect the access token" although token remains valid

3 participants