fix(matrix): truncate thread starter body on code-point boundaries#96407
Closed
ly-wang19 wants to merge 1 commit into
Closed
fix(matrix): truncate thread starter body on code-point boundaries#96407ly-wang19 wants to merge 1 commit into
ly-wang19 wants to merge 1 commit into
Conversation
truncateThreadStarterBody (reached via summarizeMatrixThreadStarterEvent) truncated the thread-root body with a raw `value.slice(0, 497)`. When the 500-char boundary falls in the middle of an astral character (emoji etc.), the raw slice cuts the surrogate pair in half and leaves a lone high surrogate before the ellipsis, rendering as a broken/replacement glyph. Use the SDK's surrogate-safe `sliceUtf16Safe` so truncation stops on a code-point boundary, dropping the half character entirely. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Closing this PR because the author has more than 20 active PRs in this repo. Please reduce the active PR queue and reopen or resubmit once it is back under the limit. You can close your own PRs to get back under the limit. |
This was referenced Jun 26, 2026
vincentkoc
pushed a commit
that referenced
this pull request
Jun 26, 2026
…97121) Matrix thread-starter previews truncated long bodies by raw UTF-16 slice, which could cut an astral character (e.g. emoji) and leave a lone surrogate, rendering mojibake in the agent's thread context. Reuse the existing sliceUtf16Safe helper so the cut backs up to a valid surrogate boundary, preserving the 500-code-unit limit and '...' suffix. Adds a regression test that fails against the raw-slice implementation. Salvages the original fix from #96407 (auto-closed by the active-PR queue cap). Preserves @ly-wang19's authorship; rebased clean onto main by @Bartok9. Co-authored-by: ly-wang19 <[email protected]>
Member
|
Superseded by the clean replacement PR #97121, now merged to The landed diff preserves the original Matrix fix and contributor credit, touching only |
wangmiao0668000666
pushed a commit
to wangmiao0668000666/openclaw
that referenced
this pull request
Jun 27, 2026
…penclaw#97121) Matrix thread-starter previews truncated long bodies by raw UTF-16 slice, which could cut an astral character (e.g. emoji) and leave a lone surrogate, rendering mojibake in the agent's thread context. Reuse the existing sliceUtf16Safe helper so the cut backs up to a valid surrogate boundary, preserving the 500-code-unit limit and '...' suffix. Adds a regression test that fails against the raw-slice implementation. Salvages the original fix from openclaw#96407 (auto-closed by the active-PR queue cap). Preserves @ly-wang19's authorship; rebased clean onto main by @Bartok9. Co-authored-by: ly-wang19 <[email protected]>
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Jun 27, 2026
…penclaw#97121) Matrix thread-starter previews truncated long bodies by raw UTF-16 slice, which could cut an astral character (e.g. emoji) and leave a lone surrogate, rendering mojibake in the agent's thread context. Reuse the existing sliceUtf16Safe helper so the cut backs up to a valid surrogate boundary, preserving the 500-code-unit limit and '...' suffix. Adds a regression test that fails against the raw-slice implementation. Salvages the original fix from openclaw#96407 (auto-closed by the active-PR queue cap). Preserves @ly-wang19's authorship; rebased clean onto main by @Bartok9. Co-authored-by: ly-wang19 <[email protected]>
xydigit-zt
pushed a commit
to xydigit-zt/xydigit-zt-openclaw
that referenced
this pull request
Jun 28, 2026
…penclaw#97121) Matrix thread-starter previews truncated long bodies by raw UTF-16 slice, which could cut an astral character (e.g. emoji) and leave a lone surrogate, rendering mojibake in the agent's thread context. Reuse the existing sliceUtf16Safe helper so the cut backs up to a valid surrogate boundary, preserving the 500-code-unit limit and '...' suffix. Adds a regression test that fails against the raw-slice implementation. Salvages the original fix from openclaw#96407 (auto-closed by the active-PR queue cap). Preserves @ly-wang19's authorship; rebased clean onto main by @Bartok9. Co-authored-by: ly-wang19 <[email protected]>
QiuYuang
pushed a commit
to QiuYuang/openclaw
that referenced
this pull request
Jul 1, 2026
…penclaw#97121) Matrix thread-starter previews truncated long bodies by raw UTF-16 slice, which could cut an astral character (e.g. emoji) and leave a lone surrogate, rendering mojibake in the agent's thread context. Reuse the existing sliceUtf16Safe helper so the cut backs up to a valid surrogate boundary, preserving the 500-code-unit limit and '...' suffix. Adds a regression test that fails against the raw-slice implementation. Salvages the original fix from openclaw#96407 (auto-closed by the active-PR queue cap). Preserves @ly-wang19's authorship; rebased clean onto main by @Bartok9. Co-authored-by: ly-wang19 <[email protected]>
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.
What Problem This Solves
truncateThreadStarterBodyinextensions/matrix/src/matrix/monitor/thread-context.ts(reached via the exportedsummarizeMatrixThreadStarterEvent) trims an over-length Matrix thread-root body with a raw UTF-16 slice:String.prototype.sliceoperates on UTF-16 code units, so when the 500-char boundary lands in the middle of an astral character (emoji, many CJK extensions, etc.), the surrogate pair is cut in half. The result is a lone, unpaired high surrogate immediately before the ellipsis, which renders as a broken/replacement glyph (U+FFFD).Repro — a thread-root
m.room.messagewhosecontent.bodyis 496acharacters, then😀(U+1F600 — a surrogate pair at UTF-16 indices 496–497), thenbcd(total length 501):slice(0, 497)cuts the emoji in half, leaving a lone high surrogate:"a".repeat(496) + "\uD83D" + "..."— a broken glyph followed by the ellipsis."a".repeat(496) + "..."— 496as then the ellipsis, no orphaned surrogate.The fix swaps the raw slice for the existing SDK helper
sliceUtf16Safe(fromopenclaw/plugin-sdk/text-utility-runtime), which already backs the surrogate-safe truncation used by the Discord, Slack, Telegram, and other adapters. Behavior is unchanged for short bodies and for long bodies whose cut point is not inside a surrogate pair.Evidence
A standalone Node script replicates the old (buggy) and new (fixed)
truncateThreadStarterBodylogic and asserts the red→green transition plus that unaffected inputs are unchanged:"a".repeat(496) + "\uD83D" + "..."(a lone high surrogate)."a".repeat(496) + "..."with no orphaned surrogate.A matching unit test was added to
extensions/matrix/src/matrix/monitor/thread-context.test.tsthat calls the exportedsummarizeMatrixThreadStarterEventdirectly with the repro body and asserts the surrogate-safe output ("a".repeat(496) + "..."with no surrogate code unit surviving).