fix(recipe bug): treat empty string as "any" in Criteria.Specificity()#492
Merged
yuanchen8911 merged 1 commit intoNVIDIA:mainfrom Apr 6, 2026
Merged
Conversation
When overlay YAML is parsed, omitted criteria fields get the Go zero value "" (empty string), not the "any" constant. Specificity() checked only field \!= "any", so empty fields contributed to the score — making all overlays report specificity 4-5 regardless of how many criteria fields they actually specify. This made the sort in FindMatchingOverlays non-deterministic for overlays with different numbers of specified criteria. Align Specificity() with Matches() and MatchesCriteriaField(), which already treat "" as equivalent to "any". Add regression tests covering YAML-parsed zero-value criteria (empty strings) alongside the existing tests that use explicit Criteria*Any values. Signed-off-by: Yuan Chen <yuanchen97@gmail.com>
ayuskauskas
approved these changes
Apr 6, 2026
This was referenced Apr 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fix
Specificity()to treat empty string""as equivalent to"any"for YAML-parsed criteria fields, consistent withMatches()andMatchesCriteriaField().Motivation / Context
When overlay YAML is parsed, omitted criteria fields get the Go zero value
"", not the"any"constant.Specificity()checked onlyfield \!= "any", so empty fields contributed to the score — all overlays reported specificity 4-5 regardless of how many criteria fields they actually specify. This made the sort inFindMatchingOverlaysnon-deterministic for overlays at different specificity levels.The bug was masked by the current linear overlay tree structure (every matching overlay is an ancestor of the most-specific leaf). It becomes observable with any overlay structure that has competing matches at different specificity levels.
Discovered during prototype implementation of ADR-005 (PR #439).
Fixes: N/A
Related: #439, #305
Type of Change
Component(s) Affected
cmd/aicr,pkg/cli)cmd/aicrd,pkg/api,pkg/server)pkg/recipe)pkg/bundler,pkg/component/*)pkg/collector,pkg/snapshotter)pkg/validator)pkg/errors,pkg/k8s)docs/,examples/)Implementation Notes
The fix adds
&& field \!= ""to each specificity check, aligning with the existing logic inMatchesCriteriaField()which already treats both""and"any"as wildcards.Regression tests cover YAML-parsed zero-value criteria (struct literals with omitted fields) alongside the existing tests that use explicit
Criteria*Anyvalues.Observable behavior change:
appliedOverlaysmetadata may list overlays in a different order for queries that matchb200-any-trainingorgb200-any-training(these overlays now sort at their correct specificity). Hydrated recipe content (constraints, components, validation, deployment order) is unchanged for all current leaf overlays.Testing
go test -race -v ./pkg/recipe/... -run TestCriteriaSpecificityGolden-file comparison of all current leaf overlays confirms zero semantic change to hydrated recipe output.
Risk Assessment
Rollout notes: No migration needed. The fix only affects sort ordering of overlays with different specificity levels. Current overlay tree is linear, so recipe output is unchanged.
Checklist
make testwith-race)make lint)git commit -S) — GPG signing info