From af250199003ed0ca03ce9cbe88f212a3a6c22143 Mon Sep 17 00:00:00 2001 From: Molecule AI Core-BE Date: Sat, 16 May 2026 13:31:30 +0000 Subject: [PATCH] fix(inbox): add delegate_result exclusion to _is_self_echo_row RFC #2829 PR-2 regression fix: rows with method="delegate_result" are now excluded from the self-echo guard even when source_id matches our workspace_id. The platform may write a delegation-result row with our workspace_id as source_id (e.g. a self-delegation or edge case in the platform's result-writing path); such rows must reach the inbox so the runtime receives the delegation result. Fixes regression vs PR #1346 where this guard was present. Added test_is_self_echo_row_false_for_delegate_result regression pin. All 9 self-echo tests pass locally. Co-Authored-By: Claude Opus 4.7 --- workspace/inbox.py | 11 ++++++++++- workspace/tests/test_inbox.py | 11 +++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/workspace/inbox.py b/workspace/inbox.py index 046f2977..bd8cc040 100644 --- a/workspace/inbox.py +++ b/workspace/inbox.py @@ -453,10 +453,19 @@ def _is_self_echo_row(row: dict[str, Any], workspace_id: str) -> bool: ``workspace_id`` must be non-empty — an empty-string workspace_id (single-workspace legacy path) can never match a UUID source_id, so the predicate is always False there, which is safe. + + RFC #2829 PR-2 note: rows with method="delegate_result" are excluded + from the self-echo guard even when source_id matches our workspace_id. + The platform may write a delegation-result row with source_id set to + our workspace_id (e.g. a self-delegation or edge case in the platform's + result-writing path). Such rows must reach the inbox so that + message_from_activity can surface them as peer_agent inbound and the + runtime receives the delegation result. Silently filtering them as + self-echo would break delegation result delivery. """ if not workspace_id: return False - return row.get("source_id") == workspace_id + return row.get("source_id") == workspace_id and row.get("method") != "delegate_result" def message_from_activity(row: dict[str, Any]) -> InboxMessage: diff --git a/workspace/tests/test_inbox.py b/workspace/tests/test_inbox.py index 1a6c0b03..dd7dbdae 100644 --- a/workspace/tests/test_inbox.py +++ b/workspace/tests/test_inbox.py @@ -539,6 +539,17 @@ def test_is_self_echo_row_false_when_source_id_key_absent(): assert inbox._is_self_echo_row(row, "ws-1") is False +def test_is_self_echo_row_false_for_delegate_result(): + """RFC #2829 PR-2 regression pin: a row with source_id matching our + workspace_id but method=delegate_result must NOT be filtered as a + self-echo. The platform may write a delegation-result row with our + workspace_id as source_id; such rows must reach the inbox so the + runtime receives the delegation result. Silently filtering them would + break delegate_result delivery.""" + row = {"source_id": "ws-1", "method": "delegate_result"} + assert inbox._is_self_echo_row(row, "ws-1") is False + + def test_poll_once_skips_self_echo_rows(state: inbox.InboxState): """Internal #469 regression pin: a row with source_id matching our workspace_id must NOT land in the inbox queue — it is our own