Skip to content

fix: Potentially Undisposed SDK Clients in API Providers (api_provider_clients) #4238

@kiwina

Description

@kiwina

name: Bug Report
description: Potentially Undisposed SDK Clients in API Providers
labels: ["bug", "memory-leak", "likely", "api-providers", "auto-generated"]

Thanks for your report! Please check existing issues first:
👉 https://github.com/RooCodeInc/Roo-Code/issues

App Version

N/A (Static Analysis - Detected in api_provider_clients)

API Provider

Multiple (Anthropic, OpenAI, Gemini, Ollama, Bedrock, OpenRouter)

Model Used

N/A (SDK Clients)

🔁 Steps to Reproduce

  1. Setup: A Task instance is created, which in turn instantiates an API provider handler (e.g., AnthropicHandler, OpenAIHandler).
  2. Exact actions:
    • The API provider handler's constructor creates an SDK client (e.g., new Anthropic(), new OpenAI()).
    • The Task instance is later aborted or disposed of, or an error occurs preventing its full cleanup.
  3. What happened after each step:
    • The Task.abortTask() or Task.dispose() methods are called (or are intended to be called).
    • Currently, these methods do not explicitly call a dispose method on the this.api handler.
    • The API provider handlers themselves do not have dispose methods to clean up their SDK clients.
    • The SDK client may remain active, potentially holding resources like network connections or internal caches.

💥 Outcome Summary

Expected all SDK clients created by API provider handlers to be explicitly disposed of when the parent Task is cleaned up. However, the lack of dispose methods in the handlers and the Task not calling such methods on its api property can lead to resource leaks if SDKs do not perfectly self-manage all resources or if Task instances are orphaned.

📄 Relevant Logs or Errors (Optional)

Summary from leak-report/likely/api_provider_clients.md:

Various API provider handlers ... instantiate SDK client objects in their constructors... These provider handler classes do not have explicit dispose() or close() methods... If a Task instance is not properly disposed of... the ApiHandler instance it holds, along with the underlying SDK client, will also not be explicitly cleaned up. The Task.abortTask() method does not currently have explicit calls to dispose of its this.api handler.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue - Needs ScopingValid, but needs effort estimate or design input before work can start.bugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions