synapse icon indicating copy to clipboard operation
synapse copied to clipboard

Room summary API returns "room not found or is inaccessible" incorrectly

Open nexy7574 opened this issue 8 months ago • 5 comments

Description

Attempting to query the MSC3266 room summary endpoint for some specific rooms incorrectly returns that the rooms are inaccessible. This bug does not occur on Dendrite or other Conduit-based servers.

I cannot figure out why, I'm hoping someone with a better understanding of this can attach some more relevant info. However, this bug is causing Element X clients to fail to load room summaries, which actually prevents them from being able to join our rooms.

This also affects the /hierarchy call for the space (mentioned in repro steps) - rooms that cannot be previewed are additionally not returned in the space hierarchy call.

Steps to reproduce

  • Attempt to query https://matrix.to/#/#space:continuwuity.org, https://matrix.to/#/#continuwuity:continuwuity.org, or https://matrix.to/#/#offtopic:continuwuity.org
  • Observe that the aliases resolve to room IDs correctly (!rooms:continuwuity.org, !main-1:continuwuity.org, !offtopic-1:continuwuity.org)
  • The room is not known to the local server, so the federated lookup is performed
  • The federated lookup returns a 200 successfully, but Synapse still claims that the room is unknown.

Homeserver

synapse.nexy7574.co.uk (but also envs.net, matrix.org, littlevortex.net, and nerdhouse.io)

Synapse Version

1.128.0 (and 1.129.0rc1)

Installation Method

Docker (matrixdotorg/synapse)

Database

PostgreSQL (mono, no port, no backup)

Workers

Single process

Platform

synapse.nexy7574.co.uk is running on an ubuntu LXC in a docker container. I also tested on maunapse.nexy7574.co.uk, which is on the same LXC, but is not running in docker.

Hardware seems irrelevant.

Configuration

trusted_key_servers:
  - server_name: maunium.net
  - server_name: sulian.eu
  - server_name: codestorm.net
  - server_name: littlevortex.net
redaction_retention_period: 61d
experimental_features:
  msc2815_enabled: true
  msc2409_to_device_messages_enabled: true
  msc3202_device_masquerading: true
  msc3202_transaction_extensions: true
  msc3266_enabled: true
  msc4210_enabled: true
  msc4222_enabled: true
  msc4133_enabled: true
  msc3852_enabled: true

presence is disabled

Relevant log output

