Skip to content

fix(whatsapp): use truncateUtf16Safe for session error stringify truncation#102722

Closed
lzyyzznl wants to merge 1 commit into
openclaw:mainfrom
lzyyzznl:fix/truncateUtf16Safe-whatsapp-errors
Closed

fix(whatsapp): use truncateUtf16Safe for session error stringify truncation#102722
lzyyzznl wants to merge 1 commit into
openclaw:mainfrom
lzyyzznl:fix/truncateUtf16Safe-whatsapp-errors

Conversation

@lzyyzznl

@lzyyzznl lzyyzznl commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

One .slice(0, limit) truncation site in the WhatsApp session errors module may cut UTF-16 surrogate pairs in half when the serialized error value contains multi-byte characters such as emoji.

Why This Change Was Made

extensions/whatsapp/src/session-errors.ts uses raw .slice(0, limit) for error string truncation. Replacing with truncateUtf16Safe ensures truncated output is always valid Unicode.

User Impact

Truncated error strings in WhatsApp session errors remain valid Unicode at existing size limits. No behavioral changes for ASCII-only content.

Evidence

  • Mechanical replacement: .slice(0, limit) to truncateUtf16Safe(raw, limit)
  • No runtime behavior change for ASCII or valid Unicode input

Generated with Claude Code

@openclaw-barnacle openclaw-barnacle Bot added channel: whatsapp-web Channel integration: whatsapp-web size: XS labels Jul 9, 2026
@clawsweeper

clawsweeper Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 9, 2026, 7:33 AM ET / 11:33 UTC.

Summary
The PR imports truncateUtf16Safe into the WhatsApp session error formatter and uses it instead of raw slice when truncating JSON-stringified fallback error text.

PR surface: Source +2. Total +2 across 1 file.

Reproducibility: yes. at source level. Current main uses raw UTF-16 code-unit slicing in safeStringify, so a JSON-stringified fallback error whose high surrogate lands at the 800-code-unit boundary can return a dangling surrogate before the ellipsis; I did not run a live WhatsApp session.

Review metrics: none identified.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🐚 platinum hermit
Result: blocked until real behavior proof is added.

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

Rank-up moves:

  • [P1] Add redacted real behavior proof such as terminal output, runtime logs, copied live output, or a validation transcript showing the after-fix WhatsApp/session error formatting path.
  • [P2] Add a focused regression for formatError's JSON fallback with an emoji at the truncation boundary to cover this call site directly.

Proof guidance:

  • [P1] Needs real behavior proof before merge: Missing: the PR body gives only mechanical evidence; the contributor should add redacted terminal output, copied live output, runtime logs, or a validation transcript showing after-fix WhatsApp/session error formatting, then update the PR body to trigger re-review.

Risk before merge

  • [P1] Contributor real-behavior proof is still missing; the PR body only describes the mechanical replacement and does not show a redacted live run, runtime log, terminal output, or validation transcript for the after-fix WhatsApp error formatting path.
  • [P2] The diff does not add a focused WhatsApp formatError regression for an emoji split at the JSON fallback truncation boundary, so call-site coverage remains weaker than the shared helper coverage.

Maintainer options:

  1. Decide the mitigation before merge
    Land the local helper substitution after contributor-supplied real-behavior proof is added, ideally with a focused formatError JSON-fallback regression; no core or plugin API change is needed.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P1] The remaining blocker is contributor-supplied real behavior proof and ordinary maintainer review; ClawSweeper should not open a repair PR for evidence that must come from a real run.

Security
Cleared: Cleared: the diff only imports an existing SDK helper and changes local string truncation, with no dependency, workflow, secret, package, or code-execution surface change.

Review details

Best possible solution:

Land the local helper substitution after contributor-supplied real-behavior proof is added, ideally with a focused formatError JSON-fallback regression; no core or plugin API change is needed.

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

Yes at source level. Current main uses raw UTF-16 code-unit slicing in safeStringify, so a JSON-stringified fallback error whose high surrogate lands at the 800-code-unit boundary can return a dangling surrogate before the ellipsis; I did not run a live WhatsApp session.

Is this the best way to solve the issue?

