Skip to content

fix: keep emoji intact when a gateway text frame is split - #1630

Merged
shanselman merged 5 commits into
openclaw:mainfrom
SebTardif:fix/f028-websocket-split-char
Oct 6, 2026
Merged

shanselman merged 5 commits into
openclaw:mainfrom
SebTardif:fix/f028-websocket-split-char

Conversation

@SebTardif

@SebTardif SebTardif commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Chat, canvas, and config text is corrupted when one character arrives in two WebSocket frames.

User Impact

Emoji and non-English characters stay intact when the gateway splits a text message across frames.

Why This Change Was Made

Each frame was decoded on its own. A UTF-8 character cut between frames became a replacement character on both sides. The receive loop now keeps one decoder for the message and flushes it only when the frame ends the message. Explicit fragmentation tracking also handles a first fragment that produces zero characters.

Evidence

Contributor-reported before-fix loopback result:

Assert.Equal() Failure: Strings differ
Expected: "hi😀"
Actual:   "hi���"

Fresh maintainer validation at 18b0e53c51f1e77656c83fa235332991deee2450 passed both real-socket regressions: split hi😀 followed by next, and an emoji-only first message whose initial fragment produces zero characters followed by another fragmented message. Neither result contains replacement characters.

The contributor's earlier proof was recorded at f43c4e2e7cc54597c58596e82a9799ce55cc3366. Its tree and the current head tree are identical (2006f05c2ce975e5feaf072addbfa4d67c7f5f04); the three later commits only retriggered CI. Historical contributor totals are not presented as this fresh run.

Change Type

  • Bug fix
  • Feature
  • Refactor
  • Docs or instructions
  • Tests or validation
  • Security hardening
  • Chore or infrastructure

Scope

  • Tray or WinUI UX
  • Windows node capability
  • Local MCP or winnode
  • Gateway, connection, or pairing
  • Setup or onboarding
  • Permissions, privacy, or security
  • Tests, CI, or docs

Required proof pools

  • none: this is a shared text-decoding repair with real loopback WebSocket proof. No tray page, node command contract, installer, WSL setup, or pairing behavior changed.

Validation

Fresh maintainer run on native Windows ARM64, isolated worktree, exact head 18b0e53c51f1e77656c83fa235332991deee2450. OPENCLAW_REPO_ROOT points to this worktree; OPENCLAW_TRAY_DATA_DIR and OPENCLAW_TRAY_LOCAL_DATA_DIR point to session-isolated directories. Fresh test projects were built before --no-restore so these counts represent executed tests.

Command Result
.\build.ps1 Exit 0; all five projects built, documentation gate passed
dotnet build .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --verbosity quiet Exit 0
dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore --filter FullyQualifiedName~WebSocketClientBaseTests 37 passed, 0 skipped, 0 failed
dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore 4224 passed, 36 skipped, 0 failed; 4260 total
dotnet build .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --verbosity quiet Exit 0
dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore 3893 passed, 0 skipped, 0 failed

Each test command additionally used a TRX logger and session-local results directory. Local logs and transport.trx, shared.trx, and tray.trx are retained in the landing session artifacts. No local failure or retry occurred.

  • Exact-head CI run 37222672047, attempt 1: success; required CI Gate passed.
  • Current landing base 9dedabe66187a1438a1e6a1f9c49b98f99581218: CI run 37395675439, attempt 1 passed core/CLI, tray/setup/integration, UI/accessibility, recovery and setup E2E, plus release builds.
  • git merge-tree --write-tree origin/main HEAD produced clean candidate tree 40d9104e431d2bfc87d97fff87ee75cfa0b3fee9. Relative to current main it contains exactly the original two-file change. Neither touched file changed on main since the PR merge-base, so no speculative branch refresh was needed. The candidate combined tree was inspected, not separately executed.
  • Direct bounded maintainer review: no blocking findings. Stateful decoder capacity, zero-character fragments, message-boundary reset, pooled buffer return, accumulation limit, and connection-generation guard checked. Separate rubber-duck review not required for this narrow transport repair with no new UI/MCP/node-command/setup/pairing/security/permissions/diagnostics contract.

Real Behavior Proof

  • Environment tested: native Windows ARM64, isolated local worktree.
  • PR head tested: 18b0e53c51f1e77656c83fa235332991deee2450.
  • Command: focused WebSocketClientBaseTests run listed above.
  • SplitUtf8Character_SurvivesTwoFramesAndTheNextMessage: passed. Real HttpListener/ClientWebSocket transport sends 68 69 F0 9F then 98 80, yielding hi😀, then next.
  • ZeroCharFirstFragment_DoesNotCorruptTheNextSplitMessage: passed. Sends F0 9F then 98 80, then fragmented next; records the emoji and next without replacement characters.
  • Observed result: all 37 transport tests passed, including both introduced regressions.
  • Screenshot or artifact links verified: N/A; current results are retained as local TRX artifacts rather than published media.
  • Not verified / blocked: no live gateway session or UI capture was used. The production receive loop is exercised through real loopback sockets. The 36 Shared skips remain unexecuted coverage, including opt-in integration/MXC, symlink prerequisites, and hardware-specific tests; no skips are counted as passes. These unrelated pools are not required for this text-only change.

Security Impact

  • New permissions or capabilities? No
  • Secrets or tokens handling changed? No
  • New or changed network calls? No
  • Command or tool execution surface changed? No
  • Data access scope changed? No
  • If any answer is Yes, explain the risk and mitigation:

Compatibility and Migration

  • Backward compatible? Yes
  • Config or environment changes? No
  • Migration needed? No

Review Conversations

  • I replied to or resolved every bot review conversation addressed by this PR.
  • I left unresolved only conversations that still need maintainer judgment.

Live review-thread check: zero inline threads. Contributor implementation and authorship preserved; no code changes were needed during landing.

A multi-frame WebSocket message was decoded with GetChars on each
chunk. A UTF-8 character split across those frames became U+FFFD on
both sides, so chat and canvas text lost emoji and non-English
characters. The receive loop now keeps one decoder for the message
and flushes it only when the frame ends the message.

The regression drives a real loopback socket: the four UTF-8 bytes of
an emoji are split 2 and 2, and the next message still decodes.

Signed-off-by: Sebastien Tardif <[email protected]>
@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 message-delivery 🚨 Merging this PR could drop, duplicate, misroute, suppress, or wrongly target messages. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 4, 2026
@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed October 5, 2026, 11:32 PM ET / October 6, 2026, 03:32 UTC (Revision 6).

ClawSweeper review

What this changes

The PR preserves emoji and other UTF-8 characters across fragmented gateway messages and adds two real-socket regression tests.

Merge readiness

✅ Ready for maintainer review

The fix remains necessary: current main and the latest release still decode text fragments independently. The earlier fragment-tracking finding is resolved, the real-socket evidence covers the changed receive path, and no blocking defect remains.

Priority: P2
Reviewed head: 18b0e53c51f1e77656c83fa235332991deee2450

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused transport repair with before/after real-socket evidence, two complementary regressions, reported required validation, and no remaining blocking findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The reported Windows 11 loopback execution sends deliberately split emoji bytes through real WebSockets and the production shared receive loop, observing intact emoji and correctly isolated following messages after the fix. The tested source is unchanged at the pinned head. A live Gateway session was not exercised; no stored-data contract changes.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The reported Windows 11 loopback execution sends deliberately split emoji bytes through real WebSockets and the production shared receive loop, observing intact emoji and correctly isolated following messages after the fix. The tested source is unchanged at the pinned head. A live Gateway session was not exercised; no stored-data contract changes.
Evidence reviewed 8 items Pinned introduced change: The merge-base-to-head diff changes only the shared receive loop and its tests. Fragment tracking is independent of decoded character count; the decoder flushes at message completion and resets before another message.
Current main still needs the repair: Current main uses Encoding.UTF8.GetChars separately for each fragment and selects the complete-message fast path using StringBuilder length. It does not contain the proposed decoder repair.
Latest release also retains the defect: The v2026.9.4 source uses the same independent per-fragment decoding. No shipped replacement for this repair was established.
Findings None None.
Security None None.

How this fits together

The shared WebSocket transport receives gateway messages for both the operator and Windows node clients. It assembles text before passing complete messages to their protocol handlers.

flowchart TD
  A[Gateway text frames] --> B[Shared receive loop]
  B --> C{Fragmented message}
  C -->|No| D[Decode complete text]
  C -->|Yes| E[Retain UTF-8 decoder state]
  E --> F[Flush at message end]
  D --> G[Operator and node handlers]
  F --> G
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and test LOC production +18/-6 (net +12), tests +74/-0 The production growth implements message-scoped decoding, with two focused socket regressions protecting character preservation and message isolation.

Technical review

Best possible solution:

Keep UTF-8 decoder state within each fragmented message while preserving the complete-message fast path and existing transport safeguards.

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

Yes. Splitting an emoji's UTF-8 bytes across text fragments exercises the independently decoding current-main path; the contributor reports a failing-before and passing-after real-socket run. This reviewer did not execute it.

Is this the best way to solve the issue?

