Skip to content

fix(discord): keep gateway close reasons UTF-16 safe#102246

Merged
steipete merged 2 commits into
openclaw:mainfrom
mushuiyu886:fix/followup-101685
Jul 9, 2026
Merged

fix(discord): keep gateway close reasons UTF-16 safe#102246
steipete merged 2 commits into
openclaw:mainfrom
mushuiyu886:fix/followup-101685

Conversation

@mushuiyu886

@mushuiyu886 mushuiyu886 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

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

formatDiscordGatewayCloseReason now uses truncateUtf16Safe from the supported openclaw/plugin-sdk/text-utility-runtime facade. 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

  • Production-path test constructs the Discord gateway plugin, injects the existing WebSocket test seam, emits close(1008, Buffer), and inspects the emitted runtime warning.
  • The exact reason prefix, close code, and receiver-limit hint are asserted.
  • Targeted oxfmt and git diff --check: pass.
  • Fresh maintainer autoreview: clean, confidence 0.99.
  • Exact-head CI run 28991617622, OpenGrep run 28991617608, and CodeQL run 28991617585 on 143d723f24776b8bca6ffbe68a361b75539af5c8: success.

AI-assisted: yes. Maintainer-reviewed and tightened.

@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord size: S labels Jul 8, 2026
@clawsweeper

clawsweeper Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 8, 2026, 11:27 PM ET / 03:27 UTC.

Summary
The PR changes Discord gateway close-reason formatting to use the shared UTF-16-safe truncation helper and adds a close-handler regression test.

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
Relationship: canonical
Canonical: #102246
Summary: This PR is the canonical open fix for the remaining Discord gateway close-reason formatter gap; adjacent Unicode truncation work either covered other surfaces or a different gateway close helper.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦞 diamond lobster
Proof: 🦞 diamond lobster
Patch quality: 🦞 diamond lobster
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Next step before merge

  • No ClawSweeper repair lane is needed; this is ready for normal maintainer review with required exact-head checks as the remaining gate.

Security
Cleared: The diff only uses an existing exported helper and adds a focused test, with no dependency, lockfile, workflow, secrets, permissions, package-resolution, or code-execution changes.

Review details

Best 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 changes

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🦀 challenger crab: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: This is a normal-priority Discord gateway diagnostics correctness fix with limited runtime blast radius.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Live GitHub state has proof: sufficient and a passing Real behavior proof check for this head; no contributor proof action is needed.
  • proof: sufficient: Contributor real behavior proof is sufficient. Live GitHub state has proof: sufficient and a passing Real behavior proof check for this head; no contributor proof action is needed.
Evidence reviewed

PR surface:

Source +1, Tests +31. Total +32 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 2 1 +1
Tests 1 31 0 +31
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 33 1 +32

What I checked:

Likely related people:

  • vincentkoc: Current-main blame and GitHub PR mapping tie the close-reason formatter, WebSocket close log path, and shared UTF-16 helper implementation to merged PR refactor(zalo): localize internal declarations #102065. (role: introduced behavior in current-main history; confidence: high; commits: fc4626c1221d; files: extensions/discord/src/monitor/gateway-plugin.ts, extensions/discord/src/monitor/gateway-plugin.test.ts, packages/normalization-core/src/utf16-slice.ts)
  • steipete: Merged PR fix: prevent garbled emoji at remaining text limits #101685 added the broader UTF-16-safe bounded-text sweep across adjacent surfaces, and this account authored the latest test-tightening commit on this branch. (role: recent adjacent UTF-16 truncation contributor; confidence: medium; commits: 176fee5d071d, 8edbb1b26460, 143d723f2477; files: extensions/discord/src/monitor/reply-delivery.ts, extensions/discord/src/outbound-adapter.ts, extensions/discord/src/monitor/gateway-plugin.test.ts)
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.
Review history (2 earlier review cycles)
  • reviewed 2026-07-08T16:27:36.736Z sha 200f780 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-08T16:34:06.981Z sha 200f780 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. rating: 🦀 challenger crab Exceptional PR readiness: strong proof, clean patch, and convincing validation. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Jul 8, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🦀 challenger crab Exceptional PR readiness: strong proof, clean patch, and convincing validation. labels Jul 9, 2026
@steipete

steipete commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Maintainer verification complete on exact head 143d723f24776b8bca6ffbe68a361b75539af5c8.

  • Replaced the manual surrogate scanner with an exact runtime-log assertion that fails against the old malformed output.
  • Fresh autoreview: clean, confidence 0.99.
  • CI run 28991617622: success.
  • OpenGrep run 28991617608: success.
  • CodeQL Critical Quality run 28991617585: success.

The supported plugin SDK facade owns the boundary; Discord gateway lifecycle, capture, reconnect, and delivery behavior are unchanged.

@steipete
steipete merged commit e90bf31 into openclaw:main Jul 9, 2026
119 of 123 checks passed
@steipete

steipete commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

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

Labels

channel: discord Channel integration: discord P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants