Skip to content

fix(slack): read thread_id from metadata for in-thread routing#924

Closed
boyleryan wants to merge 1 commit intoNousResearch:mainfrom
boyleryan:fix/slack-thread-metadata-key-public
Closed

fix(slack): read thread_id from metadata for in-thread routing#924
boyleryan wants to merge 1 commit intoNousResearch:mainfrom
boyleryan:fix/slack-thread-metadata-key-public

Conversation

@boyleryan
Copy link

Summary

Slack thread replies — progress messages, typing indicators, session hygiene
warnings, and other auxiliary sends from _process_message_background() — land
in the top-level DM window instead of the conversation thread.

Root Cause

The base adapter and gateway construct thread metadata with a thread_id key:

  • gateway/platforms/base.py:691: _thread_metadata = {"thread_id": event.source.thread_id}
  • gateway/run.py: _progress_metadata = {"thread_id": source.thread_id}

But SlackAdapter.send() only checks for thread_ts:

  • gateway/platforms/slack.py:163: metadata.get("thread_ts")

The value is correct — it's the original Slack thread_ts, stored as thread_id
in MessageSource at slack.py:530. The key name just doesn't match what
send() looks for.

The Telegram adapter already handles this correctly — telegram.py:218 reads
metadata.get("thread_id").

Changes

  • gateway/platforms/slack.py: Accept both thread_ts and thread_id from
    metadata in send(), preferring thread_ts when both are present. This aligns
    with the Telegram adapter's approach of reading the canonical thread_id key.
  • tests/gateway/test_slack.py: Add TestSendThreading class with 4 tests:
    thread_id-only metadata, thread_ts-only metadata, both-keys precedence,
    and reply_to precedence over metadata.

How to Test

  1. Connect a Slack workspace
  2. Start a threaded conversation with the bot
  3. Send a message that triggers tool use (e.g., web search)
  4. Verify progress messages appear in the thread, not the main DM window

Automated: pytest tests/gateway/test_slack.py::TestSendThreading -v

Platforms Tested

  • Slack (primary fix, live-verified)

Related

Known Related Issue (not addressed here)

The Slack media methods (send_image, send_document, send_video,
send_voice, send_image_file) accept **kwargs from the base adapter but
don't extract metadata for threading. Media sent during threaded conversations
may land outside the thread. This is a separate issue affecting media method
implementations across adapters and should be addressed in a follow-up.

@teknium1
Copy link
Contributor

Superseded by PR #1103 (merged), which addressed the same thread_id/thread_ts key mismatch fix plus additional threading improvements.

@teknium1 teknium1 closed this Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants