feat(feishu): per-message session for group top-level messages

Align with deer-flow: group top-level messages (no root_id) now get
their own session keyed by message_id instead of sharing a single
group-wide session. Topic replies continue to share session via
root_id.
This commit is contained in:
chengyongru 2026-04-20 00:07:25 +08:00 committed by chengyongru
parent d5122f6df8
commit 08c5ce95f2
2 changed files with 7 additions and 8 deletions

View File

@ -1728,11 +1728,11 @@ class FeishuChannel(BaseChannel):
return
# Build topic-scoped session key for conversation isolation.
# Group chat: thread replies (root_id != message_id) get a scoped
# session so each Feishu thread has its own conversation context.
# Group chat: each topic gets its own session via root_id (replies
# inside a topic) or message_id (top-level messages start a new topic).
# Private chat: no override — same behavior as Telegram/Slack.
if chat_type == "group" and root_id and root_id != message_id:
session_key = f"feishu:{chat_id}:{root_id}"
if chat_type == "group":
session_key = f"feishu:{chat_id}:{root_id or message_id}"
else:
session_key = None

View File

@ -480,8 +480,8 @@ async def test_session_key_group_with_root_id_is_thread_scoped() -> None:
@pytest.mark.asyncio
async def test_session_key_group_no_root_id_uses_default() -> None:
"""Group message without root_id uses default session key (no override)."""
async def test_session_key_group_no_root_id_uses_message_id() -> None:
"""Group message without root_id gets session keyed by message_id (per-message session)."""
channel = _make_feishu_channel(group_policy="open")
bus_spy = []
original_publish = channel.bus.publish_inbound
@ -504,8 +504,7 @@ async def test_session_key_group_no_root_id_uses_default() -> None:
await channel._on_message(event)
assert len(bus_spy) == 1
assert bus_spy[0].session_key_override is None
assert bus_spy[0].session_key == "feishu:oc_abc"
assert bus_spy[0].session_key == "feishu:oc_abc:om_001"
@pytest.mark.asyncio