← Back to PRs

#13970: feat: add Feishu topic auto-threading for message tool

by 4ier open 2026-02-11 08:32 View on GitHub →
agents stale
## Problem When the agent uses the `message` tool from within a Feishu topic session (topic groups with `topicSessionMode: "enabled"`), the `threadId` (topic `root_id`) is not propagated. This causes Feishu to create a new topic for each message sent via the tool, instead of keeping messages within the existing topic thread. This results in a snowball effect: each new topic creates a new session → agent sends another message via `message` tool → another new topic → etc. Agent direct replies work correctly because they go through the session's `deliveryContext` which includes `threadId`. The bug is specific to the `message` tool's outbound path. ## Root Cause The `message` tool's `ChannelThreadingToolContext` only carries `currentThreadTs` (designed for Slack), but Feishu topics use message-ID-based threading (`root_id`), not timestamps. The auto-threading pattern exists for Slack (`resolveSlackAutoThreadId`) and Telegram (`resolveTelegramAutoThreadId`) but was missing for Feishu. Additionally, the `sendMessage` fallback path in `outbound-send-service.ts` → `message.ts` → `deliverOutboundPayloads` didn't forward `threadId` at all, so even if the auto-threading resolved a threadId, it would be lost downstream. ## Changes | File | Change | |------|--------| | `types.core.ts` | Add `currentThreadId` to `ChannelThreadingToolContext` | | `openclaw-tools.ts` | Pass `agentThreadId` to `createMessageTool` as `currentThreadId` | | `message-tool.ts` | Accept `currentThreadId` option, forward in `toolContext` | | `message-action-runner.ts` | Add `resolveFeishuAutoThreadId()` following the Slack/Telegram pattern | | `outbound-send-service.ts` | Forward `threadId` from `params` to `sendMessage` | | `message.ts` | Accept `threadId` param, pass to `deliverOutboundPayloads` | ## How It Works The fix mirrors the existing Slack and Telegram auto-threading patterns: 1. Session's `MessageThreadId` flows into `agentThreadId` → `currentThreadId` in toolContext 2. When the `message` tool is invoked targeting the same group, `resolveFeishuAutoThreadId()` detects matching targets and injects the threadId 3. The threadId is written back into params and forwarded through the full send pipeline 4. The Feishu outbound adapter uses `threadId` as `replyToMessageId` in the Feishu API call, keeping the message in the correct topic Closes #13880 <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR implements Feishu topic auto-threading to prevent the message tool from creating new topics instead of replying within existing threads. The approach correctly mirrors the Slack and Telegram auto-threading patterns in `message-action-runner.ts`, but the implementation is incomplete and won't work without critical missing pieces. **Critical Issues Found:** 1. **Outbound adapter doesn't forward `threadId`** - The Feishu outbound adapter (`extensions/feishu/src/outbound.ts`) receives `threadId` via `ChannelOutboundContext` but doesn't pass it to `sendMessageFeishu()` or `sendMediaFeishu()` as `replyToMessageId`. This breaks the entire threading flow. 2. **Inbound context missing `MessageThreadId`** - The Feishu bot (`extensions/feishu/src/bot.ts`) doesn't set `MessageThreadId` in `finalizeInboundContext()`, so the session won't capture the topic `root_id`. 3. **Missing threading adapter** - Feishu has no `threading.buildToolContext` adapter in the channel plugin, so even if `MessageThreadId` were set, it wouldn't flow into `agentThreadId` → `currentThreadId` → tool context. **How the fix should work:** - Session's `MessageThreadId` (topic `root_id`) → threading adapter → `agentThreadId` → `currentThreadId` in tool context - When message tool targets same group, `resolveFeishuAutoThreadId()` detects match and injects threadId - threadId flows through `outbound-send-service.ts` → `message.ts` → `deliverOutboundPayloads` → outbound adapter - Outbound adapter passes threadId as `replyToMessageId` to Feishu API **What's implemented correctly:** - Core auto-threading logic in `message-action-runner.ts` follows the established pattern - Type additions to `ChannelThreadingToolContext` and parameter forwarding through `openclaw-tools.ts` → `message-tool.ts` - `outbound-send-service.ts` and `message.ts` correctly forward threadId parameter The PR description is accurate about the problem and solution, but the implementation is missing the Feishu-specific integration points needed to make it work. <h3>Confidence Score: 1/5</h3> - This PR has critical implementation gaps that will prevent the feature from working - Three critical bugs prevent the auto-threading feature from functioning: (1) outbound adapter doesn't forward threadId to send functions, (2) inbound context doesn't set MessageThreadId, and (3) missing threading adapter prevents threadId from flowing into tool context. The core logic is correct but incomplete. - `extensions/feishu/src/outbound.ts` (must forward threadId), `extensions/feishu/src/bot.ts` (must set MessageThreadId), `extensions/feishu/src/channel.ts` (must add threading adapter) <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs