Skip to content

fix(inventory): make change hash order invariant - #233

Merged
ooolafhu merged 2 commits into
mainfrom
fix/compute-hash-sort
Jul 22, 2026
Merged

fix(inventory): make change hash order invariant#233
ooolafhu merged 2 commits into
mainfrom
fix/compute-hash-sort

Conversation

@ooolafhu

@ooolafhu ooolafhu commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Description

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

Summary by CodeRabbit

  • Bug Fixes
    • Improved inventory signature stability by deterministically ordering set-like fields and nested resource lists before hashing.
    • Real content changes (for example, GPU identifiers or block device parent details) still update the signature, while parent ordering changes behave as expected.
    • Added clearer error behavior for nil inventory snapshots.
  • Tests
    • Expanded coverage to ensure reordering does not change the computed hash (and does not mutate the original snapshot), validates detection of meaningful item changes, and confirms proper handling of nil input.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 12dc5877-3627-4a43-b267-acba149c3b62

📥 Commits

Reviewing files that changed from the base of the PR and between ef434c7 and 374734b.

📒 Files selected for processing (2)
  • internal/inventory/hash.go
  • internal/inventory/hash_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/inventory/hash.go
  • internal/inventory/hash_test.go

📝 Walkthrough

Walkthrough

ComputeHash now canonicalizes unordered component and resource collections before hashing. Tests verify order independence, input immutability, content sensitivity, parent ordering, and nil snapshot errors.

Changes

Inventory hashing

Layer / File(s) Summary
Canonicalize inventory fields
internal/inventory/hash.go
ComputeHash sorts component lists and canonicalizes GPU, block device, and NIC interface slices using stable JSON ordering, with helpers and error handling.
Validate hash stability and sensitivity
internal/inventory/hash_test.go
Tests verify reordered set-like fields produce equal hashes without mutation, while item changes, parent ordering, and nil snapshots produce the expected results.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: making inventory change hashing order-invariant.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/compute-hash-sort

Comment @coderabbitai help to get the list of available commands.

Signed-off-by: xuefengh <xuefengh@nvidia.com>
@ooolafhu
ooolafhu force-pushed the fix/compute-hash-sort branch from feaf348 to ef434c7 Compare July 22, 2026 20:06
Signed-off-by: xuefengh <xuefengh@nvidia.com>
@ooolafhu
ooolafhu requested a review from jingxiang-z July 22, 2026 20:20
@ooolafhu
ooolafhu merged commit 2462b30 into main Jul 22, 2026
9 checks passed
@ooolafhu
ooolafhu deleted the fix/compute-hash-sort branch July 22, 2026 20:41
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