Skip to content

fix: populate currentThreadTs in threading tool context fallback (#52217)#52900

Merged
obviyus merged 1 commit intoopenclaw:mainfrom
Lukavyi:fix/topic-threadid-52217
Mar 24, 2026
Merged

fix: populate currentThreadTs in threading tool context fallback (#52217)#52900
obviyus merged 1 commit intoopenclaw:mainfrom
Lukavyi:fix/topic-threadid-52217

Conversation

@Lukavyi
Copy link
Copy Markdown
Contributor

@Lukavyi Lukavyi commented Mar 23, 2026

Problem

When a channel plugin lacks a custom buildToolContext in its threading adapter (e.g. Telegram), the fallback path in buildThreadingToolContext() did not include currentThreadTs from the inbound MessageThreadId.

This caused resolveTelegramAutoThreadId() to return undefined (because it requires both currentThreadTs AND currentChannelId), so any message(action=send) without an explicit threadId would route to the main chat instead of the originating DM topic.

Reproduction

  1. Open a DM topic with the bot (e.g. topic 1045687)
  2. Send a message in another topic or main chat (updates lastThreadId in session entry)
  3. Return to original topic - agent sends message(action=send) with buttons/media without explicit threadId
  4. Result: Message arrives in main chat instead of topic

Fix

Add currentThreadTs derived from sessionCtx.MessageThreadId to the fallback return in buildThreadingToolContext() when threading?.buildToolContext is absent.

This ensures resolveTelegramAutoThreadId() can auto-inject the correct message_thread_id for Telegram DM topics, matching the behavior that channels with custom buildToolContext already have.

Changes

  • src/auto-reply/reply/agent-runner-utils.ts: Add currentThreadTs to fallback path (3 lines)

Testing

  • Existing threading tests pass (message-action-runner.threading.test.ts, channel.test.ts)
  • Manually verified: message(action=send) without threadId now correctly routes to topic after the user interacts with main chat

Fixes #52217

@Lukavyi Lukavyi marked this pull request as ready for review March 23, 2026 14:01
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 23, 2026

Greptile Summary

This PR fixes a one-line routing bug in the threading tool context fallback path: when a channel plugin (e.g. Telegram) has no custom buildToolContext, currentThreadTs was missing from the returned object, so resolveTelegramAutoThreadId() could not identify the originating DM topic and messages fell back to the main chat.

  • Fix: Three lines added to buildThreadingToolContext() — derives threadTs from sessionCtx.MessageThreadId (matching the pattern already used in src/gateway/server-methods/agent.ts:688) and includes it as currentThreadTs in the fallback return.
  • Type-safe: currentThreadTs is a declared optional field on ChannelThreadingToolContext (string | undefined), so no type changes were needed.
  • Tested: A new assertion in agent-runner-utils.test.ts (line 194) directly covers the fix, and existing threading tests continue to pass.

Confidence Score: 5/5

  • This PR is safe to merge — it is a minimal, well-targeted fix with direct test coverage and no side-effects on other paths.
  • The change is 3 lines in a single file, follows an established pattern in the codebase, is covered by a new unit-test assertion, and leaves the existing buildToolContext-present path completely untouched.
  • No files require special attention.

Reviews (1): Last reviewed commit: "fix: populate currentThreadTs in threadi..." | Re-trigger Greptile

@obviyus obviyus self-assigned this Mar 24, 2026
…Telegram DM topics (openclaw#52217)

When a channel plugin lacks a custom buildToolContext (e.g. Telegram),
the fallback path in buildThreadingToolContext did not set currentThreadTs
from the inbound MessageThreadId. This caused resolveTelegramAutoThreadId
to return undefined, so message tool sends without explicit threadId
would route to the main chat instead of the originating DM topic.

Fixes openclaw#52217
@obviyus obviyus force-pushed the fix/topic-threadid-52217 branch from 90049d4 to c3da194 Compare March 24, 2026 02:56
@obviyus obviyus merged commit 7ffe7e4 into openclaw:main Mar 24, 2026
34 of 37 checks passed
@obviyus
Copy link
Copy Markdown
Contributor

obviyus commented Mar 24, 2026

Landed on main.

Thanks @Lukavyi.

@Lukavyi Lukavyi deleted the fix/topic-threadid-52217 branch March 24, 2026 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Subagent announce delivers to wrong Telegram DM topic (stale threadId)

2 participants