Skip to content

fix(discord): persist thread participation across gateway restarts#1661

Merged
teknium1 merged 1 commit intomainfrom
fix/discord-thread-persistence
Mar 17, 2026
Merged

fix(discord): persist thread participation across gateway restarts#1661
teknium1 merged 1 commit intomainfrom
fix/discord-thread-persistence

Conversation

@teknium1
Copy link
Copy Markdown
Contributor

Fixes Discord thread context loss reported by k_sze — bot starts responding outside threads after gateway restart.

What was happening

_bot_participated_threads was an in-memory set(). Every gateway restart wiped it. After restart:

  • Bot forgot which threads it was active in
  • With require_mention=true (default), it ignored follow-up messages in threads
  • If user @mentioned in the parent channel, bot created a new auto-thread instead of continuing

Fix

  • Persist thread IDs to ~/.hermes/discord_threads.json
  • Load on adapter init, save on every new thread tracked
  • _track_thread() replaces direct .add() for atomic persist
  • Cap at 500 entries to prevent unbounded growth
  • /thread slash command also tracks participation

Tests

7 new tests: persistence, restart survival, dedup, cap enforcement, corruption recovery, missing directory handling.

987 gateway tests passing.

_bot_participated_threads was an in-memory set — lost on every restart.
After restart, the bot forgot which threads it was active in, requiring
fresh @mentions and potentially creating duplicate threads instead of
continuing existing conversations.

Changes:
- Persist thread IDs to ~/.hermes/discord_threads.json
- Load on adapter init, save on every new thread participation
- _track_thread() replaces direct .add() calls for atomic persist
- Cap at 500 tracked threads to prevent unbounded growth
- /thread slash command also tracks participation
- 7 new tests covering persistence, restart survival, corruption
  recovery, cap enforcement
@teknium1 teknium1 merged commit 36a76bf into main Mar 17, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant