Skip to content

Fix pydantic.ext ToolReturn/deferred metadata, turnstile handling, and durable iter() - #241

Open
sharosoo wants to merge 1 commit into
restatedev:mainfrom
sharosoo:fix/restate-sdk-python-pydantic-fix
Open

sharosoo wants to merge 1 commit into
restatedev:mainfrom
sharosoo:fix/restate-sdk-python-pydantic-fix

Conversation

@sharosoo

Copy link
Copy Markdown

Fixes #237.

Changes

  • _toolset.py: Preserve ToolReturn (return_value, content, metadata) via a typed tool_return: ToolReturn | None = None field on RestateContextRunResult, and preserve CallDeferred.metadata / ApprovalRequired.metadata via metadata: dict[str, Any] | None = None. Default both fields to None so existing journal entries continue to deserialize.
  • _toolset.py & turnstile.py: Call turnstile.allow_next_after(id) and do not cancel sibling tool calls when a tool raises CallDeferred, ApprovalRequired, or ModelRetry. Ignore untracked tool_call_id values in Turnstile.wait_for and cancel_all_after (such as resumed deferred tool calls before the first model request or nested tool calls) unless the turnstile is already canceled.
  • _model.py: Initialize current_state().turnstile in RestateModelWrapper.request_stream just as in request (also addresses pydantic ext: request_stream() never initializes the turnstile — KeyError('call_...') on first tool call of a streamed run #223).
  • _agent.py: Override RestateAgent.iter() with with self._restate_overrides(): and matching output-type overloads so agent.iter() uses the durable model and toolset wrappers.
  • tests/test_pydantic_ext.py: Add 13 unit tests covering ToolReturn round-trip, CallDeferred metadata, parallel ApprovalRequired / CallDeferred / ModelRetry sibling execution, request_stream turnstile initialization, resumed deferred tool calls, untracked turnstile IDs, and durable agent.iter().

@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

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.

pydantic ext: tool results lose ToolReturn and deferred metadata, turnstile breaks on deferred and nested calls, iter() is not durable

1 participant