Repository navigation
fix(startup): hold desktop activations until the startup window exists - #22495
Conversation
A second-instance, open-url, or open-file activation that landed after app ready but before the startup window was created opened its own main window. The startup open then built a second window, threw on the duplicate 'window:isMaximized' handler, and aborted runtime launch: no runtime RPC, no orca-runtime.json, an orphan hidden window holding the trusted-renderer id, and the visible window refused trusted IPC. The desktop activation gate now starts 'initializing' for every launch mode. The startup window opener releases it once that window exists, so queued activations focus it, and a desktop launch that fails first releases it so later activations can still open a window. Serve mode keeps settling the gate after its RPC is ready.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Gate starts held for desktop launches too (
src/main/startup/main-process-preflight.ts:130-133) — the activation gate now begins'initializing'for every launch mode, so a second-instance / deep-link /open-file/ macOSactivatethat lands afterreadybut before the startup window exists queues instead of opening a duplicate main window. - Startup opener releases the gate (
src/main/startup/serve-desktop-activation.ts:30-45,src/main/startup/main-process-ready.ts:15-38) —releaseDesktopActivationAfterwrapsopenMainWindowand callsmarkReady()in afinally, so the queued activation replays against the now-existing window; the launch-phase.catchreleases the gate for desktop (not serve) so a failed launch does not swallow later activations. - Regression test (
src/main/startup/main-process-runtime-launch-activation.test.ts) — real gate, realfocusExistingMainWindow, and the real launch/ready phases, with a fake opener that reproduces the duplicatewindow:isMaximizedthrow, on darwin/linux/win32-packaged.
Both desktop open sites go through the wrapped opener, and state.mainWindow is assigned (main-window-controller.ts:185) before the opener returns, so the replay focuses rather than re-opens. I also ran the surrounding suites (main-process-runtime-launch-activation, main-process-ready-phase-ordering, desktop-startup-ordering, serve-desktop-activation-wiring, serve-desktop-activation, focus-existing-window, main-process-ready-identity-write, browser-process-user-agent-ordering) — 52 passed.
ℹ️ The new gate release covers the launch phase only
The .catch that releases the desktop gate wraps initializeMainProcessRuntimeLaunch, but the two awaits above it are outside it, so a rejection from initializeReadyFoundation / initializeReadyRuntimeServices leaves the gate 'initializing' and later activations are silently queued and never replayed. This is consistent with the PR's own disclosed trade-off and is not a functional regression in practice — the window cannot work without the store requireMainWindowServices needs — so no change is required; scoping the code comment to the launch phase would just make the guarantee it states precise.
Technical details
# Gate release is scoped to the launch phase
## Affected sites
- `src/main/startup/main-process-ready.ts:22-23` — `initializeReadyFoundation()` / `initializeReadyRuntimeServices()` are awaited outside the new `.catch` at lines 31-37.
- `src/main/startup/main-process-ready.ts:31-37` — releases the desktop gate on launch failure only.
- `src/main/startup/serve-desktop-activation.ts:58-68` — `requestActivation` only sets `pendingActivation` while `'initializing'`; nothing replays it without a `markReady()`.
## Notes
- `initializeReadyFoundation` throws on a missing dev identity (`main-process-ready-foundation.ts:94-96`) and can propagate from `ensureActiveOrcaProfile()` / `new Store(...)`; `initializeReadyRuntimeServices` throws when the store is absent (`main-process-ready-runtime.ts:43-45`).
- `src/main/index.ts:109-114` has no `.catch` on the ready chain and unhandled-rejection logging keeps the process alive, so the app can remain running with the gate held.
- Pre-PR the same failure still could not produce a usable window (`requireMainWindowServices` throws without store/runtime), so behaviour is equivalent in practice.ℹ️ Nitpicks
- The preflight initial gate state is pinned only by a source-text assertion (
main-process-runtime-launch-activation.test.ts:218-227); the behavioural cases build their own gate, so they would pass even if onlymain-process-preflight.tsregressed. releaseDesktopActivationAfterhas no direct unit test inserve-desktop-activation.test.ts; its behaviour is covered indirectly by the new launch test.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 📝 WalkthroughWalkthroughThe desktop activation gate now starts in the initializing state for all launch modes. The main-process startup flow wraps the main-window opener and marks the gate ready after the opener runs. If ready-phase initialization fails outside serve mode, the flow marks the gate ready and rethrows the error. Tests cover activation during install-directory repair, ready-phase failures, and the preflight gate state. Priority: ⬆️ High Merge Risk: 🟡 Moderate · up to A failed startup can consume a pending activation without opening a window and may obscure the original error. Prevent activation replay after failed initialization before merging. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to The change addresses a startup race that could leave the desktop app partly unusable. The normal startup path is covered by tests, but the behavior when window creation itself fails is not established well enough to rule out a lost activation or another inconsistent window state. Retained concerns
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description covers the change, rationale, testing, platform considerations, and review notes. However, the required Linked Issue section does not provide an issue reference and explicitly states that no separate issue was filed. The template requires an issue link for every pull request. Resolution Add the issue reference in the required
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 96cc6413-2db2-4a66-961e-e1165991f266
📒 Files selected for processing (4)
src/main/startup/main-process-preflight.tssrc/main/startup/main-process-ready.tssrc/main/startup/main-process-runtime-launch-activation.test.tssrc/main/startup/serve-desktop-activation.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
| initializeMainProcessRuntimeLaunch(options).catch((error: unknown) => { | ||
| // Why: a desktop launch that failed before its startup window must not swallow later activations. | ||
| if (!state.isServeMode) { | ||
| state.desktopActivationGate?.markReady() |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
# Inspect callers and their rejection handling; do not run repository code.
rg -n -C 8 --type ts '\binitializeMainProcessReady\s*\(' src/mainRepository: stablyai/orca
Length of output: 14196
🏁 Script executed:
#!/bin/bash
printf '%s\n' '--- src/main/startup/main-process-ready.ts ---'
cat -n src/main/startup/main-process-ready.ts
printf '%s\n' '--- src/main/index.ts caller ---'
sed -n '80,125p' src/main/index.ts
printf '%s\n' '--- quit and rejection handlers ---'
rg -n -C 6 --type ts 'installMainProcessQuitHandlers|unhandledRejection|uncaughtException|app\.quit|app\.exit|markReady|requestActivation|getState' src/main
printf '%s\n' '--- gate implementation ---'
cat -n src/main/startup/serve-desktop-activation.ts
printf '%s\n' '--- phase definitions ---'
cat -n src/main/startup/main-process-ready-foundation.ts
cat -n src/main/startup/main-process-ready-runtime.tsRepository: stablyai/orca
Length of output: 45525
🏁 Script executed:
#!/bin/bash
printf '%s\n' '--- ready implementation ---'
sed -n '1,80p' src/main/startup/main-process-ready.ts
printf '%s\n' '--- caller ---'
sed -n '95,120p' src/main/index.ts
printf '%s\n' '--- relevant handlers and gate operations ---'
rg -n -C 5 --type ts 'installMainProcessQuitHandlers|unhandledRejection|uncaughtException|app\.quit|app\.exit|markReady|requestActivation|getState' src/mainRepository: stablyai/orca
Length of output: 45543
🏁 Script executed:
#!/bin/bash
for log in /tmp/coderabbit-shell-logs/shell-output-MzCy4A /tmp/coderabbit-shell-logs/shell-output-tUnOtu; do
printf '%s\n' "--- $log markers ---"
rg -n -- '--- |^ [0-9]+ (export async function initializeMainProcessReady|void app\.whenReady|process\.on|app\.on|function installMainProcessQuitHandlers|export function installMainProcessQuitHandlers|markReady|requestActivation|getState)' "$log" | head -80
printf '%s\n' "--- $log beginning ---"
sed -n '1,180p' "$log"
doneRepository: stablyai/orca
Length of output: 25483
🏁 Script executed:
#!/bin/bash
printf '%s\n' '--- main-process rejection handlers ---'
rg -n -C 12 --glob '*.ts' --glob '!**/node_modules/**' '(process\.on\(\x27(unhandledRejection|uncaughtException)\x27|process\.on\("(unhandledRejection|uncaughtException)"|unhandledRejection|uncaughtException)' src/main/index.ts src/main/main-process* src/main/startup src/main/host src/main/configure-process.ts src/main
printf '%s\n' '--- deferred-secret-protection test ---'
sed -n '185,215p' src/main/host/deferred-secret-protection-report.test.tsRepository: stablyai/orca
Length of output: 41653
🏁 Script executed:
#!/bin/bash
rg -n -C 8 --type ts 'installUnhandledRejectionLogging' src/mainRepository: stablyai/orca
Length of output: 10084
Handle failures from the full ready phase.
initializeReadyFoundation() and initializeReadyRuntimeServices() run before the runtime-launch rejection handler. If either rejects, state.desktopActivationGate remains initializing. The main-process unhandled-rejection handler keeps the process alive, so queued activations cannot replay. Handle failure of the complete ready phase so the gate is released or launch is retried.
|
Seen again in the field on v1.4.210 (Windows 11 26200, Slack report). This was the first launch after the 1.4.207 → 1.4.210 auto-update:
What users see: after an update, Orca opens a window that looks fine but is only half started. The CLI and mobile can't connect, and trusted IPC is refused. The user's only way out was to kill Orca and start it again. A second open right after an update (the installer relaunching the app, plus a double-click) seems a likely trigger. Repro attempt on a Windows box (installed 1.4.207, not reproduced): I used an isolated profile (
|
|
Scan-24 field hit on v1.4.210: report 620d36ea. The launch logged both signatures ('Attempted to register a second handler for window:isMaximized' 37 s after main start, then 'skills:getUpdateRun: Unauthorized skill IPC sender'). The user killed renderer, network and GPU about 3.5 min later. There are no 1.4.211 hits yet this scan. |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: b8e8e9eb-582a-401b-8b8f-ce9167e094e6
📒 Files selected for processing (3)
src/main/startup/main-process-ready-activation-failure.test.tssrc/main/startup/main-process-ready.tssrc/main/startup/main-process-runtime-launch-activation.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
| function releaseDesktopActivationOnFailure(error: unknown): never { | ||
| // Keep later opens possible after a failed phase; serve promotion still fails closed. | ||
| if (!state.isServeMode) { | ||
| state.desktopActivationGate?.markReady() |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
set -euo pipefail
ast-grep outline src/main/startup/main-process-preflight.ts --view expanded
rg -n -C 12 'createServeDesktopActivationGate|activateWindow:|canOpenWindow|openWindow:|focusExistingMainWindow' \
src/main/startup/main-process-preflight.ts src/main/window/focus-existing-window.tsRepository: stablyai/orca
Length of output: 10221
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- changed ready-phase file ---'
cat -n src/main/startup/main-process-ready.ts
printf '%s\n' '--- activation gate implementation ---'
cat -n src/main/startup/serve-desktop-activation.ts
printf '%s\n' '--- preflight imports and callback binding ---'
sed -n '1,155p' src/main/startup/main-process-preflight.ts
printf '%s\n' '--- focus-existing-window definitions and callers ---'
ast-grep outline src/main/window/focus-existing-window.ts --view expanded
rg -n -C 10 'function focusExistingWindow|const focusExistingWindow|focusExistingWindow\\s*=|focusExistingMainWindow\\(' src/main
printf '%s\n' '--- relevant diff summary ---'
git diff --stat 15baf8666005f44de5679753c9f3ed61e78266ec d2e4dfe33543cc0e9973a4937b67abc359cd2602 -- src/main/startup/main-process-ready.ts src/main/startup/serve-desktop-activation.ts src/main/startup/main-process-preflight.ts src/main/window/focus-existing-window.tsRepository: stablyai/orca
Length of output: 14980
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- changed ready-phase file ---'
cat -n src/main/startup/main-process-ready.ts
printf '%s\n' '--- activation gate implementation ---'
cat -n src/main/startup/serve-desktop-activation.ts
printf '%s\n' '--- preflight imports and callback binding ---'
sed -n '1,155p' src/main/startup/main-process-preflight.ts
printf '%s\n' '--- focus-existing-window definitions and callers ---'
ast-grep outline src/main/window/focus-existing-window.ts --view expanded
rg -n -C 10 'function focusExistingWindow|const focusExistingWindow|focusExistingWindow\s*=|focusExistingMainWindow\(' src/main
printf '%s\n' '--- relevant diff summary ---'
git diff --stat 15baf8666005f44de5679753c9f3ed61e78266ec d2e4dfe33543cc0e9973a4937b67abc359cd2602 -- src/main/startup/main-process-ready.ts src/main/startup/serve-desktop-activation.ts src/main/startup/main-process-preflight.ts src/main/window/focus-existing-window.tsRepository: stablyai/orca
Length of output: 42099
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- ready-phase callers ---'
rg -n -C 14 'initializeMainProcessReady|initializeReadyFoundation|app\.whenReady|whenReady\(' src/main
printf '%s\n' '--- foundation implementation ---'
ast-grep outline src/main/startup/main-process-ready-foundation.ts --view expanded
cat -n src/main/startup/main-process-ready-foundation.ts
printf '%s\n' '--- main window opener ---'
rg -n -C 18 'function openMainWindow|openMainWindowController|export function openMainWindow' src/main/startup src/main/window src/main/index.ts
printf '%s\n' '--- process error handling around ready startup ---'
rg -n -C 18 'initializeMainProcessReady\(\\|mainProcessReady|catch.*startup|startup.*catch|app\.on\\(.+(ready|error)' src/mainRepository: stablyai/orca
Length of output: 42343
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- ready-phase callers ---'
rg -n -C 14 'initializeMainProcessReady|initializeReadyFoundation|app\.whenReady|whenReady\(' src/main
printf '%s\n' '--- foundation implementation ---'
ast-grep outline src/main/startup/main-process-ready-foundation.ts --view expanded
cat -n src/main/startup/main-process-ready-foundation.ts
printf '%s\n' '--- main window opener ---'
rg -n -C 18 'function openMainWindow|openMainWindowController|export function openMainWindow' src/main/startup src/main/window src/main/index.ts
printf '%s\n' '--- process error handling around ready startup ---'
rg -n -C 18 'initializeMainProcessReady\(|mainProcessReady|catch.*startup|startup.*catch|app\.on\(.+(ready|error)' src/mainRepository: stablyai/orca
Length of output: 45663
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- exact ready invocation ---'
sed -n '35,115p' src/main/index.ts
printf '%s\n' '--- main window service readiness ---'
cat -n src/main/startup/main-window-service-readiness.ts
printf '%s\n' '--- runtime services initializer ---'
cat -n src/main/startup/main-process-ready-runtime.ts
printf '%s\n' '--- window controller continuation ---'
sed -n '45,180p' src/main/startup/main-window-controller.tsRepository: stablyai/orca
Length of output: 20054
Fail closed after ready-phase initialization fails.
When foundation initialization fails, markReady() consumes the queued activation and calls focusExistingWindow(). If no window exists and the ACL guard does not block, openMainWindow() then throws because state.runtime was never initialized. The activation is lost, and this exception can replace the original startup error.
Suggested fix
- state.desktopActivationGate?.markReady()
+ state.desktopActivationGate?.markBlocked('desktop startup initialization failed')📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| state.desktopActivationGate?.markReady() | |
| state.desktopActivationGate?.markBlocked('desktop startup initialization failed') |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Prerequisite failures now release the desktop gate (
src/main/startup/main-process-ready.ts:22-23,35-41) —initializeReadyFoundationandinitializeReadyRuntimeServicesare wrapped in.catch(releaseDesktopActivationOnFailure), so a rejected prerequisite phase re-opens the gate for desktop instead of leaving it stuck'initializing'. Serve still fails closed. - One shared failure helper — the launch-phase
.catchbody was extracted intoreleaseDesktopActivationOnFailure, so foundation, runtime services, and launch all share the same release-then-rethrow policy for desktop only. - Failure-path regression tests (
src/main/startup/main-process-ready-activation-failure.test.ts, new) — covers desktop replay/acceptance after a foundation or runtime-services failure, serve staying held, and a menu failure that must not release the gate while window creation is still pending. - Ready-phase mocks return promises (
src/main/startup/main-process-runtime-launch-activation.test.ts) — the mocked foundation/runtime initializers now resolve so the new.catchruns.
I re-ran main-process-runtime-launch-activation, main-process-ready-activation-failure, main-process-ready-phase-ordering, and serve-desktop-activation (19 tests), plus the changed-code quality gate — all green. The new test file is behavioural: without the .catch, the desktop replay case would leave the gate 'initializing' and never call activateWindow, so it fails against the old code.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Failure now disables the startup-activation gate instead of releasing it (
src/main/startup/main-process-ready.ts:38-52) — the ready phase adopts main'stry/catchpersistence-cleanup shape and setsstate.desktopActivationGate = nullbefore awaitingstore.freezeWritesAsync()and releasingprofileStateAdmission. This matchesmain-process-preflight-failure.ts:12and main's fail-and-exit contract:index.ts:116-149catches the rejection, shows the recovery dialog, thenapp.exit(1)unconditionally for desktop and serve. - A throwing window opener no longer replays a queued activation (
src/main/startup/serve-desktop-activation.ts:34-43) —releaseDesktopActivationAfterdropstry/finallyfor a plain sequence, sogate.markReady()runs only afteropen(...)returns. A failed window creation is not followed by an activation that would try to open again. - Failure-path tests updated and extended —
main-process-ready-activation-failure.test.tsnow expects the gate disabled (not released) on desktop and serve, plus a throwing-opener case; the newmain-process-ready-persistence-cleanup.test.tsasserts the gate is null before the writer freeze resolves. - Merged main
6fc3cdcad6— incorporated the ready-phase persistence cleanup so the gate change composes with the new closing-writer ordering.
I re-ran main-process-ready-activation-failure, main-process-ready-persistence-cleanup, main-process-runtime-launch-activation, main-process-ready-phase-ordering, and serve-desktop-activation (24 tests), plus the changed-code quality gate — all green. The new behavior is covered by tests that fail against the prior commit: the throwing-opener case would call activateWindow under the old finally, and the serve/foundation cases would observe 'ready'/'initializing' instead of null.
Both desktop open sites still route through the wrapped opener, and state.mainWindow is assigned before openMainWindow returns, so a released gate takes the focus-existing branch. The removed finally is safe: every production throw path propagates to the ready-phase catch, which disables the gate, and the process exits.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
Opening Orca again while its first window was still starting could leave two windows and a half-started app. Extra opens now wait for the startup window.
What Changed
Start the desktop activation gate in its initializing state for ordinary launches as well as serve mode. Release queued activations only after the window opens successfully, so every activation finds the same window. On startup failure, disable activation before main closes the profile writer and exits. Preserve main’s join of concurrent menu and launch work before persistence cleanup.
Before, the duplicate window registered
window:isMaximizedtwice, stopping runtime startup; the visible window then receivedUnauthorized skill IPC senderand CLI/mobile could not connect. After, startup creates one window and completes its runtime registration.Why
Reusing an early-created window would allow it to open before shell PATH setup and Windows permission repair. Holding the existing gate preserves startup order and handles second-instance launches, file opens, deep links and macOS activation together.
Linked Issue
Crash report with both failure signatures; no separate issue was filed.
Visual Proof
N/A — no layout change. Original hidden Electron 43.7 macOS reproduction, with a temporary startup delay and a second process, showed two BrowserWindows, refused trusted IPC and no runtime file before; one BrowserWindow, working IPC and the runtime file after. All windows remained hidden with ORCA_BACKGROUND_LAUNCH=1. No fresh rendered-app run was performed in this refresh.
Testing
Review
Integration review caught a changed startup-failure contract on main: profile persistence now closes before the recovery dialog and exit. The fix preserves that contract and prevents reopening against a closing writer. Previous CI passed except the unrelated stale terminal hook snapshot; #23090 fixes that snapshot and the refreshed local check passes. Full CI reruns on this head.
Agent skill upstream boundary
Notes
No RPC, SSH process-liveness, provider or workspace-kind behavior changes. Normal second opens may wait longer during a slow startup; failed startup follows main’s existing recovery-and-exit behavior.
Checklist