Skip to content

fix(updater): clear a cancelled macOS install request before staging the next update - #28010

Merged
OrcaWin merged 2 commits into
mainfrom
np/d1e-shipit-recovery
Oct 12, 2026
Merged

OrcaWin merged 2 commits into
mainfrom
np/d1e-shipit-recovery

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​210 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​208
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​276 $\color{#cf222e}{\Huge{\mathbf{−}}}$​53 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​223

ELI5

On a Mac, the app's updater (Squirrel) hands each update to a helper called ShipIt. If ShipIt is cancelled partway, for example because a background orca serve restarted while it was installing, it leaves its request and a half-prepared copy of the update behind. From then on every update stops at "Downloading… 100%". It stays that way across restarts until someone deletes those files by hand (#14732). This PR has Orca clear those leftovers before it prepares the next update, but only when it can prove nothing else still needs them.

What Changed

  • Before: Orca never touched ~/Library/Caches/com.stablyai.orca.ShipIt/. A cancelled install left ShipItState.plist and an update.<random>/ folder there. The reporter showed that later updates then never reached "installer ready", and that deleting exactly those two items fixed it.
  • After: right before this process asks Squirrel to prepare an update, Orca runs a short recovery step:
    • When it runs: at download start on the desktop, where Squirrel prepares as soon as the download ends. For a supervised headless serve, it runs right before the native install, where Squirrel's preparation is deferred (fix(updater): install macOS orca serve updates instead of waiting on Squirrel forever #27466).
    • What it may delete: only ShipItState.plist and update.* folders. ShipIt's logs stay.
    • Under an install lock: ~/Library/Application Support/orca/bundle-coordination/install.lock, created with exclusive create and holding the owner's pid. A lock whose owner died is reclaimed once. While a live holder has it, nothing is deleted.
    • Only with no owner left: every process that prepares an update leaves an empty record under bundle-coordination/shipit-staging-owners/<pid>, so a desktop holding an update that's ready to install is never cleaned out from under it. Records of dead processes are pruned.
    • Never while Orca's ShipIt runs: if a ShipIt is running for com.stablyai.orca.ShipIt (launchd's job label for it), or the process list can't be read, nothing is deleted. Other apps' ShipIt processes don't block the cleanup. Owners are checked again right before deleting, in case one registered while the process list was being read.
  • Safe by construction:
    • The step only runs in a packaged macOS app. Tests, dev builds and other platforms skip it.
    • It never throws into the update flow. An outcome other than "nothing to do" is recorded as an updater_macos_shipit_leftovers breadcrumb.
    • Nothing new runs at startup, and nothing retries on its own. Each update attempt clears at most what an earlier, dead attempt left, so it can't loop.
  • Reuse: the ps listing and the ShipIt matching that the supervisor's install hold already used moved to src/shared/shipit-process-listing.ts, so both callers share them. A new matcher finds Orca's ShipIt by its job label, so app paths that contain spaces still match. The installer's session-release helper moved to its own file to keep updater-install-execution.ts under the line limit; its behavior is unchanged.

Why

This is B7 of the headless-serve robustness plan. B4 and B6 (#27716, #27722) stop the respawn race that cancels ShipIt. But a machine that has already hit it once stays stuck, and anything else that kills ShipIt has the same effect.

Alternatives considered:

  • Delete leftovers at startup: this could remove an update another running Orca has already prepared and is about to install. The per-process owner records exist to prevent exactly that.
  • Time-based expiry: a pending update can sit for days waiting for a restart, so its age proves nothing.
  • Detect the stall and retry: that adds a timer loop, and you can't tell a stall from a slow preparation.
    Clearing only under the lock, only with no live owner and no ShipIt running, and only right before preparing the next update, is the narrowest rule that both unsticks the machine and never races a live install.

Linked Issue

Fixes the "every later update stalls" half of #14732 (with #27716 and #27722).

Visual Proof

N/A. This changes background update behavior, with no UI.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • shipit-leftover-recovery.test.ts, in temporary folders:

    • the request and the prepared copy are cleared and the logs kept;
    • a live owner, Orca's running ShipIt (including an app path with a space; another app's ShipIt doesn't count), or an unreadable process list each block the cleanup;
    • a live lock holder blocks it, and a dead holder's lock is reclaimed;
    • dead owner records are pruned;
    • with nothing to clean, the process list isn't read.
  • updater.mac-install.test.ts: the desktop download starts only after the recovery step finishes. This failed before the change.

  • updater.headless-serve-install.test.ts: supervised serve on macOS runs the step after the handoff and right before the native install, never at download. This failed before the change.

  • The full updater and serve-install-hold suites, pnpm tc, oxlint, pnpm run check:code-quality:changed and pnpm lint pass locally.

  • Not run: a real cancelled ShipIt on a test Mac. That is real-host test 2 in the design.

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Compatibility: new files only. Older Orca versions don't write owner records, so while an old desktop is running with an update prepared, a newer process could clear it. That needs two Orca versions of the same app running at once with an update pending in the older one. The older one's next install then fails and asks to retry, which is today's failure mode anyway.
  • Cross-platform: macOS only. Squirrel and ShipIt don't exist on Linux or Windows, and the step returns immediately there.
  • SSH: local updater state only.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

Walkthrough

The changes add shared ShipIt process-listing helpers and macOS staging recovery. Recovery tracks staging owners, coordinates through an install lock, and removes recognized leftovers when its checks allow. Updater downloads now wait for staging preparation unless preparation is deferred until installation. Deferred installs prepare staging before invoking the native updater. Installer session release moves to a shared function. Tests cover recovery outcomes and staging-preparation timing.


Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to 6fc71

The install ordering is implemented, but its new test leaves an asynchronous regression unprotected. This is a bounded concern that can be addressed before merge or tracked as a follow-up.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 72.73% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 10 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: clearing cancelled macOS install state before staging the next update.
Description check Passed The description follows the template and explains the user impact, implementation, rationale, linked issue, testing, compatibility, and checklist status. It also states that visual proof is not applic…
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.

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

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

🧹 Nitpick comments (1)
src/main/updater.headless-serve-install.test.ts (1)

350-403: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Keep staging pending until the test checks the native install boundary.

prepareShipItStagingMock resolves immediately, so the test passes even if quitAndInstall invokes native installation without awaiting staging. Use a deferred promise and assert that native installation has not started before resolving it.

Suggested fix
       const lifecycle: string[] = []
+      let finishPreparing: () => void = () => undefined
       prepareShipItStagingMock.mockImplementation(() => {
         lifecycle.push('shipit-staging-prepared')
-        return Promise.resolve()
+        return new Promise<void>((resolve) => {
+          finishPreparing = resolve
+        })
       })
...
       quitAndInstall()
       await vi.advanceTimersByTimeAsync(100)

+      expect(lifecycle).toEqual(['handoff-persisted', 'shipit-staging-prepared'])
+      finishPreparing()
+      await vi.advanceTimersByTimeAsync(0)
+
       expect(lifecycle).toEqual([
         'handoff-persisted',
         'shipit-staging-prepared',
         'native-quit-and-install'

ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 00e2bd40-cf36-4b1c-af93-9cf3ece84717
📥 Commits

Reviewing files that changed from the base of the PR and between cef4d29 and 6fc71e6.

📒 Files selected for processing (10)
  • src/cli/runtime/serve-install-hold.test.ts
  • src/cli/runtime/serve-install-hold.ts
  • src/main/updater.headless-serve-install.test.ts
  • src/main/updater.mac-install.test.ts
  • src/main/updater/shipit-leftover-recovery.test.ts
  • src/main/updater/shipit-leftover-recovery.ts
  • src/main/updater/updater-download-install.ts
  • src/main/updater/updater-install-execution.ts
  • src/main/updater/updater-installer-session-release.ts
  • src/shared/shipit-process-listing.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

@OrcaWin
OrcaWin merged commit dedea9c into main Oct 12, 2026
46 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