Skip to content

Agent tools incorrectly treat non-existent workspace files as external #292424

Closed
microsoft/vscode-copilot-chat
#3795

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

Activity

  1. vs-code-engineering commented on Feb 3, 2026

    @vs-code-engineering
    Contributor

    Hi Harald Kirschner (@digitarald). As a member of the team, you can help us triage this issue by referring to https://github.com/microsoft/vscode-copilot/wiki/Copilot-Inbox-Tracker and assigning an owner directly.

  2. connor4312 commented on Feb 3, 2026

    @connor4312
    Member

    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)?

  3. garretwilson commented on Feb 6, 2026

    @garretwilson

    We don't do any existence checks to show the prompt.

    I'm puzzled by what existence checks would have to do with the algorithm, unless there is another bug. Whether a path is within a particular workspace is a product of a known algorithm of normalizing and resolving paths and then seeing if they have the same prefix. Whether they exist shouldn't come into play in this algorithm. In fact both the workspace and the requested path could both not exist, yet the algorithm should still work.

    For example see my isSubPath() utility in https://github.com/globalmentor/globalmentor-base/blob/main/core/src/main/java/com/globalmentor/io/Paths.java (which I wrote before LLMs).

    I spent a long time in #293204 providing a comprehensive matrix of the different scenarios. I recommend creating a test suite based upon those scenarios, run the algorithm, and fix the failing tests. Nothing about that sounds complicated or novel, other than the fact that apparently it hasn't been done yet.

  4. sbatten commented on Feb 10, 2026

    @sbatten
    Member

    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.

  5. sbatten commented on Feb 10, 2026

    @sbatten
    Member

    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)

  6. garretwilson commented on Feb 11, 2026

    @garretwilson

    … 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)

    SteVen Batten (@sbatten) can you clarify the intended meaning of that sentence?

    Did you really mean "… that are indeed outside the workspace"?

    I saw "… which are indeed outside the workspace", and at first I interpreted this to mean that you assume any absolute path is outside the workspace. (I was dumbfounded!) But now I think you meant "… that are indeed outside the worksapce", in other words, you don't consider every absolute path outside the workspace, but in this particular case the paths were indeed outside the workspace. I hope that's what you meant.

    But if this ticket is about absolute file requests outside the workspace, then why was my ticket #293204 closed which meticulously spells out a bug for absolute paths that are indeed inside the workspace? (In fact my ticket description plainly says: "The file is inside the workspace.") In addition my ticket shows two tools behaving differently for the same input path. If this current ticket is about files outside the workspace, my ticket #293204 is not a duplicate and should be reopened.

  7. locked and limited conversation to collaborators on Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions