Skip to content

fix(app): bound the wake/quit paths implicated in the phone-session-ended freeze (#9447) - #9853

Merged
brennanb2025 merged 21 commits into
mainfrom
brennanb2025/bug-macos-app-freezes-on-the-phone-session-ended
Jul 24, 2026
Merged

brennanb2025 merged 21 commits into
mainfrom
brennanb2025/bug-macos-app-freezes-on-the-phone-session-ended

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Bounds every wait and handshake reachable from #9447: macOS could wake onto the phone-session-ended restore modal with a frozen renderer, restore actions that never settled, and a quit path that never reached teardown.

What changed

  1. Window close handshake: 10s renderer acknowledgement deadline. Electron does not emit will-quit until renderer-backed windows close. Each app-wide close request now carries a per-window identity token, and preload acknowledges that exact request immediately. Responsive renderers retain dirty-file prompts and synchronous checkpoint behavior; stale acknowledgements from earlier or duplicate close attempts cannot disarm the active deadline; and an already-unresponsive renderer is destroyed after 10s so normal main-process cleanup can proceed. Ordinary window closes are unchanged.
  2. Relay shutdown: 5s physical-close deadline with complete cleanup. CloudRelayTransport.stop() installs close waiters before terminate(), handles synchronous close, and finalizes connection metadata/callback ownership on timeout. Expired attach handshakes now release that ownership immediately even when a half-open socket never emits close, so stale connection IDs and listeners cannot survive until origin shutdown.
  3. Quit teardown: 20s aggregate deadline with diagnostics. The deadline now clears on fast settlement and reports exactly which named teardown was still pending before continuing through telemetry and app.quit().
  4. Terminal restore: one shared 15s action budget. Local and remote restores are both bounded at the UI boundary. Restore-all keeps at most 8 calls in flight and stops launching more work when the shared deadline expires, so 100 dead PTYs take 15s and 8 calls rather than roughly 195s and 100 calls. Local retries for the same PTY reuse the in-flight reclaim instead of accumulating duplicate layout waiters after the UI timeout.

The branch also contains the merged #9847 wake-reconnect coalescing fix from main, which removes the independently confirmed renderer freeze caused by staggered reconnect refresh storms.

Reliability contract

  • Invariant: window.quit.bounded-exit — app-wide quit cannot wait forever before or during will-quit; a responsive renderer still owns save/checkpoint decisions.
  • Invariant: terminal-geometry.visible-convergence — explicit phone-to-desktop restore either converges or returns control within one 15s action budget, with no unbounded provider fanout.
  • Invariant: mobile-relay.cleanup — stopped or attach-expired relay sockets release connection identity and close callbacks even when the OS never supplies a close event.
  • Failure source: [Bug]: macOS app freezes on the "phone session ended" resize modal after waking from sleep, and can't be quit except via Force Quit #9447 on macOS 26.5.1 / Orca 1.4.138-rc.7 after sleep during a phone-driven session.
  • Oracle: deterministic fake-time tests prove 10s unresponsive-renderer destruction, acknowledgement preservation plus stale/foreign acknowledgement rejection, 5s relay cleanup and synchronous-close ordering, attach-expiry cleanup without a native close event, named 20s teardown escape, single and bulk 15s restore bounds, an exact 8-call cap for 100 wedged PTYs, and one runtime reclaim for concurrent same-PTY retries while different PTYs remain parallel. Packaged Electron tests prove the visible restore-this, restore-all, non-focused, and hidden-workspace journeys.
  • Gate: existing experimental terminal-geometry.visible-convergence gate passed. Window-quit acknowledgement and relay-stop timeout have deterministic unit coverage here; no matching manifest gate exists yet, so promotion/soak history remains an accepted gap.
  • Provider/platform coverage: local and daemon restore are covered; remote-runtime timeout and SSH geometry are covered; WSL is unaffected because no path or provider selection changed; mobile/relay cleanup is covered. Logic is platform-neutral, with packaged macOS Electron evidence and existing Windows crash-survival CI.
  • Performance budget: no idle polling, scans, subprocesses, or renderer render work were added. Quit allocates one timer and one acknowledgement IPC only after explicit app-wide quit. Restore-all is capped at 8 in flight and 15s total; repeated local retries reuse one in-flight reclaim per PTY. Relay timeout cleanup releases maps/listeners instead of retaining dead sockets.
  • Diagnostics: quit logs the unacknowledged renderer fallback and named pending teardowns; relay close continues through the existing connection-close callbacks.

Verification

  • pnpm run typecheck — passed.
  • Focused wake/quit/relay/restore and neighboring ownership suites — 236 passed, 2 skipped.
  • Experimental terminal-geometry.visible-convergence gate — 1,393 tests passed.
  • Terminal geometry plus local/daemon/SSH/remote/mobile reliability sweep — 1,474 passed, 2 skipped.
  • Packaged Electron mobile-banner.spec.ts — 5 passed, including hidden-workspace restore-all.
  • oxfmt --check, touched-file oxlint, max-lines ratchet, and reliability manifest validation — passed.
  • Full pnpm test under the locally installed, unsupported Node 26 completed with 34,692 passed, 46 unrelated environment-sensitive failures, and 58 skipped (primarily unavailable localStorage, subprocess timeouts, and inherited process-environment contamination); focused and reliability gates were green.
  • Full pnpm run lint passes oxlint, switch exhaustiveness, reliability, max-lines, and bundled-skill checks, then reaches unrelated localization keys missing from en.json on current main. Touched-file lint and format checks pass.

Residual gap

The exact real-sleep renderer freeze trigger from 1.4.138-rc.7 was not reproduced in three paired iOS-simulator runs. Current main now includes #9847 for the proven wake reconnect freeze, while this PR makes restore and quit bounded if another renderer or transport stall remains. Reporter retest on the resulting build is still required before claiming the original hardware-specific trigger is fully reproduced.

Fixes #9447.

ELI5

Think of the app as several people waiting for answers after the Mac wakes up: the phone connection, terminal resize, window, and quit cleanup. Before this change, one part that never answered could make everyone wait forever, leaving the app frozen and Cmd+Q stuck. Now each wait has a reasonable deadline, stale connections are cleaned up, and wake-up reconnect requests are grouped so they cannot overwhelm the UI. Responsive sessions still follow the normal save and shutdown flow; this only provides an escape when something is genuinely stuck.

…nded freeze (#9447)

- relay-transport: waitForClose now times out (5s) so a half-open post-sleep
  socket can't wedge runtimeRpc.stop()
- will-quit: race teardown against a 20s deadline so app.quit() always runs
  (Force Quit was the only escape when any teardown member never settled)
- terminal-fit-restore: local restoreTerminalFit invoke gets the same 15s
  bound as the remote path so the held-fit modal buttons can't pin disabled
@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds bounded timeout handling for relay socket closure, application quit teardown, renderer quit acknowledgement, and terminal fit restoration. Main-process shutdown races teardown completion against a fixed deadline. Relay transport shutdown resolves when sockets close or time out. Renderer close requests receive acknowledgement before a bounded force-destroy fallback. Local and remote terminal restoration share a deadline, including bulk restores. Concurrent terminal restore IPC requests are deduplicated by PTY. Tests cover settled and hanging operations with fake timers.

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The skill manifest/version file updates are unrelated to #9447 and appear to be separate release bookkeeping. Move the manifest/version churn into a separate PR unless it is required for this fix.
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning It has useful content, but it does not follow the required template sections or include Screenshots, Testing, AI Review Report, Security Audit, and Notes. Reformat the description to match the template and add the missing required sections, especially Screenshots, Testing checklist, AI Review Report, Security Audit, and Notes.
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes bound the restore and quit paths that were freezing #9447, matching the issue's requirements.
Title check ✅ Passed The title clearly summarizes the main change: bounding wake/quit paths for the phone-session-ended freeze.

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.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8899809a-fab4-48a0-ad56-6f12cb4908e5

📥 Commits

Reviewing files that changed from the base of the PR and between b0e86c7 and 4fc1ec7.

📒 Files selected for processing (11)
  • src/main/index.ts
  • src/main/quit-teardown-deadline.test.ts
  • src/main/quit-teardown-deadline.ts
  • src/main/runtime/rpc/relay-transport.test.ts
  • src/main/runtime/rpc/relay-transport.ts
  • src/main/window/createMainWindow.test.ts
  • src/main/window/createMainWindow.ts
  • src/main/window/window-close-decision.ts
  • src/preload/index.ts
  • src/renderer/src/components/terminal-pane/terminal-fit-restore.test.ts
  • src/renderer/src/components/terminal-pane/terminal-fit-restore.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/main/quit-teardown-deadline.test.ts
  • src/main/index.ts
  • src/renderer/src/components/terminal-pane/terminal-fit-restore.ts

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8e50a73c-0d07-4714-b2fb-ba2c48859ade

📥 Commits

Reviewing files that changed from the base of the PR and between f9af7b0 and 6896f2e.

📒 Files selected for processing (4)
  • src/main/ipc/runtime.test.ts
  • src/main/ipc/runtime.ts
  • src/main/runtime/rpc/relay-transport.test.ts
  • src/main/runtime/rpc/relay-transport.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/runtime/rpc/relay-transport.ts

Comment thread src/main/ipc/runtime.ts Resolved
…s-app-freezes-on-the-phone-session-ended

# Conflicts:
#	src/main/ipc/worktree-common-git-directory.ts
#	src/main/skills/skill-installation-topology.ts
…s-app-freezes-on-the-phone-session-ended

# Conflicts:
#	resources/skills/release-mapping.json
…s-app-freezes-on-the-phone-session-ended

# Conflicts:
#	src/main/runtime/relay/relay-control-origin.ts
#	src/main/runtime/relay/relay-session-broker.test.ts
#	src/main/runtime/rpc/mobile-socket-wiring.ts
#	src/main/runtime/rpc/relay-transport.ts
@brennanb2025
brennanb2025 merged commit bded1fb into main Jul 24, 2026
4 checks passed
nwparker added a commit that referenced this pull request Jul 24, 2026
This reverts commit 8f40ddf (#10179).

Rebased on current main. The revert applied cleanly across the vast majority
of the 1,626-file PR; the remaining work was preserving PRs that had been built
on top of #10179 after it merged. All are preserved:

- #9990  perf(terminal): cold-restore replay
- #10213 fix(codex): TUI settings promotion
- #10135 fix(mobile): images in native chat
- #9387  fix(status-bar): Resource Manager badge + concurrent listSessions
- #9853  fix(app): bound wake/quit paths (phone-session-ended freeze)
- #10237 fix(claude-accounts): quote claude path for Windows (kept shell:false)

Because those PRs were written against helper modules/APIs that #10179
introduced, the minimal, typecheck-verified closure they depend on is kept so
the tree builds and every later-PR test passes:

- bounded file/JSON readers used by #10213/#9990 (agent-state-file-reader,
  node-bounded-file-reader, json-text-structure-limit, terminal-history limits)
- claimed-agent-pty-owner cap API + pty:listSessions admission (#9990/#9387)
- the mobile-E2EE outbound-memory-budget subsystem #9853 builds on
  (e2ee-channel, mobile-e2ee-*, ws-outbound-backpressure-queue,
  remote-runtime-request-frames/-memory-limits, map-with-concurrency, e2ee-crypto)

Everything else #10179 added (~555 files) is deleted; every file it modified
elsewhere is restored to its pre-#10179 state.

Verified: root typecheck (node+cli+web), mobile typecheck, full root test suite,
full mobile test suite, oxlint, localization catalog + coverage, reliability
gates, max-lines ratchet, and the CLI emit build all pass. Two checks fail only
locally and fail identically on clean origin/main (this clone's git-tag
namespace for verify:skill-bundle-manifest; an inherited GIT_CONFIG_* env for
one relay test) — both pass on a clean CI environment.

Co-authored-by: Orca <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…nded freeze (stablyai#9447) (stablyai#9853)

* fix(app): bound the wake/quit paths implicated in the phone-session-ended freeze (stablyai#9447)

- relay-transport: waitForClose now times out (5s) so a half-open post-sleep
  socket can't wedge runtimeRpc.stop()
- will-quit: race teardown against a 20s deadline so app.quit() always runs
  (Force Quit was the only escape when any teardown member never settled)
- terminal-fit-restore: local restoreTerminalFit invoke gets the same 15s
  bound as the remote path so the held-fit modal buttons can't pin disabled

* fix(app): close wake recovery timeout gaps

* fix(relay): drop late frames after forced teardown

* fix(relay): fence detached socket callbacks

* fix(app): close timeout resource gaps

* fix(relay): detach retired mobile transports

* fix(types): exclude absent stat overloads

* fix(runtime): expire wedged terminal restore dedupe

* fix(runtime): keep restore retries on one reclaim

* chore(skills): refresh bundled skill manifests

* fix(window): fence quit acknowledgements by request

* fix(relay): bound revoked device socket cleanup
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.

[Bug]: macOS app freezes on the "phone session ended" resize modal after waking from sleep, and can't be quit except via Force Quit

1 participant