fix(discord): keep gateway close reasons UTF-16 safe#102246
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 8, 2026, 11:27 PM ET / 03:27 UTC. Summary PR surface: Source +1, Tests +31. Total +32 across 2 files. Reproducibility: yes. Source inspection shows current main can split a surrogate pair with a 239-character prefix plus emoji at the 240-code-unit close-reason log boundary, and the PR adds a focused close-handler regression test for that path. Review metrics: none identified. 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. Next step before merge
Security Review detailsBest possible solution: Land the focused helper replacement and regression test after normal maintainer review and required exact-head CI, preserving Discord gateway behavior outside warning-log formatting. Do we have a high-confidence way to reproduce the issue? Yes. Source inspection shows current main can split a surrogate pair with a 239-character prefix plus emoji at the 240-code-unit close-reason log boundary, and the PR adds a focused close-handler regression test for that path. Is this the best way to solve the issue? Yes. Fixing the formatter where the invalid string is created and reusing the existing shared helper is narrower than adding a Discord-local helper or downstream log sanitizer. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 1252a3da59a8. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +1, Tests +31. Total +32 across 2 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
|
|
Maintainer verification complete on exact head
The supported plugin SDK facade owns the boundary; Discord gateway lifecycle, capture, reconnect, and delivery behavior are unchanged. |
|
Merged via squash.
|
* fix(discord): keep gateway close reasons UTF-16 safe * test(discord): assert exact close reason truncation --------- Co-authored-by: Peter Steinberger <[email protected]>
What Problem This Solves
Discord gateway close reasons are capped at 240 UTF-16 code units before being written to the runtime warning log. The formatter used raw slicing, which could retain a lone high surrogate when the limit crossed an emoji or another astral character.
Why This Change Was Made
formatDiscordGatewayCloseReasonnow usestruncateUtf16Safefrom the supportedopenclaw/plugin-sdk/text-utility-runtimefacade. Buffer decoding, whitespace normalization, log conditions, capture behavior, and gateway lifecycle remain unchanged.The maintainer fixup replaced a manual surrogate scanner with a stronger exact assertion: the production WebSocket close path must log 239 ASCII characters followed immediately by the existing
...suffix. That assertion fails against the previous malformed output.User Impact
Abnormal Discord gateway close diagnostics remain readable when a truncation boundary crosses an astral character. Connection, reconnect, identify, and message delivery behavior do not change.
Evidence
close(1008, Buffer), and inspects the emitted runtime warning.git diff --check: pass.28991617622, OpenGrep run28991617608, and CodeQL run28991617585on143d723f24776b8bca6ffbe68a361b75539af5c8: success.AI-assisted: yes. Maintainer-reviewed and tightened.