Skip to content

bug: file watcher native callback loses ALS context - #17615

Closed
kitlangton wants to merge 1 commit into
devfrom
repro/watcher-als-bug
Closed

bug: file watcher native callback loses ALS context#17615
kitlangton wants to merge 1 commit into
devfrom
repro/watcher-als-bug

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

Bug

The @parcel/watcher native C++ callback fires outside the Instance AsyncLocalStorage context. Bus.publish needs Instance.directory to resolve per-instance subscribers and tag GlobalBus events, so it silently throws Context.NotFound — no log, no crash, events just vanish.

The git HEAD watcher is always active (no experimental flag), so this affects all users.

Impact

  • TUI branch indicator never live-updates when switching branches externally (git checkout in another terminal)
  • Vcs.Event.BranchUpdated never fires from the native watcher path
  • Any Bus.subscribe(FileWatcher.Event.Updated, ...) listener silently receives nothing from native file changes

(Tool-initiated events from edit.ts, write.ts, apply_patch.ts still work because they call Bus.publish from within Instance.provide.)

Repro

This PR adds a failing test that:

  1. Boots an instance with the file watcher
  2. Listens on GlobalBus for watcher events
  3. Triggers a git checkout -b to change .git/HEAD
  4. Times out after 5s because the event never arrives
bun run test test/file/watcher-als-bug.test.ts

Fix

Addressed in #17601 via Instance.bind(fn) — captures the ALS context at subscription time and restores it synchronously in the native callback.

The @parcel/watcher native callback fires outside the Instance
AsyncLocalStorage context. Bus.publish silently throws because
Instance.directory is unavailable, so watcher events never reach
subscribers. This breaks live branch detection in the TUI.
@kitlangton
kitlangtonforce-pushed the repro/watcher-als-bug branch from e23e7e9 to 70e23caCompareMarch 15, 2026 15:25
@kitlangton
kitlangton marked this pull request as draft March 15, 2026 15:36
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@kitlangton