2025-04-23 15:32:51,658 - synapse.access.http.8020 - 463 - DEBUG - GET-125 - 81.102.249.156 - 8020 - Received request: GET /_matrix/client/v3/directory/room/%23continuwuity:continuwuity.org
2025-04-23 15:32:51,659 - synapse.http.matrixfederationclient - 688 - DEBUG - GET-125 - {GET-O-12} [continuwuity.org] Sending request: GET matrix-federation://continuwuity.org/_matrix/federation/v1/query/directory?room_alias=%23continuwuity%3Acontinuwuity.org; timeout 10.000000s
2025-04-23 15:32:51,659 - synapse.util.metrics - 179 - DEBUG - GET-125 - Entering block outbound_request
2025-04-23 15:32:51,659 - synapse.util.metrics - 179 - DEBUG - GET-125 - Entering block get_well_known
2025-04-23 15:32:51,659 - synapse.http.federation.well_known_resolver - 260 - INFO - GET-125 - Fetching https://continuwuity.org/.well-known/matrix/server
2025-04-23 15:32:51,659 - synapse.http.proxyagent - 326 - DEBUG - GET-125 - Requesting https://continuwuity.org/.well-known/matrix/server via <HostnameEndpoint continuwuity.org:443>
2025-04-23 15:32:51,678 - synapse.metrics._gc - 125 - DEBUG - sentinel - Collecting gc 0
2025-04-23 15:32:51,768 - synapse.http.federation.well_known_resolver - 197 - INFO - GET-125 - Response from .well-known: {'m.server': 'matrix.continuwuity.org:443'}
2025-04-23 15:32:51,769 - synapse.util.metrics - 192 - DEBUG - GET-125 - Exiting block get_well_known
2025-04-23 15:32:51,769 - synapse.http.federation.matrix_federation_agent - 360 - DEBUG - GET-125 - Connecting to matrix.continuwuity.org:443
2025-04-23 15:32:51,869 - synapse.util.metrics - 192 - DEBUG - GET-125 - Exiting block outbound_request
2025-04-23 15:32:51,870 - synapse.http.matrixfederationclient - 739 - DEBUG - GET-125 - {GET-O-12} [continuwuity.org] Got response headers: 200 OK
2025-04-23 15:32:51,870 - synapse.http.matrixfederationclient - 364 - INFO - GET-125 - {GET-O-12} [continuwuity.org] Completed request: 200 OK in 0.21 secs, got 737 bytes - GET matrix-federation://continuwuity.org/_matrix/federation/v1/query/directory?room_alias=%23continuwuity%3Acontinuwuity.org
2025-04-23 15:32:51,870 - synapse.storage.txn - 761 - DEBUG - GET-125 - [TXN START] {get_partial_state_servers_at_join-1a49}
2025-04-23 15:32:51,870 - synapse.storage.txn - 865 - DEBUG - GET-125 - [TXN END] {get_partial_state_servers_at_join-1a49} 0.000175 sec
2025-04-23 15:32:51,871 - synapse.storage.txn - 761 - DEBUG - GET-125 - [TXN START] {get_users_in_room-1a4a}
2025-04-23 15:32:51,871 - synapse.storage.txn - 865 - DEBUG - GET-125 - [TXN END] {get_users_in_room-1a4a} 0.000194 sec
2025-04-23 15:32:51,872 - synapse.access.http.8020 - 508 - INFO - GET-125 - 81.102.249.156 - 8020 - {None} Processed request: 0.213sec/0.000sec (0.002sec, 0.000sec) (0.000sec/0.000sec/2) 737B 200 "GET /_matrix/client/v3/directory/room/%23continuwuity:continuwuity.org HTTP/1.1" "gomuks/0.4.0+dev.fc324671 mautrix-go/v0.23.2+dev.99ff0c09 go/1.24.2" [0 dbevts]
2025-04-23 15:32:51,884 - synapse.access.http.8020 - 463 - DEBUG - GET-126 - 81.102.249.156 - 8020 - Received request: GET /_matrix/client/unstable/im.nheko.summary/summary/%23continuwuity:continuwuity.org?via=2o4.ca&via=synapse.nexy7574.co.uk&via=myriation.xyz
2025-04-23 15:32:51,884 - synapse.http.matrixfederationclient - 688 - DEBUG - GET-126 - {GET-O-13} [continuwuity.org] Sending request: GET matrix-federation://continuwuity.org/_matrix/federation/v1/query/directory?room_alias=%23continuwuity%3Acontinuwuity.org; timeout 10.000000s
2025-04-23 15:32:51,884 - synapse.util.metrics - 179 - DEBUG - GET-126 - Entering block outbound_request
2025-04-23 15:32:51,912 - synapse.util.metrics - 192 - DEBUG - GET-126 - Exiting block outbound_request
2025-04-23 15:32:51,912 - synapse.http.matrixfederationclient - 739 - DEBUG - GET-126 - {GET-O-13} [continuwuity.org] Got response headers: 200 OK
2025-04-23 15:32:51,912 - synapse.http.matrixfederationclient - 364 - INFO - GET-126 - {GET-O-13} [continuwuity.org] Completed request: 200 OK in 0.03 secs, got 737 bytes - GET matrix-federation://continuwuity.org/_matrix/federation/v1/query/directory?room_alias=%23continuwuity%3Acontinuwuity.org
2025-04-23 15:32:51,913 - synapse.storage.txn - 761 - DEBUG - GET-126 - [TXN START] {is_host_joined-1a4b}
2025-04-23 15:32:51,913 - synapse.storage.txn - 865 - DEBUG - GET-126 - [TXN END] {is_host_joined-1a4b} 0.000249 sec
2025-04-23 15:32:51,913 - synapse.handlers.room_summary - 512 - INFO - GET-126 - Requesting summary for !main-1:continuwuity.org via ['continuwuity.org', '2o4.ca', 'synapse.nexy7574.co.uk', 'myriation.xyz', 'chat.atiusamy.com', 'explodie.org', 'vrkknn.net', 'noevil.pl', 'n8y.dev', 'matrix.techwork.zone', 'everypizza.im', 'ellis.link', 'd3v0.me', 'skhron.org', 'aguiarvieira.pt', 'morj.men', 'julian45.net', 'feline.support', 'stbn.xyz', 'tomfos.tr', 'nexy7574.co.uk', 'matrix.org', 'transgender.ing', 'booq.org', 'nerdhouse.io', 'rue.nabulator.com', 'dimensionproject.net', 'littlevortex.net', 'ncat.cafe', 'sulian.eu', 'igland.xyz', 'cont.everypizza.im', 'krvtz.net', 'catboyindustries.co', 'joeth.uk', 'bopsen.club', 'craftingcomrades.net', 'rory.gay', 'unredacted.org', 'codestorm.net', 'nexy7574.uk', 'kde.org', 'magmaus3.eu.org', 'nyanbinary.rs', 'envs.net']
2025-04-23 15:32:51,914 - synapse.http.matrixfederationclient - 688 - DEBUG - GET-126 - {GET-O-14} [continuwuity.org] Sending request: GET matrix-federation://continuwuity.org/_matrix/federation/v1/hierarchy/%21main-1%3Acontinuwuity.org?suggested_only=true; timeout 60.000000s
2025-04-23 15:32:51,914 - synapse.util.metrics - 179 - DEBUG - GET-126 - Entering block outbound_request
2025-04-23 15:32:51,942 - synapse.util.metrics - 192 - DEBUG - GET-126 - Exiting block outbound_request
2025-04-23 15:32:51,942 - synapse.http.matrixfederationclient - 739 - DEBUG - GET-126 - {GET-O-14} [continuwuity.org] Got response headers: 200 OK
2025-04-23 15:32:51,942 - synapse.http.matrixfederationclient - 364 - INFO - GET-126 - {GET-O-14} [continuwuity.org] Completed request: 200 OK in 0.03 secs, got 510 bytes - GET matrix-federation://continuwuity.org/_matrix/federation/v1/hierarchy/%21main-1%3Acontinuwuity.org?suggested_only=true
2025-04-23 15:32:51,943 - synapse.storage.txn - 761 - DEBUG - GET-126 - [TXN START] {get_filtered_current_state_ids-1a4c}
2025-04-23 15:32:51,943 - synapse.storage.txn - 865 - DEBUG - GET-126 - [TXN END] {get_filtered_current_state_ids-1a4c} 0.000285 sec
2025-04-23 15:32:51,943 - synapse.handlers.room_summary - 591 - INFO - GET-126 - room !main-1:continuwuity.org is unknown, omitting from summary
2025-04-23 15:32:51,943 - synapse.http.server - 130 - INFO - GET-126 - <XForwardedForRequest at 0x73c604b930e0 method='GET' uri='/_matrix/client/unstable/im.nheko.summary/summary/%23continuwuity:continuwuity.org?via=2o4.ca&via=synapse.nexy7574.co.uk&via=myriation.xyz' clientproto='HTTP/1.1' site='8020'> SynapseError: 404 - Room not found or is not accessible
2025-04-23 15:32:51,944 - synapse.access.http.8020 - 508 - INFO - GET-126 - 81.102.249.156 - 8020 - {@nex:maunapse.nexy7574.co.uk} Processed request: 0.060sec/0.000sec (0.003sec, 0.001sec) (0.000sec/0.001sec/2) 71B 404 "GET /_matrix/client/unstable/im.nheko.summary/summary/%23continuwuity:continuwuity.org?via=2o4.ca&via=synapse.nexy7574.co.uk&via=myriation.xyz HTTP/1.1" "gomuks/0.4.0+dev.fc324671 mautrix-go/v0.23.2+dev.99ff0c09 go/1.24.2" [0 dbevts]

