Skip to content

Python: Apply caller-supplied run kwargs over checkpoint kwargs on restore - #9853

Open
Abhinav Maurya (Fire162) wants to merge 1 commit into
microsoft:mainfrom
Fire162:fix/caller-kwargs-checkpoint-restore
Open

Abhinav Maurya (Fire162) wants to merge 1 commit into
microsoft:mainfrom
Fire162:fix/caller-kwargs-checkpoint-restore

Conversation

@Fire162

Copy link
Copy Markdown

Motivation & Context

When resuming a workflow from a checkpoint, passing function_invocation_kwargs or client_kwargs did not take effect because checkpoint restoration ran after _run_workflow_with_tracing committed the caller kwargs, wiping state with checkpoint.state. The contract specifies that checkpoint-restored kwargs should be preserved unless the caller explicitly supplies new kwargs on continuation.

Description & Review Guide

  • What are the major changes?
    • In Workflow._run_core, restore the checkpoint (restore_from_checkpoint) before _run_workflow_with_tracing begins (matching the pattern in cancel_pending_requests).
    • Separated _execute_with_message to seed the entry message, and updated _resolve_execution_mode to handle message dispatch and responses cleanly.
    • Added regression test test_caller_kwargs_override_checkpoint_kwargs_on_restore in test_workflow_kwargs.py covering standalone checkpoint_id resumption, subsequent response resumption, and combined checkpoint_id + responses resumption for both function_invocation_kwargs and client_kwargs.
  • What is the impact of these changes?
    • Callers can override run kwargs when resuming workflows from a checkpoint without losing new parameters. Existing behavior without kwargs continues to preserve checkpoint-stored kwargs.
  • What do you want reviewers to focus on?
    • Execution order in _run_core and backward compatibility of _resolve_execution_mode.

Related Issue

Fixes #9850

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: Analysis of checkpoint restoration ordering, implementation in _workflow.py, and regression test in test_workflow_kwargs.py.

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 links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change.

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.

🟡 Changes recommended

Checkpoint restoration occurs outside the tracing/error boundary, so restore failures bypass failure events and error tracing and leave workflow status unchanged.

1 open issue
What changed in this PR

This PR addresses #9850 by restoring Python workflow checkpoints before applying caller-supplied run kwargs, so continuation overrides take precedence over checkpoint values.

Changes:

  • Moves checkpoint restoration ahead of run-kwargs application.
  • Separates initial-message setup from checkpoint and response dispatch.
  • Adds regression coverage for both kwargs channels across checkpoint-only, subsequent-response, and combined resumptions.
File Description
python/​packages/​core/​tests/​workflow/​test_workflow_kwargs.py Tests caller-kwargs precedence when resuming checkpoints.
python/​packages/​core/​agent_framework/​_workflows/​_workflow.py Reorders restoration and refactors execution-mode setup.

Review effort: Balanced

"or build workflow with WorkflowBuilder(checkpoint_storage=checkpoint_storage)."
)

await self._runner.restore_from_checkpoint(checkpoint_id, checkpoint_storage)

This branch was previously deployed

1 inactive deployment
github-app-auth — 9af62f44 Deployed Oct 29, 2026 by Fire162 via team_check #8050
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: [Bug]: Resuming from a checkpoint discards caller-supplied run kwargs, contrary to the documented contract

2 participants