Skip to content

fix(board): prevent emoji corruption in event notices - #111702

Merged
steipete merged 3 commits into
openclaw:mainfrom
zhangguiping-xydt:fix/board-event-unicode-truncation
Aug 1, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
zhangguiping-xydt:fix/board-event-unicode-truncation

Conversation

@zhangguiping-xydt

@zhangguiping-xydt zhangguiping-xydt commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Long dashboard board.event payloads can split an emoji surrogate pair at the existing 500-character notice limit, publishing corrupted Unicode in the user-visible session event.

Outcome

What problem does this PR solve?

Dashboard widget events with long Unicode payloads could show a replacement character when the 500-character notice limit landed inside an emoji. The board.event Gateway path could emit a lone UTF-16 surrogate into the session system event instead of a well-formed notice.

What is the intended outcome?

Root-cause fix. Board notice formatting must preserve the existing 500 UTF-16-code-unit envelope and widget suffix without cutting a surrogate pair.

What is intentionally out of scope?

The public board.event request/response protocol, widget persistence, payload-size cap, deduplication window, notice limit, and configuration are not changed. The related open PR scan and current PR discussion did not identify a separate canonical contract change to adopt; this remains an internal board-notice normalization fix.

Why This Change Was Made

The canonical owner is src/boards/board-notices.ts, where the serialized payload becomes the queued human-readable notice. The old raw string slice could stop after an emoji's high surrogate. The fix uses the repository's shared surrogate-safe UTF-16 truncation capability at that owner boundary, before enqueueSystemEvent stores text for the session consumer.

The numeric subtraction is not a new product threshold: one UTF-16 code unit is reserved for the literal ellipsis already required by the notice format, while the existing 500-unit limit and full widget suffix remain unchanged. This fixes the normalization invariant rather than adding a downstream replacement-character cleanup.

The branch also keeps the existing scripts/pr wrapper fixture independent of the host's optional rg, jq, and pnpm inventory. That test-only change does not alter product or wrapper behavior.

User Impact

Users can receive long dashboard widget event summaries without emoji or other supplementary Unicode characters being corrupted at the truncation boundary.

Risk

What is the highest-risk area?

The merge risk is availability and message integrity at the Gateway-to-session system-event boundary: an incorrect truncation budget could exceed the existing notice cap, remove the widget suffix, or change queue behavior.

How is that risk mitigated?

The change is confined to the canonical notice formatter, preserves every existing limit and queue contract, adds a focused boundary regression, and is backed by a live production-Gateway WebSocket run that observed the actual queued event. No public contract, persistence, or configuration surface changes.

Evidence

  • Fresh complete-branch xhigh autoreview passed with 0.99 confidence.

  • Verified current main publishes a 500-character notice containing a dangling high surrogate; repaired head publishes a valid 499-character notice with the same ellipsis and widget suffix.\n- Rebased-head Gateway board suite: 30/30 passed.\n- Rebased-head maintainer wrapper suite: 13/13 passed.

  • Exact current-main port head: 0ad37857e3de548855c778b50e57b7c2d716b84b.

  • src/gateway/server-methods/board.test.ts: 28 tests passed, including the surrogate-boundary regression.

  • test/scripts/pr-wrappers.test.ts: 12 tests passed. The local Git 2.27 runner used a bootstrap-only compatibility shim for newer git init -b and rev-parse --path-format=absolute syntax; all other Git commands passed through unchanged.

  • oxfmt --check passed for all three changed files.

  • pnpm check:max-lines-ratchet --base f466c3de326e34f02caac610f601fffb8f413768 passed on the exact synthetic merge preview (1136 grandfathered suppressions).

Real Behavior Proof

An isolated production Gateway was started from the exact current head with temporary state and a loopback token. A real GatewayClient WebSocket connection then:

  1. created and listed a live session,
  2. installed the counter widget through board.widget.put,
  3. confirmed it through board.get,
  4. sent a payload through board.event whose emoji high surrogate landed at the legacy truncation edge, and
  5. inspected the system event queued by the same Gateway process.
BOARD_EVENT_APPENDED=true
SYSTEM_EVENT_COUNT=1
NOTICE_UTF16_CODE_UNITS=499
NOTICE_MAX_UTF16_CODE_UNITS=500
NOTICE_HAS_ELLIPSIS=true
NOTICE_ENDS_WITH_EXPECTED_SUFFIX=true
NOTICE_LONE_SURROGATE_INDEXES=[]

This proof exercised production WebSocket authentication and routing, board handlers and store, JSON serialization, surrogate-safe truncation, and the real system-event queue. Only the loopback port, temporary configuration/state, authentication token, and final in-process queue observation were test-owned.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XS labels Jul 20, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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 Jul 20, 2026
@clawsweeper

clawsweeper Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 1, 2026, 1:47 AM ET / 05:47 UTC.

ClawSweeper review

What this changes

