Skip to content

fix(itg): only propagate string-valued attributes through the optimiz… - #316

Merged
yushan8 merged 4 commits into
mainfrom
itg-attribute-string-type
Sep 22, 2026
Merged

yushan8 merged 4 commits into
mainfrom
itg-attribute-string-type

Conversation

@yushan8

@yushan8 yushan8 commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

OptimizedGraph.AddTarget and upsertTarget previously recorded every target attribute via GetName()/GetStringValue(), regardless of its underlying type. For non-string attributes (bool, int, label lists, etc.) this silently coerced values through the zero-value string getters, corrupting the stored attribute map.

Only record attributes whose Type is buildpb.Attribute_STRING and whose Name/StringValue are non-nil. OptimizedTargetToTarget now also sets Type explicitly to buildpb.Attribute_STRING when reconstructing attributes, since every attribute stored in the optimized graph is now guaranteed to be string-valued and downstream consumers that check GetType() should not see an ambiguous zero-value default. This matches the OptimizedTarget graph format with tgb as well.

TODO: support non-string based attribute values #318

Test Plan

unit tests and tested internally

…ed graph

OptimizedGraph.AddTarget and upsertTarget previously recorded every
target attribute via GetName()/GetStringValue(), regardless of its
underlying type. For non-string attributes (bool, int, label lists,
etc.) this silently coerced values through the zero-value string
getters, corrupting the stored attribute map.

Only record attributes whose Type is buildpb.Attribute_STRING and
whose Name/StringValue are non-nil. OptimizedTargetToTarget now also
sets Type explicitly to buildpb.Attribute_STRING when reconstructing
attributes, since every attribute stored in the optimized graph is now
guaranteed to be string-valued and downstream consumers that check
GetType() should not see an ambiguous zero-value default.

Co-Authored-By: Claude Sonnet 5 <ANONYMIZED_EMAIL_ADDRESS_0_5>
@yushan8
yushan8 requested review from a team as code owners September 22, 2026 20:37
@yushan8
yushan8 marked this pull request as draft September 22, 2026 21:51
@yushan8
yushan8 marked this pull request as ready for review September 22, 2026 21:58
Comment thread core/itg/graph/graph.go Outdated
Comment thread core/itg/graph/graph.go
continue
}
attrNameID := getOrGenerateRecordReverse(*attr.Name, g.AttrNameToID, g.AttrNameIDToString)
attrValueID := getOrGenerateRecordReverse(*attr.StringValue, g.AttrValueToID, g.AttrValueIDToString)

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.

also btw does stringList order matter? such as tags = ["a", "b"] vs tags = ["b", "a"]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good q, it does. Added a test to verify.

Make the STRING-type attribute filter in AddTarget/upsertTarget
explicitly skip a nil *buildpb.Attribute element instead of relying on
GetType()'s nil-safe default (Attribute_INTEGER) short-circuiting the
`||` before the nil-unsafe Name/StringValue field reads. Behavior is
unchanged, but the safety is now explicit rather than incidental.

Co-Authored-By: Claude Sonnet 5 <ANONYMIZED_EMAIL_ADDRESS_0_6>
Directly answers the PR review question on this branch about whether
StringListValue order (e.g. tags = ["a","b"] vs ["b","a"]) affects the
target hash. It doesn't: HashRuleCommon's canonical encoder sorts
string-list attribute values before hashing, so itg's
computeAvailableHashes produces an identical HashWithoutDeps for both
orderings. Verified this assertion actually exercises the sort by
temporarily removing it and confirming the new test fails.

Co-Authored-By: Claude Sonnet 5 <ANONYMIZED_EMAIL_ADDRESS_0_7>
@yushan8
yushan8 merged commit 50b3695 into main Sep 22, 2026
10 checks passed
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.

2 participants