Skip to content

Fix quit and macOS last-window lifecycle#144

Merged
kostyafarber merged 2 commits into
mainfrom
agent/prevent-quit-port-deadlock
Jul 11, 2026
Merged

Fix quit and macOS last-window lifecycle#144
kostyafarber merged 2 commits into
mainfrom
agent/prevent-quit-port-deadlock

Conversation

@kostyafarber

@kostyafarber kostyafarber commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • reject in-flight channel calls when the remote endpoint closes
  • send an explicit close envelope for DOM MessagePort clients, which do not expose a native remote-close event
  • observe native Electron, utility-process, and Node port closure in their transport adapters
  • disconnect the renderer document lane when its workspace utility process exits
  • cover orderly server shutdown and raw remote disconnects with real MessageChannel tests
  • keep the macOS app process alive after its last window closes and reopen the launcher on Dock activation

Root cause

The quit guard asks the renderer for settled document state, which serializes behind pending workspace edits. When a workspace sync port was replaced or lost, the channel kept its request promise pending because only explicit local disposal rejected calls. AppLifecycle therefore remained in confirming, and subsequent quit attempts were ignored as an already-running guard.

This is a follow-up to #87, which introduced the dirty-document close guard and requires fast close after an edit to settle safely.

Impact

Workspace or renderer port teardown now becomes an observable channel failure. Close and quit flows can recover or fail instead of waiting indefinitely, and DocumentClient.connected no longer reports a remotely closed lane as live. Closing all windows on macOS now preserves the normal document-app lifecycle without changing Windows or Linux quit behavior.

Validation

  • pnpm --filter @shift/desktop test (44 files, 500 tests)
  • pnpm --filter @shift/desktop typecheck
  • pnpm --filter @shift/desktop lint:check
  • pnpm format:check
  • commit hooks: oxfmt, oxlint, tsgo typecheck, deadcode strict, Vitest

python3 scripts/context-drift-check.py still reports 22 pre-existing repository documentation errors unrelated to this change.

@kostyafarber kostyafarber changed the title Prevent quit deadlocks after port closure Fix quit and macOS last-window lifecycle Jul 11, 2026
@kostyafarber kostyafarber marked this pull request as ready for review July 11, 2026 15:57
@kostyafarber kostyafarber merged commit 88cf09e into main Jul 11, 2026
10 checks passed
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.

1 participant