Skip to content

Python: serialize durabletask options response format - #6819

Closed
VectorPeak (VectorPeak) wants to merge 6 commits into
microsoft:mainfrom
VectorPeak:codex-durabletask-response-format-options
Closed

Python: serialize durabletask options response format#6819
VectorPeak (VectorPeak) wants to merge 6 commits into
microsoft:mainfrom
VectorPeak:codex-durabletask-response-format-options

Conversation

@VectorPeak

@VectorPeak VectorPeak (VectorPeak) commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Motivation & Context

RunRequest.to_dict() already serializes the top-level response_format, but options["response_format"] can still contain a raw Pydantic model class.

That means a durable request like this cannot cross the JSON transport boundary:

RunRequest(
    message="Test",
    correlation_id="corr",
    options={"response_format": MyModel},
)

Calling json.dumps(request.to_dict()) raises because the model class is not JSON serializable. The affected path is:

DurableAIAgent.run(..., options={"response_format": Model})
  -> RunRequest(...)
  -> RunRequest.to_dict()
  -> durable JSON transport

Description & Review Guide

  • What are the major changes?

    • Serialize options["response_format"] using the same module/qualname marker already used for top-level response_format.
    • Deserialize that marker back to the Pydantic model class in RunRequest.from_dict() when it can be resolved.
    • Drop unresolved options-level durable response format markers so they do not block fallback to the top-level response_format.
    • Add regression tests for the JSON boundary and unresolved marker fallback behavior.
  • What is the impact of these changes?

    • Durable RunRequest payloads with options["response_format"] can cross the JSON boundary.
    • Other option keys are preserved unchanged.
    • The top-level response_format behavior is unchanged.
  • What do you want reviewers to focus on?

    • The helper intentionally handles only the known durable response_format option rather than recursively transforming arbitrary options.

Related Issue

Fixes #6821

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) - a workflow keeps the label and title prefix in sync automatically.

Copilot AI review requested due to automatic review settings June 30, 2026 05:21
@moonbox3 Evan Mattson (moonbox3) added the python Usage: [Issues, PRs], Target: Python label Jun 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes durable JSON transport serialization for RunRequest.options["response_format"] by converting Pydantic model classes to the existing {module, qualname} marker format during to_dict(), and restoring them during from_dict(). This ensures durable requests can safely cross a JSON boundary without embedding non-serializable Python class objects.

Changes:

  • Add _serialize_options() to convert options["response_format"] (when it’s a Pydantic model class) into the durable marker dict during RunRequest.to_dict().
  • Add _deserialize_options() to restore options["response_format"] marker dicts back into the Pydantic model class during RunRequest.from_dict().
  • Add a regression test that round-trips to_dict() -> json.dumps/loads -> from_dict() for options["response_format"].

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
python/packages/durabletask/agent_framework_durabletask/_models.py Serializes/deserializes the durable options["response_format"] value to cross JSON boundaries.
python/packages/durabletask/tests/test_models.py Adds regression coverage for JSON round-tripping options["response_format"].

Comment thread python/packages/durabletask/agent_framework_durabletask/_models.py Outdated
@VectorPeak
VectorPeak (VectorPeak) marked this pull request as ready for review June 30, 2026 05:25
@VectorPeak
VectorPeak (VectorPeak) requested a review from a team as a code owner June 30, 2026 05:25
@VectorPeak
VectorPeak (VectorPeak) force-pushed the codex-durabletask-response-format-options branch from 1466fe4 to 7e52b8f Compare June 30, 2026 05:27
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/durabletask/agent_framework_durabletask
   _models.py1741094%41, 44, 63, 66, 71, 76, 93, 183, 223–224
TOTAL43246514388% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
8538 37 💤 0 ❌ 0 🔥 2m 15s ⏱️

@moonbox3

Copy link
Copy Markdown
Contributor

VectorPeak (@VectorPeak) please have a look at the failing CI/CD checks.

@VectorPeak

Copy link
Copy Markdown
Contributor Author

Thanks for the heads up. I fixed the failing Package Checks (3.11) pyright issue in packages/durabletask and pushed commit 0497b090b to this PR branch.

Local validation passed:

  • uv run --directory D:\ZXY\Github\agent-framework\python poe pyright -P durabletask
  • uv run --directory D:\ZXY\Github\agent-framework\python poe syntax -P durabletask --check
  • uv run --directory D:\ZXY\Github\agent-framework\python pytest packages\durabletask\tests\test_models.py

The new GitHub Actions pull_request runs for this fork PR are currently in action_required state and require maintainer/admin approval before they can run. I tried approving/rerunning them, but GitHub returned 403 Must have admin rights to Repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Python durabletask RunRequest options response_format is not JSON serializable

3 participants