Skip to content

fix(slack): preserve thread_ts in queue drain and deliveryContext - #11934

Closed
sandieman2 wants to merge 1 commit into
openclaw:mainfrom
sandieman2:fix/slack-thread-context-delivery
Closed

sandieman2 wants to merge 1 commit into
openclaw:mainfrom
sandieman2:fix/slack-thread-context-delivery

Conversation

@sandieman2

@sandieman2 sandieman2 commented Feb 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Two related fixes for Slack thread reply routing that cause replies meant for threads to leak to the main channel.

Bug 1: Queue drain drops string thread_ts (#11195)

typeof threadId === "number" in drain.ts only matches Telegram numeric topic IDs. Slack thread_ts is a string like "1770474140.187459" which fails the check, causing threadKey to become empty. Queued replies then lose their thread context and land in the main channel.

Fix: Changed to threadId != null && threadId !== "" to accept both number and string thread IDs. Applied to all 3 occurrences in drain.ts:

  • Cross-channel detection guard
  • Thread key building for collect grouping
  • Collected originatingThreadId extraction

Bug 2: DM deliveryContext missing thread_ts (#10837)

updateLastRoute calls for Slack DMs in both prepare.ts and dispatch.ts built the deliveryContext without threadId, so the session's delivery context never included thread_ts for DM threads.

Fix: Added threadId from threadContext.messageThreadId / ctxPayload.MessageThreadId to both updateLastRoute call sites.

Files Changed

File Change
src/auto-reply/reply/queue/drain.ts Accept string thread IDs (3 locations)
src/slack/monitor/message-handler/prepare.ts Include threadId in DM updateLastRoute
src/slack/monitor/message-handler/dispatch.ts Include threadId in DM updateLastRoute
src/auto-reply/reply/queue.collect-routing.test.ts 3 new test cases

Tests

3 new cases in queue.collect-routing.test.ts:

  • ✅ Collects messages with matching string thread_ts (same Slack thread)
  • ✅ Separates messages with different string thread_ts (different threads)
  • ✅ Treats empty string threadId same as absent
pnpm test src/auto-reply/reply/queue.collect-routing.test.ts
 ✓ 9 tests passed

Prior Art

Behavior Changes

  • String thread IDs (Slack thread_ts) now preserved during queue drain
  • Empty string "" treated as absent (prevents spurious thread grouping)
  • DM sessions now include thread_ts in deliveryContext when applicable
  • No change for numeric thread IDs (Telegram)

Closes #10837, closes #11195

Greptile Overview

Greptile Summary

This PR fixes Slack thread reply routing in two places:

  • In the followup queue drain logic, thread IDs are now treated as present when they are non-null and non-empty, so Slack thread_ts (string) is preserved when building the collect-grouping key and when extracting originatingThreadId for the collected run.
  • For Slack DMs, both prepareSlackMessage and dispatchPreparedSlackMessage now include threadId in the updateLastRoute deliveryContext so DM thread sessions retain thread_ts.

Tests were expanded in queue.collect-routing.test.ts to cover collecting/separating runs by string thread IDs and treating empty string as absent.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk.
  • Changes are narrowly scoped to routing keys and session deliveryContext, align with Slack thread_ts being a string, and are covered by targeted unit tests for collect routing behavior (including empty-string edge case).
  • No files require special attention

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

Two related fixes for Slack thread reply routing:

1. Queue drain drops string thread_ts (openclaw#11195)
   - `typeof threadId === "number"` in drain.ts only matches Telegram numeric
     topic IDs. Slack thread_ts is a string like "1770474140.187459" which
     fails the check, causing threadKey to become empty.
   - Changed to `threadId != null && threadId !== ""` to accept both number
     and string thread IDs.
   - Applies to all 3 occurrences in drain.ts: cross-channel detection,
     thread key building, and collected originatingThreadId extraction.

2. DM deliveryContext missing thread_ts (openclaw#10837)
   - updateLastRoute calls for Slack DMs in both prepare.ts and dispatch.ts
     built deliveryContext without threadId, so the session's delivery context
     never included thread_ts for DM threads.
   - Added threadId from threadContext.messageThreadId / ctxPayload.MessageThreadId
     to both updateLastRoute call sites.

Tests: 3 new cases in queue.collect-routing.test.ts
- Collects messages with matching string thread_ts (same Slack thread)
- Separates messages with different string thread_ts (different threads)
- Treats empty string threadId same as absent

Closes openclaw#10837, closes openclaw#11195
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@vincentkoc

Copy link
Copy Markdown
Member

Thanks for the detailed Slack thread-context fix.

I’m closing this in favor of #23804, which rebases this change cleanly on current main, keeps the queue/drain + DM deliveryContext.threadId behavior, and adds the Unreleased changelog entry.

Your contribution is preserved in the replacement branch. If any behavior drifted, point me to it and I can reopen immediately.

@vincentkoc vincentkoc closed this Feb 22, 2026
@vincentkoc vincentkoc added dedupe:child Duplicate issue/PR child in dedupe cluster close:duplicate Closed as duplicate labels Feb 22, 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 close:duplicate Closed as duplicate dedupe:child Duplicate issue/PR child in dedupe cluster stale Marked as stale due to inactivity

Projects

None yet

2 participants