Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(harness): deduplicate empty turn failure notices
cyh151f1a673d77
diff --git a/core/message_dispatcher.py b/core/message_dispatcher.pyindex 6d92f0fd8..49fe9504c 100644--- a/core/message_dispatcher.py+++ b/core/message_dispatcher.py@@ -1355,6 +1355,37 @@ class ConsolidatedMessageDispatcher:metadata["turn_failure_notification"] = notificationreturn replace(output_semantics, metadata=metadata)+ def _output_with_implicit_turn_failure_notification(+ self,+ context: MessageContext,+ output_semantics: MessageOutput,+ *,+ is_error: bool,+ has_visible_result: bool,+ mutates_turn_lifecycle: bool,+ ) -> MessageOutput:+ """Give an invisible failed Harness Turn one shared fallback identity."""++ if (+ not is_error+ or has_visible_result+ or not mutates_turn_lifecycle+ or not output_semantics.settles_run+ ):+ return output_semantics+ notification = output_semantics.metadata.get("turn_failure_notification")+ if isinstance(notification, dict) and str(notification.get("failure_id") or "").strip():+ return output_semantics+ turn_id = str((context.platform_specific or {}).get("turn_token") or "").strip()+ if not turn_id or not self._terminal_agent_run_ids(context, output_semantics):+ return output_semantics+ metadata = dict(output_semantics.metadata)+ metadata["turn_failure_notification"] = {+ "failure_id": f"turn:{turn_id}",+ "delivered": False,+ }+ return replace(output_semantics, metadata=metadata)+def _run_has_blocking_activity(self, run_id: str) -> bool:service = getattr(self.controller, "agent_service", None)registry = getattr(service, "activities", None)@@ -1999,11 +2030,6 @@ class ConsolidatedMessageDispatcher:canonical_type = settings_manager._canonicalize_message_type(message_type or "")settings_key = self._get_settings_key(context)output_semantics = output_for_message(canonical_type, output)- if canonical_type == "result" and output_semantics.completes_turn:- output_semantics = self._output_with_turn_fallback_owner(- context,- output_semantics,- )activity_batch_incomplete = bool(output_semantics.requires_delivery_for_run_settlementand output_semantics.metadata.get("activity_batch_complete") is False@@ -2058,6 +2084,18 @@ class ConsolidatedMessageDispatcher:text = enhanced.visible_textelse:text = strip_silent_blocks(raw_text)+ if canonical_type == "result" and output_semantics.completes_turn:+ output_semantics = self._output_with_implicit_turn_failure_notification(+ context,+ output_semantics,+ is_error=is_error,+ has_visible_result=level != "silent" and bool(text and text.strip()),+ mutates_turn_lifecycle=mutates_turn_lifecycle,+ )+ output_semantics = self._output_with_turn_fallback_owner(+ context,+ output_semantics,+ )# Persist the exact terminal body in the Turn snapshot before delivery.# A steer accepted after this Turn settles can then complete its Agent Run# without guessing from transcript order or requiring a live sink.diff --git a/docs/plans/harness-watch-run-failure-boundary.md b/docs/plans/harness-watch-run-failure-boundary.mdindex ef0105ad3..a86ebf15e 100644--- a/docs/plans/harness-watch-run-failure-boundary.md+++ b/docs/plans/harness-watch-run-failure-boundary.md@@ -140,8 +140,8 @@ does not claim that an event was detected.complete Turn fallback; pending callback delivery defers it.- `HFR-441`: persistence under `suppress_delivery` cannot satisfy or shadow alater outward receipt, including in a foreground callback target Session.-- `HFR-442`: bare Turn provenance without a notification contract does not- bypass definition-level failure-notice suppression.+- `HFR-442`: a visible direct error with bare Turn provenance does not bypass+ definition-level failure-notice suppression.- `HFR-443`: a deferred participant's pending callback remains part of the Turncallback aggregate and blocks an immediate sibling fallback.- `HFR-444`: a Watch in its first in-flight waiter cycle reports unknown waiter@@ -174,6 +174,9 @@ does not claim that an event was detected.receipt through the shared Turn output even when another Run owns the Message.- `HFR-459`: independent Activity completions reserve the SQLite writer beforereading deferred participants and electing their shared Turn fallback owner.+- `HFR-472`: an empty failed Harness Turn synthesizes the existing Turn failure+ contract before its immutable snapshot, so every accepted Run shares one+ fallback owner instead of emitting one notice per Run.Residual manual check: trigger two one-shot Watches into one failing Turn andconfirm that the conversation contains one backend error, both Runs are failed,diff --git a/tests/scenarios/harness_failure_recovery/catalog.yaml b/tests/scenarios/harness_failure_recovery/catalog.yamlindex 27ce795a8..c58e6edf3 100644--- a/tests/scenarios/harness_failure_recovery/catalog.yaml+++ b/tests/scenarios/harness_failure_recovery/catalog.yaml@@ -4235,6 +4235,15 @@ scenarios:# Exit 124 keeps a once Watch waiting only when listed, then the first event# queues one Run and retires normally.test: tests/test_watches.py::test_once_watch_retries_timeout_only_when_124_is_allowed+ - id: HFR-472+ name: empty failed Turn owns one fallback across all accepted Runs+ status: covered+ kind: failure_recovery+ layer: contract+ backend: shared+ # The shared dispatcher stamps one Turn failure identity before the immutable+ # terminal snapshot; the existing atomic settlement elects one Run owner.+ test: tests/test_message_dispatcher_result_fallback.py::MessageDispatcherResultFallbackTests::test_hfr_472_empty_failed_turn_creates_one_shared_fallback_contractmanual_evidence:- local Incus backend process death after prompt acceptance- local Incus controller restart with persisted queued successordiff --git a/tests/test_message_dispatcher_result_fallback.py b/tests/test_message_dispatcher_result_fallback.pyindex 75e2d30c6..17c4fc35f 100644--- a/tests/test_message_dispatcher_result_fallback.py+++ b/tests/test_message_dispatcher_result_fallback.py@@ -229,6 +229,85 @@ class MessageDispatcherResultFallbackTests(unittest.IsolatedAsyncioTestCase):)store.get_run.assert_not_called()+ async def test_hfr_472_empty_failed_turn_creates_one_shared_fallback_contract(self):+ controller = self._terminal_lifecycle_controller()+ dispatcher = ConsolidatedMessageDispatcher(controller)+ dispatcher._collapse_status_bubble = mock.AsyncMock()+ dispatcher._clear_consolidated_state = mock.AsyncMock()+ context = MessageContext(+ user_id="U1",+ channel_id="C1",+ platform="slack",+ platform_specific={+ "agent_runtime_turn_key": "runtime-1",+ "agent_runtime_turn_token": "runtime-turn-1",+ "turn_token": "turn-empty-failure",+ "accepted_agent_run_ids": ["run-b", "run-a"],+ },+ )+ store = mock.Mock()+ store.get_run.side_effect = lambda run_id: {+ "run-a": {"id": "run-a", "status": "running"},+ "run-b": {"id": "run-b", "status": "running"},+ }.get(run_id)++ with mock.patch(+ "core.message_dispatcher.SQLiteBackgroundTaskStore",+ return_value=store,+ ):+ await dispatcher.emit_agent_message(+ context,+ "result",+ "",+ is_error=True,+ output=MessageOutput(completes_turn=True, completes_run=True),+ )++ evidence = controller.session_turns.on_terminal_result.call_args.kwargs[+ "terminal_evidence"+ ]+ notification = evidence["output_provenance"]["turn_failure_notification"]+ self.assertEqual(+ notification,+ {+ "failure_id": "turn:turn-empty-failure",+ "delivered": False,+ "fallback_run_id": "run-a",+ },+ )+ store.record_turn_run_outputs.assert_called_once()+ record_call = store.record_turn_run_outputs.call_args+ self.assertEqual(record_call.args[0], ["run-b", "run-a"])+ self.assertEqual(+ record_call.kwargs["provenance"]["turn_failure_notification"],+ notification,+ )+ self.assertEqual(controller.im_client.sent_messages, [])++ def test_visible_direct_error_does_not_create_a_turn_fallback_contract(self):+ dispatcher = ConsolidatedMessageDispatcher(_StubController(platform="slack"))+ context = MessageContext(+ user_id="U1",+ channel_id="C1",+ platform="slack",+ platform_specific={+ "turn_token": "turn-visible-error",+ "accepted_agent_run_ids": ["run-a", "run-b"],+ },+ )+ output = MessageOutput(completes_turn=True, completes_run=True)++ unchanged = dispatcher._output_with_implicit_turn_failure_notification(+ context,+ output,+ is_error=True,+ has_visible_result=True,+ mutates_turn_lifecycle=True,+ )++ self.assertIs(unchanged, output)+ self.assertNotIn("turn_failure_notification", unchanged.metadata)+async def test_detached_stale_result_delivers_without_mutating_newer_turn(self):controller = _StubController(platform="slack")controller.agent_service = type(