ReviewOS

home-lang/home

fix(runtime): port reloadProcess so --watch restarts the process

#759
Closed glennmichael123 opened this 9 days ago ·
9 days ago

Parent: #66

home --watch and home build --watch cannot restart. packages/runtime/src/home.zig:726 defines reloadProcess as an empty stub, and the bun import used by the watcher resolves to home.zig. WatchReloader (reload_immediately = true) calls bun.reloadProcess(...) and then unreachable (jsc/hot_reloader.zig:263), so the first file change reaches unreachable. The bundler watcher (bundle_v2.zig) hits the same stub.

Bun's implementation (~/Code/bun/src/bun.zig reloadProcess, isProcessReloadInProgressOnAnotherThread, maybeHandlePanicDuringProcessReload) is already copied, unused, at packages/runtime/src/bun.zig:1576. Port it into the live home.zig namespace; do not stub.

Also compare Bun's Run.start watch branch (src/bun.js.zig ~L401-445: addMainToWatcherIfNeeded + tickPossiblyForever when the entry rejects) with Home's live boot, src/main.zig VmRunState.start.

Verification: unchanged test/cli/watch and test/cli/hot files vs pinned Bun 4982b91e37.

9 days ago

Reopening: the commit used a Closes keyword, which auto-closed this. Evidence follows in the next comment; leaving the call to close to @chrisbbreuer.

9 days ago

Ported on origin/main in 2b48dc083, together with isProcessReloadInProgressOnAnotherThread and maybeHandlePanicDuringProcessReload, which the crash handler already called.

Zig 0.17 adaptations, all mechanical: no std.posix.nanosleep / execveZ (libc directly, errno through bun.sys.getErrno), the spawn wrapper takes raw descriptors and u16 flags, Output.Source.Stdio.restore re-exported from bun_core/output.zig, and TerminateProcess declared for the Windows branch.

Unchanged test/cli/hot, same JSC debug build, control = the same tree with the runtime changes stashed:

passfail
Home, unchanged parent87
Home, 2b48dc083105
pinned Bun 4982b91e37150

The two that flipped are --watch works > with entry.js and > with tmp.js, which timed out at 5,001 ms on the parent because the watcher thread reached unreachable.

The five remaining failures are identical on the unchanged parent, so they are separate pre-existing gaps, not regressions: preload not found should exit with code 1 and not time out (error text) and four sourcemap cases (should work with sourcemap generation, should not remap against a stale sourcemap after a partial-file reload, should work with sourcemap loading, … with large files). Pinned Bun passes all five, so they are real Home gaps and are tracked separately.

9 days ago

Verified on current origin/main at c6ab9aeeb using the required native ReleaseFast binary.

The reloadProcess implementation from 2b48dc083 remains active, and the later hot-entry/sourcemap work in ce5d0c099 clears every formerly separate failure. The complete unchanged test/cli/watch plus test/cli/hot directories pass 21/21 tests and 539 assertions, covering process restarts, non-ASCII paths, watcher traces across reloads, startup-error recovery, generated/loaded/stale/large sourcemaps and the 129-directory stress case.

No fixture, workload, deadline, assertion, skip, TODO, snapshot or expected outcome changed. Closing after full current-main acceptance verification.

Sign in to comment on this issue.