Skip to content

fix(startup): hold desktop activations until the startup window exists - #22495

Merged
OrcaWin merged 4 commits into
mainfrom
fix/scan21-startup-double-open
Sep 26, 2026
Merged

OrcaWin merged 4 commits into
mainfrom
fix/scan21-startup-double-open

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​401 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​401
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​29 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​27

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:isMaximized twice, stopping runtime startup; the visible window then received Unauthorized skill IPC sender and 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

  • Original regression covers a second instance during startup on macOS/Linux/packaged Windows using the real gate and launch code.
  • Failure regressions cover foundation/runtime/permission/window failures, serve behavior, menu/launch ordering and activation while writer shutdown is pending.
  • Integrated main 6fc3cdc: 75 tests across 11 suites pass, including persistence cleanup and terminal hook parity; node typecheck, changed-code quality, focused lint and formatting pass on macOS.
  • Fresh manual Windows/Linux app run. Windows timing attempts in the original scan did not reproduce the race without a widened delay.

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

  • Not applicable.

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

  • Focused fix; mechanism, alternatives and validation stated.
  • Self-reviewed and cross-platform/serve behavior covered.
  • Targeted tests, typecheck and quality passed; full checks run in CI.

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.

@pullfrog pullfrog 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.

✅ 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 / macOS activate that lands after ready but 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) — releaseDesktopActivationAfter wraps openMainWindow and calls markReady() in a finally, so the queued activation replays against the now-existing window; the launch-phase .catch releases 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, real focusExistingMainWindow, and the real launch/ready phases, with a fake opener that reproduces the duplicate window:isMaximized throw, 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 only main-process-preflight.ts regressed.
  • releaseDesktopActivationAfter has no direct unit test in serve-desktop-activation.test.ts; its behaviour is covered indirectly by the new launch test.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

📝 Walkthrough

Walkthrough

The 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 d2e4d

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 Review

Security architecture risk: 🟡 Moderate · up to d2e4d

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

  • Medium · reliability · inferred: The new release point marks activation ready even if the startup-window opener throws. A queued request is then consumed without first establishing that a valid main window is available. Existing focus retries mitigate this, but the partial-window failure and trusted-renderer ownership outcome remain unverified; this is an incomplete failure-state guarantee, not a demonstrated new IPC bypass.
Security review details

Security Blast Radius

  • inferred — The affected security-relevant scope is activation and trusted-window availability in a desktop process, with downstream CLI and mobile connectivity dependent on runtime startup. The examined paths do not establish a new cross-service authority or tenant boundary.

Security Findings and Attack Paths

  • inferred — A second launch or accepted OS activation can request the existing focus-or-open action, but the examined change does not show a new route around trusted-renderer IPC checks. The failed-opener ownership path remains uncertain rather than a verified bypass.

Trust Boundaries and Controls

  • observed — The gate controls when an activation callback executes; focus chooses a live main window or the normal opener. The skill IPC path separately checks sender identity against the trusted renderer.

Resilience and Maintainability Implications

  • observed — On an opener exception, focus can retry and adopt a live window exposed by its getter. The gate itself does not retain its pending activation after marking ready, so that retry behavior is material to failure containment.

Hardening Proposals

  • proposed — Exercise an opener that fails both before and after partial window creation, including trusted-renderer assignment, and establish whether the gate should retain or explicitly fail a queued activation until window ownership is known.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning 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 t… Add the issue reference in the required Fixes # format, or create and link a tracking issue. Also provide visual proof for this behavior change, or confirm why the repository requirement does not apply; the current N/A explanation only …
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly describes the primary change: delaying desktop activations until the startup window exists.
Full details: Description check

Explanation

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 Fixes # format, or create and link a tracking issue. Also provide visual proof for this behavior change, or confirm why the repository requirement does not apply; the current N/A explanation only addresses layout changes, not behavior changes.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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: Advanced

Run ID: 96cc6413-2db2-4a66-961e-e1165991f266

📥 Commits

Reviewing files that changed from the base of the PR and between dac82f6 and 888476a.

📒 Files selected for processing (4)
  • src/main/startup/main-process-preflight.ts
  • src/main/startup/main-process-ready.ts
  • src/main/startup/main-process-runtime-launch-activation.test.ts
  • src/main/startup/serve-desktop-activation.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Comment thread src/main/startup/main-process-ready.ts Outdated
