diff --git a/src/clean_agent_preview.py b/src/clean_agent_preview.py index 42d7d6d11..73fe39b15 100644 --- a/src/clean_agent_preview.py +++ b/src/clean_agent_preview.py @@ -4814,6 +4814,32 @@ async def stream_preview(*, endpoint_url, model, messages, headers, turn_contrac history[-1] = {'role': 'assistant', 'content': confirmation} yield event({'type': 'final_response', 'content': confirmation}) break + if ( + not successful_artifact_write + and artifact_body_handoff_attempts < 2 + and round_number < round_limit + ): + artifact_body_handoff_attempts += 1 + artifact_body_handoff_target = target + force_no_tools_next_round = True + replace_streamed_draft_on_finish = True + history.append({ + 'role': 'user', + '_harness_control': True, + 'content': ( + 'The prior body-only artifact response was empty or did not ' + f'match the required format for {target}. Return only the ' + 'complete raw file body now. Do not emit a tool call, JSON ' + 'wrapper, commentary, or another action plan.' + ), + }) + yield event({ + 'type': 'completion_recovery', + 'reason': 'invalid_artifact_body_retry', + 'path': target, + 'attempt': artifact_body_handoff_attempts, + }) + continue if ( native_workspace_enabled and required_artifacts diff --git a/tests/test_clean_agent_preview.py b/tests/test_clean_agent_preview.py index 23fdf86c9..d99de2213 100644 --- a/tests/test_clean_agent_preview.py +++ b/tests/test_clean_agent_preview.py @@ -549,12 +549,6 @@ async def test_repeated_off_contract_calls_recover_via_required_artifact_body(mo })}, }]}}]}, {'choices': [{'delta': {'content': ''}}]}, - {'choices': [{'delta': {'tool_calls': [{ - 'index': 0, 'id': 'bad-inspect', - 'function': {'name': 'inspect_media', 'arguments': json.dumps({ - 'path': '/workspace/input.png', - })}, - }]}}]}, {'choices': [{'delta': {'content': 'Recovered'}}]}, ]) @@ -611,7 +605,7 @@ async def test_repeated_off_contract_calls_recover_via_required_artifact_body(mo event.get('type') == 'tool_output' and event.get('execution_attempted') is False for event in events - ) == 3 + ) == 2 assert any( event.get('type') == 'artifact_body_handoff' and event.get('path') == '/workspace/output.html'