Skip to content

chat: keep pulled changes out of agent edit review - #347442

Merged
Justin Chen (justschen) merged 6 commits into
microsoft:mainfrom
justschen:agents/git-pull-keep-undo-investigation
Nov 11, 2026
Merged

Justin Chen (justschen) merged 6 commits into
microsoft:mainfrom
justschen:agents/git-pull-keep-undo-investigation

Conversation

@justschen

@justschen Justin Chen (justschen) commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Prevent unrelated changes from a terminal git pull from appearing as agent Keep/Undo hunks in the editor.

A disk reload can replace one broad range spanning pending agent edits and unrelated upstream changes. The shared edit tracker treats that replacement as overlapping the agent edit, leaving the review baseline stale.

  • Refresh Agent Host editor review from recorded Working Set snapshots after non-agent disk reloads and normal editor Undo/Redo.
  • Keep refreshes ordered with Working Set updates and reject stale results.
  • Preserve tracked user text when refreshing the review: snapshot-derived adjustments only refine existing pending edits, and must match a pending replacement in both range and text. Both document and original model versions are checked.
  • Compare ownership with uncoalesced character mappings, so unchanged inline user text and user-deleted separators are not folded into a wider display change.
  • Retry a comparison that newer edits superseded instead of suspending review.
  • If a precise comparison is unavailable, suspend editor review with the existing synchronization warning and recovery path instead of applying an incorrect baseline. File contents are preserved. The suspended entry keeps its tracked original, so recovery after save or revert does not rebuild ownership from Working Set snapshots alone; it is released when the file leaves the Working Set and is not reused for a newer revision.
  • Cover LF/CRLF reloads, editor Undo/Redo, coarse-diff failures and save recovery, typing during refresh, newer agent edits, user text adjacent to deleted agent edits, retained inline text, and suspended-entry removal and replacement.

The behavior change is limited to Agent Host editor review; it does not change legacy local-chat editing semantics.

Shared API note for reviewers: IEditorWorkerService.computeStringEditFromDiff* now takes IStringDiffOptions, which adds an optional computeRawChanges flag. It reuses DefaultLinesDiffComputer.computeDiffWithRawChanges and is only supported with the built-in advanced algorithm. Existing callers are unaffected: the flag is off by default and the display diff path is unchanged.

An earlier revision of this PR also carried a Chat Sessions smoke-test readiness fix. The same fix landed separately in #347394, so it is no longer part of this diff.

Tracking issue: none supplied; reported directly during use.

Validation

The branch includes main at 691ae8dc3b125d88b6e03ee2afb7ff3c5c72ae0e. The only merge conflict was the smoke test above, resolved by taking main's version. The commands below were all rerun on the merged tree.

  • pnpm run build-fast --client-only, pnpm run typecheck-client, and pnpm run monaco-compile-check — all passed.

  • The following focused Electron test command — passed, 125 tests:

    ./scripts/test.sh \
      --run src/vs/workbench/contrib/chat/test/browser/agentHost/agentHostEditReview.test.ts \
      --run src/vs/workbench/contrib/chat/test/browser/chatEditing/chatEditingService.test.ts \
      --run src/vs/workbench/contrib/chat/test/browser/chatEditing/chatEditingCodeEditorIntegration.test.ts \
      --run src/vs/editor/test/common/services/editorWebWorker.test.ts \
      --reporter dot
  • pnpm run eslint on the seven changed files (the editor worker service, worker, and their tests, plus agentHostEditReview.ts and its test) — passed.

  • git diff --check origin/main...HEAD — passed.

  • The original reload regression and the later editor Undo/Redo, coarse-diff, adjacent-user-text, inline-text, suspended-recovery, and superseded-comparison regressions failed before their respective fixes.

Live validation on macOS used a signed-in Code OSS window, a real Copilot SDK edit, and a disposable local repository. A terminal pull left one agent-review hunk; editor Keep/Undo's Undo action removed only the agent change and preserved both upstream changes on disk. This live run preceded the editor Undo/Redo, coarse-diff, adjacent-user-text, and later review-feedback follow-ups; those follow-ups are covered by the automated tests above, not by a live run. Windows/Linux live validation and full integration/smoke suites were not run locally.

Manual test

  1. In a disposable repository, use Copilot SDK to edit a line in the middle of a file and leave Keep/Undo review pending.
  2. Commit that edit without accepting its review, so a normal pull can merge other changes to the same file.
  3. Make upstream changes both before and after the agent-edited line, then run git pull in the integrated terminal.
  4. Verify only the original agent hunk is under review; both pulled changes are ordinary file content.
  5. Use normal editor Undo and Redo and verify the review still contains only the agent hunk.
  6. Use the editor's chat-edit Undo action and verify the pulled changes remain intact on disk.

Reconcile disk reloads and editor undo/redo with recorded Working Set snapshots so unrelated external changes do not become Keep/Undo hunks.

Suspend editor review when precise comparison is unavailable and reuse the existing recovery path. Cover reloads, edit races, line endings, and save recovery.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 10, 2026 18:56

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

Undo/Redo refreshes can drop adjacent user-owned text from the tracked review baseline, incorrectly placing it back under agent review.

1 open issue
What changed in this PR

This PR updates Agent Host editor review to keep unrelated changes from terminal pulls out of agent Keep/Undo hunks, without changing legacy local-chat editing behavior.

Changes:

  • Refresh review baselines after disk reloads and editor Undo/Redo, ordered with Working Set updates and guarded against stale results.
  • Suspend review when changes cannot be compared precisely, preserving file contents and allowing recovery after save or revert.
  • Add regression coverage for line endings, recovery, concurrent typing, and newer agent edits.
File Description
src/​vs/​workbench/​contrib/​chat/​test/​browser/​agentHost/​agentHostEditReview.test.ts Adds reload, Undo/Redo, recovery, and pending-refresh regression tests.
src/​vs/​workbench/​contrib/​chat/​browser/​agentSessions/​agentHost/​agentHostEditReview.ts Adds guarded baseline refreshes and shared synchronization-error handling.

Review effort: Balanced

The chat view can bind the default Agent Host session while the New Local Chat command is still activating. Wait for a new local session before sending the smoke prompt, reusing the readiness helper used by the other chat suites.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep tracked non-agent text in the review baseline when reconciling disk reloads and editor undo/redo. Restrict snapshot-derived adjustments to existing pending changes and guard both model versions.

Add adjacent-user-edit regressions, including a broad reload followed by undo and redo.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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

Containment checks and coarse-refresh recovery can misclassify user-authored text as agent edits, risking unintended removal of user content during review.

3 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Coalesce queued refreshes per entry

src/​vs/​workbench/​contrib/​chat/​browser/​agentSessions/​agentHost/​agentHostEditReview.ts:495

Every Undo/Redo or reload appends another full-document refresh to _updates, even when an already queued task will compare the same latest models. Repeated Undo on a large file can therefore accumulate redundant worker diffs and delay Working Set updates and Keep/Undo operations on the same sequencer. Coalesce queued refreshes per entry so a burst schedules only the latest necessary comparison.

1 resolved since last review

Review effort: Max

Retry comparisons superseded by newer edits instead of suspending review. Retain a suspended entry and its tracked original so recovery does not rebuild ownership from Working Set snapshots alone.

Refine the review baseline with uncoalesced character mappings, through an opt-in editor worker option, and require refinements to match pending replacements in range and text.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@justschen
Justin Chen (justschen) marked this pull request as ready for review November 10, 2026 23:23
Resolve the conflict in test/smoke/src/areas/chat/chatSessions.test.ts by taking main's version: microsoft#347394 landed the same Local-session readiness fix.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@justschen
Justin Chen (justschen) merged commit 0bbc838 into microsoft:main Nov 11, 2026
52 of 53 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.147.0 milestone Nov 11, 2026
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