feat(discord): sync thread titles with session titles - #35420
Conversation
f8e72d3 to
5a84e1b
Compare
|
Found the attachment/document retitle edge case from live gateway logs and added a regression test commit, but GitHub rejected pushing directly to the contributor branch from my account despite maintainerCanModify=true. Branch/commit with the test:
Failure mode: Discord creates the thread from the raw starter text, but the agent prompt can be prefixed with attachment metadata like This PR's |
b40d238 to
f7ac8d8
Compare
What changed: - Start Discord auto-created threads with the normal message-based title instead of a forced placeholder. - Rename Discord threads after Hermes generates a session summary title. - Only auto-rename when the thread name is still the original auto-created name, preserving workflow or user titles like `sample-repo ExampleOrg#1000001`. - Sync explicit `/title ...` changes from Hermes sessions to Discord thread titles. - Sync Discord thread rename events back to Hermes session titles for existing sessions. - Add session lookup by platform thread ID for platform-side title update events. - Add tests for generated summary title renaming, preserving manual or workflow-renamed threads, explicit `/title` syncing, Discord rename syncing, slash-command auto-thread routing, and initial auto-thread name capture. Verified: - `scripts/run_tests.sh` (27,394 tests passed, 0 failed) - `pytest -q tests/gateway/test_discord_thread_rename.py tests/gateway/test_discord_free_response.py tests/gateway/test_session.py tests/gateway/test_discord_slash_commands.py -q` - `pytest -q tests/gateway/test_discord_slash_commands.py::test_auto_thread_creates_thread_and_redirects -q` - `pytest -q tests/gateway/test_discord_free_response.py::test_discord_summary_rename_skips_when_thread_name_changed -q` - `python -m py_compile ...` - `python scripts/check-windows-footguns.py --diff origin/main` - `git diff --check` - Static added-line security scan found no hardcoded secret, shell injection, eval/exec, pickle, or SQL injection patterns. - Independent review checked the diff against CONTRIBUTING.md.
f7ac8d8 to
d9b64b8
Compare
|
Fixed via #60187 (salvage of #56792 by @rungmc357). Your PR was the earliest implementation of this feature - thanks for kicking off the direction. The merged fix follows the Telegram title_callback pattern that landed on main after your branch was cut, and config lives in config.yaml rather than env vars per current policy. |
What does this PR do?
Adds minimal Discord thread-title synchronization for Hermes sessions.
When Hermes generates a session title for a Discord thread, the gateway now attempts to rename the Discord thread to that generated title, but only when the thread still appears to have its initial/default name, the same session is still bound to that Discord thread, and the generated title is useful. Low-information auto-titles such as
Hermesare ignored so they do not replace a better message-derived thread name.It also syncs Discord thread renames back into the Hermes session title so
/title,/history,/resume, and session search stay aligned with the visible Discord thread name.Manual
/title <name>remains explicit user intent and can rename the Discord thread even when the original initial thread name is unavailable. Explicit title renames use Discord's full 100-character thread-name limit.Auto-thread naming is configurable via
discord.auto_thread_name_mode/DISCORD_AUTO_THREAD_NAME_MODE:summary(default): rename auto-created Discord threads to the generated Hermes session title after the first response.message: keep the initial message-derived Discord thread name.Summary-generated thread titles use
discord.auto_thread_summary_max_chars/DISCORD_AUTO_THREAD_SUMMARY_MAX_CHARS(default70, capped at Discord's 100-character thread-name limit).Related Issue
Fixes #
Type of Change
Changes Made
gateway/session.pythread_initial_nameonSessionSourceso the gateway can tell whether a Discord thread still has its initial/default name.gateway/platforms/base.pyplugins/platforms/discord/adapter.pySessionSource.rename_thread(...)support with an optional expected-current-name guard.expected_current_name, so cached stale thread names cannot bypass the guard.discord.auto_thread_name_modeanddiscord.auto_thread_summary_max_charsfromconfig.yamlto environment variables.agent/title_generator.pyandhermes_state.pySessionDB.set_session_title_if_empty(...)and uses it for auto-generated titles.gateway/run.pyHermesso they do not overwrite better initial thread names./titledelivery.auto_thread_name_mode: summary | messageand configurable summary title length./title <name>as user intent and schedules a Discord thread rename without the initial-name guard.Website docs
discord.auto_thread_name_mode,DISCORD_AUTO_THREAD_NAME_MODE,discord.auto_thread_summary_max_chars, andDISCORD_AUTO_THREAD_SUMMARY_MAX_CHARSnear the existingauto_thread/DISCORD_AUTO_THREADentries.Tests
/titlefull-length and truncation behavior, fresh Discord fetch for the rename guard, bot rename echo suppression, interleaved bot rename echoes, rebound-session stale echo suppression, config bridging, and thread-title sync-back.How to Test
Run focused title-sync tests:
Run gateway/agent related tests:
Run the full test suite using the repository’s preferred CONTRIBUTING.md-compatible wrapper:
Run review/lint sanity checks:
git diff --check git diff origin/main --name-only | sortChecklist
Code
fix(scope):,feat(scope):, etc.)scripts/run_tests.shwrapper and all tests passDocumentation & Housekeeping
docs/, docstrings)cli-config.yaml.exampleif I added/changed config keys — N/A (Discord plugin config docs are in website docs/reference)CONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — N/A;CONTRIBUTING.mdis not touched by this PRReview Notes
Claude reviewer feedback led to additional hardening for title-sync races:
expected_current_namechecks fetch fresh thread state before comparing./titleechoes cannot cause an older echo to overwrite a newer title.Additional local reviewer loop:
NO BLOCKING ISSUESNO BLOCKING ISSUESScreenshots / Logs
Focused post-echo-queue-fix title-sync tests:
Post-echo-queue-fix gateway/agent related tests:
Full suite before final echo-queue follow-up, after all earlier code fixes:
Reviewer loop: