Skip to content

fix(daemon): judge severed macOS TCC attribution by the daemon's own executable - #21826

Open
davbebawy wants to merge 4 commits into
stablyai:mainfrom
davbebawy:fix/daemon-severed-check-own-executable
Open

davbebawy wants to merge 4 commits into
stablyai:mainfrom
davbebawy:fix/daemon-severed-check-own-executable

Conversation

@davbebawy

@davbebawy davbebawy commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Orca keeps a background helper (the terminal daemon) running across app updates so your terminals survive. On macOS, an update moves the old app bundle aside and later deletes it, so the helper ends up running from a program file that no longer exists. macOS then can no longer tell that the helper belongs to Orca, and every shell it hosts silently loses access to Documents, Desktop, Downloads and the local network. Orca already has a guard that should notice this and restart the helper. But the guard looks at the wrong file (the app binary, which the update recreates), so it never fires. This PR makes the guard look at the helper's own program file, and makes Orca say so in Settings when it decides not to restart the helper because terminals are still running.

What Changed

Before: after two auto-updates (or one, for Local Network), ls ~/Documents in every Orca terminal fails with Operation not permitted, node/adb/Homebrew Python get EHOSTUNREACH on the LAN, and the attribution check reports the daemon as intact. Nothing in the app points at the Local Network variant; the only fix is a manual daemon restart.

After: the attribution check detects the condition. With no live sessions, Orca replaces the daemon at launch or before the next terminal spawn (existing behaviour, now reachable). With live sessions, it keeps them, writes a daemon.replacement_deferred trace span (reason and session count) to the trace file, and the existing Settings attribution notice names the folders and Local Network and shows how many live sessions Orca declined to kill.

Mechanism:

  • getMacDaemonTccAttributionHealth decided with existsSync(spawnerExecPath). spawnerExecPath is /Applications/Orca.app/Contents/MacOS/Orca, which every in-place update deletes and recreates, so the verdict was always intact. It now also reads the daemon pid's own executable through the code-identity probe that feat(telemetry): report the macOS daemon's code identity on adoption and folder-denial events #22171 added for telemetry (daemon-mac-code-identity.ts, codesign --display --verbose=1 +<pid>). The verdict is severed when the identity is unresolvable (executable unlinked) or parked (inside a Squirrel ShipIt directory), when the resolved path no longer exists, or when it lies outside the installed app bundle recorded in spawnerExecPath. A failed probe keeps the old spawner check, so nothing gets stricter where codesign cannot answer.
  • The probe module gains inspectDaemonMacCodeIdentity, which returns the resolved path beside the verdict. getDaemonMacCodeIdentity (telemetry) now maps from it, so both readers share the same coalesced spawn and classifier. Telemetry output is unchanged.
  • The per-daemon-generation cache remembers the resolved path and re-probes when that path disappears, so a daemon judged before the second update is judged again after it without waiting for a pid-record change.
  • New daemon-replacement-deferral.ts records every "wanted to replace, kept it because of live sessions" decision from the launch preflight and the pre-spawn recovery paths, and exposes it through pty:management:macTccAttribution next to the existing folderAccessMismatch. The Settings notice shows the kept-session count for any declined reason, because after an update the stale-bundle check usually declines first. Replacement, a successful respawn or a Manage Sessions restart clears it. A repeated identical decision (one per new terminal) does not emit again.
  • One notice per cause. Until now the app-wide severed toast almost never fired, because the check always said intact. With the check fixed, a user with a measured folder denial would get both the severed toast and fix(macos): tell the user when Orca's terminal service can't read their folder, and walk them through the fix #21923's folder toast for one daemon. While a folder notice the user has not dismissed is up for folderAccessMismatch, the severed toast now stays down (and is taken down if already up), and the folder toast with its Fix dialog owns the cause. Severed with no folder denial, which is the Local Network case, still toasts. This replaces fix(macos): tell the user when Orca's terminal service can't read their folder, and walk them through the fix #21923's raises both notices test with a one-notice test.

Off macOS nothing changes: the check returns unknown before any probe, and the deferral record is read only by the macOS notice.

