From 67620569ab1c35cdb7f08b860230bce2b2681840 Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Fri, 13 Feb 2026 09:30:35 +0000 Subject: [PATCH] fix(server): avoid recursive checkout diff watches on linux --- packages/server/src/server/session.ts | 47 +++++++++++++++++---------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/packages/server/src/server/session.ts b/packages/server/src/server/session.ts index cbfb467b8..539708c6c 100644 --- a/packages/server/src/server/session.ts +++ b/packages/server/src/server/session.ts @@ -3934,17 +3934,17 @@ export class Session { latestFingerprint: null, }; - const watchPaths = new Set([cwd]); - if (watchRoot) { - watchPaths.add(watchRoot); - } + const repoWatchPath = watchRoot ?? cwd; + const watchPaths = new Set([repoWatchPath]); const gitDir = await this.resolveCheckoutGitDir(cwd); if (gitDir) { watchPaths.add(gitDir); } - let hasWatchRootCoverage = false; + let hasRecursiveRepoCoverage = false; + const allowRecursiveRepoWatch = process.platform !== "linux"; for (const watchPath of watchPaths) { + const shouldTryRecursive = watchPath === repoWatchPath && allowRecursiveRepoWatch; const createWatcher = (recursive: boolean): FSWatcher => watch( watchPath, @@ -3955,18 +3955,31 @@ export class Session { ); let watcher: FSWatcher | null = null; + let watcherIsRecursive = false; try { - watcher = createWatcher(true); - } catch (error) { - try { + if (shouldTryRecursive) { + watcher = createWatcher(true); + watcherIsRecursive = true; + } else { watcher = createWatcher(false); + } + } catch (error) { + if (shouldTryRecursive) { + try { + watcher = createWatcher(false); + this.sessionLogger.warn( + { err: error, watchPath, cwd, compare }, + "Checkout diff recursive watch unavailable; using non-recursive fallback" + ); + } catch (fallbackError) { + this.sessionLogger.warn( + { err: fallbackError, watchPath, cwd, compare }, + "Failed to start checkout diff watcher" + ); + } + } else { this.sessionLogger.warn( { err: error, watchPath, cwd, compare }, - "Checkout diff recursive watch unavailable; using non-recursive fallback" - ); - } catch (fallbackError) { - this.sessionLogger.warn( - { err: fallbackError, watchPath, cwd, compare }, "Failed to start checkout diff watcher" ); } @@ -3983,12 +3996,12 @@ export class Session { ); }); target.watchers.push(watcher); - if (watchRoot && watchPath === watchRoot) { - hasWatchRootCoverage = true; + if (watchPath === repoWatchPath && watcherIsRecursive) { + hasRecursiveRepoCoverage = true; } } - const missingRepoCoverage = Boolean(watchRoot) && !hasWatchRootCoverage; + const missingRepoCoverage = !hasRecursiveRepoCoverage; if (target.watchers.length === 0 || missingRepoCoverage) { target.fallbackRefreshInterval = setInterval(() => { this.scheduleCheckoutDiffTargetRefresh(target); @@ -4001,7 +4014,7 @@ export class Session { reason: target.watchers.length === 0 ? "no_watchers" - : "missing_repo_root_coverage", + : "missing_recursive_repo_root_coverage", }, "Checkout diff watchers unavailable; using timed refresh fallback" );