Skip to content

fix(desktop): skip file watcher on $HOME and filesystem root#32610

Closed
vzwjustin wants to merge 5 commits into
anomalyco:devfrom
vzwjustin:dev
Closed

fix(desktop): skip file watcher on $HOME and filesystem root#32610
vzwjustin wants to merge 5 commits into
anomalyco:devfrom
vzwjustin:dev

Conversation

@vzwjustin

@vzwjustin vzwjustin commented Jun 16, 2026

Copy link
Copy Markdown

Desktop could persist and boot instances for the entire home directory or /, causing inotify subscribe timeouts and pegging opencode-cli CPU. Skip watching broad roots, sanitize persisted project lists, and add a Flatpak workaround script plus troubleshooting guide.

Issue for this PR
Closes # (no linked issue — reproduced locally on Flatpak 1.4 / Linux)

Type of change

Bug fix

New feature

Refactor / code improvement

Documentation
What does this PR do?
On Linux desktop, OpenCode could end up with an instance rooted at $HOME or / (persisted in server.projects and recreated workspace state). The sidecar then subscribed inotify on that tree, hit subscribe timeouts, and retried in a loop — opencode-cli sat at ~100% CPU.

This PR:

Core — adds isBroadWatchRoot() and skips the file watcher when the instance directory is $HOME or / (still watches normal project dirs).
App — on load, strips home/root from persisted desktop project lists; projects.open() refuses those paths so they are not re-added from the UI.
Docs/script — docs/guides/desktop-file-watcher-cpu.md and scripts/opencode-safe.sh for Flatpak users who cannot run a fixed build yet.
Why it works: the CPU peg was not random load — logs showed repeated service=file.watcher dir=/home/... cause=TimeoutError. Stopping watches on those two broad roots removes the failure mode; project-scoped dirs are unchanged.

How did you verify your code works?
Added unit tests: packages/core/test/filesystem/watch-root.test.ts, extended packages/app/src/context/server.test.ts for sanitize/open behavior.
Reproduced the bug on Flatpak desktop (logs showing dir=$HOME, high opencode-cli CPU), then confirmed the client workaround (opencode-safe + flatpak HOME override) scopes the watcher to a single repo.
(Maintainers: bun test on the two test files above — bun was not available in the agent environment that opened this PR.)
Screenshots / recordings
N/A — backend/desktop sidecar behavior, no UI layout change.

Checklist

I have tested my changes locally

I have not included unrelated changes in this PR

justin and others added 2 commits June 16, 2026 18:31
Desktop could persist and boot instances for the entire home directory or /,
causing inotify subscribe timeouts and pegging opencode-cli CPU. Skip
watching broad roots, sanitize persisted project lists, and add a Flatpak
workaround script plus troubleshooting guide.
fix(desktop): skip file watcher on $HOME and filesystem root
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Jun 16, 2026
@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Found a potentially related PR:

PR #30209: fix(opencode): skip watching $HOME to avoid slow FSEvents exclusion setup
#30209

This PR appears to address a similar issue—skipping the $HOME directory to avoid slow file watcher setup. The current PR (32610) extends this concept to also skip the filesystem root. You should verify if PR #30209 was already merged and whether the current PR builds upon it or duplicates its solution.

vzwjustin and others added 3 commits June 16, 2026 18:40
Use a browser-safe broad-root helper in the app bundle, harden persisted
state sanitization, return rejection from projects.open() so callers skip
navigation, and launch Flatpak with transient --env instead of persistent overrides.

Co-authored-by: Cursor <cursoragent@cursor.com>
Extend browser-safe isBroadWatchRoot to block Windows drive roots and
typical C:/Users/<name> home paths, with unit tests.
Fix compaction overflow headroom, ACP permission errors, atomic file writes,
and error logging gaps. Bundle RTK as a built-in plugin with install/build support.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jun 17, 2026
@github-actions github-actions Bot closed this Jun 17, 2026
Sign up for free to 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.

2 participants