Skip to content

improvement: cache Daytona client and improve error handling#3

Open
hjpinheiro wants to merge 1 commit into
daytona:mainfrom
hjpinheiro:improvement/client-caching-and-errors
Open

improvement: cache Daytona client and improve error handling#3
hjpinheiro wants to merge 1 commit into
daytona:mainfrom
hjpinheiro:improvement/client-caching-and-errors

Conversation

@hjpinheiro

Copy link
Copy Markdown

Summary

Two improvements to _client.py:

1. Client caching

build_client() created a new Daytona instance (with new HTTP session/connection pool) on every tool invocation. Since the plugin daemon is a long-running process, caching the client by credentials hash avoids redundant connection setup.

# Before — new instance every call:
def build_client(credentials):
    return Daytona(config)

# After — cached per unique credentials:
_client_cache: dict[str, Daytona] = {}

def build_client(credentials):
    key = _cache_key(credentials)
    if key not in _client_cache:
        _client_cache[key] = Daytona(config)
    return _client_cache[key]

The cache key is a SHA-256 hash of api_key + api_url, so different credentials get different clients.

2. Broader error handling in get_sandbox()

Previously only DaytonaNotFoundError was caught. SDK errors like auth failures, rate limits, or server errors leaked as raw exceptions. Now also catches DaytonaError (the parent class) and converts to a descriptive ValueError.

Testing

  • py_compile passes
  • DaytonaError import verified against daytona==0.187.0

build_client() previously created a new Daytona instance on every tool
invocation. Since the plugin daemon is a long-running process, cache the
client by credentials hash to avoid redundant connection setup.

Also catch DaytonaError (parent class) in get_sandbox() to provide clear
ValueError messages for SDK errors beyond not-found (auth failures, rate
limits, server errors).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants