Skip to content

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

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

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

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes an issue where Feishu/Lark DM quoted replies (引用回复) create isolated sessions, causing the agent to lose all conversation context. When a user quotes/replies to a message in a DM, the Lark SDK populates thread_id/root_id, which then flows into the session key and creates a brand new empty session instead of continuing the existing DM conversation.

Related Issue

Fixes #44028

Type of Change

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

Changes Made

  • gateway/platforms/feishu.py: In _process_inbound_message, clear thread_id when chat_type == "p2p" (DM), since Feishu DMs do not support real threads — only group chats do. (+4 lines)
  • tests/gateway/test_feishu.py: Add two regression tests — test_p2p_quoted_reply_ignores_thread_id verifies DM quoted replies get thread_id=None, and test_group_quoted_reply_preserves_thread_id verifies group thread routing is unaffected. (+89 lines)

How to Test

  1. python -m pytest tests/gateway/test_feishu.py -k "test_p2p_quoted_reply_ignores_thread_id or test_group_quoted_reply_preserves_thread_id" -v — both new tests should pass
  2. python -m pytest tests/gateway/test_feishu.py -q — all 162 tests pass, 45 skipped (no regressions)
  3. Manual: send a quoted reply in a Feishu DM to a Hermes bot — the reply should stay in the same session as regular DM messages (no session isolation)

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: _process_inbound_message in gateway/platforms/feishu.py (line 3098); build_sourcebuild_session_key flow for DM session key construction
  • Blast radius: LOW — change only affects Feishu p2p (DM) chat type; group chat threading is explicitly preserved
  • Related patterns: Same chat_type == "p2p" guard pattern used elsewhere in feishu.py (e.g., line 3891)

…d sessions

When a user sends a quoted reply (引用回复) in a Feishu/Lark DM, the
Lark SDK populates `message.thread_id` (or `message.root_id`) with the
parent message ID.  This thread_id then flows into `build_session_key()`,
creating an isolated session (e.g. `feishu:dm:oc_xxx:om_yyy` instead of
`feishu:dm:oc_xxx`), which causes the agent to lose all conversation
context.

Feishu DMs do not support real threads — only group chats do.  The fix
clears thread_id for p2p (DM) chat_type in `_process_inbound_message`.
@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 — the same Feishu root_id/thread_id-vs-quote-reply fix (also tracked in open PR #30164). #44058 was the same-day twin (now closed). Consolidating on #36233 as the canonical open fix.

@liuhao1024

Copy link
Copy Markdown
Contributor Author

Thanks for the flag @alt-glitch. Confirmed — #36233 is a more comprehensive fix (+342 lines covering root_id/thread_id distinction across multiple code paths). 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