Skip to content

Launch skill: never take focus from the user on macOS - #350456

Draft
Sandeep Somavarapu (sandy081) wants to merge 1 commit into
mainfrom
sandy081/agents/launch-background-mode-fix
Draft

Sandeep Somavarapu (sandy081) wants to merge 1 commit into
mainfrom
sandy081/agents/launch-background-mode-fix

Conversation

@sandy081

Copy link
Copy Markdown
Member

On macOS, Code OSS instances that agents start with the launch skill took focus from the user for a few seconds: when the first window showed, on a window reload or workspace switch, and when the instance was stopped by killing its helper processes first. Electron's show(), focus() and app.focus({ steal }) all activate the app; only showInactive() doesn't.

Changes

  • New hidden, dev-only --inactive-window argument. isInactiveWindowMode requires the argument and !environmentMainService.isBuilt (isBuilt is !VSCODE_DEV), so built products ignore it. In this mode, windows:
    • are created hidden and shown with showInactive(), and focus requests never activate the app;
    • skip app.focus({ steal }) for second-instance launches;
    • keep GPU, tracing and browser views from activating the app;
    • close a renderer-gone window without a dialog, and only log an unresponsive one.
  • Launch skill:
    • launch.sh passes --inactive-window by default (--foreground opts out);
    • a new check-activation.sh reports any activation from the macOS log in the launch JSON (activated, activations), and warns on stderr. It reports only, and never hides the window;
    • a new cleanup/cleanup.sh stops the main process first, so a dead renderer can't reopen its window in front;
    • SKILL.md documents both scripts. launch.ps1 is unchanged.

How to test

  • ./scripts/test.sh --run src/vs/platform/windows/test/electron-main/windowImpl.test.ts (new suite "BaseWindow - inactive window mode"): passed, 29 tests.
  • ./scripts/test.sh --run src/vs/platform/environment/test/node/argv.test.ts: passed, 9 tests.
  • pnpm run typecheck-client: passed. pnpm run oxlint on the changed TypeScript files: passed.
  • Live on macOS, 10 sequential runs, 5 with --skip-prelaunch and 5 without. Each run launched, opened a second workspace with --reuse-window, reloaded the window over CDP, then stopped with cleanup.sh. The macOS log recorded no activations (SETFRONT events), and 0 of about 850 lsappinfo front polls found Code - OSS in front.

Written by GitHub Copilot on behalf of Sandeep Somavarapu (@sandy081)

Add a dev-only `--inactive-window` flag (ignored by built VS Code) that shows
windows without activating the app and turns app-initiated focus requests
(window open and reload, second instance, crash dialog) into inactive shows.
The launch skill passes it by default, reports whether the instance activated,
and a new cleanup.sh stops the main process first and reports activations over
the whole lifetime of the instance.

Co-authored-by: Copilot <[email protected]>
@sandy081 Sandeep Somavarapu (sandy081) added this to the 1.149.0 milestone Nov 25, 2026
Copilot AI balanced review requested due to automatic review settings November 25, 2026 21:24

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

Inactive restoration can still steal focus for maximized or fullscreen windows, and combining inactive mode with hidden mode can unexpectedly reveal a window.

2 open issues
What changed in this PR

This PR adds a development-only inactive-window mode to keep agent-launched Code OSS instances from taking focus, with macOS activation reporting and safer cleanup.

Changes:

  • Adds --inactive-window and guards window display, focus, and error-handling paths.
  • Enables inactive launches by default in the Bash launcher and adds activation-checking and cleanup helpers.
  • Documents the workflow and adds inactive-window unit tests.
File Description
src/​vs/​platform/​windows/​test/​electron-main/​windowImpl.test.ts Tests inactive-mode gating, display, and focus behavior.
src/​vs/​platform/​windows/​electron-main/​windows.ts Defines inactive mode and creates its windows hidden.
src/​vs/​platform/​windows/​electron-main/​windowImpl.ts Adjusts restoration, focus, and renderer-error handling.
src/​vs/​platform/​native/​electron-main/​nativeHostMainService.ts Guards native focus and diagnostic-window display.
src/​vs/​platform/​launch/​electron-main/​launchMainService.ts Skips app activation for second-instance launches.
src/​vs/​platform/​environment/​node/​argv.ts Registers the hidden command-line flag.
src/​vs/​platform/​environment/​common/​argv.ts Adds the parsed argument type.
src/​vs/​platform/​browserView/​electron-main/​browserViewMainService.ts Prevents forced browser-view focus in inactive mode.
.agents/​skills/​launch/​SKILL.md Documents inactive launches, activation reporting, and cleanup.
.agents/​skills/​launch/​scripts/​launch.sh Enables inactive mode and records launch metadata.
.agents/​skills/​launch/​scripts/​cleanup/​cleanup.sh Stops the main process first and removes the temporary profile.
.agents/​skills/​launch/​scripts/​check-activation.sh Reports macOS activation events from the system log.

Review effort: Balanced

Comment on lines +376 to +377
if (isInactiveWindowMode(this.environmentMainService)) {
this._win?.showInactive();
this._win?.showInactive(); // a window that is about to be minimized must not take focus
}
this._win?.minimize();
} else if (isInactiveWindowMode(this.environmentMainService) && this._win && !this._win.isVisible()) {

This branch has not been deployed

No deployments
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.

2 participants