fix: resolve tool cache invalidation bug and bedrock HTTP/2 compatibility #1067
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes two MEDIUM priority bugs affecting SDK functionality.
1. Tool Runner Cache Invalidation Bug
Problem:
BaseToolRunner.set_messages_params()promises to "invalidate any cached tool responses" in its docstring, but never actually cleared_cached_tool_call_response. This caused:tool_use_id_messages_modifiedflag wasn't setFix:
_cached_tool_call_response = Nonewhen params change_messages_modified = Trueto prevent message duplication2. Bedrock HTTP/2 KeyError
Problem:
get_auth_headers()unconditionally executeddel headers["connection"]:Fix:
headers.pop("connection", None)for safe removalImplementation Details
Cache Invalidation
src/anthropic/lib/tools/_beta_runner.py:79-92_paramsbut never cleared cached tool responsesself._cached_tool_call_response = None- clears cached tool responseself._messages_modified = True- prevents message duplication in loopsHTTP/2 Compatibility
src/anthropic/lib/bedrock/_auth.py:56-61del headers["connection"]assumes header existsheaders.pop("connection", None)httpx.Headers(case-insensitive) and plain dictsTesting
Changes
src/anthropic/lib/tools/_beta_runner.py:91-92self._cached_tool_call_response = Noneself._messages_modified = Truesrc/anthropic/lib/bedrock/_auth.py:61del headers["connection"]toheaders.pop("connection", None)Impact