Skip to content

fix(agents): keep exec auto-reviewer rationale truncation UTF-16 safe#101513

Merged
steipete merged 3 commits into
openclaw:mainfrom
wm0018:fix/auto-reviewer-utf16-safe-truncation
Jul 7, 2026
Merged

fix(agents): keep exec auto-reviewer rationale truncation UTF-16 safe#101513
steipete merged 3 commits into
openclaw:mainfrom
wm0018:fix/auto-reviewer-utf16-safe-truncation

Conversation

@wm0018

@wm0018 wm0018 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where exec auto-reviewer rationale and session prompt-template descriptions could render broken U+FFFD replacement characters () when the text contained an emoji or CJK supplementary character at the truncation boundaries (500 characters for rationale, 60 for descriptions).

String.prototype.slice cuts at UTF-16 code unit boundaries. Emoji like 🚀 are surrogate pairs (2 code units). When a pair straddles the cut position, the lone high surrogate renders as .

Why This Change Was Made

Replace (text ?? fallback).slice(0, 500) in exec-auto-reviewer.ts and firstLine.slice(0, 60) in prompt-templates.ts with truncateUtf16Safe — the standard UTF-16-safe truncation helper already used across the codebase.

User Impact

Exec auto-reviewer rationale and session prompt-template descriptions containing emoji or CJK supplementary characters near the truncation limits now display cleanly truncated text, without broken replacement characters.

Evidence

Standalone proof (production helper, same head)

$ node --import tsx --input-type=module
node=v22.22.0
head=3ed27b43f9

// exec reviewer rationale (500 chars)
text.length=501
slice(0,500).lastCodeUnit=0xd83d
slice(0,500).hasLoneSurrogate=true
truncateUtf16Safe(text,500).matches-x499=true

// prompt template description (60 chars)
text.length=61
slice(0,60).lastCodeUnit=0xd83d
slice(0,60).hasLoneSurrogate=true
truncateUtf16Safe(text,60).matches-y59=true

Tests

$ node scripts/run-vitest.mjs src/agents/exec-auto-reviewer.test.ts

 Test Files  1 passed (1)
      Tests  15 passed (15)

Files Changed (3 files, +38/-3)

 src/agents/exec-auto-reviewer.test.ts       | 35 +++++++++
 src/agents/exec-auto-reviewer.ts            |  3 +-
 src/agents/sessions/prompt-templates.ts     |  4 +-

String.prototype.slice at offset 500 can split surrogate pairs in
LLM-generated review rationale text, rendering broken U+FFFD in
exec approval UI payloads.

Replace raw slice(0, 500) with truncateUtf16Safe.
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Jul 7, 2026
…tion truncation UTF-16 safe

String.prototype.slice can split surrogate pairs at truncation boundaries,
producing broken U+FFFD in both exec approval rationale (500 chars) and
session prompt-template descriptions (60 chars).

Replace raw slice with truncateUtf16Safe in both locations.
@clawsweeper

clawsweeper Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 7, 2026, 6:40 AM ET / 10:40 UTC.

Summary
The PR changes exec auto-reviewer rationale normalization from .slice(0, 500) to truncateUtf16Safe(..., 500) and adds a regression test for a surrogate-pair boundary.

PR surface: Source +1, Tests +18. Total +19 across 2 files.

Reproducibility: yes. by source inspection: current main still truncates exec reviewer rationale with raw .slice(0, 500), which can split a surrogate pair at the boundary. I did not run tests in this read-only review.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: serialized state: src/agents/exec-auto-reviewer.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

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

Rank-up moves:

  • [P2] Clear or rerun the failing checks-node-compact-small-whole-2 CI shard before merge.

Risk before merge

  • [P1] The live PR is behind the base branch and one broad CI shard is failing; I did not find evidence that the diff causes that failure, so this is merge handling rather than a code-review finding.

Maintainer options:

  1. Decide the mitigation before merge
    Land the focused helper-based exec reviewer fix after ordinary maintainer review and exact-head checks; handle other raw truncation sites as separate follow-up work if needed.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • No repair lane is needed because there are no blocking review findings; remaining action is normal maintainer review plus CI/rebase handling.

Security
Cleared: The diff only changes TypeScript source and a focused test to use an existing internal helper; it does not touch dependencies, workflows, secrets, package metadata, generated assets, or code-execution setup.

Review details

Best possible solution:

Land the focused helper-based exec reviewer fix after ordinary maintainer review and exact-head checks; handle other raw truncation sites as separate follow-up work if needed.

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

