Skip to content

fix(config): keep codename hash architecture-stable on 32-bit - #2667

Merged
max-sixty merged 1 commit into
mainfrom
fix/issue-2663-codename-index-32bit
May 10, 2026
Merged

max-sixty merged 1 commit into
mainfrom
fix/issue-2663-codename-index-32bit

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Summary

codename_index hashes 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 target as usize truncates 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_stable snapshots cover stability and remain green.

Test plan

  • cargo test --lib codename (5 tests) passes
  • Snapshot for test_codename_outputs_are_stable is unchanged (verified by passing test)

Closes part of #2663.

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]>
@max-sixty
max-sixty merged commit f0ffe77 into main May 10, 2026
31 checks passed
@max-sixty
max-sixty deleted the fix/issue-2663-codename-index-32bit branch May 10, 2026 14:58
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