Skip to content

[typescript/google-adk] heartbeat streamed model calls only on the timer - #518

Merged
campoy merged 3 commits into
mainfrom
feat/google-adk-ts-timer-only-heartbeat
Nov 17, 2026
Merged

campoy merged 3 commits into
mainfrom
feat/google-adk-ts-timer-only-heartbeat

Conversation

@campoy

@campoy campoy commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What was changed

adk-invokeModelStreaming no longer heartbeats after every chunk. Like every other Activity in the plugin, it heartbeats only on the timer at half the heartbeat timeout.

  • The TemporalModelOptions.activity JSDoc and the README said a streamed call also heartbeats per chunk. Now they say it doesn't, and that heartbeatTimeout: 0 turns heartbeats off, not just the timer, so a cancel never reaches a running call.
  • The README now says a cancel can't reach a call before half the timeout, so a shorter call runs to the end.
  • The README's streaming example no longer sets a 30-second heartbeat timeout. With the 10-second default, a cancel reaches its call 5 seconds in, not 15.
  • The comment on startAdaptiveHeartbeat now says it's the only source of heartbeats, so a call shorter than half the timeout sends none.

Why?

#491 sets one rule for every plugin: heartbeats come only from the timer, and the first one goes out half the timeout into a call. Streamed model calls here broke it.

What did that cost? The SDK sends a call's first heartbeat at once, so every streamed call that sent a chunk cost a Temporal Cloud Action, even one that ended in a second. The timer already keeps a slow stream alive, so the per-chunk heartbeats added nothing. Now, with the 10-second default, a streamed call shorter than 5 seconds sends no heartbeat.

Is there a downside? Yes, a small one. A cancel reaches a call only through a heartbeat, so a cancel that came in before the first chunk used to stop the call there. Now it waits for the timer, like a non-streamed call always has. After that first chunk, the SDK held the next heartbeat for 0.8 × the timeout anyway.

Does this affect replay? No. Heartbeats come from the Activity, not the Workflow, so replay never sees them. The replay tests pass.

Checklist

  1. Closes [Feature Request] Heartbeat Google ADK TypeScript streamed model calls only on the timer #517

  2. How was this tested:

    • New streamedCallHeartbeatsOnlyOnTimer in streaming.test.ts: it runs a three-chunk streamed call that takes 100 ms in a MockActivityEnvironment and checks for heartbeats. A 10-second heartbeat timeout and 0 should send none, and 100 ms should send at least one. I added a new test because History doesn't record heartbeats, so the end-to-end streaming tests can't count them, and the other mock tests cover failures. With the per-chunk heartbeat back, the 10-second case fails:
      streamedCallHeartbeatsOnlyOnTimer
      heartbeatTimeoutMs 10000
      Difference (- actual, + expected):
      - true
      + false
      
      With the timer removed from the streaming Activity, the 100 ms case fails instead (- false, + true). No other test covers that timer. And if the timer's guard skips only an undefined timeout, the 0 case fails.
    • The streaming tests and the cancellation tests that need heartbeats still pass.
    • Locally, make test (254 passed) and make lint pass, on Node 22.23.4 with Temporal CLI 1.10.1. Before the review fixes, the conventions check also passed, on Node 24 with Temporal CLI 1.10.0.
  3. Any docs updates needed?
    The JSDoc and the README are updated here. Release notes should say that streamed model calls no longer heartbeat per chunk.

adk-invokeModelStreaming heartbeated after every chunk, on top of the timer
at half the heartbeat timeout. The SDK sends a call's first heartbeat at once,
so even a short streamed call cost a Temporal Cloud Action, and the timer
already keeps a slow stream alive.

Drop the per-chunk heartbeat. Now a call shorter than half the timeout sends
no heartbeat, and heartbeatTimeout: 0 turns heartbeats off completely.

Part of #491.
@campoy
campoy marked this pull request as ready for review November 13, 2026 03:57
@campoy
campoy requested a review from a team as a code owner November 13, 2026 03:57
The guard in startAdaptiveHeartbeat had no test: with it skipping only an
undefined timeout, the whole suite still passed. The heartbeat test now
runs a 100 ms streamed call with a 10-second timeout and with 0. With that
weaker guard, the 0 case sends 77 heartbeats and fails.
@campoy campoy changed the title Heartbeat Google ADK TypeScript streamed model calls only on the timer [google-adk-typescript] heartbeat streamed model calls only on the timer Nov 16, 2026
@campoy campoy changed the title [google-adk-typescript] heartbeat streamed model calls only on the timer [typescript/google-adk] heartbeat streamed model calls only on the timer Nov 16, 2026

@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.

This PR looks right to me for what it sets out to do.

One thing I think the per-chunk heartbeat did add: the first chunk's heartbeat went out at once, so a cancel requested before it reached a short streamed call. Now it can't. Questions inline about that, about heartbeatTimeout: 0, and about a positive case for the test.

@@ -131,8 +131,6 @@ export function createModelActivities(options: ModelActivitiesOptions = {}): Mod
const model = resolveModel(args.model);
const request = fromWireRequest(args.request);
for await (const response of model.generateContentAsync(request, true, abortSignal)) {

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.

The first chunk's heartbeat went out at once, so a cancel requested before it, say from a failed sibling node, stopped the call there. Now a streamed call shorter than half the timeout can't be cancelled: 15 seconds with the README's streaming example. Is that an accepted cost, and should the README say so?

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.

yeah, I think that's a fair cost and it's the same across all plugins

Comment thread typescript/google-adk/README.md Outdated
call shorter than half the timeout sends none. A cancel reaches a running call
only through a heartbeat. In Temporal Cloud each heartbeat that reaches the
service is an Action: with the default, at most one every 8 seconds of a running
call. Set `heartbeatTimeout: 0` to turn heartbeats off. The bound on a stalled

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.

With 0, a streamed call used to learn of a cancel at a chunk, and now nothing delivers one, so WAIT_CANCELLATION_COMPLETED waits for the whole call. Could this say that turning heartbeats off also turns cancels off for a running call?

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.

Good call, done. It now says that with heartbeatTimeout: 0 a cancel never reaches a running call. The TemporalModelOptions.activity JSDoc also says WAIT_CANCELLATION_COMPLETED then waits until the call ends.

})) as unknown as typeof WorkflowStreamClient.fromWithinActivity;
try {
const activities = createModelActivities({ modelProvider: (model) => new SlowStreamingLlm({ model }) });
for (const heartbeatTimeoutMs of [10_000, 0]) {

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.

Both cases expect zero, so the test would also pass with the timer removed from the streaming Activity. Could it add a short timeout, say 100 ms, and expect at least one heartbeat? That would also make the SlowStreamingLlm comment true for a working timer.

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.

Good catch: no other test covered that timer. The test now also runs a 100 ms timeout and expects a heartbeat. With the timer removed from the streaming Activity, it fails:

heartbeatTimeoutMs 100
Difference (- actual, + expected):
- false
+ true

A cancel reaches a running call only through a heartbeat. So it can't stop
a call shorter than half the timeout, and with heartbeatTimeout: 0 it never
reaches a running call. The README and the TemporalModelOptions.activity
JSDoc now say so.

The streaming example drops its 30-second heartbeat timeout and uses the
10-second default, so a cancel arrives 5 seconds into a call, not 15.

The heartbeat test now also runs a 100 ms timeout and expects a heartbeat.
Before, every case expected none, so it passed with the timer removed from
the streaming Activity.
@campoy
campoy merged commit d564549 into main Nov 17, 2026
29 checks passed
@campoy
campoy deleted the feat/google-adk-ts-timer-only-heartbeat branch November 17, 2026 05:17
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] Heartbeat Google ADK TypeScript streamed model calls only on the timer

2 participants