The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(groups): surface directly addressed members that pass
Gille6337f1f22fe2
diff --git a/gateway/hosted_room_discussion.py b/gateway/hosted_room_discussion.pyindex 39ec5f7efe2..958122e2229 100644--- a/gateway/hosted_room_discussion.py+++ b/gateway/hosted_room_discussion.py@@ -567,17 +567,21 @@ def _truncate_utf8_text(value: Any, *, max_bytes: int, suffix: str = "") -> str:def _build_prompt(*, room: DiscussionRoom, member: DiscussionMember, messages: Sequence[_ValidatedEvent], watermark: int,- seen_through_seq: int) -> str:+ seen_through_seq: int, reply_required: bool = False) -> str:delta = [event for event in messages if watermark < event.seq <= seen_through_seq][- MAX_DISCUSSION_DELTA_LINES:]peers = ", ".join(f"@{candidate.handle}" for candidate in room.members if candidate.member_id != member.member_id)opening = [f'[Discussion: "{room.name}"] You are @{member.handle}, one participant 'f"with {peers or 'no other members'} and the user.", "","New messages in this thread since your last turn (oldest first):"]- rules = [- "", "Rules for this Discussion:",+ participation = [+ "- The user directly addressed you. Reply with your answer, result, or concrete blocker.",+ '- Do not return "(pass)". If you cannot proceed, explain why and what you need from the user.',+ ] if reply_required else ["- Reply with one conversational message only when you have something new worth adding.",- '- If you have nothing new to add, reply with exactly "(pass)".',+ '- If you have nothing new to add, reply with exactly "(pass)".']+ rules = [+ "", "Rules for this Discussion:", *participation,"- Mention a teammate by handle to pull them into the next round; do not repeat points already made.","- Never reveal content from private conversations. Your reply is published verbatim."]fixed_bytes = len("\n".join([*opening, *rules]).encode("utf-8"))@@ -598,6 +602,15 @@ def _build_prompt(return prompt+def _requires_direct_reply(+ room: DiscussionRoom, source: _ValidatedEvent | None, member: DiscussionMember, round_index: int,+) -> bool:+ # Only the user's initial address requires a reply. A later peer handoff may+ # legitimately pass after this member has already answered that user.+ return (round_index == 0 and source is not None and source.kind == "message.user"+ and member in resolve_mentions((str(source.payload["text"]),), room.members, default_all=False))++def _make_task_plan(*, room: DiscussionRoom, discussion_event: _ValidatedEvent, member: DiscussionMember, member_index: int,round_index: int, seen_through_seq: int, prompt: str,@@ -742,7 +755,8 @@ def plan_next_task(seen_through_seq = delta[-1].seqprompt = _build_prompt(room=room, member=member, messages=thread_messages, watermark=watermark,- seen_through_seq=seen_through_seq)+ seen_through_seq=seen_through_seq,+ reply_required=_requires_direct_reply(room, discussion, member, round_index))return decide("task", "member_turn", task=_make_task_plan(room=room, discussion_event=discussion, member=member, member_index=member_index,round_index=round_index, seen_through_seq=seen_through_seq, prompt=prompt, attachments=attachments,@@ -896,6 +910,13 @@ def plan_publication(event.kind == "message.user" and event.seq > int(task.payload["source_event_seq"])and event.payload.get("thread_id") == task.identity.thread_id for event in validated)effective_status: TerminalKind = ("cancelled" if newer_same_thread and status != "deferred" else status)+ source = next((event for event in validated if event.event_id == task.discussion_event_id), None)+ if (effective_status == "settled" and _requires_direct_reply(room, source, task.member, task.round_index)+ and is_pass_text(_terminal_text(result, field="text", fallback=""))):+ # The execution completed, but did not answer the user. Publish that+ # failure from the durable receipt without replaying any tools or model calls.+ effective_status = "failed"+ result = {"error": f"@{task.member.handle} was directly addressed but returned no visible reply."}digest = task.identity.task_id.removeprefix("dtask:")terminal_event_id = (f"ddeferred:{digest}:g{execution_generation}" if effective_status == "deferred" else f"dterminal:{digest}")diff --git a/tests/gateway/test_hosted_room_addressed.py b/tests/gateway/test_hosted_room_addressed.pynew file mode 100644index 00000000000..6db952c2ce0--- /dev/null+++ b/tests/gateway/test_hosted_room_addressed.py@@ -0,0 +1,142 @@+"""Direct user addresses must not disappear as ordinary Discussion silence."""++import pytest++from gateway import hosted_room_discussion as discussion+from gateway import hosted_rooms+from tests.gateway.test_hosted_room_discussion import (+ GATEWAY_ID,+ LOCAL_PROFILES,+ MEMBERS,+ ROOM_ID,+ _append_publication,+ _append_user,+ _events,+ _next_task,+ _settle_next,+)+++def room_db(tmp_path):+ db = tmp_path / "state.db"+ room = hosted_rooms.create_room(+ db,+ room_id=ROOM_ID,+ name="Release",+ members=MEMBERS,+ authority_gateway_id=GATEWAY_ID,+ now=1,+ )+ return db, room++[email protected]("address", ["@research", "@RESEARCH", "@everyone", "@all"])[email protected]("reply", ["(pass)", "", "pass."])+def test_addressed_pass_is_visible_and_does_not_schedule_a_second_attempt(+ room_db, address, reply+):+ db, room = room_db+ _append_user(db, event_id="user-1", text=f"{address} continue the task")+ task = _next_task(room, db)+ assert "concrete blocker" in task.payload["prompt"]+ assert 'reply with exactly "(pass)"' not in task.payload["prompt"]+ publication = discussion.plan_publication(+ room,+ _events(db),+ task,+ status="settled",+ result={"text": reply},+ local_profiles=LOCAL_PROFILES,+ )+ assert publication.terminal_kind == "turn.failed"+ assert len(publication.events) == 1+ assert "directly addressed" in publication.events[0].payload["error"]+ _append_publication(db, publication)+ next_decision = discussion.plan_next_task(+ room, _events(db), local_profiles=LOCAL_PROFILES+ )+ assert next_decision.task is None or next_decision.task.member != task.member++[email protected]("message", ["Continue the task", "@unknown continue"])+def test_unaddressed_collaborative_pass_stays_silent(room_db, message):+ db, room = room_db+ _append_user(db, event_id="user-1", text=message)+ task = _next_task(room, db)+ assert 'reply with exactly "(pass)"' in task.payload["prompt"]+ result = discussion.plan_publication(+ room,+ _events(db),+ task,+ status="settled",+ result={"text": "(pass)"},+ local_profiles=LOCAL_PROFILES,+ )+ assert result.terminal_kind == "turn.settled"+ assert result.events[0].payload["passed"] is True+++def test_answered_member_can_pass_on_a_later_peer_handoff(room_db):+ db, room = room_db+ _append_user(db, event_id="user-1", text="@research check the release")+ _settle_next(room, db, text="Checked. @build please confirm.")+ _settle_next(room, db, text="Confirmed. @research anything else?")+ task = _next_task(room, db)+ assert task.member.handle == "research" and task.round_index > 0+ result = discussion.plan_publication(+ room,+ _events(db),+ task,+ status="settled",+ result={"text": "(pass)"},+ local_profiles=LOCAL_PROFILES,+ )+ assert result.terminal_kind == "turn.settled"+ assert result.events[0].payload["passed"] is True+++def test_superseded_addressed_pass_remains_cancelled(room_db):+ db, room = room_db+ _append_user(db, event_id="user-1", text="@research inspect")+ task = _next_task(room, db)+ _append_user(db, event_id="user-2", text="Never mind")+ result = discussion.plan_publication(+ room,+ _events(db),+ task,+ status="settled",+ result={"text": "(pass)"},+ local_profiles=LOCAL_PROFILES,+ )+ assert result.terminal_kind == "turn.cancelled"+ assert result.events[0].payload["reason"] == "superseded_by_newer_user_event"+++def test_peer_member_address_is_checked_against_handle_not_profile(room_db):+ db, room = room_db+ room["members"][0] = {+ "member_id": "remote-member",+ "profile": "default",+ "handle": "remote",+ "target": {+ "kind": "peer",+ "profile": "default",+ "peer_id": "peer-1",+ "installation_id": "remote-install",+ "capability_digest": "a" * 64,+ },+ }+ _append_user(db, event_id="user-1", text="@remote report your blocker")+ task = _next_task(room, db)+ assert task.member.member_id == "remote-member"+ result = discussion.plan_publication(+ room,+ _events(db),+ task,+ status="settled",+ result={"text": "(pass)"},+ local_profiles=LOCAL_PROFILES,+ )+ assert result.terminal_kind == "turn.failed"+ assert "@remote" in result.events[0].payload["error"]diff --git a/tests/tui_gateway/test_hosted_room_addressed_restart.py b/tests/tui_gateway/test_hosted_room_addressed_restart.pynew file mode 100644index 00000000000..b34eacb7acc--- /dev/null+++ b/tests/tui_gateway/test_hosted_room_addressed_restart.py@@ -0,0 +1,92 @@+"""A completed silent member turn survives restart without duplicate execution."""++import time++import pytest++from gateway import hosted_room_discussion as discussion+from gateway import hosted_room_driver as driver+from tui_gateway.hosted_room_service import HostedRoomService+from tests.tui_gateway.test_hosted_room_service import _FakeRPC, _server+++def _service(db, monkeypatch):+ service = HostedRoomService(_server(), db_path=db)+ rpc = _FakeRPC()+ monkeypatch.setattr(service, "rpc", rpc)+ monkeypatch.setattr(service.runtime, "rpc", rpc)+ monkeypatch.setattr(service, "local_profiles", lambda: ("default", "ops"))+ return service++[email protected]("legacy_prompt", [False, True])+def test_restart_publishes_addressed_pass_once_without_reexecuting(+ tmp_path, monkeypatch, legacy_prompt+):+ db = tmp_path / "state.db"+ service = _service(db, monkeypatch)+ service.create_room(+ room_id="room-1",+ name="Release room",+ members=[+ {"member_id": "default", "profile": "default", "handle": "hermes"},+ {"member_id": "ops", "profile": "ops", "handle": "ops"},+ ],+ )+ send = {+ "room_id": "room-1",+ "event_id": "user-1",+ "payload": {"text": "@ops continue", "thread_id": "thread-1"},+ }+ service.send(**send)+ binding = service.bindings()[0]+ with monkeypatch.context() as patch:+ if legacy_prompt:+ # A queued pre-upgrade task keeps its original prompt and identity.+ patch.setattr(+ discussion,+ "_build_prompt",+ lambda **kwargs: 'Old room prompt: reply "(pass)" if idle.',+ )+ service.prepare_room(binding)+ task = driver.list_tasks(db, room_id="room-1", status="queued")[0]+ lease = driver.acquire_lease(+ db,+ room_id="room-1",+ gateway_id=binding.gateway_id,+ authority_epoch=binding.authority_epoch,+ process_generation="before-restart",+ ttl_seconds=30,+ clock=time.time,+ )+ attempt = driver.start_task(+ db, task["identity"], lease, expected_cancel_generation=0, clock=time.time+ )+ driver.settle_task(+ db,+ attempt,+ settlement_id="reply-1",+ status="settled",+ result={"text": "(pass)"},+ clock=time.time,+ )++ # Crash after the execution receipt, before its room publication.+ restored = _service(db, monkeypatch)+ restored.prepare_room(restored.bindings()[0])+ events = restored._events("room-1")+ failures = [e for e in events if e["kind"] == "turn.failed"]+ assert len(failures) == 1+ assert "directly addressed" in failures[0]["payload"]["error"]+ assert not any(e["kind"] == "message.member" for e in events)++ # Another restart and a duplicate delivery must reuse that same outcome.+ replayed = _service(db, monkeypatch)+ replayed.send(**send)+ replayed.prepare_room(replayed.bindings()[0])+ assert replayed._events("room-1") == events+ tasks = driver.list_tasks(db, room_id="room-1")+ assert len(tasks) == 1+ assert tasks[0]["identity"] == task["identity"]+ assert tasks[0]["execution_generation"] == 1+ assert tasks[0]["status"] == "settled"