#9253: Fix: Feishu chat ID mismatch causing session context confusion
stale
Cluster:
Feishu Messaging Fixes
## Summary
Fixes #9246 - Feishu chat ID mismatch causing session context confusion across different groups.
## Root Cause
The `/whoami` command was incorrectly displaying `ctx.From` (sender's open_id) instead of `ctx.To` (chat_id) for group chats. This caused the agent to report wrong group IDs when asked, leading to session context confusion where messages from one group would reference context from another group.
## The Bug
In `src/auto-reply/reply/commands-info.ts` line 194-196:
```typescript
if (params.ctx.ChatType === "group" && params.ctx.From) {
lines.push(`Chat: ${params.ctx.From}`); // ❌ Wrong - shows sender ID
}
```
## The Fix
```typescript
if (params.ctx.ChatType === "group" && params.ctx.To) {
lines.push(`Chat: ${params.ctx.To}`); // ✅ Correct - shows chat ID
}
```
## Impact
✅ Fixes session context confusion in Feishu groups
✅ Agent now correctly identifies which group it's in
✅ `/whoami` command displays correct chat_id (oc_xxx) instead of sender's open_id (ou_xxx)
✅ Prevents cross-group context bleeding
## Testing
Manual testing recommended:
1. Create multiple Feishu groups with the bot
2. Send messages to each group
3. Verify `/whoami` shows correct chat_id for each group
4. Verify agent responses don't reference context from other groups
## Changed Files
- `src/auto-reply/reply/commands-info.ts` (2 lines changed)
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates the `/whoami` output for Feishu group chats to display the chat identifier from `ctx.To` (chat_id) instead of `ctx.From` (sender open_id). This aligns the identity report with how session routing/state tracking elsewhere treats `ctx.To` as the conversation target, and prevents operators from copying the wrong ID when diagnosing or scoping group sessions.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk.
- Change is isolated to `/whoami` display formatting and matches existing session routing conventions that prioritize `ctx.To` for conversation targeting; no behavioral side-effects beyond corrected diagnostics output were found.
- No files require special attention
<!-- greptile_other_comments_section -->
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#10309: fix: use group ID for peer.id in Feishu group messages
by ParsifalC · 2026-02-06
85.7%
#13211: feat(feishu): skip reply-to in DM conversations
by Vincentwei1021 · 2026-02-10
78.4%
#10407: fix(feishu): Remove incorrect oc_ prefix assumption in resolveFeish...
by Bermudarat · 2026-02-06
78.3%
#18529: feat(feishu): add parentId and rootId to inbound context for quote/...
by qiangu · 2026-02-16
78.3%
#19793: feat(feishu): reply-in-thread, parallel group sessions, and fire-an...
by yinsn · 2026-02-18
78.0%
#19027: fix(feishu): keep chunked messages in topic/thread context
by qiangu · 2026-02-17
77.1%
#3182: fix(gateway): use canonical session key in chat.send
by chrisherold · 2026-01-28
75.8%
#21484: fix(feishu): scope message deduplication by accountId to support mu...
by guanyu-zhang · 2026-02-20
75.7%
#13761: fix(feishu): silently degrade when contact permission is missing
by echoVic · 2026-02-11
74.5%
#15982: fix: pass agentId to resolveSessionFilePath in reply flow (NX-003)
by automagik-genie · 2026-02-14
74.2%