Repository navigation
Agents - implement discard changes for Session Changes - #342260
Merged
Ladislau Szomoru (lszomoru) merged 3 commits intoOct 17, 2026
Merged
Ladislau Szomoru (lszomoru) merged 3 commits into
Ladislau Szomoru (lszomoru) merged 3 commits into
Conversation
…scard Move reading the revert steps, preparing the revert, recording the discard rows while applying the revert inside the transaction, and undoing it on failure out of _discardTurnFile into _discardRecordedEdits, so the Session Changes discard can reuse it. No behavior change. Co-authored-by: Copilot <[email protected]>
Offer Discard Changes on Session Changes unless the changeset spans more than one folder, with or without Git. The discard reuses the Last Turn core: it reads one revert step per tracked edit of the file across every turn, prepares a single revert, and records one discard row per turn, newest turn first, in the transaction that applies the revert, after checking that no turn ran in any chat of the session meanwhile. Files outside the session's folders, renamed files, and files that more than one chat edited are rejected, and a file the session created gets a Session-specific message. Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Replaying previously discarded history can overwrite later user edits or incorrectly reject a valid discard.
1 open issue
What changed in this PR
Adds resource-scoped discard to Session Changes, extending Agent Host’s tracked-edit revert flow across turns.
Changes:
- Shares transactional revert logic between Last Turn and Session Changes.
- Adds session database access, safety guards, and operation availability without Git.
- Extends tests, service fakes, and provider documentation.
| File | Description |
|---|---|
src/vs/sessions/contrib/providers/agentHost/AGENT_HOST_SESSIONS_PROVIDER.md |
Documents session discard behavior. |
src/vs/platform/agentHost/test/node/fileEditDiscard.test.ts |
Tests per-turn discard bookkeeping. |
src/vs/platform/agentHost/test/node/agentSideEffects.test.ts |
Updates service fake. |
src/vs/platform/agentHost/test/node/agentHostTurnTelemetry.test.ts |
Updates service fake. |
src/vs/platform/agentHost/test/node/agentHostTurnHangTelemetry.test.ts |
Updates service fake. |
src/vs/platform/agentHost/test/node/agentHostToolCallTelemetry.test.ts |
Updates service fake. |
src/vs/platform/agentHost/test/node/agentHostDiscardChangesOperationProvider.test.ts |
Tests session operation advertising. |
src/vs/platform/agentHost/test/node/agentHostDiscardChangesOperationHandler.test.ts |
Tests session revert and rejection paths. |
src/vs/platform/agentHost/test/node/agentHostCommitOperationHandler.test.ts |
Updates service fake. |
src/vs/platform/agentHost/test/node/agentHostChangesetService.test.ts |
Tests database and folder selection. |
src/vs/platform/agentHost/test/node/agentHostChangesetOperationService.test.ts |
Tests availability with and without Git. |
src/vs/platform/agentHost/test/node/agentHostChangesetCoordinator.test.ts |
Updates service fake. |
src/vs/platform/agentHost/test/common/sessionTestHelpers.ts |
Extends shared service stub. |
src/vs/platform/agentHost/node/fileEditDiscard.ts |
Generates per-turn session discard rows. |
src/vs/platform/agentHost/node/agentHostDiscardChangesOperationProvider.ts |
Advertises single-folder session discard. |
src/vs/platform/agentHost/node/agentHostDiscardChangesOperationHandler.ts |
Implements transactional session discard. |
src/vs/platform/agentHost/node/agentHostChangesetService.ts |
Exposes tracked session databases. |
src/vs/platform/agentHost/node/agentHostChangesetOperationService.ts |
Exempts session discard from Git requirements. |
src/vs/platform/agentHost/node/agentConfigurationService.ts |
Extracts session directory aggregation. |
src/vs/platform/agentHost/common/agentHostChangesetService.ts |
Defines tracked session database contracts. |
Review effort: Balanced
… Changes Discard rows span their whole turn rather than what that discard changed on disk, which kept changes made between the turn's edits. Replaying them could overwrite a later change to the file or conflict with it. Revert on disk only the edits that no discard undid yet, while every record still counts towards each turn's discard row. Co-authored-by: Copilot <[email protected]>
Ladislau Szomoru (lszomoru)
marked this pull request as ready for review
October 17, 2026 15:33
Ladislau Szomoru (lszomoru)
enabled auto-merge (squash)
October 17, 2026 15:33
Alexandru Dima (alexdima)
approved these changes
Oct 17, 2026
Ross Wollman (rwoll)
approved these changes
Oct 17, 2026
Ladislau Szomoru (lszomoru)
deleted the
lszomoru/agents/session-changes-discard-phase2-implementation
branch
October 17, 2026 16:00
1 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

This pull request implements Phase 2 of the Session Changes discard functionality, building upon the reviewed Phase 1 code. The changes include:
Refactor: Extracted shared core logic into a new method
_discardRecordedEdits, ensuring that the Last Turn behavior remains unchanged. All Phase 1 discard tests pass without modifications.Session Discard Implementation:
readFileEditRevertSteps, with a singleprepare()and write operation for efficiency.Tests and Documentation: Updated tests to reflect the new logic and added documentation for the Session Changes discard behavior.
All tests have been run successfully, and the implementation adheres to the outlined requirements. Further manual testing is pending before finalizing the PR.