terminal.integrated.hideOnStartup: "always" shows, hides, then re-shows the terminal panel when a workspace with a folderOpen task is reopened while VS Code is frontmost
- Dominant language
- TypeScript
- Stars
- 193k
- Forks
- 42.4k
- PR merge metrics
- PR metrics pending
Description
Does this issue occur when all extensions are disabled?: Yes
- VS Code Version: 1.135.0 (08d4889f9ec4a1685d257b9b95de036c8e1ce1e5)
- OS Version: macOS 14.6.1 (23G93)
With `terminal.integrated.hideOnStartup` set to `always` and a `folderOpen` task that reveals a terminal, reopening the workspace while VS Code is already the frontmost application shows the terminal panel, hides it, then shows it again with the task's terminal.
Steps to Reproduce:
1. Create `repro/folder/` and `repro/repro.code-workspace` with:
```json
{
"folders": [{ "path": "folder" }],
"settings": { "terminal.integrated.hideOnStartup": "always" },
"tasks": {
"version": "2.0.0",
"tasks": [
{
"label": "Agent",
"type": "shell",
"command": "sleep 600",
"runOptions": { "runOn": "folderOpen" },
"presentation": { "reveal": "always", "panel": "dedicated" }
}
]
}
}
```
2. `code --disable-extensions repro/repro.code-workspace` and allow automatic tasks. The task's terminal appears in the panel.
3. Close that window while the panel is showing.
4. With another VS Code window frontmost, run the same `code` command again. From an integrated terminal in that window is the easy way; `sleep 4; code ...` from an outside terminal and then clicking into VS Code before it fires also works.
Actual: the panel appears, disappears about half a second later, then appears again with the task's terminal.
Expected: the panel is hidden until the task reveals it, with no intermediate show and hide. The setting's description is "Whether to hide the terminal view on startup, avoiding creating a terminal when there are no persistent sessions", and `always` is documented as "Always hide the terminal, even when there are persistent sessions restored".
Narrowing:
- Without the task (settings only), there is no flash.
- Running the same `code` command from an outside terminal (kitty) while VS Code is running but not frontmost, there is no flash. The same command from kitty with a VS Code window frontmost flashes. Which binary runs and the environment make no difference: `which code` is the same in both terminals, and `env -i PATH="$PATH" HOME="$HOME" code ...` from an integrated terminal still flashes.
- Extensions on or off makes no difference.
A guess at the cause, reading `main` at df814e65a7: `TerminalViewPane._initializeTerminal` (`src/vs/workbench/contrib/terminal/browser/terminalView.ts`) applies the hide. It runs only once `this._terminalService.connectionState === TerminalConnectionState.Connected`, so a view restored visible stays visible until the pty host connection is established:
```ts
let hideOnStartup: 'never' | 'whenEmpty' | 'always' = 'never';
if (!wasInitialized) {
hideOnStartup = this._configurationService.getValue(TerminalSettingId.HideOnStartup);
if (hideOnStartup === 'always') {
this._terminalGroupService.hidePanel();
}
}
```
The hide also runs before `shouldCreate` checks whether terminals already exist, so when the `folderOpen` task has created and revealed its terminal first, the hide closes the panel over it and the task's `reveal` opens it again. Frontmost matters, I assume, because when VS Code has to be activated first the new window's first paint comes late enough for the pty host connection and the hide to land before it; when VS Code is already frontmost the window paints at once and the hide is visible.
Context: `always` is the workaround for #142796 (a `folderOpen` task getting an extra empty terminal when the panel was visible at close), so the flash occurs on every open of such a workspace from within VS Code.
Contributor guide
Assessment
This issue has not been assessed yet.