Skip to content

fix(strands): let the agent trim the conversation on a context overflow (breaking) - #279

Closed
campoy wants to merge 3 commits into
fix/strands-typescript-plugin-replaces-caller-failure-converterfrom
fix/strands-typescript-context-overflow-recovery-skipped
Closed

campoy wants to merge 3 commits into
fix/strands-typescript-plugin-replaces-caller-failure-converterfrom
fix/strands-typescript-context-overflow-recovery-skipped

Conversation

@campoy

@campoy campoy commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

What was changed

TemporalModel.stream rethrows a model Activity failure of type ContextWindowOverflowError as Strands' own ContextWindowOverflowError. The agent's conversation manager then trims the conversation and calls the model again, as it does outside Temporal. The README's Retries section says so, with an upgrade note.

Stacked on #200, whose Activity interceptor sends the overflow as a non-retryable failure of that type. Review base: #200's branch.

Why?

Strands' conversation managers recover from a context overflow by trimming the oldest messages and retrying, but only when the model call fails with ContextWindowOverflowError. Through the plugin, the overflow reached the agent as an ActivityFailure, which Strands wraps in a plain ModelError. Nothing was trimmed: the error left agent.invoke and, uncaught, failed the Workflow Task on every attempt, so a chat whose history outgrew the model's context stopped answering. A code owner's review of #200 pointed out that nothing decoded the typed failure back.

Breaking change

  • A run whose Workflow code caught that overflow before this version calls the model again on replay instead, and fails with [TMPRL1100].
  • A run whose Workflow Task kept failing on the overflow continues once this version runs: the agent trims and the turn answers.

Upgrade: let runs that caught a context overflow finish before you upgrade, or keep them on the earlier version with Worker Versioning.

Checklist

  1. No issue of its own; follow-up to fix(strands): keep the caller's failure converter and turn Strands errors into Temporal failures (breaking) #200 ([Bug] strands-agents (TypeScript): StrandsPlugin replaces the caller's failure converter #199).

  2. How was this tested:

    • a context overflow in the model activity lets the agent trim the conversation: a stub model holds six messages. Three turns fill them, and the fourth overflows; the agent trims and answers, keeping six messages. With fix(strands): keep the caller's failure converter and turn Strands errors into Temporal failures (breaking) #200's head (cb4cfa4) the Workflow Task fails with Activity task failed until the run times out.
    • Replay check against a local dev server, Workers with a Workflow cache of 0, and real agent Workflows on that stub model:
      • Histories recorded on cb4cfa4 without an overflow replay on this change, and the other way around.
      • A cb4cfa4 run that caught the overflow fails with [TMPRL1100] on this change.
      • A cb4cfa4 run whose Workflow Task kept failing on the overflow completes on this change with the trimmed conversation, and its history replays here.
      • Rolling back to cb4cfa4: a trimmed history fails replay there, since that code lets the overflow escape again.
      • A control Workflow with one extra Activity fails with [TMPRL1100].
    • Local, in a Linux container with Node 24 and pnpm 10.27.0: make sync, make lint, make test (39 tests; 40 after merging fix(strands): keep the caller's failure converter and turn Strands errors into Temporal failures (breaking) #200's caae774 into this branch as f1744e4), make build, the npm package check, the smoke install and check_conventions.py pass, and Prettier with the SDK settings reports the changed files clean. The Node 22, macOS and Windows cells did not run locally.
    • Not run against a real model provider.
  3. Any docs updates needed?
    The plugin README is updated. Release notes must say that context overflows are now trimmed and which runs started before the upgrade do not replay on it.

Not covered

…ow (breaking)

A ContextWindowOverflowError from the model activity reached the agent
as an ActivityFailure, which Strands wraps in a plain ModelError. The
conversation manager only trims on ContextWindowOverflowError, so it
never ran: the error left agent.invoke and, uncaught, failed the
workflow task on every attempt.

TemporalModel.stream now rethrows a failure of type
ContextWindowOverflowError, which the plugin's activity interceptor
produces, as Strands' own ContextWindowOverflowError. The conversation
manager then trims and calls the model again, as outside Temporal.

Breaking change: a run whose workflow code caught that overflow before
this version calls the model again on replay and fails with a
nondeterminism error. A run whose workflow task kept failing on it
continues and trims.
…places-caller-failure-converter' into fix/strands-typescript-context-overflow-recovery-skipped

# Conflicts:
#	typescript/strands-agents/README.md
#	typescript/strands-agents/src/__tests__/workflows/strands.ts
…places-caller-failure-converter' into fix/strands-typescript-context-overflow-recovery-skipped
@campoy

campoy commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Folded into #200 as 455d742, at the reviewers' request to ship the overflow decode with the interceptor change. The review history stays here.

@campoy campoy closed this Oct 30, 2026
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