Repository navigation
Release async tool contexts when callable validation fails - #1978
sylvesterkaczmarek wants to merge 1 commit into
Conversation
Signed-off-by: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com>
sigley
left a comment
There was a problem hiding this comment.
Validated exact head 05f9dedb independently. The async context-manager path enters the resource before pydantic.validate_call(inner); on validation failure this head now awaits __aexit__ with the active exception before re-raising, matching the synchronous cleanup behavior and preventing the entered resource from being stranded. The regressions also cover attempted suppression and verify cleanup is not repeated later. The branch merges cleanly with current main, the complete function-tool test file passes 27/27, and compile/diff checks are clean. This is the earlier, broader-tested branch for #1977, so I would consolidate here rather than duplicate the same production fix. I do not see a blocking correctness issue.
Fixes #1977.
If validation of the callable yielded by an async context manager fails, call and await
__aexit__with the active exception before re-raising. This mirrors the existing synchronous construction-failure path. Successful lazy initialization and normal tool cleanup remain unchanged.The new cases use real async context managers and real Pydantic schema failures. They verify that cleanup finishes before the error is returned, receives the original exception, cannot suppress the setup failure, and is not repeated by later cleanup. The synchronous failure case remains a passing control.
Validation
./scripts/lintpassed with all development extras installed, including Ruff, dependency-cap checks, strict Pyright and the import smoke test.git diff --checkpassed.Tests ran on macOS and use local fixtures rather than the configured API URL. The full repository suite and live sessions were not run. No public API, dependency, lockfile or workflow changes.