fix: make collection document node order deterministic - #113
Open
ehennestad wants to merge 1 commit into
Open
Conversation
Contributor
Test Results (R2022a)700 tests 700 ✅ 2m 24s ⏱️ Results for commit c88ae83. ♻️ This comment has been updated with latest results. |
Contributor
Test Results (R2026a)700 tests 700 ✅ 2m 17s ⏱️ Results for commit c88ae83. ♻️ This comment has been updated with latest results. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #113 +/- ##
==========================================
+ Coverage 77.07% 77.11% +0.03%
==========================================
Files 417 417
Lines 4022 4028 +6
==========================================
+ Hits 3100 3106 +6
Misses 922 922 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The nodes of a collection document appeared in whatever order the collection returned them, and that order depends on the MATLAB release. Collection stores its nodes in a dictionary from R2022b, which preserves insertion order, and in a containers.Map on older releases, which returns values sorted by key. The same collection therefore serialized to a different document on R2022a than on R2022b and later. A @graph is semantically an unordered set, so no reader is affected by the order. But a document that differs by release cannot be compared against a golden file, defeats reproducible output for users who keep their metadata under version control, and produces noisy diffs when the same collection is saved from two machines. The nodes of a collection document are now sorted by @id before the document is assembled. Documents emitted separately, one per instance, are not reordered, because the folder store pairs them with their instances by position. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
ehennestad
force-pushed
the
fix-collection-document-node-order
branch
from
September 1, 2026 14:31
b3b4115 to
c88ae83
Compare
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.
Found by the R2022a leg of CI failing
FixtureTest/testSerializedOutputMatchesGoldenFixtureon every PR in this stack, while the R2026a leg passed.The defect
The nodes of a collection document appeared in whatever order
Collectionreturned them, and that order depends on the MATLAB release.Collectionstores its nodes in adictionaryfrom R2022b, which preserves insertion order, and in acontainers.Mapon older releases, which returns values sorted by key. The same collection therefore serialized to a different document on R2022a than on R2022b and later — the CI log showed the nodes alphabetical by@idon R2022a, while the golden fixture, generated on R2025b, held them in insertion order.A
@graphis semantically an unordered set, so no conforming reader is affected. But a document that differs by release cannot be compared against a golden file, defeats reproducible output for anyone keeping their metadata under version control, and produces noisy diffs when the same collection is saved from two machines.The fix
The nodes of a collection document are sorted by
@idbefore the document is assembled, inJsonLdSerializer.createCollectionDocument. Both container types then produce byte-identical documents, and the golden fixture comparison in the PR above this one is release-independent.Documents emitted separately, one per instance, are deliberately not reordered:
FolderMetadataStorepairs serialized documents with their instances by position, so reordering them would write each document to the wrong file.Regenerating the golden fixture under this ordering (done in the PR above) reproduced byte-for-byte the order R2022a emitted in CI, which confirms the diagnosis.
Why it sits at the bottom of the stack
The golden fixture is introduced by the tests PR directly above, and its comparison only holds across releases once the order is deterministic. Every PR in the stack inherits the fix, so all CI legs can go green from the bottom up.
An alternative was to make the fixture comparison order-insensitive and leave the output nondeterministic. That would hide the release dependence rather than remove it, and would weaken the byte-for-byte comparison that caught two shape regressions while the serializer was being reworked later in this stack.
🤖 Generated with Claude Code