Skip to content

fix undo/redo interactions in agent host - #320650

Merged
Justin Chen (justschen) merged 1 commit into
mainfrom
justin/comfey
Jun 9, 2026
Merged

Justin Chen (justschen) merged 1 commit into
mainfrom
justin/comfey

Conversation

@justschen

Copy link
Copy Markdown
Collaborator

Fix window crash when redoing agent-host checkpoints

Problem: Clicking Redo after restoring a checkpoint in an agent-host session crashed the window.

AgentHostSnapshotController.redoInteraction() was a no-op, but the Redo action drains in a loop:

while (editingSession.canRedo.get()) {
    await editingSession.redoInteraction();
}

Since canRedo is derived from the checkpoint cursor and the no-op never advanced it, the loop spun forever on the main thread → hang/crash. It only reproduced after a restore/undo, since that's the only time canRedo is true.

Fix: Implement undoInteraction() / redoInteraction() to move the checkpoint cursor one step, sharing a new _navigateToCheckpointIndex() helper that restoreSnapshot() also uses. Each redo advances the cursor monotonically toward HEAD, so canRedo is guaranteed to flip false and the loop terminates.

Tests: Added two unit tests — single-step undo, and redo draining that stops at HEAD (regression guard for the infinite loop).

Copilot AI review requested due to automatic review settings June 9, 2026 18:58

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.

Pull request overview

Fixes a hang/crash in agent-host chat sessions when users click Redo after restoring a checkpoint by implementing real per-checkpoint undo/redo navigation in AgentHostSnapshotController, ensuring the Redo drain loop always makes progress and terminates.

Changes:

  • Implement undoInteraction() and redoInteraction() to move the checkpoint cursor by one step per invocation.
  • Factor shared cursor/file-state movement into a new _navigateToCheckpointIndex() helper and reuse it from restoreSnapshot().
  • Add unit tests covering single-step undo and redo draining to HEAD (regression guard against infinite loops).
Show a summary per file
File Description
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostSnapshotController.ts Implements checkpoint cursor navigation for undo/redo and reuses shared navigation in restore logic to prevent redo drain infinite loops.
src/vs/workbench/contrib/chat/test/browser/agentHost/agentHostSnapshotController.test.ts Adds regression tests verifying stepwise undo and that redo draining reaches HEAD and terminates.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 0

@justschen
Justin Chen (justschen) marked this pull request as ready for review June 9, 2026 20:18
@justschen
Justin Chen (justschen) enabled auto-merge (squash) June 9, 2026 20:19
@justschen
Justin Chen (justschen) merged commit 2c39db7 into main Jun 9, 2026
26 checks passed
@justschen
Justin Chen (justschen) deleted the justin/comfey branch June 9, 2026 20:20
@vs-code-engineering vs-code-engineering Bot added this to the 1.125.0 milestone Jun 9, 2026
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Jul 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants