Repository navigation
feat(telemetry): report the macOS daemon's code identity on adoption and folder-denial events - #22171
Conversation
…1826 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]>
…wo 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]>
…on 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.
…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.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughThe change adds macOS daemon code-identity probing through Priority: ⬇️ Low Merge Risk: 🔵 Low · up to Rapid interleaved requests for different daemon PIDs can perform a redundant codesign probe for one PID. This is a bounded telemetry overhead issue, but should be addressed when practical. 🚥 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: 3
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 4ae87f22-d275-4eb3-bd90-cae00e2e9a41
📒 Files selected for processing (8)
src/main/daemon/daemon-adoption-telemetry-event.test.tssrc/main/daemon/daemon-adoption-telemetry-event.tssrc/main/daemon/daemon-mac-code-identity.test.tssrc/main/daemon/daemon-mac-code-identity.tssrc/main/daemon/daemon-provider-init.tssrc/shared/daemon-adoption-telemetry.test.tssrc/shared/daemon-adoption-telemetry.tssrc/shared/telemetry-daemon-event-schemas.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.
There was a problem hiding this comment.
ℹ️ No critical issues — one minor doc fix inline.
Reviewed changes
- New macOS code-identity probe.
daemon-mac-code-identity.tsresolves a daemon pid's on-disk executable via/usr/bin/codesign --display --verbose=1 +<pid>and classifies it asresolved/parked/unresolvable/probe-failed; concurrent asks for one pid share a single spawn and nothing is cached across events. - Telemetry plumbing.
classifyDaemonAdoptionOriginis now async and addscode_identity;trackDaemonAdopted/trackDaemonPtyCwdDeniedbecame async;reportDaemonPtyCwdVerdictrecords the user-facing mismatch notice before awaiting the probe. - Schema.
code_identityadded as a required enum to the.strict()daemon_adopted/daemon_pty_cwd_deniedschemas; enum defined indaemon-adoption-telemetry.ts. Both areMAIN_OWNEDand emitted in-process, so the new required field has no IPC/remote consumer to break. - Callers and tests.
daemon-provider-init.tsawaitstrackDaemonAdopted; three suites updated and a new probe suite added.
I verified the load-bearing external contracts: +<pid> is the documented codesign pid form and Executable= is emitted to stderr at verbosity level 0 (Apple cs_dump.cpp / cs_utils.cpp), the unlinked case exits 1 with a perror-formatted No such file or directory, and XNU's proc_pidpath returns ENOENT once the executable's vnode is unlinked. The classifier matches that behavior, and the coalescing / fresh-read logic is correct.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
`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.
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.
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.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Discarded a timed-out
codesignprobe.probenow checksrunProcess'stimedOutflag and returnsprobe-failedbefore classifying, so a deadline-killedcodesignthat already printed a partialExecutable=line can no longer be reported asresolved/parked.runProcessdoes settimedOut: trueon deadline (run-process.ts:255), so the guard is load-bearing. - Corrected the verdict docs. The
getDaemonMacCodeIdentityJSDoc no longer claims the parked copy survives "until the next update"; the probe, enum, and test comments now assert only the move, the later disappearance, and the explicitly unknown schedule. This retires the one open pullfrog thread on the file. - Added a regression test. A timed-out probe that printed
Executable=/xfirst resolves toprobe-failed.
The classifier, coalescing, and no-cache behavior are otherwise unchanged and remain correct.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…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.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the delta since the prior Pullfrog review (ffa1c47bad): one commit (53fcf82) adding the daemon_pty_cwd_readable control event.
- Added the readable control event.
trackDaemonPtyCwdReadableemitsdaemon_pty_cwd_readablefor a TCC-gated cwd the daemon could read, carrying the same enum origin tuple as the denial event. It is darwin-only, gated toMAC_TCC_FOLDER_CLASSES, requires a daemon identity, does no app-side directory read, and dedups once per daemon incarnation × folder class per app run via module-levelreportedReadable(reset for tests). - Wired it into the readable verdict branch. The
cwdReadableByDaemon === truebranch ofreportDaemonPtyCwdVerdictnow clears the mismatch notice first, then awaits the control emit. Since the caller voidsreportDaemonPtyCwdVerdict(daemon-pty-session-spawn.ts:257), the added codesign probe adds no spawn latency. - Registered the event.
daemonPtyCwdReadableSchemaadded toeventSchemas, and the name added toMAIN_OWNED_TELEMETRY_EVENTSso a compromised renderer cannot spoof it. Tests assert the exact payload, the dedup sequence, the skip conditions (non-TCC, null identity, non-darwin), and throw swallowing; the touched suites (31 tests) andpnpm tc:nodepass.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
… 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.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the delta since the prior Pullfrog review (53fcf82): one commit (96e534f) consolidating the two cwd-verdict emitters and schemas.
- Merged the two emitters into
trackDaemonPtyCwdVerdict.trackDaemonPtyCwdDeniedandtrackDaemonPtyCwdReadablecollapse into one async function taking the event name;reportDaemonPtyCwdVerdictcalls it from both the readable and denied branches. - Dropped the readable dedup state.
reportedReadableandresetDaemonPtyCwdReadableForTestsare gone, sodaemon_pty_cwd_readablenow fires on every readable TCC-gated spawn — matching the PR body's "counted per spawn like the denial event" and giving the read-out a per-spawn denominator. - Merged the schemas.
daemonPtyCwdDeniedSchemaanddaemonPtyCwdReadableSchemabecome onedaemonPtyCwdVerdictSchemasharingdaemonOriginShape; both registry entries point at it. The readable emit stays gated to the three TCC classes inreportDaemonPtyCwdVerdict, so the broadercwd_classenum only loosens the wire validator, which this MAIN_OWNED emitter alone feeds. - Test seam moved to module mocking. The probe no longer takes an injected
runCommand;daemon-mac-code-identity.test.tsmocksrunProcess, and the event suite mocksgetDaemonMacCodeIdentity, so no unit test spawnscodesign.
Verified pnpm tc:node and the three touched suites (40 tests) pass. The readable branch no longer requires a daemon identity; the payload is derived from the pid record, which makes it consistent with the denied branch rather than a regression.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
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: 40fdb0b5-a6c0-4bbf-9489-07348a959321
📒 Files selected for processing (7)
src/main/daemon/daemon-adoption-telemetry-event.test.tssrc/main/daemon/daemon-adoption-telemetry-event.tssrc/main/daemon/daemon-mac-code-identity.test.tssrc/main/daemon/daemon-mac-code-identity.tssrc/shared/daemon-adoption-telemetry.tssrc/shared/telemetry-daemon-event-schemas.tssrc/shared/telemetry-event-registry.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- src/main/daemon/daemon-mac-code-identity.ts
- src/shared/daemon-adoption-telemetry.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.
| // Why: `daemon_pty_cwd_denied` is the #17696 symptom — the daemon cannot read a cwd the app can, | ||
| // on proven divergence only. `daemon_pty_cwd_readable` is its control, on TCC-gated folders only. | ||
| export const daemonPtyCwdVerdictSchema = z | ||
| .object({ cwd_class: z.enum(DAEMON_PTY_CWD_CLASSES), ...daemonOriginShape }) |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Preserve the TCC-only contract for readable events.
This schema now accepts other-home and outside-home for daemon_pty_cwd_readable. The current producer filters these values, but EventProps and the central validator now permit them for any direct caller. Such events would contaminate the readable control population.
Keep the origin fields shared, but use an event-specific schema with MAC_TCC_FOLDER_CLASSES for daemon_pty_cwd_readable.
🧰 Tools
🪛 GitHub Check: static analysis
[failure] 80-80: anti-slop(no-shape-in-symbol-names)
src/shared/telemetry-daemon-event-schemas.ts:80:59: Rename symbol "daemonOriginShape" for its domain role; "shape" describes structure rather than ownership.
…lop gate no-shape-in-symbol-names rejects daemonOriginShape; the fields are event props.
…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

ELI5
Community PR #21826 says macOS terminals lose access to Documents, Desktop, and Downloads after an update because the terminal daemon keeps running from a program file the updater has since moved aside and deleted, so macOS can no longer tell the daemon belongs to Orca. That PR also proposes an automatic fix. Before we let Orca act on that signal, this PR only measures it: on every daemon adoption and every folder denial we already report, we now also record where macOS says the daemon's executable is. A week of data tells us whether the signal predicts the failure.
What Changed
Before:
daemon_adoptedanddaemon_pty_cwd_deniedcarry the daemon's app-version match and where its spawner binary lives. Neither says whether the daemon's own executable still exists on disk.After: both events carry one more closed-enum property,
code_identity, and a new control event,daemon_pty_cwd_readable, carries it too on every spawn where the daemon can read a Documents/Desktop/Downloads cwd, counted per spawn like the denial event:resolvedparked…ShipIt…directory, i.e. the old bundle the updater moved asideunresolvableprobe-failedcodesignmissing, timeout, or unparseable outputMechanism:
daemon-mac-code-identity.ts, imported from #21826 with co-author credit, runs/usr/bin/codesign --display --verbose=1 +<pid>throughrunProcess(3 s deadline, args only) and classifies theExecutable=line or its absence. It runs fresh on every ask, with concurrent asks for one pid sharing a single spawn, and a timed-out spawn readsprobe-failedregardless of partial output; nothing is cached across events, because the outgoing bundle is moved aside at install and disappears later on a schedule we have not pinned down (this Mac's ShipIt log records the move but no removal, yet every parked bundle from the last two days is gone), so one pid's verdict can change within an app run and that crossover is worth dating. Both emits stay off the hot path: adoption already emits after connect, and the denial emit already runs fire-and-forget after the spawn; the folder-access notice is recorded before the awaited emit so the user-facing path never waits oncodesign.The readable event is emitted from the existing readable branch of the same fire-and-forget verdict path, with no app-side directory read. Without it, an
unresolvableadoption with no denial cannot be told apart from a user who never opened a terminal in a protected folder, so the false-positive rate would be unmeasurable.Nothing reads the verdict. No UI, no daemon replacement, no admission change, on any platform.
Why
We have two competing explanations for the field data (1,438 users in three weeks, 96% on a daemon from an older install): #21826's unlinked-executable theory, and our September lab matrix where deleting the spawner under a running daemon kept folder access. Two machines versus one lab run is not enough to turn on an automatic daemon replacement. This property, on the denied event and on the healthy adoption event alike, gives the false-positive and false-negative rates directly: if nearly every denial is
unresolvable/parkedand nearly every healthy daemon isresolved, #21826's detector is right and its behaviour can ship with confidence. If healthy daemons also readunresolvable, we learned it before killing anyone's terminals.Alternatives: adopting #21826 as is (acts on an unverified trigger; replacement is bounded to zero-session daemons, but the Settings notice would fire on every false positive);
lsof -p(seconds on a busy machine; #20072 tried it);ps -o comm(echoes argv[0], cannot see the parked copy); a nativeproc_pidpathaddon (a new build target for one syscall).Linked Issue
Relates to #20007 and #21826. Follow-up to #21923.
Visual Proof
N/A: telemetry property only, no UI.
Testing
macOS only by construction: the probe returns
probe-failedbefore spawning anything on other platforms, and both events were already macOS-only.Classifier verified against real
codesignoutput on Darwin 25.5 for all four shapes: a live Electron helper →resolved; the same executable moved into a…ShipIt…-named directory →parked; the executable unlinked → noExecutable=line, exit 1,No such file or directory→unresolvable; a dead pid →probe-failed. A dev build readsresolved, so there is no false finding from unsigned or ad hoc code.Automated: probe classification for each output shape, fresh read per ask and coalescing of concurrent asks, both event schemas reject an unknown value, emit ordering keeps the folder-access notice ahead of the awaited spawn.
pnpm tc:node,check:code-quality:changed(0 new findings), the touched suites and the fullsrc/main/daemonsuite pass.Cost: one ~20 ms async spawn per event; adoption happens once per launch, denial once per denied spawn.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Implemented and reviewed with Claude (Claude Code, Opus and Fable 5.1), directed by the author. The probe module is David Bebawy's from #21826 (co-author trailer on both commits).
Review
probe-failedbefore any spawn. Child process viasrc/shared/child-process/.codesignruns with a fixed program path and a pid argument only; only the enum reaches the wire, never a path..strict()main-process telemetry schemas; no IPC or remote wire change.Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Read-out plan, after ~7 days: on protected-folder spawns only, cross-tab
code_identityagainstdaemon_pty_cwd_deniedvsdaemon_pty_cwd_readable, deduped per user and daemon (denials fire per spawn). Keepparkedandunresolvableas separate rows: a parked executable still exists, and whether it alone predicts denial is part of the question. Watch theprobe-failedshare by macOS version, since an oldercodesignmay print the unlinked case differently. If denials are mostlyunresolvable/parkedand readable spawns mostlyresolved, #21826's auto-replacement ships.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)