Skip to content

fix(cli): publish a readable /usr/local/bin/orca symlink on macOS and repair unreadable ones - #29245

Merged
AmoabaKelvin merged 1 commit into
stablyai:mainfrom
AmoabaKelvin:fix-macos-cli-symlink-readable
Oct 16, 2026
Merged

AmoabaKelvin merged 1 commit into
stablyai:mainfrom
AmoabaKelvin:fix-macos-cli-symlink-readable

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​91 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​91
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​104 $\color{#cf222e}{\Huge{\mathbf{−}}}$​58 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​46

ELI5

Registering the orca command on a Mac through the admin password prompt left behind a link that only root could read. Your own account could not see where it pointed, so Settings showed an error and typing orca in a terminal failed. The link is now created so everyone can read it, and an old unreadable link can be repaired from Settings.

What Changed

Before: after registering the CLI with the admin prompt, /usr/local/bin/orca was root-owned with mode 0700. Opening Settings failed with EACCES: permission denied, readlink '/usr/local/bin/orca', and running orca printed Unable to determine Orca.app path from symlink. Registering again failed with the same error, so the only way out was a manual sudo chmod -h 755.

After: a fresh registration publishes the link as 0755, so Settings loads and orca resolves the app. A link left behind by an older version shows as stale in Settings with "cannot be read. Register again to repair it". Clicking register asks for the admin password once, root makes the link readable, and Orca then judges it by its normal ownership rule. If it already points at the current launcher, which is the case for everyone hit by #19120, that is the end. If it points at an older Orca launcher, the usual replacement follows. If it points somewhere else, Orca refuses with its usual "non-Orca command" message and leaves it in place.

Mechanism: the privileged shell transaction ran entirely under umask 077 so its staging directories would be private. On macOS that umask also applies to ln -s, so the published link inherited 0700, and macOS enforces a symlink's own mode on readlink. Three changes in src/main/cli/:

  • cli-command-filesystem-transaction.ts: the script now runs under umask 022 and creates only its transaction and publish directories with mkdir -m 700. That gives the link 0755 and also fixes any parent directories the script creates for a custom command path, which used to come out root-only. A new one-line privileged command, buildMacPrivilegedSymlinkReadableCommand, runs chmod -h 755 on the link after checking its device and inode still match the inspected entry. It deletes and replaces nothing. The transaction builder takes the inspection object instead of three copied fields.
  • cli-command-inspection.ts: a permission error from readlink reports the link as stale with a null target instead of throwing. The Settings pane already hides the target line when it is null, and nothing auto-installs on stale.
  • cli-command-installation.ts: inspectStableSymlink runs the make-readable command when the link is unreadable on macOS, then re-inspects. From there install and remove continue through the existing path and the existing isManagedSymlinkTarget check. The stable-inspection loop no longer treats an unreadable link as "changed under us".

Why

The link's mode comes from the umask of the process that creates it, so fixing the umask fixes the cause in one step. Alternatives considered:

  • chmod -h 755 after ln -s: a second step that can fail separately, and the staged link would still be created wrong first.
  • Keeping umask 077 and scoping 022 around ln -s only: fixes the link but leaves parent directories created by mkdir -p root-only. Setting 022 for the script and making the private directories explicit covers both.
  • Having the root script decide whether an unreadable link is Orca's: that is a second copy of the ownership rule, in shell, and it drifted from the TypeScript one in review. Making the link readable and reusing the existing rule keeps one rule.
  • Repairing existing links at startup: that would show an admin prompt nobody asked for. Showing stale and letting the user click register is less surprising.

Linked Issue

Fixes #19120

Visual Proof

N/A. No layout change. The CLI status row shows the existing stale state instead of an error, and the orca command works. Brennan's before and after captures from a dev build are in the review thread below.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Tested on macOS (arm64). Reproduced first by running the real generated transaction script in a temp directory: the link came out 0700, and removing the read bit made readlink fail with EACCES.

Five assertions added to cli-command-privileged-transaction.test.ts, which runs the real shell commands as a non-root user with lchmod standing in for root ownership:

  • the published link is 0755
  • parent directories the script creates are 0755
  • an unreadable link to the current launcher reports as stale with a null target, and one privileged chmod -h 755 makes it installed
  • an unreadable link to an older Orca launcher is repaired through the make-readable step and then the transaction
  • an unreadable non-Orca link is refused with the normal "non-Orca command" error and left intact

All five fail on the unmodified code.

pnpm lint, pnpm tc, the three CI audits, check:code-quality:changed, check:react-doctor:changed and check:zustand-selector-fanout pass on the branch rebased onto current main. The whole src/main/cli suite passes apart from packaged-cli-assets.test.ts, which fails on main too on this machine because of a /var versus /private/var tmpdir mismatch.

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

Security: the transaction and quarantine directories stay 0700; the published link and any created parent directories are 0755, like the other shims in /usr/local/bin. Root never deletes or replaces an unreadable link; it only makes it readable, after an inode check, and the existing ownership rule decides the rest. Cross-platform: macOS only. Linux ignores symlink modes, and Windows uses wrapper files. SSH, mobile, remote wire and performance are unaffected. Backwards compatible: readable installs behave exactly as before.

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 15, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The change reports symlinks with permission-denied targets as stale and adds a privileged operation to make an unreadable symlink readable when its device and inode still match the inspected identity. Installation and removal use a shared privileged transaction when quarantine returns null. The transaction validates captured inspection evidence and creates transaction and publish directories with explicit permissions. Tests cover published symlink permissions, nested parent directories, and handling of unreadable Orca and non-Orca symlinks.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🟡 Moderate · up to 27f90

Registration can replace a foreign app-bundle command link or change the permissions of a foreign link it refuses to replace. Resolve these ownership and preservation risks before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed The changes meet the coding requirements in #19120. On macOS, the transaction uses umask 022 and creates the published symlink with mode 0755. Existing unreadable symlinks report stale with no t…
Out of Scope Changes check Passed The changes stay within #19120. The production changes address symlink permissions, stale inspection, and repair behavior. The test changes verify those behaviors. No unrelated product area or platfor…
Title check Passed The title clearly summarizes the main macOS CLI change: publishing a readable symlink and repairing unreadable ones.
Description check Passed The description is complete and follows the required template. It explains the user impact, implementation, rationale, linked issue, testing, platform scope, security considerations, known test limita…
  • Fix all pre-merge checks with AI
  • 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 056663ef-fbea-4170-957b-0043169f6b92
📥 Commits

Reviewing files that changed from the base of the PR and between 26f0581 and d9ed3719b58be2a1053090909607758028aab49b.

📒 Files selected for processing: 4
  • src/main/cli/cli-command-filesystem-transaction.ts
  • src/main/cli/cli-command-inspection.ts
  • src/main/cli/cli-command-installation.ts
  • src/main/cli/cli-command-privileged-transaction.test.ts

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

@brennanb2025

Copy link
Copy Markdown
Contributor

Thanks for picking this up so fast. I reviewed it and ran it on a second Mac. The core fix is right. I'd like one small round of changes before merge.

What I verified

  • The cause and the fix. Under umask 077, ln -s on macOS produces lrwx------. With the scoped (umask 022; ln -s ...) the link comes out lrwxr-xr-x, the staging directory stays 0700, and the hard-linked published entry keeps 0755.
  • Tests. cli-command-privileged-transaction.test.ts passes 6/6 at d9ed371. With only the three production files reverted to the parent commit, 3 fail (0700 instead of 0755, getStatus() rejects with EACCES, and the unreadable foreign link isn't handled). So the tests pin the bug.
  • Real app (Electron dev build, throwaway profile). I pointed ORCA_CLI_INSTALL_PATH at a link I couldn't read (chmod -h 0300, so readlink fails with EACCES):
Before (parent commit) After (this PR)
before after
Refreshing CLI status raises Error invoking remote method 'cli:getInstallStatus': Error: EACCES: permission denied, readlink ... (the toast is clipped at the bottom right of the capture). The card shows "...cannot be read. Register again to repair it." with no error and no target line.

Also checked: a readable link to an older Orca.app looks the same before and after. Registering into a user-writable path works without an admin prompt and produces a 0755 link. I didn't drive the real admin-password prompt; only the test's stand-in runner covers that.

Requested changes

1. Use one ownership rule, not two. For an unreadable link, the root script decides "is this Orca's?" with its own pattern, *.app/Contents/Resources/bin/<name> or the exact launcher. That pattern doesn't match isManagedSymlinkTarget, in both directions:

  • It refuses links that inspection treats as Orca's. Repair then fails right after the admin prompt (exit 73). This covers dev or generated launchers under the profile's cli/bin (including the sibling dev profile's orca-dev) and raw targets containing .., such as /Applications/Orca.app/Contents/Resources/bin/../bin/orca. Inspection resolves the path before checking it; the shell pattern doesn't.
  • It accepts /tmp/.app/Contents/Resources/bin/orca. Shell * matches an empty name, while the regex requires at least one character before .app, so inspection calls this a conflict.

The packaged case (/Applications/Orca.app/...) works fine, so this only affects edge cases. Still, two copies of the ownership rule will keep drifting. A simpler shape: when the link can't be read, the privileged step only makes it readable and deletes nothing. For example:

[ -L "$cmd" ] && [ "$(stat -f '%d:%i' "$cmd")" = "<dev:ino>" ] && chmod -h 755 "$cmd"

Then re-inspect and continue through the normal path with the normal isManagedSymlinkTarget check. The shell predicate goes away, and so does problem 2: a foreign link then shows as the usual "points to a non-Orca launcher" conflict. For users hit by #19120 the link already points at the current launcher, so after that one prompt it reads as installed. A link to an older app path would need a second prompt to replace it, which seems acceptable for a one-time repair. If you'd rather keep the shell check, it at least needs to match the regex's rules: a non-empty name before .app, and the profile launcher roots.

2. Explain the refusal. When root refuses an unreadable foreign link, the script restores it and exits 73 with empty stderr, so the user sees a generic osascript failure right after Settings told them "Register again to repair it". If you keep that path, have it print a plain sentence the error notice can show, along the lines of "/usr/local/bin/orca belongs to another program, so Orca left it in place."

3. Optional, same root cause, not new in this PR. mkdir -p for the command directory still runs under umask 077, so any parent directories the script creates end up root-owned 0700 and the user can't traverse to the link. That happens with ORCA_CLI_INSTALL_PATH under a protected, missing parent. Setting umask 022 for the script and creating only the private directories with mkdir -m 700 (the transaction and publish directories) would fix publication and parent directories together, and you wouldn't need the subshell around ln -s.

Testing note: if you keep a root-side ownership check, one small table test comparing it against isManagedSymlinkTarget would pin the parity. If you switch to the "make it readable, then re-inspect" approach, the existing repair test mostly covers it.

… repair unreadable ones

The privileged install script ran under umask 077, and macOS applies the
umask to symlinks too, so the root-owned command was 0700. macOS also
enforces a symlink's own mode on readlink, so Settings threw EACCES and
the launcher could not resolve the app bundle. The script now runs under
umask 022 and creates only its transaction directories private, which
also fixes parent directories it creates. An existing link the user
cannot read reports as stale; registering again asks root to make it
readable, then the normal ownership check decides what happens to it.
@AmoabaKelvin
AmoabaKelvin force-pushed the fix-macos-cli-symlink-readable branch from d9ed371 to 27f9002 Compare October 15, 2026 23:52

@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: 2ac0e276-f3e2-41b0-84c2-320cd226b4a5
📥 Commits

Reviewing files that changed from the base of the PR and between d9ed3719b58be2a1053090909607758028aab49b and 27f9002.

📒 Files selected for processing: 3
  • src/main/cli/cli-command-filesystem-transaction.ts
  • src/main/cli/cli-command-installation.ts
  • src/main/cli/cli-command-privileged-transaction.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.

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

Thanks Kelvin, this round addresses all three points:

  • One ownership rule. For an unreadable link, the admin step now only makes the link readable, after checking it's still the same link. The normal isManagedSymlinkTarget check then decides, so there's no second pattern to drift. A link to the current launcher takes one prompt, an older Orca launcher is replaced after a second prompt, and a foreign link is refused with the existing "Refusing to replace non-Orca command" message.
  • Refusal message. It's covered by the above; the unexplained exit-73 path for foreign links is gone.
  • Permissions. The script runs under umask 022, and only the transaction and publish directories use mkdir -m 700, so new parent directories and the link both come out readable.

I also confirmed the new admin prompt only appears on register and remove, never when Settings reads the status. I reviewed this version by reading the diff. The earlier real-app and macOS test runs were on the previous head, and I haven't run the new tests myself.

One optional follow-up, not blocking: the make-readable step checks [ -L ] and the device and inode, then runs chmod -h 755 on the live path as root. If something swapped a regular file into that path between the check and the chmod, root would change that file's mode. That needs a writable command directory and a very narrow race during the password prompt, so I'm fine landing as is. Doing the chmod on the entry after moving it into the private transaction directory, as the install path already does, would close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: macOS CLI registration creates a 0700 /usr/local/bin/orca symlink; Settings crashes with EACCES on readlink

2 participants