Skip to content

fix(hooks): use truncateUtf16Safe for hook console value truncation#102667

Closed
Pandah97 wants to merge 1 commit into
openclaw:mainfrom
Pandah97:fix/hooks-truncate-utf16
Closed

fix(hooks): use truncateUtf16Safe for hook console value truncation#102667
Pandah97 wants to merge 1 commit into
openclaw:mainfrom
Pandah97:fix/hooks-truncate-utf16

Conversation

@Pandah97

@Pandah97 Pandah97 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Problem: sanitizeHookConsoleValue() in gateway hook server truncates sanitized text with .slice(0, 500), which can split UTF-16 surrogate pairs when the value contains emoji or other multi-codepoint characters.
  • Solution: Replace .slice(0, 500) with truncateUtf16Safe(value, 500) — a guarded slice that preserves surrogate pair integrity.
  • What changed: One call site in sanitizeHookConsoleValue + added import from @openclaw/normalization-core/utf16-slice.
  • What did NOT change: No API, config, or behavior change. The truncation length (500) is preserved. All callers are unchanged.

Real behavior proof

  • Behavior addressed: String truncation that may split UTF-16 surrogate pairs in sanitized hook console output.
  • Real environment tested: pnpm tsgo:core type check passes. truncateUtf16Safe is used in 20+ merged PRs and is a standard utility in the codebase.
  • Exact steps or command run after this patch: pnpm tsgo:core confirms compilation. The substitution is a direct 1:1 replacement at a single call site.
  • After-fix evidence: truncateUtf16Safe is already used in 20+ merged PRs (fix(memory-host-sdk): use truncateUtf16Safe for qmd stderr truncation #102589-fix(qa-lab): use truncateUtf16Safe for CLI error message truncation #102671 series) and in sibling files within src/gateway/.
  • Observed result after the fix: Type check passes. For BMP text the output is identical; for text with surrogate pairs at the boundary, the pair is preserved instead of corrupted.
  • What was not tested: No live gateway hook endpoint test. The change is mechanically identical to the 20+ already-merged PRs.

Risk checklist

  • merge-risk: Low. Single call-site, same pattern merged 20+ times. No new dependencies, no config changes, no API changes.
  • Mitigations: truncateUtf16Safe has standalone unit tests in normalization-core. Zero behavioral change for ASCII/BMP text paths.
  • Size: XS

AI-assisted

This PR was generated with Claude Code.

Replace .slice(0, 500) with truncateUtf16Safe() to prevent
UTF-16 surrogate pair corruption in sanitized hook output.
@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. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. 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, 6:43 AM ET / 10:43 UTC.

Summary
The branch imports truncateUtf16Safe and uses it instead of .slice(0, 500) when sanitizing Gateway hook warning console values.

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

Reproducibility: yes. from source inspection: current main calls .slice(0, 500) after sanitizing hook console values, so a surrogate pair starting at the cutoff can be split. I did not execute a live hook run in this read-only review.

Review metrics: none identified.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🐚 platinum hermit
Result: blocked until real behavior proof from a real setup 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 live hook run output, terminal output, or logs showing a non-ok hook consoleMessage with a surrogate pair at the truncation boundary.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR body reports type checking and existing utility coverage, but it does not include redacted live hook output, terminal output, or logs showing the changed consoleMessage; updating the PR body with that proof should trigger a fresh review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] No redacted real Gateway hook run or log/terminal output is attached yet, so the behavior proof currently relies on source inspection and existing helper tests.
  • [P1] The adjacent Gateway hook test covers consoleMessage content but not this exact surrogate-boundary truncation case.

Maintainer options:

  1. Decide the mitigation before merge
    Land the narrow Gateway hook sanitizer change after the contributor adds redacted real hook warning console output or an equivalent runtime validation transcript showing surrogate-safe truncation.
  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 real-behavior proof rather than a code repair that ClawSweeper should make.

Security
Cleared: Cleared: the diff only imports an existing internal normalization helper and changes local string truncation; it does not alter dependencies, workflows, credentials, permissions, or execution surfaces.

Review details

Best possible solution:

Land the narrow Gateway hook sanitizer change after the contributor adds redacted real hook warning console output or an equivalent runtime validation transcript showing surrogate-safe truncation.

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

Yes from source inspection: current main calls .slice(0, 500) after sanitizing hook console values, so a surrogate pair starting at the cutoff can be split. I did not execute a live hook run in this read-only review.

Is this the best way to solve the issue?

Yes: using the existing truncateUtf16Safe helper at the single truncation site is the narrowest maintainable fix, and it avoids adding new API, config, or duplicate truncation logic.

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add P3: This is a low-risk, narrow Gateway logging correctness fix with limited user impact and no API, config, or data-model surface.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish 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: The PR body reports type checking and existing utility coverage, but it does not include redacted live hook output, terminal output, or logs showing the changed consoleMessage; updating the PR body with that proof should trigger a fresh review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Label justifications:

  • P3: This is a low-risk, narrow Gateway logging correctness fix with limited user impact and no API, config, or data-model surface.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish 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: The PR body reports type checking and existing utility coverage, but it does not include redacted live hook output, terminal output, or logs showing the changed consoleMessage; updating the PR body with that proof should trigger a fresh review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +1. Total +1 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 1 2 1 +1
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 2 1 +1

What I checked:

Likely related people:

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: 🦪 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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Jul 9, 2026
@vincentkoc vincentkoc self-assigned this Jul 9, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Closing this as an isolated UTF truncation micro-change rather than spending a separate maintainer cycle on one diagnostic-only call site.

The production diff is a two-line helper substitution in hook warning formatting, with no linked runtime failure or focused active-path regression. We are consolidating this class of raw-slice cleanup by owner/surface instead of landing a stream of one-call-site PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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