Repository navigation
Conversation
Greptile SummaryThis PR changes macOS daemon replacement preflight so app-path or packaged-bundle skew is classified before resolver health, preserving live sessions while routing new PTYs through a sticky local fallback.
Confidence Score: 5/5The PR appears safe to merge, with no concrete changed-code-triggered failure identified. The new mode remains sticky during ordinary health recovery, preserves ownership routing for both daemon and local sessions, and is cleared by the explicit restart path that reconstructs the provider.
|
| Filename | Overview |
|---|---|
| src/main/daemon/daemon-replacement-preflight.ts | Reorders healthy-daemon classification so launch-path and packaged-bundle skew is handled before macOS resolver health, returning sticky local fallback when live sessions require preservation. |
| src/main/daemon/daemon-provider-init.ts | Installs the degraded provider for the new sticky mode while intentionally omitting its health-based fresh-spawn recovery probe. |
| src/main/daemon/daemon-out-of-process-launcher.ts | Propagates the new sticky fallback mode through preserved daemon handles. |
| src/main/daemon/daemon-spawner.ts | Extends the daemon process handle contract with the sticky degraded routing mode. |
| src/main/daemon/daemon-init-live-session-preservation.test.ts | Adds Darwin-specific coverage proving skewed daemons with live sessions are preserved and resolver health cannot override sticky fallback. |
| src/main/daemon/daemon-init-packaged-bundle-staleness.test.ts | Verifies stale packaged daemons with live sessions enter sticky fallback on macOS. |
| src/main/daemon/daemon-init-provider-installation.test.ts | Verifies generic health recovery cannot clear sticky fresh-spawn routing. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Healthy daemon discovered] --> B[Classify launch identity and bundle age]
B -->|Current| C[Check macOS resolver health]
B -->|Skewed| D{Has live sessions or unknown session state?}
D -->|Yes on macOS| E[Preserve old daemon]
E --> F[Install sticky degraded provider]
F --> G[Existing sessions use preserved daemon]
F --> H[Fresh PTYs use local provider]
D -->|No| I[Replace daemon]
C -->|Healthy or unknown| J[Preserve normal daemon routing]
C -->|Unhealthy with no live sessions| I
K[Explicit daemon restart] --> L[Install fresh non-degraded provider]
L --> M[Fresh PTYs return to daemon]
Reviews (1): Last reviewed commit: "fix(macos): route fresh PTYs away from s..." | Re-trigger Greptile
📝 WalkthroughWalkthroughThe daemon lifecycle now supports Merge Risk: 🟡 Moderate · up to The PR can still route fresh terminals through the current app, but it is not merge-ready until the replacement race and invalid test declarations are fixed. Without those fixes, a newly created session could be terminated during daemon cleanup, validation could fail to load affected tests, and unverifiable daemon identity could leave new terminals using a stale daemon. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description includes the change summary, linked issue, and validation results, but it omits several template sections, including an explicit Visual Proof entry, ELI5, Why, Review, Notes, and checklist status. Resolution Complete the required template sections. Add an explicit Visual Proof entry with Full details: Linked Issues checkExplanation The changes directly address issue [
✨ 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: Team
Run ID: 8ff93664-bff5-4544-b1d1-53ab90841428
📒 Files selected for processing (8)
src/main/daemon/daemon-init-live-session-preservation.test.tssrc/main/daemon/daemon-init-mock-types.tssrc/main/daemon/daemon-init-packaged-bundle-staleness.test.tssrc/main/daemon/daemon-init-provider-installation.test.tssrc/main/daemon/daemon-out-of-process-launcher.tssrc/main/daemon/daemon-provider-init.tssrc/main/daemon/daemon-replacement-preflight.tssrc/main/daemon/daemon-spawner.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
| const launcher = spawnerInstances[0].launcher as ( | ||
| socketPath: string, | ||
| tokenPath: string | ||
| ) => Promise<{ mode?: string; shutdown(): Promise<void> }> |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Remove the duplicated function-type declarations.
Each duplicate follows a complete ) => Promise<...> declaration. TypeScript cannot parse either test module. Vitest and type checking cannot load these files.
src/main/daemon/daemon-init-live-session-preservation.test.ts#L128-L128: remove the repeated) => Promise<{ mode?: string; shutdown(): Promise<void> }>line.src/main/daemon/daemon-init-packaged-bundle-staleness.test.ts#L62-L62: remove the repeated) => Promise<{ mode?: 'degraded-new-pty-fallback'; shutdown(): Promise<void> }>line.
📍 Affects 2 files
src/main/daemon/daemon-init-live-session-preservation.test.ts#L128-L128(this comment)src/main/daemon/daemon-init-packaged-bundle-staleness.test.ts#L62-L62
| reason: stalePackagedBundle ? 'stale_bundle' : 'different_app_path', | ||
| liveSessionCount: 0 | ||
| } | ||
| confirmedReplacement = (await cleanupDaemonForProtocol(runtimeDir, PROTOCOL_VERSION)).cleaned |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- applicable repository guidance ---'
find /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4 -type f -name '*.md' -print
printf '%s\n' '--- target file outline ---'
ast-grep outline src/main/daemon/daemon-replacement-preflight.ts
printf '%s\n' '--- target file ---'
cat -n src/main/daemon/daemon-replacement-preflight.ts
printf '%s\n' '--- directly bound cleanup and preservation definitions ---'
rg -n -U -C 8 'cleanupDaemonForProtocol|shouldPreserveDaemonWithLiveSessions' src/main
printf '%s\n' '--- session creation and replacement-preflight callers ---'
rg -n -U -C 6 'createSession|startSession|daemon-replacement-preflight|replacementPreflight|preflight' src/main/daemon src/mainRepository: stablyai/orca
Length of output: 50370
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- target preflight ---'
sed -n '1,150p' src/main/daemon/daemon-replacement-preflight.ts
printf '%s\n' '--- exact cleanup references ---'
rg -n -C 12 'cleanupDaemonForProtocol' src/main/daemon
printf '%s\n' '--- exact live-session references ---'
rg -n -C 12 'shouldPreserveDaemonWithLiveSessions' src/main/daemon
printf '%s\n' '--- daemon server request handling ---'
rg -n -C 10 "'createOrAttach'|createOrAttach|shutdown|killSessions" src/main/daemon/daemon-server.ts src/main/daemon/daemon-host.ts src/main/daemon
printf '%s\n' '--- launcher and preflight callers ---'
rg -n -C 12 'prepareDaemonReplacement|launchDaemon|createOrAttach' src/main/daemon/daemon-out-of-process-launcher.ts src/main/daemon/daemon-spawner.ts src/main/daemon/daemon-server.tsRepository: stablyai/orca
Length of output: 50370
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- target preflight ---'
cat -n src/main/daemon/daemon-replacement-preflight.ts | sed -n '1,140p'
printf '%s\n' '--- files defining or calling cleanupDaemonForProtocol ---'
rg -l 'cleanupDaemonForProtocol' src/main/daemon --glob '*.ts' --glob '!*.test.ts'
printf '%s\n' '--- files defining or calling shouldPreserveDaemonWithLiveSessions ---'
rg -l 'shouldPreserveDaemonWithLiveSessions' src/main/daemon --glob '*.ts' --glob '!*.test.ts'
printf '%s\n' '--- relevant server/host files ---'
git ls-files 'src/main/daemon/*server*.ts' 'src/main/daemon/*host*.ts' 'src/main/daemon/*launcher*.ts' 'src/main/daemon/*preflight*.ts'Repository: stablyai/orca
Length of output: 9201
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- cleanup implementation ---'
cat -n src/main/daemon/daemon-protocol-cleanup.ts
printf '%s\n' '--- preservation helper and remaining preflight ---'
cat -n src/main/daemon/daemon-replacement-preflight.ts | sed -n '140,280p'
printf '%s\n' '--- daemon server lifecycle and admission fields ---'
rg -n -C 14 'createOrAttachInFlight|idle-shutdown-pending|route|createOrAttach|shutdownIfIdle|shutdown' src/main/daemon/daemon-server.ts src/main/daemon/daemon-server-lifecycle.ts
printf '%s\n' '--- terminal host creation path ---'
cat -n src/main/daemon/terminal-host-session-create.ts
printf '%s\n' '--- replacement launcher path ---'
cat -n src/main/daemon/daemon-out-of-process-launcher.ts | sed -n '45,180p'Repository: stablyai/orca
Length of output: 48719
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- terminal admission implementation ---'
cat -n src/main/daemon/daemon-terminal-admission.ts
printf '%s\n' '--- request router implementation ---'
cat -n src/main/daemon/daemon-request-router.ts
printf '%s\n' '--- server construction and request dependencies ---'
cat -n src/main/daemon/daemon-server.ts | sed -n '30,210p'
printf '%s\n' '--- all direct admission calls ---'
rg -n -C 8 'admission\.|new DaemonTerminalAdmission|begin.*Create|end.*Create|inFlight' src/main/daemon --glob '*.ts' --glob '!*.test.ts'Repository: stablyai/orca
Length of output: 50369
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- session-count probe implementation ---'
rg -n -C 18 'function getAliveDaemonSessionCount|export .*getAliveDaemonSessionCount|getAliveDaemonSessionCount' src/main/daemon/daemon-launch-paths.ts
printf '%s\n' '--- client concurrency and connection handling ---'
rg -n -C 12 'class DaemonClient|async request|onControlRequest|handleRequest|authenticatedPairEstablished' src/main/daemon/client.ts src/main/daemon/daemon-client-connections.ts src/main/daemon/daemon-server.ts
printf '%s\n' '--- replacement launch entry points ---'
rg -n -C 10 'createOutOfProcessLauncher|prepareDaemonReplacement|new DaemonPtyAdapter|ensureConnectedWithin' src/main/daemon --glob '*.ts' --glob '!*.test.ts'
printf '%s\n' '--- daemon-scoped repository guidance and architecture ---'
find /tmp/coderabbit-repo-knowledge/stablyai/orca-89dc44e4 -type f -name '*.md' -print0 |
xargs -0 grep -Il 'daemon\|terminal\|session' |
while read -r file; do
printf '\n--- %s ---\n' "$file"
sed -n '1,120p' "$file"
doneRepository: stablyai/orca
Length of output: 50369
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- adapter session-creation caller ---'
rg -n -C 12 "'createOrAttach'|createOrAttach" src/main/daemon/daemon-pty-adapter.ts src/main/daemon/daemon-pty-connection-lifecycle.ts src/main/daemon --glob '*.ts' --glob '!*.test.ts' |
grep -E 'daemon-pty-adapter|daemon-pty-connection-lifecycle|createOrAttach|request' | head -120
printf '%s\n' '--- host disposal contract ---'
rg -n -C 14 'async dispose|dispose\(\)' src/main/daemon/terminal-host.ts src/main/daemon/terminal-host-session-shutdown.ts
printf '%s\n' '--- applicable guidance files ---'
find /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4 -type f -name '*.md' -printRepository: stablyai/orca
Length of output: 18765
Serialize session creation before cleanup
After shouldPreserveDaemonWithLiveSessions returns zero, createOrAttach can still pass DaemonTerminalAdmission while the daemon is accepting work. cleanupDaemonForProtocol then sends shutdown with killSessions: true; TerminalHost.dispose() can terminate that newly created session. Add a replacement admission fence or an atomic drain operation before the zero-session check.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Skew-before-resolver classification —
daemon-replacement-preflight.tsnow checksgetDaemonLaunchIdentity+isDaemonStaleForCurrentBundlebefore the macOS resolver probe, so an app-path/bundle-skewed daemon is diagnosed as such rather than as a generic resolver failure. - Sticky degraded fallback — a skewed macOS daemon that owns live sessions is preserved with a new
degraded-new-pty-fallback-stickymode that routes fresh PTYs to the local provider and never re-routes them (noprobeCurrentDaemonSpawn), so TCC attribution stays on the current app until an explicit restart. - Resolver/TCC path unchanged — the identity-
matchcase falls through to the previous resolver → TCC-attribution logic untouched. - Regression coverage — darwin-forced assertions pin the sticky mode, the resolver bypass on mismatch, and the no-probe recovery in the provider-installation suite.
The reorder is sound: on non-macOS the resolver probe already returned 'unknown' and identity ran anyway, so the only real differences are (1) mismatched/stale daemons with live sessions now localize fresh PTYs on macOS, and (2) a resolver-unhealthy-but-identity-mismatched daemon now reports different_app_path/stale_bundle instead of unhealthy_resolver — both intentional and reflected by the telemetry-ranking comment. The mode-literal propagation (daemon-spawner → daemon-out-of-process-launcher → preflight → daemon-provider-init) is complete, and the new tests assert exact values rather than loose truthiness, so they genuinely fail on regression.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
|
Closing after independent review + empirical validation of the failure model. Why: The fix triggers on version skew ( Empirical check (released 1.4.194 app, scratch TCC-clean profile, PTYs spawned by its daemon into ~/Documents):
Natural experiment: a production machine currently runs a 5-week / ~35-version stale daemon (1.4.159 under 1.4.194) with fully working terminals. Conclusion: 'version skew breaks TCC for fresh daemon PTYs' does not reproduce in any variant, so the sticky fallback trades a proven regression for an unconfirmed fix. #17696 needs a reproduced root cause first (candidates: daemon outliving its login session — the existing resolver-health territory — rather than bundle skew). |

Summary
Fixes #17696
Validation
pnpm test src/main/daemon/daemon-init-endpoint-adoption.test.ts src/main/daemon/daemon-init-provider-installation.test.ts src/main/daemon/daemon-init-restart-sequence.test.ts src/main/daemon/daemon-init-live-session-preservation.test.ts src/main/daemon/daemon-init-packaged-bundle-staleness.test.ts src/main/daemon/degraded-daemon-pty-provider.test.ts --run(81 passed)pnpm tc:nodepnpm exec oxlinton changed files