Skip to content

Give Google ADK Go model, MCP and A2A Activities a 10-second default heartbeat timeout - #512

Merged
campoy merged 4 commits into
mainfrom
feat/googleadk-go-default-heartbeat-timeout
Nov 13, 2026
Merged

campoy merged 4 commits into
mainfrom
feat/googleadk-go-default-heartbeat-timeout

Conversation

@campoy

@campoy campoy commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What was changed

InvokeModel, ListMcpTools, CallMcpTool, ResolveA2AAgentCard, SendA2AMessage and CancelA2ATask now get a 10-second HeartbeatTimeout when you don't set one. Before, only a streamed model call got one, of 30 seconds.

  • These Activities already heartbeat on a timer (startPeriodicHeartbeats). It now heartbeats every half of the timeout instead of every third, like the other plugins. A timeout you set wins.
  • A negative HeartbeatTimeout turns 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.
  • The timer now sends its first heartbeat half the timeout into a call, instead of as soon as it starts. It's still inside the timeout, and a call shorter than that, 5 seconds by default, sends none, as in the other plugins.
  • CancelA2ATask gets 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.
  • ActivityAsTool runs your own Activity, so it stays as it is.
  • A new Heartbeats section in the README covers the default, the opt-out, the cost and the cancel's limits. The doc comments on WithModelActivityOptions, MCPToolsetOptions.ActivityOptions, NewA2AAgentCardProvider and NewA2AClientProvider say the same. WithStreaming no 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 on main.

But a call that didn't set HeartbeatTimeout now 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 every MaxHeartbeatThrottleInterval of 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:

every timeout/2, heartbeat timeout 10s (start-to-close 1m0s), 3s call that succeeds: 0 heartbeats sent
every timeout/2, heartbeat timeout 10s (start-to-close 1m0s), 4s call that succeeds: 0 heartbeats sent
every timeout/2, heartbeat timeout 10s (start-to-close 1m0s), 6s call that succeeds: 1 heartbeats sent
every timeout/2, heartbeat timeout 10s (start-to-close 1m0s), 30s call that succeeds: 4 heartbeats sent
every timeout/2, heartbeat timeout 10s (start-to-close 1m0s), 30s call that fails: 4 heartbeats sent
every timeout/2, heartbeat timeout 5s (start-to-close 5s), 2s call that succeeds: 0 heartbeats sent
every timeout/2, heartbeat timeout 5s (start-to-close 5s), 3s call that succeeds: 1 heartbeats sent

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

  1. Closes [Feature Request] Give Google ADK Go model, MCP and A2A Activities a 10-second default heartbeat timeout #511

  2. How was this tested:

    • TestReplaySingleAndMultiAgent now 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 the ActivityAsTool ones. Without the change, all of them have none:
      actual  : map[string]bool{"googleadk.CallMcpTool 0s":true, "googleadk.InvokeModel 0s":true, "googleadk.ListMcpTools 0s":true, "googleadk.ResolveA2AAgentCard 0s":true, "googleadk.SendA2AMessage 0s":true, "guarded_alpha 0s":true, "guarded_beta 0s":true, "guarded_gamma 0s":true}
      
    • New TestShortModelCallSendsNoHeartbeat, with a model that answers at once. default gets 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 with Should be zero, but was 1, and with the old timer that beat at once, default fails the same way. Without the whole change, default fails with expected: 10s, actual: 0s, and off with A valid timeout may not be negative. (type: InvalidArgument, retryable: true).
    • The existing TestModelHeartbeatsWhileAwaitingSlowResponse and TestStreamingModelHeartbeatsBeforeFirstChunk still pass: a model that stays silent for 2.5 seconds under a 1-second heartbeat timeout isn't timed out.
    • No test here covers the cancel's options. On a dev server, its History shows googleadk.CancelA2ATask heartbeat_timeout=5s start_to_close=5s.
    • The heartbeat counts above come from a throwaway program against a dev server, with a gRPC interceptor counting RecordActivityTaskHeartbeat calls. It takes about two minutes, so it isn't part of this PR.
    • Locally, make test (118 tests), make lint and the conventions check pass, on Go 1.26.10.
  3. 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.

…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
campoy marked this pull request as ready for review November 13, 2026 00:55
@campoy
campoy requested a review from a team as a code owner November 13, 2026 00:55

@DABH DABH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM up to a couple questions/comments

Comment thread go/googleadk/a2a.go Outdated
@@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we rewrite this to be a bit more human friendly?

Comment thread go/googleadk/model.go
case <-ctx.Done():
return
case <-ticker.C:
activity.RecordHeartbeat(ctx)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this moved?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@campoy
campoy merged commit 4bd0339 into main Nov 13, 2026
27 checks passed
@campoy
campoy deleted the feat/googleadk-go-default-heartbeat-timeout branch November 13, 2026 15:41
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.

[Feature Request] Give Google ADK Go model, MCP and A2A Activities a 10-second default heartbeat timeout

2 participants