Skip to content

Fix tool-bridge slot leak when session.abort() throws inside runAgentTurn #73

Description

@KochC

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions