Gate group speaker isolation to shared chat sessions only.

Per-user group sessions (user_in_chat) already isolate history; keep Sender tags and focus hints only when session_scope=chat (legacy shared __group__ transcripts).

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-08-10 23:16:27 +08:00
parent e91e4fe773
commit 9bbac6c0b8
5 changed files with 50 additions and 21 deletions

View file

@ -400,8 +400,10 @@ def test_prepare_group_user_text_for_model_user_in_chat() -> None:
mention_names=["吴华"],
lang="zh",
)
assert out.startswith("[发言: Bob]")
assert "每三分钟提醒@吴华 喝水" in out
# Per-user group sessions already isolate by session — no sender prefix.
assert out == "每三分钟提醒@吴华 喝水"
assert "[发言:" not in out
assert "[Sender:" not in out
def test_prepare_group_user_text_for_model_shared_chat_prefix() -> None:
@ -423,7 +425,7 @@ def test_build_group_focus_instruction() -> None:
en = build_group_focus_instruction()
zh = build_group_focus_instruction(lang="zh")
assert "current sender" in en
assert "[Sender:" in en or "Sender" in en
assert "Shared group" in en or "shared" in en.lower()
assert "群聊规则" in zh
@ -751,8 +753,9 @@ def test_inbound_group_mention_uses_per_user_session_and_sender_prefix(
assert len(session_ids) == 2
assert session_ids[0] != session_ids[1]
assert "[群成员:" not in captured["text"]
assert captured["text"].startswith("[Sender: Bob]")
assert captured["text"].endswith("again")
assert "[发言:" not in captured["text"]
assert "[Sender:" not in captured["text"]
assert captured["text"] == "again"
assert "群聊规则" not in captured["text"]
sid = store.get_or_create_channel_session_v2(

View file

@ -956,10 +956,10 @@ def test_channel_file_delivery_hint_goes_to_system_not_user_message() -> None:
assert not OclawGateway._is_channel_delivery_channel(msg_admin)
def test_group_focus_system_hint_only_for_groups() -> None:
def test_group_focus_system_hint_only_for_shared_group_scope() -> None:
from runtime.types import StandardMessage
group_msg = StandardMessage(
shared = StandardMessage(
session_id="s1",
tenant_id="t1",
user_id="u1",
@ -967,7 +967,17 @@ def test_group_focus_system_hint_only_for_groups() -> None:
channel="whatsapp",
text="@bot alarms",
attachments=[],
metadata={"is_group": True},
metadata={"is_group": True, "group_session_scope": "chat"},
)
per_user = StandardMessage(
session_id="s1",
tenant_id="t1",
user_id="u1",
role="member",
channel="whatsapp",
text="@bot alarms",
attachments=[],
metadata={"is_group": True, "group_session_scope": "user_in_chat"},
)
dm = StandardMessage(
session_id="s1",
@ -979,6 +989,7 @@ def test_group_focus_system_hint_only_for_groups() -> None:
attachments=[],
metadata={"is_group": False},
)
hint = OclawGateway._group_focus_system_hint(group_msg, "en")
hint = OclawGateway._group_focus_system_hint(shared, "en")
assert "current sender" in hint
assert OclawGateway._group_focus_system_hint(per_user, "en") == ""
assert OclawGateway._group_focus_system_hint(dm, "en") == ""