Repository navigation
feat(ssh): runtime-store GC in production and exec-stdin upload fallback - #24136
Conversation
|
| } | ||
| }) | ||
| } | ||
|
|
There was a problem hiding this comment.
Release can remove another owner's lock
If a runtime-store GC pass stays active beyond the 20-minute stale threshold, another client can replace its .store-lock. When the original pass finishes, this unconditional release removes the new owner's lock. A third client can then run GC or promotion at the same time, defeating the lock that protects runtime publication and deletion. The release needs to verify that it still owns the current lock.
Knowledge Base Used: Remote connectivity and execution
| ` recent=$(find "$s" -mmin -${staleMinutes} -print 2>/dev/null) || continue`, | ||
| ' [ -z "$recent" ] || continue', | ||
| ` rm -rf -- "$s" && printf '${SWEPT_STAGE} %s\n' "\${s##*/}"`, |
There was a problem hiding this comment.
Sweep can delete active uploads
If an SFTP archive upload pauses for more than 20 minutes while another client runs GC, this sweep deletes its stage because no file has been modified recently. The uploader has not yet taken the store lock, and the SFTP transfer has no matching idle timeout. When the upload resumes, its stage is gone and runtime promotion fails. An old file timestamp alone does not show that the upload has ended.
Knowledge Base Used: Remote connectivity and execution
| case 'failed': | ||
| throw new Error(`The pinned Node self-test at ${remoteRelayDir} failed: ${verdict.detail}`) |
There was a problem hiding this comment.
PTY failure blocks entire relay
If a host cannot open a PTY—for example, a container without usable /dev/pts—the self-test reports a spawn failure and this branch aborts the pinned relay install. File and Git services never start, although the legacy relay can launch with terminal support degraded. A PTY spawn failure should not prevent those other relay services from starting.
Knowledge Base Used: Remote connectivity and execution
| if (!Number.isSafeInteger(byteLength) || byteLength < 0) { | ||
| throw new Error(`Invalid upload size: ${byteLength}`) | ||
| } | ||
| const part = `${remotePath}.orca-part-${options.token}` |
There was a problem hiding this comment.
Interrupted uploads leave partial files
If an exec upload is aborted or times out before the shell reaches its failure branch, that branch cannot remove the .orca-part-* file. No later cleanup targets these filenames, so repeated interrupted uploads can leave large partial archives in the remote install area. This is a non-blocking cleanup gap.
There was a problem hiding this comment.
ℹ️ No critical issues — one design tradeoff worth a decision, plus minor notes below.
Reviewed changes — initial review of the full PR: the runtime-store GC wired into the production pinned-relay deploy under a new .store-lock, and a new exec-stdin upload fallback for hosts whose SFTP is refused or sandboxed.
- Runtime-store GC in production — after a pinned launch,
gcRemoteNodeRuntimeStoreruns with the launched pin ascurrentPins, sequenced after the version/ripgrep passes that drop superseded refs. .store-lock—remote-node-runtime-store-lock.tsreuses the install lock's mkdir primitives and 20-minute stale rule; GC tries once and skips a busy pass, promotion waits.- Stage sweeping — GC removes
.stage-*dirs nothing has written to inside the stale window; the stage prefix is now a shared constant. - Exec-stdin upload fallback — a new writer streams bytes into an exec channel, size-checks and atomically renames; selected only for exact ssh2 SFTP-refusal/sandbox errors on POSIX non-system-ssh transports, latched per connect generation.
- Pinned-Node relay runtime — per-host
remoteRuntime: 'pinned-node'opt-in, glibc probing with a 2.28 floor, prebuilt addons staged from the orcad slot, a runtime-folded relay version, pre-launch self-test verdicts, and an optional informationalruntimeon the handshake.
ℹ️ Nitpicks
ssh-exec-stdin-file-transfer.ts— a.orca-part-<token>partial written before an abrupt client abort/crash is never cleaned up; the new GC sweeps only.stage-*. Harmless (the suffix keeps it out of the "final file" class) but it can accumulate in a relay version dir.execCommand's newstdinhandling (ssh-relay-exec-command.ts:204-208) has no test for the local-read-error or non-zero-close-while-piping paths;ssh-exec-stdin-file-transfer.test.tsonly models the remote-side truncation (head -c 1000).- PR body claim precision: the fallback "covers both the system-ssh and ssh2 transports", but
canFallBackToExecStdindeliberately excludes the system-SSH transport (it already writes via exec). Worth wording as "the ssh2 transport gains the fallback; system-SSH already streams".
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| export async function withRuntimeStoreLock<T>( | ||
| conn: SshConnection, | ||
| host: RemoteHostPlatform, | ||
| storeDir: string, | ||
| task: () => Promise<T>, | ||
| signal?: AbortSignal | ||
| ): Promise<T> { | ||
| await acquireInstallLock(conn, storeDir, host, { | ||
| signal, | ||
| lockName: RUNTIME_STORE_LOCK_NAME, | ||
| relayGcClaim: false | ||
| }) | ||
| return runHoldingLock(conn, host, storeDir, task) | ||
| } |
There was a problem hiding this comment.
The store lock inherits the install lock's 20-minute stale takeover, but its holder is not bounded below that threshold the way an install-lock holder is. That steal rule exists because RELAY_DEPLOY_TIMEOUT_MS (15 min) keeps a live install-lock holder shorter than the 20-minute stale rule; a GC holder has no such bound — collectHoldingStoreLock runs an unbounded plan.purgeTombstones loop plus up to 8 move/re-inventory/remove cycles, each a 30 s exec. If a pass crosses 20 minutes, another client can legitimately steal the lock, and because releaseRuntimeStoreLock carries no ownership token it then deletes the thief's lock, letting a third holder run concurrently.
Technical details
# Store lock has no bound below its own steal threshold and no ownership check on release
## Affected sites
- `src/main/ssh/remote-node-runtime-store-lock.ts:90-103` — `withRuntimeStoreLock` acquires via `acquireInstallLock`, which steals any lock older than `INSTALL_LOCK_STALE_SECONDS` (1200 s).
- `src/main/ssh/remote-node-runtime-store-lock.ts:29-38` — `releaseRuntimeStoreLock` unconditionally `rm -rf`s the lock dir with no proof this process still owns it.
- `src/main/ssh/remote-node-runtime-store-gc.ts:221-256` — the GC task's duration is the sum of an unbounded `purgeTombstones` loop and up to `MAX_REMOVALS_PER_PASS` (8) move/re-inventory/remove cycles; no aggregate cap.
- `src/main/ssh/ssh-relay-install-lock-commands.ts:86-128` — the reused POSIX steal (`posixStealInstallLockCommand`) is what enables the ABA.
## Required outcome
- A GC pass cannot outlive the lock's stale threshold while it is still considered the owner, or a stolen lock cannot be released by the former holder.
## Suggested approach (optional)
- Bound `collectHoldingStoreLock` (e.g. cap `purgeTombstones` like `MAX_REMOVALS_PER_PASS`, or add an aggregate deadline below 1200 s) and/or have the lock carry a per-holder token (random value written into the lock dir) that `releaseRuntimeStoreLock` verifies before removing.
## Open questions for the human
- Is a >20-minute GC pass actually reachable on the supported hosts (large tombstone backlog + slow/large removals), or is the current narrow window acceptable given the rename/re-check/restore guard?3dc1d67 to
06355b9
Compare
3c6d318 to
22a2da0
Compare
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 🧰 Additional context used📚 Code guidelines (1)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 (4)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthroughThe change adds a shared lock for remote Node runtime promotion and garbage collection. Runtime collection now sweeps stale upload stages, and pinned deployments retain the active runtime hash. Pinned relay installation checks for the runtime under the lock. New exec-stdin transfer helpers support file, string, and directory uploads. Relay transfers use exec-stdin fallback for selected SFTP failures on eligible hosts. Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to This change adds locking around remote runtime promotion and cleanup, and an upload fallback for hosts that refuse SFTP. No concrete merge-blocking issue remains from this review. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The upload fallback uses the existing SSH connection and preserves staged writes and runtime verification. The main remaining risk is cleanup racing deployment of an older cached runtime. Recovery after interrupted remote work also needs stronger assurance. Retained concerns
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
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 |
22a2da0 to
38481bb
Compare
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
ℹ️ No new issues in this delta — the two D5 features were rebased onto the runtime-ladder base and two test commits landed. The only behavior adaptation is that rung C (host Node) and Windows hosts no longer take the runtime-store lock.
Reviewed changes — incremental delta since the prior pullfrog review (22a2da06 → 38481bb2): the PR was rebased onto the pinned-runtime ladder and now carries only the runtime-store GC and exec-stdin upload features.
- Rebased onto the runtime ladder — the post-launch
gcRemoteNodeRuntimeStorecall indeployAndLaunchRelayOnRuntimeis now keyed onprebuilt?.kind === 'pinned-node', so rung C and the legacy host-Node path skip it;currentPinsstays the launched pin. - Store lock only for the pinned rung —
verifyPinnedRelayInstalltakes the store lock and confirms/reinstalls the pin only forplan.kind === 'pinned-node'on a POSIX host; host-Node and Windows plans skip the store-lock round trips. - Test coverage — assertions that rung C never calls
withRuntimeStoreLock, that the OpenCode runtime setup answers the.store-lock(exec count 7 → 11), and that the pinned deploy GCs aftergcOldRelayVersions.
The other functional files in the diff (remote-node-runtime-store-lock.ts, remote-node-runtime-store-gc.ts, ssh-exec-stdin-file-transfer.ts, ssh-relay-install-transfers.ts) are unchanged from the previously reviewed state. The six affected ssh test files pass locally (58 tests).
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…store lock (D5) The pinned-Node relay deploy now collects runtimes/ after a successful launch, keeping the pin it runs. Promotion in ensureRemoteOrcadNodeRuntime and GC deletion both hold runtimes/.store-lock (install-lock primitives, 20-minute stale rule); GC only tries the lock and skips when busy. A cold pinned install re-checks its runtime under the lock once the relay ref is visible, closing the ensure-then-ref window. GC also sweeps runtimes/.stage-* dirs nothing has written to within the stale rule.
… is refused (D5) On the bundled ssh2 transport to a POSIX host, a definite SFTP refusal (subsystem refused, sftp-server exited during the handshake, or a chrooted view answering NO_SUCH_FILE for a shell-created path) now falls back to writing through an exec channel's stdin, reusing makePosixWriteFileCommand with a byte-count check and atomic rename. Transport loss, timeouts and aborts never select the fallback. execCommand gains a stdin option.
…p test Promotion now runs under runtimes/.store-lock, so the mocked host must grant the lock and the stage-exhaustion case makes four more round trips.
38481bb to
2241d8e
Compare
There was a problem hiding this comment.
ℹ️ No new issues in this delta. The branch was rebased onto the base that absorbed the Windows pinned-Node relay (#24135,
67014c8); the only production change is the promote/GC branch split that follows from that base, and no new review comments are warranted.
Reviewed changes — incremental delta since the prior pullfrog review (38481bb2 → 2241d8e2): the rebase adaptation for the Windows pinned-Node base plus the two test commits already covered.
- Windows promote takes no store lock —
ensureRemoteOrcadNodeRuntimenow splits the Windows promote (windowsNodeRuntimePromoteCommand,hostRemovedStage = windows) from the POSIX path that re-probes and promotes insidewithRuntimeStoreLock. Consistent by design:gcRemoteNodeRuntimeStorereturnsskippedon Windows andconfirmPinnedRuntimeHeldis POSIX-only. - Store lock still scoped to the pinned POSIX rung —
verifyPinnedRelayInstallconfirms/reinstalls the held runtime only forplan.kind === 'pinned-node'on a POSIX host; rung C and Windows skip the lock round trips (asserted by the new test). - Tests — the OpenCode runtime setup test answers the
.store-lockround trips (exec count 7 → 11); the two test commits are content-identical to those reviewed at38481bb2.
The exec-stdin, store-lock, and store-GC modules (remote-node-runtime-store-lock.ts, remote-node-runtime-store-gc.ts, ssh-exec-stdin-file-transfer.ts, ssh-relay-install-transfers.ts) are unchanged from the previously reviewed state.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
Two things. First, cleanup of the shared Node runtimes now actually runs after a pinned relay starts, under a lock so it can't race an install. Second, when a host's SFTP is missing or sandboxed (Synology, chrooted jump hosts), Orca now streams uploads over the SSH command channel instead of failing.
What Changed
gcRemoteNodeRuntimeStoreafter launch, after the version-folder GC. The legacy path never calls it.runtimes/.store-lockmkdir lock (20-minute stale rule) covers promotion, which re-probes under the lock, and GC, which tries the lock once and skips the pass if it's busy.Why
Design D5: without a production caller, runtime GC did nothing. The upload fallback addresses #12868 and #15479.
Linked Issue
Part of the Node runtime plan (Phase 2). Stacked on #24130 (includes #24129).
Visual Proof
N/A. This changes remote host setup, with no UI.
Testing
Command construction and fallback selection are tested for both transports.
A real local-shell test streams a payload over 10 MB and checks its hash.
Not tested against a real Synology or chrooted host: the ssh2 error strings are matched from ssh2 1.17.0's source.
Follow-ups:
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.