ReviewOS

home-lang/home

fix(ts-watch): preserve presence transitions and stat failures

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

The current TS watch foundation stores an absent path as a zeroed Stat and leaves the prior stat unchanged after a removal. On pinned Zig 0.17, two new guarded lifecycle controls fail: a missing file emits removed on every poll, and a newly created real file with (mtime,size)=(0,0) emits no added. A recreation with exactly the old metadata can likewise be missed. RealStatFs also maps every stat error, including permission/resource failures, to absence; a transient error can become a false removal. Watcher.track, Watcher.tick, and VirtualWatchFs.add have allocation paths that need owned-key/ChangeSet cleanup on failure.

Acceptance: represent presence separately from metadata, emit exactly one event per present/missing transition and detect same-metadata recreation and zero-stat files; propagate non-absence stat errors without mutating tracked state; preserve tracked/virtual-map contents and ownership on allocation failure. Add direct lifecycle/error/OOM tests to the standard TS watch test gate on Zig 0.17 and 0.18, including optimized mode. Keep the real CLI's existing deletion handling visible; this issue does not by itself claim complete deleted-module recompilation. No polling cutoff or metadata heuristic.

9 days ago

Implemented and pushed directly to origin/main as glennmichael123 in 9b21446d0, with exactly three files and no coauthors. Presence is now distinct from (mtime,size)=(0,0); missing/present transitions emit once, including same-metadata recreation. Only FileNotFound/NotDir map to absence; other stat failures propagate. A tick commits its new baselines only after every stat and allocation succeeds, so later errors cannot consume earlier undispatched events. Tracked keys/event paths and virtual-FS insertions retain correct ownership under injected OOM; virtual replacements update in place.

Both new lifecycle controls failed before the fix. The standard TS-watch gate passes 19/19 on Zig 0.17 and 0.18 in Debug and ReleaseFast under the serial 3,840 MB guard (peak tree footprint 383–551 MB). After rebasing over Chris's non-overlapping video commit, both test executables reran 19/19. The shipped home-tsc Debug CLI builds on both Zig versions with enable_jsc=false under the guard (peaks 2,173 and 2,096 MB). Zig format checks and staged whitespace check pass. These are watcher and CLI-build results, not a full watch-mode, Bun-corpus, or all-platform pass. The CLI still skips removed changes; that separate source/Program invalidation gap is tracked by #923.

Sign in to comment on this issue.