In index.js runAgentTurn() (around the step-finish event branch, ~line 855), releaseToolBridge(bridge) is called in the finally block of the outer try, but the inner try/catch around client.session.abort() only suppresses the error — it does not break out of the event-stream loop on abort failure, so the loop continues consuming events. If a subsequent session.error event then throws before the finally runs (e.g. due to an unhandled rejection or a re-throw from the for await body), the finally is still reached, which is correct. However, the stream subscription object returned by client.event.subscribe() is never explicitly closed/cancelled after the for await loop exits; there is no stream.return() or equivalent call in the finally. If the underlying async iterator does not auto-close, this leaks the server-sent-event connection for the lifetime of the process. The fix is to call stream.return?.() in the finally block alongside releaseToolBridge(bridge).
In
index.jsrunAgentTurn()(around thestep-finishevent branch, ~line 855),releaseToolBridge(bridge)is called in thefinallyblock of the outertry, but the innertry/catcharoundclient.session.abort()only suppresses the error — it does notbreakout of the event-stream loop on abort failure, so the loop continues consuming events. If a subsequentsession.errorevent then throws before thefinallyruns (e.g. due to an unhandled rejection or a re-throw from thefor awaitbody), thefinallyis still reached, which is correct. However, thestreamsubscription object returned byclient.event.subscribe()is never explicitly closed/cancelled after thefor awaitloop exits; there is nostream.return()or equivalent call in thefinally. If the underlying async iterator does not auto-close, this leaks the server-sent-event connection for the lifetime of the process. The fix is to callstream.return?.()in thefinallyblock alongsidereleaseToolBridge(bridge).