Skip to content

Conversation

@MadLittleMods
Copy link
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
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
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
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
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
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)

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
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.

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.

4 participants