fix(diagnostics-prometheus): use truncateUtf16Safe for error message truncation#102591
Conversation
…truncation The safeErrorMessage function uses naive .slice(0, 500) on error messages which can split surrogate pairs. Replace with truncateUtf16Safe().
|
Codex review: needs real behavior proof before merge. Reviewed July 9, 2026, 5:30 AM ET / 09:30 UTC. Summary PR surface: Source +3. Total +3 across 1 file. Reproducibility: yes. Source inspection shows current main truncates Review metrics: 1 noteworthy metric.
Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. 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 one narrow PR for this call site after redacted runtime proof is added, then close the duplicate open PR rather than carrying both. Do we have a high-confidence way to reproduce the issue? Yes. Source inspection shows current main truncates Is this the best way to solve the issue? Yes. Replacing only the final truncation with the exported SDK helper preserves redaction and the 500-code-unit cap while matching the sibling diagnostics-otel pattern; the remaining gap is proof, not fix shape. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 4ad94febcb31. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +3. Total +3 across 1 file. 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 verification at exact head
No docs, config, metrics, API, or dependency changes. Ready to merge. |
|
Merged via squash.
|
…truncation (openclaw#102591) * fix(diagnostics-prometheus): use truncateUtf16Safe for error message truncation The safeErrorMessage function uses naive .slice(0, 500) on error messages which can split surrogate pairs. Replace with truncateUtf16Safe(). * test(diagnostics-prometheus): cover UTF-16-safe errors --------- Co-authored-by: Peter Steinberger <[email protected]>
What Problem This Solves
The Prometheus diagnostics service bounded sanitized event-handler errors with
slice(0, 500). When an error contained an astral character across that boundary, the log could end with an unpaired UTF-16 surrogate.Why This Change Was Made
Use the existing
truncateUtf16Safeutility at the final rendering boundary. The established redaction, null-byte removal, control-character normalization, and 500-code-unit limit remain unchanged.The follow-up test exercises the public service lifecycle: it captures the registered diagnostics listener, makes the real
model.usagerecorder throw a boundary-straddling error through a property getter, and checks the complete logger output. This proves the changed call site rather than only the shared helper.User Impact
Prometheus exporter event-handler failures remain bounded and sanitized, but their logs no longer contain malformed UTF-16 when an emoji or another surrogate pair crosses the limit. No config, API, metric, or dependency behavior changes.
Evidence
node scripts/run-vitest.mjs extensions/diagnostics-prometheus/src/service.test.ts— 17 tests passed.oxfmtcompleted for the changed test.git diff --checkpassed.Risk
Low. One rendering boundary now uses the shared truncation invariant; ASCII and BMP output within the existing limit is unchanged.
AI-assisted
This PR was generated with Claude Code and improved/reviewed by a maintainer agent.