Async context-manager tools leak entered resources when callable validation fails

Aperta
#1,977 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@sylvesterkaczmarek ci sta già lavorando.

Dal 5/10/2026.

  • #1978 di @sylvesterkaczmarek — aperta
  • #2001 di @iosayin — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python
Ambito
api, backend

Direzione di ricerca

Start at beta_async_tool and compare its async context-manager setup failure path with the synchronous branch, which the issue says already cleans up construction failures. Run the two async regression cases described in the issue, including the case where __aexit__ suppresses the validation exception; done means awaited cleanup receives the active exception and the setup failure is re-raised unless suppressed. A linked pull request is already open.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

On main at 18f25547f20cf5f01da69ac611e700e3bc9ebf21, beta_async_tool enters an async context manager before validating its yielded callable. If pydantic.validate_call(inner) raises, the entered manager is neither exited immediately nor registered for subsequent tool cleanup.

A reproducible case is an @asynccontextmanager that acquires a resource and yields an async callable with an unsupported custom parameter type. Wrap it with beta_async_tool(name="invalid", input_schema={"type": "object"}) and invoke .call(...). Pydantic raises PydanticSchemaGenerationError, but the context manager's finally block has not run when that call finishes.

Expected: pass the active exception to __aexit__, await cleanup, and re-raise the setup failure. The synchronous context-manager branch already does this for construction failures.

Two async regression cases reproduce the missing cleanup, including a manager that tries to suppress the validation exception. A synchronous counterpart is a passing control. The async cleanup itself awaits, so checking only that an exit coroutine was created would not satisfy the regression.

Reproduced on macOS with Python 3.14.7 and Pydantic v2. No live API calls are needed.

Lingua principale
Python
Stelle
4.1k
Fork
915
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di anthropics/anthropic-sdk-python

Tutte le issue di anthropics/anthropic-sdk-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.