Repository navigation
Require temporalio-mcp 0.4 in OpenAI Agents and Strands - #435
Conversation
Widen temporalio-mcp from >=0.2.0,<0.3 to >=0.2.0,<0.4 in the mcp extra and dev group of both plugins, so they can pick up 0.3.0's lost-session retry (#379) before GA. The locks stay on 0.2.0 until 0.3.0 is on PyPI.
|
Here's what I ran on temporalio-mcp 0.3.0 with these pins. Once 0.3.0 is on PyPI, I'll refresh the locks and rerun on the published package. How did I test it with the plugins?I built a local candidate: the GA release candidate plus #433, #434 (before its test-helper change) and #435. I built temporalio-mcp from that tree as 0.3.0 and installed it over each plugin's lock. Then I reran everything we have for the two plugins that use temporalio-mcp: OpenAI Agents and Strands (both Python). I compared each result with the same check on the release candidate, which used temporalio-mcp 0.2.0.
What changed, on purpose?
What didn't change?The items that failed on the release candidate still fail the same way here, and none of them comes from temporalio-mcp. In OpenAI Agents, two defect fix checks and five feature checks were already failing on the release candidate. Only three defect checks and one feature item in OpenAI Agents go through the temporalio-mcp route; the rest of its MCP evidence uses the deprecated providers, which don't import it. Anything flaky, or not run?
|
Refresh both locks with uv lock --upgrade-package temporalio-mcp now that 0.3.0 is on PyPI. It adds exceptiongroup on Python 3.10.
… 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.
…and correct the MCP README (#377) ## What was changed Misconfigured Strands MCP factories can fail every Activity attempt and retry without limit. This PR rejects factories that need arguments or aren't callable when the plugin is built. It reports wrong client types and function transports as typed, non-retryable Activity errors. - `StrandsPlugin(mcp_clients=...)` refuses a factory that needs arguments with a `TypeError` that names the server. On Python 3.14+, the check reads the factory's parameters without evaluating its annotations, so `-> Client` with `Client` imported only under `TYPE_CHECKING` still works. - It also refuses a factory that isn't callable, such as a client passed in its place: `MCP server factory 'weather' is mcp.client.client.Client, not callable`. - A factory that returns something other than an `mcp.Client` fails with type `MCPServerFactoryTypeError`. When an async factory returns a coroutine, the coroutine is closed first, so Python doesn't warn that it was never awaited. - A factory that returns an `mcp.Client` built on a plain function fails with type `MCPServerFactoryTransportError`. This catches `Client(lambda: stdio_client(...))`, the shape an old Strands factory takes when only its import changes. Both Activity errors name the server and the fix, and set `non_retryable=True`, matching the factory configuration checks in #451. The README and plugin docstring also clarify that factories run for every connection and must return a fresh client and transport. The README explains the `factory_argument` limit, resumed interrupts, and the retry, idle-timeout and connection changes from #190. It also covers rejected MCP results. With `temporalio-mcp` 0.4, which this plugin requires since #435, two kinds of rejected result reach the agent at once as a failed tool result, without a retry: a malformed result the MCP client can't parse, and a result that breaks the tool's output schema. The tests run the factory checks through the plugin's list-tools Activity and check the error types and non-retryable flags. Factories that take no arguments (a lambda, a defaulted parameter, a callable object, a `functools.partial`, and on 3.14+ an annotation that exists only under `TYPE_CHECKING`) list tools through the same Activity. The tests also cover idle-timeout forwarding, tool filtering and failed tool results. A malformed result and an output-schema mismatch go through the call-tool Activity, with a valid result as the control. Both rejected results fail with a non-retryable `MCPProtocolError`. ## Why? Follow-up to the [last review of #190](#190 (review)), which found these factory checks and README gaps. ## Is it breaking? (Breaking) Wrong client types and function transports already failed, but those failures were retryable. They now stop the Activity without retries, including on the next attempt of an in-flight Activity. Fix these factories before upgrading: deploying a corrected Worker won't resume an Activity that has already failed. A factory that isn't callable used to start the worker and then fail every MCP Activity with a retryable `TypeError`. Now `StrandsPlugin(...)` raises, even when no workflow uses that server. The README includes these upgrade warnings. No Workflow code changes. ## Checklist 1. Related: #320, #376, #435 and #451. No issue to close. 2. How was this tested: - `make test PYTEST_ARGS='-n 4 -q'` on Python 3.13: 293 passed, 2 skipped. - The same on Python 3.14: 295 passed. - `make lint` on Python 3.13 and 3.14: ruff import sorting and formatting, pyright, mypy, basedpyright and pydocstyle passed. pyright, mypy and basedpyright also passed when targeting Python 3.11 and 3.15. I couldn't set up a 3.15 environment locally (`pydantic-core` has no 3.15 wheel yet), so the CI cell covers a real 3.15 run. - After adding the startup check and the coroutine close: `make test` on Python 3.12, 294 passed, and `make lint` passed. The extended factory test fails without each of the two changes. - `git diff --check` passed. 3. Any docs updates needed? - The plugin README's MCP section is updated. - Outside this repo, to land with the release: `strands_plugin/mcp/run_worker.py` in temporalio/samples-python, and the Strands page in temporalio/documentation, which renders that sample. Both still build Strands' `MCPClient` and don't install the `mcp` extra.
What was changed
temporalio-mcp>=0.4.0,<0.5instead of>=0.2.0,<0.3, in theirmcpextra and dev group.uv.lockfiles now resolve the published 0.4.0. No other locked package changes.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-mcp0.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:
mcp_servers)mcp_clients)ExceptionGroupfixes (mcp: fail an MCPError wrapped in an ExceptionGroup without retrying it #411, mcp: fail an invalid response wrapped in an ExceptionGroup without retrying it #433, mcp: fail a repeated pagination cursor without retrying it when the client has a factory argument #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_timeoutwhen the Activity config leaves it out. So a cancel reaches a running MCP request, and a request longer than aheartbeat_timeoutyou set no longer fails with a heartbeat timeout.workflow.temporal_mcp_server()passesactivity_configtoTemporalMCPClientas 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=Noneturns it off.TemporalMCPClientalways passesheartbeat_timeout,Noneunless 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-mcpwith 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, andtemporalio.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?
temporalio-mcp0.4, with its lost-session retry and its default heartbeat timeout.Checklist
Closes: no issue.
How was this tested:
make sync,make lintandmake testpass in both plugins withtemporalio-mcp0.4.0 installed (OpenAI Agents: 626 passed, 2 skipped; Strands: 279 passed, 1 skipped).heartbeat_timeoutset on Strands'TemporalMCPClientno longer times out MCP requests, andtemporal_mcp_server()operations are scheduled with a 10-second heartbeat timeout. Everything else matches the 0.3.0 run.main10f9082, 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).temporal_mcp_server()docstring is updated here; no README changes. The release notes need the Breaking line under "What's left?".