Skip to content

[typescript/openai-agents] give model calls a 10-second default heartbeat timeout - #514

Merged
campoy merged 5 commits into
mainfrom
feat/openai-agents-ts-default-heartbeat-timeout
Nov 17, 2026
Merged

campoy merged 5 commits into
mainfrom
feat/openai-agents-ts-default-heartbeat-timeout

Conversation

@campoy

@campoy campoy commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What was changed

The model Activities (invokeModelActivity and invokeModelStreamActivity) now get a 10-second heartbeatTimeout by default. It sits in DEFAULT_MODEL_ACTIVITY_OPTIONS, next to the 60-second startToCloseTimeout.

  • The Activities already heartbeat on a timer (startAdaptiveHeartbeat) at half the timeout.
  • That timer now sends its first heartbeat half the timeout into the call, instead of right away, like the Vercel AI SDK, Google ADK and Strands plugins. So a call that ends sooner sends none.
  • A heartbeatTimeout you set wins, in the plugin's modelParams or in the runner's defaultModelParams. heartbeatTimeout: 0 turns heartbeats off.
  • ModelActivityOptions now documents heartbeatTimeout: what the default does, how to turn it off, and how much time the Worker's startup and heartbeat encoding get. The README says the same, next to the modelParams example.

Local Activities (useLocalActivity: true) don't take a heartbeat timeout, and still don't get one.

The stateful MCP session uses the same timer. It sends its own heartbeat when it starts, so it still heartbeats right away. Only the timer's first beat, a repeat with the same details, moves later. Its tests pass, including the slow connect and heartbeat timeout ones.

Why?

Without a heartbeat timeout, the model Activities never heartbeat. So a cancel never reaches a running model call, and a lost Worker goes unnoticed until the 60-second start-to-close timeout. #491 has the details, and the measurements behind 10 seconds. #496 makes the same change in Python.

Why wait before the first heartbeat? The heartbeat timeout already counts from the start of the attempt, so a heartbeat right away adds nothing. Waiting means a call shorter than 5 seconds sends no heartbeat, and doesn't pay for one.

What's the catch? The first heartbeat has to reach the server within the timeout. It goes out half the timeout after the Activity starts, and the Worker encodes it with your payload codecs first. So the Worker's startup work for the attempt (interceptors and payload decoding) plus that encoding must fit in the other half: under 5 seconds with the default. A slower setup, like a codec that calls a remote key service, needs a heartbeatTimeout of more than twice that time, or 0. The docs say so.

So does a cancel stop the model call now? Not yet. The cancel reaches the Activity, but the Activity doesn't pass it to the model, so the call still runs to the end. That's #503. A fix for #428 (the TypeScript side of #227, which #228 fixes in Python) needs both.

Does this break anything? Not replay: when core replays a scheduled Activity, it only compares its ID and type. I recorded a model call on main, with no heartbeat timeout, and it replays fine with this change. But a model call that didn't set heartbeatTimeout now heartbeats once it runs past 5 seconds. In Temporal Cloud, that's at most one Action every 8 seconds from then on. A Worker whose event loop is blocked for about 10 seconds now fails the call with a heartbeat timeout, and retries it. If interceptors, payload decoding or a payload codec take a large part of the timeout, raise heartbeatTimeout.