Anything else that would be useful to know?

Response from synapse:

{
  "errcode": "M_NOT_FOUND",
  "error": "Room not found or is not accessible"
}

Response from Continuwuity 0.5.0rc5:

{
  "room_id": "!offtopic-1:continuwuity.org",
  "canonical_alias": "#offtopic:continuwuity.org",
  "avatar_url": "mxc://rory.gay/vxEICAarGiRIWzNxFpngUoDa",
  "guest_can_join": false,
  "name": "Continuwuity Offtopic",
  "num_joined_members": 39,
  "topic": "Breakout offtopic room for the Continuwuity community",
  "world_readable": false,
  "join_rule": "public",
  "im.nheko.summary.room_version": "11",
  "membership": "leave"
}
Dendrite does not support the room summary API, however, the space hierarchy resolves correctly (which it does not on Synapse, presumably as a result of this issue):
{
  "rooms": [
    {
      "canonical_alias": "#space:continuwuity.org",
      "name": "Continuwuity",
      "num_joined_members": 41,
      "room_id": "!rooms:continuwuity.org",
      "topic": "Space for the Continuwuity rooms",
      "world_readable": false,
      "guest_can_join": false,
      "join_rule": "public",
      "children_state": [
        {
          "type": "m.space.child",
          "state_key": "!moderation:continuwuity.org",
          "content": {
            "order": "7g7g7c",
            "suggested": false,
            "via": [
              "continuwuity.org"
            ]
          },
          "sender": "@nex:continuwuity.org",
          "origin_server_ts": 1745166312763
        },
        {
          "type": "m.space.child",
          "state_key": "!bans:continuwuity.org",
          "content": {
            "order": "OOOOOI",
            "suggested": false,
            "via": [
              "continuwuity.org"
            ]
          },
          "sender": "@nex:continuwuity.org",
          "origin_server_ts": 1745166312768
        },
        {
          "type": "m.space.child",
          "state_key": "!main-1:continuwuity.org",
          "content": {
            "order": "+s+s+p",
            "suggested": true,
            "via": [
              "continuwuity.org"
            ]
          },
          "sender": "@nex:continuwuity.org",
          "origin_server_ts": 1745166321385
        },
        {
          "type": "m.space.child",
          "state_key": "!offtopic-1:continuwuity.org",
          "content": {
            "order": "1m1m1i",
            "suggested": true,
            "via": [
              "continuwuity.org"
            ]
          },
          "sender": "@nex:continuwuity.org",
          "origin_server_ts": 1745166324606
        },
        {
          "type": "m.space.child",
          "state_key": "!dev-1:continuwuity.org",
          "content": {
            "order": "4j4j4f",
            "suggested": false,
            "via": [
              "continuwuity.org"
            ]
          },
          "sender": "@nex:continuwuity.org",
          "origin_server_ts": 1745166326638
        },
        {
          "type": "m.space.child",
          "state_key": "!minecraft-1:continuwuity.org",
          "content": {
            "auto_join": false,
            "order": "696963",
            "suggested": false,
            "via": [
              "continuwuity.org"
            ]
          },
          "sender": "@nex:continuwuity.org",
          "origin_server_ts": 1745166329559
        },
        {
          "type": "m.space.child",
          "state_key": "!0hQX7RWvN1Bj3twFQR:tomfos.tr",
          "content": {
            "auto_join": false,
            "order": "_?_?_:",
            "suggested": false,
            "via": [
              "tomfos.tr",
              "continuwuity.org",
              "nexy7574.co.uk"
            ]
          },
          "sender": "@nex:continuwuity.org",
          "origin_server_ts": 1745190224337
        },
        {
          "type": "m.space.child",
          "state_key": "!releases:continuwuity.org",
          "content": {
            "auto_join": false,
            "order": "%y%y%v",
            "suggested": true,
            "via": [
              "tomfos.tr",
              "continuwuity.org"
            ]
          },
          "sender": "@nex:continuwuity.org",
          "origin_server_ts": 1745190232928
        }
      ],
      "room_type": "m.space"
    },
    {
      "canonical_alias": "#continuwuity:continuwuity.org",
      "name": "Continuwuity",
      "num_joined_members": 45,
      "room_id": "!main-1:continuwuity.org",
      "topic": "Continuwuity general on-topic room | Docs: https://continuwuity.org/ | CoC: https://continuwuity.org/conduwuit_coc | Forge: https://forgejo.ellis.link/continuwuation/continuwuity | space: #space:continuwuity.org",
      "world_readable": false,
      "guest_can_join": false,
      "children_state": [],
      "room_type": ""
    },
    {
      "canonical_alias": "#offtopic:continuwuity.org",
      "name": "Continuwuity Offtopic",
      "num_joined_members": 32,
      "room_id": "!offtopic-1:continuwuity.org",
      "topic": "Breakout offtopic room for the Continuwuity community",
      "world_readable": false,
      "guest_can_join": false,
      "children_state": [],
      "room_type": ""
    },
    {
      "canonical_alias": "#dev:continuwuity.org",
      "name": "Continuwuity Development",
      "num_joined_members": 18,
      "room_id": "!dev-1:continuwuity.org",
      "topic": "Meta room for discussing continuwuity development and contributions",
      "world_readable": false,
      "guest_can_join": false,
      "children_state": [],
      "room_type": ""
    },
    {
      "canonical_alias": "#minecraft:continuwuity.org",
      "name": "Continuwuity Minecraft 🧊",
      "num_joined_members": 17,
      "room_id": "!minecraft-1:continuwuity.org",
      "topic": "Join minecraft.continuwuity.org in either Java (1.21.4) or Bedrock!\nPlease be considerate and respect other people - this is a co-operative survival world!",
      "world_readable": false,
      "guest_can_join": false,
      "children_state": [],
      "room_type": ""
    },
    {
      "canonical_alias": "#releases:continuwuity.org",
      "name": "Continuwuity Releases",
      "num_joined_members": 14,
      "room_id": "!releases:continuwuity.org",
      "topic": "A room to announce Continuwuity releases",
      "world_readable": false,
      "guest_can_join": false,
      "children_state": [],
      "room_type": ""
    }
  ]
}

nexy7574 avatar Apr 23 '25 15:04 nexy7574

Implementation bug found in the summary implementation: join_rule=None is treated incorrectly, should be treated as public, but currently fails the condition join_rule in (JoinRules.PUBLIC, JoinRules.KNOCK, JoinRules.KNOCK_RESTRICTED)

TheArcaneBrony avatar Apr 23 '25 17:04 TheArcaneBrony

I thought having no join rule was equivalent to invite, not public.

clokep avatar Apr 26 '25 12:04 clokep

s2s hierarchy is inverted - see https://spec.matrix.org/v1.14/server-server-api/#get_matrixfederationv1hierarchyroomid_response-200_spacehierarchychildroomschunk

join_rule: The room’s join rule. When not present, the room is assumed to be public.

nexy7574 avatar Apr 26 '25 12:04 nexy7574

Querying continuwuity.org's hierarchy for the offtopic room using the following command:

./scripts-dev/federation_client.py -N continuwuity.org -k ../config/my.signing.key --server-name example.org -d continuwuity.org '/_matrix/federation/v1/hierarchy/!main-1:continuwuity.org'

we get the following response:

{
  "children": [],
  "inaccessible_children": [],
  "room": {
    "canonical_alias": "#continuwuity:continuwuity.org",
    "name": "Continuwuity",
    "num_joined_members": 159,
    "room_id": "!main-1:continuwuity.org",
    "topic": "Continuwuity general on-topic room | Docs: https://continuwuity.org/ | Guidelines: https://continuwuity.org/community | Forge: https://forgejo.ellis.link/continuwuation/continuwuity | space: #space:continuwuity.org",
    "world_readable": true,
    "guest_can_join": false,
    "join_rule": "public",
    "children_state": [],
    "im.nheko.summary.room_version": "11"
  }
}

the join_rule received is "public". Did this used to be null when this issue was created?

It appears that the relevant code is here, in _is_local_room_accessible:

https://github.com/element-hq/synapse/blob/7c633f1a58e22ea27a172efdc52d94bfdac8c728/synapse/handlers/room_summary.py#L572-L592

which makes little sense, as this is a remote room. We should not have ended up here.

This method is called by _is_remote_room_accessible:

https://github.com/element-hq/synapse/blob/7c633f1a58e22ea27a172efdc52d94bfdac8c728/synapse/handlers/room_summary.py#L701-L723

and @TheArcaneBrony is right, in that:

https://github.com/element-hq/synapse/blob/7c633f1a58e22ea27a172efdc52d94bfdac8c728/synapse/handlers/room_summary.py#L703-L708

does not account for a join_rule of null equating to public. All that needs to happen is that line changed to room.get("join_rule", JoinRules.PUBLIC).

PR's welcome, and ideally a Complement test for this scenario as well.

anoadragon453 avatar May 09 '25 10:05 anoadragon453

@anoadragon453

the join_rule received is "public". Did this used to be null when this issue was created?

Yes, we have deployed a temporary patch to Continuwuity due to the volume of people complaining our space is broken or they flat out can't join on Element X. People on our latest release (most of our users) won't have this patch, so still an issue.

PR's welcome, and ideally a Complement test for this scenario as well.

Will get to that when I have a moment, unless someone beats me to it.

nexy7574 avatar May 11 '25 20:05 nexy7574

Not sure why this wasn't closed; PR was merged, bug is now fixed

nexy7574 avatar Jun 20 '25 16:06 nexy7574