Skip to content

agentHost: resolve remote Working Set files and track parallel edits - #345031

Merged
Justin Chen (justschen) merged 1 commit into
mainfrom
agents/fix-copilot-path-separator-issue
Oct 29, 2026
Merged

Justin Chen (justschen) merged 1 commit into
mainfrom
agents/fix-copilot-path-separator-issue

Conversation

@justschen

Copy link
Copy Markdown
Collaborator

This fixes two problems with the session Working Set ("N files changed" above the chat input) in Copilot harness (Agent Host) sessions.

There is no issue for these reports. #308847 shows a similar symptom for file links in chat responses when connected to a Linux server; this PR does not change that code path.

Remote windows: clicking a changed file opens a path on the client

In a window attached to a remote (WSL, dev container, SSH), the window's own agent host runs on the remote, but its sessions resolve with the reserved local authority. The Working Set, the editor review (AgentHostEditReview) and the Keep/Undo matching converted the host's changeset files with that authority. toAgentHostUri leaves file: URIs unwrapped for local, so a container file such as file:///workspaces/app/src/a.ts was treated as a file on the client: on a Windows client it showed as \workspaces\app\src\a.ts and failed to open. The old diff view worked because it only read snapshot content through the agent host; since #344477, Working Set rows open the file itself.

The Working Set diffs, the Keep/Undo matching and the editor review now use the authority of the connection's resource URIs, as artifact pills already did since #343483. That helper moved from agentHostSessionInputPills.ts to agentHostResponseFileChanges.ts as getAgentHostResourceAuthority. Local windows and separately connected remote agent hosts are unchanged.

Parallel edits of one file: the Working Set under-counts and Keep/Undo disappears

FileEditTracker kept one pending and one completed edit per file path. A batch of tool calls runs all of its preToolUse hooks before any of its tools, so when several calls edited the same file, each trackEditStart replaced the previous call's entry:

  • Only the first call to finish recorded an edit, from the original file to its own change. The other calls recorded nothing, so the Working Set showed, for example, +1 −1 for seven edits.
  • The other calls' coordinator leases leaked, so isEditing stayed true until the session ended. The editor review skips a file that is being edited, so it showed no inline diff or Keep/Undo, and the host's discard (Undo) waited 30s and failed with "The agent is still editing".

FileEditTracker now keeps per-file queues of pending and completed edits:

  • trackEditStart and completeEdit take the tool input, as takeCompletedEdit already did, so each call finds its own entry; calls without input are paired in order. In the reporting session's logs, the hook arguments and the tool.execution_start arguments were structurally equal for all 22 edit calls.
  • An edit that started before other edits of the file completed begins from what the last of them wrote.
  • Every lease is released when its edit is taken or dropped. Entries skipped by a later matched call, whose completion was never delivered, are dropped too.
  • A file's state is forgotten once it has no edits, so no content is retained.

The Copilot hooks and the Claude file-edit observer now pass their tool input; both providers share the tracker. Pairing relies on the edits of one file completing in the order they started, which held for every batch in the logs. Two agents editing the same file at the same moment could still be attributed to the wrong call.

How to test

Remote window (Windows client with WSL or a dev container):

  1. Set chat.editor.workingSet.enabled to true and start a Copilot harness chat.
  2. Ask the agent to edit a file, then click the file in the Working Set. It opens through the agent host instead of failing on a \-separated path on the client.

Parallel edits (any window):

  1. Set chat.editor.workingSet.enabled to true and use the Copilot harness with a model that batches tool calls, such as Claude Sonnet 5.5.
  2. Ask it to edit three non-adjacent lines of a file "with exactly three parallel edit tool calls in a single response".
  3. The Working Set shows +3 −3, the editor shows "Keep / Undo / 3 of 3", and keeping or undoing a single change works.

Validation

  • ./scripts/test.sh --reporter dot --run src/vs/workbench/contrib/chat/test/browser/agentHost/agentHostSessionInputPills.test.ts --run src/vs/workbench/contrib/chat/test/browser/agentHost/agentHostEditReview.test.ts --run src/vs/workbench/contrib/chat/test/browser/agentHost/agentHostResponseFileChanges.test.ts --run src/vs/workbench/contrib/chat/test/browser/agentHost/agentHostSnapshotController.test.ts --run src/vs/workbench/contrib/chat/test/browser/widget/input/chatSessionWorkingSet.test.ts: passed, 290 passing.
  • ./scripts/test.sh --reporter dot --runGlob "vs/platform/agentHost/test/node/*.test.js": passed, 12,367 passing and 74 pending.
  • The new tests fail without the source changes: the remote Working Set resolves file:///repo/file.ts on the client, the editor review never loads the file, and the tracker reports editing: true with later calls not recorded.
  • npm run eslint -- <the 9 changed files>: passed.
  • npm run typecheck-client: passed.
  • npm run build-fast (client, built-in extensions and Copilot): passed.
  • Manual, parallel edits: a Code OSS build of this branch with the Copilot harness and Claude Sonnet 5.5. The SDK ran one response with three edit calls (one preToolUse batch of 3). The Working Set showed +3 −3 and the review "3 of 3"; Keep gave "2 of 2", Undo gave "1 of 1" with the file restored, and Keep cleared the rest.
  • Not run: a real Windows window attached to WSL or a dev container. Unit tests cover the remote case by modeling the remote window's ambient connection (the local authority with a remote resource URI mapper).

