Skip to content

chore: sort resource messages for deterministic generation#16756

Draft
ohmayr wants to merge 2 commits intomainfrom
sort-resource-names
Draft

chore: sort resource messages for deterministic generation#16756
ohmayr wants to merge 2 commits intomainfrom
sort-resource-names

Conversation

@ohmayr
Copy link
Copy Markdown
Contributor

@ohmayr ohmayr commented Apr 21, 2026

sort resource messages for deterministic generation

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces deterministic ordering for resource messages by sorting them before they are returned, changing several return types from frozenset to tuple or sorted OrderedDict. This change ensures consistent output across different runs. A review comment suggests refining the sorting logic in wrappers.py by using a composite key to prevent non-deterministic behavior in case of attribute ties.

Comment on lines +2319 to +2322
sorted_messages = sorted(
unique_messages,
key=lambda m: m.resource_type_full_path or m.name
)
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.

medium

The current sorting key m.resource_type_full_path or m.name may not guarantee deterministic ordering if multiple messages share the same resource type path or if a message name conflicts with a resource type path. Since the input is a frozenset (which is unordered), any tie in the sort key will result in non-deterministic output order across different runs.

Consider using a tuple as a sort key to provide a consistent tie-breaker, such as (m.resource_type_full_path or "", m.name).

Suggested change
sorted_messages = sorted(
unique_messages,
key=lambda m: m.resource_type_full_path or m.name
)
sorted_messages = sorted(
unique_messages,
key=lambda m: (m.resource_type_full_path or "", m.name)
)
References
  1. To ensure dictionary keys remain sorted without manual effort, programmatically sort the dictionary before returning it instead of relying on manual ordering in the code.

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.

1 participant