fix: interrupt message output before tool result

This commit is contained in:
Xin Wang
2026-08-04 09:30:52 +08:00
parent d068927b53
commit a16ecd8e01
10 changed files with 152 additions and 37 deletions

View File

@@ -138,6 +138,51 @@ class ClientToolExecutorTests(unittest.IsolatedAsyncioTestCase):
class ClientToolBrokerTests(unittest.IsolatedAsyncioTestCase):
async def test_interrupts_before_resolving_configured_result(self):
broker = ClientToolBroker()
outbound = []
observed_future_states = []
async def push_frame(frame, direction=FrameDirection.DOWNSTREAM):
outbound.append((frame, direction))
async def broadcast_interruption():
observed_future_states.append(
[pending.future.done() for pending in broker._pending.values()]
)
broker.push_frame = push_frame
broker.broadcast_interruption = broadcast_interruption
call = asyncio.create_task(
broker.call(
"show_message",
{},
timeout_seconds=1,
response_wait_mode="session",
interrupt_on_result=True,
)
)
await asyncio.sleep(0)
message = outbound[0][0].message
await broker.process_frame(
InputTransportMessageFrame(
message={
"type": "client-tool-result",
"tool_call_id": message["tool_call_id"],
"status": "ok",
"data": {"action": "confirmed"},
}
),
FrameDirection.DOWNSTREAM,
)
self.assertEqual(observed_future_states, [[False]])
self.assertEqual(
await call,
{"status": "ok", "data": {"action": "confirmed"}},
)
async def test_correlates_result_and_times_out(self):
broker = ClientToolBroker()
outbound = []