ReviewOS

also looking at this

home-lang/home

fix(runtime): realign ResolvedSource.Tag ids to the linked (pinned) Bun codegen

#117
Merged glennmichael123 wants to merge fix/resolved-source-tag-pin-realign into main
2 files +186 -235
8 days ago

Problem

All node:* / bun:* builtins are broken on main: require("node:path"), node:fs, node:os, etc. return empty objects or infinitely recurse in the C++ InternalModuleRegistry (createInternalModuleById → createInternalModuleById, ~10k frames → crash). This blocks the entire native test-loop — no Bun test that imports a node builtin can run.

Root cause

ResolvedSource.Tag is ABI with the C++ InternalModuleRegistry: the loader masks off InternalModuleRegistryFlag (512) and calls internalModuleRegistry()->requireId(tag & 511). So the Zig enum ids must match the InternalModuleRegistryConstants of the Bun C++ objects Home actually links.

Home links the pinned Bun build (~/Code/bun @ fd0b6f1a27 / 1.3.14, objects built Jul 7), whose codegen ResolvedSourceTag.zig has 161 builtin entries. The enum had been regenerated from a newer Bun HEAD (4982b91e3) with 182 entries — ~21 extra internal modules inserted mid-range (internal:async_context_frame, internal:async_hooks, internal:fs/binding, internal:streams/iter/*, node:stream/iter, node:zlib/iter, …). Every id past the first insertion is shifted:

modulelinked (pin)enum was (HEAD)
node:fs610628
node:path619637
node:test631650
bun:test650670
bun661681

→ require("node:path") selected the wrong registry module → recursion.

Fix

Restore the enum verbatim from the linked codegen (~/Code/bun/build/release/codegen/ResolvedSourceTag.zig) and add a test pinning the ids so drift fails loudly at build time instead of recursing at runtime.

This undoes the id shift introduced in 496160c05.

If you're bumping the linked Bun objects to a newer HEAD: regenerate this enum from the new build/*/codegen/ResolvedSourceTag.zig in the same change. The added test will catch a mismatch — that's the intended guardrail.

Verification (home-debug)

  • require("node:path").join("a","b") → a/b
  • require("node:fs").openSync / mkdirSync → function
  • require("node:os").platform() → darwin
  • decorators (bun:wrap synthetic path, unaffected) → @log m(41) → 42

2 changed files on the files tab, with 0 review threads.

Sign in to comment on this pull request.