#20744: fix(feishu): reply under topic instead of creating new topic in topic groups [Enhanced]
channel: discord
agents
channel: feishu
size: S
Cluster:
Feishu Enhancements and Fixes
# PR Description
## Summary
Fixes an issue where bot replies in Feishu/Lark topic groups create new topics instead of appearing as replies under the original topic.
## Problem
In Feishu topic groups (话题群), when users mention the bot within an existing topic thread, the bot's response was created as a new standalone topic rather than appearing as a comment under the original topic where it was mentioned.
### Root Cause
The bot used `ctx.messageId` as the `replyToMessageId` parameter when calling the Feishu message reply API. In topic groups, messages have a `root_id` field that identifies the root message of the topic thread. To reply within a topic, the API call must target the root message ID, not the specific message that triggered the response.
## Solution
Use `ctx.rootId ?? ctx.messageId` instead of just `ctx.messageId` when setting `replyToMessageId`. This ensures:
- When in a topic (`rootId` exists): Reply targets the topic root → appears under the topic
- When not in a topic: Falls back to normal message reply behavior
## Changes
### Core Fix (Original)
```diff
// extensions/feishu/src/bot.ts
- replyToMessageId: ctx.messageId,
+ replyToMessageId: ctx.rootId ?? ctx.messageId,
```
Applied to both:
1. Normal reply dispatcher (line ~935)
2. Permission error notification dispatcher (line ~850)
### Enhanced Features (Added)
- **Debug Logging**: Added `rootId` and `msgId` to message reception logs for easier debugging
- **Context Enhancement**: Added `MessageThreadId` to the context payload for better thread tracking
```diff
// extensions/feishu/src/bot.ts
- `feishu[${account.accountId}]: received message from ${ctx.senderOpenId} in ${ctx.chatId} (${ctx.chatType})`
+ `feishu[${account.accountId}]: received message from ${ctx.senderOpenId} in ${ctx.chatId} (${ctx.chatType}) rootId=${ctx.rootId ?? "null"} msgId=${ctx.messageId}`
// In context payload
MessageSid: ctx.messageId,
+ MessageThreadId: ctx.rootId ?? undefined,
```
### Streaming Card Support
Updated `FeishuStreamingSession` to support reply mode:
- Constructor accepts `replyToMessageId` parameter
- Streaming cards now use `message.reply()` API when replying to topics
- Falls back to `message.create()` for non-topic messages
## Testing
- [x] Tested in Feishu topic group: Verified bot replies appear under the original topic
- [x] Verified normal group behavior remains unchanged
- [x] No regression in DM handling
- [x] Debug logs correctly show rootId/msgId values
- [x] Streaming card mode works correctly with topic replies
## Related
- Fixes: Topic group replies creating new topics instead of replying under original topic
- Enhanced with: Debug logging and MessageThreadId context for better observability
## Local Deployment Status
✅ **Successfully deployed and tested** on production OpenClaw instance (v2026.2.17)
- Running in production since 2026-02-19
- Verified in actual Feishu topic groups
- No issues reported
## Checklist
- [x] Code follows project style guidelines
- [x] Changes are minimal and focused
- [x] No sensitive information exposed
- [x] Tested locally
- [x] Enhanced with debugging capabilities
- [x] Production-ready
---
**Example Behavior:**
Before fix:
```
User: @Bot (in Topic A) → "Hello"
Bot: (creates new Topic B) → "Hi there!"
```
After fix:
```
User: @Bot (in Topic A) → "Hello"
Bot: (replies under Topic A) → "Hi there!"
```
**Debug Log Example:**
```
feishu[main]: received message from ou_xxx in chat:oc_xxx (group) rootId=om_x100b565xxx msgId=om_x100b5648xxx
```
Most Similar PRs
#18529: feat(feishu): add parentId and rootId to inbound context for quote/...
by qiangu · 2026-02-16
77.9%
#19793: feat(feishu): reply-in-thread, parallel group sessions, and fire-an...
by yinsn · 2026-02-18
77.1%
#13211: feat(feishu): skip reply-to in DM conversations
by Vincentwei1021 · 2026-02-10
75.7%
#19027: fix(feishu): keep chunked messages in topic/thread context
by qiangu · 2026-02-17
75.7%
#9253: Fix: Feishu chat ID mismatch causing session context confusion
by vishaltandale00 · 2026-02-05
72.3%
#10309: fix: use group ID for peer.id in Feishu group messages
by ParsifalC · 2026-02-06
70.8%
#8975: feat(feishu): comprehensive enhancements for Feishu channel
by jiulingyun · 2026-02-04
69.7%
#21484: fix(feishu): scope message deduplication by accountId to support mu...
by guanyu-zhang · 2026-02-20
68.9%
#19274: feat(mattermost): enable threaded replies in channels
by rockinyp · 2026-02-17
67.6%
#13970: feat: add Feishu topic auto-threading for message tool
by 4ier · 2026-02-11
67.4%