Skip to content

fix(vercel-ai-sdk): cancel the model Activity when a caller abortSignal aborts - #470

Merged
moetemp merged 5 commits into
mainfrom
fix/vercel-ai-sdk-abort-signal
Nov 13, 2026
Merged

moetemp merged 5 commits into
mainfrom
fix/vercel-ai-sdk-abort-signal

Conversation

@moetemp

@moetemp moetemp commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

What changed?

This PR makes a caller abortSignal work.

  • Workflow side. The signal isn't sent to the Activity. The Activity call runs in a CancellationScope, and an abort cancels it. A signal that is already aborted schedules no Activity.
  • Activity side. The three model Activities pass the Activity cancellation signal to the model as abortSignal.

Fixes #AI-952

Why?

An AbortSignal doesn't survive the JSON payload converter. It arrived in the Activity as {}, and a real provider fails on that on every attempt. The provider also never got a signal, so cancellation didn't stop the provider call.

A Workflow without a signal schedules the same Activity inputs as before.

The cancellation is behind a Workflow patch. An execution from an earlier version replays as it ran then, when an abort sent no command. The new behavior starts with its first model call that isn't a replay. A call without a signal records no patch marker.

Two limits stay. The AI SDK timeout option still doesn't work in the sandbox, so the README says to use startToCloseTimeout. And a running Activity learns about cancellation only through heartbeats, which #465 adds.

How did you test it?

  • Unit tests. They cover a signal that never aborts, one that is already aborted, and an abort during generateText and streamText.
  • Histories recorded on main replay on this branch.
  • A history recorded on the old behavior, where the signal aborts while invokeEmbeddingModel runs, replays on this branch. It fails to replay without the patch gate.
  • make lint and make test pass in typescript/vercel-ai-sdk.
  • I didn't test firstChunkMs and chunkMs of streamText.

@moetemp
moetemp force-pushed the fix/vercel-ai-sdk-abort-signal branch from c8af963 to 6e41d0d Compare November 12, 2026 06:51
@moetemp
moetemp marked this pull request as ready for review November 12, 2026 07:21
@moetemp
moetemp requested a review from a team as a code owner November 12, 2026 07:21

@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 cancellation change breaks replay of existing embedding histories where the caller's signal aborted. It needs a compatibility patch or an explicit breaking-change migration policy.

campoy added a commit that referenced this pull request Nov 13, 2026
…tbeat timeout (#510)

## What was changed

`TemporalLanguageModel` and `TemporalEmbeddingModel` now give their
Activities (`invokeModel`, `invokeModelStreaming` and
`invokeEmbeddingModel`) a 10-second `heartbeatTimeout` when the options
don't set one. `TemporalProvider` builds its models with its `default`,
`languageModel` and `embeddingModel` options, so it gets the default
too.

- The Activities already heartbeat on a timer at half the timeout
(#465), so they don't change.
- A `heartbeatTimeout` you set wins, and `heartbeatTimeout: 0` turns it
off. The default is applied with `??`, so a 0 passes through, and
Temporal schedules it as no heartbeat timeout.
- The README said the Activities send no heartbeat without a
`heartbeatTimeout`. It now gives the default and how to turn it off.

The MCP Activities don't heartbeat yet, so they still get no heartbeat
timeout.

## Why?

Without a heartbeat timeout, these Activities never heartbeat while they
wait on the provider. So a cancel never reaches the call, and a lost
Worker goes unnoticed until the 10-minute start-to-close timeout. #491
has the details, and the measurements behind 10 seconds.

Does this break anything? Not replay: when core replays a scheduled
Activity, it only compares its ID and type. I recorded a History for
each of the three Activities without this change, and all three replay
with it. But a call that didn't set `heartbeatTimeout` now heartbeats,
which in Temporal Cloud is at most one Action every 8 seconds of a
running call. And a Worker whose event loop is blocked for about 10
seconds now fails the call with a heartbeat timeout, and retries it.

This goes well with #470, which passes the Activity's cancellation
signal to the model. Without a heartbeat timeout, that signal never
fires while the call waits on the provider.

This PR and #469 both change the `proxyActivities` options in
`TemporalEmbeddingModel.doEmbed`. Whichever merges second keeps both.

## Checklist

1. Closes #509

2. How was this tested:
- `Model activity (<call>) heartbeats while the provider is slow` now
runs each call three times and reads the Activity's heartbeat timeout
from History: 1 second when set (which passes only if the Activity
heartbeats, since each call takes 2 seconds), 10 seconds by default, and
none with `0`. Without the change, all three tests fail on the default:
     ```
     Difference (- actual, + expected):

       [
     -   undefined,
     +   10000,
       ]
     ```
- With `||` in place of `??`, the `0` case gets 10 seconds and fails, so
the test covers the opt-out too.
- Locally, `make test` (86 passed, 1 skipped), `make lint` and the
conventions check pass, on Node 24.

3. Any docs updates needed?
The README is updated here. Release notes should mention the new
default, and how to turn it off.
@moetemp
moetemp force-pushed the fix/vercel-ai-sdk-abort-signal branch from 4fe7325 to eb8a2cb Compare November 13, 2026 07:48
@moetemp
moetemp requested a review from brianstrauch November 13, 2026 07:56

@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 cancellation gate fixes the previously reported case, but the async wrapper still breaks replay for some signal-free concurrent calls. Targeted replay reproduced this regression; the full test suite was blocked by sandbox restrictions on server startup.

The signal reached the Activity as an empty object and failed every attempt. An abort now cancels the Activity, and the Activity passes its cancellation signal to the model.
On a loaded CI runner the Activity can take more than three seconds to start.
A history where a signal aborted while the model Activity ran holds no cancel request, so it did not replay.
The async wrapper added a promise turn to every model call, so commands could change order on replay of an older history.
@moetemp
moetemp force-pushed the fix/vercel-ai-sdk-abort-signal branch from 5d3ddfb to a6f52c9 Compare November 13, 2026 17:42
@moetemp
moetemp requested a review from brianstrauch November 13, 2026 17:52
@moetemp
moetemp merged commit 2795d5f into main Nov 13, 2026
15 checks passed
@moetemp
moetemp deleted the fix/vercel-ai-sdk-abort-signal branch November 13, 2026 18:30
moetemp added a commit that referenced this pull request Nov 13, 2026
### What changed?

This PR adds a "Plugin contract" section to `AGENTS.md` and a shared
test helper for payload round trips.

- `findPayloadChange(value)` sends a value through the default payload
converter and returns the first field that changed.
- The helper is in `typescript/_template` and the five TypeScript
plugins. `check_conventions.py` keeps the copies equal.
- `vercel-ai-sdk` gets a contract test for its Activity input and
results.
- The contract has six rules for plugins that run model or tool calls in
Activities.

This branch contains #465 to #470, because the contract test fails
without them. Those should merge first.

Fixes #AI-953

### Why?

The review of `@temporalio/vercel-ai-sdk` 2.0.0 found six defects. Three
had one cause. A value changed between the Workflow and the Activity,
and no test sent a real value through the converter. Each rule in the
contract comes from one of the six.

### How did you test it?

- [x] `make lint` and `make test` pass in `vercel-ai-sdk`, `langsmith`,
`openai-agents` and `strands-agents`.
- [x] `python3 scripts/ci/check_conventions.py` passes.
- [ ] `make test` in `google-adk` fails on my machine in the
`strict-layout` cleanup hook. It fails the same way on `main`.
- [ ] The four other plugins only get the helper. There's no Python
helper yet.
campoy added a commit that referenced this pull request Nov 16, 2026
Replay is promised only within a major, and the next Vercel AI SDK
release is 2.0.0. Two patches only kept 1.x runs on their old paths, so
they go:

- vercel-ai-sdk-download-urls-in-model-activity (#468): the model always
  reports that it supports every URL, so the model Activity downloads them.
- vercel-ai-sdk-abort-signal-cancels-model-activity (#470): a caller's
  abortSignal always cancels the model Activity.

The README says which 1.x runs don't replay.
campoy added a commit that referenced this pull request Nov 16, 2026
…586)

## What was changed

The next Vercel AI SDK release is 2.0.0, so its current major is 2, and
replay is promised only within a major. Two patches only keep 1.x runs
on their old paths, so let's remove them before 2.0:

- `vercel-ai-sdk-download-urls-in-model-activity` (#468): the model
always reports that it supports every URL, so URL parts always go to the
model Activity, which downloads them.
- `vercel-ai-sdk-abort-signal-cancels-model-activity` (#470): a caller's
`abortSignal` always cancels the model Activity.

The README drops both patch notes and says which 1.x runs don't replay.

## What will you notice? (Breaking)

Two kinds of 1.x run don't replay on 2.0. Let them finish on 1.x Workers
before you upgrade, or keep them there with Worker Versioning:

- A run in which an `experimental_download` function scheduled an
Activity for a URL. On 2.0 the model call comes first: `[TMPRL1100]
Activity type of scheduled event 'downloadNotes' does not match activity
type of activity command 'invokeModel'`.
- A run in which a signal aborted while a model or embedding call ran.
On 1.x the abort sent no command, and on 2.0 it cancels the Activity, so
sdk-core fails the replay with `Fatal error in workflow machines:
ActivityMachine in state ScheduledActivityCancelCommandCreated says the
transition is invalid`.

A run on a `main` build since #468 or #470 that took the new path
recorded the marker, so it doesn't replay either. No release wrote those
markers.

## Why?

We decided that replay is promised only within a major, and that a gate
that only protects an older major's runs is removed before the next
major ships. The Vercel AI SDK plugin's next release is 2.0.0, so these
gates go before it.

## Checklist

1. No issue.

2. How was this tested:
- `make sync`, `make lint` and `make test` for
`typescript/vercel-ai-sdk`, in Docker with Node 24: 133 tests passed.
- Replay: the three 1.x histories that #565 stops replaying, run through
the replay tests #565 removes, on #565 and on this PR. On #565 all three
replay. On this PR, the `experimental_download` and abort histories fail
as above, and the one with a model call next to a plain Activity still
replays.

3. Any docs updates needed? The README changes are here.
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.

2 participants