Repository navigation
fix(config): keep codename hash architecture-stable on 32-bit - #2667
Merged
Merged
Conversation
The function hashed through u64 specifically to keep the index identical across 32-bit and 64-bit, but the final cast was `(u64 as usize) % len` — on 32-bit `as usize` truncates to 32 bits before the modulo, so the same branch would pick a different word than on 64-bit, defeating the whole point of the u64 indirection. Take the modulo in u64 first, then narrow. No-op on 64-bit (the existing `test_codename_outputs_are_stable` snapshots are unchanged), correct on 32-bit. Worktrunk doesn't ship 32-bit binaries today, so this is a correctness fix for the comment more than for any user — but the comment was making a load-bearing claim, so do the matching arithmetic. Closes part of #2663. Co-Authored-By: Claude Opus 4.7 <[email protected]>
This was referenced May 10, 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
codename_indexhashes through u64 with a comment promising the result is identical across 32-bit and 64-bit builds, but the last line cast(u64::from_le_bytes(bytes) as usize) % len— on a 32-bit targetas usizetruncates to the low 32 bits before the modulo, so the upper 32 bits of the SHA-256-derived integer never participate, and 32-bit and 64-bit pick different words for the same branch. Worktrunk doesn't ship 32-bit binaries today (so no user is affected in practice), but the comment was load-bearing — keep the modulo in u64, then narrow.No-op on 64-bit. The existing
test_codename_outputs_are_stablesnapshots cover stability and remain green.Test plan
cargo test --lib codename(5 tests) passestest_codename_outputs_are_stableis unchanged (verified by passing test)Closes part of #2663.