[engine] Check for old resources first by URN and then aliases #13883
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change fixes a regression in the step generator when looking for old resources. When generating steps for a register resource event, we previously looked for old resources first by the resource's URN and then by aliases.
This regressed with #10819:
Previously, aliases were in a slice and we always looked for the URN first, then aliases.
With #10819, aliases changed to being stored in a map (a set). The URN was added to the map before iterating over it, but there's no guarantee it will be looked at first (iteration order for maps is unspecified), and with the current behavior when there are aliases in the map, the URN very likely won't come first.
This can lead to duplicate resources in the state (stack corruption) when the wrong old resource is chosen.
The fix is to move back to always checking for old resources using the URN first. We also move back to maintaining aliases in a slice for consistent ordering.
Fixes #13848