Reject `override(toolsets=...)` and run-time `id` collisions under durable execution

Closed
DO
3mo ago
+350-55

The shared defect

Both issues let a toolset the agent was not constructed with escape durable wrapping:

  • override(toolsets=...) replaced the construction-time list while the runtime guard was deciding which leaves were registered.
  • @agent.toolset appended a DynamicToolset after construction and after the engine created its activities, steps, or tasks.

The fix makes _registered_toolsets the single answer to β€œwhat was this agent built with?” Agent._build_toolset_list(ignore_overrides=True) now ignores contextual overrides and slices decorator-added dynamic toolsets off at the constructor-time boundary. The durable runtime guard re-reads that live view during each run, so capability-contributed toolsets that are legitimately recreated per run are compared with the current capability tree rather than stale object identities.

Executing toolsets that arrive later are rejected inside a workflow or flow through each engine's existing _unsupported_runtime_toolset_kinds. Outside a durable container, the capability remains transparent. The error directs users to pass DynamicToolset(..., id='...') through Agent(toolsets=[...]).

Why #6946 was superseded

#6946 was closed as superseded by this PR. Its bind-time snapshot of registered leaf object identities failed because capability-contributed toolsets are legitimately recreated per run. Fresh runtime identities were therefore misclassified as late arrivals, including by test_durability_validates_only_resolved_runtime_capability_layers. This PR deliberately uses a live re-read of _registered_toolsets instead.

Existing #6908 behavior

The existing change continues to:

  • reject unsupported executing toolsets passed through run(toolsets=...) or override(toolsets=...);
  • preserve DBOS's deliberate allowance for FunctionToolset, whose tools run inline;
  • reject run-time toolsets that reuse a registered id, preventing dispatch to the wrong wrapped toolset.

Tests and docs

Each durable engine now covers:

  • a decorator-registered DynamicToolset working outside the durable container;
  • the same registration raising UserError inside a workflow or flow;
  • DynamicToolset(..., id='...') passed to Agent(toolsets=[...]) receiving activities, steps, or tasks.

The Temporal, DBOS, and Prefect guides and the bundled agent-building skill now state that every executing toolset must be passed to the constructor under durable execution. Temporal no longer recommends decorator id= as a durable configuration.

Checklist

  • Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
  • No breaking changes in accordance with the version policy.
  • PR title is fit for the release changelog.