Repository navigation
Description
Is your feature request related to a problem? Please describe.
A running activity only hears about a cancel when it heartbeats. Most of our plugins heartbeat only if you set a heartbeat_timeout, and almost none set one for you. Many activities, like most MCP ones, never heartbeat at all.
So by default:
- A cancel never reaches a running call. A tripped guardrail ([Bug] openai_agents: stream topic subscribers get the rest of the answer after a parallel input guardrail trips #227, [Bug] openai-agents (TypeScript): stream topic subscribers get the rest of the answer after a parallel input guardrail trips #428), a cancelled Workflow, a framework timeout: the model or tool runs to the end, and we pay for it. Stream subscribers get the whole answer.
- A lost Worker goes unnoticed until start-to-close, 1 to 10 minutes depending on the plugin. The stream just stops, and then the retry streams a new answer after the partial one.
@JasonSteving99 found that this makes the fix in #228 do nothing with the defaults: the Workflow records the cancel, but the activity never hears it.
Why not heartbeat without a timeout? Then the SDK sends at most one heartbeat every 30 seconds, so the cancel can arrive 30 seconds late. @DABH found this on #228.
And why not set a timeout yourself? On an activity that never heartbeats, every call longer than the timeout fails and retries. #465 fixed that for the Vercel AI SDK model calls. Most MCP activities still have it.
Describe the solution you'd like
- Every activity a plugin defines heartbeats on a timer, at half the timeout, for as long as it runs. Not per chunk: a model can be quiet for a long time before its first token.
- Those activities get a 10-second
heartbeat_timeoutby default. A timeout you set wins, and you can turn it off. - Your own activities (
activity_as_tool,activity_node, LangGraph nodes) stay as they are.
Why 10 seconds? The SDK sends at most one heartbeat every 0.8 × the timeout, so the timeout sets how fast a cancel arrives. Here's what I measured (Python 3.13, temporalio 1.35.0, Temporal CLI 1.10.0 dev server):
heartbeat_timeout= 30s trip at 1.0s cancel reached the activity after 14.0s
heartbeat_timeout= 30s trip at 16.0s cancel reached the activity after 23.0s
heartbeat_timeout= 10s trip at 1.0s cancel reached the activity after 4.0s
heartbeat_timeout= 10s trip at 6.0s cancel reached the activity after 7.0s
heartbeat_timeout= 5s trip at 1.0s cancel reached the activity after 1.5s
heartbeat_timeout= 5s trip at 3.5s cancel reached the activity after 3.0s
At 30 seconds, many answers finish before the cancel lands. At 5, a Worker that stalls for 5 seconds times out, and we pay for the call twice. The Claude Agent SDK and Codex plugins already use 10.
It needs no version gate: replay only compares an activity's ID and type, and a run I recorded with no heartbeat timeout replayed fine with one.
What does it cost? In Temporal Cloud, a heartbeat is an Action only when it reaches the server: at most one every 8 seconds here. A 30-second streamed answer already sends up to about 300 Signals, and heartbeats add about 4. A 30-second call that doesn't stream goes from 1 Action to about 5, or $0.0002. If that matters to you, turn it off.
What each plugin needs, from reading main:
| Plugin | Needs only the default | Needs a timer first |
|---|---|---|
| Python OpenAI Agents | model calls, stateful MCP session | MCP operations, sandbox |
| TypeScript OpenAI Agents | model calls, stateful MCP session | MCP operations, sandbox |
| Python Deep Agents | everything (#350 adds 30 s) | |
| Python Strands | model calls, sandbox | model config read, MCP |
| TypeScript Strands | model calls | model config read, MCP |
| Python Google ADK | stateful MCP session | model calls (per chunk at best), MCP operations |
| TypeScript Google ADK | model calls, MCP | |
| Go Google ADK | everything (today 30 s, for streamed model calls only) | |
| Java Google ADK | MCP | model calls: the timer starts only after the model is built |
| Java Spring AI | chat model, MCP | |
| TypeScript Vercel AI SDK | model and embedding calls | MCP |
| Python google-genai | all 16 call types, MCP | |
Python MCP (temporalio-mcp, used by OpenAI Agents and Strands) |
all 7 operations | |
| Python Claude Agent SDK, Codex | nothing: they already use 10 s |
I left out Python typesafe (its calls are short, and it skips heartbeats on purpose) and Python LangGraph (every activity is your own node or task).
Where it stands (November 14):
- Merged:
temporalio-mcp(mcp: heartbeat while an MCP operation runs, with a 10-second default heartbeat timeout #494, released in 0.4.0), which Python OpenAI Agents' MCP operations use since Require temporalio-mcp 0.4 in OpenAI Agents and Strands #435; Python OpenAI Agents model calls (openai_agents: give model calls a 10-second default heartbeat timeout #496); Python Strands (strands_agents: give model and sandbox activities a 10-second default heartbeat timeout #504); TypeScript Google ADK (Give Google ADK TypeScript model and MCP Activities a 10-second default heartbeat timeout #506); TypeScript Strands (Give Strands TypeScript model calls a 10-second default heartbeat timeout #508); Vercel AI SDK (Give Vercel AI SDK model and embedding calls a 10-second default heartbeat timeout #510, Heartbeat Vercel AI SDK streamed model calls only on the timer #516); Go Google ADK (Give Google ADK Go model, MCP and A2A Activities a 10-second default heartbeat timeout #512). The Strands model config reads get no heartbeat timeout: they're synchronous, so they can't heartbeat. - In review: TypeScript OpenAI Agents ([typescript/openai-agents] give model calls a 10-second default heartbeat timeout #514), Python Google ADK ([python/google_adk] breaking: give model calls a 10-second default heartbeat timeout #520), google-genai (Breaking: give google-genai calls a 10-second default heartbeat timeout #551), TypeScript Google ADK's timer-only heartbeats ([typescript/google-adk] heartbeat streamed model calls only on the timer #518), and two docs follow-ups ([python/mcp] say that
timedelta(0)also turns heartbeats off #521, Say how to upgrade the Vercel AI SDK plugin from 1.0.0 with its heartbeat timeout #552). Deep Agents is in [python/deepagents] give model activities a default heartbeat timeout #350, still at 30 seconds. - After the GA releases: the OpenAI Agents sandbox (Python and TypeScript), MCP in the other plugins, including the stateful MCP sessions, and moving the Python OpenAI Agents and
temporalio-mcptimers toloop.call_later, like the rest. - Not planned yet: Java Google ADK and Java Spring AI.
Where a released version's activities don't heartbeat (Python Google ADK, google-genai, Vercel AI SDK, temporalio-mcp), a call that a new Workflow schedules fails on an older Worker after 10 seconds. So each one gets upgrade steps: in #520, #551 and #552, and in the temporalio-mcp 0.4.0 release notes.
Additional context
- @pingu1m, could [python/deepagents] give model activities a default heartbeat timeout #350 use 10 seconds, to match?
- Two more things this fixes:
- A slow stateful MCP operation with a heartbeat timeout stops showing up as "the dedicated Worker died" (OpenAI Agents and Google ADK).
- In TypeScript OpenAI Agents, the stateful MCP session hears
cleanup()within a heartbeat. Today it may not hear it until the run ends, and a new server with the same name fails until then.
- In TypeScript OpenAI Agents and the Vercel AI SDK, the cancel will arrive but won't stop the model call yet. That's [Bug] openai-agents and vercel-ai-sdk (TypeScript): a cancelled model Activity doesn't stop the model call #503. I'll file the other timeout problems I found separately and link them here.
- Related: [Bug] openai_agents: stream topic subscribers get the rest of the answer after a parallel input guardrail trips #227, Breaking: stop the OpenAI Agents streaming model activity when a parallel input guardrail trips #228 and [Bug] openai-agents (TypeScript): stream topic subscribers get the rest of the answer after a parallel input guardrail trips #428 (OpenAI Agents), [Bug] deepagents: model and tool activities get no heartbeat timeout by default, so the auto-heartbeater is inert, crash recovery waits out start-to-close, and cancellation never reaches a running model call #341 and [python/deepagents] give model activities a default heartbeat timeout #350 (Deep Agents), fix(vercel-ai-sdk): heartbeat while the model Activities wait on the provider #465 and fix(vercel-ai-sdk): cancel the model Activity when a caller abortSignal aborts #470 (Vercel AI SDK), fix(strands): give the model the activity's cancellation signal #297 (TypeScript Strands).
The script behind the numbers
"""How long does a cancel take to reach a heartbeating activity, for each heartbeat_timeout?
The activity heartbeats every heartbeat_timeout / 2, like the plugin's heartbeating().
The workflow cancels it after `trip_after` seconds. The latency is the time between
ActivityTaskCancelRequested and ActivityTaskCanceled in History.
"""
import asyncio
import uuid
from datetime import timedelta
from temporalio import activity, workflow
from temporalio.client import Client
from temporalio.testing import WorkflowEnvironment
from temporalio.worker import UnsandboxedWorkflowRunner, Worker
@activity.defn
async def stream() -> None:
timeout = activity.info().heartbeat_timeout
delay = timeout.total_seconds() / 2 if timeout else None
async def beat() -> None:
while True:
await asyncio.sleep(delay)
activity.heartbeat()
task = asyncio.create_task(beat()) if delay else None
try:
await asyncio.sleep(300)
finally:
if task:
task.cancel()
@workflow.defn
class Trip:
@workflow.run
async def run(self, heartbeat_s: float, trip_after: float) -> None:
handle = workflow.start_activity(
stream,
start_to_close_timeout=timedelta(seconds=300),
heartbeat_timeout=timedelta(seconds=heartbeat_s),
cancellation_type=workflow.ActivityCancellationType.WAIT_CANCELLATION_COMPLETED,
)
await asyncio.sleep(trip_after)
handle.cancel()
try:
await handle
except Exception:
pass
async def case(client: Client, heartbeat_s: float, trip_after: float) -> str:
handle = await client.start_workflow(
Trip.run, args=[heartbeat_s, trip_after], id=str(uuid.uuid4()), task_queue="tq"
)
await handle.result()
times = {}
async for e in handle.fetch_history_events():
name = e.WhichOneof("attributes")
if name in ("activity_task_cancel_requested_event_attributes", "activity_task_canceled_event_attributes"):
times[name] = e.event_time.ToDatetime()
latency = (
times["activity_task_canceled_event_attributes"]
- times["activity_task_cancel_requested_event_attributes"]
).total_seconds()
return f"heartbeat_timeout={heartbeat_s:>4}s trip at {trip_after:>4}s cancel reached the activity after {latency:5.1f}s"
async def main() -> None:
async with await WorkflowEnvironment.start_local() as env:
async with Worker(
env.client,
task_queue="tq",
workflows=[Trip],
activities=[stream],
workflow_runner=UnsandboxedWorkflowRunner(),
):
cases = []
for t in (30, 10, 5):
# Early in the call, and just after the first heartbeat went out.
cases += [(t, 1.0), (t, t / 2 + 1)]
for line in await asyncio.gather(*(case(env.client, t, a) for t, a in cases)):
print(line)
asyncio.run(main())
Activity
[-][Feature Request] Default heartbeat timeout for streaming model activities in every plugin[/-][+][Feature Request] Default heartbeat timeout for every plugin's own activities[/+]campoy commentedon Nov 12, 2026
I widened this from streaming model calls to every activity a plugin defines. A survey of all the plugins showed the same problem in non-streaming model calls, MCP and sandbox activities. Many of them never heartbeat at all, so they need a timer before they can take a default. I also added what it costs in Temporal Cloud Actions, and the plugins left out on purpose.
openai_agents: give model calls a 10-second default heartbeat timeout (…
Give Google ADK TypeScript model and MCP Activities a 10-second defau…
Give Strands TypeScript model calls a 10-second default heartbeat tim…
Give Vercel AI SDK model and embedding calls a 10-second default hear…
mcp: heartbeat while an MCP operation runs, with a 10-second default …
Give Google ADK Go model, MCP and A2A Activities a 10-second default …
Heartbeat Vercel AI SDK streamed model calls only on the timer (#516)
strands_agents: give model and sandbox activities a 10-second default…
Say how to upgrade the Vercel AI SDK plugin from 1.0.0 with its heart…
Breaking: give google-genai calls a 10-second default heartbeat timeo…
fix(deepagents): default model calls to a 10-second heartbeat timeout
Give Google ADK Python model calls a 10-second default heartbeat timeout
[python/google_adk] breaking: give model calls a 10-second default he…
[typescript/openai-agents] give model calls a 10-second default heart…
[typescript/google-adk] heartbeat streamed model calls only on the ti…