fix(slack): keep top-level channel turns in one session when replyToMode=off#32193
Conversation
🔒 Aisle Security AnalysisWe found 1 potential security issue(s) in this PR:
1. 🟡 Slack thread replies missing thread_ts can fall back to channel-scoped session when replyToMode=off (context bleed)
DescriptionIn This becomes security-relevant when Slack delivers a semantic thread reply that is missing
Impact:
Vulnerable code (new logic): const roomThreadId =
isThreadReply && threadTs
? threadTs
: replyToMode === "off"
? undefined
: threadContext.messageTs;
const canonicalThreadId = isRoomish
? roomThreadId
: isThreadReply
? threadTs
: autoThreadId;RecommendationHarden thread/session scoping for the known Slack edge case Options (pick one consistent with desired UX):
const maybeThreadReply = Boolean(message.parent_user_id) && !threadTs;
const roomThreadId =
isThreadReply && threadTs
? threadTs
: maybeThreadReply
? threadContext.messageTs // isolate instead of channel-scoping
: replyToMode === "off"
? undefined
: threadContext.messageTs;
In all cases, add a regression test that simulates a roomish message with Analyzed PR: #32193 at commit Last updated on: 2026-03-02T22:40:30Z |
Greptile SummaryThis PR fixes a bug where Slack top-level channel messages were always assigned per-message Key changes:
The Confidence Score: 5/5
Last reviewed commit: b0e4203 |
b0e4203 to
4ebed6d
Compare
|
Landed via temp rebase onto main.
Thanks @bmendonca3! |
|
Landed via temp rebase onto main.
Thanks @bmendonca3! |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4ebed6d9d7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| : replyToMode === "off" | ||
| ? undefined | ||
| : threadContext.messageTs; |
There was a problem hiding this comment.
Preserve context when off-mode turns move into threads
With replyToMode="off", this branch makes top-level room messages use the base channel session, while thread replies still use a :thread:<thread_ts> session. That means a common flow (top-level question → assistant reply → user replies in thread) now jumps to a fresh session and loses prior assistant/user context unless thread.inheritParent is enabled (it defaults to false in src/slack/monitor/provider.ts). Before this change, both turns shared the same thread key, so continuity was preserved.
Useful? React with 👍 / 👎.
Summary
Describe the problem and fix in 2–5 bullets:
:thread:<message.ts>session keys, so each new top-level turn created a fresh isolated session.replyToMode=off(default), users lose channel conversation continuity and the agent appears to "forget" context across normal channel chat.replyToMode=off; true thread replies remain thread-scoped.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
replyToMode=off: top-level channel/group messages now stay in one channel session instead of splitting per message.thread_tssession keys.replyToMode=allremains thread-scoped for top-level room turns.Security Impact (required)
Yes/No) NoYes/No) NoYes/No) NoYes/No) NoYes/No) NoYes, explain risk + mitigation:Repro + Verification
Environment
channels.slack.replyToMode: "off"Steps
tsvalues and nothread_ts.prepareSlackMessage) withreplyToMode=off.ctxPayload.SessionKeyvalues.Expected
:thread:<ts>suffix).Actual
:thread:<message.ts>session key.Evidence
Attach at least one:
Human Verification (required)
What you personally verified (not just CI), and how:
pnpm -s vitest run src/slack/monitor/message-handler/prepare.thread-session-key.test.tspnpm -s vitest run src/slack/monitor/message-handler/prepare.test.tspnpm -s vitest run src/slack/monitor.threading.missing-thread-ts.test.tspnpm -s vitest run src/slack/monitor/message-handler.test.tsthread_ts.replyToMode=allstill uses thread-scoped room turns.replyToMode=offremain non-thread-scoped.pnpm checkcurrently fails on upstreammaindue unrelated pre-existing TS error insrc/discord/monitor/agent-components.ts:873.Compatibility / Migration
Yes/No) YesYes/No) NoYes/No) NoFailure Recovery (if this breaks)
b0e42039d8c0b11d37d54d19aecf413398b4325d.src/slack/monitor/message-handler/prepare.tssrc/slack/monitor/message-handler/prepare.thread-session-key.test.tsreplyToMode=off.Risks and Mitigations
List only real risks for this PR. Add/remove entries as needed. If none, write
None.