Yes. Message-scoped decoding is a focused repair in the existing transport owner, and explicit fragment tracking handles prefixes that produce no characters without contaminating the next message.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 9dedabe66187.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: This repairs bounded text corruption when a gateway message splits a UTF-8 character across receive fragments.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The reported Windows 11 loopback execution sends deliberately split emoji bytes through real WebSockets and the production shared receive loop, observing intact emoji and correctly isolated following messages after the fix. The tested source is unchanged at the pinned head. A live Gateway session was not exercised; no stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The reported Windows 11 loopback execution sends deliberately split emoji bytes through real WebSockets and the production shared receive loop, observing intact emoji and correctly isolated following messages after the fix. The tested source is unchanged at the pinned head. A live Gateway session was not exercised; no stored-data contract changes.

Evidence

What I checked:

  • Pinned introduced change: The merge-base-to-head diff changes only the shared receive loop and its tests. Fragment tracking is independent of decoded character count; the decoder flushes at message completion and resets before another message. (src/OpenClaw.Shared/WebSocketClientBase.cs:465, 18b0e53c51f1)
  • Current main still needs the repair: Current main uses Encoding.UTF8.GetChars separately for each fragment and selects the complete-message fast path using StringBuilder length. It does not contain the proposed decoder repair. (src/OpenClaw.Shared/WebSocketClientBase.cs:459, 9dedabe66187)
  • Latest release also retains the defect: The v2026.9.4 source uses the same independent per-fragment decoding. No shipped replacement for this repair was established. (src/OpenClaw.Shared/WebSocketClientBase.cs:459, 3c43751b2bac)
  • Production-boundary real-socket proof: The captured PR body reports Windows 11 before/after loopback execution: split emoji bytes previously produced replacement characters, then produced hi😀 followed by next. A second run covers an emoji fragment that initially decodes to zero characters and a subsequent fragmented message. The inspected harness uses a real accepted WebSocket and the production base-class receive loop; only the downstream message observer is substituted. Full build, Shared tests, and Tray tests are reported passing. A live Gateway session is explicitly unverified. (tests/OpenClaw.Shared.Tests/WebSocketClientBaseTests.cs:140, 18b0e53c51f1)
  • Proof remains applicable to the pinned head: The production and test files have no differences between the explicitly tested f43c4e2 revision and the pinned head. The earlier zero-character fragment finding is repaired by explicit fragment tracking and covered by the second regression. (src/OpenClaw.Shared/WebSocketClientBase.cs:481, 18b0e53c51f1)
  • Implementation boundary and safeguards: The architecture documentation identifies the shared library as the owner of both gateway clients and their WebSocket transport. The patch preserves connection-generation dispatch and the existing bounded message accumulation guard; it changes no credentials, permissions, persistent formats, or dependency execution. (docs/CONNECTION_ARCHITECTURE.md:331, 18b0e53c51f1)

Likely related people:

  • shanselman: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • christineyan4: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

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

History

Review history (5 earlier review cycles)
  • reviewed 2026-10-04T16:09:50.255Z sha 51051c3 :: blocked before merge. :: [P2] Track fragmented messages independently of decoded character count
  • reviewed 2026-10-04T16:56:27.227Z sha f43c4e2 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-04T17:14:24.104Z sha e4abbb5 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-04T17:49:40.508Z sha fc3042f :: needs maintainer review before merge. :: none
  • reviewed 2026-10-04T18:04:42.872Z sha 18b0e53 :: needs maintainer review before merge. :: none

The fast path treated a final frame as a new message whenever no
characters had been appended yet. A leading fragment of an emoji
holds bytes in the decoder and appends nothing, so the last frame
was decoded alone and the leftover bytes corrupted the next message.
A message now stays fragmented until its last frame, independent of
how many characters that prefix produced.

Signed-off-by: Sebastien Tardif <[email protected]>
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed merge-risk: 🚨 message-delivery 🚨 Merging this PR could drop, duplicate, misroute, suppress, or wrongly target messages. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 4, 2026
The revocation job failed in wsl-create before any test body.
Fresh WSL install did not register expected distro OpenClawE2E-698efb65.
The decoder change does not touch setup.

Signed-off-by: Sebastien Tardif <[email protected]>
Core failed two Connection migration tests that do not read WebSocket text.
DeletedReceipt expected 11 preserved items and saw 2.
CleanupScript clock rollback expected exit 10 and got exit 2.
The sibling removeDirectory case passed.

Signed-off-by: Sebastien Tardif <[email protected]>
The UI job aborted after five minutes of inactivity.
The tests named at the crash were markdown list rows and theme color fallback.
Those do not read WebSocket frames.
Core, Tray, Setup, Network, and Revocation passed on this head.

Signed-off-by: Sebastien Tardif <[email protected]>
@shanselman shanselman added the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Oct 6, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Oct 6, 2026
@shanselman
shanselman merged commit d53b5ab into openclaw:main Oct 6, 2026
27 checks passed
@shanselman shanselman removed the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Oct 6, 2026
@SebTardif
SebTardif deleted the fix/f028-websocket-split-char branch October 7, 2026 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. 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.

2 participants