Repository navigation
fix(macos): preserve terminal permissions across app updates with a small signed helper - #27021
Conversation
…ndpoint A copy, signature, plist or deadline failure before bootstrap, a bootstrap launchd refused with the job absent, a job whose daemon exited before answering, and a foreign endpoint all threw out of the launcher. The app then lost its persistent daemon and fell back to local PTYs, where main forks one. These now fall through to the existing fork path, which also adopts a foreign occupant normally instead of as a degraded endpoint. A timed-out bootstrap or a job still running/unreadable stays fatal, so no second daemon races it.
daemon_adopted, daemon_pty_cwd_denied and daemon_pty_cwd_readable gain a closed-enum launch_method (stable-copy / app-fork / unknown), read from the spawner path the daemon recorded, so the update fix is measurable per daemon even when an old forked daemon is adopted across updates. The reliability gate is a test manifest with no runtime switch, so there is no gate state to report; spawner_path_class reports the private copy as 'other' alongside other non-/Applications installs.
The separate launch_method property duplicated what the recorded spawner path already says. spawner_path_class gains `stable-copy`, classified from the same path under the private runtime root, and launch_method, its enum and classifier are removed from all three .strict() daemon origin events. A deleted copy still reports `missing`.
The permissions handler already asks for the terminal-host status only on macOS, so the status function's own platform check and the pane's 'unsupported' branch could never fire. The off-macOS guarantee is now tested at the handler.
The stable launch could run until 55 s after the launch started, so a late "unavailable" verdict left the fork fallback's own 10 s readiness wait to finish after the 60 s gate had already moved the app to local PTYs. The launcher now gives the stable attempt one handoff deadline: the gate minus the fork's readiness timeout and the 5 s lease/adapter allowance (45 s). Copy, signature check and plist conversion share one abort signal that ends early enough for bootstrap and the job's own readiness wait to meet that deadline; every command otherwise keeps a fixed timeout. An unavailable verdict past the deadline is reported instead of forking a daemon that cannot arrive in time. The per-step budget module is gone (its deletion landed in the previous commit by a staging slip). The launch body is now two blocks: preparation (plist, plutil, deadline check) fails as unavailable after removing the copy and job file, and bootstrap runs in its own try/finally that always deletes the job file. Retirement is simpler and claims more orphans: one in-flight collection per process instead of a per-root map and rotating 20-record scan, and the job record (written before copying) no longer carries a bundle name because lsof +D scans the whole runtime directory (measured equal cost, same result on a live copy). A never-submitted copy is retired once its producer has exited and its job is missing, so a bootstrap timeout or a crash mid-copy no longer leaves a copy forever; the open-file check still guards deletion. Collection now starts from the launcher after the attempt.
The signed investigation harness left the tree in the previous telemetry commit by a staging slip; its results and pinned link stay in the PR. This trims the reference doc to why the copy and launchd exist, the fallback states and the cleanup rule, trims the reliability gate to what its validator needs, and points AGENTS.md at the reference doc next to the Windows relocation entry.
A copied daemon refused at exec (for example by Gatekeeper) never answers, so every fresh start paid the full 10 s readiness wait before the fork fallback. The readiness loop now reads the job state every 500 ms and abandons as soon as the job is stopped or missing; a running or unreadable job is still waited out and never forked beside. Also drops the dead forkEntryPath the stable launch never read (its options type now omits it) and un-exports the handoff constant.
…d ones Each runtime copy is a full Orca.app, so Spotlight indexed it as an app and LaunchServices kept a record for it that outlived the copy. A registered copy claims orca: links and Markdown/CSV files, and becomes their default handler whenever /Applications/Orca.app is not registered. New copies go under runtime-*/app.noindex/, which Spotlight skips and which stops the record LaunchServices made while the bundle was being copied. Retirement now runs lsregister -u on every bundle in the copy (both the app.noindex layout and the earlier runtime-*/Orca.app layout) once lsof shows it unused, then deletes it. A running copy stays registered, because Local Network access may be resolved through that record. Collection and stable-copy telemetry match the runtime-* directory, so copies made before this change are still adopted, classified and retired.
The reference doc now explains why copies sit in a .noindex folder, why only retired copies are unregistered, and how to turn the copy launch off: make launchMacDaemonFromStableBundle return null, and keep the retirement code until no copy-launched daemon can remain, because the old code never deletes copies. A test pins that rollback: with the stable launcher returning null, the launcher forks and still runs the copy collection.
…e them The `.noindex` folder kept copies out of Spotlight and LaunchServices, but Local Network access is resolved from the signing identifier through LaunchServices to the executable's Mach-O UUID. After an update that changes Electron only the copy carries the running daemon's UUID, so an unregistered copy risks the same Local Network loss main has today. Copies go back to `runtime-*/Orca.app`; retirement still unregisters each copy before deleting it, so deleted copies leave no LaunchServices entry. The remaining trade-off: while `/Applications/Orca.app` is missing, a running registered copy can be picked for `orca:` links and documents.
Spotlight listed each runtime copy as a second Orca app. New copies go back under runtime-*/app.noindex/Orca.app, which Spotlight skips. Retirement and stable-copy telemetry match the runtime-* directory, so copies in the earlier runtime-*/Orca.app layout still retire and classify the same way. Local Network access identifies the daemon by its code signature and main-executable UUID, not by a LaunchServices record, so an unregistered copy keeps it. The launchd job now sets AssociatedBundleIdentifiers to com.stablyai.orca, which is how a job not installed through SMAppService names the app it belongs to. Copies are never registered explicitly; retirement still runs lsregister -u before deleting each one.
…on on the pinned Node Contents/Helpers/Orca Terminal Host.app carries the pinned Node, the daemon's out/main JS and this slice's node-pty, signed inside-out as com.stablyai.orca. afterPack boots it through one PTY round trip, then fails the build on layout, Info.plist, macOS floor (NODE_RUNTIME_DARWIN_MINIMUM_OS vs Node's minos), architecture or signature drift.
Packaging now fetches the darwin Node from nodejs.org, whose download has no retry. Each mac workflow caches it with the electron-builder downloads, keyed on the pin, and warms both darwin targets inside the existing retry wrapper.
…r, not the whole app The stable launch now clones Contents/Helpers/Orca Terminal Host.app (~124 MiB instead of ~628 MiB) and runs its Node on its daemon entry, without ELECTRON_RUN_AS_NODE. The copy must still match the running app's designated requirement. A missing helper falls back to the fork, and macOS below the helper's Node floor forks without copying.
…ways clean up A daemon that stayed silent hung packaging past the 20 s deadline; one that closed the connection left the hello unsettled so Node exited 0 without cleanup; a malformed line threw uncaught. Every connect, hello and PTY wait now races the deadline, close/error/parse failures reject, and the daemon and scratch dir are removed on every path.
…fallback Sharing the electron-builder cache let old Node archives accumulate through restore-keys. Also moves release-mac-build's Electron cache comment back onto its step.
…s name in one test packageMacTerminalHost turned an unknown arch into darwin-undefined; it now throws through the shared mac arch mapping. A test asserts the packager and the desktop agree on the helper bundle and executable names, replacing a Linux/Windows test that could not fail.
…minal-host # Conflicts: # AGENTS.md
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 Walkthrough
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: 🔵 Low · up to The new macOS terminal-host helper finds the daemon's dependencies by scanning its source with simple patterns. Some valid module-loading forms, or packages installed only inside another package, could either stop the macOS build or leave a dependency out of the helper. There is no evidence that the current daemon uses those forms, so the change is mergeable. The scanner should still be hardened soon so that later daemon changes do not break helper packaging. Pre-merge checks |
|
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:
a853d9b0-7855-4810-ac62-c6804ddcc10b
📒 Files selected for processing (54)
.github/workflows/adhoc-mac-build.yml.github/workflows/daily-mac-build.yml.github/workflows/hourly-mac-build.yml.github/workflows/release-mac-build.ymlAGENTS.mdconfig/electron-builder.config.cjsconfig/reliability-gates.jsoncconfig/scripts/macos-folder-usage-descriptions.cjsconfig/scripts/macos-folder-usage-descriptions.test.mjsconfig/scripts/macos-terminal-host-bundle.cjsconfig/scripts/macos-terminal-host-bundle.test.mjsconfig/scripts/pinned-node-downloads.mjsconfig/scripts/verify-packaged-daemon-entry.cjsconfig/scripts/verify-packaged-daemon-entry.test.mjsdocs/reference/macos-daemon-tcc-attribution.mdsrc/main/codex/codex-background-terminals.tssrc/main/daemon/daemon-adoption-telemetry-event.test.tssrc/main/daemon/daemon-adoption-telemetry-event.tssrc/main/daemon/daemon-full-disk-access-status.test.tssrc/main/daemon/daemon-full-disk-access-status.tssrc/main/daemon/daemon-init-macos-stable-launch-fallback.test.tssrc/main/daemon/daemon-launched-child-spawn.tssrc/main/daemon/daemon-launched-child.tssrc/main/daemon/daemon-mac-code-identity.test.tssrc/main/daemon/daemon-mac-code-identity.tssrc/main/daemon/daemon-out-of-process-launcher.tssrc/main/daemon/daemon-permission-requests.tssrc/main/daemon/daemon-pty-adapter-full-disk-access.test.tssrc/main/daemon/daemon-pty-adapter.tssrc/main/daemon/daemon-request-router.tssrc/main/daemon/daemon-server.test.tssrc/main/daemon/macos-daemon-bundle-retirement.test.tssrc/main/daemon/macos-daemon-bundle-retirement.tssrc/main/daemon/macos-daemon-bundle.test.tssrc/main/daemon/macos-daemon-bundle.tssrc/main/daemon/macos-daemon-job-state.test.tssrc/main/daemon/macos-daemon-job-state.tssrc/main/daemon/macos-daemon-launchd.test.tssrc/main/daemon/macos-daemon-launchd.tssrc/main/daemon/types.tssrc/main/ipc/developer-permissions.test.tssrc/main/ipc/developer-permissions.tssrc/main/macos-full-disk-access-status.test.tssrc/main/macos-full-disk-access-status.tssrc/renderer/src/components/editor/editor-cmd-save-target.tssrc/renderer/src/components/settings/DeveloperPermissionsPane.test.tsxsrc/renderer/src/components/settings/DeveloperPermissionsPane.tsxsrc/renderer/src/components/tab-bar/tab-bar-item-surface.tsxsrc/renderer/src/components/terminal-workspace-model.tssrc/renderer/src/i18n/locales/en.jsonsrc/shared/daemon-adoption-telemetry.test.tssrc/shared/daemon-adoption-telemetry.tssrc/shared/developer-permissions-types.tssrc/shared/node-runtime-pin.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
…ection; keep only passing gate commands
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:
7291d6d1-d03e-44be-8a3b-eef32f9840e1
📒 Files selected for processing (16)
config/electron-builder.config.cjssrc/main/daemon/daemon-launched-child-spawn.tssrc/main/daemon/daemon-launched-child.tssrc/main/daemon/daemon-mac-code-identity.test.tssrc/main/daemon/daemon-mac-code-identity.tssrc/main/daemon/daemon-out-of-process-launcher-host-prune.test.tssrc/main/daemon/daemon-out-of-process-launcher.tssrc/main/daemon/macos-daemon-bundle-retirement.test.tssrc/main/daemon/macos-daemon-bundle-retirement.tssrc/main/daemon/macos-daemon-bundle.test.tssrc/main/daemon/macos-daemon-bundle.tssrc/main/daemon/macos-daemon-job-state.test.tssrc/main/daemon/macos-daemon-job-state.tssrc/main/daemon/macos-daemon-launchd.test.tssrc/main/daemon/macos-daemon-launchd.tssrc/renderer/src/i18n/locales/en.json
🚧 Files skipped from review as they are similar to previous changes (2)
- src/renderer/src/i18n/locales/en.json
- src/main/daemon/daemon-mac-code-identity.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
…bs start in the terminal host helper
…and boot it outside the build tree
There was a problem hiding this comment.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
50cb2e87-c2bf-4d8a-bb78-9e499ddf8cd0
📒 Files selected for processing (3)
config/scripts/macos-terminal-host-bundle.cjsconfig/scripts/macos-terminal-host-bundle.test.mjsconfig/scripts/verify-packaged-daemon-entry.cjs
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
…ectory loads, and keep nested dependencies
…lper folder strings to a follow-up Keeps this change to the update-safe terminal host itself. The follow-up restores: - the `stable-copy` spawner path class in daemon adoption telemetry; - the per-terminal-host Full Disk Access row in Settings and its daemon RPC; - writing folder usage descriptions into the app's Electron Helpers for the fork fallback. The helper still takes its Desktop, Documents and Downloads descriptions from `macos-folder-usage-descriptions.cjs`, so that constant stays.
The previous commit took the file from a newer main, which pulled unrelated strings into this PR.
…r a fixed launchd label Name the copy after the helper's CDHash, reuse it when present, and publish a new one by cloning into a staging dir, verifying it once against the app's designated requirement and renaming it into place. One launchd label per profile and protocol replaces per-launch labels, so job.json, producer pids and per-label collection go away. Retirement deletes any other copy lsof shows unused. The stable launcher returns null for every fork fallback and logs its reason.
…ves them A nested package's own dependencies were never walked, so a hoisted dependency of a nested package was left out of the helper. Resolve each dependency through the node_modules lookup Node performs from its parent and copy it to the same relative place, unless a copied package already carries it.
…minal-host slice An arm64 runner without Rosetta skipped the x64 helper's PTY boot check and shipped the slice untested. Release channels and CI now fail there; local cross-arch builds still skip with a log line.
… reusing its label
…minal-host # Conflicts: # src/main/daemon/daemon-launched-child-spawn.ts # src/main/daemon/daemon-out-of-process-launcher.ts
ELI5
When Orca updates on macOS, terminals that were already open can lose access to protected files (Full Disk Access, Documents, Desktop, Downloads), even though Orca's permission checkbox stays on. This runs the terminal service from Orca's own small, signed helper, kept in a private copy that updates can't touch. macOS still sees it as Orca, so the existing permissions keep working.
This PR combines #25848 (the update-safe launcher) with a slimmer copy: a 124 MB helper instead of the whole 628 MB app.
What Changed
Update-safe launcher (from #25848), now with one copy per helper build
userData/daemon-host/macos/terminal-host-<cdhash>/app.noindex/Orca Terminal Host.app. If that copy exists, a new daemon reuses it with no copy and no signature check. Otherwise Orca clones the helper into a staging folder beside it, checks it once withcodesign --verify --strict -R "=<the app's designated requirement>", and publishes it with one atomic rename. If another publisher wins the rename, Orca uses that copy.gui/$UID) under one fixed label per profile and protocol, withAssociatedBundleIdentifiersnaming Orca. Before starting, Orca removes a stopped job left under that label. If a job under that label is still running, the launch fails rather than starting a second daemon beside it. The existing authenticated handshake and launch nonce establish ownership.lsof +Dshows no process using it (afterlsregister -u).lsof +Dexits 1 even when a process is using the folder, so only empty output counts as unused. If the check is uncertain, the copy stays. No per-copy record file is kept.prepare-failed,deadline,bootstrap-refused,exited-before-readyorendpoint-taken). If the published copy fails to start, Orca deletes it when nothing uses it, so the next launch makes a fresh copy.Slim helper (new)
The macOS build adds
Contents/Helpers/Orca Terminal Host.app, which contains:orca-terminal-host;It is signed as
com.stablyai.orcawith the same team and entitlements, so its designated requirement equals the app's. It claims no URL schemes or document types.A check after signing boots the signed helper and opens a real PTY on each architecture. The build fails if it can't. Release and CI builds also fail if this machine cannot run a slice (for example x64 without Rosetta); local builds skip that slice with a log line.
The launcher copies this helper instead of the whole app. The packaging step copies each package the daemon needs from where Node would load it, including dependencies of nested packages. Below macOS 13.5 (the Node runtime's floor), Orca uses the forked daemon, as it does today.
The 4 macOS release workflows cache and prefetch the pinned Node archive.
Disk use for each old version whose terminals outlive an update:
The installed app grows from 628 MB to ~752 MB, and the download from ~255 MB to ~294 MB (estimated).
Why
macOS ties privacy grants to the designated requirement, not to the path or the binary hash. A daemon whose app is deleted before its first protected access is denied, even after the app comes back. A launchd job running from a private signed copy is unaffected. I considered:
The helper has the same identity and only what the daemon needs.
Why one copy per build rather than one per launch: macOS spends about 1 s the first time a binary runs from a new path (measured 996 ms on the first run, 23 ms after). With a copy per launch, every new daemon paid about 0.7 s more than
main. With one copy per build, only the first daemon after an update pays it. Keeping one copy per build also removes the per-copy record file, producer pid tracking and per-launch label cleanup, and caps disk use at one copy per build still in use. Investigation history: #20452, and the original signed experiment.Rollback
Make
launchMacDaemonFromStableBundleinsrc/main/daemon/macos-daemon-launchd.tsreturnnullright after its platform checks; every launch then forks as before. Keep the cleanup call running there (retireOtherMacDaemonCopies(root, '')) until no copy-launched daemon can remain.Linked Issue
Fixes #13921
Visual Proof
N/A: no UI change. The terminal service starts differently; nothing on screen changes. The Settings status row moved to #27354, with its screenshots.
Testing
Signed ad hoc builds of this branch. These predate the switch to one copy per build and the fixed launchd label, so they ran the earlier copy-per-launch launcher. They were built before the split, so they also include #27354: A and B. On both:
Deleting the app (build A, macOS 27, arm64, launchd jobs). The app is deleted while a shell is open, then the shell makes its first protected read. The shell's parent process was recorded in every run.
Daily use (signed spike of this design on macOS 27): the daemon ran from the helper copy. Documents, Desktop, Downloads, Full Disk Access and local network all worked with no prompt. Settings showed a single Orca entry, the helper was not registered with LaunchServices, and the copy was 124 MB.
#25848's own evidence (whole-app copy) still applies to the shared launcher:
app.noindex;0b5f6c48e09b.Unit tests cover packaging, the boot check, the OS-floor gate and the helper launch path.
After the switch to one copy per build, locally on macOS (arm64):
pnpm tcpasses.repro-13767-shell-ready-marker-lost-to-exec.test.ts, which also fails onmainon this Mac.pnpm run check:reliability-gatespasses; the gate's focused command runs 64 tests, all passing.oxlintandpnpm run check:code-quality:changedare clean on the changed files.lsoflists a process but exits 1 (the shape seen on a live copy).Not yet covered:
Review
Ownership, startup deadlines, signed-copy integrity and unknown-preserving cleanup were reviewed in #25848. The helper packaging, the boot check and the launch change had two spec reviews and one code review, and all must-fix findings are addressed. Old terminals that were already denied still need a deliberate restart.
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Split: the Settings Full Disk Access row per terminal host, the
stable-copytelemetry value, and folder descriptions for the app's Helper bundles (used by the fork fallback) are in #27354, stacked on this PR.macOS only. Linux, Windows, SSH and dev builds use their existing paths. Bumps the daemon protocol to v45, so after an update new macOS tabs start in the helper while existing tabs stay on their old daemon. Rolling back to a v44 build cannot reach the v45 daemon's tabs until re-upgrade, as with any bump. The bump rides with the launcher change on purpose (label
allow-runtime-launcher-protocol-bump). There's no new stream opcode. The bump also gives Linux and Windows users a fresh daemon on update, with no benefit to them; that is the usual cost of a protocol bump.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)