Skip to content

fix(gateway): use truncateUtf16Safe for voice-wake trigger truncation#103210

Merged
steipete merged 4 commits into
openclaw:mainfrom
lsr911:fix/server-utils-utf16-truncation
Jul 10, 2026
Merged

fix(gateway): use truncateUtf16Safe for voice-wake trigger truncation#103210
steipete merged 4 commits into
openclaw:mainfrom
lsr911:fix/server-utils-utf16-truncation

Conversation

@lsr911

@lsr911 lsr911 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

normalizeVoiceWakeTriggers() in src/gateway/server-utils.ts truncates user-configured voice wake trigger phrases to 64 characters with naive .slice(0, 64). Voice wake triggers are user-configurable text strings that may contain emoji or non-BMP characters. A .slice(0, 64) at a surrogate pair boundary produces a lone high surrogate (0xD83D), which corrupts the trigger text sent to the speech recognition service.

Why This Change Was Made

Replace .slice(0, 64) with truncateUtf16Safe(value, 64) — the standard UTF-16-safe truncation helper already used across the gateway module (same pattern as assistant-identity.ts, chat-display-projection.ts, ws-log.ts).

User Impact

Voice wake trigger phrases containing emoji or CJK supplementary characters near the 64-char limit now remain valid UTF-16, without lone surrogates that could break downstream speech recognition or display.

Evidence

Standalone proof (production helper, same head)

$ node --import tsx test/_proof_voice_wake_utf16.mjs
node=24.12.0
head=local

trigger.length=65
naive.slice(0,64).hasLoneSurrogate=true

normalizeVoiceWakeTriggers[0].length=63
normalizeVoiceWakeTriggers[0].hasLoneSurrogate=false
normalizeVoiceWakeTriggers[0]===base=true

PASS: voice wake trigger preserves surrogate pairs

Negative control (revert and verify test catches the bug)

$ git stash && npx vitest run src/gateway/gateway-misc.test.ts -t "surrogate"
# Test fails: normalizeVoiceWakeTriggers returns lone surrogate characters

Files Changed (2 files, +20/-1)

 src/gateway/gateway-misc.test.ts | 18 ++++++++++++++++++
 src/gateway/server-utils.ts      |  3 ++-

🤖 Generated with Claude Code

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. size: S and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. size: XS labels Jul 10, 2026
@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: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal backlog priority with limited blast radius. labels Jul 10, 2026
@clawsweeper

clawsweeper Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed July 10, 2026, 8:06 AM ET / 12:06 UTC.

Summary
The PR replaces naive voice-wake trigger truncation with the shared UTF-16-safe helper, adds a focused regression test, and adds a standalone voice-wake proof script.

PR surface: Source +1, Tests +46. Total +47 across 3 files.

Reproducibility: yes. Current main’s 64-unit slice can split a surrogate pair, and the existing helper implementation plus the focused regression case establish the exact failing boundary with high confidence.

Review metrics: none identified.

Merge readiness
Overall: 🦐 gold shrimp
Proof: 🦞 diamond lobster
Patch quality: 🦐 gold shrimp
Result: needs maintainer review before merge.

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

Rank-up moves:

  • Remove test/_proof_voice_wake_utf16.mjs while retaining the production change, focused Vitest regression, and PR-body terminal transcript.

Next step before merge

  • The only remaining blocker is a single mechanical file deletion that requires no product, security, compatibility, or ownership decision.

Security
Cleared: The diff does not change dependencies, permissions, secrets, workflows, package resolution, publishing metadata, or another security-sensitive execution boundary.

Review findings

  • [P2] Remove the remaining PR-only proof script — test/_proof_voice_wake_utf16.mjs:1-2
Review details

Best possible solution:

Retain the canonical UTF-16-safe substitution and focused Vitest regression, delete the duplicate standalone proof script, and preserve its useful terminal evidence in the PR body.

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

Yes. Current main’s 64-unit slice can split a surrogate pair, and the existing helper implementation plus the focused regression case establish the exact failing boundary with high confidence.

Is this the best way to solve the issue?

Yes for the runtime behavior: using the existing UTF-16-safe helper is the narrowest maintainable fix. The standalone proof script is not part of that best solution because the maintained regression and PR-body terminal transcript already cover it.

Full review comments:

  • [P2] Remove the remaining PR-only proof script — test/_proof_voice_wake_utf16.mjs:1-2
    Delete this standalone executable proof file. The focused Vitest regression already preserves the behavior and the PR body already contains the terminal transcript, so keeping a second one-off execution path adds unmaintained repository surface. This is the still-unresolved portion of the prior review finding.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P2: The PR addresses a bounded gateway text-corruption bug, and the remaining merge blocker is a narrow branch-cleanup defect.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): The PR body includes after-fix terminal output from the production helper and describes a negative-control regression failure, providing sufficient real behavior proof for this non-visual change.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix terminal output from the production helper and describes a negative-control regression failure, providing sufficient real behavior proof for this non-visual change.
Evidence reviewed

PR surface:

Source +1, Tests +46. Total +47 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 2 1 +1
Tests 2 46 0 +46
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 48 1 +47

Acceptance criteria:

  • [P1] pnpm test src/gateway/gateway-misc.test.ts -t "preserves surrogate pairs at truncation boundary".
  • [P1] git diff --check.

What I checked:

  • Current-main defect: Current main still truncates each normalized voice-wake trigger with value.slice(0, 64), which can leave a dangling high surrogate when the boundary falls inside a non-BMP character. (src/gateway/server-utils.ts:10, a238dead67bd)
  • Shipped behavior: The latest release v2026.6.11 contains the same unsafe value.slice(0, 64) implementation, so the bug is not already fixed in the shipped release. (src/gateway/server-utils.ts:10, e085fa1a3ffd)
  • Canonical helper contract: truncateUtf16Safe delegates to sliceUtf16Safe, which backs the end boundary up when it would separate a high surrogate from its following low surrogate. (packages/normalization-core/src/utf16-slice.ts:43, a238dead67bd)
  • Runtime propagation: The voice-wake RPC handler persists the normalized triggers and broadcasts them to connected clients, so malformed truncation is not confined to a temporary local value. (src/gateway/server-methods/voicewake.ts:28, a238dead67bd)
  • Unresolved prior finding: Comparison with the previously reviewed SHA shows that the latest commit deleted only test/_proof_console_sanitize_c1.mjs; test/_proof_voice_wake_utf16.mjs remains unchanged on the branch. (test/_proof_voice_wake_utf16.mjs:1, 2c38b021508c)
  • Repository test pattern: Tracked root test scripts are maintained harness or Vitest routing files; no comparable one-off _proof executable is kept alongside an equivalent focused regression test. (test/_proof_voice_wake_utf16.mjs:1, 2c38b021508c)

Likely related people:

  • gorkem2020: Commit a6b9078 introduced the current gateway utility, voice-wake caller, UTF-16 helper, and adjacent gateway test surface. (role: introduced current area surface; confidence: high; commits: a6b907825a85; files: src/gateway/server-utils.ts, src/gateway/server-methods/voicewake.ts, packages/normalization-core/src/utf16-slice.ts)
  • steipete: Merged the PR that introduced these current surfaces and authored several commits in its merged series, providing a second routing signal for the gateway test organization. (role: merger and adjacent contributor; confidence: medium; commits: a6b907825a85, ea71cab8c6ca, f0698c06489c; files: src/gateway/server-utils.ts, src/gateway/gateway-misc.test.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.
Review history (1 earlier review cycle)
  • reviewed 2026-07-10T09:18:59.323Z sha 4273a95 :: needs changes before merge. :: [P2] Remove the unrelated proof artifacts

lsr911 added a commit to lsr911/openclaw that referenced this pull request Jul 10, 2026
ClawSweeper review: the console-sanitization proof script belongs
to openclaw#103226, not this gateway voice-wake fix. Remove it to keep the
branch clean.

Ref: openclaw#103210 review
@lsr911

lsr911 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 10, 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:

lsr911 and others added 4 commits July 10, 2026 14:25
Replace naive .slice(0, 64) with truncateUtf16Safe() in
normalizeVoiceWakeTriggers to prevent surrogate pair splitting
in user-configured voice wake trigger phrases.

Voice wake triggers are user-configurable text strings that may
contain emoji or non-BMP characters. A naive .slice(0, 64) at
a surrogate pair boundary produces a lone surrogate, which
corrupts the trigger text.

Co-Authored-By: Claude <[email protected]>
ClawSweeper review: the console-sanitization proof script belongs
to openclaw#103226, not this gateway voice-wake fix. Remove it to keep the
branch clean.

Ref: openclaw#103210 review
@steipete
steipete force-pushed the fix/server-utils-utf16-truncation branch from 2c38b02 to 52dcaa5 Compare July 10, 2026 13:30
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Jul 10, 2026
@steipete

Copy link
Copy Markdown
Contributor

Land-ready at exact head 52dcaa53cb57b6c488aad91398e851076f2a0eb3.

Maintainer cleanup:

  • removed the non-CI proof script;
  • reduced the maintained regression to the exact 64-unit boundary contract;
  • documented the 64 UTF-16 code-unit limit without split surrogate pairs;
  • updated the existing Unreleased Unicode-safe bounded-text entry and contributor credit.

Proof:

  • sanitized direct AWS Crabbox cbx_59e3ead61bf0 (silver-krill), run run_597550aa044a: trusted bootstrap fetched the exact PR head with no IAM role, no hydration, and isolated HOME; pnpm test src/gateway/gateway-misc.test.ts passed 160/160 tests across four projects;
  • targeted oxfmt and git diff --check passed;
  • fresh structured autoreview reported no findings (0.99 confidence);
  • native OPENCLAW_TESTBOX=1 scripts/pr prepare-run 103210 certified the exact-head hosted CI/Testbox rollup with no failed or pending required checks.

Known proof gaps: none for this bounded Gateway normalization change.

@steipete
steipete merged commit 0990bcc into openclaw:main Jul 10, 2026
105 of 106 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 11, 2026
…openclaw#103210)

* fix(gateway): use truncateUtf16Safe for voice-wake trigger truncation

Replace naive .slice(0, 64) with truncateUtf16Safe() in
normalizeVoiceWakeTriggers to prevent surrogate pair splitting
in user-configured voice wake trigger phrases.

Voice wake triggers are user-configurable text strings that may
contain emoji or non-BMP characters. A naive .slice(0, 64) at
a surrogate pair boundary produces a lone surrogate, which
corrupts the trigger text.

Co-Authored-By: Claude <[email protected]>

* test: add proof scripts for C1 sanitize and voice-wake UTF-16

* chore: remove unrelated proof script from voice-wake PR

ClawSweeper review: the console-sanitization proof script belongs
to openclaw#103226, not this gateway voice-wake fix. Remove it to keep the
branch clean.

Ref: openclaw#103210 review

* fix(gateway): harden voice wake unicode boundary

---------

Co-authored-by: Claude <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XS status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants