Skip to content

Add log to determine whether clients are using /messages as expected#19226

Merged
MadLittleMods merged 10 commits intodevelopfrom
madlittlemods/better-messages-endpoint-typing
Dec 1, 2025
Merged

Add log to determine whether clients are using /messages as expected#19226
MadLittleMods merged 10 commits intodevelopfrom
madlittlemods/better-messages-endpoint-typing

Conversation

@MadLittleMods
Copy link
Copy Markdown
Contributor

@MadLittleMods MadLittleMods commented Nov 25, 2025

Add log to determine whether clients are using /messages as expected

Spawning from wanting some better homeserver logs to debug #19153. We can check whether we are returning a /messages response with an end pagination token and then check to see whether the client is making another /messages request with that token.

Although clients should also have similar logs and debugging capabilities to determine this info as well. This just makes it easier for us when someone creates an issue claiming backend issue and we can ask them for homeserver logs.

Dev notes

COMPLEMENT_DIR=../complement COMPLEMENT_ALWAYS_PRINT_SERVER_LOGS=1 ./scripts-dev/complement.sh ./tests/csapi/... -run TestMessagesOverFederation

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
    • Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry.
  • Code style is correct (run the linters)

Comment on lines +910 to +922
# Useful for debugging timeline/pagination issues. For example, if a client
# isn't seeing the full history, we can check the homeserver logs to see if the
# client just never made the next request with the given `end` token.
logger.info(
"Responding to `/messages` request: {%s} %s %s -> %d messages with end_token=%s",
requester.user.to_string(),
request.get_method(),
request.get_redacted_uri(),
len(get_messages_result.messages_chunk),
(await get_messages_result.end_token.to_string(self.store))
if get_messages_result.end_token
else None,
)
Copy link
Copy Markdown
Contributor Author

@MadLittleMods MadLittleMods Nov 25, 2025

Choose a reason for hiding this comment

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

This is the main objective of this PR.

The rest is just refactoring for better types and separation of concerns so we can pull it out easier instead of shoddy JSON dict lookups.

# Useful for debugging timeline/pagination issues. For example, if a client
# isn't seeing the full history, we can check the homeserver logs to see if the
# client just never made the next request with the given `end` token.
logger.info(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Using logger.info(...) as it's at the same logging level as our access logs:

synapse.access.http.8080 - 521 - INFO - GET-9 - ::ffff:127.0.0.1 - 8080 - {@user-2-bob:hs2} Processed request: 1.535sec/0.000sec (0.019sec, 0.001sec) (0.086sec/0.076sec/135) 861B 200 "GET /_matrix/client/r0/rooms/%21zCWZKZWGiStxkXpoSZ:hs1/messages?dir=b&limit=10 HTTP/1.0" "Go-http-client/1.1" [4 dbevts]

@MadLittleMods MadLittleMods marked this pull request as ready for review November 25, 2025 23:06
@MadLittleMods MadLittleMods requested a review from a team as a code owner November 25, 2025 23:06
state, time_now, config=serialize_options
)

return chunk
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Better separation of concerns. We now do the serializing/encoding at the REST layer instead of in the handler (see encode_messages_response)

Copy link
Copy Markdown
Contributor

@reivilibre reivilibre left a comment

Choose a reason for hiding this comment

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

can't argue with any of that, nice cleanup :)

Comment on lines +915 to +917
requester.user.to_string(),
request.get_method(),
request.get_redacted_uri(),
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.

are these fields useful, given they would be visible in the same logcontext?

