Reject late `DynamicToolset` registration under durable execution

Draft
DO
4mo ago
+144-22

Durable execution registers toolset activities, steps, or tasks when the capability binds during Agent construction. A DynamicToolset added later with @agent.toolset was absent from that registration but escaped the runtime guard because the guard re-read the agent’s live toolset list.

This change records every leaf visited during bind-time registration and uses that snapshot when checking toolsets at run time. A decorator-registered DynamicToolset therefore raises a UserError inside a Temporal workflow, DBOS workflow, or Prefect flow, while durable agents remain transparent outside those containers. The error directs users to pass DynamicToolset(..., id=...) through Agent(toolsets=[...]), which remains fully supported and receives its durable units.

The snapshot also includes pass-through leaves and is reset whenever the durable toolset registry is reset. Existing capability-contributed toolset coverage for Capability(tools=...), MCP(...), and DynamicCapability passes without false positives.

Coordination with #6954

The bind-time snapshot makes #6954’s proposed AbstractAgent._registered_toolsets property redundant for rejecting override(toolsets=...): overridden leaves were not visited at bind time, so they are absent from the snapshot without re-reading the agent or adding agent API surface. It does not subsume #6954’s separate run-time id collision guard in get_wrapper_toolset; that remains independent. Thus _registered_toolsets is redundant, while #6954 as a whole is only partially redundant.

Verification

  • uv run pytest tests/test_prefect.py tests/test_dbos.py tests/test_capabilities.py — 1061 passed
  • Targeted Temporal regression test passed without starting the shared Temporal server
  • Each new per-engine regression test fails with the production patch removed
  • PYRIGHT_PYTHON_IGNORE_WARNINGS=1 uv run pyright <changed Python files>
  • uv run ruff check
  • uv run ruff format --check
  • pre-commit passed, including repo typecheck

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.