diff --git a/backend/docs/runtime-guidance-details.md b/backend/docs/runtime-guidance-details.md index 4b47147178..61354b61a0 100644 --- a/backend/docs/runtime-guidance-details.md +++ b/backend/docs/runtime-guidance-details.md @@ -167,7 +167,15 @@ JSON, a `.work/` scratch tree) is excluded, so it never enters `produced_paths`. The worker passes this list through `_produced_output_paths()` to its delivery check; an empty list leaves `produced_paths` and `verification` absent from the delivery receipt, and -`_delivery_error()` returns no error. When that empty list accompanies a truncated +`_delivery_error()` returns no error. Delivery enforcement is required when the +run took part in a goal: the continuation helper reports an active, expected +goal through a participation callback before any evaluation write, a scheduled +goal is installed, the evaluator verdict was persisted, or the goal state could +not be read (unknown keeps delivery required). A failed verdict write therefore +still requires delivery. An ordinary run records the same +verdict with `enforcement: "advisory"` and stays successful, because working +files and a local copy of a result written to an external system are not +deliverables. When that empty list accompanies a truncated pre-run snapshot, the receipt includes `verification_skipped: "truncated_pre_run_snapshot"` on both normal completion and failure/cancellation cleanup. This marker explains the skipped check without diff --git a/backend/packages/harness/deerflow/runtime/runs/worker.py b/backend/packages/harness/deerflow/runtime/runs/worker.py index c0c52bc6cd..490ad933dc 100644 --- a/backend/packages/harness/deerflow/runtime/runs/worker.py +++ b/backend/packages/harness/deerflow/runtime/runs/worker.py @@ -400,8 +400,15 @@ def _delivery_content_with_outputs( produced_paths: list[str], *, pre_run_snapshot: WorkspaceSnapshot | None = None, + required: bool = False, ) -> dict[str, Any]: - """Attach a delivery verdict or explain why a truncated scan skipped it.""" + """Attach a delivery verdict or explain why a truncated scan skipped it. + + ``required`` marks a goal run, where clearing the goal depends on a presented + deliverable. An ordinary run still records the verdict (``enforcement: + "advisory"``) but does not fail on it: working files and a local copy of a + result written to an external system are not deliverables. + """ if not produced_paths: if pre_run_snapshot is not None and pre_run_snapshot.truncated: return {**content, "verification_skipped": "truncated_pre_run_snapshot"} @@ -422,16 +429,31 @@ def _delivery_content_with_outputs( "matched_paths": matched_paths, "stage": "presented" if satisfied else ("mismatched" if presented_paths else "not_started"), "satisfied": satisfied, + "enforcement": "required" if required else "advisory", } def _delivery_error(content: dict[str, Any]) -> str | None: - """Return the terminal error when no changed output was presented.""" + """Return the terminal error when a required delivery is missing.""" + if content.get("enforcement") != "required": + return None if not content.get("produced_paths") or content.get("satisfied") is True: return None return _DELIVERY_INCOMPLETE_ERROR +def _with_delivery_enforcement(content: dict[str, Any], *, required: bool) -> dict[str, Any]: + """Normalize a receipt's enforcement after the goal verdict is known. + + The recursion-capped path builds its receipt before the goal continuation + call can record a verdict; without this it would persist ``advisory`` for a + goal run. Receipts without produced paths carry no enforcement field. + """ + if not content.get("produced_paths"): + return content + return {**content, "enforcement": "required" if required else "advisory"} + + def _workspace_excluded_dir_names(app_config: AppConfig | None) -> frozenset[str]: """Directory names workspace snapshots must skip for this deployment. @@ -1111,6 +1133,10 @@ async def run_agent( approval_runtime = None scheduled_goal: GoalState | None = None final_goal_verdict: dict[str, Any] | None = None + # Whether this run took part in a goal at all. A verdict can stay unset when + # persisting the evaluation fails, so delivery enforcement must not depend on + # the verdict alone. + goal_participated = False produced_output_paths: list[str] | None = None terminal_error_frame: dict[str, str] | None = None # Journal construction moved ahead of preflight so every terminal run can @@ -1877,6 +1903,18 @@ async def run_agent( if isinstance(runtime.context, dict): runtime.context.pop("stop_reason", None) + def mark_goal_participation(_goal: GoalState | None) -> None: + """Record that this run took part in a goal, before evaluation persists. + + The verdict callback only fires after the checkpoint write succeeds, + so a transient write failure must not downgrade delivery enforcement + to advisory for a run that actually took part in a goal. ``None`` + means the goal state could not be read: unknown is not absent, so + delivery stays required. + """ + nonlocal goal_participated + goal_participated = True + def capture_goal_verdict(evaluated_goal: GoalState, evaluation: GoalEvaluation, stand_down_reason: str | None) -> None: nonlocal final_goal_verdict if scheduled_goal is not None and not _goal_instance_matches(scheduled_goal, evaluated_goal): @@ -1914,6 +1952,7 @@ async def run_agent( interaction_policy=resolve_run_interaction_policy(config), expected_goal=scheduled_goal, verdict_callback=capture_goal_verdict, + participation_callback=mark_goal_participation, usage_callback=journal.record_external_llm_usage_records if journal is not None else None, ) if isinstance(continuation_input, _GoalCompletionCandidate): @@ -1983,6 +2022,11 @@ async def run_agent( journal.get_delivery_content() if journal is not None else _empty_delivery_content(), produced_output_paths, pre_run_snapshot=pre_run_workspace_snapshot, + # A goal run's completion depends on the presented deliverable; + # an ordinary run that leaves working files or a local copy of + # an external write is still finished (issue #8239). + # Participation covers a goal run whose verdict write failed. + required=goal_participated or scheduled_goal is not None or record.goal_verdict is not None, ) delivery_error = _delivery_error(delivery_content) cancel_action = await run_manager.set_status_if_not_cancelled( @@ -2055,8 +2099,14 @@ async def run_agent( interaction_policy=resolve_run_interaction_policy(config), expected_goal=scheduled_goal, verdict_callback=capture_goal_verdict, + participation_callback=mark_goal_participation, ) record.goal_verdict = final_goal_verdict + # The receipt was built before the continuation call could record a + # verdict; normalize its enforcement now so a capped goal run does + # not persist an advisory verdict. Participation covers a run whose + # verdict write failed after the evaluator saw an active goal. + delivery_content = _with_delivery_enforcement(delivery_content, required=goal_participated or scheduled_goal is not None or record.goal_verdict is not None) stop_status_kwargs = {"stop_reason": _RECURSION_CAPPED_STOP_REASON, "goal_verdict": record.goal_verdict} else: logger.exception("Run %s failed: %s", run_id, error_msg) @@ -2181,9 +2231,14 @@ async def run_agent( if delivery_content is None: if produced_output_paths is None: produced_output_paths = await _produced_output_paths(pre_run_workspace_snapshot, thread_id=thread_id, user_id=workspace_changes_user_id, extra_excluded_dir_names=workspace_excluded_dir_names) - delivery_content = _delivery_content_with_outputs(journal.get_delivery_content(), produced_output_paths, pre_run_snapshot=pre_run_workspace_snapshot) + delivery_content = _delivery_content_with_outputs( + journal.get_delivery_content(), + produced_output_paths, + pre_run_snapshot=pre_run_workspace_snapshot, + required=goal_participated or scheduled_goal is not None or record.goal_verdict is not None, + ) receipt_persisted = await _persist_delivery_receipt(event_store, thread_id=thread_id, run_id=run_id, content=delivery_content) - if produced_output_paths and record.status == RunStatus.success and not receipt_persisted: + if produced_output_paths and record.status == RunStatus.success and not receipt_persisted and delivery_content.get("enforcement") == "required": await run_manager.set_status(run_id, RunStatus.error, error=_DELIVERY_RECEIPT_FAILED_ERROR, persist=False) # Same invariant as the completion branch: the record is now # `error`, so the stream must not end as a success. Frames @@ -2947,6 +3002,7 @@ async def _prepare_goal_continuation_input( interaction_policy: RunInteractionPolicy | None = None, expected_goal: GoalState | None = None, verdict_callback: Callable[[GoalState, GoalEvaluation, str | None], None] | None = None, + participation_callback: Callable[[GoalState | None], None] | None = None, usage_callback: Callable[[list[dict[str, int | str | None]]], None] | None = None, ) -> dict[str, Any] | _GoalCompletionCandidate | None: """Return a continuation input or a completion candidate for finalization. @@ -2961,16 +3017,32 @@ async def _prepare_goal_continuation_input( if abort_event is not None and abort_event.is_set(): return None - try: - goal = await read_thread_goal(checkpointer, thread_id) - except Exception: - logger.warning("Could not read goal for thread %s after run %s", thread_id, run_id, exc_info=True) - return None + goal: GoalState | None = None + for attempt in range(2): + try: + goal = await read_thread_goal(checkpointer, thread_id) + break + except Exception: + if attempt == 0: + continue + logger.warning("Could not read goal for thread %s after run %s", thread_id, run_id, exc_info=True) + # The goal state is unknown, not absent: keep delivery required for + # this run instead of downgrading an interactive goal run to + # advisory when a transient checkpoint read fails. + if participation_callback is not None: + participation_callback(None) + return None if not goal or goal.get("status") != "active": return None if expected_goal is not None and not _goal_instance_matches(expected_goal, goal): return None + # This run took part in a goal. Record it before any evaluation write: the + # verdict callback only fires after the write succeeds, and delivery + # enforcement must stay required even when that write fails. + if participation_callback is not None: + participation_callback(goal) + async def _persist( goal: GoalState, evaluation: GoalEvaluation, diff --git a/backend/tests/test_goal_worker.py b/backend/tests/test_goal_worker.py index 927942db52..e7c982ae1b 100644 --- a/backend/tests/test_goal_worker.py +++ b/backend/tests/test_goal_worker.py @@ -1506,3 +1506,89 @@ async def test_rollback_restores_the_met_goal_record_a_cancelled_run_dropped(mod assert restored is True assert values["goal_outcome"] == record assert values.get("goal") is None + + +@pytest.mark.asyncio +async def test_participation_callback_fires_before_the_goal_verdict_is_persisted(monkeypatch): + """Delivery enforcement must not depend on the verdict write succeeding.""" + saver = InMemorySaver() + thread_id = "participation-before-verdict" + await _seed_goal_thread(saver, thread_id=thread_id, goal_text="Finish the controlled task") + participated: list[dict] = [] + + async def failing_persist(*_args, **_kwargs): + raise RuntimeError("checkpoint write failed") + + monkeypatch.setattr(worker, "_persist_goal_evaluation", failing_persist) + + with pytest.raises(RuntimeError, match="checkpoint write failed"): + await worker._prepare_goal_continuation_input( + accessor=_full_accessor(saver), + bridge=_CollectingBridge(), + checkpointer=saver, + thread_id=thread_id, + run_id="run-1", + model_name=None, + app_config=None, + participation_callback=participated.append, + ) + + assert participated and participated[0]["status"] == "active" + + +@pytest.mark.asyncio +async def test_participation_callback_skips_a_run_without_a_goal(): + saver = InMemorySaver() + thread_id = "participation-no-goal" + checkpoint = empty_checkpoint() + checkpoint["channel_values"] = {"messages": [HumanMessage(content="hello")]} + checkpoint["channel_versions"] = {"messages": 1} + saver.put( + {"configurable": {"thread_id": thread_id, "checkpoint_ns": ""}}, + checkpoint, + {"step": 1}, + {"messages": 1}, + ) + participated: list[dict] = [] + + result = await worker._prepare_goal_continuation_input( + accessor=_full_accessor(saver), + bridge=_CollectingBridge(), + checkpointer=saver, + thread_id=thread_id, + run_id="run-1", + model_name=None, + app_config=None, + participation_callback=participated.append, + ) + + assert result is None + assert participated == [] + + +@pytest.mark.asyncio +async def test_participation_callback_fires_when_the_goal_read_fails(monkeypatch): + """An unreadable goal is unknown, not absent: delivery stays required.""" + saver = InMemorySaver() + thread_id = "participation-goal-read-fails" + await _seed_goal_thread(saver, thread_id=thread_id, goal_text="Finish the controlled task") + participated: list = [] + + async def failing_read(*_args, **_kwargs): + raise RuntimeError("checkpoint read failed") + + monkeypatch.setattr(worker, "read_thread_goal", failing_read) + + result = await worker._prepare_goal_continuation_input( + accessor=_full_accessor(saver), + bridge=_CollectingBridge(), + checkpointer=saver, + thread_id=thread_id, + run_id="run-1", + model_name=None, + app_config=None, + participation_callback=participated.append, + ) + + assert result is None + assert participated == [None] diff --git a/backend/tests/test_run_recursion_capped.py b/backend/tests/test_run_recursion_capped.py index df4cb09d8e..30eecb746f 100644 --- a/backend/tests/test_run_recursion_capped.py +++ b/backend/tests/test_run_recursion_capped.py @@ -145,6 +145,7 @@ async def test_recursion_cap_reports_a_plain_stop_with_unpresented_outputs(tmp_p assert len(result["deliveries"]) == 1 assert result["deliveries"][0]["produced_paths"] == produced assert result["deliveries"][0]["satisfied"] is False + assert result["deliveries"][0]["enforcement"] == "advisory" @pytest.mark.asyncio @@ -162,6 +163,10 @@ async def test_recursion_cap_stands_the_goal_down_without_an_evaluator_call(tmp_ assert record.goal_verdict is not None assert record.goal_verdict["stand_down_reason"] == "recursion_capped" assert json.dumps(record.goal_verdict) # stored as plain data on the run record + # The receipt is built before the continuation call records the verdict; + # it must be normalized to required for this goal run. + assert len(result["deliveries"]) == 1 + assert result["deliveries"][0]["enforcement"] == "required" def test_recursion_cap_message_without_outputs_or_limit(): diff --git a/backend/tests/test_run_terminal_protocol.py b/backend/tests/test_run_terminal_protocol.py index 2fa4e58823..6720fea52f 100644 --- a/backend/tests/test_run_terminal_protocol.py +++ b/backend/tests/test_run_terminal_protocol.py @@ -191,7 +191,7 @@ async def test_two_root_completions_keep_legacy_outputs_and_one_terminal(runtime @pytest.mark.asyncio -async def test_graph_success_before_failed_artifact_delivery_has_error_terminal(runtime, monkeypatch): +async def test_graph_success_waits_for_delivery_verdict_before_terminal(runtime, monkeypatch): """Catches terminal success published before real output verification.""" entered, release = asyncio.Event(), asyncio.Event() original = worker_module._produced_output_paths @@ -224,12 +224,13 @@ async def test_graph_success_before_failed_artifact_delivery_has_error_terminal( release.set() await settled(run.task) row = await runtime.runs.get(run.record.run_id, user_id=run.record.user_id) - assert row["status"] == "error" - assert row["error"] == "Artifact delivery incomplete: no produced output artifact was presented" + assert row["status"] == "success" + assert row["error"] is None delivery = await runtime.events.list_events(run.record.thread_id, run.record.run_id, event_types=["run.delivery"]) assert delivery[0]["content"]["produced_paths"] == ["/mnt/user-data/outputs/report.md"] assert delivery[0]["content"]["satisfied"] is False - confirmed_terminal(await terminal_events(runtime, run.record), run.record, "error") + assert delivery[0]["content"]["enforcement"] == "advisory" + confirmed_terminal(await terminal_events(runtime, run.record), run.record, "success") @pytest.mark.asyncio diff --git a/backend/tests/test_run_worker_delivery.py b/backend/tests/test_run_worker_delivery.py index 0819850f90..6c5109def4 100644 --- a/backend/tests/test_run_worker_delivery.py +++ b/backend/tests/test_run_worker_delivery.py @@ -126,8 +126,9 @@ async def test_vanished_scratch_file_does_not_discard_run_file_changes(tmp_path, delivery = await _delivery_events(store, "thread-1", record.run_id) assert delivery[0]["content"]["produced_paths"] == ["/mnt/user-data/outputs/report.md"] assert delivery[0]["content"]["satisfied"] is False - assert record.status == RunStatus.error - assert record.error == "Artifact delivery incomplete: no produced output artifact was presented" + assert delivery[0]["content"]["enforcement"] == "advisory" + assert record.status == RunStatus.success + assert record.error is None @pytest.mark.anyio @@ -250,12 +251,13 @@ async def test_changed_outputs_succeed_when_a_produced_output_is_presented(monke "matched_paths": ["/mnt/user-data/outputs/report.md"], "stage": "presented", "satisfied": True, + "enforcement": "advisory", } assert record.status == RunStatus.success @pytest.mark.anyio -async def test_changed_outputs_fail_closed_when_not_presented(monkeypatch): +async def test_changed_outputs_are_advisory_when_not_presented(monkeypatch): run_manager = RunManager() record = await run_manager.create("thread-1") store = MemoryRunEventStore() @@ -292,10 +294,96 @@ async def test_changed_outputs_fail_closed_when_not_presented(monkeypatch): "matched_paths": [], "stage": "not_started", "satisfied": False, + "enforcement": "advisory", } + assert record.status == RunStatus.success + assert record.error is None + assert record.stop_reason is None + + +@pytest.mark.anyio +async def test_goal_run_delivery_stays_required_when_not_presented(monkeypatch): + """A goal run's missing deliverable still fails the run. + + The evaluator's verdict marks the run as a goal run, so delivery keeps its + strict verdict instead of the ordinary advisory one. + """ + run_manager = RunManager() + record = await run_manager.create("thread-1") + store = MemoryRunEventStore() + monkeypatch.setattr( + "deerflow.runtime.runs.worker._produced_output_paths", + AsyncMock(return_value=["/mnt/user-data/outputs/report.md"]), + ) + + async def prepare_continuation(**kwargs): + kwargs["verdict_callback"]({"continuation_count": 1}, {"satisfied": True}, None) + return None + + monkeypatch.setattr("deerflow.runtime.runs.worker._prepare_goal_continuation_input", prepare_continuation) + + class ProseOnlyAgent: + async def astream(self, graph_input, config=None, stream_mode=None, subgraphs=False): + yield {"messages": [AIMessage(content="SESSION SUMMARY")]} + + await run_agent( + _make_bridge(), + run_manager, + record, + ctx=RunContext(checkpointer=None, event_store=store), + agent_factory=lambda *, config: ProseOnlyAgent(), + graph_input={}, + config={}, + ) + + delivery = await _delivery_events(store, "thread-1", record.run_id) + assert delivery[0]["content"]["enforcement"] == "required" + assert delivery[0]["content"]["satisfied"] is False + assert record.goal_verdict["satisfied"] is True + assert record.status == RunStatus.error + assert record.error == "Artifact delivery incomplete: no produced output artifact was presented" + + +@pytest.mark.anyio +async def test_active_goal_participation_keeps_delivery_required_without_a_verdict(monkeypatch): + """A goal run stays required even when persisting its verdict failed. + + ``capture_goal_verdict`` only fires after the checkpoint write; the + participation callback fires as soon as the run sees an active goal. + """ + run_manager = RunManager() + record = await run_manager.create("thread-1") + store = MemoryRunEventStore() + monkeypatch.setattr( + "deerflow.runtime.runs.worker._produced_output_paths", + AsyncMock(return_value=["/mnt/user-data/outputs/report.md"]), + ) + + async def prepare_continuation(**kwargs): + kwargs["participation_callback"]({"status": "active"}) + return None + + monkeypatch.setattr("deerflow.runtime.runs.worker._prepare_goal_continuation_input", prepare_continuation) + + class ProseOnlyAgent: + async def astream(self, graph_input, config=None, stream_mode=None, subgraphs=False): + yield {"messages": [AIMessage(content="SESSION SUMMARY")]} + + await run_agent( + _make_bridge(), + run_manager, + record, + ctx=RunContext(checkpointer=None, event_store=store), + agent_factory=lambda *, config: ProseOnlyAgent(), + graph_input={}, + config={}, + ) + + delivery = await _delivery_events(store, "thread-1", record.run_id) + assert delivery[0]["content"]["enforcement"] == "required" + assert record.goal_verdict is None assert record.status == RunStatus.error assert record.error == "Artifact delivery incomplete: no produced output artifact was presented" - assert record.stop_reason is None @pytest.mark.anyio @@ -313,6 +401,15 @@ async def test_unpresented_outputs_publish_an_error_frame_before_end(monkeypatch "deerflow.runtime.runs.worker._produced_output_paths", AsyncMock(return_value=["/mnt/user-data/outputs/report.md"]), ) + + async def prepare_continuation(**kwargs): + # Delivery enforcement is required only for a goal run; mark this fixture + # as one so it keeps exercising the required delivery path. + kwargs["participation_callback"]({"status": "active"}) + return None + + monkeypatch.setattr("deerflow.runtime.runs.worker._prepare_goal_continuation_input", prepare_continuation) + bridge = _RecordingBridge() class ProseOnlyAgent: @@ -353,6 +450,15 @@ async def test_unpersisted_delivery_receipt_publishes_an_error_frame_before_end( "deerflow.runtime.runs.worker._persist_delivery_receipt", AsyncMock(return_value=False), ) + + async def prepare_continuation(**kwargs): + # Delivery enforcement is required only for a goal run; mark this fixture + # as one so it keeps exercising the required delivery path. + kwargs["participation_callback"]({"status": "active"}) + return None + + monkeypatch.setattr("deerflow.runtime.runs.worker._prepare_goal_continuation_input", prepare_continuation) + bridge = _RecordingBridge() class PresentingAgent: @@ -440,6 +546,14 @@ async def test_unconfirmed_delivery_terminal_status_defers_the_error_frame_until AsyncMock(return_value=["/mnt/user-data/outputs/report.md"]), ) + async def prepare_continuation(**kwargs): + # Delivery enforcement is required only for a goal run; mark this fixture + # as one so it keeps exercising the required delivery path. + kwargs["participation_callback"]({"status": "active"}) + return None + + monkeypatch.setattr("deerflow.runtime.runs.worker._prepare_goal_continuation_input", prepare_continuation) + class ProseOnlyAgent: async def astream(self, graph_input, config=None, stream_mode=None, subgraphs=False): yield {"messages": [AIMessage(content="SESSION SUMMARY")]} @@ -525,8 +639,8 @@ async def test_truncated_snapshots_limit_output_delivery_verification(tmp_path, elif terminal_outcome == "cancelled": assert record.status == RunStatus.interrupted elif modify_existing: - assert record.status == RunStatus.error - assert record.error == "Artifact delivery incomplete: no produced output artifact was presented" + assert record.status == RunStatus.success + assert record.error is None else: assert record.status == RunStatus.success assert record.error is None @@ -698,7 +812,7 @@ async def test_changed_outputs_succeed_when_one_of_multiple_outputs_is_presented @pytest.mark.anyio -async def test_changed_outputs_fail_when_present_files_only_presents_an_unrelated_file(monkeypatch): +async def test_changed_outputs_are_advisory_when_present_files_only_presents_an_unrelated_file(monkeypatch): run_manager = RunManager() record = await run_manager.create("thread-1") store = MemoryRunEventStore() @@ -740,7 +854,9 @@ async def test_changed_outputs_fail_when_present_files_only_presents_an_unrelate assert delivery["presented_paths"] == ["/mnt/user-data/outputs/old-report.md"] assert delivery["matched_paths"] == [] assert delivery["satisfied"] is False - assert record.status == RunStatus.error + assert delivery["enforcement"] == "advisory" + assert record.status == RunStatus.success + assert record.error is None @pytest.mark.anyio @@ -1038,7 +1154,7 @@ async def test_delivery_write_failure_preserves_real_durable_terminal_status(): @pytest.mark.anyio -async def test_produced_artifact_delivery_fails_closed_when_receipt_cannot_be_persisted(monkeypatch): +async def test_produced_artifact_delivery_keeps_an_advisory_run_successful_when_receipt_cannot_be_persisted(monkeypatch): class FailingReceiptStore(MemoryRunEventStore): async def put_if_absent(self, **kwargs): raise RuntimeError("event store unavailable") @@ -1079,6 +1195,61 @@ async def test_produced_artifact_delivery_fails_closed_when_receipt_cannot_be_pe config={}, ) + assert record.status == RunStatus.success + assert record.error is None + assert (await run_store.get(record.run_id))["status"] == "success" + + +@pytest.mark.anyio +async def test_required_delivery_receipt_failure_still_fails_a_goal_run(monkeypatch): + """A goal run still fails closed when its delivery receipt cannot be persisted.""" + + class FailingReceiptStore(MemoryRunEventStore): + async def put_if_absent(self, **kwargs): + raise RuntimeError("event store unavailable") + + run_store = MemoryRunStore() + run_manager = RunManager(store=run_store) + record = await run_manager.create("thread-1") + monkeypatch.setattr( + "deerflow.runtime.runs.worker._produced_output_paths", + AsyncMock(return_value=["/mnt/user-data/outputs/report.md"]), + ) + + async def prepare_continuation(**kwargs): + kwargs["participation_callback"]({"status": "active"}) + return None + + monkeypatch.setattr("deerflow.runtime.runs.worker._prepare_goal_continuation_input", prepare_continuation) + + class PresentingAgent: + async def astream(self, graph_input, config=None, stream_mode=None, subgraphs=False): + journal = config["context"]["__run_journal"] + journal._remember_current_run_tool_calls( + AIMessage(content="", tool_calls=[{"id": "call_1", "name": "present_files", "args": {}}]), + caller="lead_agent", + ) + journal.on_tool_end( + Command( + update={ + "artifacts": ["/mnt/user-data/outputs/report.md"], + "messages": [ToolMessage("Successfully presented files", tool_call_id="call_1")], + } + ), + run_id=uuid4(), + ) + yield {"messages": []} + + await run_agent( + _make_bridge(), + run_manager, + record, + ctx=RunContext(checkpointer=None, event_store=FailingReceiptStore()), + agent_factory=lambda *, config: PresentingAgent(), + graph_input={}, + config={}, + ) + assert record.status == RunStatus.error assert record.error == "Artifact delivery verification failed: terminal delivery receipt could not be persisted" assert (await run_store.get(record.run_id))["status"] == "error"