Repository navigation
mcp: heartbeat while an MCP operation runs, with a 10-second default heartbeat timeout - #494
Merged
Merged
Conversation
…heartbeat timeout A cancel reaches a running Activity only in a heartbeat's response, and MCP operations never heartbeated. So a cancelled Workflow's MCP request ran to the end, and a lost worker went unnoticed until the start-to-close timeout. Setting heartbeat_timeout didn't help: every request longer than it failed. Now every operation heartbeats on a timer at half the heartbeat timeout, and TemporalMCPClient adds a 10-second heartbeat_timeout when the config leaves it out. Set it to None to turn heartbeats off. Part of #491.
DABH
approved these changes
Nov 13, 2026
| running on a worker only through a heartbeat, and the heartbeat timeout is how | ||
| Temporal notices a lost worker before the start-to-close timeout. In Temporal | ||
| Cloud each heartbeat that reaches the service is an Action: with the default, at | ||
| most one every 8 seconds of a running request. Set `heartbeat_timeout` to `None` |
Contributor
There was a problem hiding this comment.
so in some plugins you are proposing 0 or negative has special meanings, but here it's either set or none (and unclear what 0 does). can / should we be more consistent across the plugins?
Contributor
Author
There was a problem hiding this comment.
It's actually the same everywhere: unset gets 10s, set to a positive integer and it wins, and one value to disable the heartbeats.
The "disable" value depends on the language:
- py: None, or timedelta(0), which the SDK treats as no timeout
- ts: 0, since option merges drop undefined.
- go: a negative value, since 0 is kept for default and making this a pointer seemed uglier.
A boolean send_heartbeats option would work too, but I'd wait until someone needs it.
DABH
added a commit
that referenced
this pull request
Nov 13, 2026
main (#494) makes temporalio-mcp heartbeat at half a 10-second default heartbeat timeout. The pinned 0.3.0 still does not, so the README and the provider docstring say which is which instead of a flat "do not heartbeat".
campoy
added a commit
that referenced
this pull request
Nov 13, 2026
## What was changed - OpenAI Agents and Strands (Python) require `temporalio-mcp>=0.4.0,<0.5` instead of `>=0.2.0,<0.3`, in their `mcp` extra and dev group. - Both `uv.lock` files now resolve the published 0.4.0. No other locked package changes. - The `temporal_mcp_server()` docstring now says its MCP operations get a 10-second heartbeat timeout by default, and how to turn it off. ## Why? The `temporalio-mcp` 0.3.0 release notes say OpenAI Agents and Strands keep 0.2.0 behavior until their pins move: both plugins pin `<0.3`. This PR makes them require 0.4, which includes 0.3.0's changes, before GA. 0.3.0 changes how these plugins' MCP calls fail. I ran each change through each plugin's own MCP wiring, against an in-process streamable-HTTP MCP server, on 0.2.0 and 0.3.0: | Case | OpenAI Agents (`mcp_servers`) | Strands (`mcp_clients`) | |---|---|---| | A tool result the MCP client rejects (#437) | Retried forever → fails at once | Retried forever → fails at once | | A lost session, HTTP 404 (#379) | No session in my test (see below) | Failed at once → retried with a new session | | Repeated pagination cursor, MCP error | Already failed at once | Already failed at once | - The rejected-result fix reaches both plugins, with and without a factory argument. Strands turns the failure into a tool error the model sees, instead of the run hanging. - #379 is Caller-breaking for Strands: a lost session used to become a tool error; now the run waits for a new session under its retry policy. Taking it after GA would mean a new major, so before GA is the cheapest moment. - With OpenAI Agents, the Agents SDK used the current MCP protocol, which has no sessions, so I couldn't trigger the 404 path. - The factory-argument `ExceptionGroup` fixes (#411, #433, #455) don't change either plugin: Strands' factories take no argument, and OpenAI Agents' backend doesn't wrap errors in groups. 0.4.0 adds one more change (#494): MCP operations heartbeat while they run, with a 10-second `heartbeat_timeout` when the Activity config leaves it out. So a cancel reaches a running MCP request, and a request longer than a `heartbeat_timeout` you set no longer fails with a heartbeat timeout. - OpenAI Agents: `workflow.temporal_mcp_server()` passes `activity_config` to `TemporalMCPClient` as it is, so its MCP operations now heartbeat by default. In Temporal Cloud, that's at most one Action every 8 seconds of a running request. `heartbeat_timeout=None` turns it off. - Strands: `TemporalMCPClient` always passes `heartbeat_timeout`, `None` unless you set it, so heartbeats stay off by default. If you set it, long requests stop failing with a heartbeat timeout. Why not allow 0.2 or 0.3 too? Every GA install should get the same retry behavior, and CI only tests the locked version, so nobody would test older versions with the GA plugins. The cost: if you use an older `temporalio-mcp` with these plugins, you upgrade it together with the plugin. Does OpenAI Agents need code changes? No. It imports `temporalio.mcp._backend`, which is unchanged since 0.2.0, and `temporalio.mcp._activities._MCPActivities`, whose constructor and Activities are unchanged; 0.3.0 changes only how they classify errors, and 0.4.0 only adds the heartbeats. ## What's left? - Add a Breaking line to both plugins' release notes: they now require `temporalio-mcp` 0.4, with its lost-session retry and its default heartbeat timeout. ## Checklist 1. Closes: no issue. 2. How was this tested: - On this branch, with uv 0.12.24: `make sync`, `make lint` and `make test` pass in both plugins with `temporalio-mcp` 0.4.0 installed (OpenAI Agents: 626 passed, 2 skipped; Strands: 279 passed, 1 skipped). - Before the release, I re-ran the analysis' 178 feature and defect checks for both plugins with the 0.4.0 wheel the release dry run built, which is byte for byte the one on PyPI. Only the intended #494 change shows up: a `heartbeat_timeout` set on Strands' `TemporalMCPClient` no longer times out MCP requests, and `temporal_mcp_server()` operations are scheduled with a 10-second heartbeat timeout. Everything else matches the 0.3.0 run. - At `main` 10f9082, both suites give the same per-test results on 0.2.0 and 0.3.0 (OpenAI Agents: 565 passed, 1 skipped; Strands: 245 passed). 3. Any docs updates needed? The `temporal_mcp_server()` docstring is updated here; no README changes. The release notes need the Breaking line under "What's left?".
campoy
added a commit
that referenced
this pull request
Nov 14, 2026
… heartbeat timeout (#504) ## What was changed `TemporalAgent`, `TemporalModel` and `TemporalSandbox` now default `heartbeat_timeout` to 10 seconds instead of `None`, so the model and sandbox activities heartbeat by default. - The activities already heartbeat on a timer at half the timeout (`auto_heartbeater`). A timeout you set wins, and `heartbeat_timeout=None` turns heartbeats off, as before. - The timer now starts when the activity does, not at its first `await`. Before, a model factory that blocked the event loop for over half the timeout made the attempt fail with a heartbeat timeout. Now it takes the whole timeout, which is when the warning below fires. - `strands_get_model_config` is now scheduled without a heartbeat timeout. It builds the model and reads its config synchronously, so it can't heartbeat, and a model factory slower than the timeout would fail it. - A model factory slower than the heartbeat timeout now logs a warning on the worker. The factory runs on the worker's event loop, so the heartbeat timer can't run while it builds the model, and that attempt may fail with a heartbeat timeout. The next attempt reuses the built model. - The docstrings and the README say what the default does and how to turn it off. They also say that a model factory or model call that blocks the event loop longer than the timeout fails. In Strands 1.56.0, `SageMakerAIModel` and `LlamaAPIModel` call their synchronous clients on the loop, so they need `heartbeat_timeout=None` (or a longer timeout). `activity_as_tool` and `activity_as_hook` run your own Activities, so they stay as they are. ### Why not build models on a thread? An automated review round suggested it, so a slow factory couldn't block the heartbeat timer. But that broke factories that need a running event loop, such as one that builds an `aiohttp` session, and the fix for that made this PR much bigger. A factory slower than 10 seconds is rare, and the retry reuses the model it built, so a warning that says what happened is enough. ## Why? Without a heartbeat timeout, these activities never heartbeat. So a cancel never reaches a running model call or sandbox command, and it runs to the end. A lost worker also goes unnoticed until the start-to-close timeout. #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. But a call that didn't set `heartbeat_timeout` now heartbeats, which in Temporal Cloud is at most one Action every 8 seconds of a running call. `TemporalMCPClient` isn't in this PR. Since #435, Strands requires `temporalio-mcp` 0.4, whose Activities heartbeat (#494). But Strands' `TemporalMCPClient` still passes `heartbeat_timeout=None`, so its Activities don't heartbeat yet. A follow-up can give it the 10-second default too. This works with #497, which makes a cancelled tool call cancel the agent. I merged its branch on top of this one, and its cancellation tests pass with these defaults. ## Checklist 1. Closes #498 2. How was this tested: - `test_model` now checks the heartbeat timeouts in History: none for `strands_get_model_config`, 10 seconds for `invoke_model`. Without the change it fails with `assert [None, None] == [None, datetime.timedelta(seconds=10)]`. - `test_sandbox_operations_are_durable_and_factory_runs_for_each_activity` now checks that all seven sandbox Activities get 10 seconds. Without the change, they get none. - `test_heartbeat_timer_counts_from_the_start` blocks the event loop for 0.7 seconds under a 1-second heartbeat timeout, and checks that the first heartbeat comes before the timeout. With the old timer, the first heartbeat would come 1.2 seconds in, so the test fails with `assert ([])`. - `test_slow_model_factory_logs_a_warning` builds a model with a factory that takes 0.3 seconds, under a 0.1-second heartbeat timeout, and checks the warning. A fast factory logs nothing. Without the warning it fails with `assert ("Building model 'slow' took" in '') == True`. - Locally, `make test` (262 passed, 1 skipped), `make lint` and the conventions check pass, on Python 3.12 with uv 0.12.24. With #497 merged in, its two cancellation test files and these tests pass (53 passed). 3. Any docs updates needed? The docstrings and the README are updated here. Release notes should mention the new default, and how to turn it off.
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
temporalio-mcp's operations now heartbeat, andTemporalMCPClientgives them a 10-second heartbeat timeout by default._MCPActivities._run, which all seven operations go through, heartbeats on a timer at half the Activity'sheartbeat_timeoutwhile the operation runs. The beats don't depend on the request's progress, so a slow request isn't mistaken for a lost worker. With no heartbeat timeout, nothing changes.TemporalMCPClientaddsheartbeat_timeout=timedelta(seconds=10)whenactivity_configleaves it out. A timeout you set wins, andheartbeat_timeout=Noneturns heartbeats off.heartbeat_timeoutnow says what the heartbeats do, what they cost in Temporal Cloud, and how to turn them off.Why?
A cancel reaches a running Activity only in a heartbeat's response, and these operations never heartbeated. So a cancelled Workflow's MCP request ran to the end, and a lost worker went unnoticed until the one-minute start-to-close timeout. Setting
heartbeat_timeoutdidn't help either: every request longer than it failed with a heartbeat timeout and retried.Why 10 seconds? #491 has the measurements. It's also what the Claude Agent SDK and Codex plugins already use.
Does this break anything? Not replay: when core replays a scheduled Activity, it only compares its ID and type (#491 has the check). But a run that didn't set
heartbeat_timeoutnow heartbeats, which in Temporal Cloud is at most one Action every 8 seconds of a running request.OpenAI Agents and Strands lock
temporalio-mcp0.2.0 from PyPI, so they get this after a release. Strands always passesheartbeat_timeout,Noneunless you set it, so it stays off there until its own change for #491.Checklist
Closes [Feature Request] mcp: heartbeat MCP operations, with a 10-second default heartbeat timeout #493
How was this tested:
test_operation_heartbeats_while_its_request_runsintest_activities.py: a tool call that waits for the Activity's first heartbeat, with a 100 ms heartbeat timeout. Without the change it never heartbeats, and the test fails withTimeoutErrorafter 5 seconds.test_activity_config_keeps_default_timeout_only_when_needednow also reads the heartbeat timeout from History: 10 seconds by default, and none in a newheartbeat-offcase (heartbeat_timeout=None). Without the change it fails withassert None == datetime.timedelta(seconds=10).make test(139 passed),make lintand the conventions check pass, on Python 3.12 with uv 0.12.24.Any docs updates needed?
The README is updated here. Release notes should mention the new default heartbeat timeout.