In a window attached to a remote (WSL, dev container, SSH), the ambient agent host runs on the remote but its sessions resolve with the reserved `local` authority. The session Working Set, the editor review and Keep/Undo matching converted the host's changeset files with that authority, which leaves `file:` URIs unwrapped, so clicking a changed file opened a path on the client's disk (shown with Windows separators on a Windows client) and failed. They now use the authority of the connection's resource URIs, as artifact pills already did.

FileEditTracker kept one pending and one completed edit per file path. When a batch of tool calls edited one file in parallel, each start replaced the previous one: only one call's edit was recorded and the other calls' edit leases leaked, so the file stayed marked as being edited for the rest of the session. The Working Set then under-counted the agent's changes, the editor review skipped the file and Undo timed out. Edits are now tracked per tool call, matched by tool input or else in order; an edit that starts while others of the file are pending begins from what the last of them wrote; and every lease is released when its edit is taken or dropped.

Co-authored-by: Copilot <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 29, 2026 17:34

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.

🟡 Changes recommended

Concurrency issues in fileEditTracker can produce incorrect before-snapshots, double-counting changes during overlapping completions or attributing a user’s Undo to a subsequent edit.

2 open issues
What changed in this PR

This PR fixes Agent Host Working Set file resolution in remote windows and tracks multiple edits to the same file. It follows the move to opening Working Set files in regular editors and reuses the resource-authority handling introduced for artifact pills.

Changes:

  • Resolve Working Set files, editor review, and Keep/Undo matching through the connection’s resource authority.
  • Queue edits per file, pair them by tool input, and release their coordinator leases.
  • Add regression coverage for remote-window resolution and batched edits.
File Description
src/​vs/​workbench/​contrib/​chat/​test/​browser/​agentHost/​agentHostSessionInputPills.test.ts Tests remote Working Set resources and Keep/Undo operations.
src/​vs/​workbench/​contrib/​chat/​test/​browser/​agentHost/​agentHostEditReview.test.ts Adds remote-window editor review coverage.
src/​vs/​workbench/​contrib/​chat/​browser/​agentSessions/​agentHost/​agentHostSessionInputPills.ts Uses resource authority for Working Set files and operation matching.
src/​vs/​workbench/​contrib/​chat/​browser/​agentSessions/​agentHost/​agentHostResponseFileChanges.ts Exposes the shared resource-authority helper.
src/​vs/​workbench/​contrib/​chat/​browser/​agentSessions/​agentHost/​agentHostEditReview.ts Resolves review files using resource authority.
src/​vs/​platform/​agentHost/​test/​node/​fileEditTracker.test.ts Tests batched edits and missed-completion cleanup.
src/​vs/​platform/​agentHost/​node/​shared/​fileEditTracker.ts Adds per-file edit queues and snapshot chaining.
src/​vs/​platform/​agentHost/​node/​copilot/​copilotAgentSession.ts Passes tool input into edit tracking hooks.
src/​vs/​platform/​agentHost/​node/​claude/​claudeFileEditObserver.ts Passes tool input into observed edit tracking.

Review effort: Balanced

@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

TylerLeonhardt

Matched files:

  • src/vs/platform/agentHost/node/claude/claudeFileEditObserver.ts

@justschen
Justin Chen (justschen) merged commit 2f45c38 into main Oct 29, 2026
56 checks passed
@justschen
Justin Chen (justschen) deleted the agents/fix-copilot-path-separator-issue branch October 29, 2026 19:18
@vs-code-engineering vs-code-engineering Bot added this to the 1.145.0 milestone Oct 29, 2026
Ladislau Szomoru (lszomoru) added a commit that referenced this pull request Nov 6, 2026
…346553)

* agentHost: open Working Set files of remote windows as remote files

In a window attached to a remote (WSL, SSH, containers), the ambient agent host resolves with the `local` authority. The Working Set, its Keep/Undo matching, and the editor review converted changeset files with `toAgentHostUri(file, authority)`, which leaves `local` file URIs unwrapped. Clicking a changed file then opened the remote path on the client's disk, which a Windows client shows with backslashes and reports as not found.

#345031 fixed this through the connection's mapper authority, but #345306 changed the editor-remote mapper to return `vscode-remote` URIs, so the authority fell back to `local` again. Map the file through the owning connection's `resourceUris.fromAgentHost` instead, so it opens as the workspace's file, while recorded contents stay Agent Host content URIs. The tests now use the real editor-remote mapper.

Fixes #345420

Co-authored-by: Copilot <[email protected]>

* agentHost: map turn changes through the owning connection's resource URIs

Address review feedback: the changeset helper now takes the owning connection, so callers can no longer pass a mapper built from an authority. The per-response changes provider uses its connection's resourceUris for both changeset and response-part files, which removes its remaining TODO(agent-host-uri) bypasses. Recorded contents stay Agent Host content URIs.

The provider tests now run across every Agent Host connection kind, including the strict exactly-once mapper.

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Copilot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants