Repository navigation
fix(beam): clip mirrored session text without splitting surrogate pairs - #117671
Conversation
|
Codex review: needs maintainer review before merge. Reviewed August 1, 2026, 6:49 PM ET / 22:49 UTC. ClawSweeper reviewWhat this changesThe PR replaces raw UTF-16 slicing of Beam mirror transcript text and session titles with surrogate-safe truncation, then adds regressions for emoji at each clipping boundary. Merge readinessKeep open: current main still slices Beam mirror text at raw UTF-16 code-unit boundaries, while this branch uses the already-published surrogate-safe SDK helper at both affected limits without changing the caps or upload shape. The PR body provides before/after loopback receiver output and the patch adds focused regression coverage. Likely related people: steipete (high-confidence feature owner) and zenglingbiao (medium-confidence adjacent shared-helper contributor). Priority: P2 Review scores
Verification
How this fits togetherBeam mirror reads active local coding-session catalogs, reduces their transcripts to a redacted bounded upload, and POSTs that upload to a remote Beam receiver. Titles and message text are constrained before payload fitting so receiver rows remain valid and readable. flowchart LR
Catalogs[Local session catalogs] --> Mirror[Beam mirror]
Mirror --> Reduce[Redact and reduce transcript]
Reduce --> Clip[UTF-16-safe text clipping]
Clip --> Fit[Bounded upload payload]
Fit --> Receiver[Remote Beam receiver]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +1, Tests +25. Total +26 across 2 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Retain the existing UTF-16 unit caps and wire format, apply the public surrogate-safe SDK helper at both Beam mirror clip sites, and merge after normal current-head CI and maintainer review complete. Do we have a high-confidence way to reproduce the issue? Yes, a high-confidence source reproduction is available: on current main, a title of 159 ASCII code units followed by an emoji reaches the 160-unit slice with only the emoji's high surrogate. The PR also supplies before/after loopback receiver output for that exact path. Is this the best way to solve the issue? Yes. Using the existing public plugin SDK truncation helper fixes the owner-boundary defect at both clip sites while retaining the receiver's code-unit limits; code-point slicing would alter those limits and duplicate the established contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against e49c8339b857. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Maintainer verification for exact contributor head
Thanks @zenglingbiao for the precise producer-owned fix and regression coverage. |
|
Merged via squash.
|
Summary
Clip beam-mirrored session titles and transcript text with
truncateUtf16Safeinstead of UTF-16 code-unitslice, so emoji/CJK characters straddling the clip boundary no longer reach the Beam receiver as a lone surrogate (tofu).What Problem This Solves
extensions/beam/src/mirror.tsuploads local coding-session metadata to a remote Beam receiver. Two user-visible text fields are bounded by raw UTF-16 code-unit slicing:mirror.ts:137—clipTextcuts transcript message text atBEAM_MAX_ITEM_CHARS(6000) withtext.slice(0, ...).mirror.ts:328— the upload title is cut at 160 withcandidate.title.slice(0, 160). The title comes from the session name, which users control.Any character outside the Basic Multilingual Plane (emoji, CJK ext-B) occupies two UTF-16 code units. When such a character straddles the clip boundary,
slicekeeps only the leading high surrogate, producing a lone surrogate that renders as tofu/invalid glyph on the Beam receiver — on every mirrored session row whose name has an emoji at the boundary, and on any clipped long message.Code evidence:
extensions/beam/src/mirror.ts:137andmirror.ts:328both bounded user-controlled text with code-unitslice(0, n).Root Cause
7e8afba7032("feat(plugins): mirror local coding sessions to a remote Beam receiver", 2026-07-27, feat(plugins): mirror local coding sessions to a remote Beam receiver #114735), which added both clip sites with code-unit slicing.slice(0, N); astral characters occupy two UTF-16 units, so the cut can keep half a character.Why This Fix
truncateUtf16Safefromopenclaw/plugin-sdk/text-utility-runtime— the repo's established convention for exactly this bug class (already used insessions-cleanup, signal install, and elsewhere; fix(terminal): keep Unicode cron columns aligned #117062 introduced it for display-width text).truncateUtf16Safe(text, n)is a drop-in for thelength > n ? slice(0, n) : textshape (same length contract) but drops a dangling surrogate at the cut instead of emitting half a character.Array.from(text).slice(0, n).join("")(code-point clip) — changes the cap semantics from UTF-16 units to code points and allocates the whole string; the receiver contract is unit-based, sotruncateUtf16Safeis the minimal correct fix.User Impact
"Fix flow: xxx…\uD83D"— a dangling surrogate rendered as an invalid glyph."Fix flow: xxx…"), no broken glyphs.Evidence
main, a real loopback Beam receiver captures an upload whose session name places 🙂 across the 160-unit cap — received title is 160 units endingU+0078 U+D83D(lone high surrogate) → FAIL.U+0078 U+0078— emoji dropped whole → PASS.Real Behavior Proof
The proof runs the real
createBeamMirrorRunnerpipeline (config parse → candidate selection → upload build → real HTTP POST) against a real loopback Beam receiver and inspects the received title's trailing code units. Session name: 159 code units + 🙂 (161 units), so the emoji straddles the 160-unit cap.Before (on main)
$ node --import tsx proof.mjs session_name_units=161 received_title_units=160 tail_units=U+78 U+d83d FAIL: beam received a title ending in a lone UTF-16 surrogate (tofu)After (with fix)
Tests and Validation
extensions/beam/src/mirror.test.ts:buildBeamMirrorItemsmust not split a surrogate pair when clipping message text at the 6000-unit cap, and the runner must upload a session title with no lone surrogate when the emoji straddles the 160-unit cap. Both fail onmainand pass with the fix; the other 15 tests are unchanged.node scripts/run-vitest.mjs extensions/beam/src/mirror.test.ts— 17/17 tests passed.oxfmt --checkandoxlintclean on both changed files;git diff --checkclean.fitBeamMirrorUploaddrops whole items by byte budget and never slices text); the sametruncateUtf16Safeconvention was applied to sessions cleanup in fix(cli): align sessions cleanup label summary by visible width #117459.