Repository navigation
connector: cut off long messages so they fit in a Matrix event - #308
Merged
Merged
Conversation
Inbound LINE messages whose body, formatted body and mentions add up to more than the homeserver's 64 KiB event limit once encrypted were rejected with M_BAD_JSON and never bridged. Apply the same cutoff as mautrix-whatsapp to every converted part: drop ghost mentions, shorten the plain-text fallback when a formatted body is present, and cut the remaining text at 40k bytes.
Contributor
Author
|
No issues found.
All CI checks passed on
Select any unchecked box below to run or rerun that agent. Full resultsIndent Review Agent
|
highesttt
requested changes
Nov 4, 2026
highesttt
left a comment
Collaborator
There was a problem hiding this comment.
Size check uses raw bytes, but the limit is on the JSON-encoded event. Quote-heavy HTML can pass the check and still be too large. Measure the encoded size instead
The homeserver limit applies to the encoded event, where quotes, angle brackets and ampersands expand to escape sequences, so raw string lengths could pass the check while the event stayed too large. Measure json.Marshal output, and binary-search the cut point so escape-heavy text isn't cut far shorter than needed.
highesttt
enabled auto-merge (squash)
November 4, 2026 15:33
highesttt
self-requested a review
November 4, 2026 15:33
highesttt
approved these changes
Nov 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Production logs from the last 24 h show 60
Failed to send message part to Matrixerrors withM_BAD_JSON: event content can't be over 64 KiB, across 5 accounts and 30 distinct LINE messages. The encrypted send requests were ~75 KB, so the plaintext content was around 55 KB. These messages are never bridged. Since they're never saved, the recent-message backfill re-queues them on every restart and they fail again.Cause:
convertLineMessagehas no size limit. A long LINE text keeps the full text inbody, and when it has mentions or inline sticons, the same text is copied again intoformatted_body, together withm.mentions.Change: after conversion, each part whose JSON-encoded content is over 40,000 bytes goes through a cutoff modeled on mautrix-whatsapp (whatsapp#988/#995). Ghost mentions are dropped. If a formatted body is present, the plain-text fallback is shortened to 500 bytes. If it's still too large, the formatted body (then the body) is cut at a rune and tag boundary, with a "[long message cut off]" marker. The cut point is found by binary search on the encoded size, because quotes,
<,>and&expand when escaped. A warn line logs the LINE content type and the encoded size before and after the cut.Tag
@indentto continue the conversation here.