Skip to content

UnboundLocalError: now_token in /sync for appservice bots using MSC3202 (regression in v1.150.0) #19618

Closed

Description

@Just-Insane

Description

Synapse v1.150.0 causes all /sync requests from appservice bridge bots to fail with HTTP 500 when msc4190_enabled: true. Every bridge bot's sync crashes every ~10 seconds, breaking all E2EE message delivery to/from bridges.

Steps to reproduce

Steps to reproduce:

  • Enable MSC4190 in homeserver.yaml: experimental_features: { msc4190_enabled: true }
  • Start any mautrix bridge (discord, signal, whatsapp, etc.) with E2EE enabled
  • Bridge bot calls GET /_matrix/client/v3/sync?org.matrix.msc3202.device_id=<device_id>&user_id=@bot:example.com
  • Synapse returns HTTP 500 on every sync request from the bot

What happened vs expected:
Expected: Bridge bots sync successfully and can participate in E2EE rooms.
Actual: Every sync request returns HTTP 500 with UnboundLocalError: cannot access local variable 'now_token'. All bridges stop receiving/decrypting messages.

Workaround: Setting msc4354_enabled: false fully resolves the issue, indicating the regression was introduced by #19487 (MSC4354 sticky events in legacy /sync).

Homeserver

Self-hosted (matrix.cloudhub.social)

Synapse Version

1.150.0

Installation Method

Docker (matrixdotorg/synapse)

Database

PostgreSQL: single server, no recent restore

Workers

Single process

Platform

Docker container, Linux (Debian)

Configuration

experimental_features:
  msc4354_enabled: true  # sticky events — disabling this is the workaround

Relevant log output

UnboundLocalError: cannot access local variable 'now_token' where it is not associated with a value
  File ".../synapse/http/server.py", line 335, in _async_render_wrapper
  File ".../synapse/http/server.py", line 576, in _async_render
  File ".../synapse/rest/client/sync.py", line 271, in on_GET
  File ".../synapse/handlers/sync.py", line 365, in wait_for_sync_for_user
  File ".../synapse/util/caches/response_cache.py", line 402, in wrap
  File ".../synapse/util/caches/response_cache.py", line 343, in cb
UnboundLocalError: cannot access local variable 'now_token' where it is not associated with a value

Anything else that would be useful to know?

No response

Activity

  1. tulir commented on Mar 27, 2026

    @tulir
    Contributor

    This is not related to the bug, but note that there's no experimental_features key called msc4190_enabled and never has been, that field is a no-op. Also, the device_id query param was moved to MSC4326. MSC3202 is the solution for replacing /sync, so if you're using /sync, you're not using MSC3202. Both MSC4190 and MSC4326 are already in the spec (but MSC3202 is not)

  2. Just-Insane commented on Mar 27, 2026

    @Just-Insane
    Author

    Ah, yup, my bad. I am using the Matrix-Docker-Ansible-Deploy playbook with the following config:

    # See https://github.com/matrix-org/matrix-spec-proposals/pull/4140
    matrix_synapse_experimental_features_msc4140_enabled: true
    
    # See `matrix_synapse_experimental_features_msc4140_enabled`.
    matrix_synapse_max_event_delay_duration: 730h
    
    # See https://github.com/matrix-org/matrix-spec-proposals/pull/4143
    matrix_synapse_experimental_features_msc4143_enabled: true
    
    # See https://github.com/matrix-org/matrix-spec-proposals/pull/4222
    matrix_synapse_experimental_features_msc4222_enabled: true
    
    # See:
    # - https://github.com/matrix-org/matrix-spec-proposals/pull/4306
    # - https://github.com/matrix-org/matrix-spec-proposals/pull/4308
    matrix_synapse_experimental_features_msc4306_enabled: true
    
    # See https://github.com/matrix-org/matrix-spec-proposals/pull/4354
    matrix_synapse_experimental_features_msc4354_enabled: false
    
    ## Bridges
    matrix_bridges_encryption_enabled: true
    matrix_bridges_encryption_default: true
    matrix_bridges_msc4190_enabled: true
    matrix_bridges_self_sign_enabled: true
    matrix_bridges_relay_enabled: true

    With matrix_synapse_experimental_features_msc4354_enabled: true, I get the error from this issue.

  3. MadLittleMods commented on Apr 2, 2026

    @MadLittleMods
    Contributor

    Bug is here and introduced in #19487 as you suspected:

    now_token, sticky_by_room = await self.sticky_events_by_room(
    sync_result_builder, now_token, since_token
    )

    It should be using sync_result_builder.now_token.

    It sucks that we don't have any linters that yell about the Unbound value. I can see the typing in VSCode.

    cc @reivilibre

  4. MadLittleMods commented on May 16, 2026

    @MadLittleMods
    Contributor

    This is fixed by #19787

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions