@@ -1400,6 +1400,56 @@ async def fake_send_raw(event):
14001400 assert payload_types .count ("response.create" ) == 2
14011401 assert payload_types [- 1 ] == "response.create"
14021402
1403+ @pytest .mark .asyncio
1404+ async def test_raw_response_create_is_sequenced_with_follow_up_tool_output (
1405+ self , model , monkeypatch
1406+ ):
1407+ """Raw response.create should block later tool follow-up response.create."""
1408+ payload_types : list [str ] = []
1409+ response_create_started = asyncio .Event ()
1410+ allow_response_create_send = asyncio .Event ()
1411+
1412+ async def fake_send_raw (event ):
1413+ payload_types .append (event .type )
1414+ if event .type == "response.create" and not response_create_started .is_set ():
1415+ response_create_started .set ()
1416+ await allow_response_create_send .wait ()
1417+
1418+ monkeypatch .setattr (model , "_send_raw_message" , fake_send_raw )
1419+
1420+ await model .send_event (
1421+ RealtimeModelSendRawMessage (
1422+ message = {
1423+ "type" : "response.create" ,
1424+ "other_data" : {"response" : {"instructions" : "Say hello." }},
1425+ }
1426+ )
1427+ )
1428+ await response_create_started .wait ()
1429+
1430+ await model ._send_tool_output (
1431+ RealtimeModelSendToolOutput (
1432+ tool_call = RealtimeModelToolCallEvent (name = "t" , call_id = "c" , arguments = "{}" ),
1433+ output = "ok" ,
1434+ start_response = True ,
1435+ )
1436+ )
1437+ await asyncio .sleep (0 )
1438+
1439+ assert payload_types == ["response.create" , "conversation.item.create" ]
1440+
1441+ allow_response_create_send .set ()
1442+ await asyncio .sleep (0 )
1443+
1444+ assert payload_types .count ("response.create" ) == 1
1445+
1446+ await model ._mark_response_created ()
1447+ await model ._mark_response_done ()
1448+ await asyncio .sleep (0 )
1449+
1450+ assert payload_types .count ("response.create" ) == 2
1451+ assert payload_types [- 1 ] == "response.create"
1452+
14031453 def test_add_remove_listener_and_tools_conversion (self , model ):
14041454 listener = AsyncMock ()
14051455 model .add_listener (listener )
0 commit comments