Skip to content

[Slack] fix: preserve thread context for string threadId in queue drain#5245

Closed
cutsome wants to merge 1 commit intoopenclaw:mainfrom
cutsome:fix/slack-thread-queue-context
Closed

[Slack] fix: preserve thread context for string threadId in queue drain#5245
cutsome wants to merge 1 commit intoopenclaw:mainfrom
cutsome:fix/slack-thread-queue-context

Conversation

@cutsome
Copy link
Copy Markdown

@cutsome cutsome commented Jan 31, 2026

Summary

Fixes:

Queued messages in Slack threads were losing their thread context and being posted to the main channel instead of the thread.

Root Cause

In src/auto-reply/reply/queue/drain.ts, the originatingThreadId was only being handled when it was a number type (for Telegram topic IDs), but Slack uses string type thread IDs (e.g., "1769840211.421709").

Three locations were checking typeof threadId === "number", which caused Slack's string-based threadId to be ignored:

  1. Line 34: Early return condition
  2. Line 40: threadKey generation for cross-channel detection
  3. Line 74-76: originatingThreadId extraction from queued items

Changes

Changed all three checks to use != null instead of typeof === "number" to support both:

  • Number type: Telegram topic IDs
  • String type: Slack thread timestamps
- if (!channel && !to && !accountId && typeof threadId !== "number") {
+ if (!channel && !to && !accountId && threadId == null) {

- const threadKey = typeof threadId === "number" ? String(threadId) : "";
+ const threadKey = threadId != null ? String(threadId) : "";

- const originatingThreadId = items.find((i) => typeof i.originatingThreadId === "number")?.originatingThreadId;
+ const originatingThreadId = items.find((i) => i.originatingThreadId != null)?.originatingThreadId;
Testing
Manually tested by:

Sending multiple rapid messages in a Slack thread
Confirming all responses are now correctly posted to the thread
Verified both buggy behavior (before fix) and correct behavior (after fix)

Testing

Manually tested by:

  1. Sending multiple rapid messages in a Slack thread
  2. Confirming all responses are now correctly posted to the thread
  3. Verified both buggy behavior (before fix) and correct behavior (after fix)
image

Greptile Overview

Greptile Summary

This PR attempts to fix Slack thread context preservation by supporting both number (Telegram) and string (Slack) thread IDs in the queue drain logic. However, the fix is incomplete.

What was changed

  • Line 50: threadKey generation now uses threadId != null instead of typeof threadId === "number"
  • Lines 76-77: originatingThreadId extraction now uses i.originatingThreadId != null instead of typeof i.originatingThreadId === "number"

Critical issue found

The PR description claims three locations were updated, but line 43 was not changed. It still checks typeof threadId !== "number", which means:

  • When a Slack message with a string thread ID is queued, it would still hit the early return condition
  • The message would be marked as having no routing context (return {})
  • Cross-channel detection logic would not work correctly for Slack threads

Impact

The bug would likely still occur because the early return check on line 43 happens before the other two fixed checks, preventing Slack threads from being processed correctly.

Recommendation

Update line 43 to use threadId == null for consistency with the other two fixes.

Confidence Score: 2/5

  • This PR is not safe to merge due to an incomplete fix that would leave the original bug partially unresolved
  • The fix only addresses 2 of the 3 locations that need updating. The missed location (line 43) is an early return check that executes before the other two fixes, meaning Slack threads would still not be handled correctly. This is a critical logical error that prevents the PR from achieving its stated goal.
  • src/auto-reply/reply/queue/drain.ts needs the additional fix on line 43

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Jan 31, 2026

Additional Comments (1)

src/auto-reply/reply/queue/drain.ts
This line still checks typeof threadId !== "number", which means Slack threads (with string thread IDs) would still hit the early return and not be processed correctly. This is the third location mentioned in the PR description that needs fixing.

            if (!channel && !to && !accountId && threadId == null) {
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/auto-reply/reply/queue/drain.ts
Line: 43:43

Comment:
This line still checks `typeof threadId !== "number"`, which means Slack threads (with string thread IDs) would still hit the early return and not be processed correctly. This is the third location mentioned in the PR description that needs fixing.

```suggestion
            if (!channel && !to && !accountId && threadId == null) {
```

How can I resolve this? If you propose a fix, please make it concise.

@cutsome cutsome changed the title fix: preserve thread context for string threadId in queue drain [Slack] fix: preserve thread context for string threadId in queue drain Jan 31, 2026
@Lukavyi
Copy link
Copy Markdown
Contributor

Lukavyi commented Feb 7, 2026

Hey! I ran into the same issue and submitted #11194 which builds on this approach but adds empty-string edge case protection (threadId != null && threadId !== "" instead of just threadId == null). This addresses the concern Greptile raised in the review here — if any provider normalizes missing thread IDs to "", the != null check alone would treat it as a real thread. Also added 3 test cases for string thread_ts handling.

@sebslight
Copy link
Copy Markdown
Member

Closing as duplicate of #4749. If this is incorrect, comment and we can reopen.

@sebslight sebslight closed this Feb 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.

3 participants