@@ -138,6 +138,49 @@ describe("turnStateFromEvent", () => {
138138 expect ( bothDone . activeToolCalls ) . toHaveLength ( 0 ) ;
139139 } ) ;
140140
141+ test ( "tool.done only sets awaitingResponse once every parallel call has finished" , ( ) => {
142+ // Regression for CL-5661: with a fan-out of two outstanding calls, the
143+ // first tool.done must not claim the turn is idle while the second call
144+ // is still running — that falsely tells consumers (stall watchdog,
145+ // status chrome) the model is the only thing left to wait on.
146+ const running = fold ( [
147+ { type : "inference.start" } ,
148+ { type : "tool.start" , data : { call : { id : "call_1" , name : "grep" } } } ,
149+ { type : "tool.start" , data : { call : { id : "call_2" , name : "bash" } } } ,
150+ ] ) ;
151+ expect ( running . activeToolCalls ) . toHaveLength ( 2 ) ;
152+ expect ( running . awaitingResponse ) . toBe ( false ) ;
153+
154+ const oneDone = turnStateFromEvent (
155+ running ,
156+ { type : "tool.done" , data : { result : { callId : "call_1" } } } ,
157+ 200 ,
158+ ) ;
159+ expect ( oneDone . activeToolCalls ) . toHaveLength ( 1 ) ;
160+ expect ( oneDone . awaitingResponse ) . toBe ( false ) ;
161+
162+ const bothDone = turnStateFromEvent (
163+ oneDone ,
164+ { type : "tool.done" , data : { result : { callId : "call_2" } } } ,
165+ 201 ,
166+ ) ;
167+ expect ( bothDone . activeToolCalls ) . toHaveLength ( 0 ) ;
168+ expect ( bothDone . awaitingResponse ) . toBe ( true ) ;
169+ } ) ;
170+
171+ test ( "a lone tool.done still sets awaitingResponse" , ( ) => {
172+ const running = fold ( [
173+ { type : "inference.start" } ,
174+ { type : "tool.start" , data : { call : { id : "call_1" , name : "bash" } } } ,
175+ ] ) ;
176+ const done = turnStateFromEvent (
177+ running ,
178+ { type : "tool.done" , data : { result : { callId : "call_1" } } } ,
179+ 200 ,
180+ ) ;
181+ expect ( done . awaitingResponse ) . toBe ( true ) ;
182+ } ) ;
183+
141184 test ( "a second call to the same tool name does not inherit a finished call's id" , ( ) => {
142185 const firstDone = fold ( [
143186 { type : "inference.start" } ,
0 commit comments