Skip to content

fix(feishu): ignore thread_id in DM quoted replies to prevent isolated sessions - #44259

Closed
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/feishu-dm-thread-session
Closed

fix(feishu): ignore thread_id in DM quoted replies to prevent isolated sessions#44259
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/feishu-dm-thread-session

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes a bug where quoted replies (引用回复) in Feishu DMs create isolated sessions, causing the agent to lose all conversation context. The Lark SDK populates thread_id for DM quoted replies, but Feishu DMs don't support real threads — the field is erroneously used to build a different session key.

Related Issue

Fixes #44028

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • gateway/platforms/feishu.py: Clear thread_id when chat_type == "p2p" so DM quoted replies stay in the normal DM session. Group thread behavior is preserved.
  • tests/gateway/test_feishu.py: Added two regression tests — DM quoted reply strips thread_id, group reply preserves it.

How to Test

  1. Configure a Feishu bot with DM access
  2. Start a conversation with the bot (normal messages work fine)
  3. Send a quoted reply to one of the bot's messages
  4. Before fix: agent loses context (new empty session created)
  5. After fix: agent continues in the same session with full context
pytest tests/gateway/test_feishu.py::TestFeishuProcessInboundMessage::test_dm_quoted_reply_does_not_create_thread_session tests/gateway/test_feishu.py::TestFeishuProcessInboundMessage::test_group_quoted_reply_preserves_thread_id -v

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Code Intelligence

  • Analyzed: FeishuAdapter._process_inbound_message() (callers: Lark SDK event handler, flows: 1)
  • Blast radius: LOW — only affects Feishu DM inbound message processing
  • Related patterns: Session key builder uses thread_id for group threads; DMs should not use it

…d sessions

When a user sends a quoted reply (引用回复) in a Feishu DM, the Lark SDK
populates message.thread_id with the parent message ID. The gateway's
session key builder then appends this thread_id, creating an isolated
session (e.g. `agent:main:feishu:dm:oc_xxx:om_yyy`) instead of using
the normal DM session (`agent:main:feishu:dm:oc_xxx`). This causes the
agent to lose all conversation context.

Feishu DMs do not support real threads — quoted replies are just messages
in the same conversation. Only group chats (话题/话题区) use real threads.

Fix: clear thread_id when chat_type is "p2p" so the session key remains
unchanged. Group thread behavior is preserved.

Closes NousResearch#44028
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/feishu Feishu / Lark adapter duplicate This issue or pull request already exists labels Jun 11, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #36233 — same root cause and fix (clear thread_id for chat_type=='p2p' so Feishu DM quoted replies stay in the main DM session). #36233 is the earliest open canonical PR; #44083/#44058 are closed twins.

@liuhao1024

Copy link
Copy Markdown
Contributor Author

Thanks for the flag @alt-glitch. Confirmed — #36233 covers the same root cause with a more comprehensive approach (+342/-13 across 4 files vs this PR's +55). Closing in favor of #36233.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists platform/feishu Feishu / Lark adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feishu DM: quoted reply (引用回复) creates isolated thread session, breaks conversation context

2 participants