Skip to content

Give Strands TypeScript model calls a 10-second default heartbeat timeout - #508

Merged
campoy merged 1 commit into
mainfrom
feat/strands-agents-ts-default-heartbeat-timeout
Nov 13, 2026
Merged

campoy merged 1 commit into
mainfrom
feat/strands-agents-ts-default-heartbeat-timeout

Conversation

@campoy

@campoy campoy commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

What was changed

TemporalModel, and so TemporalAgent, now schedules the model activities with a 10-second heartbeatTimeout unless activityOptions sets one. So invokeModel, invokeModelStreaming, strandsInvokeStatefulModel and strandsInvokeStatefulModelStreaming heartbeat by default.

  • The activities already heartbeat on a timer at half the timeout (autoHeartbeat), so they don't change. A timeout you set wins, and heartbeatTimeout: 0 (or '0s') turns heartbeats off.
  • strandsGetModelConfig is now scheduled without a heartbeat timeout, even when you set one. It builds the model and reads its config synchronously, so a heartbeat timer can't fire until it returns, and a model factory slower than the timeout would fail it.
  • The README and the docs on TemporalAgent, TemporalModel and the model activity said cancellation needs a heartbeatTimeout you set. They now say what the default does and how to turn it off.

activityAsTool and activityAsHook run your own activities, so they stay as they are.

Why?

Without a heartbeat timeout, the model activities never heartbeat. So a cancel never reaches a running model call: since #297 the model gets the activity's cancellation signal, but the signal only aborts once the worker hears about the cancel, and it only hears through a heartbeat. With the default, the cancel stops models that pass cancelSignal to their client, like OpenAIModel and BedrockModel. A lost worker also goes unnoticed until the start-to-close timeout, 10 minutes by default. #491 has the details, and the measurements behind 10 seconds.

Does this break anything? Not replay: when core replays a scheduled Activity, it only compares its ID and type, and the replay tests pass, including the histories recorded with no heartbeat timeout. But a model call that didn't set heartbeatTimeout now heartbeats, which in Temporal Cloud is at most one Action every 8 seconds of a running call. And a Worker whose event loop blocks for about 10 seconds now fails the call with a heartbeat timeout, and retries it.

TemporalMCPClient isn't in this PR. Its activities never heartbeat, so a default there would fail every MCP call longer than 10 seconds. It needs a timer first, in a later PR.

Checklist

  1. Closes [Feature Request] Give Strands TypeScript model calls a 10-second default heartbeat timeout #507

  2. How was this tested:

    • TemporalAgent dispatches model.stream() through invokeModel activity now reads the heartbeat timeouts from History: none for strandsGetModelConfig, 10 seconds for invokeModel. Without the change it fails:
      Difference (- actual, + expected):
        [
          [
            'strandsGetModelConfig',
            0,
          ],
          [
            'invokeModel',
      -     0,
      +     10000,
          ],
        ]
      
    • The two cancelling a TemporalAgent workflow ... aborts the model call tests, whose agent sets heartbeatTimeout: '5 seconds', now check that the model call keeps those 5 seconds and the config read gets none. Without the change, the config read got 5 seconds too.
    • To check the opt-out, I ran a throwaway test that schedules one model call with each setting and reads the activity's heartbeat timeout from History and from Context.current().info:
      heartbeatTimeout="default"    scheduled invokeModel: heartbeatTimeout {"seconds":"10"} (10000 ms); activity info heartbeatTimeoutMs=10000
      heartbeatTimeout="undefined"  scheduled invokeModel: heartbeatTimeout {"seconds":"10"} (10000 ms); activity info heartbeatTimeoutMs=10000
      heartbeatTimeout="0"          scheduled invokeModel: heartbeatTimeout {} (0 ms); activity info heartbeatTimeoutMs=0
      heartbeatTimeout="0s"         scheduled invokeModel: heartbeatTimeout {} (0 ms); activity info heartbeatTimeoutMs=0
      heartbeatTimeout="5 seconds"  scheduled invokeModel: heartbeatTimeout {"seconds":"5"} (5000 ms); activity info heartbeatTimeoutMs=5000
      
      autoHeartbeat starts its timer only when heartbeatTimeoutMs > 0, so 0 means no heartbeats.
    • Locally, make test (105 passed, including the replay tests), make lint and the conventions check pass, with Node 24.
  3. Any docs updates needed?
    The README and docs are updated here. Release notes should mention the new default, and how to turn it off.

…eout

TemporalModel, and so TemporalAgent, scheduled the model activities without a
heartbeat timeout unless activityOptions set one, and the activities heartbeat
only when it's set. So a cancel never reached a running model call, and a lost
worker went unnoticed until the start-to-close timeout.

Default it to 10 seconds. The model activities already heartbeat on a timer at
half the timeout. Setting it to 0 still turns heartbeats off. The model config
read runs synchronously and can't heartbeat, so it's scheduled without a
heartbeat timeout.

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
@campoy
campoy merged commit 14ec941 into main Nov 13, 2026
15 checks passed
@campoy
campoy deleted the feat/strands-agents-ts-default-heartbeat-timeout branch November 13, 2026 01:25
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 Strands TypeScript model calls a 10-second default heartbeat timeout

2 participants