(Don't mind either way)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Useful to me as I don't want to dig and correlate 🤷

Comment on lines +101 to +105
"""
A list of state events relevant to showing the chunk. For example, if
lazy_load_members is enabled in the filter then this may contain the membership
events for the senders of events in the chunk.
"""
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: we should also state that this field is omitted from the response if it's none, as we do with end_token.

And perhaps especially note that empty lists will be omitted as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated docstring ✅

And perhaps especially note that empty lists will be omitted as well.

Updated to only omit when explicitly None

@MadLittleMods MadLittleMods merged commit 88310fe into develop Dec 1, 2025
78 of 80 checks passed
@MadLittleMods MadLittleMods deleted the madlittlemods/better-messages-endpoint-typing branch December 1, 2025 23:10
@MadLittleMods
Copy link
Copy Markdown
Contributor Author

Thanks for the review @reivilibre and @anoadragon453 🐠

reivilibre added a commit that referenced this pull request Dec 11, 2025
The team has decided to deprecate and stop publishing python wheels for MacOS.
Synapse docker images will continue to work on MacOS, as will building Synapse
from source (though note this requires a Rust compiler).

Admins using the unstable [MSC2666](matrix-org/matrix-spec-proposals#2666) endpoint (`/_matrix/client/unstable/uk.half-shot.msc2666/user/mutual_rooms`),
please check [the relevant section in the upgrade notes](https://github.com/element-hq/synapse/blob/develop/docs/upgrade.md#upgrading-to-v11440) as this release contains changes
that disable that endpoint by default.

No significant changes since 1.144.0rc1.

Admins using the unstable [MSC2666](matrix-org/matrix-spec-proposals#2666) endpoint (`/_matrix/client/unstable/uk.half-shot.msc2666/user/mutual_rooms`), please check [the relevant section in the upgrade notes](https://github.com/element-hq/synapse/blob/develop/docs/upgrade.md#upgrading-to-v11440) as this release contains changes that disable that endpoint by default.

- Add experimentatal implememntation of [MSC4380](matrix-org/matrix-spec-proposals#4380) (invite blocking). ([\#19203](#19203))
- Allow restarting delayed event timeouts on workers. ([\#19207](#19207))

- Fix a bug in the database function for fetching state deltas that could result in unnecessarily long query times. ([\#18960](#18960))
- Fix v12 rooms when running with `use_frozen_dicts: True`. ([\#19235](#19235))
- Fix bug where invalid `canonical_alias` content would return 500 instead of 400. ([\#19240](#19240))
- Fix bug where `Duration` was logged incorrectly. ([\#19267](#19267))

- Document in the `--config-path` help how multiple files are merged - by merging them shallowly. ([\#19243](#19243))

- Stop building release wheels for MacOS. ([\#19225](#19225))

- Improve event filtering for Simplified Sliding Sync. ([\#17782](#17782))
- Export `SYNAPSE_SUPPORTED_COMPLEMENT_TEST_PACKAGES` environment variable from `scripts-dev/complement.sh`. ([\#19208](#19208))
- Refactor `scripts-dev/complement.sh` logic to avoid `exit` to facilitate being able to source it from other scripts (composable). ([\#19209](#19209))
- Expire sliding sync connections that are too old or have too much pending data. ([\#19211](#19211))
- Require an experimental feature flag to be enabled in order for the unstable [MSC2666](matrix-org/matrix-spec-proposals#2666) endpoint (`/_matrix/client/unstable/uk.half-shot.msc2666/user/mutual_rooms`) to be available. ([\#19219](#19219))
- Prevent changelog check CI running on @dependabot's PRs even when a human has modified the branch. ([\#19220](#19220))
- Auto-fix trailing spaces in multi-line strings and comments when running the lint script. ([\#19221](#19221))
- Move towards using a dedicated `Duration` type. ([\#19223](#19223), [\#19229](#19229))
- Improve robustness of the SQL schema linting in CI. ([\#19224](#19224))
- Add log to determine whether clients are using `/messages` as expected. ([\#19226](#19226))
- Simplify README and add ESS Getting started section. ([\#19228](#19228), [\#19259](#19259))
- Add a unit test for ensuring associated refresh tokens are erased when a device is deleted. ([\#19230](#19230))
- Prompt user to consider adding future deprecations to the changelog in release script. ([\#19239](#19239))
- Fix check of the Rust compiled code being outdated when using source checkout and `.egg-info`. ([\#19251](#19251))
- Stop building macos wheels in CI pipeline. ([\#19263](#19263))

* Bump Swatinem/rust-cache from 2.8.1 to 2.8.2. ([\#19244](#19244))
* Bump actions/checkout from 5.0.0 to 6.0.0. ([\#19213](#19213))
* Bump actions/setup-go from 6.0.0 to 6.1.0. ([\#19214](#19214))
* Bump actions/setup-python from 6.0.0 to 6.1.0. ([\#19245](#19245))
* Bump attrs from 25.3.0 to 25.4.0. ([\#19215](#19215))
* Bump docker/metadata-action from 5.9.0 to 5.10.0. ([\#19246](#19246))
* Bump http from 1.3.1 to 1.4.0. ([\#19249](#19249))
* Bump pydantic from 2.12.4 to 2.12.5. ([\#19250](#19250))
* Bump pyopenssl from 25.1.0 to 25.3.0. ([\#19248](#19248))
* Bump rpds-py from 0.28.0 to 0.29.0. ([\#19216](#19216))
* Bump rpds-py from 0.29.0 to 0.30.0. ([\#19247](#19247))
* Bump sentry-sdk from 2.44.0 to 2.46.0. ([\#19218](#19218))
* Bump types-bleach from 6.2.0.20250809 to 6.3.0.20251115. ([\#19217](#19217))
* Bump types-jsonschema from 4.25.1.20250822 to 4.25.1.20251009. ([\#19252](#19252))
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.

3 participants