Repository navigation
fix(ssh): collect relay versions only when provably exited; runtimes/ store GC - #24130
Conversation
|
| 'pid=$(cat "$pid_file" 2>/dev/null) || { echo UNVERIFIABLE; exit 0; }', | ||
| 'case "$pid" in "" | *[!0-9]*) echo UNVERIFIABLE; exit 0;; esac', | ||
| 'if orcad_alive "$pid"; then echo LIVE; exit 0; fi', | ||
| 'for f in "$dir"/relay-*.sock "$dir"/relay.sock; do', |
There was a problem hiding this comment.
Relocated live sockets go unseen
On a host with a long home path, relay sockets move under /tmp/.orca-relay-…, but this probe checks only the version directory. If two relays share that directory and the last one to write .relay-pid exits while the other remains active, the probe sees a dead PID and no sockets. It reports EXITED, allowing GC to remove an install that a live relay still uses.
| if (!recheck || holdReason(sha, recheck, new Set(options.currentPins)) !== null) { | ||
| await restoreTree(conn, host, tombstone, entryDir, options.signal) | ||
| kept.push(name) | ||
| continue | ||
| } | ||
| if (await removeTree(conn, host, tombstone, options.signal)) { |
There was a problem hiding this comment.
References can arrive after recheck
The collector checks for new references after renaming a runtime, then deletes it without coordinating with installers. If an installer writes a slot’s .runtime-node marker for an older, unpinned runtime after that check, the deletion leaves the slot pointing to a missing bin/node, and its launcher exits with status 78. This is a non-blocking concern while runtime-store cleanup is not called in production, but it needs a handoff with installers before the collector is enabled.
There was a problem hiding this comment.
ℹ️ No critical issues — well-tested change; one minor suggestion inline about the strength of the new
exitedverdict.
Reviewed changes
- Relay version-dir liveness becomes three-way (
relay-version-dir-liveness.ts, new): the relay publishes.relay-pidafter binding (relay-pid-publication.ts,relay-daemon.ts), and GC deletes only on anexitedverdict — recorded PID dead and every in-dirrelay-*.sockrefusing. No-PID dirs keep thetest -Srule; Windows keeps the pipe probe. - Previous relay build is pinned (
remote-install-previous-version.ts, new): the shared GC resolves the newest other completed install by.install-completemtime viaresolveExtraPinnedDirNames, and deletes nothing when the host cannot answer. runtimes/gets its own owner (remote-install-model.ts): neither version-dir model can list or delete the shared Node store.- Shared runtime-store GC (
remote-node-runtime-store-gc.ts+remote-node-runtime-store-inventory.ts, new): delete anode-<sha>only when verified, unreferenced, unpinned and unheld, using rename-to-tombstone then full re-inventory with restore; abandoned tombstones are purged. Wired only from orcad GC whennodeRuntimePinsis supplied. - Tests across liveness (real
/bin/sh+ real sockets), previous-version ordering (real shell), and runtime-store GC (real processes, symlinked home) are meaningful and would fail on the behavior they pin.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| ' *) echo UNVERIFIABLE; exit 0;;', | ||
| ' esac', | ||
| 'done', | ||
| 'echo EXITED' |
There was a problem hiding this comment.
The exited verdict here rests on "recorded PID dead" plus a failed connect, but unlike parseRelayEndpointIncumbentProbe it never enumerates socket holders, and the single last-writer .relay-pid cannot represent a version dir serving several instances (the PR body notes this). A live sibling whose own relay-*.sock was unlinked or relocated outside $dir is invisible to this loop, so the header's "provably dead" wording (lines 5-8) claims more than the evidence carries. This is largely the pre-existing blind spot of test -S/in-dir globs, but since the worst outcome here is deleting a tree under a running relay, it is worth either enumerating holders before saying exited (reuse RELAY_LSOF_PROBE_JS) or explicitly scoping the header to the in-dir socket set.
Technical details
# `exited` is asserted from less evidence than the boundary doc requires
## Affected sites
- `src/main/ssh/relay-version-dir-liveness.ts:43` — sibling-instance case handled only through the `accepted` branch
- `src/main/ssh/relay-version-dir-liveness.ts:51` — `echo EXITED` when no in-dir socket accepts
- `src/main/ssh/relay-version-dir-liveness.ts:5-8` — header claims provable exit
- `src/main/ssh/relay-pid-publication.ts:21-24` — one `.relay-pid`, last writer, never removed on shutdown
- `src/main/ssh/ssh-relay-endpoint-incumbent.ts:181` — the established `exited` requires `holdersEnumerable && (refused || absent)`
## Relevant behavior
- `remote-install-gc.ts:307-308` treats `!== 'exited'` as live, so `exited` is the only verdict that authorizes deletion.
- `ssh-relay-endpoint-incumbent.ts:10-20` documents that an unlinked-socket relay is "invisible to this probe by construction".
- Startup/takeover windows: `relay-daemon.ts:108-109` binds before publishing the PID, and `relay-socket-ownership.ts:198-212` unlinks a stale inode before rebinding, so a brief `absent`/`refused` interval can coincide with a live process.
## Required outcome (pick one)
- Enumerate socket holders (as the incumbent probe does) before returning `exited`, or
- Treat "dead recorded PID + no accepting in-dir socket" as `unverifiable`, or
- Keep the current behavior but narrow the header claim to the in-dir socket set and record the unlinked/relocated-sibling blind spot as an accepted limitation.
## Open question
- Is a version dir that still hosts a live-but-unlinked relay intentionally collectible, or should it be kept?…s the previous build The relay records .relay-pid in its version dir once it owns its socket. GC calls a relay version dir exited only when that PID is provably dead and every relay-*.sock refuses a connection; a dir without a PID file keeps the test -S rule. The most recently completed other relay build is pinned like orcad's rollback target. Design D5 GC liveness.
…n owner runtimes/ gets its own owner in the install model, so no version-dir GC (new or old clients, whose listings are prefix-scoped) can list or delete it. A store pass removes node-<sha> only when no retained dir references it, it is neither a current pin nor the newest other verified runtime, and a ps or /proc check ran and found no process using it. Legacy relay-*/orcad-* dirs are read for references and reported as diagnostics only (design D10 two-step). Wired behind orcad GC's nodeRuntimePins.
…a symlinked home /proc exe resolves symlinks and argv keeps whatever spelling launched the runtime, so filtering on the exact $root path missed in-use runtimes on hosts like /home -> /var/home. Filter on the store segment instead; the parser already attributes holds root-agnostically.
3dc1d67 to
06355b9
Compare
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 🧰 Additional context used📚 Code guidelines (1)📝 WalkthroughWalkthroughThe changes add relay PID publication, endpoint liveness checks, and completed-install ordering to remote version cleanup. They add remote Node runtime-store inventory and garbage collection, including retention checks and staged removal. The install inventory now classifies the shared runtimes directory separately. Orcad cleanup can run the shared runtime-store collector when runtime pins are supplied. Priority: ⬇️ Low Merge Risk: 🟡 Moderate · up to Runtime-store cleanup could delete a Node runtime that a running process is still using on hosts that restrict Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to Cleanup gains useful retention safeguards, but interrupted recovery can leave a needed shared runtime unavailable at its original path. The risk is constrained by explicit runtime pins and conservative reference checks; no privilege escalation was established. Retained concerns
Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 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: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 45fa0d83-a89b-44ec-bcf3-8b691e78ff8b
📒 Files selected for processing (22)
src/main/ssh/orcad-remote-gc.test.tssrc/main/ssh/orcad-remote-gc.tssrc/main/ssh/relay-version-dir-liveness.test.tssrc/main/ssh/relay-version-dir-liveness.tssrc/main/ssh/remote-install-gc-termination.test.tssrc/main/ssh/remote-install-gc.tssrc/main/ssh/remote-install-model.test.tssrc/main/ssh/remote-install-model.tssrc/main/ssh/remote-install-previous-version.test.tssrc/main/ssh/remote-install-previous-version.tssrc/main/ssh/remote-node-runtime-store-gc.test.tssrc/main/ssh/remote-node-runtime-store-gc.tssrc/main/ssh/remote-node-runtime-store-inventory.tssrc/main/ssh/ssh-relay-cross-version-isolation.test.tssrc/main/ssh/ssh-relay-deploy.tssrc/main/ssh/ssh-relay-endpoint-incumbent.tssrc/main/ssh/ssh-relay-versioned-install.test.tssrc/main/ssh/ssh-remote-commands.tssrc/relay/relay-daemon.tssrc/relay/relay-pid-publication.test.tssrc/relay/relay-pid-publication.tssrc/shared/relay-artifacts.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
| 'if ps_out=$(ps -e -o args= 2>/dev/null); then', | ||
| " printf 'PROCESS_CHECK ps\\n'", | ||
| ` printf '%s\\n' "$ps_out" | grep -F -- /${ORCAD_RUNTIMES_DIRNAME}/ | sed 's/^/HOLD /'`, | ||
| 'fi', |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
set -eu
printf '%s\n' '--- changed file ---'
cat -n src/main/ssh/remote-node-runtime-store-inventory.ts
printf '%s\n' '--- merge-base diff ---'
git diff --no-ext-diff --unified=80 6593d7d194c758238119e548f1005d898374e2a1 06355b91f604a3803aa30783e0bc88ee1c0222c5 -- src/main/ssh/remote-node-runtime-store-inventory.ts
printf '%s\n' '--- direct references ---'
rg -n --glob '*.{ts,d.ts}' 'processCheckRan|PROCESS_CHECK proc|readlink /proc|PROCESS_CHECK ps|parseRuntimeStoreInventory|runtimeStoreInventoryCommand' srcRepository: stablyai/orca
Length of output: 16275
🏁 Script executed:
set -eu
cat -n src/main/ssh/remote-node-runtime-store-gc.ts | sed -n '35,145p'
printf '%s\n' '--- related tests ---'
cat -n src/main/ssh/remote-node-runtime-store-gc.test.ts | sed -n '35,135p'Repository: stablyai/orca
Length of output: 8641
Only mark the /proc check after reading a numeric PID link.
readlink /proc/self/exe does not prove that the scan can read runtime processes. The loop ignores failed PID-link reads, but PROCESS_CHECK proc still sets processCheckRan. The collector can then remove a running, unpinned runtime when held is empty.
Suggested fix
if [ -n "$(readlink /proc/self/exe 2>/dev/null)" ]; then
- printf 'PROCESS_CHECK proc\n'
+ proc_pid_read=0
for p in /proc/[0-9]*/exe; do
t=$(readlink "$p" 2>/dev/null) || continue
+ proc_pid_read=1
case "$t" in */${ORCAD_RUNTIMES_DIRNAME}/*) printf 'HOLD %s\n' "$t";; esac
done
+ [ "$proc_pid_read" -eq 1 ] && printf 'PROCESS_CHECK proc\n'
fi
ELI5
Remote hosts were filling up with old relay folders (5 GB on one test host), because a stale socket file looked like a running relay. The cleanup now checks whether the relay process is actually alive. It also keeps the previous version and cleans up the shared Node runtimes safely.
What Changed
.relay-pid: the relay writes it into its version folder after it starts listening.relay-version-dir-liveness.ts):exitedonly when the recorded PID is dead and everyrelay-*.sockrefuses a connection. A live PID meanslive. Anything uncertain meansunverifiable, and the folder is kept.runtimes/store:remote-install-model.ts, so relay and orcad cleanup can never touch it.relay-*andorcad-*folders as diagnostics only this release (design D10, two-step).Why
A socket file outlives its daemon, so
test -Salone could never collect dead installs. A connect probe alone would race with a daemon that is about to go idle; checking the PID first closes that race.Linked Issue
Part of the Node runtime plan (Phase 2; design D5 and D10). Related: #13852, #21215, #19194. Stacked on #24110.
Visual Proof
N/A. This changes cleanup on remote hosts, with no UI.
Testing
Real-shell tests cover:
The previous-version pin and the ownership rules have unit tests.
pnpm tcand the quality gates pass.Limits:
.relay-pidper folder, although one folder can serve several relays.I manually tested these changes locally
Automated tests added/updated, or explained why not below
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.