Why

The signal that predicts the failure is the daemon's code identity, not the spawner path. On the reporter machines in #20007 and on the author's (Orca 1.4.205, daemon 1.4.201, macOS 27.0), codesign --display +<daemon pid> fails with No such file or directory, responsibility_get_pid_responsible_for_pid() returns the pid itself for every shell under the daemon, tccd logs Platform binary prompting is 'Deny', and unbundled tools hit the Local Network default-deny while Apple-signed curl/nc work. A fresh daemon fixes all of it.

Relationship to merged work:

Alternatives considered: ps -o comm= echoes argv[0] as spawned, so it cannot see the parked copy; lsof -p (#20072) can take seconds on a busy machine; a native proc_pidpath addon is a new build target for one syscall.

Linked Issue

Fixes #20007. Builds on #22171; complements #21923.

Visual Proof

N/A for the detection change. The only UI change is text inside the existing amber attribution notice: the body names Documents/Desktop/Downloads and Local Network, and a second line shows the live-session count when Orca declined to restart the daemon. No layout or component changes.

Testing

Platform tested: macOS only (Apple Silicon, macOS 27.0). Linux and Windows are unaffected by construction (process.platform !== 'darwin' returns unknown before any probe); CI covers their suites.

  • pnpm tc:node, pnpm tc:web and check:code-quality:changed (0 new findings) pass on the rebased branch.

  • src/main, src/shared and the touched renderer suites: 18814 passed. 2 tests in repro-13767-shell-ready-marker-lost-to-exec.test.ts fail identically on a clean upstream/main checkout on this machine and touch nothing here.

  • daemon-tcc-attribution.test.ts (#20007 block). Against main's check, the first five fail with expected 'intact' to be 'severed':

    • spawner binary exists, daemon executable unlinked (unresolvable) -> severed
    • resolved executable path no longer exists -> severed
    • executable resolves inside a com.stablyai.orca.ShipIt.* bundle -> severed
    • a cached intact is inspected again once the executable disappears -> severed
    • end to end against the real codesign(1): a daemon-shaped copy of the test's node binary runs from a fake Orca.app; the bundle is renamed aside and a fresh spawner written (update 1) -> severed; the parked copy is deleted (update 2) -> severed
    • plus classifier cases for parked, probe-failed fallback and an unbundled spawner.
  • daemon-mac-code-identity.test.ts: feat(telemetry): report the macOS daemon's code identity on adoption and folder-denial events #22171's cases unchanged and passing, plus the path returned by inspectDaemonMacCodeIdentity.

  • daemon-replacement-deferral.test.ts (record, clear, trace, one emit for a repeated decision), daemon-pty-adapter-daemon-recovery.test.ts, daemon-adoption-telemetry-event.test.ts: pass.

  • daemon-init-restart-sequence.test.ts: a Manage Sessions restart clears the deferral record (fails without the fix).

  • TerminalTccAttributionNotice.test.tsx: the count shows for a stale_bundle deferral and hides when attribution is intact.

  • useMacTccAttributionSeveredNotice.test.tsx: severed plus a folder denial raises only the folder toast; a severed toast already up is taken down when the denial arrives. It comes back if the denial clears while attribution stays severed (unless the user had already dismissed it), and it shows when the user has already closed the folder notice, which cannot come back.

  • Manual, read-only, against a live severed daemon on the author's Mac (spawner path present, lsof maps a deleted ShipIt.* bundle): codesign --display --verbose=1 +<pid> -> No such file or directory, which classifies as unresolvable -> severed. The daemon was not restarted.

  • I manually tested these changes locally

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

AI Disclosure

Written with Claude (Anthropic, via Claude Code), directed and reviewed by the author.

Review

  • Cross-platform: every probe is behind process.platform === 'darwin'. codesign runs through runProcess from src/shared/child-process/. Bundle detection uses node:path.
  • SSH / remote: the daemon and its attribution are local-host concerns; nothing touches the execution-host boundary or the remote wire. The extended IPC response is renderer to main inside one app, and the new field is optional.
  • Performance: no new spawn. The attribution check reuses feat(telemetry): report the macOS daemon's code identity on adoption and folder-denial events #22171's probe (about 20 ms, async, coalesced per pid) once per daemon generation, again only when the resolved path disappears or the pid record changes.
  • Security: Apple's /usr/bin/codesign with a pid argument only. The trace record carries a reason enum and a session count; no paths or user data.
  • Backwards compatibility: legacy pid records without spawnerExecPath are now judged by the daemon executable (intact when it resolves) instead of always unknown; they trigger a replacement only when the executable is gone or parked.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

A more prominent banner listing the affected sessions, and keeping sessions across a replacement (issue suggestions 2 and 3), are follow-ups.

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 Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Important

Review skipped

We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting @coderabbitai full review.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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: 75d5628d-cc39-4715-89ca-afe8b0130d24

📥 Commits

Reviewing files that changed from the base of the PR and between c0ff1a22ce1f9f188c46d5dfb6130b7a9cb5545b and c0dbff1be4bd98e3699fefffde2fc8241c26c3e0.

📒 Files selected for processing (3)
  • src/main/daemon/daemon-mac-code-identity.test.ts
  • src/main/daemon/daemon-mac-code-identity.ts
  • src/main/daemon/daemon-pty-daemon-recovery.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/daemon/daemon-pty-daemon-recovery.ts

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


📝 Walkthrough

Walkthrough

The change adds macOS code-identity inspection and uses the result to classify daemon TCC attribution. It records deferred daemon replacements with reasons, session counts, timestamps, and trace events. The management API exposes this state to the renderer. The settings notice now reports preserved live sessions and updated permission details in English and French. Tests cover identity parsing, attribution, replacement state, IPC data, and notification rendering.

Priority: ⬆️ High

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 26.32% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 15 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR meets the coding objectives in #20007. inspectMacProcessCodeIdentity resolves the daemon PID with codesign. The attribution logic reports severed for an unresolvable identity, a missing e…
Out of Scope Changes check ✅ Passed The changes remain within #20007 scope. Deferral tracking for existing replacement paths supports the required live-session reporting. IPC, localization, Settings UI, tracing, and tests support detect…
Title check ✅ Passed The title clearly identifies the main change: fixing macOS TCC attribution detection by checking the daemon's own executable.
Description check ✅ Passed The description is complete and follows the repository template. It explains the problem, user impact, implementation, linked issue, testing, platform considerations, security, performance, compatibil…

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: 8271b761-2d7f-41ff-8553-ec905c451a8a

📥 Commits

Reviewing files that changed from the base of the PR and between 68b1128 and c0ff1a22ce1f9f188c46d5dfb6130b7a9cb5545b.

📒 Files selected for processing (17)
  • src/main/daemon/daemon-mac-code-identity.test.ts
  • src/main/daemon/daemon-mac-code-identity.ts
  • src/main/daemon/daemon-pty-adapter-daemon-recovery.test.ts
  • src/main/daemon/daemon-pty-daemon-recovery.ts
  • src/main/daemon/daemon-replacement-deferral.test.ts
  • src/main/daemon/daemon-replacement-deferral.ts
  • src/main/daemon/daemon-replacement-preflight.ts
  • 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
  • src/main/ipc/pty-management.ts
  • src/preload/api-types.ts
  • src/preload/api/pty-management-api.ts
  • src/renderer/src/components/settings/TerminalTccAttributionNotice.test.tsx
  • src/renderer/src/components/settings/TerminalTccAttributionNotice.tsx
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/fr.json

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

@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 detection logic, its cache invalidation, and the deferral plumbing are sound and well covered. Two minor points below.

Reviewed changes

  • Severed TCC judged by the daemon's own executable — getMacDaemonTccAttributionHealth now resolves the daemon's code identity through codesign -d +<pid> (daemon-mac-code-identity.ts) and calls classifyMacDaemonCodeIdentity, so a daemon running from a Squirrel-parked bundle reads severed instead of intact.
  • Per-generation cache remembers the resolved executable path — a cached verdict is re-probed once that path disappears, without waiting for a pid-record change.
  • Deferred replacements become visible — daemon-replacement-deferral.ts records each preserve-with-live-sessions decision, emits a daemon.replacement_deferred trace span, and exposes the record through pty:management:macTccAttribution.
  • Settings notice names the denied resources and the preserved count — TerminalTccAttributionNotice adds the live-session line for the severed reason; en/fr strings updated.
  • Tests — parser/runner classification, the real-codesign two-update E2E, cache re-probe, deferral record/clear/trace, adapter preserve/respawn paths, and the notice count.

ℹ️ Legacy pid records skip the parked-bundle check

classifyMacDaemonCodeIdentity only runs the bundle-containment test when spawnerExecPath is present. A daemon launched by an Orca version that predates that field records null, and the resolved-path-missing branch doesn't fire while the parked copy still exists. For such a daemon after one in-place update the probe resolves to the parked (still-present) path, so the verdict stays intact — the single-update Local Network breakage is only caught after the second update deletes the parked bundle. This matches the backwards-compatibility note in the PR description; flagging it only so the residual coverage is explicit, in case the maintainers want to rely on the pid-record field being ubiquitous before considering the issue fully closed.

Technical details
# Legacy-record coverage gap

## Affected sites
- src/main/daemon/daemon-tcc-attribution.ts:95 — `const bundleRoot = spawnerExecPath ? findMacAppBundleRoot(spawnerExecPath) : null`
- src/main/daemon/daemon-tcc-attribution.ts:156 — resolved path is recorded only, so with `bundleRoot === null` and an existing path the verdict is `intact`.

## Required outcome
- Confirm that shipped daemons (the population this fix targets) all carry `spawnerExecPath`, or accept that a legacy daemon's first post-update window is undetected.

## Open questions for the human
- How long has `spawnerExecPath` been written to the pid record? If it predates the versions in the wild, no action is needed.

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

@davbebawy

Copy link
Copy Markdown
Contributor Author

Answering the informational point in the pullfrog review — how long spawnerExecPath has been written to the pid record, which decides whether a legacy daemon can skip the parked-bundle check.

It predates the population this fix targets. My clone was shallow, so I deepened it to 3207 commits (back to 2026-08-09) and the field is already present in src/main/daemon/ at that boundary — it was not introduced inside that window, so it is at least ~6 weeks old and older than any daemon version in the wild here (the reporter's is 1.4.201). Concretely, the live severed daemon I tested against was spawned on Sep 14 and its pid record carries the spawner path.

So the residual gap is a daemon that has been running continuously since before that field shipped, which is older than any build still in circulation. I have left the spawnerExecPath ? ... : null guard in place rather than assuming the field — a missing record still falls back to the resolved-path-missing branch rather than asserting intact — but I do not think it needs additional coverage to consider #20007 closed. Happy to be told otherwise if maintainers know of longer-lived daemons.

@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

  • Narrowed the unlinked-executable signal to ENOENT — UNLINKED_EXECUTABLE_PATTERN is now /No such file or directory/, and errSecCSNoSuchCode ("host has no guest with the requested attributes") is treated as unavailable (fail open), since on the --display path it means the pid is exiting rather than its executable being unlinked. This resolves the prior review's inline concern; the live-daemon --display vs --verify evidence confirms the narrowed pattern still classifies the severed daemon.
  • Recorded the derived live-session count in the recovery-path deferral branches — daemon-pty-daemon-recovery.ts now passes null when the daemon's inventory is unavailable and the derived max(activeSessionIds, daemon) count otherwise, so the recorded count matches what the warning prints and what the preflight path already reports.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Jinwoo-H added a commit that referenced this pull request Sep 22, 2026
A reviewer read `resolved` as a claim that the executable sits inside the
installed app and asked for that to be validated. It is not that claim, and we
are not making it: proving containment needs the pid record's spawner path, and
deciding anything from where the code lives is #21826's proposed behaviour
rather than this measurement.

The enum doc now spells out all four verdicts in the terms the probe can
actually support, and says plainly why `resolved` stops at "exists and is not
parked". A matching note sits beside the parked-path pattern.
Jinwoo-H added a commit that referenced this pull request Sep 23, 2026
…y control

`daemon_pty_cwd_denied` gives code_identity's hit rate on denials, but a
readable spawn emitted nothing, so an `unresolvable` adoption with no denial
could not be told apart from a user who never opened a terminal in Documents,
Desktop, or Downloads. The false-positive rate that gates #21826's
auto-replacement was unmeasurable.

`daemon_pty_cwd_readable` now fires when a daemon reads a TCC-gated cwd, once
per daemon and folder class per app run, with the same origin properties as
the denial event. The read-out becomes a 2x2 of code_identity against
readable/denied on protected-folder spawns. Fire-and-forget on the spawn path
like the denial emit, and no app-side directory read.
Jinwoo-H added a commit that referenced this pull request Sep 23, 2026
… dedupe state

The once-per-daemon dedupe on `daemon_pty_cwd_readable` was keyed before the
probe ran, so a daemon first seen readable while `parked` never reported again
once it turned `unresolvable` — the one cell that would count most against
#21826. It also counted per daemon while denials count per spawn, so the 2x2
mixed units.

Readable now reports every spawn, like denied, and both events share one
emitter (`trackDaemonPtyCwdVerdict`) and one schema. The TCC-folder gate lives
in the verdict branch. The origin fields are one shape spread into both
schemas. The codesign probe calls `runProcess` directly and tests mock it,
replacing a test-only runner parameter. The repeated "never cached" rationale
is now said once.
Jinwoo-H added a commit that referenced this pull request Sep 23, 2026
…and folder-denial events (#22171)

* feat(daemon): import the macOS process code-identity probe from PR #21826

Takes `daemon-mac-code-identity.ts` and its test verbatim from David Bebawy's
community PR #21826 (stablyai/orca). The probe asks Security.framework, via
`codesign --display --verbose=1 +<pid>`, where a live process's code lives on
disk — the question Node cannot answer, and the one that decides whether tccd
can still resolve a running daemon's code identity after an app update.

Imported unchanged here so the adaptation that follows is reviewable as a diff
against the author's original.

Co-authored-by: David Bebawy <[email protected]>

* feat(telemetry): report the daemon pid's macOS code identity on the two adoption events

Community PR #21826 argues that macOS terminal daemons lose Documents/Desktop/
Downloads access after an update because the daemon's own executable is
unlinked — Squirrel parks the outgoing bundle under a ShipIt staging directory
and later deletes it — so tccd can no longer map the daemon pid to on-disk
code. Today's `spawner_path_class` and `tcc_attribution` read the binary that
forked the daemon, which an in-place update deletes and recreates, so neither
can see that state.

This adds the detector as a measurement only. `code_identity` rides on
`daemon_adopted` and `daemon_pty_cwd_denied`, the two events that already
describe an adopted daemon, so denied daemons can be cross-tabbed against
healthy ones. Nothing reads the verdict: no replacement, no notice, no UI.

The probe is David Bebawy's, narrowed from a path-carrying union to the closed
enum the wire allows, and memoised per pid so one codesign spawn answers for a
whole daemon generation. Off macOS, or with no pid, it reports `probe-failed`,
which keeps both schemas strict and non-optional.

Co-authored-by: David Bebawy <[email protected]>

* fix(telemetry): read the daemon's code identity fresh on every adoption event

The probe memoised its verdict per pid and never expired it, so
`daemon_pty_cwd_denied` reported whatever the probe saw at adoption rather than
what was true at the denial. That breaks the measurement in both directions: a
transient codesign failure during startup pinned `probe-failed` for the rest of
the run, and the `parked` to `unresolvable` transition became invisible.
Squirrel leaves the parked bundle in place until the next update, which can be
days, so a daemon adopted as `parked` and denied as `unresolvable` is the exact
crossover this study exists to catch, and the cache hid it.

Now every ask runs its own codesign. Only concurrent asks about the same pid
share a probe, and that entry is cleared as soon as it settles, so nothing
survives to be reported later. Both events are rare enough that one spawn each
is not worth a cache.

* fix(telemetry): drop the dead existence check from the code-identity probe

The classifier stat'd the path codesign displayed and called a missing one
unresolvable. That path is unreachable: once the executable is unlinked,
`codesign --display` prints no `Executable=` line at all and exits 1 with
"No such file or directory", which the fallback below already classifies as
unresolvable. Verified directly on Darwin 25.5 against a signed binary deleted
out from under a running pid.

All the branch actually covered was the window between codesign reading the
path and this process stat'ing it, and it paid for that with a synchronous
stat on the main thread.

* fix(telemetry): never classify a timed-out codesign probe as a verdict

`runProcess` kills the child at the deadline and reports `timedOut`, but the
runner type dropped that field, so a codesign killed mid-display could still
have printed an `Executable=` line and been read as `resolved` or `parked`.
A half-written display proves nothing about where the daemon's code lives.

The runner result now carries `timedOut`, and a timed-out probe returns
`probe-failed` before the output is looked at.

* docs(telemetry): state what each code-identity verdict actually asserts

A reviewer read `resolved` as a claim that the executable sits inside the
installed app and asked for that to be validated. It is not that claim, and we
are not making it: proving containment needs the pid record's spawner path, and
deciding anything from where the code lives is #21826's proposed behaviour
rather than this measurement.

The enum doc now spells out all four verdicts in the terms the probe can
actually support, and says plainly why `resolved` stops at "exists and is not
parked". A matching note sits beside the parked-path pattern.

* docs(telemetry): stop asserting how long a parked bundle survives

The probe's rationale claimed Squirrel keeps the parked bundle "until the next
update". A reviewer claimed the opposite, that it is deleted at the end of the
same install. Neither holds up against this Mac's ShipIt log: the install moves
the outgoing bundle to a TMPDIR ShipIt directory and logs no removal of it at
all, and the one "Couldn't remove owned bundle" line names the incoming
download staging copy, not the parked one. Every parked bundle from the last
two days is nevertheless gone now.

So the rationale in the probe doc, the enum doc, and the reprobe test comment
now assert only what is established: the outgoing bundle is moved aside at
install and disappears later on a schedule we have not pinned down. That is
already enough to justify the design, since one pid's verdict can change
within an app run, which is exactly why every ask reads fresh.

* feat(telemetry): report readable TCC-gated spawns as the code-identity control

`daemon_pty_cwd_denied` gives code_identity's hit rate on denials, but a
readable spawn emitted nothing, so an `unresolvable` adoption with no denial
could not be told apart from a user who never opened a terminal in Documents,
Desktop, or Downloads. The false-positive rate that gates #21826's
auto-replacement was unmeasurable.

`daemon_pty_cwd_readable` now fires when a daemon reads a TCC-gated cwd, once
per daemon and folder class per app run, with the same origin properties as
the denial event. The read-out becomes a 2x2 of code_identity against
readable/denied on protected-folder spawns. Fire-and-forget on the spawn path
like the denial emit, and no app-side directory read.

* refactor(telemetry): one emitter and schema for both cwd verdicts, no dedupe state

The once-per-daemon dedupe on `daemon_pty_cwd_readable` was keyed before the
probe ran, so a daemon first seen readable while `parked` never reported again
once it turned `unresolvable` — the one cell that would count most against
#21826. It also counted per daemon while denials count per spawn, so the 2x2
mixed units.

Readable now reports every spawn, like denied, and both events share one
emitter (`trackDaemonPtyCwdVerdict`) and one schema. The TCC-folder gate lives
in the verdict branch. The origin fields are one shape spread into both
schemas. The codesign probe calls `runProcess` directly and tests mock it,
replacing a test-only runner parameter. The repeated "never cached" rationale
is now said once.

* fix(telemetry): rename the shared origin schema fields for the anti-slop gate

no-shape-in-symbol-names rejects daemonOriginShape; the fields are event props.

---------

Co-authored-by: David Bebawy <[email protected]>
…executable

The severed check compared `spawnerExecPath`, which every in-place update
deletes and recreates, so a daemon running from a bundle Squirrel parked and
later deleted was always reported `intact`. Read the daemon pid's own
executable through the code-identity probe stablyai#22171 added for telemetry
(`inspectDaemonMacCodeIdentity`, which now also returns the resolved path, so
both readers share one coalesced `codesign` spawn) and report `severed` when
the identity is `unresolvable` or `parked`, when the resolved path no longer
exists, or when it lies outside the installed app bundle. A failed probe keeps
the old spawner-binary verdict. Re-probe a cached verdict once the resolved
executable path disappears.

When replacement is declined because the daemon owns live sessions, record the
reason and count, emit it as a `daemon.replacement_deferred` trace span so it
reaches diagnostic bundles, and expose it through the management IPC beside
the folder-access evidence, so the Settings attribution notice can say why
Orca did not restart the daemon.

Fixes stablyai#20007
@davbebawy
davbebawy force-pushed the fix/daemon-severed-check-own-executable branch from c0dbff1 to 979d39d Compare October 1, 2026 19:44
@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Daemon restart logic and macOS TCC attribution checks.

The PR appears safe to merge; no outstanding previous finding or actionable new issue was established.

Summary

The PR checks the daemon’s own macOS code identity to detect severed TCC attribution, records when replacement is deferred to preserve live sessions, and surfaces the result in Settings. It also coordinates the attribution and folder-access toasts so one cause does not raise both notices.

Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  P[Daemon PID] --> C[Code-identity probe]
  C --> H[TCC attribution health]
  H --> R{Replacement safe?}
  R -->|No live sessions| X[Replace daemon]
  R -->|Live sessions| D[Record deferral]
  H --> I[Management IPC]
  D --> I
  I --> S[Settings notice]
  I --> T[Coordinate attribution and folder toasts]
Loading

Reviews (4) · Last reviewed commit: "fix(macos): keep a severed toast the use..."

@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

  • Reused #22171's shared code-identity module — daemon-mac-code-identity.ts now builds on main's DaemonCodeIdentity types, adding inspectDaemonMacCodeIdentity (returns the resolved path beside the verdict) and sharing one coalesced codesign --display spawn between adoption telemetry and the attribution check.
  • parked now decides severing directly — the probe classifies an executable inside a …ShipIt… directory as parked, and classifyMacDaemonCodeIdentity maps parked to severed without requiring spawnerExecPath. This closes the prior review's legacy-record gap: a daemon launched before spawnerExecPath was recorded, parked by a single in-place update, is now caught.
  • Tests reworked around the shared probe — injected-probe verdicts, resolved-path-missing, parked-inside-installed-bundle, cache re-probe on path disappearance, the real-codesign two-update E2E, and the classifier table; the main-thread suite mocks the module to keep its ps spawn budget pinned.

The ENOENT narrowing from the prior review survived the rebase (UNLINKED_EXECUTABLE_PATTERN stays /No such file or directory/, host has no guest fails open as probe-failed), and no thread remains open. The deferral module, recovery paths, and Settings notice are unchanged since the last review.

ℹ️ DaemonCodeIdentity still documented as "Measurement only"

src/shared/daemon-adoption-telemetry.ts describes the DaemonCodeIdentity enum as Measurement only (#21826), but this PR now makes that same verdict the input that decides whether Orca replaces a daemon. The module header in daemon-mac-code-identity.ts was updated to say it is read by the TCC attribution check, so the shared enum doc is the one spot left implying the value is observational only.

Technical details
# Update the shared enum doc to reflect the decisioning reader

## Affected sites
- `src/shared/daemon-adoption-telemetry.ts:26` — `Where macOS says the daemon pid's own executable is now (#21826). Measurement only.`

## Required outcome
- The comment should note that `getDaemonMacCodeIdentity` (telemetry) and
  `classifyMacDaemonCodeIdentity` (replacement decision) both read it, matching the updated
  header at `src/main/daemon/daemon-mac-code-identity.ts:1-2`.

## Open questions for the human
- If #20452 is still expected to fold this into a broader at-risk/severed model, leaving the doc
  as-is may be intentional; otherwise a one-line doc update is enough.

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

… record current

- Settings shows the preserved-session count for any declined replacement.
  After an update the stale-bundle check usually declines first, so keying
  the line on `severed_tcc_attribution` hid it in the common case.
- A Manage Sessions restart clears the deferral record, so the new daemon
  is never paired with the old daemon's decision.
- A repeated identical deferral (one per new terminal while sessions are
  kept) no longer emits a span and forces a synchronous trace flush.
- While a folder denial is measured for the severed daemon, the app-wide
  severed toast stays down and the folder toast with its Fix dialog owns the
  cause. Severed without a denial (Local Network) still toasts.
- The shared `DaemonCodeIdentity` doc names its second reader.

@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 — one minor suggestion inline.

Reviewed changes

  • One notice per cause — while a measured folder denial (folderAccessMismatch) is present, the severed toast stays down (and is taken down if already up) so the folder Fix dialog is the only remedy; severed with no denial (Local Network) still toasts.
  • Deferral record stays current — cleared on a successful manual restart (runRestartDaemon) in addition to the existing replacement/respawn clears, and deduplicated so a repeated identical decision (same reason + live count, one per new terminal) no longer emits another span or flush.
  • Preserved-session count for any deferral reason — the Settings notice shows the kept-session line even when the stale_bundle check declined first, since it is the same daemon and the same sessions.
  • Doc/copy updates — DaemonCodeIdentity no longer reads "Measurement only" (resolves the prior review's nit), and the notice body now names the folder + Local Network denials.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

…nger owns the remedy

The one-notice rule had two holes. Yielding to the folder toast left the
once-per-session latch set, so the severed toast could not re-raise after the
folder denial cleared. And a folder notice the user dismissed still held the
severed toast down, though it can never come back, leaving no remedy shown.
Reset the latch on yield, and let only a non-dismissed folder notice own the
cause.

@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

  • Severed toast yields and can return — when a live folder denial owns the cause, applySeveredNotice now dismisses the severed toast and clears toastedThisSession.current, so the notice is eligible again once the denial clears while attribution stays severed.
  • A dismissed folder notice stops owning the remedy — folderNoticeOwnsCause is now mismatch !== null && phase !== 'dismissed', so once the user closes the folder notice the severed (Local Network) toast still fires.
  • Two tests added — re-raise after the denial clears, and raise after the user already dismissed the folder notice; the shared noticeCalls(id) helper lets assertions target either toast.

The prior inline finding is addressed; I replied to it and resolved its thread. All 27 hook tests pass locally, and both new tests fail without the corresponding source change.

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

Yielding to the folder notice reset the once-per-session latch even when the
user had already dismissed or acted on the severed toast, so a transient
folder denial brought the dismissed warning back. Track whether the toast is
still on screen and reset the latch only when it yields from there.

@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

  • A user-dismissed severed toast stays dismissed — the ownership-takedown branch now resets toastedThisSession only when the severed toast is actually on screen, tracked by a new severedToastOnScreen ref that is set on raise and cleared by a markHandled callback wired to the action, cancel, and onDismiss handlers. Previously the previous delta's unconditional latch reset re-armed a toast the user had already dismissed, so a transient folder denial could bring it back.
  • Regression test added — keeps a severed toast the user dismissed down after a transient folder denial drives severed → user dismiss → folder denial → denial clears and asserts the severed toast is not re-raised; it fails against the previous commit's toastedThisSession check.

The prior inline finding is addressed and its thread was resolved in the previous run. No open threads remain.

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

@davbebawy

Copy link
Copy Markdown
Contributor Author

@Jinwoo-H I rebased this onto main and reworked it around your two PRs:

One question: has the code_identity data from #22171 come in? If denials line up with unresolvable/parked and healthy daemons read resolved, this should be ready. If not, I'm happy to hold it or narrow it to whatever the data supports.

This branch has not been deployed

No deployments
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

1 participant