Yes by source inspection: current main still truncates exec reviewer rationale with raw .slice(0, 500), which can split a surrogate pair at the boundary. I did not run tests in this read-only review.

Is this the best way to solve the issue?

Yes. Reusing the existing truncateUtf16Safe helper at normalizeRationale is the narrow owner-boundary fix; display-side cleanup or a broad raw-slice audit would be larger than this PR’s exec reviewer bug.

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P3: The PR fixes rare text display corruption at one internal agent-review truncation boundary with limited blast radius.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes copied Node live output showing raw slice creates a lone surrogate and the existing helper returns clean truncated text; the current head keeps the same exec reviewer runtime change.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes copied Node live output showing raw slice creates a lone surrogate and the existing helper returns clean truncated text; the current head keeps the same exec reviewer runtime change.
Evidence reviewed

PR surface:

Source +1, Tests +18. Total +19 across 2 files.

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

What I checked:

Likely related people:

  • LZY3538: Current-main blame in the available shallow history attributes both the affected normalizeRationale raw slice and the shared UTF-16 helper to a6352f9356cc2ddf782059b66d042e2157e6d309. (role: introduced behavior; confidence: medium; commits: a6352f9356cc; files: src/agents/exec-auto-reviewer.ts, packages/normalization-core/src/utf16-slice.ts)
  • steipete: Live GitHub metadata shows the introducing commit came through merged pull request fix(status): surface auto-fallback model in status and session_status (#96126) #101337, merged by steipete, and the current PR also has a maintainer follow-up test commit from steipete. (role: merger and recent follow-up owner; confidence: medium; commits: a6352f9356cc, e97afe94d43f; files: src/agents/exec-auto-reviewer.ts, src/agents/exec-auto-reviewer.test.ts, packages/normalization-core/src/utf16-slice.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-07T09:21:11.250Z sha 3ed27b4 :: needs maintainer review before merge. :: none

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

steipete commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Land-ready at exact reviewed head e97afe94d43f92c0413d0c0d9cd15d1ddf150bef.

  • Replaced raw rationale slicing in the exec auto-review response parser with the canonical normalization-core UTF-16 helper at the existing 500-code-unit cap.
  • Removed unrelated prompt-template churn and helper-only tests; the final regression asserts the actual parsed conservative decision shape.
  • Fresh Codex autoreview: clean, no accepted/actionable findings (correctness 0.93).
  • oxfmt on both touched files and git diff --check: passed.
  • Exact-head hosted CI: 71 checks passed. The only first-attempt failure was an unrelated TUI PTY timeout; workflow 28859095473 attempt 2 passed completely.
  • Native OPENCLAW_TESTBOX=1 scripts/pr prepare-run 101513: passed exact-head hosted gates.

No docs or changelog change is required for this internal parser-boundary correction.

@steipete
steipete merged commit e7d617d into openclaw:main Jul 7, 2026
157 of 158 checks passed
@steipete

steipete commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

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

* fix(agents): keep exec auto-reviewer rationale truncation UTF-16 safe

String.prototype.slice at offset 500 can split surrogate pairs in
LLM-generated review rationale text, rendering broken U+FFFD in
exec approval UI payloads.

Replace raw slice(0, 500) with truncateUtf16Safe.

* fix(agents): keep exec reviewer rationale and prompt template description truncation UTF-16 safe

String.prototype.slice can split surrogate pairs at truncation boundaries,
producing broken U+FFFD in both exec approval rationale (500 chars) and
session prompt-template descriptions (60 chars).

Replace raw slice with truncateUtf16Safe in both locations.

* test(exec): cover UTF-16-safe reviewer rationale

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>
giodl73-repo pushed a commit to giodl73-repo/openclaw that referenced this pull request Jul 8, 2026
…openclaw#101513)

* fix(agents): keep exec auto-reviewer rationale truncation UTF-16 safe

String.prototype.slice at offset 500 can split surrogate pairs in
LLM-generated review rationale text, rendering broken U+FFFD in
exec approval UI payloads.

Replace raw slice(0, 500) with truncateUtf16Safe.

* fix(agents): keep exec reviewer rationale and prompt template description truncation UTF-16 safe

String.prototype.slice can split surrogate pairs at truncation boundaries,
producing broken U+FFFD in both exec approval rationale (500 chars) and
session prompt-template descriptions (60 chars).

Replace raw slice with truncateUtf16Safe in both locations.

* test(exec): cover UTF-16-safe reviewer rationale

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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