Skip to content

fix: do not synthesize exception for cancelled tools#2106

Open
Gastly wants to merge 1 commit intostrands-agents:mainfrom
Gastly:fix/cancel-tool-exception-propagation
Open

fix: do not synthesize exception for cancelled tools#2106
Gastly wants to merge 1 commit intostrands-agents:mainfrom
Gastly:fix/cancel-tool-exception-propagation

Conversation

@Gastly
Copy link
Copy Markdown

@Gastly Gastly commented Apr 10, 2026

Description

After #2046 , setting cancel_tool on a BeforeToolCallEvent now populates AfterToolCallEvent.exception with a synthesized exception which cannot be overwritten, causing tool cancellations to appear as failures to downstream hooks.

Cancellation is a deliberate action, not a failure. AfterToolCallEvent.cancel_message already exists to identify cancelled tools; hooks can use it to distinguish cancellations from genuine exceptions without needing a fake exception object. Additionally, tool result status remains as error for cancellations.

Span observability is preserved: StatusCode.ERROR is now set by inspecting tool_result["status"] directly rather than relying on a synthesized exception.

Public API Changes

AfterToolCallEvent.exception is once again None for cancelled tools. cancel_message remains the correct field to detect cancellations.

Related Issues

#2046

Documentation PR

No documentation changes needed.

Type of Change

Bug fix

Testing

  • [x ] I ran hatch run prepare

Checklist

  • [x ] I have read the CONTRIBUTING document
  • [ x] I have added any necessary tests that prove my fix is effective or my feature works
  • [ x] I have updated the documentation accordingly
  • [ x] I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • [ x] My changes generate no new warnings
  • [ x] Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant