fix(native-hook-relay): use truncateUtf16Safe for hook display text truncation#102467
Conversation
Replace naive .slice(0, MAX) with truncateUtf16Safe() to prevent surrogate pair splitting in tool policy audit log output. Co-Authored-By: Claude <[email protected]>
…runcation Replace naive .slice(0, N) truncation with truncateUtf16Safe() in: - truncateText() helper (covers 4 call sites for tool display text) - Inline hook result truncation (...[truncated] suffix) Prevents surrogate pair splitting in native hook relay display output (tool names, commands, descriptions shown to users). Co-Authored-By: Claude <[email protected]>
|
Codex review: needs real behavior proof before merge. Reviewed July 9, 2026, 2:48 AM ET / 06:48 UTC. Summary PR surface: Source +1. Total +1 across 1 file. Reproducibility: yes. from source inspection: current main slices user-visible hook text by UTF-16 code units, and the shared helper tests show a one-code-unit cut through an emoji surrogate pair is unsafe without boundary adjustment. I did not run a live native-hook scenario in this read-only review. Review metrics: none identified. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Keep the narrow helper substitution, add real behavior proof, and preferably add focused coverage for surrogate-pair truncation in the native hook relay display paths before merge. Do we have a high-confidence way to reproduce the issue? Yes, from source inspection: current main slices user-visible hook text by UTF-16 code units, and the shared helper tests show a one-code-unit cut through an emoji surrogate pair is unsafe without boundary adjustment. I did not run a live native-hook scenario in this read-only review. Is this the best way to solve the issue? Yes for the code shape: reusing the existing shared UTF-16-safe helper at the two native-hook display truncation sites is the narrowest maintainable fix. Local surrogate logic or a Codex hook protocol change would be broader than needed for display-only truncation. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 5f91f6c95840. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +1. Total +1 across 1 file. View PR surface stats
Acceptance criteria:
What I checked:
Likely related people:
What the crustacean ranks mean
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
|
|
Land-ready maintainer pass complete at exact head I kept the useful two-boundary fix, switched it to the direct normalization-core import, corrected snapshot accounting to charge the actual retained prefix, and added exact production-path tests for retained hook payloads and permission approval previews. Proof:
The focused test ran locally because fork-contributor code is not eligible for credential-hydrated Testbox execution before landing review. Exact-head fork CI supplies the broad hosted proof. No remaining proof gap. |
|
Merged via squash.
|
…runcation (openclaw#102467) * fix(tool-policy-audit): use truncateUtf16Safe for audit field truncation Replace naive .slice(0, MAX) with truncateUtf16Safe() to prevent surrogate pair splitting in tool policy audit log output. Co-Authored-By: Claude <[email protected]> * fix(native-hook-relay): use truncateUtf16Safe for hook display text truncation Replace naive .slice(0, N) truncation with truncateUtf16Safe() in: - truncateText() helper (covers 4 call sites for tool display text) - Inline hook result truncation (...[truncated] suffix) Prevents surrogate pair splitting in native hook relay display output (tool names, commands, descriptions shown to users). Co-Authored-By: Claude <[email protected]> * test(agents): cover hook relay UTF-16 boundaries --------- Co-authored-by: Claude <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
What Problem This Solves
The native hook relay uses naive
.slice(0, N)truncation in two places:truncateText()helper (4 call sites: tool names, commands, descriptions)...[truncated]suffix)Both can split surrogate pairs mid-character in hook display output.
Why This Change Was Made
Replace
.slice(0, N)withtruncateUtf16Safe()which preserves surrogate pair boundaries.Evidence
Files Changed
src/agents/harness/native-hook-relay.ts.slice(0,N)→truncateUtf16Safe()intruncateText()+ inline truncation🤖 Generated with Claude Code
Co-Authored-By: Claude [email protected]