recover empty artifact writer turns through body handoff

This commit is contained in:
pewdiepie-archdaemon
2026-09-18 16:33:30 +00:00
parent 629bd32d03
commit 3985172885
2 changed files with 97 additions and 0 deletions
+63
View File
@@ -543,6 +543,69 @@ def test_provider_wire_drops_deepseek_reasoning_only_turn_rejected_by_provider()
assert module.provider_wire_messages(messages) == []
@pytest.mark.asyncio
async def test_empty_artifact_writer_turn_recovers_via_body_handoff(monkeypatch):
import src.clean_agent_preview as module
responses = iter([
{'choices': [{'delta': {'reasoning_content': 'spent the turn planning'}}]},
{'choices': [{'delta': {'content': '<html><body>Recovered</body></html>'}}]},
])
class Response:
def __init__(self, payload): self.payload = payload
async def __aenter__(self): return self
async def __aexit__(self, *args): pass
def raise_for_status(self): pass
async def aiter_lines(self):
yield 'data: ' + json.dumps(self.payload)
yield 'data: [DONE]'
requests = []
class Client:
def __init__(self, **kwargs): pass
async def __aenter__(self): return self
async def __aexit__(self, *args): pass
def stream(self, *args, **kwargs):
requests.append(kwargs['json'])
return Response(next(responses))
executed = []
async def execute(block, **kwargs):
executed.append(block)
return block.tool_type, {'output': 'written', 'exit_code': 0}
monkeypatch.setattr(module, 'NATIVE_ARTIFACT_RESEARCH_LIMIT', 0)
monkeypatch.setattr(module.httpx, 'AsyncClient', Client)
monkeypatch.setattr(module, 'execute_tool_block', execute)
schema = next(
item for item in FUNCTION_TOOL_SCHEMAS
if item['function']['name'] == 'write_file'
)
contract = resolve_full_inventory_contract(schemas=[schema], policy=ToolPolicy())
raw = [chunk async for chunk in stream_preview(
endpoint_url='http://test', model='deepseek-flash',
messages=[{'role': 'user', 'content': 'Create the requested HTML.'}],
headers={}, turn_contract=contract, session_id='test', owner='test',
disabled_tools=set(), tool_policy=ToolPolicy(), workspace='/workspace',
client_runtime_context={
'surface': 'odysseus-native', 'terminal_agent': True,
'unattended_mode': True,
'completion_requirements': {
'required_artifacts': ['/workspace/output.html'],
},
}, max_tokens=8192, max_rounds=3,
)]
assert len(requests) == 2
assert requests[1]['max_tokens'] == 8192
assert [block.tool_type for block in executed] == ['write_file']
events = [json.loads(chunk[6:]) for chunk in raw if '[DONE]' not in chunk]
assert any(event.get('type') == 'artifact_body_handoff' for event in events)
@pytest.mark.asyncio
async def test_repeated_off_contract_calls_recover_via_required_artifact_body(monkeypatch):
import src.clean_agent_preview as module