Comment on lines +31 to +34
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()

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.

🩺 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/main

Repository: 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.ts

Repository: 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/main

Repository: 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"
done

Repository: 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.ts

Repository: stablyai/orca

Length of output: 41653


🏁 Script executed:

#!/bin/bash
rg -n -C 8 --type ts 'installUnhandledRejectionLogging' src/main

Repository: 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.

@OrcaWin

OrcaWin commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator Author

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:

  • 20:05:06 the update installed. 20:06:43 the new main process started.
  • 20:06:55.507 main_unhandled_rejection: Attempted to register a second handler for 'window:isMaximized'. The stack is openMainWindow < openWindow < … < Promise.all, so the startup path opened its window after an activation had already made one.
  • 20:06:58 the ACL probe came back clean (matchesPoisonSignature=false), so the install-folder repair isn't involved here.
  • 20:07:01.711 renderer: skills:getUpdateRun: Unauthorized skill IPC sender. The visible window was the untrusted one, as this PR describes.
  • 20:08:06 the renderer, GPU and network service all exited with code 1 within about 150 ms (reason killed). That looks like the user ending the task. A fresh main process started at 20:08:13 and came up clean.

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 (ORCA_E2E_USER_DATA_DIR plus a throwaway home) with ORCA_BACKGROUND_LAUNCH=1 and ORCA_STARTUP_DIAGNOSTICS=1. I started a second Orca.exe 0, 250, 500, 1000, 1500, 2500 and 4000 ms after the first. All 7 runs finished cleanly: the second instance exited 3 (it handed off to the first), there was one window, orca-runtime.json was written, and there was no "second handler" error.

  • The diagnostics show why it didn't reproduce. In every run the early activation did reach openWindow before the startup window existed. The Runtime must be initialized before opening the main window guard refused it, logged as Failed to reopen main window for second-instance launch, and the activation was dropped.
  • So the field failure needs the activation to arrive after the runtime is set but before startup opens its window. On a warm, empty profile that gap was about 25 ms (services-initialized → open-main-window-start). It is presumably wider on a real profile on its first launch after an update.
  • This PR's gate closes both cases. It also fixes the silently dropped activation that the repro showed. Afterwards I confirmed no leftover processes and deleted the temporary profile.

@OrcaWin

OrcaWin commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator Author

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.

@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: Advanced

Run ID: b8e8e9eb-582a-401b-8b8f-ce9167e094e6

📥 Commits

Reviewing files that changed from the base of the PR and between 888476a and d2e4dfe.

📒 Files selected for processing (3)
  • src/main/startup/main-process-ready-activation-failure.test.ts
  • src/main/startup/main-process-ready.ts
  • src/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.

Comment thread src/main/startup/main-process-ready.ts Outdated
function releaseDesktopActivationOnFailure(error: unknown): never {
// Keep later opens possible after a failed phase; serve promotion still fails closed.
if (!state.isServeMode) {
state.desktopActivationGate?.markReady()

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.

🩺 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.ts

Repository: 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.ts

Repository: 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.ts

Repository: 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/main

Repository: 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/main

Repository: 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.ts

Repository: 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.

Suggested change
state.desktopActivationGate?.markReady()
state.desktopActivationGate?.markBlocked('desktop startup initialization failed')

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Prerequisite failures now release the desktop gate (src/main/startup/main-process-ready.ts:22-23,35-41) — initializeReadyFoundation and initializeReadyRuntimeServices are 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 .catch body was extracted into releaseDesktopActivationOnFailure, 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 .catch runs.

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.

@OrcaWin
OrcaWin merged commit 029b5ba into main Sep 26, 2026
3 checks passed

@pullfrog pullfrog 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.

✅ 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's try/catch persistence-cleanup shape and sets state.desktopActivationGate = null before awaiting store.freezeWritesAsync() and releasing profileStateAdmission. This matches main-process-preflight-failure.ts:12 and main's fail-and-exit contract: index.ts:116-149 catches the rejection, shows the recovery dialog, then app.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) — releaseDesktopActivationAfter drops try/finally for a plain sequence, so gate.markReady() runs only after open(...) 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.ts now expects the gate disabled (not released) on desktop and serve, plus a throwing-opener case; the new main-process-ready-persistence-cleanup.test.ts asserts 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.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

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