Repository navigation
fix(workspace-fs): keep generated dirs out of the watch when git's ignored-dir listing fails or overflows its cap #10195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pgilmore
wants to merge
2
commits into
ParadevAI:main
Choose a base branch
from
patiently:bugfix/ignored-dir-listing-fixes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // Both the FsWatcherManager and the search-index `fast-glob` walk consume this | ||
| // list. Patterns matched here are not just hidden from consumers — on Linux | ||
| // they're applied at watch-creation time by @parcel/watcher, so no inotify | ||
| // watches are installed for matched dirs. That's the main lever against | ||
| // ENOSPC (inotify watch limit). On macOS FSEvents these are userspace-only | ||
| // filters; the kernel still queues events for ignored paths but consumers | ||
| // never see them. | ||
| export const DEFAULT_IGNORE_PATTERNS = [ | ||
| "**/node_modules/**", | ||
| "**/.git/**", | ||
| "**/dist/**", | ||
| "**/build/**", | ||
| "**/.next/**", | ||
| "**/.turbo/**", | ||
| "**/coverage/**", | ||
| "**/.cache/**", | ||
| "**/.parcel-cache/**", | ||
| "**/.vite/**", | ||
| "**/.svelte-kit/**", | ||
| "**/.vercel/**", | ||
| "**/target/**", | ||
| "**/out/**", | ||
| "**/.venv/**", | ||
| "**/vendor/**", | ||
| "**/.gradle/**", | ||
| "**/.pnpm-store/**", | ||
| "**/.yarn/**", | ||
| // Agent/worktree tools pile up sibling git worktrees under these dirs — a | ||
| // full repo copy each, with its own node_modules. Left unignored, watching a | ||
| // project that contains one balloons the watcher to millions of directories. | ||
| // The nested-repo prune in watch.ts catches any worktree generically by its | ||
| // `.git` marker; these globs are the cheap native backstop for the known | ||
| // conventions (Claude Code, `git worktree` under `.worktrees`, Conductor), | ||
| // and still prune even if that scan is truncated on a pathological tree. | ||
| "**/.worktrees/**", | ||
| "**/.claude/worktrees/**", | ||
| "**/.conductor/**", | ||
| "**/*.tsbuildinfo", | ||
| ]; | ||
|
|
||
| /** | ||
| * Directory basenames the nested-repo discovery scan (watch.ts) prunes as it | ||
| * walks, so it never descends into the heavy ignored trees (node_modules, .git, | ||
| * …). Derived from the single-segment `**\/<name>/**` entries above so the two | ||
| * ignore surfaces can't drift. Multi-segment globs (`.claude/worktrees`) are | ||
| * intentionally excluded: the scan still traverses `.claude/` and discovers the | ||
| * worktrees generically by their `.git` marker. | ||
| */ | ||
| export const DEFAULT_IGNORE_DIR_NAMES: ReadonlySet<string> = new Set( | ||
| DEFAULT_IGNORE_PATTERNS.map( | ||
| (pattern) => /^\*\*\/([^/*]+)\/\*\*$/.exec(pattern)?.[1], | ||
| ).filter((name): name is string => name !== undefined), | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
packages/workspace-fs/src/watch-gitignored-listing-failure.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import { afterEach, describe, expect, it } from "bun:test"; | ||
| import fs from "node:fs/promises"; | ||
| import os from "node:os"; | ||
| import path from "node:path"; | ||
| import { FsWatcherManager } from "./watch"; | ||
| import type { NativeWatchBackend } from "./watch-backend"; | ||
|
|
||
| const tempRoots: string[] = []; | ||
| const managers: FsWatcherManager[] = []; | ||
|
|
||
| afterEach(async () => { | ||
| await Promise.all(managers.splice(0).map((m) => m.close())); | ||
| await Promise.all( | ||
| tempRoots | ||
| .splice(0) | ||
| .map((root) => fs.rm(root, { recursive: true, force: true })), | ||
| ); | ||
| }); | ||
|
|
||
| const failing = () => Promise.reject(new Error("git ls-files timed out")); | ||
|
|
||
| async function setup(listings: (() => Promise<string[]>)[]) { | ||
| const rootPath = await fs.realpath( | ||
| await fs.mkdtemp(path.join(os.tmpdir(), "watch-listing-failure-")), | ||
| ); | ||
| tempRoots.push(rootPath); | ||
| const attaches: string[][] = []; | ||
| const backend: NativeWatchBackend = { | ||
| name: "fake", | ||
| watchesEachEntry: true, | ||
| subscribe: async (request) => { | ||
| attaches.push(request.ignore); | ||
| return { unsubscribe: async () => {} }; | ||
| }, | ||
| }; | ||
| let calls = 0; | ||
| const manager = new FsWatcherManager({ | ||
| backend, | ||
| useDefaultIgnores: false, | ||
| gitIgnoredRetryInitialMs: 1, | ||
| gitIgnoredRetryMaxMs: 1, | ||
| listGitIgnoredDirs: () => { | ||
| const listing = listings[Math.min(calls, listings.length - 1)]; | ||
| calls += 1; | ||
| return (listing ?? failing)(); | ||
| }, | ||
| findNestedRepoRoots: async () => ({ roots: [], truncated: false }), | ||
| }); | ||
| managers.push(manager); | ||
| let overflows = 0; | ||
| const overflowWaiters: { count: number; resolve: () => void }[] = []; | ||
| await manager.subscribe({ absolutePath: rootPath }, (batch) => { | ||
| for (const event of batch.events) { | ||
| if (event.kind !== "overflow") continue; | ||
| overflows += 1; | ||
| for (const waiter of overflowWaiters) { | ||
| if (overflows >= waiter.count) waiter.resolve(); | ||
| } | ||
| } | ||
| }); | ||
| const untilOverflows = (count: number) => | ||
| new Promise<void>((resolve) => { | ||
| if (overflows >= count) resolve(); | ||
| else overflowWaiters.push({ count, resolve }); | ||
| }); | ||
| const isPruned = (relativePath: string) => | ||
| manager.isPathPruned(rootPath, path.join(rootPath, relativePath)); | ||
| return { rootPath, manager, attaches, untilOverflows, isPruned }; | ||
| } | ||
|
|
||
| describe("a failed gitignored-dir listing", () => { | ||
| it("prunes generated dirs until a retry gets git's answer", async () => { | ||
| const run = await setup([failing, failing, async () => ["vendor"]]); | ||
|
|
||
| expect(run.attaches[0]).toContain("**/node_modules/**"); | ||
| expect(run.isPruned("node_modules/a.js")).toBe(true); | ||
|
|
||
| await run.untilOverflows(2); | ||
|
|
||
| expect(run.attaches).toHaveLength(2); | ||
| expect(run.attaches[1]).not.toContain("**/node_modules/**"); | ||
| expect(run.attaches[1]).toContain("vendor/**"); | ||
| expect(run.isPruned("node_modules/a.js")).toBe(false); | ||
| expect(run.isPruned("vendor/a.js")).toBe(true); | ||
| }); | ||
|
|
||
| it("keeps the current prune when a refresh fails", async () => { | ||
| const run = await setup([async () => ["node_modules"], failing]); | ||
|
|
||
| expect(await run.manager.refreshIgnores(run.rootPath)).toBe(false); | ||
|
|
||
| expect(run.attaches).toHaveLength(1); | ||
| expect(run.isPruned("node_modules/a.js")).toBe(true); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not classify every “cannot change to” error as a missing root.
Git 2.50.0 emits this message for any failed
chdir, not only a missing directory. Permission and I/O failures can therefore reach this branch. (raw.githubusercontent.com)This branch returns
[], so the watcher treats the failure as a successful listing and does not enable provisional pruning or retries. Restrict this exception to a confirmed missing root. Rethrow other failures.