Skip to content

Python: fix kernel_function decorator mutating shared Annotated metadata dicts - #14442

Open
Manohar Paturi (ManoharPaturi) wants to merge 1 commit into
microsoft:mainfrom
ManoharPaturi:fix/kernel-function-metadata-mutation
Open

Manohar Paturi (ManoharPaturi) wants to merge 1 commit into
microsoft:mainfrom
ManoharPaturi:fix/kernel-function-metadata-mutation

Conversation

@ManoharPaturi

Copy link
Copy Markdown

Fixes #14441.

_parse_parameter() now reads the description with get() and copies only known keys into the parameter metadata instead of pop()-ing from the Annotated dict, so decoration never mutates caller-owned dicts and shared metadata keeps working across functions.

2 regression tests (shared-dict reuse keeps descriptions; source dict untouched) fail on main and pass here; tests/unit/functions green.

…ata dicts

_parse_parameter() called meta.pop("description") on dict metadata used
in typing.Annotated, mutating the user-provided dict. When the same
metadata dict is reused across multiple kernel functions (shared
parameter docs), every function after the first silently lost its
parameter description, and the dict itself was permanently modified.

Use meta.get() instead of meta.pop() and filter the description key out
when applying the remaining metadata keys, so semantics are unchanged
but the caller's dict is left untouched.

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 reached their quota limit.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The original mutation issue is fixed on main. The inline comment identifies an additional behavior change that is not described in this PR. Its old label/review/gate runs also need fresh validation if this is retained as a separate fix.

if "description" not in ret and (description := meta.get("description", None)):
ret["description"] = description
ret.update(meta)
ret.update({key: value for key, value in meta.items() if key != "description"})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The mutation bug is already fixed on main by #14496 using a local dict copy. This version also changes description precedence: Annotated[int, "earlier string", {"description": "later dictionary"}] currently produces "later dictionary", but this filtering produces "earlier string". I reproduced both results. Is that additional behavior change intentional? Please clarify the remaining bug and cover the precedence rule before rebasing; otherwise the original shared-metadata fix is already delivered.

This branch had an error being deployed

1 failed deployment
github-app-auth — 851efcef Deployed Sep 13, 2026 by ManoharPaturi via review #510
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.

Python: @kernel_function mutates shared Annotated metadata dicts (description lost after first use)

3 participants