From 874f32acce832fa8ff7b39e1c41c0767a52cf0c4 Mon Sep 17 00:00:00 2001
From: Patrick Gilmore
Date: Sun, 22 Nov 2026 16:08:47 +0000
Subject: [PATCH 1/2] fix(workspace-fs): don't watch generated dirs when git's
ignored-dir listing fails
With useDefaultIgnores: false (host-service), git's ignored-dir listing is
the only thing that prunes node_modules, build, .gradle and the like from the
watch. listGitIgnoredDirs swallowed every failure and returned [], so a
listing that timed out while many workspaces attached at once looked like
"nothing ignored": chokidar crawled the whole tree, node_modules included,
and nothing was logged. One worktree held ~300k inotify watches that way.
Since #9896 a later git:changed event can re-list and re-attach. That does
not cover the attach itself (the full crawl has already happened), and an
idle worktree never emits one. A worker-pool rejection hits the same path.
Worse, refreshIgnores turned a failed listing into [], read that as every
dir being un-ignored, and re-attached with no gitignored prune at all.
- listGitIgnoredDirs still returns [] for a non-git or missing root, and
rejects on any other failure. git runs with LC_ALL=C so the check holds.
git-watcher already logs a rejection and retries on its next emit.
- A failed listing at attach prunes the static generated-dir globs
provisionally when default ignores are off, and isPathPruned reports those
paths as pruned so targeted file watches still cover them.
- The listing is retried through refreshIgnores with backoff (5 s doubling
to 5 min). Once git answers, the root re-attaches with git's list. That
releases the provisional prune, so tracked build/vendor files are visible
again, and listeners get an overflow.
- A refresh whose listing fails keeps the current prune.
Claude-Session: https://claude.ai/code/session_01SmhtiD5kaHuqyogu8ef5R2
---
.../src/runtime/git/ignored-dirs.test.ts | 7 ++
.../src/runtime/git/ignored-dirs.ts | 25 ++++-
.../watch-gitignored-listing-failure.test.ts | 95 ++++++++++++++++++
packages/workspace-fs/src/watch.ts | 98 +++++++++++++++++--
4 files changed, 212 insertions(+), 13 deletions(-)
create mode 100644 packages/workspace-fs/src/watch-gitignored-listing-failure.test.ts
diff --git a/packages/host-service/src/runtime/git/ignored-dirs.test.ts b/packages/host-service/src/runtime/git/ignored-dirs.test.ts
index 6516d5779c1..1c9b1c44e04 100644
--- a/packages/host-service/src/runtime/git/ignored-dirs.test.ts
+++ b/packages/host-service/src/runtime/git/ignored-dirs.test.ts
@@ -49,6 +49,13 @@ describe("listGitIgnoredDirs", () => {
expect(await listGitIgnoredDirs(dir)).toEqual([]);
});
+ test("rejects when git fails on a real repo, so callers can tell failure from nothing ignored", async () => {
+ const dir = await createRepo();
+ await writeFile(path.join(dir, ".git", "index"), "not an index");
+
+ await expect(listGitIgnoredDirs(dir)).rejects.toThrow();
+ });
+
test("returns [] for a missing path", async () => {
expect(
await listGitIgnoredDirs("/nonexistent/definitely-not-here"),
diff --git a/packages/host-service/src/runtime/git/ignored-dirs.ts b/packages/host-service/src/runtime/git/ignored-dirs.ts
index f51ec4d2c7a..8c1ca5e19f4 100644
--- a/packages/host-service/src/runtime/git/ignored-dirs.ts
+++ b/packages/host-service/src/runtime/git/ignored-dirs.ts
@@ -25,8 +25,9 @@ const MAX_BUFFER_BYTES = 10 * 1024 * 1024;
*
* `under` limits the listing to those root-relative dirs, matched literally.
*
- * Returns [] for non-git roots, timeouts, and every other failure — callers
- * degrade to the static ignore list, never block on this.
+ * Returns [] when the root is not a git worktree or does not exist. Every
+ * other failure (a timeout under attach load, a corrupt index) rejects, so
+ * callers can tell "git ignores nothing here" from "git did not answer".
*/
export async function listGitIgnoredDirs(
rootPath: string,
@@ -47,7 +48,12 @@ export async function listGitIgnoredDirs(
"-z",
...(under ? ["--", ...under] : []),
],
- { timeout: TIMEOUT_MS, maxBuffer: MAX_BUFFER_BYTES },
+ {
+ timeout: TIMEOUT_MS,
+ maxBuffer: MAX_BUFFER_BYTES,
+ // isNotAWorktree matches git's untranslated messages.
+ env: { ...process.env, LC_ALL: "C" },
+ },
);
const dirs: string[] = [];
for (const entry of stdout.split("\0")) {
@@ -56,7 +62,16 @@ export async function listGitIgnoredDirs(
if (dirs.length >= MAX_IGNORED_DIRS) break;
}
return dirs;
- } catch {
- return [];
+ } catch (error) {
+ if (isNotAWorktree(error)) return [];
+ throw error;
}
}
+
+function isNotAWorktree(error: unknown): boolean {
+ const stderr = String((error as { stderr?: unknown } | null)?.stderr ?? "");
+ return (
+ stderr.includes("not a git repository") ||
+ stderr.includes("cannot change to")
+ );
+}
diff --git a/packages/workspace-fs/src/watch-gitignored-listing-failure.test.ts b/packages/workspace-fs/src/watch-gitignored-listing-failure.test.ts
new file mode 100644
index 00000000000..612741380bc
--- /dev/null
+++ b/packages/workspace-fs/src/watch-gitignored-listing-failure.test.ts
@@ -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)[]) {
+ 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((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);
+ });
+});
diff --git a/packages/workspace-fs/src/watch.ts b/packages/workspace-fs/src/watch.ts
index bad44b53517..db0998fd84b 100644
--- a/packages/workspace-fs/src/watch.ts
+++ b/packages/workspace-fs/src/watch.ts
@@ -62,6 +62,8 @@ const IGNORE_GROWTH_REATTACH_MIN_MS = 30_000;
// ask git about new dirs at once, batched, before the walk goes deep.
const NEW_DIR_IGNORE_CHECK_DELAY_MS = 10;
const NEW_DIR_IGNORE_CHECK_MAX_DIRS = 64;
+const GIT_IGNORED_RETRY_INITIAL_MS = 5_000;
+const GIT_IGNORED_RETRY_MAX_MS = 5 * 60_000;
// Recovery liveness probe: a freshly attached FSEvents stream can be deaf for
// a sub-second window after subscribe() resolves (observed on a busy Electron
@@ -236,6 +238,14 @@ interface WatcherState {
queuedIgnoreRefresh: Promise | null;
/** Bumped when a full ignore listing is applied; older scoped answers are stale. */
ignoreListingEpoch: number;
+ /**
+ * The last attach ran without git's ignored-dir list. With default ignores
+ * off, the static generated-dir globs stand in for it meanwhile; they can
+ * hide tracked build/vendor files, so a retry swaps them for git's answer.
+ */
+ gitIgnoredListingFailed: boolean;
+ gitIgnoredRetryTimer: ReturnType | null;
+ gitIgnoredRetryDelayMs: number;
filePaths: Map;
directoryPaths: Set;
pendingEvents: NativeWatchEvent[];
@@ -314,8 +324,9 @@ export interface FsWatcherManagerOptions {
* (fully-untracked subtrees like `.next` or `__pycache__`), so they can be
* pruned from the native subscription alongside the static defaults.
* Injected (rather than spawning git here) to mirror how search injects
- * `runRipgrep`. Best-effort: failures degrade to the static list. With
- * `under`, it lists only inside those root-relative dirs.
+ * `runRipgrep`. A rejection means git did not answer: the attach prunes
+ * the static generated-dir globs meanwhile and retries. With `under`, it
+ * lists only inside those root-relative dirs.
*/
listGitIgnoredDirs?: (
rootPath: string,
@@ -333,6 +344,9 @@ export interface FsWatcherManagerOptions {
overflowRescanMaxMs?: number;
overflowBackoffResetMs?: number;
growthReattachMinMs?: number;
+ /** Backoff for retrying a failed gitignored-dir listing. Test-only overrides. */
+ gitIgnoredRetryInitialMs?: number;
+ gitIgnoredRetryMaxMs?: number;
/** Limit on native subscribe and unsubscribe during teardown. Test-only override. */
teardownTimeoutMs?: number;
now?: () => number;
@@ -361,6 +375,8 @@ export class FsWatcherManager {
private readonly overflowRescanMaxMs: number;
private readonly overflowBackoffResetMs: number;
private readonly growthReattachMinMs: number;
+ private readonly gitIgnoredRetryInitialMs: number;
+ private readonly gitIgnoredRetryMaxMs: number;
private readonly teardownTimeoutMs: number;
private readonly now: () => number;
private readonly watchers = new Map();
@@ -407,6 +423,10 @@ export class FsWatcherManager {
options.overflowBackoffResetMs ?? OVERFLOW_BACKOFF_RESET_MS;
this.growthReattachMinMs =
options.growthReattachMinMs ?? IGNORE_GROWTH_REATTACH_MIN_MS;
+ this.gitIgnoredRetryInitialMs =
+ options.gitIgnoredRetryInitialMs ?? GIT_IGNORED_RETRY_INITIAL_MS;
+ this.gitIgnoredRetryMaxMs =
+ options.gitIgnoredRetryMaxMs ?? GIT_IGNORED_RETRY_MAX_MS;
this.teardownTimeoutMs = options.teardownTimeoutMs ?? TEARDOWN_TIMEOUT_MS;
this.now = options.now ?? Date.now;
}
@@ -522,6 +542,7 @@ export class FsWatcherManager {
clearTimeout(state.newDirCheckTimer);
state.newDirCheckTimer = null;
}
+ this.clearGitIgnoredRetry(state);
state.generation += 1;
state.throttler.dispose();
const subscription = state.subscription;
@@ -706,6 +727,9 @@ export class FsWatcherManager {
ignoreRefresh: null,
queuedIgnoreRefresh: null,
ignoreListingEpoch: 0,
+ gitIgnoredListingFailed: false,
+ gitIgnoredRetryTimer: null,
+ gitIgnoredRetryDelayMs: this.gitIgnoredRetryInitialMs,
filePaths: new Map(),
directoryPaths: new Set(),
pendingEvents: [],
@@ -760,7 +784,11 @@ export class FsWatcherManager {
]);
state.controller.signal.throwIfAborted();
state.ignoreListingEpoch += 1;
- state.prunedRelPrefixes = [...nestedRepoRelDirs, ...gitIgnoredRelDirs];
+ state.gitIgnoredListingFailed = gitIgnoredRelDirs === null;
+ state.prunedRelPrefixes = [
+ ...nestedRepoRelDirs,
+ ...(gitIgnoredRelDirs ?? []),
+ ];
state.nativePrunedRelPrefixes = state.prunedRelPrefixes;
this.setFilteredRelPrefixes(state, []);
// Root-relative escaped globs: parcel matches ignores relative to the
@@ -772,7 +800,13 @@ export class FsWatcherManager {
(relDir) => `${escapeGlobMagic(relDir)}/**`,
);
- const ignore = [...this.ignore, ...prunedDirIgnores];
+ const ignore = [
+ ...new Set([
+ ...this.ignore,
+ ...(this.hasProvisionalPrune(state) ? DEFAULT_IGNORE_PATTERNS : []),
+ ...prunedDirIgnores,
+ ]),
+ ];
// Subscribe to the resolved real path so kernel paths come back in a
// consistent form; we map them back to `state.absolutePath` in
@@ -796,6 +830,47 @@ export class FsWatcherManager {
this.queueNativeEvents(state, events);
},
});
+ if (gitIgnoredRelDirs === null) this.scheduleGitIgnoredRetry(state);
+ else this.markGitIgnoredListed(state);
+ }
+
+ private hasProvisionalPrune(state: WatcherState): boolean {
+ return state.gitIgnoredListingFailed && !this.useDefaultIgnores;
+ }
+
+ private markGitIgnoredListed(state: WatcherState): void {
+ state.gitIgnoredListingFailed = false;
+ state.gitIgnoredRetryDelayMs = this.gitIgnoredRetryInitialMs;
+ this.clearGitIgnoredRetry(state);
+ }
+
+ private clearGitIgnoredRetry(state: WatcherState): void {
+ if (state.gitIgnoredRetryTimer) {
+ clearTimeout(state.gitIgnoredRetryTimer);
+ state.gitIgnoredRetryTimer = null;
+ }
+ }
+
+ private scheduleGitIgnoredRetry(state: WatcherState): void {
+ if (state.gitIgnoredRetryTimer) return;
+ const delayMs = state.gitIgnoredRetryDelayMs;
+ state.gitIgnoredRetryDelayMs = Math.min(
+ delayMs * 2,
+ this.gitIgnoredRetryMaxMs,
+ );
+ const timer = setTimeout(() => {
+ state.gitIgnoredRetryTimer = null;
+ if (this.watchers.get(state.absolutePath) !== state) return;
+ void this.refreshIgnores(state.absolutePath).catch((error) => {
+ if (state.controller.signal.aborted) return;
+ console.error("[workspace-fs/watch] gitignored-dir retry failed", {
+ absolutePath: state.absolutePath,
+ error: toErrorMessage(error),
+ });
+ });
+ }, delayMs);
+ timer.unref?.();
+ state.gitIgnoredRetryTimer = timer;
}
private queueNativeEvents(
@@ -918,11 +993,12 @@ export class FsWatcherManager {
* excludesfile all honored). Snapshot at attach time: a dir created later
* (first `bun dev` making `.next`) stays watched until the next attach, but
* the git-watcher's own ignored-path filter caps its downstream cost.
+ * Null when the listing failed, as opposed to git reporting nothing ignored.
*/
private async computeGitIgnoredRelDirs(
realPath: string,
signal: AbortSignal,
- ): Promise {
+ ): Promise {
if (!this.listGitIgnoredDirs) {
return [];
}
@@ -935,7 +1011,7 @@ export class FsWatcherManager {
absolutePath: realPath,
error: toErrorMessage(error),
});
- return [];
+ return null;
}
}
@@ -1003,6 +1079,12 @@ export class FsWatcherManager {
// State changed while the providers ran.
return false;
}
+ if (gitIgnoredRelDirs === null) {
+ if (state.gitIgnoredListingFailed) this.scheduleGitIgnoredRetry(state);
+ return false;
+ }
+ const releaseProvisional = this.hasProvisionalPrune(state);
+ this.markGitIgnoredListed(state);
state.ignoreListingEpoch += 1;
const fresh = [...new Set([...nestedRepoRelDirs, ...gitIgnoredRelDirs])];
const freshSet = new Set(fresh);
@@ -1016,7 +1098,7 @@ export class FsWatcherManager {
this.backend.watchesEachEntry === true &&
state.filteredRelPrefixes.some((dir) => !freshSet.has(dir));
const added = fresh.filter((dir) => !native.has(dir));
- let reattach = nativeShrunk || filteredShrunk;
+ let reattach = nativeShrunk || filteredShrunk || releaseProvisional;
if (!reattach && added.length > 0 && this.backend.watchesEachEntry) {
const waitMs =
state.lastGrowthReattachAt + this.growthReattachMinMs - this.now();
@@ -1242,7 +1324,7 @@ export class FsWatcherManager {
return isRelPathUnderPrunedDirs(
relative,
state.prunedRelPrefixes,
- this.useDefaultIgnores,
+ this.useDefaultIgnores || state.gitIgnoredListingFailed,
);
}
From cb07e92b407d1d247cf083dae5d66b6efc574555 Mon Sep 17 00:00:00 2001
From: Patrick Gilmore
Date: Sun, 22 Nov 2026 16:08:57 +0000
Subject: [PATCH 2/2] fix(host-service): never cap generated ignored dirs
listGitIgnoredDirs kept the first 200 collapsed dirs in git's sorted order,
so a worktree with more ignored dirs lost whichever sorted last, and chokidar
crawled those subtrees. On a real monorepo checkout git lists 268 ignored
dirs: the cut drops 68 of them, 13 of them node_modules, the root
node_modules among them because it sorts after every nested path. Of the 268,
222 are generated dirs, so no ranking can fit them under a fixed cap.
#9912's new-dir prune does not reach these. It reacts to create events, and
chokidar runs with ignoreInitial, so existing dirs never produce one. The
git-watcher refresh compares one capped list with another, sees no growth,
and never re-attaches.
- Every fully ignored dir named like generated output
(DEFAULT_IGNORE_DIR_NAMES) is kept, with no cap. The 200 cap now bounds
only the other ignored dirs. Only git-confirmed, fully ignored dirs are
pruned, so tracked build/vendor files stay observable.
- DEFAULT_IGNORE_PATTERNS and DEFAULT_IGNORE_DIR_NAMES move unchanged into a
dependency-free ignore-defaults module with its own package entry, so the
watcher worker that runs the listing does not load the search code.
Claude-Session: https://claude.ai/code/session_01SmhtiD5kaHuqyogu8ef5R2
---
.../src/runtime/git/ignored-dirs.test.ts | 28 ++++++++++
.../src/runtime/git/ignored-dirs.ts | 20 +++++--
packages/workspace-fs/package.json | 4 ++
.../src/find-nested-repos.test.ts | 2 +-
packages/workspace-fs/src/ignore-defaults.ts | 53 ++++++++++++++++++
packages/workspace-fs/src/search.ts | 55 +------------------
packages/workspace-fs/src/watch.ts | 4 +-
7 files changed, 104 insertions(+), 62 deletions(-)
create mode 100644 packages/workspace-fs/src/ignore-defaults.ts
diff --git a/packages/host-service/src/runtime/git/ignored-dirs.test.ts b/packages/host-service/src/runtime/git/ignored-dirs.test.ts
index 1c9b1c44e04..ba3f4a352d4 100644
--- a/packages/host-service/src/runtime/git/ignored-dirs.test.ts
+++ b/packages/host-service/src/runtime/git/ignored-dirs.test.ts
@@ -56,6 +56,34 @@ describe("listGitIgnoredDirs", () => {
await expect(listGitIgnoredDirs(dir)).rejects.toThrow();
});
+ test("never caps generated dirs, only the other ignored dirs", async () => {
+ const dir = await createRepo();
+ await writeFile(
+ path.join(dir, ".gitignore"),
+ "cache-*/\nbuild/\nnode_modules/\n",
+ );
+ const makeDir = async (relativeDir: string) => {
+ await mkdir(path.join(dir, relativeDir), { recursive: true });
+ await writeFile(path.join(dir, relativeDir, "entry"), "x");
+ };
+ const indexes = Array.from({ length: 205 }, (_, index) =>
+ String(index).padStart(3, "0"),
+ );
+ for (const index of indexes) {
+ await makeDir(`cache-${index}`);
+ await makeDir(`pkgs/p${index}/build`);
+ }
+ await makeDir("zz/node_modules");
+
+ const ignored = await listGitIgnoredDirs(dir);
+
+ const builds = ignored.filter((entry) => entry.endsWith("/build"));
+ const caches = ignored.filter((entry) => entry.startsWith("cache-"));
+ expect(builds).toHaveLength(205);
+ expect(ignored).toContain("zz/node_modules");
+ expect(caches).toHaveLength(200);
+ });
+
test("returns [] for a missing path", async () => {
expect(
await listGitIgnoredDirs("/nonexistent/definitely-not-here"),
diff --git a/packages/host-service/src/runtime/git/ignored-dirs.ts b/packages/host-service/src/runtime/git/ignored-dirs.ts
index 8c1ca5e19f4..692b5432414 100644
--- a/packages/host-service/src/runtime/git/ignored-dirs.ts
+++ b/packages/host-service/src/runtime/git/ignored-dirs.ts
@@ -1,13 +1,15 @@
import { execFile } from "node:child_process";
import { promisify } from "node:util";
import { resolveCommand } from "@superset/shared/resolve-command";
+import { DEFAULT_IGNORE_DIR_NAMES } from "@superset/workspace-fs/ignore-defaults";
const execFileAsync = promisify(execFile);
-// Bounds for a pathological repo (thousands of ignored entries): the caller
-// turns each dir into a per-event glob/prefix check, so an unbounded list
-// would trade watcher churn for matcher churn.
-const MAX_IGNORED_DIRS = 200;
+// Bounds the non-generated remainder for a pathological repo (thousands of
+// ignored entries). Dirs named like generated output (node_modules, build,
+// dist, …) are never capped: they are the subtrees that must not be watched,
+// and a monorepo can have more of them than any fixed cap.
+const MAX_OTHER_IGNORED_DIRS = 200;
const TIMEOUT_MS = 3_000;
const MAX_BUFFER_BYTES = 10 * 1024 * 1024;
@@ -56,10 +58,16 @@ export async function listGitIgnoredDirs(
},
);
const dirs: string[] = [];
+ let others = 0;
for (const entry of stdout.split("\0")) {
if (!entry.endsWith("/")) continue;
- dirs.push(entry.slice(0, -1));
- if (dirs.length >= MAX_IGNORED_DIRS) break;
+ const dir = entry.slice(0, -1);
+ const name = dir.slice(dir.lastIndexOf("/") + 1);
+ if (!DEFAULT_IGNORE_DIR_NAMES.has(name)) {
+ if (others >= MAX_OTHER_IGNORED_DIRS) continue;
+ others += 1;
+ }
+ dirs.push(dir);
}
return dirs;
} catch (error) {
diff --git a/packages/workspace-fs/package.json b/packages/workspace-fs/package.json
index 630fcbb09eb..49bf96b9a67 100644
--- a/packages/workspace-fs/package.json
+++ b/packages/workspace-fs/package.json
@@ -20,6 +20,10 @@
"types": "./dist-types/host/index.d.ts",
"default": "./src/host/index.ts"
},
+ "./ignore-defaults": {
+ "types": "./dist-types/ignore-defaults.d.ts",
+ "default": "./src/ignore-defaults.ts"
+ },
"./watch-scan": {
"types": "./dist-types/find-nested-repos.d.ts",
"default": "./src/find-nested-repos.ts"
diff --git a/packages/workspace-fs/src/find-nested-repos.test.ts b/packages/workspace-fs/src/find-nested-repos.test.ts
index 83e0c843e8e..20dbf691566 100644
--- a/packages/workspace-fs/src/find-nested-repos.test.ts
+++ b/packages/workspace-fs/src/find-nested-repos.test.ts
@@ -3,7 +3,7 @@ import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { findNestedRepoRoots } from "./find-nested-repos";
-import { DEFAULT_IGNORE_DIR_NAMES } from "./search";
+import { DEFAULT_IGNORE_DIR_NAMES } from "./ignore-defaults";
const tempRoots: string[] = [];
diff --git a/packages/workspace-fs/src/ignore-defaults.ts b/packages/workspace-fs/src/ignore-defaults.ts
new file mode 100644
index 00000000000..75e6b4f7b69
--- /dev/null
+++ b/packages/workspace-fs/src/ignore-defaults.ts
@@ -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 `**\//**` 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 = new Set(
+ DEFAULT_IGNORE_PATTERNS.map(
+ (pattern) => /^\*\*\/([^/*]+)\/\*\*$/.exec(pattern)?.[1],
+ ).filter((name): name is string => name !== undefined),
+);
diff --git a/packages/workspace-fs/src/search.ts b/packages/workspace-fs/src/search.ts
index 0c39e127cfb..fe762a51136 100644
--- a/packages/workspace-fs/src/search.ts
+++ b/packages/workspace-fs/src/search.ts
@@ -11,6 +11,7 @@ import {
scoreFuzzy,
scoreItemFuzzy,
} from "./fuzzy-scorer";
+import { DEFAULT_IGNORE_PATTERNS } from "./ignore-defaults";
import { normalizeAbsolutePath, toRelativePath } from "./paths";
import type { FsContentMatch, FsSearchMatch } from "./types";
@@ -25,60 +26,6 @@ const KEYWORD_SEARCH_CANDIDATE_MULTIPLIER = 4;
const KEYWORD_SEARCH_MAX_COUNT_PER_FILE = 3;
const KEYWORD_SEARCH_RIPGREP_BUFFER_BYTES = 10 * 1024 * 1024;
-// 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 `**\//**` 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 = new Set(
- DEFAULT_IGNORE_PATTERNS.map(
- (pattern) => /^\*\*\/([^/*]+)\/\*\*$/.exec(pattern)?.[1],
- ).filter((name): name is string => name !== undefined),
-);
-
interface SearchIndexEntry {
absolutePath: string;
relativePath: string;
diff --git a/packages/workspace-fs/src/watch.ts b/packages/workspace-fs/src/watch.ts
index db0998fd84b..6e3eb0ff2b3 100644
--- a/packages/workspace-fs/src/watch.ts
+++ b/packages/workspace-fs/src/watch.ts
@@ -8,10 +8,12 @@ import {
} from "node:timers";
import { toErrorMessage } from "./error-message";
import { findNestedRepoRoots } from "./find-nested-repos";
-import { normalizeAbsolutePath } from "./paths";
import {
DEFAULT_IGNORE_DIR_NAMES,
DEFAULT_IGNORE_PATTERNS,
+} from "./ignore-defaults";
+import { normalizeAbsolutePath } from "./paths";
+import {
invalidateSearchIndexesForRoot,
patchSearchIndexesForRoot,
type SearchPatchEvent,