The branch makes long board.event notices surrogate-safe without changing the 500-code-unit notice limit, then adds Gateway regression coverage and makes the wrapper-test fixture provide its expected command stubs.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

This PR remains necessary because current main still uses a raw UTF-16 slice at the board-notice boundary, which can leave a dangling high surrogate. The reviewed head replaces that operation at the canonical formatter with the repository’s existing safe truncation helper, preserves the established notice envelope and suffix, and has no actionable patch finding; it should wait only for the exact-head required checks to finish.

Priority: P2
Reviewed head: 84ba5b92820a900e77794620bfd71b43c2b0de0f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused root-cause repair with direct Gateway proof and useful boundary coverage; normal exact-head CI completion remains the only merge gate visible in the supplied context.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body includes redacted after-fix live Gateway WebSocket output that directly exercises authentication, routing, board storage, notice creation, and the queued system-event result; no further contributor proof is needed.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body includes redacted after-fix live Gateway WebSocket output that directly exercises authentication, routing, board storage, notice creation, and the queued system-event result; no further contributor proof is needed.
Evidence reviewed 8 items Current-main defect location: Current main formats an overlong board-event summary with String.prototype.slice, so a UTF-16 boundary can end after a high surrogate before the literal ellipsis and widget suffix are added.
Canonical owner boundary: The Gateway handler validates the request and sends its payload directly to the injected board notice appender; formatting before enqueueSystemEvent is therefore the correct producer-side repair location.
Safe helper contract: truncateUtf16Safe floors the requested UTF-16 limit and delegates to a slice helper that moves a terminal boundary before a split surrogate pair, retaining the existing maximum-length contract while preventing malformed output.
Findings None None.
Security None None.

How this fits together

A dashboard widget submits board.event through the Gateway, which validates the widget and passes its JSON-serialized payload to the board notice formatter. That formatter creates a session-scoped system event that is queued for the next agent prompt.

flowchart LR
  A[Dashboard widget event] --> B[Gateway board-event handler]
  B --> C[Widget validation]
  C --> D[Board notice formatter]
  D --> E[Surrogate-safe truncation]
  E --> F[Session system-event queue]
  F --> G[Next agent prompt]
Loading

Before merge

  • Resolve merge risk (P1) - The provided exact-head status snapshot still has required CI jobs in progress, so merging should wait for those checks to conclude successfully on 84ba5b92820a900e77794620bfd71b43c2b0de0f.
  • Complete next step (P2) - No repair lane is needed: the reviewed branch already contains the focused source and test repair, while the remaining action is normal exact-head check completion and maintainer merge review.
Agent review details

Security

None.

PR surface

Source +3, Tests +13. Total +16 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 4 1 +3
Tests 2 17 4 +13
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 21 5 +16

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Merge this focused owner-boundary repair once the exact-head checks pass, retaining the shared truncation helper and the Gateway-level boundary regression as the canonical protection against malformed board notices.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Merge this focused owner-boundary repair once the exact-head checks pass, retaining the shared truncation helper and the Gateway-level boundary regression as the canonical protection against malformed board notices.

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

Yes—current main serializes the payload and truncates it with raw UTF-16 slice, so a supplementary character whose high surrogate occupies the final retained code unit produces the reported malformed notice. The PR also supplies a concrete Gateway-level boundary scenario and exact-head live output.

Is this the best way to solve the issue?

Yes—the patch repairs the producer that creates the queued system-event text, using the existing supported surrogate-safe helper rather than adding a consumer-side cleanup or changing the public Gateway contract.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 6922ddd93610.

Labels

Label justifications:

  • P2: The patch fixes corrupted user-visible board notice text at a bounded Gateway-to-session event boundary without evidence of broader availability, security, or state loss.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes redacted after-fix live Gateway WebSocket output that directly exercises authentication, routing, board storage, notice creation, and the queued system-event result; no further contributor proof is needed.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes redacted after-fix live Gateway WebSocket output that directly exercises authentication, routing, board storage, notice creation, and the queued system-event result; no further contributor proof is needed.

Evidence

What I checked:

  • Current-main defect location: Current main formats an overlong board-event summary with String.prototype.slice, so a UTF-16 boundary can end after a high surrogate before the literal ellipsis and widget suffix are added. (src/boards/board-notices.ts:30, 6922ddd93610)
  • Canonical owner boundary: The Gateway handler validates the request and sends its payload directly to the injected board notice appender; formatting before enqueueSystemEvent is therefore the correct producer-side repair location. (src/gateway/server-methods/board.ts:403, 6922ddd93610)
  • Safe helper contract: truncateUtf16Safe floors the requested UTF-16 limit and delegates to a slice helper that moves a terminal boundary before a split surrogate pair, retaining the existing maximum-length contract while preventing malformed output. (packages/normalization-core/src/utf16-slice.ts:58, 6922ddd93610)
  • Patch preserves the notice contract: The branch replaces only the unsafe truncation expression with the exported normalization-core helper; prefix, suffix, payload cap, deduplication, queue call, and 500-code-unit budget remain intact. (src/boards/board-notices.ts:30, 84ba5b92820a)
  • Boundary regression coverage: The added Gateway test places an emoji across the former slice boundary, asserts the notice stays within 500 UTF-16 code units, contains no dangling tested high surrogate, and retains the ellipsis plus widget suffix. (src/gateway/server-methods/board.test.ts:1011, 84ba5b92820a)
  • Existing helper is a supported local dependency surface: The normalization-core package explicitly exports the ./utf16-slice subpath, and multiple current production modules already import truncateUtf16Safe through that same public subpath. (packages/normalization-core/package.json:73, 6922ddd93610)

