Skip to content

Fix terminal split layout restoration for agent sessions - #335620

Open
KAVYANSH KUMAR (kavyansh18) wants to merge 4 commits into
microsoft:mainfrom
kavyansh18:fix/restore-agent-terminal-layout
Open

Fix terminal split layout restoration for agent sessions#335620
KAVYANSH KUMAR (kavyansh18) wants to merge 4 commits into
microsoft:mainfrom
kavyansh18:fix/restore-agent-terminal-layout

Conversation

@kavyansh18

Copy link
Copy Markdown

Description

Fixes #335252

When switching between Agent sessions, terminal instances were restored but their split layout was lost.

This change:

  • Preserves the parent/child relationship between split terminals when switching sessions.
  • Restores terminals in the correct order so split groups are recreated properly.
  • Falls back to a standalone terminal if the parent terminal is no longer available.
  • Adds tests for split layout restoration and the fallback case.

Testing

  • npm run -s precommit
  • ./scripts/test.sh --grep "SessionsTerminalContribution"
  • git diff --check

Copilot AI balanced review requested due to automatic review settings September 11, 2026 04:14
@vs-code-engineering

vs-code-engineering Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

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

Anthony Kim (@anthonykim1)

Matched files:

  • src/vs/workbench/contrib/terminal/browser/terminal.ts
  • src/vs/workbench/contrib/terminal/browser/terminalService.ts
  • src/vs/workbench/contrib/terminal/test/browser/terminalService.test.ts

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

Asynchronous terminal creation can associate one terminal with multiple sessions, and the production restoration path lacks direct coverage.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Preserves split-terminal grouping when switching between Agent sessions.

Changes:

  • Captures parent relationships before backgrounding terminals.
  • Restores parents before child terminals, with standalone fallback.
  • Adds regression tests for restoration and fallback behavior.
File summaries
File Description
terminalService.ts Rejoins restored terminals to parent groups.
terminal.ts Exposes parent-aware group insertion.
sessionsTerminalContribution.ts Captures and orders split relationships.
sessionsTerminalContribution.test.ts Tests grouping and missing-parent fallback.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/vs/sessions/contrib/terminal/browser/sessionsTerminalContribution.ts Outdated
Comment thread src/vs/workbench/contrib/terminal/browser/terminalService.ts

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

Mixed session-owned and standalone split groups can still lose their layout, and restoration ordering lacks effective coverage.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

src/vs/sessions/contrib/terminal/browser/sessionsTerminalContribution.ts:683

  • The regression test backgrounds t1 before t2 and the mock enumerates terminals in creation order, so toShow is already parent-first; the test still passes if this entire sort is removed. Add a child-before-parent (or three-level split) case and assert showBackgroundCalls order so the ordering logic described here is actually exercised.
  • Files reviewed: 5/5 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread src/vs/sessions/contrib/terminal/browser/sessionsTerminalContribution.ts Outdated

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

The Show All Terminals path bypasses the new ordered restoration and can still lose split grouping or order.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread src/vs/sessions/contrib/terminal/browser/sessionsTerminalContribution.ts Outdated

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.

🟢 Approval recommended

The behavior is focused and well-tested; only a minor documentation-style issue remains.

Review details

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

src/vs/sessions/contrib/terminal/browser/sessionsTerminalContribution.ts:846

  • This four-line JSDoc exceeds the project's 1–2 sentence limit and narrates private implementation details. Please reduce it to a concise contract statement.
  • Files reviewed: 5/5 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Side-by-side terminal layout is not restored when switching Agent sessions

3 participants