Skip to content

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

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

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

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes a bug where Feishu/Lark DM quoted replies (引用回复) create isolated thread sessions, causing the agent to lose all conversation context. The fix nullifies thread_id when chat_type is "p2p" (DM), since Feishu DMs do not support real threads.

Related Issue

Fixes #44028

Type of Change

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

Changes Made

  • gateway/platforms/feishu.py: Add 4-line guard to set thread_id = None when chat_type == "p2p", preventing isolated session creation for DM quoted replies
  • tests/gateway/test_feishu.py: Add test_dm_quoted_reply_ignores_thread_id — verifies that a DM message with thread_id/root_id populated by the Lark SDK does NOT produce an isolated session

How to Test

  1. Run the new test: pytest tests/gateway/test_feishu.py -k test_dm_quoted_reply_ignores_thread_id -xvs
  2. Verify existing Feishu tests still pass: pytest tests/gateway/test_feishu.py -x
  3. (Live test) In a Feishu DM with Hermes, quote-reply a previous message — the response should maintain full conversation context instead of starting fresh

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 (callers: Feishu webhook handler → inbound processing pipeline → session key builder)
  • Blast radius: LOW — only affects Feishu DM (p2p) message routing; group chats and thread handling unchanged
  • Related patterns: build_session_key() in gateway/session.py uses thread_id to differentiate sessions; this fix ensures p2p messages always use the standard DM session key

…d sessions

In Feishu/Lark DMs, quoted replies (引用回复) populate message.thread_id
and message.root_id via the Lark SDK. These fields were passed through to
build_session_key(), which creates an isolated session keyed by thread_id
instead of the normal DM session. The agent loses all conversation context
and either responds with a wrong answer or fails silently.

The fix nullifies thread_id when chat_type is "p2p" (DM), since Feishu DMs
do not support real threads. Group chat thread_id is preserved.

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

Copy link
Copy Markdown
Collaborator

Duplicate of #36233 — same fix (nullify thread_id when chat_type == "p2p" so Feishu DM quoted replies stay in the main DM session). #36233 is the earliest open canonical; closed twins include #44083, #44058, #44259, #44430. All fix #44028.

@liuhao1024

Copy link
Copy Markdown
Contributor Author

Thanks for the flag @alt-glitch. Confirmed — #36233 is the canonical fix with a more comprehensive approach (distinguishes quote replies from topic sessions across 4 files vs this narrower DM-only fix). 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