Likely related people:

  • steipete: Current-main blame and available path history attribute the board notice formatter and original truncation behavior to this merged commit. (role: feature introducer and recent area contributor; confidence: high; commits: 90ae3c253f59; files: src/boards/board-notices.ts, src/gateway/server-methods/board.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Allow the in-progress required checks on the exact reviewed head to finish successfully before merge.

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 (8 earlier review cycles)
  • reviewed 2026-07-20T06:52:41.817Z sha 5789351ee3c5365f0d3a9f543908b0d1ecebf707 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-20T09:24:26.911Z sha ad93d79abbe39dcb97de875691622e5ae6cabc30 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-20T10:07:56.275Z sha ad93d79abbe39dcb97de875691622e5ae6cabc30 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-20T10:50:09.583Z sha ad93d79abbe39dcb97de875691622e5ae6cabc30 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-31T09:44:32.392Z sha 0ad37857e3de548855c778b50e57b7c2d716b84b :: needs maintainer review before merge. :: none
  • reviewed 2026-08-01T04:43:00.331Z sha 0dc6b85ba116f472e8e59706adeb0ff4e5817684 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-01T04:49:08.771Z sha 0dc6b85ba116f472e8e59706adeb0ff4e5817684 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-01T05:02:33.296Z sha ae0bb865725219d1312fae6955006c4b5b376c08 :: needs maintainer review before merge. :: none

@zhangguiping-xydt

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@zhangguiping-xydt
zhangguiping-xydt force-pushed the fix/board-event-unicode-truncation branch from 3acc550 to ad93d79 Compare July 20, 2026 09:23
@zhangguiping-xydt

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 20, 2026
@zhangguiping-xydt
zhangguiping-xydt force-pushed the fix/board-event-unicode-truncation branch from ad93d79 to 0ad3785 Compare July 23, 2026 10:41
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jul 23, 2026
@steipete
steipete force-pushed the fix/board-event-unicode-truncation branch from 0ad3785 to 0dc6b85 Compare August 1, 2026 04:36
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Aug 1, 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 Aug 1, 2026
@steipete
steipete force-pushed the fix/board-event-unicode-truncation branch from 0dc6b85 to ae0bb86 Compare August 1, 2026 04:57
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Aug 1, 2026
@steipete
steipete force-pushed the fix/board-event-unicode-truncation branch from ae0bb86 to 84ba5b9 Compare August 1, 2026 05:42
@steipete

steipete commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Land-ready verification for original contributor head 84ba5b9: actual production board event notice on current main ends with a dangling UTF-16 high surrogate when an emoji crosses the 500-character boundary; the identical contributor-head invocation produces valid Unicode, preserves the existing ellipsis/widget suffix, and remains within the cap (length 500 -> 499). The existing canonical truncateUtf16Safe helper repairs the authoritative event producer without config/protocol/fallback changes. I folded the Gateway regression into the existing payload-cap boundary test, preserving real widget/event dispatch while satisfying the real max-lines rule without any suppression. Original three contributor-authored commits, exact three-file scope, and production fix are retained. Focused proof: OPENCLAW_VITEST_MAX_WORKERS=1 node /Users/steipete/Projects/openclaw/scripts/run-vitest.mjs src/gateway/server-methods/board.test.ts test/scripts/pr-wrappers.test.ts src/plugin-sdk/qa-runner-runtime.integration.test.ts (29 Gateway + 13 wrapper + 3 private-QA integration tests passed). Actual oxlint/oxfmt/diff checks passed; fresh full-branch Codex xhigh autoreview passed (0.99). The original branch was rebased only after canonical #117203 repaired the independently proven unrelated QA runner eager-load timeout; the formerly timing-out integration now completes in 14.8 seconds. Exact-head full hosted CI 30686337904 and real-behavior proof 30686336786 are GREEN, including lint, all Gateway/plugin suites, private-QA shard, security, QA Smoke profiles, and openclaw/ci-gate.

@steipete
steipete merged commit 1f40646 into openclaw:main Aug 1, 2026
120 checks passed
@steipete

steipete commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 1, 2026
* fix(board): preserve Unicode notice boundaries

* test(board): document surrogate boundary

* test(pr): isolate wrapper command inventory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime 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.

2 participants