fix: use safe dual-access pattern in CancelledError handler#6
Merged
Conversation
Replace bare tc.id and tc.name attribute access with the safe getattr/dict.get dual-access pattern already used at every other tool_call access site in the file. Prevents AttributeError when providers return tool_calls as plain dicts and the user cancels during tool execution. Adds regression tests verifying CancelledError handler works with dict-based tool_calls. 🤖 Generated with [Amplifier](https://github.com/microsoft/amplifier) Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
The
asyncio.CancelledErrorhandler at lines 536-537 used bare attribute access (tc.id,tc.name) on tool_call objects that may be plain dicts. This crashes withAttributeError: 'dict' object has no attribute 'id'when providers return tool_calls as dicts and the user cancels during tool execution.Every other access site in the file (9 of them, across 3 locations) already uses the safe dual-access pattern:
getattr(tc, "id", None) or tc.get("id"). This fix applies the same pattern to the 2 remaining unsafe sites.Changes
amplifier_module_loop_basic/__init__.py: Replacetc.idandtc.namewith safegetattr/.get()dual-access pattern (2 lines)tests/test_cancelled_error_dict_tool_calls.py: New regression tests verifying CancelledError handler works with dict-based tool_callsTest Plan
AttributeErrorbefore fix, pass aftertc.idortc.nameremaining in file🤖 Generated with Amplifier