Repository navigation
fix: keep macOS daemon terminals working after TCC attribution is severed - #20452
AmethystLiang wants to merge 2 commits into
Conversation
…ered On macOS every access from a daemon-hosted terminal is attributed to the app that forked the daemon. If an evaluation lands during the updater's bundle swap the resolution fails and the denial is cached against the daemon's lineage for its lifetime, so every terminal starts getting EPERM under Documents/Desktop/Downloads while the daemon still passes health probes. Detect the severed attribution via measured folder-access divergence, persist denial evidence beside the PID record (matched by PID, start time, and launch nonce) so relaunch does not forget it, and keep live sessions alive: replace the daemon at launch when idle, otherwise adopt it in degraded in-process PTY fallback mode. Add the missing Desktop usage string and document the mechanism and structural fix. Co-authored-by: den-sj <[email protected]>
2d15e56 to
281e0c2
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between 2d15e561a70dc94b5d09483cffd8096cc2c5b02c and a74171f. 📒 Files selected for processing (9)
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughThe PR adds TCC attribution states, process identity checks, persisted denial evidence, and ShipIt staging-path classification. It routes fresh PTY spawns through an in-process provider when daemon attribution is severed while preserving live sessions. It adds guarded degradation and recovery callbacks, runtime event tracking, provider lifecycle cleanup, macOS usage metadata, documentation, tests, and updated permission messages. Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: 🟡 Moderate · up to French users can receive obsolete recovery guidance, and some macOS terminal launches can be delayed while preserving live sessions. Resolve these before merge unless the startup delay and untranslated guidance are explicitly accepted. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: cc09523e-667e-4e4b-bf4e-3192e4510cdb
📥 Commits
Reviewing files that changed from the base of the PR and between f2b6434 and 2d15e561a70dc94b5d09483cffd8096cc2c5b02c.
📒 Files selected for processing (48)
.gitignoreAGENTS.mdconfig/electron-builder.config.cjsdocs/reference/macos-daemon-tcc-attribution.mdsrc/main/daemon/daemon-adoption-telemetry-event.tssrc/main/daemon/daemon-init-dependency-mocks.tssrc/main/daemon/daemon-init-endpoint-adoption.test.tssrc/main/daemon/daemon-init-fresh-import.tssrc/main/daemon/daemon-init-mock-types.tssrc/main/daemon/daemon-init-provider-installation.test.tssrc/main/daemon/daemon-init-test-harness.tssrc/main/daemon/daemon-provider-init.tssrc/main/daemon/daemon-provider-restart.tssrc/main/daemon/daemon-provider-state.tssrc/main/daemon/daemon-pty-adapter-daemon-recovery.test.tssrc/main/daemon/daemon-pty-cwd-denial.test.tssrc/main/daemon/daemon-pty-cwd-denial.tssrc/main/daemon/daemon-pty-daemon-recovery.tssrc/main/daemon/daemon-pty-runtime-state.tssrc/main/daemon/daemon-pty-session-spawn.tssrc/main/daemon/daemon-replacement-preflight.tssrc/main/daemon/daemon-severed-attribution-degrade.test.tssrc/main/daemon/daemon-severed-attribution-degrade.tssrc/main/daemon/daemon-tcc-attribution-main-thread.test.tssrc/main/daemon/daemon-tcc-attribution.test.tssrc/main/daemon/daemon-tcc-attribution.tssrc/main/daemon/daemon-tcc-denial-record.test.tssrc/main/daemon/daemon-tcc-denial-record.tssrc/main/daemon/degraded-daemon-fresh-spawn-routing.test.tssrc/main/daemon/degraded-daemon-fresh-spawn-routing.tssrc/main/daemon/degraded-daemon-pty-provider.tssrc/main/ipc/pty-degraded-fallback-lifecycle.test.tssrc/main/ipc/pty-listener-teardown-and-orphans.test.tssrc/main/ipc/pty.tssrc/main/ipc/pty/kill-all.tssrc/main/ipc/pty/provider/bind-listeners.tssrc/main/ipc/pty/provider/local-configure.test.tssrc/main/ipc/pty/provider/local-configure.tssrc/main/ipc/pty/provider/registry.tssrc/main/ipc/pty/register-handlers.tssrc/main/providers/local-pty-runtime-events.tssrc/main/providers/local-pty-session-activation.tssrc/preload/api/pty-management-api.tssrc/renderer/src/components/settings/TerminalTccAttributionNotice.tsxsrc/renderer/src/hooks/useMacTccAttributionSeveredNotice.tssrc/renderer/src/i18n/locales/en.jsonsrc/shared/daemon-adoption-telemetry.test.tssrc/shared/daemon-adoption-telemetry.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
| @@ -56,6 +56,10 @@ export async function prepareDaemonReplacement( | |||
| | undefined | |||
| let confirmedReplacement = false | |||
| const health = await checkDaemonHealth(socketPath, tokenPath) | |||
| const preserveWithAttribution: PreserveDaemon = async (mode) => { | |||
| const attribution = await getMacDaemonTccAttributionHealth(runtimeDir, socketPath, tokenPath) | |||
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Use evidence-only attribution checks during replacement preflight.
This call can run the two-second codesign diagnostic after recoveryDeadlineMs has expired. A healthy daemon with an unhealthy resolver or stale bundle can therefore delay terminal startup beyond the absolute recovery budget.
This function only acts on severed. Denial evidence establishes that state before diagnostics. Pass evidenceOnly: true here and at Lines 124-128.
Proposed fix
- const attribution = await getMacDaemonTccAttributionHealth(runtimeDir, socketPath, tokenPath)
+ const attribution = await getMacDaemonTccAttributionHealth(
+ runtimeDir,
+ socketPath,
+ tokenPath,
+ PROTOCOL_VERSION,
+ undefined,
+ true
+ )Apply the same arguments to the attribution query at Lines 124-128.
📝 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.
| const attribution = await getMacDaemonTccAttributionHealth(runtimeDir, socketPath, tokenPath) | |
| const attribution = await getMacDaemonTccAttributionHealth( | |
| runtimeDir, | |
| socketPath, | |
| tokenPath, | |
| PROTOCOL_VERSION, | |
| undefined, | |
| true | |
| ) |
| @@ -81,7 +81,7 @@ export function TerminalTccAttributionNotice(props: { | |||
| <p className="text-xs leading-snug"> | |||
| {translate( | |||
| 'auto.components.settings.TerminalTccAttributionNotice.body', | |||
| 'The terminal daemon was started by an Orca install that no longer exists, so macOS can’t attribute its commands to Orca — Accessibility and Automation grants are silently ignored (osascript fails with error -25211). Restarting the daemon fixes this; running terminal sessions will close.' | |||
| 'The terminal daemon reported a folder-access denial for a folder Orca can read. This can happen when macOS stops applying Orca’s permissions to an older daemon. Restarting the daemon may restore access; it will close running local terminal sessions. Save your work first.' | |||
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
set -eu
printf '%s\n' '--- affected component ---'
sed -n '1,125p' src/renderer/src/components/settings/TerminalTccAttributionNotice.tsx
printf '%s\n' '--- affected hook ---'
sed -n '1,115p' src/renderer/src/hooks/useMacTccAttributionSeveredNotice.ts
printf '%s\n' '--- locale files ---'
git ls-files 'src/renderer/src/i18n/locales/*'
printf '%s\n' '--- matching translation keys and values ---'
rg -n -C 2 'folder|daemon|Tcc|tcc|terminal' src/renderer/src/i18n/locales/en.json src/renderer/src/i18n/localesRepository: stablyai/orca
Length of output: 50370
🤖 get_repo_knowledge executed:
get_repo_knowledge stablyai/orca /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings
Length of output: 33395
🏁 Script executed:
set -eu
printf '%s\n' '--- translation calls ---'
rg -n -C 3 'translate|folder-access|folder|daemon|Restarting' \
src/renderer/src/components/settings/TerminalTccAttributionNotice.tsx \
src/renderer/src/hooks/useMacTccAttributionSeveredNotice.ts
printf '%s\n' '--- matching locale values ---'
python3 - <<'PY'
import json
from pathlib import Path
needles = ("folder-access denial", "folder Orca can read", "older daemon", "Restarting the daemon", "Save your work first")
for path in sorted(Path("src/renderer/src/i18n/locales").glob("*.json")):
data = json.loads(path.read_text())
hits = []
def walk(value, parts=()):
if isinstance(value, dict):
for key, child in value.items():
walk(child, parts + (key,))
elif isinstance(value, str) and any(needle in value for needle in needles):
hits.append((".".join(parts), value))
walk(data)
if hits:
print(path)
for key, value in hits:
print(f" {key}: {value}")
PY
printf '%s\n' '--- locale inventory ---'
git ls-files 'src/renderer/src/i18n/locales/*.json' | sortRepository: stablyai/orca
Length of output: 11683
🏁 Script executed:
set -eu
printf '%s\n' '--- translate implementation ---'
rg -n -C 5 'export function translate|function translate|const translate' src/renderer/src/i18n/i18n.ts
printf '%s\n' '--- exact catalog entries ---'
python3 - <<'PY'
import json
from pathlib import Path
paths = [
("auto", "components", "settings", "TerminalTccAttributionNotice", "body"),
("auto", "hooks", "useMacTccAttributionSeveredNotice", "description"),
]
for path in sorted(Path("src/renderer/src/i18n/locales").glob("*.json")):
data = json.loads(path.read_text())
print(path)
for parts in paths:
value = data
present = True
for part in parts:
if not isinstance(value, dict) or part not in value:
present = False
break
value = value[part]
print(" " + ".".join(parts) + ": " + (repr(value) if present else "<missing>"))
PYRepository: stablyai/orca
Length of output: 2928
Update the French TCC notice translations.
translate uses the catalog value when the key exists. fr.json still contains the previous text for both affected keys, so French users do not receive the new folder-denial and daemon-restart wording. The keys are absent from es.json, ja.json, ko.json, and zh.json, so those locales use the inline fallback as intended.
📍 Affects 2 files
src/renderer/src/components/settings/TerminalTccAttributionNotice.tsx#L84-L84(this comment)src/renderer/src/hooks/useMacTccAttributionSeveredNotice.ts#L75-L75
There was a problem hiding this comment.
Caution
This PR fails its own unit tests on Linux CI. src/main/daemon/daemon-tcc-attribution-main-thread.test.ts has three failing tests because the new inspectMacProcessCodeIdentity probe returns 'unknown' when /usr/bin/codesign is absent — always true on the ubuntu-latest runners that unit-tests.yml uses.
Reviewed changes
- Severed-attribution detection (
daemon-tcc-attribution.ts): verdict type gainsat-risk;severedis now only a measured cwd-access divergence, persisted beside the pid record and matched by pid/start/nonce. Missing spawner binary or unresolvable image isat-riskand fails open. - Degrade on severed (
daemon-severed-attribution-degrade.ts): wraps the installed adapter inDegradedDaemonPtyProvider(fallback =getInProcessPtyProvider()), discovers routes before the swap, and re-checks provider/restart after async discovery. - Admission wiring (
daemon-pty-session-spawn.ts,daemon-pty-cwd-denial.ts,daemon-pty-daemon-recovery.ts,daemon-replacement-preflight.ts): severed + live sessions preserves and degrades; severed + zero sessions replaces.onSeveredWithLiveSessionsfires once. - In-process fallback plumbing (
registry.ts,kill-all.ts,local-configure.ts,register-handlers.ts,local-pty-runtime-events.ts): a distinct immutable in-process provider, plus a WeakSet so the runtime does not double-deliver events through the degraded wrapper. - Docs/packaging:
NSDesktopFolderUsageDescription, new TCC reference doc,AGENTS.mdsection, notice copy, andSHIPIT_STAGING_PATHmatching$TMPDIR/*.ShipIt.*.
Verified codesign --verify +<pid> against the codesign(1) man page. Focused suites pass except the one noted above.
ℹ️ Nitpicks
daemon-replacement-preflight.ts:139— the log string for the zero-session severed branch still saysspawning app binary no longer exists, but that condition is nowat-risk, notsevered.pty-listener-teardown-and-orphans.test.ts:325— the comment says the non-local second window keeps orphan cleanup off (only the renderer-gate reset listener remains), but the assertion was changed totoHaveLength(2)and the in-process sweep is now registered there. Update the comment to match the new behavior.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| // #17696: the symptom itself outranks a cached intact verdict and every proxy. | ||
| writePidRecord('1.2.3', true, 'launch-denied') | ||
| await expect(getMacDaemonTccAttributionHealth(dir, socketPath, tokenPath)).resolves.toBe( | ||
| 'intact' |
There was a problem hiding this comment.
This test — and the pre-existing 'intact' expectations in 'deduplicates identity inspection by daemon generation…' (line 144) and 'retries an indeterminate identity inspection' (line 179) — fail on Linux CI. beforeAll only fakes process.platform = 'darwin'; it does not provide /usr/bin/codesign, so the default inspectMacProcessCodeIdentity returns 'unknown' and the result is 'unknown', not 'intact'. unit-tests.yml runs on ubuntu-latest and does not exclude this file, so all three tests are red.
Technical details
# Linux CI fails when the default codesign probe is not stubbed
## Affected sites
- `src/main/daemon/daemon-tcc-attribution-main-thread.test.ts:144` — `resolves.toEqual(['intact','intact'])`, but `inspectMacProcessCodeIdentity` returns `unknown` off macOS.
- `src/main/daemon/daemon-tcc-attribution-main-thread.test.ts:179` — existing test, same cause; after `psError.value = null` the health is `unknown`.
- `src/main/daemon/daemon-tcc-attribution-main-thread.test.ts:191` — new test, same cause at the first `intact` assertion.
## Root cause
- `getMacDaemonTccAttributionHealth` now ends with `inspectCodeIdentity(parsedPid.pid)` and the default is `inspectMacProcessCodeIdentity`, whose first guard is `!existsSync('/usr/bin/codesign') => 'unknown'`.
- `existsSync` is a real filesystem call, so faking `process.platform` is not enough on `ubuntu-latest`.
- Confirmed locally: `pnpm exec vitest run --config config/vitest.config.ts src/main/daemon/daemon-tcc-attribution-main-thread.test.ts` -> 3 failed / 5 passed.
## Required outcome
- These three tests must assert `intact` deterministically on any host while still exercising the codesign-probe branch that distinguishes `intact`/`at-risk`.
## Suggested approach (optional)
- Pass the injectable probe explicitly, e.g. `const inspect = async () => 'valid' as const` into the calls that expect `intact` (the parameter already exists for exactly this). `at-risk` assertions after `rmSync(spawnerExecPath)` do not reach the probe.There was a problem hiding this comment.
ℹ️ No new issues in the incremental commit. The Linux-CI test failure flagged in the prior review is unchanged, so the PR is still not mergeable until that is fixed.
Reviewed changes since 2d15e561a7
- Test-only type-assertion cleanup (
a74171feca): adds a typedcreatePtyProviderTestDoublehelper insrc/main/providers/pty-provider-test-double.tsandMockSpawner/MockAdapterconstructor types, then replacesas unknown as/as nevercasts across the degraded-fallback, fresh-spawn-routing, local-configure, and daemon-init tests. No production behavior changed;tc:nodeand the changed-code quality gate are clean, and all touched test suites pass.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
I am still being hit by this every other upgrade, do you think you will be able to update this soon? |
|
Closing as stale: the code it changes no longer exists on main. |

ELI5
On macOS, when Orca auto-updates, its background helper (the daemon that hosts your terminals) can lose permission to your Documents/Desktop/Downloads folders and start throwing
EPERMon everything there — even though Full Disk Access is still granted and a fresh terminal works fine. This PR detects that situation and keeps your terminals working instead of silently breaking.What Changed
Adds detection for a "severed" TCC attribution on the macOS daemon (a measured folder-access divergence), persists the denial evidence beside the PID record so it survives app relaunch, and changes admission so a severed daemon is either replaced at launch (zero live sessions) or adopted in a degraded in-process PTY fallback mode (live sessions) — never killed out from under running terminals. Also adds the missing
NSDesktopFolderUsageDescriptionusage string, and documents the mechanism and structural fix indocs/reference/macos-daemon-tcc-attribution.md.Why
Squirrel updates move
/Applications/Orca.appout and the new bundle in, leaving the path unresolvable for a moment. A daemon that outlives enough updates eventually has a TCC evaluation land in that window; the denial is cached against the daemon's lineage for its entire lifetime, so every terminal it hosts getsEPERMwhile the daemon still passes every health probe. Killing the daemon would fix it but drop every live session, so the right behavior is to degrade fresh terminals to in-process attribution and reserve replacement for when nothing is running.Linked Issue
Fixes #17696 (STA-3491)
Visual Proof
N/A — no visual change. The behavior is process/permission routing; the only user-visible surface is the existing TCC attribution notice string.
Testing
Platforms: logic is macOS-specific and gated behind runtime checks; other platforms unaffected.
AI Disclosure
Internal contributor — section not applicable.
Review
Agent skill upstream boundary
Notes
Security: no new permissions beyond the required Desktop usage string. Cross-platform: macOS-only behavior behind runtime checks. Remote SSH: execution-host attribution unchanged. Backwards compatibility: denial evidence is additive beside the existing PID record; a replacement daemon starts clean.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)