Skip to content

[Repo Assist] refactor: replace deprecated fs.exists with fs.existsSync in addRootPath#117

Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
repo-assist/improve-deprecated-fs-exists-2026-03-31-17f72d8370135b1e
Draft

[Repo Assist] refactor: replace deprecated fs.exists with fs.existsSync in addRootPath#117
github-actions[bot] wants to merge 1 commit intomasterfrom
repo-assist/improve-deprecated-fs-exists-2026-03-31-17f72d8370135b1e

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

Summary

Replaces the deprecated fs.exists() callback API with fs.existsSync() in the addRootPath() method of extension.js.

Problem

fs.exists() has been deprecated since Node.js 4.0.0. Beyond the deprecation, there was a subtle race condition: all workspace folder checks ran concurrently (asynchronous callbacks), so in a multi-root workspace the last callback to fire would "win" and overwrite this.executablePath. This made executable resolution non-deterministic.

Additionally, since addRootPath is called synchronously from loadSettings, this.executablePath might not have been updated yet by the time format() used it, depending on callback timing.

Fix

Replace fs.exists(path, cb) with fs.existsSync(path):

  • Removes the deprecated API
  • Returns immediately on the first matching workspace folder (predictable)
  • Keeps addRootPath fully synchronous, matching its call site

Trade-offs

  • Before: last matching folder wins (async, non-deterministic)
  • After: first matching folder wins (sync, deterministic)

Behaviour is unchanged for single-root workspaces (the common case).

Test Status

All 7 unit tests pass (npm run test:unit). No new tests added (the change is to non-testable VS Code API integration code — workspace folder resolution requires a live VS Code host).

Closes no specific issue, but is related to the general reliability of multi-root workspace support.

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@346204513ecfa08b81566450d7d599556807389f

fs.exists() has been deprecated since Node.js 4.0 and was removed in
newer versions of the Node.js docs. Replace it with fs.existsSync() which:

1. Removes the deprecation warning.
2. Fixes a non-deterministic race condition: with the async callback, all
   workspace folder checks ran concurrently and the last callback to fire
   would win, making executablePath resolution unpredictable in multi-root
   workspaces. With existsSync, the first matching folder wins and the
   function returns immediately, giving consistent, predictable behaviour.
3. Keeps the code simpler — no callback nesting required.

Behaviour is unchanged for single-root workspaces (the common case).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request Apr 2, 2026
Summarises all bug fixes that are ready to ship, drawn from the
open Repo Assist PRs (primarily #106, #114, #117, #120, #124 and
the earlier consolidated fixes).

The version number in package.json is intentionally not changed here
(that file requires maintainer action due to protected-file
restrictions). This PR exists so the maintainer can review the
intended release notes and bump the version when ready.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

0 participants