Skip to content

fix(core): tolerate file watcher startup failures - #32854

Closed
sailod wants to merge 1 commit into
anomalyco:devfrom
sailod:fix/file-watcher-startup-fallback
Closed

sailod wants to merge 1 commit into
anomalyco:devfrom
sailod:fix/file-watcher-startup-fallback

Conversation

@sailod

@sailod sailod commented Jun 18, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #16610
Related #26842, #23190

Type of change

  • Bug fix

What does this PR do?

The file watcher initialization could fail in ways that made the entire TUI crash or hang. This PR makes the watcher non-fatal — if watcher setup fails, OpenCode logs a warning and continues running without file watching.

Changes in packages/core/src/filesystem/watcher.ts:

  1. Effect.promise → Effect.tryPromise — catches synchronous throws from native @parcel/watcher's subscribe(), not just promise rejections
  2. Isolated .git watcher into its own forkScoped with catchCause — a git watcher failure no longer kills the entire watcher service; only git HEAD tracking is lost
  3. Handle callback error parameter — @parcel/watcher callback signature is (error, events), errors were silently ignored, now logged
  4. Improved outer catchCause logging — message explains the consequence ("watcher disabled: initialization failed, continuing without file watching")
  5. Suppress unsubscribe() errors — prevents unhandled rejections during cleanup

How did you verify your code works?

  • Ran all 6 existing watcher tests — all pass (bun test test/filesystem/watcher.test.ts)
  • Ran all 36 filesystem tests — all pass (bun test test/filesystem/)
  • Ran typecheck — passes clean (bunx tsgo --noEmit)
  • Verified Effect.tryPromise and Effect.logWarning are used elsewhere in the codebase
  • Verified @parcel/watcher native binding loads and subscribes successfully
  • Confirmed the original bug reproduction: OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER=true opencode avoids the crash
  • The changes are purely defensive — catching errors that were previously uncaught

Screenshots / recordings

N/A — no UI changes

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Jun 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Jun 18, 2026
Fixes anomalyco#16610
Related anomalyco#26842
Related anomalyco#23190

The file watcher initialization could fail in ways that made the entire
TUI unresponsive or crash:

- Effect.promise did not catch synchronous throws from @parcel/watcher's
  subscribe() call; Effect.tryPromise does
- The .git watcher setup ran inside the main layer body, so any failure
  (git.dir timeout, subscribe timeout) killed the entire watcher service
  including the experimental root watcher; it is now isolated in its own
  forkScoped with an independent catchCause
- The @parcel/watcher callback's error parameter was silently ignored;
  it is now logged
- Unsubscribe errors during cleanup could cause unhandled rejections;
  they are now suppressed
- The outer catchCause log message now includes the directory and
  explains the consequence (watcher disabled)

Reproduction: OpenCode 1.17.8 / Bun 1.3.14 in a Linux dev container
with overlayfs crashes with exit code 132 (SIGILL) and Bun panic
'Segmentation fault at address 0x0' when run inside a Git repo.
OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER=true avoids the crash.
@sailod
sailod force-pushed the fix/file-watcher-startup-fallback branch from 74f0231 to b0d6ef6 Compare June 18, 2026 15:20
@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jun 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@sailod

sailod commented Jun 18, 2026

Copy link
Copy Markdown
Author

Closing this PR — after deeper investigation into @parcel/watcher's C++ source, the .git watcher crash is in the native subscribe() call itself, not in std::regex_match. The JS-level error handling improvements here are valid but don't fix the root cause (a native crash can't be caught by try/catch).

We're systematically reproducing the crash to isolate the exact failure point and will open a new PR with the correct fix once the root cause is confirmed.

@sailod sailod closed this Jun 18, 2026
@sailod
sailod deleted the fix/file-watcher-startup-fallback branch June 18, 2026 22:49
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.

Opencode hangs at startup if a .git repo is present and inotify user instances run out

1 participant