fix(slack): session-based sticky routing + context bloat fixes#29067
fix(slack): session-based sticky routing + context bloat fixes#29067sourman wants to merge 4 commits intoopenclaw:mainfrom
Conversation
ccc3ab7 to
cab8606
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cab8606c31
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Greptile SummaryThis PR successfully implements session-based sticky routing for Slack threads and optimizes thread context loading to reduce token bloat. The core changes are well-architected: (1) thread-scoped session checks detect prior bot participation without requiring re-@mention, (2) Slack API fallback with LRU caching handles edge cases where sessions don't yet exist, and (3) thread history is only fetched for new sessions, preventing redundant context in ongoing conversations. The implementation correctly handles the key edge case mentioned in the PR description - preventing base channel sessions from causing false positives in thread mention gating. Test coverage is comprehensive, including scenarios for new vs existing sessions, API-based participation detection, and thread-scoped gating. One minor limitation: the Slack API participation check examines up to 800 messages per thread (4 pages × 200 limit). In extremely long threads beyond this range, bot participation might not be detected and users would need to re-@mention. This is a reasonable trade-off to prevent excessive API calls and is unlikely to affect most real-world usage. Confidence Score: 4/5
Last reviewed commit: 5012366 |
cab8606 to
81a882c
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 81a882c17e
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
81a882c to
87027c3
Compare
Only fetch thread history for new sessions. Skip for existing sessions since the transcript already has full conversation. Fixes token bloat where thread history was included on every message.
Once bot replies in a thread, follow-up messages without @mention reach
the bot via implicit mention.
Uses session existence check (thread session OR base channel session)
to detect bot participation. Base session check handles routing
discontinuity where first reply goes to channel session internally
but displays as thread message in Slack UI.
Sender preamble: "Slack message detected on thread: {name} speaking"
helps LLM understand multi-human thread context.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
87027c3 to
5012366
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5012366473
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@iamfuntime would you please take a look and test it to see if it works for you? this is a little bit more reliable than the in memory approach in #16223 |
|
Thanks for the contribution and the detailed work here. Closing this PR for now because it is superseded by a tighter Workstream 3 path that we are landing to avoid overlapping Slack threading/session changes in parallel. What we are keeping:
If you want, I can cross-reference any specific test or edge case from this PR into the active salvage PRs so your coverage is preserved. |
|
Thanks @Takhoffman yeah I feel this piece needs a refactor. What exactly do you mean by workstream 3. If you can please do grab the context bloat part of this pull request as the current implementation on threads includes a history injection that blows up the agent session on the slack thread |
requireMention: true, follow-up replies in threads are dropped when users don't re-@mention the bot; even after the bot has already participated. Additionally, thread history was being fetched on every message, causing significant token bloat. See fix(slack): reduce token bloat by skipping thread context on existing sessions #27609 for bloat exampleChange Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
Once the bot replies in a Slack thread, subsequent messages from any user (without @mention) will be routed to the bot. Thread context is no longer redundantly included in messages (reduces token usage).
Config changes: None (zero new config options)
Security Impact (required)
No)No)Yes)No)No)Yes, explain risk + mitigation: We now check using the slack API if the bot account replied to a thread as a fallback if we do not find an agent session matching the thread on which a new message arrived. This adds a few API calls to slackRepro + Verification
Environment
channels.slack.requireMention: trueSteps
Expected
Bot receives and responds to the follow-up message (session-based check passes)
Actual
Before fix: Message was silently dropped (only
parent_user_id === botUserIdwas checked)After fix: Bot receives message (session exists from previous reply)
Evidence
Human Verification (required)
Compatibility / Migration
Yes)No)No)Failure Recovery (if this breaks)
src/slack/monitor/message-handler/prepare.tsRisks and Mitigations
This whole part of the codebase needs a real hard look. Why even bother with a slack channel session if the replyToMode is
all? the dichotomy between openclaw sessions and how they are presented Slack threads makes it hard for Devs and agents to work in this piece and may be unnecessary. We might consider to get rid of the channel session entirely and spawn per response sessions untilreplyToModeisoff(no threading)