Repository navigation
Description
Summary
A Slack chat session in Trinity is currently scoped to team_id : sender_id : channel_id (SlackAdapter.get_session_identifier, slack_adapter.py:44). The thread (thread_ts) is not part of the key. As a result, every @mention and every thread reply from the same user in the same channel share one channel-wide conversation transcript. Two concurrent threads in one channel cross-contaminate each other's context, and a fresh @mention does not start a fresh conversation — it inherits the channel's last-10-turn transcript.
This issue scopes the session to the thread so that a new top-level @mention starts a fresh chat and each thread continues only its own context.
Context
Surfaced while reviewing how Slack messages reach the agent. The router (ChannelMessageRouter) builds the agent prompt via db.build_public_chat_context(session_id, ...), which replays the last 10 turns for session_id as a plain-text transcript — there is no persistent Claude Code session, so the channel-scoped key is the only thing defining "the conversation."
Concrete failure: a user with two open threads in one channel —
Thread A: "summarize the Q3 report"
Thread B: "what's the weather in Tokyo"
Thread A: "translate it to French" ← prompt contains the Tokyo exchange
The agent sees both threads interleaved chronologically, with no thread attribution.
Slack already gives us a stable per-thread id for free: a top-level @mention has no thread_ts, so _parse_mention sets thread_id = event.ts (a unique new value); every reply under it carries that same root thread_ts. So thread-scoping is mostly a key change.
Desired behavior
- A new top-level
@mention→ fresh conversation (empty context). - A reply within a thread (mention or not) → continues that thread's own context only.
- A re-
@mentioninside an existing thread → continues that thread (not a new chat). - DMs are unaffected — they have no threads and stay one continuous per-user conversation.
Acceptance Criteria
-
SlackAdapter.get_session_identifierscopes channel messages to the thread:team_id : channel_id : thread_id(dropsender_idfor channel threads so multi-participant threads share one context). - DMs keep the existing
team_id : sender_id : channel_idkey. - A new top-level
@mentionresolves to a brand-newsession_id→build_context_promptreturns empty history. - Two concurrent threads in the same channel resolve to distinct
session_ids — no transcript cross-talk. - A thread reply and a re-
@mentioninside the same thread resolve to that thread'ssession_id. - Unit test covering thread-vs-mention session isolation and DM continuity.
- Slack memory file / feature-flow note updated to record the session-granularity change.
Technical Notes
Primary change is contained to src/backend/adapters/slack_adapter.py:
def get_session_identifier(self, message: NormalizedMessage) -> str:
team_id = message.metadata.get("team_id", "unknown")
is_dm = message.metadata.get("is_dm", False)
if is_dm:
return f"{team_id}:{message.sender_id}:{message.channel_id}"
return f"{team_id}:{message.channel_id}:{message.thread_id}"- No DB schema change —
public_chat_sessionsis keyed by the opaque session identifier already. max_turns=10inbuild_context_promptnow caps history within a thread, which is the intended behavior.- Out of scope: passive "observe mode" (bot absorbing non-mention thread messages into context without replying). The bot currently responds to every reply in a bot-active thread (
_parse_thread_reply). Absorbing-without-replying is a separate, larger feature ([NO_REPLY]is the existing primitive). - Group chats (
is_group) are a separate code path that already uses fresh context — unaffected.
Activity
AndriiPasternak31 commentedon Jul 4, 2026
/claim
github-actions commentedon Jul 4, 2026
@AndriiPasternak31 This issue is already assigned to AndriiPasternak31. Use
/unclaimfirst if you want to take over.fix(slack): thread-scope chat session + per-speaker attribution + sen…
fix(channels): persist proactive messages to channel session history (#…
fix(channels): persist proactive group messages to channel session hi…
fix(whatsapp): allow Twilio's media CDN as a validated redirect target (