Skip to content

fix(strands_agents): install the failure converter with a non-default payload converter - #392

Merged
brianstrauch merged 4 commits into
temporalio:mainfrom
pcbeingused333:fix/strands-failure-converter-custom-payload
Nov 3, 2026
Merged

brianstrauch merged 4 commits into
temporalio:mainfrom
pcbeingused333:fix/strands-failure-converter-custom-payload

Conversation

@pcbeingused333

@pcbeingused333 pcbeingused333 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #299

Root cause

_data_converter in the Strands plugin returned the caller's DataConverter unchanged whenever its payload converter was not DefaultPayloadConverter (for example pydantic_data_converter). StrandsFailureConverter was therefore never installed. An Activity tool's InterruptException crossed the Activity boundary as a retryable ApplicationError, so TemporalActivityTool could not rebuild the interrupt. MaxTokensReachedException, ContextWindowOverflowException, StructuredOutputException and SessionException also stayed retryable.

Fix

Keep the caller's payload converter and add the Strands exception handling on top of the caller's failure converter: a DefaultFailureConverter subclass gets the Strands to_failure mixed in, so its own from_failure still decodes recorded failures (client and replayer); the plain default converters map to the Strands ones as before (encoded attributes stay encoded); a converter that does not subclass DefaultFailureConverter is kept unchanged. README note updated.

Tests

  • New test_custom_payload_converter_gets_strands_failure_converter (client and replayer) feeds pydantic_data_converter through the plugin and checks the payload converter is kept, the failure converter is StrandsFailureConverter, and an InterruptException becomes a non-retryable StrandsInterrupt failure. It fails before the change and passes after.
  • test_custom_payload_converter_is_preserved now checks the payload converter class and codec instead of object identity.
  • test_custom_payload_converter_keeps_caller_failure_decoding and test_minimal_failure_converter_with_custom_payload_converter_is_kept (client and replayer) cover the caller's decoding on this path.
  • tests/test_plugin.py: 18 passed.

This change was prepared with the help of an AI assistant (Claude Code), and the author is responsible for the change.

🤖 Generated with Claude Code

… payload converter

StrandsPlugin returned a data converter with a non-default payload converter
unchanged, so Activity-tool interrupts and the non-retryable Strands exceptions
crossed the Activity boundary as ordinary retryable ApplicationErrors. Keep the
caller's payload converter but always install the Strands failure converter.
@pcbeingused333
pcbeingused333 requested a review from a team as a code owner November 3, 2026 15:06
@CLAassistant

CLAassistant commented Nov 3, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@brianstrauch

Copy link
Copy Markdown
Member

Please fix the lint failure @pcbeingused333

@brianstrauch brianstrauch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The interrupt fix introduces a custom failure-decoding regression that can break workflow replay.

Comment on lines +208 to +212
else:
# Keep the caller's payload converter (for example ``pydantic_data_converter``),
# but still install the failure converter: Activity-tool interrupts and the
# non-retryable Strands exceptions depend on it.
payload_converter_class = converter.payload_converter_class

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Preserve custom failure decoding for non-default payload converters

When a caller supplies both a non-default payload converter and a custom failure converter, this branch now falls through to code that discards the caller's from_failure. For example, combining the existing DomainFailureConverter with pydantic_data_converter previously decoded recorded failures as DomainError, but now produces ApplicationError, for both client and replayer. This changes exception-handling branches during replay and can break existing workflows. Add Strands-specific failure handling without replacing custom decoding on this previously preserved path.

…efault payload converter

With a non-default payload converter the caller's failure converter was always
preserved. The previous commit replaced it, which changes how recorded failures
decode (client and replayer). Add the Strands exception handling on top of the
caller's class instead, so its from_failure keeps running.
A failure converter that does not subclass DefaultFailureConverter cannot take
the Strands handling by subclassing. Return it as supplied, as before, so its
from_failure keeps decoding recorded failures.
@pcbeingused333

Copy link
Copy Markdown
Contributor Author

Good catch, thanks. Fixed in 50d2ad0 and d6a8a63: on the non-default payload converter path the caller's failure converter is no longer replaced. A DefaultFailureConverter subclass gets the Strands handling mixed in on top (StrandsFailureConverter first in the MRO), so to_failure for other exceptions and from_failure are still the caller's, and your DomainFailureConverter + pydantic_data_converter example decodes DomainError again for both client and replayer. A converter that does not build on DefaultFailureConverter is kept exactly as supplied. Running the plugin twice keeps the wrapped class. New tests cover both cases; tests/test_plugin.py: 18 passed, ruff clean.

This reply was drafted with the help of an AI assistant (Claude Code).

@brianstrauch brianstrauch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@brianstrauch
brianstrauch merged commit f633bed into temporalio:main Nov 3, 2026
27 checks passed
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.

[Bug] strands_agents: a caller payload converter, such as pydantic_data_converter, turns off Activity-tool interrupts

3 participants