feat(discord): periodic thread retitle on top of upstream semantic titles - #29983
feat(discord): periodic thread retitle on top of upstream semantic titles#29983TheoLong wants to merge 1 commit into
Conversation
8bdeed8 to
9b0820b
Compare
|
Rebased on current Re competing PR #15757 and prior closes (#13915, #16059): also happy to defer. Bumping for review. |
9b0820b to
09a5fca
Compare
|
Rebased on current The opt-out flag the triage bot asked for is already in this branch — On overlap with what's on main: current main names the CLI→Discord handoff thread at creation ( Re competing #15757 and prior closes (#13915, #16059): happy to defer if a maintainer prefers one of those. Bumping for review. |
09a5fca to
32542c7
Compare
|
Rebased on current The opt-out flag the triage bot asked for is already in this branch — No overlap with Re competing PR #15757 (thread name syncing) that automation flagged: happy to defer if a maintainer prefers it; this version additionally handles periodic drift (re-evaluates every N turns), not just the first-turn rename. |
32542c7 to
c929160
Compare
teknium1
left a comment
There was a problem hiding this comment.
Thanks for carrying the periodic-retitle portion forward. Current main already landed the first-title Discord rename in 0d9ed9214 / v2026.7.7, but the periodic behavior remains distinct.
Problems
gateway/run.py:3498-3511accepts every Discord thread, andgateway/run.py:13433-13445then directly edits any differing name. This regresses main's intentional human-name protection:gateway/session.py:185-191records auto-thread provenance, andtests/gateway/test_discord_slash_commands.py:714-729verifies a human rename is not overwritten.gateway/run.py:13398truncates by Python code points. Discord's limit is UTF-16 units; current main fixed this in1deeaf71a, using UTF-16-aware truncation atgateway/run.py:13657-13669.agent/title_generator.py:288-301omitsstrip_think_blocks, unlike the existing title path atagent/title_generator.py:90-106; periodic retitles can therefore persist reasoning markup.
Suggested changes
- Build periodic retitling on main's guarded
DiscordAdapter.rename_threadpath, preserving manual renames and auto-thread provenance. - Reuse the UTF-16 sanitizer and canonical think-block scrubber.
- Add gateway coverage for periodic scheduling, human/pre-existing thread preservation, and UTF-16 titles.
This is an automated hermes-sweeper review.
| cleaned = " ".join(cleaned.split()) | ||
| if not cleaned: | ||
| return cleaned | ||
| return cleaned[: self._DISCORD_THREAD_NAME_MAX] |
There was a problem hiding this comment.
Discord applies its thread-name limit in UTF-16 code units, so this code-point slice can still exceed the API limit for emoji/non-BMP titles. Please reuse main's UTF-16-aware sanitizer (_prefix_within_utf16_limit); this was fixed in 1deeaf71a.
| edit = getattr(channel, "edit", None) | ||
| if not callable(edit): | ||
| return | ||
| await edit(name=new_name, reason="Hermes auto-title") |
There was a problem hiding this comment.
This edits any thread whose name differs from the generated title, including a human-renamed or pre-existing thread. Main deliberately preserves the initial auto-thread name in SessionSource and uses DiscordAdapter.rename_thread(..., only_if_current_name=...); please retain equivalent ownership protection here.
| timeout=timeout, | ||
| main_runtime=main_runtime, | ||
| ) | ||
| title = (response.choices[0].message.content or "").strip() |
There was a problem hiding this comment.
Please sanitize reasoning output with the same strip_think_blocks helper used by generate_title before validating the title. Otherwise a periodic retitle from a think-enabled model can persist `` content into the session and Discord thread name.
c929160 to
5e3f10d
Compare
|
Rebased on current |
…tles Upstream 0d9ed92 ("Add semantic titles for Discord auto-threads") now does the first-turn Discord thread rename that the original carry implemented in gateway/run.py, so that half is dropped in favor of upstream's UTF-16-aware _sanitize_discord_thread_title + _schedule_discord_semantic_thread_rename. This carry now contributes ONLY the residual delta upstream still lacks: 1. agent/title_generator.py: maybe_retitle_session — re-evaluates the session title every few user turns after the initial auto-title and fires the existing title_callback only when the topic genuinely drifts. Includes regenerate_title (sticky whole-conversation re-assessment) and the _looks_like_title guard, which REJECTS prose-shaped model output (>10 words / >80 chars / mid-sentence break) instead of truncating it into a junk title. 2. gateway/run.py: the periodic call site reuses upstream's semantic rename callback via the shared maybe_auto_title_kwargs, so Discord threads get renamed on drift with no duplicate rename plumbing. The carry's own first-turn helpers (_is_discord_thread_lane, _schedule_discord_thread_rename, _rename_discord_thread_for_session_title, _sanitize_discord_thread_name) are removed as dead code superseded by upstream. Reconstructed on top of upstream during the 2026-07-10 sync. (cherry picked from commit e4bc33a) (cherry picked from commit d495f33) (cherry picked from commit 45d7d350294bd64a7b458b5548ea00cdd462437f)
5e3f10d to
25e4cd8
Compare
|
Rebased onto current Scope note — this PR is now only the periodic half. Upstream has since landed semantic thread titles ( I re-verified the integration against title_callback=(lambda t: _retitle_cb(t, "llm")) if _retitle_cb else NoneWorth stating plainly because a silent arity/gate mismatch here would make the feature a no-op in production while unit tests — which pass their own callback — stayed green. A guard worth reviewing on its own merits:
Rate limiting is respected throughout (Discord's channel-rename budget is ~2/10min); the retitle is fire-and-forget on a daemon thread and never blocks a turn. |
Problem
Discord threads default to the originating message's first line — rarely a good title for a multi-turn agent session.
Change
Rename the thread to the auto-generated session title after the first exchange, and again periodically as the conversation evolves. New periodic retitle helper added to
agent/title_generator.py; wired in viagateway/run.py.Trade-off / opt-out
I noticed #28…
feat(telegram): add disable_topic_auto_rename gateway flagjust landed for the Telegram side — users want to opt out of unsolicited renames when they've named topics by hand.This Discord change is the mirror image and the same opt-out concern applies. Happy to add
gateway.platforms.discord.extra.disable_thread_auto_rename(default False, preserving the behaviour in this PR) as a follow-up commit on this branch if maintainers want it baked in before merge.Risk
Medium. Behaviour change visible to every Discord user. Opt-out flag recommended before merge.