Skip to content

fix(slack): use channel-level session key when replyToMode=off and message is top-level#31662

Closed
CZH-THU wants to merge 1 commit intoopenclaw:mainfrom
CZH-THU:fix/slack-channel-session-key-replytomode-off-31613
Closed

fix(slack): use channel-level session key when replyToMode=off and message is top-level#31662
CZH-THU wants to merge 1 commit intoopenclaw:mainfrom
CZH-THU:fix/slack-channel-session-key-replytomode-off-31613

Conversation

@CZH-THU
Copy link

@CZH-THU CZH-THU commented Mar 2, 2026

Problem

After upgrading from 2026.2.26 to 2026.3.1, every message in a Slack channel creates a separate agent context when replyToMode="off" and messages are top-level (not in threads).

Previously, chatting with OpenClaw in a Slack channel worked like a normal chatbot — each message in the channel shared the same agent session, so the agent remembered prior context. Now each message is completely isolated with no memory of previous messages.

Root Cause

Commit 11d34700c changed the session key to always include thread-level sessions for channels:

  • Old: agent:main:slack:channel:${channelId}
  • New: agent:main:slack:channel:${channelId}:thread:${messageTs}

For users who chat in channels without threads and replyToMode="off", each top-level message gets its own ts, so every message creates a brand new isolated session.

Solution

Modified the session key resolution logic to:

  • Use thread-level sessions only when:
    1. Message is in a thread (has thread_ts), OR
    2. replyToMode is "all" or "first" (threading enabled)
  • Otherwise (replyToMode="off" and top-level), use channel-level session key
  • Thread replies always use thread-level session key regardless of replyToMode

This restores the behavior from v2026.2.26 where channel-level messages shared the same agent context when replyToMode="off".

Testing

Added test cases to verify:

  • Top-level messages with replyToMode="off" use channel-level session key
  • Thread replies with replyToMode="off" still use thread-level session key
  • Top-level messages with replyToMode="all" or "first" use thread-level session key

Fixes #31613

…ssage is top-level

When replyToMode is off and a message is top-level (no thread_ts), each message was creating a separate agent context because the session key included 🧵message.ts suffix. This broke conversation continuity for users who chat in channels without threads.

Fix: For channels/groups, use thread-level sessions only when message is in a thread (has thread_ts) OR replyToMode is all or first. Otherwise (replyToMode=off and top-level), use channel-level session key. Thread replies always use thread-level session key regardless of replyToMode.

Fixes openclaw#31613
@openclaw-barnacle openclaw-barnacle bot added channel: slack Channel integration: slack size: S labels Mar 2, 2026
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 2, 2026

Greptile Summary

This PR fixes a regression introduced in v2026.3.1 where every message in a Slack channel with replyToMode="off" created a separate isolated agent context, breaking conversation continuity.

Key Changes:

  • Modified session key logic in prepare.ts to conditionally apply thread-level sessions based on replyToMode setting and message context
  • For channels/groups with replyToMode="off" and top-level messages, now uses channel-level session key instead of thread-level
  • Thread replies still maintain isolated sessions regardless of replyToMode to prevent cross-thread context bleed
  • When replyToMode is "all" or "first", continues using thread-level sessions for all messages

Test Coverage:
Added comprehensive test cases verifying all scenarios:

  • Top-level messages with different replyToMode settings ("off", "all", "first")
  • Thread replies with replyToMode="off" to ensure they still get isolated sessions
  • Updated existing test to explicitly set replyToMode="all" for clarity

Impact:
Restores the v2026.2.26 behavior where channel-level messages shared the same agent context when replyToMode="off", while maintaining the fix from commit 11d34700c that prevents context mixing between different threads in the same channel.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix is surgical and well-tested. It correctly restores the expected behavior for replyToMode="off" without reintroducing the cross-thread context mixing issue. The logic is sound, test coverage is comprehensive (6 test cases covering all scenarios), and the change is limited to session key resolution logic with no side effects.
  • No files require special attention

Last reviewed commit: e220965

@CZH-THU CZH-THU closed this Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: slack Channel integration: slack size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Slack] Each message creates separate agent context (v2026.3.1)

2 participants