fix(discord): truncate auto-thread and handoff thread names by UTF-16 units - #60252
fix(discord): truncate auto-thread and handoff thread names by UTF-16 units#60252pierrenode wants to merge 1 commit into
Conversation
|
Thanks for finding the still-live auto-thread and handoff truncation gap. Current main confirms both reported code-point slices at Problems
Suggested changes
Automated hermes-sweeper review. |
a228495 to
a74fdb7
Compare
… units _derive_auto_thread_name() and create_handoff_thread() cap Discord thread names with a Python code-point slice ([:80]), but Discord validates the `name` field in UTF-16 code units (100 max). An emoji-heavy first message or handoff name can pass the code-point cap while exceeding 100 UTF-16 units, so create_thread() is rejected with error 50035 and the auto-thread or handoff thread is silently never created. This is the sibling rename_thread()/_sanitize_discord_thread_title() (gateway/run.py) were already fixed to use utf16_len/_prefix_within_utf16_limit for — those two functions rename a thread after semantic titling; these two construct the thread name at creation time and were missed. Fix: route both through the same utf16_len/_prefix_within_utf16_limit helpers already imported in this module. No behavior change for ASCII names (existing test_auto_create_thread_truncates_long_names still passes unmodified). Widen to the two remaining creation-time sites that share the same class of bug: - `_create_thread()` (the native /thread slash command): validates the explicit user-supplied name against the UTF-16 limit and returns a clear error rather than silently truncating input the user typed on purpose — different UX from the auto-generated-name sites, which already truncate. - `_derive_forum_thread_name()`: forum-post thread names derived from the first line of a message had the same raw `first_line[:100]` code-point slice; now routed through `_prefix_within_utf16_limit`.
a74fdb7 to
00bb1d6
Compare
|
Rebased onto current `upstream/main` — production code (`plugins/platforms/discord/adapter.py`) auto-merged cleanly, fix intact. The test file conflict was upstream's own pruning of several pre-existing `_auto_create_thread` tests unrelated to this fix — kept upstream's pruning, restored only this PR's own new UTF-16 regression test. Mutation-verified: reverting `_derive_auto_thread_name`'s truncation to code-point slicing breaks the new test (157 UTF-16 units instead of ≤80). Full `tests/gateway/test_discord_slash_commands.py` (19 tests) passes. Ruff clean. Fresh competitor search: #60196 (forum thread names, `_derive_forum_thread_name`) touches a different, sibling function — no overlap with this PR's `_derive_auto_thread_name`/`create_handoff_thread`. Squashed to a single commit on top of current `upstream/main`. |
What does this PR do?
_derive_auto_thread_name()andcreate_handoff_thread()inplugins/platforms/discord/adapter.pycap Discord thread names with a Python code-point slice (content[:80],name[:80]), but Discord validates thenamefield in UTF-16 code units (100 max). An emoji-heavy first message (auto-threading) or handoff name can pass the code-point cap while exceeding 100 UTF-16 units, socreate_thread()is rejected with error 50035 and the thread is silently never created.This is the sibling of
rename_thread()/gateway/run.py::_sanitize_discord_thread_title(), which were already migrated toutf16_len/_prefix_within_utf16_limit— those two rename a thread after semantic titling;_derive_auto_thread_name()andcreate_handoff_thread()construct the name at creation time and were missed by that pass.Fix: route both through the same
utf16_len/_prefix_within_utf16_limithelpers already imported in this module. No behavior change for ASCII names.Related Issue
No separate issue filed for this specific gap (found via sibling-site review after the recent UTF-16 truncation fixes to
rename_thread()and the forum-thread-name path).Type of Change
Changes Made
plugins/platforms/discord/adapter.py:_derive_auto_thread_name()andcreate_handoff_thread()now truncate withutf16_len/_prefix_within_utf16_limitinstead of code-point slices (+12/-5 lines)tests/gateway/test_discord_slash_commands.py: regression tests for both functions with 90-emoji names; verified RED without the fix (157/160 UTF-16 units, over the 80 budget) and GREEN with itHow to Test
Mutation-verified: reverting the fix locally makes both new tests fail with
assert 157 <= 80/assert 160 <= 80.Checklist