Skip to content

fix(daemon): inspect running process to detect severed macOS TCC attribution (#20007) - #20072

Closed
denis-sj wants to merge 2 commits into
stablyai:mainfrom
denis-sj:fix/daemon-tcc-attribution-severed-check-20007
Closed

denis-sj wants to merge 2 commits into
stablyai:mainfrom
denis-sj:fix/daemon-tcc-attribution-severed-check-20007

Conversation

@denis-sj

Copy link
Copy Markdown
Contributor

Problem

Fixes #20007.

When ShipIt installs an update on macOS, it parks the previously running bundle in $TMPDIR/com.stablyai.orca.ShipIt.<rand>/ and places the new app bundle into /Applications/Orca.app. The terminal daemon continues running from the parked bundle.

On a subsequent update, ShipIt deletes the parked copy. The daemon process's executable becomes unlinked from disk, causing macOS tccd to fail to validate the daemon's guest code identity (codesign -vvv +<pid> fails with host has no guest with the requested attributes). As a result, terminals spawned by this daemon silently lose access to TCC-protected locations (~/Documents, ~/Desktop, ~/Downloads), returning EPERM / Operation not permitted.

Previously, getMacDaemonTccAttributionHealth() checked whether spawnerExecPath exists on disk (/Applications/Orca.app/Contents/MacOS/Orca). Because the update recreated /Applications/Orca.app, this check returned 'intact', concealing the severed attribution, preventing daemon replacement, and suppressing the UI warning banners.

Solution

  1. Added checkMacProcessTccAttributionIntact(pid: number) in src/main/daemon/daemon-tcc-attribution.ts to directly inspect the running daemon process:
    • Uses /usr/sbin/lsof -a -p <pid> -d txt -Fn to verify that the daemon's mapped text/binary file has not been unlinked/deleted from disk.
    • Uses /usr/bin/codesign -v +<pid> to verify that the running process's code signature / guest identity remains valid.
    • Runs both probes concurrently via Promise.all and fails open if probe tools cannot be executed.
  2. Updated getMacDaemonTccAttributionHealth() to mark the daemon as 'severed' if either spawnerExecPath does not exist or checkMacProcessTccAttributionIntact() reports that the running process binary is unlinked or its code signature is invalid.
  3. Updated unit tests in src/main/daemon/daemon-tcc-attribution-main-thread.test.ts to mock the process probes and verify that in-flight calls remain deduplicated without redundant subprocess invocations.
  4. Added a reproduction unit test in src/main/daemon/daemon-tcc-attribution.test.ts verifying that when a daemon process's binary is unlinked from disk while spawnerExecPath exists, getMacDaemonTccAttributionHealth() accurately reports 'severed'.

Verification

  • pnpm test src/main/daemon/daemon-tcc-attribution.test.ts src/main/daemon/daemon-tcc-attribution-main-thread.test.ts (14/14 passed)
  • pnpm test src/main/daemon/daemon-pty-adapter-daemon-recovery.test.ts src/main/daemon/daemon-bundle-staleness.test.ts (all passed)
  • pnpm tc:node (clean, 0 errors)
  • pnpm run check:code-quality:changed (0 findings)
  • pnpm format (clean)

@coderabbitai

coderabbitai Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: db458252-515a-43a6-858f-04dbc349acbc

📥 Commits

Reviewing files that changed from the base of the PR and between 03b0d7c and c285cde.

📒 Files selected for processing (3)
  • src/main/daemon/daemon-tcc-attribution-main-thread.test.ts
  • src/main/daemon/daemon-tcc-attribution.test.ts
  • src/main/daemon/daemon-tcc-attribution.ts
💤 Files with no reviewable changes (1)
  • src/main/daemon/daemon-tcc-attribution-main-thread.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/daemon/daemon-tcc-attribution.test.ts

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


📝 Walkthrough

Walkthrough

The daemon TCC health check now runs a codesign probe against the running daemon process. It reports severed when the daemon binary is missing or the probe fails, and clears completed cached checks. Tests mock the expanded subprocess sequence and verify detection after the running daemon binary is unlinked.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to c285c

The daemon attribution checks and cache lifecycle changes do not leave an identified actionable merge risk.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the problem, solution, linked issue, and verification results, but it does not follow the repository template. It omits or renames several required sections, including ELI5, W… Update the description to use all template headings. Add an ELI5 summary, separate What Changed and Why sections, and include the required Visual Proof section with N/A and a reason if no visual or interaction change exists. Add the Testi…
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: inspecting the running daemon process to detect severed macOS TCC attribution.
Linked Issues check ✅ Passed Issue #20007 requires detection of a severed daemon based on the running process, not only spawnerExecPath. The PR adds checkMacProcessTccAttributionIntact(pid), probes the process with lsof and…
Out of Scope Changes check ✅ Passed The implementation changes and test updates are directly connected to issue #20007. The tests support the new process-attribution detection and cache behavior. No unrelated product behavior or unrelat…
Full details: Description check

Explanation

The description explains the problem, solution, linked issue, and verification results, but it does not follow the repository template. It omits or renames several required sections, including ELI5, What Changed, Why, Visual Proof, Testing, Review, Agent skill upstream boundary, Notes, and Checklist.

Resolution

Update the description to use all template headings. Add an ELI5 summary, separate What Changed and Why sections, and include the required Visual Proof section with N/A and a reason if no visual or interaction change exists. Add the Testing checkboxes and platform coverage, AI Disclosure when applicable, Review, Agent skill upstream boundary, Notes, and Checklist sections.

  • Fix all pre-merge checks with AI

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: 30fcd7c3-81e3-44c4-81b3-a92a9a147247

📥 Commits

Reviewing files that changed from the base of the PR and between 5fa62fe and 418356d11c7ecfb92838ce19e3aca589b1047357.

📒 Files selected for processing (3)
  • src/main/daemon/daemon-tcc-attribution-main-thread.test.ts
  • src/main/daemon/daemon-tcc-attribution.test.ts
  • src/main/daemon/daemon-tcc-attribution.ts

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

@denis-sj
denis-sj force-pushed the fix/daemon-tcc-attribution-severed-check-20007 branch from 418356d to 03b0d7c Compare September 11, 2026 07:54

@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 critical issues — the codesign-based detection is sound; minor suggestions inline.

Reviewed changes

  • checkMacProcessTccAttributionIntact — new async probe that runs /usr/bin/codesign -v +<pid> and maps a non-zero exit to severed, failing open on ENOENT/timeout.
  • getMacDaemonTccAttributionHealth — now returns severed when spawnerExecPath is missing and otherwise gates on the codesign probe, preserving the in-flight dedup.
  • Tests — main-thread test asserts the extra codesign subprocess and updated dedup counts; a darwin-only reproduction test unlinks a copied daemon binary and expects severed.

The core fix is correct: codesign -v +pid fails with host has no guest exactly as #20007 diagnosed once the daemon's on-disk binary is unlinked, and it correctly distinguishes the "parked but still valid" state from the severed one.

ℹ️ PR description no longer matches the implementation

The body describes checkMacProcessTccAttributionIntact as running two probes — /usr/sbin/lsof -a -p <pid> -d txt -Fn and /usr/bin/codesign -v +<pid> — "concurrently via Promise.all". The code only runs codesign; there is no lsof probe and no Promise.all. The codesign probe alone is sufficient, so this is a description cleanup rather than a missing feature, but a reviewer should not have to reconcile the discrepancy.

ℹ️ Nitpicks

  • checkMacProcessTccAttributionIntact is exported but only referenced within daemon-tcc-attribution.ts — drop the export unless the tests were meant to import it directly.
  • The codesign result is deliberately absent from the cache key, which is safe only because severing occurs across app relaunches (which reset the module-level cache). A one-line comment on getMacDaemonTccAttributionCacheKey documenting that reasoning would prevent a future maintainer from "fixing" it into a staleness bug.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

…al checks (stablyai#20007)

- In daemon-tcc-attribution.ts, clear cachedMacDaemonTccAttributionHealth
  once the pending promise settles so that caching only deduplicates
  concurrent in-flight probes rather than retaining settled 'intact'
  results across sequential calls. This ensures subsequent checks detect
  when a running daemon's binary is unlinked from disk (STA-3491, stablyai#20007).
- In daemon-tcc-attribution.test.ts, assert intact before unlinking
  daemonBin to verify the state transition to severed (addressing
  Pullfrog review).
- In daemon-tcc-attribution-main-thread.test.ts, align deduplication
  assertions to verify concurrent in-flight deduplication without synchronous
  spawns (addressing CodeRabbit review).

Addresses review feedback on stablyai#20072.

@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

Since the prior pullfrog review (03b0d7c):

  • Stopped caching settled results — getMacDaemonTccAttributionHealth now clears its module-level entry in a finally for every settled outcome, so a sequential check re-inspects the running process instead of returning a cached intact after the daemon binary is unlinked. Concurrent in-flight calls still share one pending.
  • Reproduction test now proves the transition — added the pre-unlink expect(...).toBe('intact') at daemon-tcc-attribution.test.ts:167, so the intact → unlink → severed case cannot pass for an unrelated codesign failure.
  • Main-thread test updated — the mock now distinguishes ps from /usr/bin/codesign, and the expected subprocess counts reflect that sequential calls re-probe.

The eviction guard (cachedMacDaemonTccAttributionHealth?.pending === pending) is interleaving-safe, and moving to finally also closes a latent leak in the old health === 'unknown'-only eviction, where a rejected pending stayed cached indefinitely.

ℹ️ Sequential checks now pay both probes on the new-session path

With the settled cache removed, every call spawns ps (identity verification) and codesign. On macOS this sits on the new-session path (daemon-pty-session-spawn.ts:183), the Settings IPC path (pty-management.ts:66), and replacement/adoption preflight, so each new terminal re-runs probes it previously served from the cached intact. This is the intended tradeoff — the cache key cannot observe the daemon binary's on-disk state — and codesign fails open, so no action is needed; noting it only so the added per-session cost is deliberate.

Pullfrog  | View workflow run | Using openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@denis-sj

Copy link
Copy Markdown
Contributor Author

Thank you for the reviews @coderabbitai and @pullfrog!

Feedback addressed in commit c285cde16:

  • Cache invalidation / in-flight dedup: The cache mechanism now clears pending in a finally block so sequential checks perform fresh probes without returning stale intact state after an unlink, while still deduplicating concurrent in-flight calls.
  • State transition test: daemon-tcc-attribution.test.ts now explicitly asserts expect(await getMacDaemonTccAttributionHealth(dir, socketPath, tokenPath)).toBe('intact') before unlinking daemonBin and severed after unlinking to prove the state transition.
  • All 14 tests in daemon-tcc-attribution.test.ts and daemon-tcc-attribution-main-thread.test.ts pass cleanly.

@pullfrog

pullfrog Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

No new changes to review: c285cde is the current head and has already been covered by Pullfrog's prior incremental review (5176487846's follow-up, ✅ no new issues), with no commits landed since. The one open thread — the missing pre-unlink intact assertion at daemon-tcc-attribution.test.ts:172 — is addressed in c285cde and already resolved, so no further review is warranted.

Task list (5/6 completed)
  • Checkout PR and read incremental + full diffs
  • Fetch prior Pullfrog reviews and retire addressed threads
  • Triage incremental changes, read related code/tests
  • Dispatch specialists for unresolved questions (if any)
  • Aggregate, draft, self-critique findings
  • Submit exactly one review or report_progress

Pullfrog  | View workflow run | via Pullfrog | Using openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@denis-sj Thanks for the update. The finally cleanup preserves in-flight deduplication and enables fresh sequential probes. The intact-to-severed test covers the required regression case.

🐇✨


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

You are interacting with an AI system.

@AmethystLiang

Copy link
Copy Markdown
Contributor

Thanks for the PR! Looking into it

@AmethystLiang

Copy link
Copy Markdown
Contributor

Hey @denis-sj — thank you so much for this! 🙏 Your PR nailed the root cause of the severed macOS TCC attribution / EPERM-on-Documents issue, and it was genuinely a big help. We took real inspiration from your approach here.

We've consolidated the fix into #20452, and I've added you as a commit co-author on that PR so your contribution is properly attributed. Going to close this one in favor of that — but truly, thank you for digging into this and sharing such a clear diagnosis. Really appreciate you! 🎉

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.

macOS: terminal daemon loses TCC access after two updates — the severed check inspects spawnerExecPath, which the update recreates

2 participants