Skip to content

Conversation

@H-Shay
Copy link
Contributor

@H-Shay H-Shay commented Oct 6, 2025

It is often useful when investigating a space to get information about that space and it's children. This PR adds an Admin API to return information about a space and it's children, regardless of room membership. Will not return information about remote rooms that the server is not participating in.

@H-Shay H-Shay requested a review from a team as a code owner October 6, 2025 18:20
@github-actions github-actions bot deployed to PR Documentation Preview October 6, 2025 18:25 Active
@H-Shay
Copy link
Contributor Author

H-Shay commented Oct 6, 2025

test failures appear to be flakes

Copy link
Contributor

@MadLittleMods MadLittleMods left a comment

Choose a reason for hiding this comment

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

Haven't reviewed the code much as there may be a potential pivot (see review comments)

@H-Shay H-Shay changed the title Add an admin API to search for the parent space of a room Add an admin API to search for children of a room Oct 15, 2025
@github-actions github-actions bot deployed to PR Documentation Preview October 15, 2025 22:37 Active
@H-Shay H-Shay requested a review from MadLittleMods October 15, 2025 23:03
@H-Shay
Copy link
Contributor Author

H-Shay commented Oct 16, 2025

failures look like flakes

@github-actions github-actions bot deployed to PR Documentation Preview October 17, 2025 18:22 Active
@H-Shay H-Shay requested a review from MadLittleMods October 17, 2025 19:29
@github-actions github-actions bot deployed to PR Documentation Preview October 20, 2025 20:22 Active
@H-Shay H-Shay requested a review from MadLittleMods October 20, 2025 20:50
@github-actions github-actions bot deployed to PR Documentation Preview October 21, 2025 19:44 Active
@github-actions github-actions bot deployed to PR Documentation Preview October 21, 2025 19:49 Active
@github-actions github-actions bot deployed to PR Documentation Preview October 21, 2025 19:54 Active
@github-actions github-actions bot deployed to PR Documentation Preview October 21, 2025 20:24 Active
@H-Shay H-Shay requested a review from MadLittleMods October 21, 2025 20:28
Comment on lines 259 to 260
# only room_id and children_state fields are returned for remote rooms
self.assertEqual(len(room_result["children_state"]), 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems a little misleading as it's unknown, not zero. Feels like this should be left unset in the remote room cases that we don't fetch.

Copy link
Contributor Author

@H-Shay H-Shay Oct 22, 2025

Choose a reason for hiding this comment

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

The default entry for _RoomEntry is ()

@attr.s(frozen=True, slots=True, auto_attribs=True)
class _RoomEntry:
    room_id: str
    # The room summary for this room.
    room: JsonDict
    # An iterable of the sorted, stripped children events for children of this room.
    #
    # This may not include all children.
    children_state_events: Sequence[JsonDict] = ()

which gets converted to json for the response by this:

    def as_json(self, for_client: bool = False) -> JsonDict:
        """
        Returns a JSON dictionary suitable for the room hierarchy endpoint.

        It returns the room summary including the stripped m.space.child events
        as a sub-key.

        Args:
            for_client: If true, any server-server only fields are stripped from
                the result.

        """
        result = dict(self.room)

        # Before returning to the client, remove the allowed_room_ids key, if it
        # exists.
        if for_client:
            result.pop("allowed_room_ids", False)

        result["children_state"] = self.children_state_events
        return result

So I think to leave children_state unset I think we'd have to change the structure of _Room_Entry to an optional and have as_json omit children_state in the case where self.children_state is None, but that seems clunkier than having the children_state be an empty list in the case of remote rooms we don't fetch - thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am wondering if this could be addressed by adding a comment about the face that children_state is unknown in the case of remote rooms in the endpoint documentation?

Copy link
Contributor

@MadLittleMods MadLittleMods Oct 23, 2025

Choose a reason for hiding this comment

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

After thinking about this more, I think we can just omit remote rooms altogether (no need for bare room_id entries). The client can still find the unknown remote rooms via the m.space.child in the children_state of the space. Further thoughts tracked in matrix-org/matrix-spec#2237

It still makes sense to call the option omit_remote_room_hierarchy and we just need to remove this part: #19021 (comment)

@github-actions github-actions bot deployed to PR Documentation Preview October 23, 2025 17:23 Active
@github-actions github-actions bot deployed to PR Documentation Preview October 23, 2025 17:30 Active
@H-Shay H-Shay requested a review from MadLittleMods October 23, 2025 17:55
{"room2", "room3", "remote_room"},
)

for room_result in rooms:
Copy link
Contributor

Choose a reason for hiding this comment

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

This is only testing the rooms from the first request 😬

rooms = rooms + new_rooms was removed in b187d6f

Perhaps we should just put this in a helper self._assert_expected_rooms_have_correct_fields(rooms) and call this after each request.

Copy link
Contributor Author

@H-Shay H-Shay Oct 23, 2025

Choose a reason for hiding this comment

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

I changed it in the last round so that each request was being asserted on separately for only the rooms that should have been returned from each request - I think this should be fine and not necessitate a helper?

Copy link
Contributor

Choose a reason for hiding this comment

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

We do this for both tests so could simplify down to a helper.

Otherwise, we probably want to have an else clause for unknown rooms even though we're asserting specific rooms above in the assertCountEqual.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a an else clause to fail the return of an unknown room (line 356 and 271 - sorry can't figure out how to link a line in a PR diff in the UI), would that suffice?

Comment on lines 326 to 329
# if we are not fetching remote room details over federation, return what is
# known about the room
elif omit_remote_room_hierarchy:
room_entry = _RoomEntry(room_id, {"room_id": room_id}, ())
Copy link
Contributor

@MadLittleMods MadLittleMods Oct 23, 2025

Choose a reason for hiding this comment

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

(marking part to remove)

See other discussion, #19021 (comment)

Comment on lines 259 to 260
# only room_id and children_state fields are returned for remote rooms
self.assertEqual(len(room_result["children_state"]), 0)
Copy link
Contributor

@MadLittleMods MadLittleMods Oct 23, 2025

Choose a reason for hiding this comment

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

After thinking about this more, I think we can just omit remote rooms altogether (no need for bare room_id entries). The client can still find the unknown remote rooms via the m.space.child in the children_state of the space. Further thoughts tracked in matrix-org/matrix-spec#2237

It still makes sense to call the option omit_remote_room_hierarchy and we just need to remove this part: #19021 (comment)

@github-actions github-actions bot deployed to PR Documentation Preview October 23, 2025 22:44 Active
@github-actions github-actions bot deployed to PR Documentation Preview October 23, 2025 22:56 Active
@H-Shay H-Shay requested a review from MadLittleMods October 23, 2025 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants