#19027: fix(feishu): keep chunked messages in topic/thread context
channel: feishu
size: XS
Cluster:
Feishu Enhancements and Fixes
# fix(feishu): keep message chunks in topic/thread context
## Summary
Fixes an issue where long message responses in Feishu topics/threads would have
their subsequent chunks sent to the main chat instead of staying within the
topic context.
## Problem
When responding to messages in a Feishu topic (thread), if the response is long
and needs to be chunked, only the first chunk stays in the topic. Subsequent
chunks appear in the main group chat, breaking the conversation flow.
### Root Cause
In `reply-dispatcher.ts`, when sending chunked messages, all chunks use the same
`replyToMessageId`. This causes Feishu to interpret subsequent chunks as replies
to the first chunk rather than part of the same topic thread.
**Code location:** `extensions/feishu/src/reply-dispatcher.ts` (lines ~144-154)
```typescript
// BEFORE (problematic)
for (const chunk of core.channel.text.chunkTextWithMode(text, textChunkLimit, chunkMode)) {
await sendMarkdownCardFeishu({
cfg,
to: chatId,
text: chunk,
replyToMessageId, // ❌ Used for ALL chunks
mentions: first ? mentionTargets : undefined,
});
first = false;
}
```
## Solution
Only use `replyToMessageId` for the **first chunk**. Subsequent chunks should
omit this parameter to stay within the topic/thread context.
```typescript
// AFTER (fixed)
for (const chunk of core.channel.text.chunkTextWithMode(text, textChunkLimit, chunkMode)) {
await sendMarkdownCardFeishu({
cfg,
to: chatId,
text: chunk,
replyToMessageId: first ? replyToMessageId : undefined, // ✅ Only first chunk
mentions: first ? mentionTargets : undefined,
});
first = false;
}
```
### Technical Details
- **File:** `extensions/feishu/src/reply-dispatcher.ts`
- **Function:** `createFeishuReplyDispatcher` → `deliver` callback
- **Applies to:** Both card messages (`sendMarkdownCardFeishu`) and text messages (`sendMessageFeishu`)
## Changes
- Modified `reply-dispatcher.ts` to conditionally set `replyToMessageId` based on
the `first` flag in both card and text message sending paths
## Testing
- [ ] Long messages in topics stay within the topic context
- [ ] First chunk correctly replies to the original message
- [ ] Subsequent chunks appear in sequence within the topic
- [ ] Non-topic messages continue to work as expected
## Related
- Feishu API behavior: Messages with `replyToMessageId` are treated as replies,
which in topic contexts can cause them to appear in the main chat
- This fix ensures chunked messages behave as a single logical response
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Fixes chunked message behavior in Feishu topics/threads by conditionally applying `replyToMessageId` only to the first chunk. Previously, all chunks used `replyToMessageId`, causing subsequent chunks to appear in the main chat rather than staying within the topic context. The fix applies to both card messages (`sendMarkdownCardFeishu`) and text messages (`sendMessageFeishu`) in `reply-dispatcher.ts:173` and `reply-dispatcher.ts:190`.
- Applied `replyToMessageId: first ? replyToMessageId : undefined` pattern to both message sending paths
- Maintains consistency with existing `mentions` field which already uses this pattern
- Preserves first chunk as a reply to maintain conversation context
- Subsequent chunks omit `replyToMessageId` to remain in the same thread
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The change is minimal, well-understood, and follows existing patterns in the codebase. The fix mirrors the existing pattern used for the `mentions` field, applies consistently to both message sending paths, and directly addresses the described bug without introducing new logic or side effects
- No files require special attention
<sub>Last reviewed commit: 478bbed</sub>
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#18529: feat(feishu): add parentId and rootId to inbound context for quote/...
by qiangu · 2026-02-16
82.5%
#13211: feat(feishu): skip reply-to in DM conversations
by Vincentwei1021 · 2026-02-10
82.1%
#19793: feat(feishu): reply-in-thread, parallel group sessions, and fire-an...
by yinsn · 2026-02-18
79.8%
#16123: Feishu card default
by QiuYi111 · 2026-02-14
79.0%
#22675: feishu: move message dedup to just before dispatch
by zijiegeng · 2026-02-21
78.7%
#9253: Fix: Feishu chat ID mismatch causing session context confusion
by vishaltandale00 · 2026-02-05
77.1%
#10309: fix: use group ID for peer.id in Feishu group messages
by ParsifalC · 2026-02-06
76.8%
#9756: fix(feishu): prevent message redelivery during long AI generation
by cszhouwei · 2026-02-05
76.3%
#20744: fix(feishu): reply under topic instead of creating new topic in top...
by paceyw · 2026-02-19
75.7%
#13970: feat: add Feishu topic auto-threading for message tool
by 4ier · 2026-02-11
75.7%