fix: normalize msgpack Binary scalars for deterministic cache hashing#7075
Open
majiayu000 wants to merge 3 commits intoflyteorg:masterfrom
Open
fix: normalize msgpack Binary scalars for deterministic cache hashing#7075majiayu000 wants to merge 3 commits intoflyteorg:masterfrom
majiayu000 wants to merge 3 commits intoflyteorg:masterfrom
Conversation
DictTransformer serializes dicts via msgpack which does not enforce key ordering. Identical dicts with different key orderings produce different byte sequences, leading to unexpected cache misses. Add normalizeMsgpackBytes() in hashify() that unmarshals msgpack bytes and re-marshals to JSON (which sorts map keys deterministically) before hashing. This handles nested dicts and lists. If normalization fails, the original bytes are used unchanged. Closes flyteorg#6776 Signed-off-by: majiayu000 <1835304752@qq.com>
- Rename shadowed variable v → elem in toJSONCompatible range loop
- Allocate new slice in []interface{} case instead of mutating in-place
- Add test for normalizeMsgpackBytes with invalid/corrupted input
- Add test for non-msgpack binary tag passthrough
Signed-off-by: majiayu000 <1835304752@qq.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7075 +/- ##
==========================================
+ Coverage 56.95% 56.96% +0.01%
==========================================
Files 931 931
Lines 58188 58224 +36
==========================================
+ Hits 33141 33170 +29
- Misses 22005 22011 +6
- Partials 3042 3043 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: majiayu000 <1835304752@qq.com>
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.
Tracking issue
Closes #6776
Why are the changes needed?
DictTransformeruses msgpack for serialization, which does not enforce key ordering. When the same dict is serialized on different machines or Python versions, the key order can vary, producing different bytes and therefore different cache hashes. This causes unexpected cache misses for identical inputs.What changes were proposed in this pull request?
In
hashify()(hashing.go), added a normalization step forBinaryscalars with themsgpacktag: unmarshal the msgpack bytes, then re-marshal to JSON (which sorts map keys alphabetically at every nesting level). The normalized JSON bytes replace the original value for hashing purposes only — stored data is unchanged.If normalization fails (e.g., non-standard msgpack), the original bytes are used as-is, preserving backward compatibility.
Changes:
normalizeMsgpackBytes()helper inhashing.gohashify()for Binary literals taggedmsgpackHow was this patch tested?
Added the following tests in
hashing_test.go:TestHashLiteralMap_MsgpackBinaryDeterministic: verifies that two msgpack-encoded maps with identical content but different key orders produce the same hash, including nested structuresTestHashify_NonMsgpackBinaryTag: verifies Binary literals with non-msgpack tags are not modifiedTestNormalizeMsgpackBytes_InvalidInput: verifies graceful fallback on invalid msgpack inputAll existing tests pass:
Labels
Check all the applicable boxes