Skip to content

Be less aggressive about removing terminal in agents app#312873

Merged
anthonykim1 merged 2 commits intomainfrom
anthonykim1/fixTerminalAutoClose
Apr 27, 2026
Merged

Be less aggressive about removing terminal in agents app#312873
anthonykim1 merged 2 commits intomainfrom
anthonykim1/fixTerminalAutoClose

Conversation

@anthonykim1
Copy link
Copy Markdown
Contributor

@anthonykim1 anthonykim1 commented Apr 27, 2026

Resolves: #312872

Screen.Recording.2026-04-27.at.11.58.35.AM.mov

/cc @TylerLeonhardt

Agents app code has this logic where terminals are forced to close in conditions like archiving/changing sessions based on cwd. Removal was based on cwd, but also cwd was used to share terminal for multiple session which doesn't make sense to me..

I think it's fair to not have such removal, or figure out better way to associate particular session with particular terminal?

Even for associating particular session with particular terminal, user always has to freedom to cd in/out of particular directory so labeling a terminal to a particular session seems to aggressive.

@anthonykim1 anthonykim1 added this to the 1.119.0 milestone Apr 27, 2026
@anthonykim1 anthonykim1 self-assigned this Apr 27, 2026
Copilot AI review requested due to automatic review settings April 27, 2026 18:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adjusts terminal lifecycle management in the Agents (sessions) window so terminals aren’t aggressively closed when a session is replaced/archived but another live session still shares the same working directory (fixing the “terminal auto-closes when first opened” behavior reported in #312872).

Changes:

  • Update terminal cleanup logic to only close terminals for archived/removed sessions when no other live session still owns the same cwd.
  • Add regression tests covering session replacement, shared-cwd archiving, and removal behavior.
  • Extend test session factory to support custom sessionIds for replacement scenarios.
Show a summary per file
File Description
src/vs/sessions/contrib/terminal/browser/sessionsTerminalContribution.ts Changes terminal cleanup to be cwd-ownership-aware using current live sessions.
src/vs/sessions/contrib/terminal/test/browser/sessionsTerminalContribution.test.ts Adds tests for replace/shared-cwd/archive/remove scenarios; enhances test session creation with sessionId.

Copilot's findings

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

Co-authored-by: Copilot <copilot@github.com>
@meganrogge
Copy link
Copy Markdown
Collaborator

@anthonykim1 what are the repro steps here? Does it always happen?

@anthonykim1
Copy link
Copy Markdown
Contributor Author

anthonykim1 commented Apr 27, 2026

@meganrogge
I couldn't get consistent repros but when I was able to once or twice it's when I had claude and copilot cli sessions on my agents app and I tried to launch the "first" terminal in the agents app.

On the buggy scenario that terminal would close immediately.

Seen @TylerLeonhardt repro and I believe he also had cli and claude sessions open in agents app and tried to spawn first terminal. Edit: couldnt constant repro either.

Like in the TODO, Long term we should have better association of terminal with session or remove closing terminal.

@anthonykim1 anthonykim1 marked this pull request as ready for review April 27, 2026 20:28

this._register(this._sessionsManagementService.onDidChangeSessions(e => {
for (const session of [...e.removed, ...e.changed.filter(s => s.isArchived.get())]) {
const archivedChanged = e.changed.filter(s => s.isArchived.get());
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed, this seems like a good stop gap solution, but the initial implementation should have been better here - using IDs and a map to keep track of session terminals. cwd is not good enough as this bug proves.

Since Ben S is out, we should fix it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created follow up issue: #312909

@anthonykim1 anthonykim1 merged commit c2235ee into main Apr 27, 2026
25 checks passed
@anthonykim1 anthonykim1 deleted the anthonykim1/fixTerminalAutoClose branch April 27, 2026 21:12
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.

agents app auto-closes terminal when first opened

4 participants