Checklist

  1. Closes [Feature Request] Give OpenAI Agents TypeScript model calls a 10-second default heartbeat timeout #513

  2. How was this tested:

    • Two tests now read the model Activities' heartbeat timeout from History, and expect 10 seconds: agent.asTool() runs take the run model, model settings and runner defaults (four invokeModelActivity calls, with a runner defaultModelParams that doesn't set one) and Streaming: external subscriber and in-workflow result see the same events (invokeModelStreamActivity, with a client modelParams that doesn't set one). Without the default, they fail with - 0 + 10.
    • The layerModelParams tests check the 10-second default, and that a 0 from the runner or the client wins over it.
    • The credentials test that checked the timer already runs while the callback waits is now the Activity heartbeats while the callback is asked for credentials, and a quick call sends none. With a 200 ms timeout, a quick call sends no heartbeat, and a call whose callback takes 350 ms sends at least two. With the old timer, the quick call fails with - 1 + 0.
    • The new A model call slower than its heartbeat timeout completes on its first attempt runs a 2.5-second call with a 1-second heartbeat timeout, and it finishes on its first attempt.
    • I also ran a 6-second model call with heartbeatTimeout unset, 0, '0s' and '3s', and read History, activityInfo().heartbeatTimeoutMs and, 5.5 seconds in, the pending Activity's last heartbeat:
      PROBE modelParams=null history.heartbeatTimeout=10s+0ns activityInfo.heartbeatTimeoutMs=10000 pending.lastHeartbeatTime=set
      PROBE modelParams={"heartbeatTimeout":0} history.heartbeatTimeout=0s+0ns activityInfo.heartbeatTimeoutMs=0 pending.lastHeartbeatTime=none
      PROBE modelParams={"heartbeatTimeout":"0s"} history.heartbeatTimeout=0s+0ns activityInfo.heartbeatTimeoutMs=0 pending.lastHeartbeatTime=none
      PROBE modelParams={"heartbeatTimeout":"3s"} history.heartbeatTimeout=3s+0ns activityInfo.heartbeatTimeoutMs=3000 pending.lastHeartbeatTime=set
      
    • With the scheduled-time math gone, in a Docker image with Node 24: pnpm run lint (0 errors; the 8 warnings are existing ones), and the credentials and model test files (22 passed). CI runs the full suite.
  3. Any docs updates needed?
    The heartbeatTimeout JSDoc and the README's modelParams section are updated here, including the time budget for startup and heartbeat encoding. Release notes should mention the new default, how to turn it off, and that slow codecs need a larger timeout.

…at timeout

The model activities' default options set no heartbeatTimeout, and they
heartbeat only when one is set. So a cancel never reached a running model
call, and a lost worker went unnoticed until the 60-second start-to-close
timeout.

Default it to 10 seconds. The model activities already heartbeat on a timer
at half the timeout. A timeout set in the plugin's modelParams or the runner's
defaultModelParams wins, and 0 turns heartbeats off. Local activities still
don't get one.

The timer now sends its first heartbeat half the timeout in, not at once, so
a call that ends sooner sends none. The stateful MCP session sends its own
heartbeat when it starts, so it still heartbeats at once.

Part of #491.
@campoy
campoy marked this pull request as ready for review November 13, 2026 01:24
@campoy
campoy requested a review from a team as a code owner November 13, 2026 01:24
@campoy campoy changed the title Give OpenAI Agents TypeScript model calls a 10-second default heartbeat timeout [openai-agents-typescript] give model calls a 10-second default heartbeat timeout Nov 16, 2026
@campoy campoy changed the title [openai-agents-typescript] give model calls a 10-second default heartbeat timeout [typescript/openai-agents] give model calls a 10-second default heartbeat timeout Nov 16, 2026

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

I'm not convinced that we need to do some extra timestamp math to avoid the case where codec takes up more than half of the heartbeat time. that seems like something the user should choose to configure.

In general, in Temporal, we should just go with the default timeout calculations because that's what we do everywhere else.

The first heartbeat now goes out half the timeout after the Activity starts, like the other plugins' timers. A slow interceptor or codec is left to heartbeatTimeout, so the codec notes and the tests for that case go too.
@campoy

campoy commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Agreed, and done. The timer now heartbeats every half timeout from when the Activity starts, like the Vercel AI SDK, Google ADK and Strands plugins, with no scheduled-time math. A slow interceptor or codec is left to heartbeatTimeout, so I took the codec notes out of the JSDoc and the README, and dropped the tests for that case.

Could you take another look?

@xumaple xumaple 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, thanks for addressing

@campoy
campoy merged commit 391f522 into main Nov 17, 2026
29 checks passed
@campoy
campoy deleted the feat/openai-agents-ts-default-heartbeat-timeout branch November 17, 2026 04:38
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 OpenAI Agents TypeScript model calls a 10-second default heartbeat timeout

2 participants