Repository navigation
[python/google_adk] breaking: give model calls a 10-second default heartbeat timeout - #520
Merged
Merged
Conversation
campoy
marked this pull request as ready for review
November 13, 2026 19:32
This was referenced Nov 14, 2026
campoy
added a commit
that referenced
this pull request
Nov 16, 2026
…beat timeout (#552) ## What was changed The Vercel AI SDK README now says how to upgrade from 1.0.0, and how to roll back, now that the model and embedding Activities get a 10-second heartbeat timeout by default (#510). ## Why? 1.0.0 schedules these Activities with no heartbeat timeout. Its `invokeModel` and `invokeEmbeddingModel` never heartbeat, and its `invokeModelStreaming` heartbeats only when a stream part arrives ([the only `heartbeat()` call in 1.0.0](https://github.com/temporalio/ai-integrations/blob/typescript/vercel-ai-sdk/v1.0.0/typescript/vercel-ai-sdk/src/activities.ts#L285)). But the timeout is recorded when a Workflow schedules the Activity, so whichever Worker runs it has to heartbeat. During a rolling upgrade, a call that a Workflow on the next version schedules and a 1.0.0 Worker runs fails with a heartbeat timeout after 10 seconds, and so does each retry. Does replay break? No: core only compares an Activity's ID and type. But a passing replay doesn't mean mixed versions work. So the README now gives the same steps that #520 and #551 give for Google ADK Python and google-genai: - Upgrade the Workers that run the model Activities first. If the same Workers run Workflows too, deploy with `heartbeatTimeout: 0` and remove it in a later deploy. - Before a rollback, deploy with `heartbeatTimeout: 0`, and wait for the calls scheduled before that deploy to finish. - Runs pinned with Worker Versioning avoid both. ## Checklist 1. No issue: a docs follow-up to #510, part of #491. 2. How was this tested: Docs only. The conventions check and `git diff --check` pass. To check the claims, I read 1.0.0's code: it sets no `heartbeatTimeout` default, and its only `heartbeat()` call is in `invokeModelStreaming`'s stream loop. On `main`, `TemporalProviderOptions.default` takes the `ActivityOptions` the example sets. #520 measured the failure itself on a local dev server: an Activity that doesn't heartbeat failed 10.02 seconds in, and both attempts of a retried one failed the same way. 3. Any docs updates needed? This is the docs update. The 2.0.0 release notes should carry the same upgrade step.
campoy
added a commit
that referenced
this pull request
Nov 16, 2026
…ut (#551) ## What was changed All 16 Gemini call activities (model calls, files, file search uploads, interactions and managed agents) now heartbeat on a timer, and `TemporalAsyncClient` gives them a 10-second `heartbeat_timeout` by default. - The timer beats at half the heartbeat timeout, and the first beat goes out half the timeout into the call. So with the default, a call shorter than 5 seconds sends none. Without a heartbeat timeout, the timer does nothing. - Temporal caps `heartbeat_timeout` at the activity's `start_to_close_timeout`, and the timer uses the capped value. So a shorter timeout, including a per-model-call `http_options.timeout` or the Interactions and Agents `timeout` argument, makes beats come sooner. With `http_options.timeout=2000`, History records a 2-second heartbeat timeout, and a 1.7-second call sends one heartbeat. `files.upload`, `files.download`, `files.register_files`, and file search store uploads pass `http_options.timeout` to the HTTP client instead. - The timer uses `loop.call_later` instead of a task, as Strands (#504) and Google ADK (#520) do. A task only starts its sleep at the call's first `await`, so anything that blocks the event loop before then pushes every beat back. - The interaction streams used to heartbeat once per event. They now use the same timer, so a model that's quiet for a while before its first event doesn't time out. With `heartbeat_timeout=None` or `timedelta(0)`, streams no longer heartbeat per event and cannot receive cancellation. With heartbeats enabled, a quiet stream stays alive until its HTTP or activity timeout; heartbeats no longer check stream progress. - The 10-second default is added to every config that leaves `heartbeat_timeout` out, including your own `activity_config`. A timeout you set wins, and `heartbeat_timeout=None` (or `timedelta(0)`) turns heartbeats off. - The README and the `activity_config` docstring say what the default does, what it costs, how to turn it off, and how to upgrade and roll back. `activity_as_tool` runs your own activities, so it stays as it is. MCP is out of scope for now. Does any of these activities block the event loop, so the timer can't run? Mostly no: google-genai reads upload files with `anyio`, and model, files and file search store calls refresh credentials on a thread. But on Vertex AI, `interactions` and `agents` don't. They get their token through a sync provider that calls `credentials.refresh()` on the event loop. That happens when the worker's `genai.Client` has no token yet, and again when the token expires, about once an hour. I checked it on a local dev server with a credential refresh that takes 11 seconds and HTTP 200 responses: | Call | `heartbeat_timeout` | Result | |---|---|---| | `agents.list()` | default | fails with `activity Heartbeat timeout` | | `interactions.create()` | default | fails with `activity Heartbeat timeout` | | `agents.list()` | `None` | succeeds | | `models.generate_content()` | default | succeeds, and heartbeats | With a 4-second refresh, both `agents.list()` and `interactions.create()` succeed. This is google-genai's behavior, so following AGENTS.md, the README documents it as a limit instead of working around it here: if your credential refresh can be slower than the heartbeat timeout, set a longer one, or `None`. A blocked loop also stops the timers of other activities sharing it, so a slow refresh can fail other running Gemini calls even if it takes less than their heartbeat timeout. Moving that refresh off the event loop is a fix for google-genai, outside this PR. ## Why? Without timer heartbeats, most of these activities never hear a cancel, so a running call goes on to the end. Earlier interaction streams could receive cancellation through their per-event heartbeats, but only once an event arrived. A lost worker also goes unnoticed until the 60-second start-to-close timeout. And you couldn't set a heartbeat timeout yourself, since the calls didn't heartbeat: most calls longer than it failed. #491 has the details, and the measurements behind 10 seconds. ## Breaking change in 1.0.0 Replay still works: core only compares an activity's ID and type, and heartbeats aren't in History. `test_replay_history_recorded_with_text_bytes_in_the_input` replays a History recorded with no heartbeat timeout, and it passes. But a passing replay doesn't mean mixed versions work. `temporalio-google-genai` 1.0.0 adds timer heartbeats and the 10-second default. The timeout is recorded when the activity is scheduled. If a worker on a version before 1.0.0 runs that activity, it doesn't heartbeat on a timer (the interaction streams only heartbeat per event), so a call longer than 10 seconds fails with a heartbeat timeout. Retries keep the recorded timeout, so they fail the same way, and rolling back doesn't clear it either. #520 measured this on a local dev server: an activity that doesn't heartbeat failed 10.02 seconds in, and both attempts of a retried one failed the same way. The README has the guidance for in-flight runs: - To upgrade to 1.0.0, put this version on every worker that runs the Gemini activities before any workflow worker. If the same workers run both, deploy with `heartbeat_timeout=None` in `activity_config`, and remove that setting in a later deploy. - To roll back from 1.0.0, first deploy this version with `heartbeat_timeout=None`, wait until the calls scheduled before that deploy finish, and then roll back. - Runs pinned with Worker Versioning avoid both cases when their Gemini activities use the workflow's task queue. A config you pass replaces the defaults. Keep your activity timeouts when disabling heartbeats; the README now shows `ActivityConfig(start_to_close_timeout=timedelta(seconds=60), heartbeat_timeout=None)` for these steps. There are more costs. A call that didn't set `heartbeat_timeout` now heartbeats, which in Temporal Cloud is at most one Action every 8 seconds of a running call with the default, and more often when a shorter start-to-close timeout caps it. A cancelled call can send one more as it stops, since core sends the heartbeat it was holding back when an activity is cancelled. A call that blocks the worker's event loop for longer than the heartbeat timeout now fails with a heartbeat timeout. On Vertex AI, that includes a slow credential refresh in `interactions` and `agents`. ## Checklist 1. Closes #550 2. How was this tested: - `test_full_integration_with_mock_client` runs the real activities in a workflow with four `activity_config`s, and reads the heartbeat timeout of all 10 scheduled activities from History: no config and a config without `heartbeat_timeout` get 10 seconds, `None` gets none. In `heartbeat-1s`, all 10 calls take 1.5 seconds under a 1-second heartbeat timeout with no retries, so it passes only if they heartbeat. Without the change, the default cases fail with `assert [None, None, ...ne, None, ...] == [datetime.tim...onds=10), ...]` and `heartbeat-1s` fails with `TimeoutError: activity Heartbeat timeout`. - `test_activity_heartbeats_on_a_timer` runs each of the 16 activities three ways. The activity helper also checks that the test cases cover every activity registered by `GeminiApiCaller.activities()`. A call that takes 0.5 seconds under a 0.2-second heartbeat timeout heartbeats; a fast call under the 10-second default sends none; and a 0.1-second call with no heartbeat timeout sends none. Without the change, all 16 slow cases fail with `assert False == True`. Without the timer's early return for a missing timeout, all 16 `off` cases fail with `AttributeError: 'NoneType' object has no attribute 'total_seconds'`. - `test_workflow_cancellation_stops_gemini_call` cancels a workflow during a model call and a quiet interaction stream. Both cases wait for the running SDK call to receive cancellation before the worker shuts down. - `test_interaction_stream_does_not_heartbeat_per_event` drains a 4-event interaction stream and expects no heartbeats. Without the change it fails with `assert [(), (), (), ()] == []`. - The Vertex refresh table and the 2-second timeout case above come from a separate script on a local dev server: a real `genai.Client(vertexai=True)` whose credentials sleep in `refresh()`, mocked HTTP responses, and no retries. It reads the heartbeat timeout from History and polls the workflow's pending activities for heartbeats the service received. - Locally, `make test` (267 passed, 1 skipped), `make lint`, `make build`, the wheel check and the conventions check pass, on Python 3.12 with uv 0.13.5. 3. Any docs updates needed? The README and the docstring are updated here. Release notes should call this out as breaking, with the upgrade and rollback steps, how to turn heartbeats off, and the Vertex AI credential refresh limit.
TemporalModel now gives both model Activities a 10-second heartbeat timeout unless activity_config sets one, and heartbeat_timeout=None turns heartbeats off. The Activities heartbeat on a timer at half the timeout instead of once per streamed response, so a call shorter than 5 seconds sends none. Part of #491.
campoy
force-pushed
the
feat/google-adk-python-default-heartbeat-timeout
branch
from
November 17, 2026 01:07
f9356bb to
86f9b8a
Compare
patbeqo
reviewed
Nov 17, 2026
patbeqo
left a comment
Contributor
There was a problem hiding this comment.
Could these activities use an @auto_heartbeater decorator like the other integrations?
Like the other Python plugins. This is a copy of Strands' decorator, which uses the same call_later timer as before, so the behavior doesn't change.
Contributor
Author
|
Yes, good call. Six of the Python plugins use one: Strands, OpenAI Agents, Claude Agent SDK, Codex, Microsoft Agent Framework and Deep Agents. Each plugin keeps its own copy. I copied Strands' |
patbeqo
approved these changes
Nov 17, 2026
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 was changed
TemporalModelnow gives both model Activities,invoke_modelandinvoke_model_streaming, a 10-secondheartbeat_timeoutwhenactivity_configdoesn't set one.heartbeat_timeout=Noneturns heartbeats off.invoke_modelnever heartbeat, andinvoke_model_streamingheartbeat once per streamed response. The timer waits before its first beat, so a call shorter than 5 seconds sends none.loop.call_later, not a task liketemporalio-mcpdoes. Why? A task only starts its sleep at the block's firstawait, so anything that blocks the event loop before then pushes every beat back. Building the model runs before thatawait, and so doesLiteLlm's import oflitellmon its first call, which took 3.4 seconds when I measured it. With a task, a 6-second block would miss the first heartbeat.TemporalModeldocstring and the README say what the default does, what it costs, how to turn it off, and how to upgrade and roll back.activity_as_toolandactivity_noderun your own Activities, so they don't change. MCP isn't in this PR either.Why?
Without a heartbeat timeout, a cancel never reaches a running model call, so it runs to the end. And a lost worker goes unnoticed until the 60-second start-to-close timeout. #491 has the details, and the measurements behind 10 seconds.
Couldn't you set
heartbeat_timeoutyourself? Well, not really:invoke_modelnever heartbeat. A 2-second model call with a 1-second heartbeat timeout failed with:With this change, it returns.
Breaking change
Replay isn't the problem. When core replays a scheduled Activity, it only compares its ID and type. #565 removed the test that replays the four 0.x histories, since 1.0.0 is next, so I ran it once against this branch: all four still replay.
But a passing replay doesn't mean mixed versions work. The timeout is recorded when the model Activity is scheduled. What happens when a Worker on an earlier version runs it? That Worker never heartbeats from
invoke_model(and frominvoke_model_streamingonly when a response arrives), so a call longer than 10 seconds fails with a heartbeat timeout. Retries keep the recorded timeout, so they fail the same way, and rolling back doesn't clear it either.I checked this on a local dev server, with a 12-second call scheduled the way
TemporalModeldoes it:heartbeat_timeoutTimeoutError: activity Heartbeat timeoutafter 10.02 sNoneThe README has the steps for in-flight runs:
heartbeat_timeout=Noneinactivity_config, and remove that setting in a later deploy.heartbeat_timeout=None, wait until the model calls scheduled before that deploy finish, and then roll back.There are two more costs:
heartbeat_timeoutnow heartbeats. In Temporal Cloud, that's at most one Action every 8 seconds of a running call.litellmimport.Checklist
Closes [Feature Request] Give Google ADK Python model calls a 10-second default heartbeat timeout #519
How was this tested:
test_single_agentnow reads the heartbeat timeouts from History: 10 seconds for both model calls, and none for theactivity_as_toolcall. Without the change it fails withassert [None, None, None] == [datetime.timedelta(seconds=10), None, datetime.timedelta(seconds=10)].test_multi_agent, the writer agent now setsheartbeat_timeout=None. It gets no heartbeat timeout, and the other two agents get 10 seconds. Without the change it fails withassert [None, None, None] == [datetime.timedelta(seconds=10), datetime.timedelta(seconds=10), None].test_model_activities_heartbeat_on_a_timerruns both model Activities with a 1-second heartbeat timeout. A fast call that streams three responses sends no heartbeat, and a slow call, whose model waits for a heartbeat, returns. Without the change, the fast streaming call fails withassert (3 > 0) == False(one heartbeat per response), and both slow calls time out waiting for a heartbeat.make lintandmake test(321 passed, 6 skipped) pass locally, on Python 3.12 with uv 0.13.5.Any docs updates needed?
The docstring and the README are updated here. The release notes should call this out as breaking, with the upgrade and rollback steps and how to turn heartbeats off.