fix(logging): keep bounded log text UTF-16 safe#102560
Conversation
Replace naive .slice(0, maxChars) with truncateUtf16Safe() in clampDiagnosticLogText() — the core helper used by all diagnostic log output (sanitizeDiagnosticLogText, formatDiagnosticAttributes, etc.). This prevents surrogate pair splitting across the entire diagnostic logging subsystem. Co-Authored-By: Claude <[email protected]>
|
@steipete this one fixes the core diagnostic logging helper |
|
Codex review: needs real behavior proof before merge. Reviewed July 9, 2026, 5:05 AM ET / 09:05 UTC. Summary PR surface: Source +1, Tests +29. Total +30 across 3 files. Reproducibility: yes. from source inspection, though not from an executed local run: current main's diagnostic and file-log clamps use raw UTF-16 code-unit slicing at the bound. A 4,095-character prefix followed by an emoji crosses the 4,096 limit and can leave a dangling surrogate before the truncation marker. Review metrics: none identified. Stored data model 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: Land this focused logger clamp change after redacted real-behavior proof is added and exact-head checks are green, keeping the shared helper and both diagnostic/file-log regression tests. Do we have a high-confidence way to reproduce the issue? Yes from source inspection, though not from an executed local run: current main's diagnostic and file-log clamps use raw UTF-16 code-unit slicing at the bound. A 4,095-character prefix followed by an emoji crosses the 4,096 limit and can leave a dangling surrogate before the truncation marker. Is this the best way to solve the issue? Yes for the code shape: reusing AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against e975d4923808. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +1, Tests +29. Total +30 across 3 files. View PR surface stats
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 review completed at exact head What changed during maintainer review:
Evidence:
Known proof gaps: none for this internal logging boundary change. |
|
Merged via squash.
|
* fix(logging): use truncateUtf16Safe in diagnostic log text clamp Replace naive .slice(0, maxChars) with truncateUtf16Safe() in clampDiagnosticLogText() — the core helper used by all diagnostic log output (sanitizeDiagnosticLogText, formatDiagnosticAttributes, etc.). This prevents surrogate pair splitting across the entire diagnostic logging subsystem. Co-Authored-By: Claude <[email protected]> * fix(logging): preserve UTF-16 in bounded log text --------- Co-authored-by: Claude <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
What Problem This Solves
Bounded logger text used raw UTF-16 code-unit slices. A boundary inside an emoji could leave an unpaired surrogate in diagnostic events or JSONL file-log messages.
Why This Change Was Made
The diagnostic and file-log clamps in
src/logging/logger.tsnow share the existing UTF-16-safe truncation helper. Review expanded the original one-sided diagnostic fix to the sibling file-log path in the same owner module.User Impact
Long diagnostic messages, diagnostic attributes, file-log messages, and promoted file-log context remain valid Unicode at their existing size limits. Markers, limits, redaction order, and short-message behavior are unchanged.
Evidence
vitest.logging.config.tsfocused run — 2 files passed; 2 tests passed, 15 skipped.🤖 Generated with Claude Code