hermes - 💡(How to fix) Fix Discord thread sessions appear to mix context between threads

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Code Example

# For threads:
chat_type = "thread"
chat_id = str(effective_channel.id)  # = thread channel ID
thread_id = str(message.channel.id)  # = SAME thread channel ID
RAW_BUFFERClick to expand / collapse

Bug Report: Discord Thread Session Mixing

Severity: Medium — user reports context from other threads/sessions bleeding into their current thread conversation on Discord

Reporter: Discord user (Boundzie) — experienced session mixing while staying in a single thread chat window

Symptoms:

  • Agent responses include information or context from unrelated Discord thread sessions
  • User has not moved between threads/channels — the mixing happens while staying in one thread
  • Issue appears Discord-specific (user reports only seeing this problem on Discord)

Analysis:

The Discord adapter constructs SessionSource for thread messages as follows (adapter.py lines 4640-4665):

# For threads:
chat_type = "thread"
chat_id = str(effective_channel.id)  # = thread channel ID
thread_id = str(message.channel.id)  # = SAME thread channel ID

This produces a session key like: agent:main:discord:thread:1512311523459203173:1512311523459203173

The key is deterministic and unique per thread — the session key logic itself appears correct. Each thread gets its own isolated session key with no overlap.

Possible causes of observed mixing:

  1. Memory injection across sessions — The memory tool loads persistent user-level memories into ALL sessions regardless of platform. If memories from other Discord thread sessions are saved and then loaded into the current session, the agent may reference prior-thread context as if it were current. This is by-design (memories are cross-session), but could feel like session mixing from the user perspective.

  2. Agent cache contamination — If the in-memory agent cache (_active_sessions) incorrectly routes messages between sessions under high concurrency or race conditions (e.g., two threads messaging simultaneously), the wrong agent instance could receive a message.

  3. Session seeding/inheritance bug — PR #7084 already fixed one cross-thread contamination issue for DM threads (v0.9.0). A similar seeding bug may exist for guild threads where initial context leaks from a parent channel or adjacent thread.

  4. Context compression artifacts — If context compression merges or summarizes content from adjacent sessions in the state.db, stale context could resurface.

What needs investigation:

  • Add session-key logging to every inbound message processing step so we can trace exactly which session each message lands in
  • Check whether thread_sessions_per_user: false (the default) causes any session-key collision when multiple users message the same thread simultaneously
  • Verify that the Discord adapter never sets chat_id to the parent channel ID while thread_id points to the thread — this would create agent:main:discord:thread:PARENT_ID:THREAD_ID which is unique, but could the parent channel also generate agent:main:discord:group:PARENT_ID and somehow share state?

Environment:

  • Hermes v0.15.1
  • Discord plugin (platform.discord)
  • Gateway running via systemd (hermes-gateway.service)
  • Config: require_mention=false, auto_thread=true

Related:

  • PR #7084 (v0.9.0): "Fix: DM thread session seeding causing cross-thread contamination"
  • PR #7930 (v0.9.0): "Scope tool interrupt signal per-thread to prevent cross-session leaks"

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING