Skip to content
This repository was archived by the owner on May 20, 2026. It is now read-only.

Skip external file confirmation for non-existent files - #3795

Merged
Connor Peet (connor4312) merged 4 commits into
mainfrom
copilot/fix-agent-tools-external-files
Feb 17, 2026
Merged

Connor Peet (connor4312) merged 4 commits into
mainfrom
copilot/fix-agent-tools-external-files

Conversation

Copilot AI commented Feb 17, 2026 •

Copy link
Copy Markdown
Contributor

Agent tools prompted "external file" confirmation for non-existent paths (e.g., /.loop/001-implement-full-spec/context.md) because getWorkspaceFolder() returns undefined for files that don't exist, causing them to be misclassified as external.

Changes

  • isFileExternalAndNeedsConfirmation(): Check file existence before returning true
    • If stat() fails, return false (not external)
    • Tool invocation proceeds and fails with proper "file not found" error
    • Avoids confusing "outside workspace" dialogs for non-existent files
// After all other checks fail...
const fileExists = await fileSystemService.stat(normalizedUri)
  .then(() => true)
  .catch(() => false);
if (!fileExists) {
  return false;  // Don't prompt - let tool fail with proper error
}
return true;  // Existing external file - needs confirmation

Testing

  • Added tests verifying non-existent files don't trigger confirmation
  • Added tests verifying existing external files still require confirmation
  • All 30 tests passing
Original prompt

This section details on the original issue you should resolve

<issue_title>Agent tools incorrectly treat non-existent workspace files as external</issue_title>
<issue_description>### Issue Description

When the agent attempts to access a file path that doesn't exist (or is invalid) within the workspace, it incorrectly identifies the file as "external" and prompts for confirmation with "is outside of the current workspace." If the user clicks the link in the error dialog, it shows "Unable to open 'common' - The editor could not be opened because the file was not found."

Example

🛠️ read_file (call_GzhPpQEUmEzfVBDyKLpYjgoG) {
  "filePath": "/.loop/001-implement-full-spec/context.md"
}
🛠️ read_file (call_mhBGKo7q8Z98OTAPIjOUbp38) {
  "filePath": "/.loop/001-implement-full-spec/plan.md"
}
🛠️ list_dir (call_fARd2sMlBt5CUjWTCPOAE2t6) {
  "path": "/.loop/001-implement-full-spec/learnings"
}
Image

Root Cause

In vscode-copilot-chat/src/extension/tools/node/toolUtils.ts, isFileExternalAndNeedsConfirmation() checks:

if (workspaceService.getWorkspaceFolder(normalizedUri)) {
    return false;  // Not external
}
// ... other checks ...
return true;  // Treat as external

When a file path is invalid or non-existent within the workspace, getWorkspaceFolder() returns undefined, causing the file to be incorrectly flagged as external rather than as an invalid workspace path.

Key Breadcrumbs

  1. File resolution: resolveToolInputPath() → promptPathRepresentationService.resolveFilePath()
  2. External check: isFileExternalAndNeedsConfirmation() at line 181
  3. Workspace lookup: workspaceService.getWorkspaceFolder() implementation uses extUriBiasedIgnorePathCase.isEqualOrParent(resource, folder)
  4. Error message: Uses dirname(uri) as the "folder" in confirmation dialog at readFileTool.tsx:181

Related Issues

Similar path resolution issues in remote/WSL scenarios:

Expected Behavior

Non-existent or invalid paths within the workspace should be identified as invalid/not found, not as external files requiring confirmation.

Reproduction

Occurs when agent provides a path that:

  • Resolves to a valid URI format
  • Is logically within the workspace directory structure
  • But doesn't exist on disk or has some path normalization issue</issue_description>

<agent_instructions>We should not show approvals when the read_file tool is called for files that don't exise</agent_instructions>

Comments on the Issue (you are Copilot in this section)

Connor Peet (@connor4312) The model here is just asking for `/.loop/...` in your filesystem root, which I assume doesn't exist. We don't do any existence checks to show the prompt. I assume it's trying to use an incorrect absolute path for something that's actually in the workspace. Not sure how these should get handled, maybe we intentionally shouldn't prompt for files that don't exist. What do you think SteVen Batten (@sbatten)? SteVen Batten (@sbatten) Connor Peet (@connor4312) aha, I believe this issue of the model reading files with incorrect paths is not new and before the model would get self corrected because we'd error behind the scenes. now we are showing a confirmation which is *correct* but annoying. maybe we should return an error just like when the file doesn't exist in the workspace. SteVen Batten (@sbatten) Garret Wilson (@garretwilson) in this issue, the read_file tools are being called with absolute paths which are indeed outside of the workspace so the algorithm is functioning correctly (at least for this particular case)

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits February 17, 2026 15:40
- Add file existence check in isFileExternalAndNeedsConfirmation()
- Non-existent files now return false (not external) to prevent confirmation dialog
- Actual tool invocation will fail with proper "file not found" error
- Update tests to reflect new behavior

Co-authored-by: connor4312 <[email protected]>
- Add comprehensive comment explaining error handling tradeoff
- Add test suite with MockFileSystemService to verify existing external files still need confirmation
- Tests confirm the fix works correctly for both existing and non-existing files

Co-authored-by: connor4312 <[email protected]>
Copilot AI changed the title [WIP] Fix agent tools identifying non-existent files as external Skip external file confirmation for non-existent files Feb 17, 2026
@connor4312
Connor Peet (connor4312) marked this pull request as ready for review February 17, 2026 17:09
Copilot AI review requested due to automatic review settings February 17, 2026 17:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an issue where agent tools incorrectly prompted for "external file confirmation" when attempting to access non-existent files within the workspace. The root cause was that getWorkspaceFolder() returns undefined for non-existent files, causing them to be misclassified as external files.

Changes:

  • Modified isFileExternalAndNeedsConfirmation() to check file existence before classifying files as external
  • Updated existing tests to reflect the new behavior for non-existent files
  • Added comprehensive test coverage for both existing and non-existent files using MockFileSystemService

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/extension/tools/node/toolUtils.ts Added file existence check using fileSystemService.stat() with .then(() => true).catch(() => false) pattern before returning true for external files
src/extension/tools/node/test/toolUtils.spec.ts Updated test expectations for non-existent files and added new test suite with MockFileSystemService to verify both existing and non-existent file scenarios

Comment thread src/extension/tools/node/toolUtils.ts Resolved
Comment thread src/extension/tools/node/toolUtils.ts Resolved
@connor4312
Connor Peet (connor4312) added this pull request to the merge queue Feb 17, 2026
Merged via the queue into main with commit 575863b Feb 17, 2026
19 checks passed
@connor4312
Connor Peet (connor4312) deleted the copilot/fix-agent-tools-external-files branch February 17, 2026 21:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agent tools incorrectly treat non-existent workspace files as external

7 participants