fix(discord): cap forum thread names by UTF-16 units, not code points - #60196
fix(discord): cap forum thread names by UTF-16 units, not code points#60196briandevans wants to merge 1 commit into
Conversation
_derive_forum_thread_name capped the derived Discord forum thread name with first_line[:100] — a Python code-point slice — but Discord validates the thread name field in UTF-16 code units (100 max). A first line opening with emoji or non-BMP text (agents commonly lead with an emoji header) can exceed 100 UTF-16 units while passing the code-point cap, so create_thread fails with error 50035 and the entire forum reply is dropped (SendResult(success=False)), not merely clipped. Switch to _prefix_within_utf16_limit (already imported and used elsewhere in this adapter) so the name never splits a surrogate pair and always stays within Discord's limit. Sibling of the UTF-16 hardening in NousResearch#60113, which bounded component labels but missed this path.
There was a problem hiding this comment.
Pull request overview
This PR fixes a Discord forum-thread posting edge case where derived thread names could exceed Discord’s 100 UTF-16 code unit limit when the first line contains non-BMP characters (e.g., emoji), causing create_thread(name=...) to fail and drop the forum reply. It aligns forum thread-name truncation with the existing UTF-16-safe truncation approach already used elsewhere in the Discord adapter.
Changes:
- Update
_derive_forum_thread_nameto cap by UTF-16 code units via_prefix_within_utf16_limit(..., 100)instead of slicing by Python code points ([:100]). - Add a regression test covering emoji-heavy and ASCII-heavy inputs to ensure derived forum thread names fit Discord’s UTF-16 budget.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| plugins/platforms/discord/adapter.py | Switch forum thread-name truncation to UTF-16-unit-safe prefixing and update the docstring to reflect Discord’s actual validation unit. |
| tests/gateway/test_discord_clarify_buttons.py | Add regression coverage ensuring forum thread-name derivation stays within the 100 UTF-16 code unit limit (emoji + ASCII cases). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Thanks for isolating the forum-thread path. The proposed replacement of the current Problems
Suggested changes
Automated hermes-sweeper review. |
This is a sibling follow-up to #60113
test_truncates_emoji_choice_label_by_utf16_limit._derive_forum_thread_name, which still capped by Python code points.[:100]code-point slice to the same_prefix_within_utf16_limithelper the adapter already imports, plus a regression test.What does this PR do?
_derive_forum_thread_nameinplugins/platforms/discord/adapter.pycaps thederived Discord forum thread name with
first_line[:100]— a code-point slice —but Discord validates the thread
namefield in UTF-16 code units (100 max).A message whose first line opens with emoji / non-BMP text (agents commonly lead
with an emoji header) can exceed 100 UTF-16 units while passing the code-point
cap, so
create_thread(name=...)fails with error 50035 ("Must be 100 or fewerin length") and the entire forum reply is dropped (
SendResult(success=False)),not merely clipped. This is the sibling the UTF-16 hardening in #60113 (component
labels) missed; the adapter already imports
_prefix_within_utf16_limit/utf16_lenfor exactly this purpose.
Related Issue
Type of Change
Changes Made
plugins/platforms/discord/adapter.py:_derive_forum_thread_namenow returns_prefix_within_utf16_limit(first_line, 100)instead offirst_line[:100](and the docstring reflects the UTF-16 unit limit).
tests/gateway/test_discord_clarify_buttons.py: addtest_forum_thread_name_capped_by_utf16_units.How to Test
_derive_forum_thread_name("\U0001F600" * 100)— 100 emoji is 200 UTF-16units under the old code-point cap; after this change the result is clamped
to <= 100 units without splitting a surrogate pair.
xstill clamps to exactly 100 units.pytest tests/gateway/test_discord_clarify_buttons.py tests/gateway/test_discord_send.py -q→ 40 passed. The new test fails before the fix (200 > 100), passes after.Follow-up (out of scope here): the
Choice.nameand describe-hint[:100]capsin the same adapter are the remaining code-point siblings and can be migrated
separately.
Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/gateway/test_discord_clarify_buttons.py tests/gateway/test_discord_send.py -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — updated the_derive_forum_thread_namedocstringcli-config.yaml.exampleif I added/changed config keys — N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — N/A