Skip to content

Fix hash function: use Bun.hash (wyhash) instead of FNV-1a#3

Open
kvkmh wants to merge 1 commit intoithiria894:masterfrom
kvkmh:fix/bun-hash-function
Open

Fix hash function: use Bun.hash (wyhash) instead of FNV-1a#3
kvkmh wants to merge 1 commit intoithiria894:masterfrom
kvkmh:fix/bun-hash-function

Conversation

@kvkmh
Copy link
Copy Markdown

@kvkmh kvkmh commented Apr 7, 2026

Summary

  • Claude Code ships as a Bun executable, so its buddy generation uses Bun.hash() (wyhash), not the FNV-1a fallback. Running the tools with node produces completely different hashes, causing rerolled IDs to generate unexpected species/rarity.
  • Adds Bun.hash detection to the hash function in all three tools (reroll.js, shiny_hunt.js, verify.js)
  • Adds a runtime warning when running under Node instead of Bun
  • Updates README to document the Bun requirement and changes all node commands to bun run

How we found this

We set a userID that our FNV-1a implementation predicted would produce a shiny legendary ghost — but Claude Code hatched an uncommon owl instead. Extracting the actual hash function from the Claude Code binary (~/.local/share/claude/versions/2.1.92) revealed the two code paths:

if (typeof Bun !== "undefined")
  return Number(BigInt(Bun.hash(s)) & 0xffffffffn);  // wyhash — actually used
// FNV-1a fallback — only for non-Bun environments

After switching to Bun.hash, the same ID correctly verified as a shiny legendary ghost and hatched as expected.

Test plan

  • Verified bun run verify.js <id> output matches the actual buddy hatched by Claude Code
  • Verified bun run shiny_hunt.js ghost finds IDs that produce real shiny legendary ghosts
  • Confirmed node run verify.js shows the warning about wrong hash function

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation

    • Updated command examples from node to bun run throughout the guide
    • Clarified hashing implementation details and requirements
  • Changes

    • Application now requires Bun runtime; Node.js is no longer supported
    • Switched to Bun's built-in hash function as primary hashing method
    • Added runtime warnings when executed outside Bun environment

Claude Code ships as a Bun executable, so its buddy generation uses
Bun.hash() (wyhash), not the FNV-1a fallback. Running the tools with
`node` produces completely different hashes, causing rerolled IDs to
generate unexpected species/rarity.

- Add Bun.hash detection to hash functions in all three tools
- Add runtime warning when running under Node instead of Bun
- Update README: document the Bun.hash requirement, change all
  `node` commands to `bun run`, add Bun install prerequisite
- Update FAQ to clarify Bun is required, not optional

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 7, 2026

📝 Walkthrough

Walkthrough

The codebase has been updated to prioritize Bun's native Bun.hash() function (wyhash) over FNV-1a hashing when executing in Bun environments, with FNV-1a retained as a fallback. Runtime warnings notify users when running outside Bun that results will differ. Documentation updated to reflect Bun as the required runtime and changed all command examples from node to bun run.

Changes

Cohort / File(s) Summary
Documentation
README.md
Updated pipeline documentation to specify Bun.hash (wyhash) as the primary hash function with FNV-1a as a fallback, and changed all command examples from node ... to bun run ....
Hash Function Implementations
reroll.js, shiny_hunt.js, verify.js
Modified hash functions to use Bun.hash() with BigInt-to-32-bit conversion when available, retaining FNV-1a as a non-Bun fallback; added runtime console warnings alerting that Node.js execution will produce incorrect results.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰✨ A swift hash now runs through Bun's warp,
No more FNV-1a's weary carp—
When Node tries sneaking, a warning shall blare,
"Use Bun, dear friend, for hashes fair!"

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: updating hash functions from FNV-1a to Bun.hash (wyhash) across the codebase and documentation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
reroll.js (1)

55-58: Consider centralizing hash runtime selection to avoid drift across scripts.

This Bun/FNV fallback logic is now duplicated in reroll.js, shiny_hunt.js, and verify.js. A shared helper would reduce maintenance risk if hash behavior changes again.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@reroll.js` around lines 55 - 58, Create a single shared helper (e.g.,
computeRuntimeHash or getStableHash) that encapsulates the runtime selection
between Bun.hash and the FNV-1a fallback (the existing Bun.hash(...) &
0xffffffffn logic and the FNV-1a fallback used now), export it from a new module
and replace the duplicated logic in reroll.js, shiny_hunt.js, and verify.js to
call that helper; ensure the helper returns a Number and preserves the exact
mask/behavior (0xffffffff) so callers like the current Bun.hash branch and FNV
fallback get identical results.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@reroll.js`:
- Around line 47-53: The script's usage/banner still suggests running with node
which produces wrong results; find the usage banner strings that mention "node
..." (the top-of-file usage/help strings) and update them to instruct users to
run the script with "bun run <script>" (e.g., "bun run reroll.js" or "bun run
<script>") so the banner consistently reflects the Bun requirement; ensure all
occurrences of the old "node" invocation in the banner/help text are replaced
and any explanatory text mentions Bun as the required runtime.

---

Nitpick comments:
In `@reroll.js`:
- Around line 55-58: Create a single shared helper (e.g., computeRuntimeHash or
getStableHash) that encapsulates the runtime selection between Bun.hash and the
FNV-1a fallback (the existing Bun.hash(...) & 0xffffffffn logic and the FNV-1a
fallback used now), export it from a new module and replace the duplicated logic
in reroll.js, shiny_hunt.js, and verify.js to call that helper; ensure the
helper returns a Number and preserves the exact mask/behavior (0xffffffff) so
callers like the current Bun.hash branch and FNV fallback get identical results.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ea2c3243-b526-4b9f-a93e-86ef33bbcce2

📥 Commits

Reviewing files that changed from the base of the PR and between 0a14faa and 19b4934.

📒 Files selected for processing (4)
  • README.md
  • reroll.js
  • shiny_hunt.js
  • verify.js

Comment thread reroll.js
Comment on lines +47 to 53
// ─── Hash: matches Claude Code's actual implementation ──────────────────────
//
// Claude Code uses Bun.hash (wyhash) when running on Bun, with FNV-1a as a
// fallback for non-Bun environments. Since the Claude Code binary ships as a
// Bun executable, Bun.hash is what's actually used in practice. Running this
// tool with Node will produce WRONG results — use `bun run` instead.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Update script usage banner to bun run to match runtime requirement.

The new guidance says Bun is required, but users copying the usage banner (Line 5, Line 8, Line 9) will still run node ... and get mismatched output.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@reroll.js` around lines 47 - 53, The script's usage/banner still suggests
running with node which produces wrong results; find the usage banner strings
that mention "node ..." (the top-of-file usage/help strings) and update them to
instruct users to run the script with "bun run <script>" (e.g., "bun run
reroll.js" or "bun run <script>") so the banner consistently reflects the Bun
requirement; ensure all occurrences of the old "node" invocation in the
banner/help text are replaced and any explanatory text mentions Bun as the
required runtime.

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.

1 participant