Repository navigation
fix(vercel-ai-sdk): heartbeat while the model Activities wait on the provider - #465
Merged
Merged
Conversation
A healthy provider call that took longer than heartbeatTimeout failed with a heartbeat timeout, and a cancellation request could not reach the Activity.
This was referenced Nov 11, 2026
moetemp
marked this pull request as ready for review
November 11, 2026 23:33
brianstrauch
approved these changes
Nov 12, 2026
This was referenced Nov 12, 2026
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
added a commit
that referenced
this pull request
Nov 13, 2026
…al aborts (#470) ### 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? - [x] Unit tests. They cover a signal that never aborts, one that is already aborted, and an abort during `generateText` and `streamText`. - [x] Histories recorded on `main` replay on this branch. - [x] 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. - [x] `make lint` and `make test` pass in `typescript/vercel-ai-sdk`. - [ ] I didn't test `firstChunkMs` and `chunkMs` of `streamText`.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed?
This PR makes the three model Activities heartbeat on a timer.
invokeModel,invokeModelStreamingandinvokeEmbeddingModelheartbeat at half theheartbeatTimeoutwhile they wait on the provider. Without aheartbeatTimeoutthey send nothing.invokeModelStreamingis retried.Fixes #AI-947
Why?
Only
invokeModelStreamingsent heartbeats, and only when a stream part arrived. AheartbeatTimeoutshorter than the time to the first token failed a healthy call. A cancellation request also didn't reach these Activities.The interval is the one
openai-agents,google-adkandstrands-agentsalready use. Recorded histories replay the same.How did you test it?
heartbeatTimeout: '1 second'fails onmainwith a heartbeat timeout, and passes here.make lintandmake testpass intypescript/vercel-ai-sdk.