Repository navigation
Give Google ADK Go model, MCP and A2A Activities a 10-second default heartbeat timeout - #512
Merged
Merged
Conversation
…heartbeat timeout InvokeModel got a 30-second heartbeat timeout only when it streamed, and the MCP and A2A Activities got none. They heartbeat only when one is set. So a cancel never reached a running MCP call, A2A send or model call that didn't stream, and reached a streamed one slowly. A lost worker went unnoticed until the start-to-close timeout. Default it to 10 seconds for InvokeModel, ListMcpTools, CallMcpTool, ResolveA2AAgentCard, SendA2AMessage and CancelA2ATask. A timeout you set wins, and a negative one turns heartbeats off. Before, the server rejected a negative one and the workflow task failed. The server caps the cancel's heartbeat timeout at its 5-second start-to-close timeout. ActivityAsTool runs your own Activity, so it stays as it is. The timer now sends its first heartbeat a third of the timeout in, instead of at once, so a call shorter than that sends none. A new Heartbeats section in the README covers the default, the opt-out and what heartbeats cost. Part of #491.
campoy
marked this pull request as ready for review
November 13, 2026 00:55
DABH
approved these changes
Nov 13, 2026
DABH
left a comment
Contributor
There was a problem hiding this comment.
LGTM up to a couple questions/comments
| @@ -82,8 +84,12 @@ func (p a2aCardProvider) resolve(ctx context.Context) (*a2a.AgentCard, error) { | |||
| // A zero StartToCloseTimeout in ao falls back to one minute, and with no | |||
Contributor
There was a problem hiding this comment.
Could we rewrite this to be a bit more human friendly?
| case <-ctx.Done(): | ||
| return | ||
| case <-ticker.C: | ||
| activity.RecordHeartbeat(ctx) |
Contributor
Author
There was a problem hiding this comment.
this is to avoid a heartbeat right away - costing more for all activities - instead of after the first timetout duration has passed
List what each Activity option does, then the cancellation's limits in a short paragraph, instead of one dense block.
The other plugins heartbeat every half of the heartbeat timeout, with the first heartbeat half the timeout in. Do the same here, so a call shorter than 5 seconds sends none with the default in every plugin. The README drops a heartbeat count for failing calls that depended on the timer racing the end of the call.
DABH
approved these changes
Nov 13, 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
InvokeModel,ListMcpTools,CallMcpTool,ResolveA2AAgentCard,SendA2AMessageandCancelA2ATasknow get a 10-secondHeartbeatTimeoutwhen you don't set one. Before, only a streamed model call got one, of 30 seconds.startPeriodicHeartbeats). It now heartbeats every half of the timeout instead of every third, like the other plugins. A timeout you set wins.HeartbeatTimeoutturns heartbeats off. Zero already means "not set" in Go. Today the server rejects a negative one (invalid HeartbeatTimeout: negative duration) and the workflow task fails, so this changes no code that works. If we ever need more, we can add a boolean.CancelA2ATaskgets the same default, with two limits. The server caps its heartbeat timeout at the cancellation's 5-second start-to-close timeout. And nothing cancels a cancellation, so its heartbeats only notice a lost worker. Only a cancellation slower than about 2.5 seconds sends one.ActivityAsToolruns your own Activity, so it stays as it is.WithModelActivityOptions,MCPToolsetOptions.ActivityOptions,NewA2AAgentCardProviderandNewA2AClientProvidersay the same.WithStreamingno longer mentions the 30-second default, and two comments in the MCP Activities no longer say they heartbeat only when you set a timeout.Why?
Without a heartbeat timeout, these Activities never heartbeat. So a cancel never reached a running MCP call, A2A send, or model call that didn't stream, and it ran to the end. A streamed model call heard it, but slowly. A lost worker went unnoticed until the start-to-close timeout: 2 minutes for a model call, 1 minute for the others.
Why 10 seconds? #491 has the measurements.
Does this break anything? Not replay: when the Go SDK replays a scheduled Activity, it only compares its ID and type. I checked both ways against a dev server: histories recorded on
main, with no heartbeat timeout, replay with this change, and histories recorded with it replay onmain.But a call that didn't set
HeartbeatTimeoutnow heartbeats. What does that cost? In Temporal Cloud, each heartbeat that reaches the server is an Action. The SDK holds heartbeats back to one every 0.8 times the timeout (8 seconds by default), or everyMaxHeartbeatThrottleIntervalof the Worker if that's shorter. I ran an Activity that heartbeats like the plugin's timer against a dev server, and counted the heartbeats that reached it:So a call under 5 seconds costs nothing more, and a 30-second call costs four more Actions with the default Worker options. The last two lines are the cancel, whose heartbeat timeout the server caps at 5 seconds.
A failed or canceled attempt can cost one more: the SDK sends the heartbeat it was holding back as the Activity ends, if the timer recorded one since the last send. Each retry heartbeats again. And a Worker that can't heartbeat for 10 seconds now fails the call with a heartbeat timeout, and retries it.
Checklist
Closes [Feature Request] Give Google ADK Go model, MCP and A2A Activities a 10-second default heartbeat timeout #511
How was this tested:
TestReplaySingleAndMultiAgentnow also runs an MCP agent, and reads the heartbeat timeout of every scheduled Activity from History: 10 seconds for the five plugin Activities it runs, none for theActivityAsToolones. Without the change, all of them have none:TestShortModelCallSendsNoHeartbeat, with a model that answers at once.defaultgets a 10-second timeout and sends no heartbeat.off(HeartbeatTimeout: -1) gets no timeout and sends none. A third case,under half the timeout, runs a 1.25-second call under a 3-second timeout: it ends between a third and half of the timeout, so it sends none. With the timer at a third of the timeout, it fails withShould be zero, but was 1, and with the old timer that beat at once,defaultfails the same way. Without the whole change,defaultfails withexpected: 10s, actual: 0s, andoffwithA valid timeout may not be negative. (type: InvalidArgument, retryable: true).TestModelHeartbeatsWhileAwaitingSlowResponseandTestStreamingModelHeartbeatsBeforeFirstChunkstill pass: a model that stays silent for 2.5 seconds under a 1-second heartbeat timeout isn't timed out.googleadk.CancelA2ATask heartbeat_timeout=5s start_to_close=5s.RecordActivityTaskHeartbeatcalls. It takes about two minutes, so it isn't part of this PR.make test(118 tests),make lintand the conventions check pass, on Go 1.26.10.Any docs updates needed?
The README and doc comments are updated here. Release notes should mention the new default, and how to turn it off.