Summary
Prevent MCP client leaks when one createMCPClient call fails after another call succeeds.
Required changes
Update executeAgentBlock to retain every successfully created MCP client when MCP client initialization has a partial failure. Re-throw the startup failure after retaining the fulfilled clients so the existing finally block closes them.
Add a regression test with one successful client creation and one rejected client creation. Verify that the successful client is closed.
Rationale
Promise.all rejects before assignment to mcpClients when any client creation fails. Clients that completed successfully before the rejection are then not available to the cleanup logic.
Affected areas
packages/runtime-core/src/agent-handler.ts
packages/runtime-core/src/execute-agent-block.test.ts
References
Acceptance criteria
Summary
Prevent MCP client leaks when one
createMCPClientcall fails after another call succeeds.Required changes
Update
executeAgentBlockto retain every successfully created MCP client when MCP client initialization has a partial failure. Re-throw the startup failure after retaining the fulfilled clients so the existingfinallyblock closes them.Add a regression test with one successful client creation and one rejected client creation. Verify that the successful client is closed.
Rationale
Promise.allrejects before assignment tomcpClientswhen any client creation fails. Clients that completed successfully before the rejection are then not available to the cleanup logic.Affected areas
packages/runtime-core/src/agent-handler.tspackages/runtime-core/src/execute-agent-block.test.tsReferences
Acceptance criteria