Yes. Reusing the existing truncateUtf16Safe SDK helper at the local truncation point is the narrow maintainable fix, with the remaining gap being proof and preferably a focused call-site regression.

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add P3: This is a very small WhatsApp diagnostic/error-string correctness fix with limited blast radius and no evidence of a broken core workflow.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Missing: the PR body gives only mechanical evidence; the contributor should add redacted terminal output, copied live output, runtime logs, or a validation transcript showing after-fix WhatsApp/session error formatting, then update the PR body to trigger re-review.

Label justifications:

  • P3: This is a very small WhatsApp diagnostic/error-string correctness fix with limited blast radius and no evidence of a broken core workflow.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Missing: the PR body gives only mechanical evidence; the contributor should add redacted terminal output, copied live output, runtime logs, or a validation transcript showing after-fix WhatsApp/session error formatting, then update the PR body to trigger re-review.
Evidence reviewed

PR surface:

Source +2. Total +2 across 1 file.

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

What I checked:

  • Repository policy read and applied: The full root policy and scoped extensions policy were read; the review applied the plugin-boundary rule that extension production code should use openclaw/plugin-sdk/* surfaces and the deep-review requirement for PR verdicts. (AGENTS.md:1, 34d257713ea3)
  • PR diff is focused on the WhatsApp formatter: The proposed head adds the SDK helper import and replaces raw.slice(0, limit) with truncateUtf16Safe(raw, limit) in the safeStringify truncation branch. (extensions/whatsapp/src/session-errors.ts:29, 240a8b74dba7)
  • Current main still has the unsafe truncation site: On current main, safeStringify still truncates the JSON string with raw slice(0, limit) before appending the ellipsis. (extensions/whatsapp/src/session-errors.ts:30, 34d257713ea3)
  • Helper contract matches the intended fix: truncateUtf16Safe clamps/floors the limit and delegates to sliceUtf16Safe, which avoids returning dangling surrogate halves at slice edges. (packages/normalization-core/src/utf16-slice.ts:44, 34d257713ea3)
  • SDK subpath is an existing extension-safe import: text-utility-runtime already exports sliceUtf16Safe and truncateUtf16Safe, and the root package exports the openclaw/plugin-sdk/text-utility-runtime subpath. (src/plugin-sdk/text-utility-runtime.ts:21, 34d257713ea3)
  • Sibling WhatsApp code already uses the helper: WhatsApp auto-reply utilities and echo logging already import and use truncateUtf16Safe, so the PR follows an established local pattern rather than adding a new abstraction. (extensions/whatsapp/src/auto-reply/util.ts:3, 34d257713ea3)

Likely related people:

  • steipete: GitHub path history shows steipete on the WhatsApp session-errors history and normalization-core extraction work, and PR discussion for related UTF-16 truncation work shows steipete handled land-ready validation and merge evidence. (role: recent area contributor and reviewer; confidence: high; commits: 30a94dfd3b7c, 58912f8fd842, 062f88e3e3af; files: extensions/whatsapp/src/session-errors.ts, extensions/whatsapp/src/session.test.ts, packages/normalization-core/src/utf16-slice.ts)
  • obviyus: Recent GitHub path history for src/plugin-sdk/text-utility-runtime.ts shows obviyus working on the plugin SDK utility export surface that this PR imports from. (role: recent plugin SDK surface contributor; confidence: medium; commits: d498b1cce49c, 210877a73e25; files: src/plugin-sdk/text-utility-runtime.ts)
  • RomneyDa: Recent WhatsApp session test history includes RomneyDa's WebSocket URL and session-surface work, making them a plausible adjacent routing candidate for WhatsApp runtime validation. (role: recent adjacent WhatsApp contributor; confidence: medium; commits: 2ec670898018, 0deddfa20428; files: extensions/whatsapp/src/session.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.

@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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Jul 9, 2026
@steipete

steipete commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Thanks @lzyyzznl. #102823 landed the same UTF-16-safe WhatsApp session-error detail cap in 5ef269c, including a formatError regression test. This branch is fully superseded, so I’m closing it.

@steipete steipete closed this Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: whatsapp-web Channel integration: whatsapp-web P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants