Skip to content

fix(gateway/slack): inject thread parent message into conversation context - #2952

Closed
jneeee wants to merge 1 commit into
NousResearch:mainfrom
jneeee:fix/slack-thread-parent-message-context
Closed

fix(gateway/slack): inject thread parent message into conversation context#2952
jneeee wants to merge 1 commit into
NousResearch:mainfrom
jneeee:fix/slack-thread-parent-message-context

Conversation

@jneeee

@jneeee jneeee commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

Summary

When Hermes receives a message inside a Slack thread, the parent (root) message that started the thread was absent from the conversation context. Only thread reply messages were visible to the agent.

Root Cause

_handle_slack_message only processes the current event payload. There was no code to fetch the thread root message via the Slack API.

Fix

Call conversations.replies with limit=1 when processing a thread reply (thread_ts present and != the message's own ts), fetch the root message, and prepend it to the agent's context as [Thread started with]: ....

Edge cases handled:

  • Skip injection if the root message was posted by the bot itself (avoids recursive context loops)
  • Silently ignore API errors via debug log — handler never crashes due to a missing parent
  • No injection for top-level messages (ts == thread_ts) or plain DMs with no thread_ts

Changes

  • gateway/platforms/slack.py: new _fetch_thread_parent() method + injection logic in _handle_slack_message
  • tests/gateway/test_slack.py: new TestThreadParentInjection class with 5 tests

Tests

Test Covers
test_parent_message_prepended_to_text Happy path — parent injected
test_parent_fetch_failure_does_not_crash API error → handler proceeds normally
test_bot_parent_message_not_injected Bot-authored root message skipped
test_top_level_message_not_fetching_parent ts == thread_ts → no API call
test_no_thread_ts_skips_fetch Plain DM → no API call

Fixes #2950
Related to #1953

…ntext

When Hermes receives a message inside a Slack thread, the parent (root)
message that started the thread was absent from the conversation context.
Only thread reply messages were visible to the agent.

Fix: call conversations.replies with limit=1 when processing a thread reply
(thread_ts present and different from the message's own ts) to fetch the
root message. Prepend it to the message text as '[Thread started with]: ...'.

- Skip injection if the root message was posted by the bot itself
- Silently ignore API errors (debug log only) to avoid crashing the handler
- No injection for top-level messages or plain DMs (ts == thread_ts or no thread_ts)

Fixes NousResearch#2950
Related to NousResearch#1953
@jneeee

jneeee commented Mar 30, 2026

Copy link
Copy Markdown
Contributor Author

Merged in #2956

Closed

@jneeee jneeee closed this Mar 30, 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.

[Bug]: Slack thread parent message missing from conversation context

1 participant