Skip to content

Make transformed tool required order deterministic - #4564

Merged
strawgate merged 1 commit into
PrefectHQ:mainfrom
Kludex:fix/deterministic-required-order
Jul 20, 2026
Merged

Make transformed tool required order deterministic#4564
strawgate merged 1 commit into
PrefectHQ:mainfrom
Kludex:fix/deterministic-required-order

Conversation

@Kludex

@Kludex Kludex commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #4565

Snapshot-testing tools/list output was impossible for servers using transformed tools: the JSON changed between test runs. The cause is that TransformedTool built its required array with list(set), so the order depended on Python's per-process hash randomization (PYTHONHASHSEED) — every fresh interpreter could produce a different ordering of the same schema.

This PR makes required follow the schema's property order in both _create_forwarding_transform and _merge_schema_with_precedence, so the wire format is stable across processes (and easier to read). Verified by hashing tools/list JSON under several PYTHONHASHSEED values: previously every seed produced a different result; now they're identical.

base = Tool.from_function(fn)  # fn(alpha, beta, gamma, delta, epsilon)
transformed = Tool.from_tool(base, transform_args={"alpha": ArgTransform(name="a")})

transformed.parameters["required"]
# before: ['delta', 'a', 'epsilon', 'gamma', 'beta']  (varies per process)
# after:  ['a', 'beta', 'gamma', 'delta', 'epsilon']  (always property order)

Label: bugs

🤖 Generated with GitHub Copilot CLI

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

@github-actions github-actions Bot closed this Jul 20, 2026
@marvin-context-protocol marvin-context-protocol Bot added bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. low-priority labels Jul 20, 2026
@github-actions github-actions Bot reopened this Jul 20, 2026

@strawgate strawgate left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Lgtm

@strawgate
strawgate merged commit 7934124 into PrefectHQ:main Jul 20, 2026
22 of 25 checks passed
jlowin added a commit that referenced this pull request Jul 27, 2026
(cherry picked from commit 7934124)

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Transformed tool required order is nondeterministic across processes

2 participants