Skip to content

fix(msteams): keep truncated parent context text well-formed#96569

Merged
vincentkoc merged 1 commit into
openclaw:mainfrom
WeeLi-009:fix/msteams-parent-truncate
Jun 27, 2026
Merged

fix(msteams): keep truncated parent context text well-formed#96569
vincentkoc merged 1 commit into
openclaw:mainfrom
WeeLi-009:fix/msteams-parent-truncate

Conversation

@WeeLi-009

@WeeLi-009 WeeLi-009 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Summary: The Teams parent-message summary was truncated with a raw UTF-16 slice, so an emoji at the 400-char boundary became a lone surrogate in the injected Replying to @sender: … context event. This uses the shared truncateUtf16Safe helper to truncate on a code-point boundary.

What Problem This Solves

MS Teams thread parent context summarization truncated long parent-message text with raw UTF-16 slicing. When the 400-character parent preview limit landed between the high and low surrogate of an emoji, the generated Replying to @sender: ... context could contain a lone surrogate.

Trigger input:

  • parent text starts with 398 ASCII characters
  • followed by an emoji such as 🦞 (U+1F99E, encoded as a UTF-16 surrogate pair)
  • followed by additional text
  • legacy truncation used slice(0, 399) + "…" and kept only the high surrogate before the ellipsis

That leaves malformed text in the injected MS Teams parent-context event and can break consumers that require well-formed strings.

Fix

extensions/msteams/src/thread-parent-context.ts now reuses the shared truncateUtf16Safe helper from openclaw/plugin-sdk/text-utility-runtime when shortening parent-message text.

The fix keeps the existing 400-character parent-context limit and ellipsis behavior, but the truncation boundary is now validated before the ellipsis is appended. If the limit would split a surrogate pair, the helper backs up to the last complete UTF-16 boundary, so the final escaped/injected parent context remains well-formed.

Evidence

Command run from an isolated temporary worktree on fix/msteams-parent-truncate:

node --import tsx demo.mts

Terminal output:

input.length=450
emoji.codePoint=1f99e
BEFORE legacy slice(0, 399) + ellipsis
before.length=400
before.tailCodeUnits=0061 0061 0061 d83e 2026
before.loneSurrogate=true
before.loneSurrogateCodeUnit=d83e
before.encodeURIComponent=URIError
AFTER summarizeParentMessage (real msteams repair path)
after.text=aaaaaaaaaaaaaaaaaaaa…[398 ×'a' elided]…
after.length=399
after.tailCodeUnits=0061 0061 0061 0061 2026
after.loneSurrogate=false
after.endsWithHighSurrogateEllipsis=false
after.encodeURIComponent=aaaaaaaaa%E2%80%A6

This demo calls the real exported summarizeParentMessage path from extensions/msteams/src/thread-parent-context.ts. The legacy reproduction leaves a lone high surrogate (d83e) and throws URIError during URI encoding; the fixed path returns well-formed text with loneSurrogate=false.

Tests

extensions/msteams/src/thread-parent-context.test.ts adds focused Vitest regression coverage for surrogate-boundary truncation in MS Teams parent-context summaries.

The test constructs the same boundary shape, verifies the summarized text does not match the unpaired-surrogate regex, confirms the emoji is not split before the ellipsis, and preserves the expected compact parent-context output shape.

@openclaw-barnacle openclaw-barnacle Bot added channel: msteams Channel integration: msteams size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jun 24, 2026
@clawsweeper

clawsweeper Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 26, 2026, 2:32 AM ET / 06:32 UTC.

Summary
The PR changes the MS Teams parent-message summary truncation path to use truncateUtf16Safe and adds a surrogate-boundary regression test.

PR surface: Source +3, Tests +19. Total +22 across 2 files.

Reproducibility: yes. Current main and v2026.6.10 both raw-slice the parent summary before appending the ellipsis, and the PR body includes terminal proof showing the legacy lone-surrogate/URIError case versus the fixed well-formed output.

Review metrics: none identified.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Wait for pending exact-head CI checks to finish green or document any unrelated failure before merge.

Risk before merge

  • [P1] Exact-head CI still had pending broad checks during review; merge should wait for those to complete green or for a maintainer to document an unrelated failure.

Maintainer options:

  1. Decide the mitigation before merge
    Land this focused MS Teams parent-context helper reuse after exact-head CI completes, keeping the sibling reflection-prompt truncation fix in its separate PR.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • No automated repair is identified; maintainers should review the clean patch and wait for exact-head CI completion before merge.

Security
Cleared: The diff imports an existing SDK helper and adds a focused test; it does not change dependencies, workflows, secrets, permissions, package resolution, generated artifacts, or external I/O.

Review details

Best possible solution:

Land this focused MS Teams parent-context helper reuse after exact-head CI completes, keeping the sibling reflection-prompt truncation fix in its separate PR.

Do we have a high-confidence way to reproduce the issue?

Yes. Current main and v2026.6.10 both raw-slice the parent summary before appending the ellipsis, and the PR body includes terminal proof showing the legacy lone-surrogate/URIError case versus the fixed well-formed output.

Is this the best way to solve the issue?

Yes. Reusing the exported truncateUtf16Safe helper at the truncation source is narrower and more maintainable than a Teams-local surrogate regex or a downstream sanitizer.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 4fc504d321b6.

Label changes

Label justifications:

  • P2: This is a focused MS Teams message-context correctness fix with limited blast radius and clear source/proof evidence.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes terminal output from a script calling the real MS Teams summarizer and showing the legacy lone-surrogate/URIError case versus the fixed well-formed output.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes terminal output from a script calling the real MS Teams summarizer and showing the legacy lone-surrogate/URIError case versus the fixed well-formed output.
Evidence reviewed

PR surface:

Source +3, Tests +19. Total +22 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 4 1 +3
Tests 1 19 0 +19
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 23 1 +22

What I checked:

Likely related people:

  • zhang-guiping: Current-main blame shows the present thread-parent-context.ts truncation code was added on main by bead84f. (role: recent area contributor; confidence: medium; commits: bead84f0ee6e; files: extensions/msteams/src/thread-parent-context.ts, extensions/msteams/src/thread-parent-context.test.ts, extensions/msteams/src/monitor-handler/message-handler.ts)
  • sudie-codes: History shows the MS Teams parent-context feature and its tests were originally added in 01ea7e4. (role: feature introducer; confidence: high; commits: 01ea7e49212a, 9edfefedf7bf, 38aa1edf76da; files: extensions/msteams/src/thread-parent-context.ts, extensions/msteams/src/thread-parent-context.test.ts, extensions/msteams/src/monitor-handler/message-handler.ts)
  • steipete: History shows the shared invalid-UTF-16 truncation helper used by this PR was introduced in 63f5fa4, with adjacent utility and MS Teams work afterward. (role: shared helper introducer; confidence: medium; commits: 63f5fa47deb6, 11b0016e9e79, 625fd5b3e3e2; files: src/utils.ts, src/plugin-sdk/text-utility-runtime.ts, extensions/msteams/src/monitor-handler/message-handler.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Jun 24, 2026
@WeeLi-009
WeeLi-009 force-pushed the fix/msteams-parent-truncate branch from b40fef9 to 0888744 Compare June 25, 2026 00:22
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Jun 25, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jun 25, 2026
summarizeParentMessage truncated the parent body with text.slice(0, PARENT_TEXT_MAX_CHARS - 1), which can cut a surrogate pair in half and emit a lone surrogate into the injected "Replying to @sender: …" system event. Use the shared truncateUtf16Safe helper so truncation falls back to a whole code-point boundary. Add a regression asserting the summary stays isWellFormed() when the limit lands inside an emoji.
@WeeLi-009
WeeLi-009 force-pushed the fix/msteams-parent-truncate branch from 0888744 to ca210f7 Compare June 26, 2026 06:24
@vincentkoc
vincentkoc merged commit 4b9e018 into openclaw:main Jun 27, 2026
87 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jun 28, 2026
…w#96569)

summarizeParentMessage truncated the parent body with text.slice(0, PARENT_TEXT_MAX_CHARS - 1), which can cut a surrogate pair in half and emit a lone surrogate into the injected "Replying to @sender: …" system event. Use the shared truncateUtf16Safe helper so truncation falls back to a whole code-point boundary. Add a regression asserting the summary stays isWellFormed() when the limit lands inside an emoji.
QiuYuang pushed a commit to QiuYuang/openclaw that referenced this pull request Jul 1, 2026
…w#96569)

summarizeParentMessage truncated the parent body with text.slice(0, PARENT_TEXT_MAX_CHARS - 1), which can cut a surrogate pair in half and emit a lone surrogate into the injected "Replying to @sender: …" system event. Use the shared truncateUtf16Safe helper so truncation falls back to a whole code-point boundary. Add a regression asserting the summary stays isWellFormed() when the limit lands inside an emoji.
chenyangjun-xy pushed a commit to chenyangjun-xy/openclaw that referenced this pull request Jul 1, 2026
…w#96569)

summarizeParentMessage truncated the parent body with text.slice(0, PARENT_TEXT_MAX_CHARS - 1), which can cut a surrogate pair in half and emit a lone surrogate into the injected "Replying to @sender: …" system event. Use the shared truncateUtf16Safe helper so truncation falls back to a whole code-point boundary. Add a regression asserting the summary stays isWellFormed() when the limit lands inside an emoji.
chenyangjun-xy pushed a commit to chenyangjun-xy/openclaw that referenced this pull request Jul 3, 2026
…w#96569)

summarizeParentMessage truncated the parent body with text.slice(0, PARENT_TEXT_MAX_CHARS - 1), which can cut a surrogate pair in half and emit a lone surrogate into the injected "Replying to @sender: …" system event. Use the shared truncateUtf16Safe helper so truncation falls back to a whole code-point boundary. Add a regression asserting the summary stays isWellFormed() when the limit lands inside an emoji.
hugenshen added a commit to hugenshen/openclaw that referenced this pull request Jul 7, 2026
…void lone surrogates

The Mattermost inbound handler in extensions/mattermost/src/mattermost/monitor.ts
truncates the message body preview with bodyText.slice(0, 200), which can split a
UTF-16 surrogate pair when an emoji (e.g. 🎉, 🦞) or other astral character lands at
the 200-char boundary. The resulting lone surrogate half leaks into the verbose log
preview and could propagate to downstream consumers that reject ill-formed strings.

Replace the raw .slice(0, 200) with the shared truncateUtf16Safe helper (from
openclaw/plugin-sdk/text-utility-runtime), which backs up one code unit when the cut
would land inside a surrogate pair. This matches the same pattern already applied to
the Slack, Discord, Telegram, IRC, Line, MS Teams, and Feishu channel previews
(openclaw#96456, openclaw#96569, openclaw#96572, openclaw#96577, openclaw#96578, openclaw#97462, openclaw#97472, openclaw#98994).

The preview is only used for the verbose inbound log line so the behavioral change
is cosmetic: when the 200th code unit would split an emoji, the preview now includes
one fewer code unit rather than emitting a broken surrogate.
hugenshen added a commit to hugenshen/openclaw that referenced this pull request Jul 7, 2026
…void lone surrogates

The Mattermost inbound handler in extensions/mattermost/src/mattermost/monitor.ts
truncates the message body preview with bodyText.slice(0, 200), which can split a
UTF-16 surrogate pair when an emoji (e.g. 🎉, 🦞) or other astral character lands at
the 200-char boundary. The resulting lone surrogate half leaks into the verbose log
preview and could propagate to downstream consumers that reject ill-formed strings.

Replace the raw .slice(0, 200) with the shared truncateUtf16Safe helper (from
openclaw/plugin-sdk/text-utility-runtime), which backs up one code unit when the cut
would land inside a surrogate pair. This matches the same pattern already applied to
the Slack, Discord, Telegram, IRC, Line, MS Teams, and Feishu channel previews
(openclaw#96456, openclaw#96569, openclaw#96572, openclaw#96577, openclaw#96578, openclaw#97462, openclaw#97472, openclaw#98994).

The preview is only used for the verbose inbound log line so the behavioral change
is cosmetic: when the 200th code unit would split an emoji, the preview now includes
one fewer code unit rather than emitting a broken surrogate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: msteams Channel integration: msteams P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants