vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Agent host: Claude sessions can't be pre-created in multi-root workspaces with a virtual folder (Approvals selection reverts, Folder picker missing)

Open GNeras opened this issue 2 weeks ago • 0 comments

Does this issue occur when all extensions are disabled?: N/A (the scenario requires an extension to provide virtual filesystem folders)

Disclosure: I analyzed this issue with the help of an AI coding agent (Claude Code), using VS Code's logs, the shipped 1.146.0 and 1.145.3 bundles, and the source at main (36e8c02).

Environment

  • VS Code: 1.146.0 (69047191fc427f2f92828279aae1d90d8eeda7ab), .deb, Linux x64
  • Last version without the problem: 1.145.3
  • Agent: Claude in the local agent host

Steps to reproduce

  1. Open a multi-root workspace with a local folder first and one or more folders from a FileSystemProvider extension. In my case they come from ABAP FS (abap: scheme):
    {
      "folders": [
        { "path": "abap-work" },
        { "name": "SYSTEM_A", "uri": "abap:/repotree-v1/SYSTEM_A" },
        { "name": "SYSTEM_B", "uri": "abap:/repotree-v1/SYSTEM_B" }
      ]
    }
    
  2. Open a new chat with the Claude agent (agent host).
  3. Before sending anything, pick another option in the Approvals picker of the chat input (for example, Edit Automatically).
  4. Send the first message.

Expected

  • The selected Approvals option is applied, as it is in a workspace with only local folders.
  • The Folder picker is shown, as it was in 1.145.3.

Actual

  • The picker accepts the click, but the selection goes back to the previous option.
  • The Folder picker is not shown.
  • After the first message is sent, the Approvals picker disappears for a few seconds and comes back. From then on, it works.

Agent host log (agenthost.log):

[error] [ProtocolServer] Request 'createSession' id=749 failed Agent 'claude' does not support virtual workspaces.
[error] [ProtocolServer] Request 'subscribe' id=751 failed Session not found on backend: claude:/98a26c3c-...
[error] [AgentService] async dispatchAction failed: Working directory must be a file URI: abap:/repotree-v1/SYSTEM_A
[error] [AgentService] async dispatchAction failed: Working directory must be a file URI: abap:/repotree-v1/SYSTEM_B
... (the last two lines repeat 150–290 times per window session)

Analysis

#346117 lets local Copilot sessions use virtual workspaces and keeps other agents out of them:

  • The agent host now rejects non-file: working directories in createSession for providers without supportsVirtualWorkspaces (agentService.ts#L6514). Only Copilot declares it.
  • The workbench drops those directories for non-Copilot providers in AgentHostSessionHandler._hostAddressableWorkingDirectories (agentHostSessionHandler.ts#L8112).

That filter only runs on the send path (_resolveRequestedWorkingDirectories). Two other places still build working-directory sets from all workspace folders, including the virtual ones:

  1. AgentHostUntitledProvisionalSessionService (_computeWorkingDirectories / _computeEntryWorkingDirectories, L441–L456). Claude advertises multipleWorkingDirectories, so the pre-warmed createSession (L800) receives [abap-work, abap:/…, …] and is rejected. Because there is no provisional session:
    • applyConfigChange has nothing to apply the Approvals selection (permissionMode) to, so the selection is lost.
    • The session state has no folderPickerDecision, so resolveFolderPickerDecisionUpdate hides the Folder picker. That logic is the same in 1.145.3; it only changed because the session is no longer created.
    • The first send creates the session through the handler, whose filter keeps only abap-work. That explains why the picker disappears and comes back, and why it works afterwards.
  2. AgentHostSessionWorkingDirectorySynchronizer._reconcile (L294). After the session starts, it dispatches SessionWorkingDirectorySet for the virtual folders. The host rejects each one (sessionWorkingDirectories.ts#L74), which produces the repeated errors above.

Proposed fix

Decide in a single place which workspace folders a provider can use as working directories, and apply that decision everywhere a working-directory set is built:

  • Move the check that _hostAddressableWorkingDirectories does today into a shared helper, next to computeWorkingDirectories in agentHostNewSessionFolderService.ts. The rule stays the same: the directory must have the host's scheme, and only the local Copilot provider (outside the Agents window) also accepts virtual directories. The send path keeps its current behaviour, now through the helper.
  • In AgentHostUntitledProvisionalSessionService and in AgentHostSessionWorkingDirectorySynchronizer, filter the workspace folders with that helper before computing the working-directory set, not after. This way usesWorkspaceRootSet is also computed from the folders the provider can actually use. In my workspace, Claude would get only abap-work, so the provisional session would be created, the Approvals selection would stick, and the Folder picker would come back.
  • Keep the node-side guard as the authoritative backstop.

This shouldn't change anything else:

  • Copilot on a virtual workspace: still allowed, because LocalAgentHostService.clientConnectionKind is Local.
  • Single-folder or local-only workspaces, the Agents window and remote hosts: they get the same rules the send path already applies.
  • A virtual folder explicitly chosen as the primary for Claude: still fails, as intended.

Possible follow-ups, out of scope here:

  • The Folder picker still lists virtual folders for providers that can't use them.
  • Longer term, agents could advertise virtual workspace support in their capabilities instead of the client comparing against COPILOT_CLI_AGENT_PROVIDER_ID.

Tests to add:

  • In agentHostUntitledProvisionalSessionService.test.ts: a workspace with one file: folder and one virtual folder, using the Claude provider with multipleWorkingDirectories. Assert that the provisional createSession receives only the file: folder.
  • The same case for agentHostSessionWorkingDirectorySynchronizer.test.ts.

GNeras avatar Nov 18 '26 09:11 GNeras