Skip to content

fix: use safe dual-access pattern in CancelledError handler#6

Merged
bkrabach merged 1 commit intomainfrom
fix/cancelled-error-dict-tool-calls
Feb 23, 2026
Merged

fix: use safe dual-access pattern in CancelledError handler#6
bkrabach merged 1 commit intomainfrom
fix/cancelled-error-dict-tool-calls

Conversation

@bkrabach
Copy link
Copy Markdown
Collaborator

Summary

The asyncio.CancelledError handler at lines 536-537 used bare attribute access (tc.id, tc.name) on tool_call objects that may be plain dicts. This crashes with AttributeError: '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: Replace tc.id and tc.name with safe getattr/.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_calls

Test Plan

  • 28/28 tests pass (including 2 new regression tests)
  • Red-green cycle verified: tests fail with AttributeError before fix, pass after
  • ruff format + lint: clean
  • pyright: clean
  • No bare tc.id or tc.name remaining in file

🤖 Generated with Amplifier

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>
@bkrabach bkrabach merged commit 3a0246f into main Feb 23, 2026
@bkrabach bkrabach deleted the fix/cancelled-error-dict-tool-calls branch February 23, 2026 15:22
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.

1 participant