Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(desktop): keep preview automation alive on macOS close #6317

Closedproxynico(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/6317/headopened View on GitHub

Problem

On macOS, closing T3 Code's last window destroys the renderer while the desktop server remains running. PreviewAutomationHosts lives in that renderer, so MCP preview requests then fail with no available preview automation host until the app is activated again.

Fix

  • Treat an ordinary macOS main-window close as hide, preserving the renderer and its preview automation streams.
  • Allow the native close to proceed once DesktopState.quitting is set, preserving Quit, updater, signal, and relaunch shutdown paths.
  • Keep non-macOS behavior unchanged.

Proof

  • vp test run apps/desktop/src/window/DesktopWindow.test.ts — 25 passed
  • vp run --filter @t3tools/desktop typecheck — passed; two unrelated existing suggestions remain
  • vp lint --report-unused-disable-directives apps/desktop/src/window/DesktopWindow.ts apps/desktop/src/window/DesktopWindow.test.ts — passed
  • git diff --check — passed
  • Mutation checks proved each new regression test fails when its protected branch is broken.
  • Independent review found no Critical or Important issues.

Risk and visual changes

Low lifecycle risk, limited to macOS main-window close handling. The window still disappears immediately, so there is no visual change. A genuine application Quit still destroys the window and completes shutdown.

Known limitation: this is covered by focused desktop lifecycle tests; it does not add a packaged Electron integration test.

Implemented with GPT-5.6-sol through the Codex harness in T3 Code.


Note

Medium Risk Touches macOS main-window close lifecycle and depends on the quitting flag to still allow real shutdown. Incorrect gating could leave a hidden window or block Quit/updater paths.

Overview On macOS, closing the main window no longer destroys the renderer. The close handler now hides the window (via preventDefault) unless DesktopState.quitting is set, so preview automation hosts in the renderer keep working while the desktop server is still running.

Genuine Quit / updater / relaunch shutdown still closes normally once quitting is true. Non-macOS close behavior is unchanged.

Adds regression tests for hide-on-close vs allow-close-during-quit, and wires DesktopState into the window layer/tests.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 15d4f0fbaff0dd5aa91e55fca851adf29af90fed. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Keep preview automation alive by hiding the main window on macOS close instead of quitting

  • On macOS, the close event handler in DesktopWindow.ts now calls event.preventDefault() and window.hide() instead of destroying the window, unless the app is in a quitting state.
  • Reads DesktopState.quitting via a synchronous Ref check to distinguish a user close from an actual quit.
  • Behavioral Change: on macOS, closing the main window no longer terminates the app — it hides it. The window only closes during a full quit.
Macroscope summarized 15d4f0f.
    1. Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: 1e0bbd58-d12b-49c8-95d4-3f99235adc20

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot).

      Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.

      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 15d4f0fbaff0dd5aa91e55fca851adf29af90fed. Configure [here](https://www.cursor.com/dashboard/bugbot).
      @@ -549,4 +553,8 @@
      549553 window.on("move", scheduleBoundsPersist);
      550554 window.on("maximize", scheduleBoundsPersist);
      551555 window.on("unmaximize", scheduleBoundsPersist);
      552- window.on("close", () => {
      556+ window.on("close", (event) => {
      557+ if (environment.platform === "darwin" && !runSync(Ref.get(desktopState.quitting))) {
      558+ event.preventDefault();
      559+ window.hide();
      560+ }

      Fullscreen close hides to black

      Medium Severity

      On macOS, ordinary main-window close now calls preventDefault and hide without leaving fullscreen first. Hiding a native fullscreen BrowserWindow is a known Electron/AppKit failure mode that leaves a black screen instead of a clean hide, so closing from fullscreen can break the intended dismiss-and-restore flow.

      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 15d4f0fbaff0dd5aa91e55fca851adf29af90fed. Configure [here](https://www.cursor.com/dashboard/bugbot).
    4. Approvability

      Verdict: Needs human review

      This PR changes macOS window close behavior from actually closing to hiding the window, which is a significant runtime behavior change affecting user experience. The author is not a frequent contributor to this file, adding a small risk signal.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    5. juliusmarminge closed this

Sign in to join this conversation.