Skip to content

Agents - implement discard changes for Session Changes - #342260

Merged
Ladislau Szomoru (lszomoru) merged 3 commits into
mainfrom
lszomoru/agents/session-changes-discard-phase2-implementation
Oct 17, 2026
Merged

Ladislau Szomoru (lszomoru) merged 3 commits into
mainfrom
lszomoru/agents/session-changes-discard-phase2-implementation

Conversation

@lszomoru

Copy link
Copy Markdown
Member

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:

    • Steps and rows are now processed using readFileEditRevertSteps, with a single prepare() and write operation for efficiency.
    • Introduced transaction handling similar to Last Turn, with checks to ensure no active turns are present before applying changes.
    • Added guards to validate file states, including checks for renamed files and files edited by multiple chats.
    • Extended the Git-state exemption to Session changesets, allowing discard operations without requiring Git.
  • 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.

…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]>
Copilot AI balanced review requested due to automatic review settings October 17, 2026 10:37

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

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]>
@lszomoru
Ladislau Szomoru (lszomoru) marked this pull request as ready for review October 17, 2026 15:33
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.

4 participants