Skip to content

Python: find state type of step declared as KernelProcessStep[State] (#14734) - #14739

Open
MOHAMMED WASIM KHAN (wasim-builds) wants to merge 1 commit into
microsoft:mainfrom
wasim-builds:fix/issue-14734-generic-step-state
Open

MOHAMMED WASIM KHAN (wasim-builds) wants to merge 1 commit into
microsoft:mainfrom
wasim-builds:fix/issue-14734-generic-step-state

Conversation

@wasim-builds

Copy link
Copy Markdown
Contributor

Motivation and Context

A process step that names its state type only in the base class, like class Counter(KernelProcessStep[CounterState]), was treated as stateless:

  • initial_state=CounterState(...) raised ProcessInvalidConfigurationException: ... the step does not accept a state
  • The step got no default state
  • State restored from KernelProcessStateMetadata stayed a plain dict
  • The state was left out of saved process state upon persistence

Caught in #14734 by PRABHU KIRAN VANDRANKI (@VANDRANKI) (thanks for the clear repro and root-cause write-up).

Fixes #14734

Description

  1. In get_generic_state_type, when the type hint is still a TypeVar (which happens when parameterized only in the base class KernelProcessStep[TState]), inspect model_fields["state"].annotation of the class where Pydantic has resolved the field annotation to the concrete state type. Plain/unparameterized KernelProcessStep steps continue to return None.
  2. In ProcessStepBuilder.build_step, instantiate the default state with t_state() and support restoring both Pydantic models and @dataclass state instances from metadata dictionaries (t_state(**candidate) when hasattr(t_state, "__fields__") or is_dataclass(t_state)).
  3. Adds comprehensive unit tests:
    • 3 tests in tests/unit/processes/test_process_types.py covering parameterized steps, inherited parameterized steps, and unparameterized controls.
    • 7 end-to-end tests in tests/unit/processes/test_process_step_generic_state.py verifying default state creation, initial_state acceptance, metadata restoration, and saved state persistence for both Pydantic and dataclass state types.

Contribution Checklist

…tate]

get_generic_state_type returned None for a step that names its state only in the base class,
because the type hint of 'state' is still the TypeVar there. Such a step then refused an
initial_state, got no default state, got a raw dict when restored, and had its state left out
of the saved process state. The concrete type is now read from the pydantic field annotation.
Default and restored states are also created for dataclass state types.
Copilot AI balanced review requested due to automatic review settings November 7, 2026 04:44

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@semantic-kernel-automation semantic-kernel-automation Bot added the python Pull requests for the Python Semantic Kernel label Nov 7, 2026

This branch was previously deployed

1 inactive deployment
github-app-auth — 0f585513 Deployed Nov 7, 2026 by wasim-builds via add_label #29619
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Pull requests for the Python Semantic Kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Bug: a process step declared as KernelProcessStep[State] is treated as stateless, so initial_state is rejected and its state is not saved

3 participants