Skip to content

ci(ssh): macOS SSH-host lane for the pinned relay; fix uploads under a symlinked root - #24179

Merged
OrcaWin merged 3 commits into
mainfrom
OrcaWin/node-rt-p2-macoshost
Oct 1, 2026
Merged

OrcaWin merged 3 commits into
mainfrom
OrcaWin/node-rt-p2-macoshost

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​222 $\color{#cf222e}{\Huge{\mathbf{−}}}$​18 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​204
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​461 $\color{#cf222e}{\Huge{\mathbf{−}}}$​60 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​401

ELI5

This adds a CI test that uses a macOS runner as the SSH host. It runs its own SSH server with no Node, npm or compiler on the SSH path, and checks that Orca's pinned Node relay works on it. The test found and fixes a real upload bug: uploads failed whenever the source folder sat under a symlink, and on macOS /var is one.

What Changed

  • Bug fix (sftp-upload.ts): uploadDirectory compared each file's resolved path against an unresolved root, so any file under a symlinked parent looked like it escaped the root. The root is now resolved once, and a test covers a symlinked parent.
  • macOS host lane (ssh-hostile-hosts.yml job macos_hosts, on macos-14 and macos-15-intel):
    • A user-level /usr/sbin/sshd listens on loopback, with no sudo and no system changes.
    • SetEnv sets a PATH with no Node or Homebrew, and logging stand-ins replace npm, node-gyp, compilers and xattr.
    • Each run checks rung A, a terminal echo, runtime reuse, and that runtime cleanup keeps the runtime in use. It also checks that no quarantine attribute is set and that the uploaded Node runs as it arrived.
  • Driver: the hostile-host driver now takes either a Docker cell or a local-sshd cell. It fails if a named cell can't run on the current machine, instead of passing without running anything (fixed in review).

Why

This covers the macOS part of the Phase 2 exit gate, on CI runners rather than a shared machine.

Linked Issue

Part of the Node runtime plan (Phase 2). Stacked on #24146.

Visual Proof

N/A. This is CI plus a bug fix.

Testing

  • Passed end to end on a local Mac (macOS 26.6.2 arm64): rung A, then a second connect with runtimeTransfer=cached.

  • 2,976 SSH tests pass.

  • Not yet run:

    • the GitHub macOS runners, which could restrict SSH logins through com.apple.access_ssh;
    • the darwin-x64 cell.
  • Can't be hidden: the SIP-protected /usr/bin/cc stubs, which are shadowed on PATH but not removed.

  • I manually tested these changes locally

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

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.

@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[High risk] Adds macOS SSH test infrastructure and symlink handling.

The PR appears safe to merge with respect to new findings, though the existing non-blocking cleanup concern remains.

Findings

  1. P2 Cleanup can delete live runtime ▶

Summary

The PR adds macOS runners as loopback SSH hosts for the pinned-relay test and adds coverage for uploads beneath a symlinked root.

  • The macOS cells build their matching runtime slots and exercise deployment, terminal use, reuse, and cleanup assertions.
  • The hostile-host driver selects only cells the current machine can run and fails rather than passing an empty named run.
  • Upload tests cover a root reached through a symlink or junction.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  CI[macOS runner] --> Build[Build matching slot and relay]
  Build --> SSHD[Start loopback sshd]
  SSHD --> Deploy[Deploy pinned relay over SSH]
  Deploy --> Verify[Check terminal, runtime reuse and cleanup]
Loading

Reviews (3) · Last reviewed commit: "test(ssh): fail a hostile-host run that ..."

Comment on lines +183 to +185
await waitForNoProcessMatching(target.tempDir, 5_000)
}
await rm(target.tempDir, { recursive: true, force: true })

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Cleanup can delete live runtime If a relay process remains after both termination attempts, the second process check can return false, but cleanup still deletes its temporary home. This can remove runtime and log files beneath a live process and make a failed macOS cell harder to diagnose. Keep the files until process exit is confirmed, and report unsuccessful cleanup.

Knowledge Base Used: Restore bounded SSH relay lsof probes

@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 — the full 3-commit PR against OrcaWin/node-rt-p2-hostile.

  • SFTP upload root resolution — uploadDirectory now resolves its root once before entries are compared by realpath, so a root under a symlinked parent (macOS /var → /private/var) no longer rejects its own children as escapes; the recursive body moved to uploadDirectoryWithin carrying the resolved root.
  • macOS hostile-host lane — new macos_hosts workflow job runs each macOS runner (macos-14 arm64, macos-15-intel x64) against its own user-level loopback sshd, builds that runner's darwin slot/template/relay, and adds src/main/ssh/sftp-* to the trigger paths.
  • Local-sshd harness — ssh-hostile-host-local-sshd.ts starts a pubkey-only sshd with PATH cut to the toolchain shims, probes the SSH exec channel to prove no host toolchain or node leaks, and cleans up sshd plus the daemonised relay by temp-dir match.
  • Cell selection guard — HostileHostCell is split into Docker and local-sshd variants; selectHostileHostCells now fails a run that names a cell the machine cannot host instead of silently skipping it, and a test asserts at least one cell was selected.
  • Shared shim — the forbidden-tool shim is factored into forbiddenToolShimScript(logPath) and reused by both targets; observers and stat identity probes split by host OS.

I verified the fix against the prior implementation and all in-repo callers: every caller already passes the upload directory as its own root, so resolving it once is idempotent while closing the symlinked-parent gap, and the sibling-escape rejection test still holds. Targeted tests, pnpm tc:node, and oxlint on the changed files all pass. The author already flags that the GitHub macOS runners and the darwin-x64 cell are unexercised.

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

@OrcaWin
OrcaWin force-pushed the OrcaWin/node-rt-p2-hostile branch from 4dfbd08 to 4fad278 Compare October 1, 2026 09:36
@OrcaWin
OrcaWin requested a review from brennanb2025 as a code owner October 1, 2026 09:36
@OrcaWin
OrcaWin force-pushed the OrcaWin/node-rt-p2-macoshost branch from 84e5df5 to e0c6946 Compare October 1, 2026 10:27
@OrcaWin
OrcaWin requested a review from Jinwoo-H as a code owner October 1, 2026 10:27
@OrcaWin
OrcaWin changed the base branch from OrcaWin/node-rt-p2-hostile to main October 1, 2026 10:29
@OrcaWin OrcaWin closed this Oct 1, 2026
@OrcaWin OrcaWin reopened this Oct 1, 2026
m4air added 3 commits October 1, 2026 04:05
The upload-root realpath fix landed with #24180; this keeps macoshost's case
where the root is passed explicitly beneath a symlinked parent.
Adds local-sshd cells for darwin-arm64 (macos-14) and darwin-x64
(macos-15-intel): a non-root sshd on 127.0.0.1 logs in as the runner user
with SetEnv PATH=<shims>:/usr/bin:/bin:/usr/sbin:/sbin and an empty HOME, so
no rc file restores Homebrew. The driver asserts rung A, terminal echo,
cached runtime reuse, GC keeping the in-use runtime, no toolchain or xattr
calls, and that the SFTP-uploaded Node carries no quarantine and runs as
uploaded. Docker cells are unchanged; each machine runs only cells it can host.
…table cell

A cell named for the wrong OS or arch was silently skipped, so a macOS job on a
mismatched runner went green having deployed nothing. Named cells must now be
hostable here, and a gated run must select at least one cell.
@OrcaWin
OrcaWin force-pushed the OrcaWin/node-rt-p2-macoshost branch from e0c6946 to 31f9f2f Compare October 1, 2026 11:05
@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

🧰 Additional context used
📚 Code guidelines (1)
AGENTS.md — auto-discovered
📝 Walkthrough

Walkthrough

The hostile-host matrix now includes macOS arm64 and x64 local SSH targets. Target selection checks host platform and architecture, and the fixture supports both Docker and local SSH targets. The workflow builds and tests the matching macOS targets. The hostile-host tests add local-target checks, and a separate SFTP test covers uploads through a symlinked parent.

Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to 31f9f

The macOS test target can leave processes and temporary files behind if sshd stalls during shutdown. This is a narrow test-cleanup risk; merge with owner awareness, preferably after bounding the termination wait.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 31f9f

The new SSH service is restricted to loopback and generated keys, with temporary test state and read-only repository permissions. Its shutdown path does not guarantee complete cleanup after a termination failure, but the supported exposure is limited to the test runner.

Retained concerns

  • Low · reliability · inferred: The newly introduced target cannot guarantee a clean terminal state after termination failure. It waits indefinitely for sshd after SIGTERM, blocking relay termination and temporary-key removal if sshd does not exit. After relay escalation to SIGKILL, it ignores the final process-absence result and can finish without proving descendants are gone. This weakens containment of runner-user processes and temporary SSH authority; actual process survival was not reproduced.
Security review details

Security Blast Radius

  • inferred — The supported new exposure is the macOS test runner's user-level SSH sessions, relay processes, and temporary credentials. Remote network reachability is restricted by the loopback listener. No new production-service or tenant authority is established by the inspected paths.

Trust Boundaries and Controls

  • observed — The workflow uses pull_request rather than pull_request_target, grants contents: read, and disables checkout credential persistence in the macOS job. The local SSH connection uses the generated identity with IdentitiesOnly, but disables host-key verification for this ephemeral test endpoint.

Resilience and Maintainability Implications

  • inferred — The 40-minute CI job timeout limits a hung job's duration but does not prove target cleanup. The cleanup concern is therefore about local process and credential lifecycle, not demonstrated external compromise.

Hardening Proposals

  • proposed — Give sshd shutdown a bounded termination-and-escalation sequence, require verified descendant termination before reporting cleanup success, and preserve a diagnosable failure state when termination cannot be confirmed.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 33 functions across 8 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes both primary changes: the macOS SSH-host CI lane and the symlinked-root upload fix.
Description check ✅ Passed The description is mostly complete. It covers the user impact, implementation, motivation, linked issue context, visual proof, testing results, limitations, and automated test updates. It omits the op…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 33 functions across 8 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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.

❤️ Share

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: 598eb6e7-e0c4-4ca6-b1b5-4d10ade8f842

📥 Commits

Reviewing files that changed from the base of the PR and between 0ad77ea and 31f9f2f.

📒 Files selected for processing (9)
  • .github/workflows/ssh-hostile-hosts.yml
  • config/scripts/ssh-hostile-hosts-workflow.test.mjs
  • src/main/ssh/sftp-upload.test.ts
  • src/main/ssh/ssh-hostile-host-cells.test.ts
  • src/main/ssh/ssh-hostile-host-cells.ts
  • src/main/ssh/ssh-hostile-host-local-sshd.test.ts
  • src/main/ssh/ssh-hostile-host-local-sshd.ts
  • src/main/ssh/ssh-hostile-host-test-fixture.ts
  • src/main/ssh/ssh-relay-hostile-hosts.docker.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

Comment on lines +173 to +178
export async function stopLocalSshdTarget(target: LocalSshdHostileHostTarget): Promise<void> {
if (target.sshd.exitCode === null && target.sshd.signalCode === null) {
const exited = new Promise((resolve) => target.sshd.once('exit', resolve))
target.sshd.kill('SIGTERM')
await exited
}

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '95,215p' src/main/ssh/ssh-hostile-host-local-sshd.ts
sed -n '90,115p' src/main/ssh/ssh-hostile-host-test-fixture.ts
sed -n '65,145p' src/main/ssh/ssh-relay-hostile-hosts.docker.test.ts

Repository: stablyai/orca

Length of output: 7743


Bound the sshd termination wait.

stopLocalSshdTarget waits indefinitely for the managed sshd process to emit exit after sending SIGTERM. A stopped or stalled sshd can remain alive and prevent relay cleanup and temporary-directory removal until the outer test hook times out. Keep the normal SIGTERM path, but use a bounded wait and send SIGKILL when the wait expires.

Suggested fix
-    const exited = new Promise((resolve) => target.sshd.once('exit', resolve))
+    const exited = new Promise((resolve) => target.sshd.once('exit', resolve))
     target.sshd.kill('SIGTERM')
-    await exited
+    const timedOut = await Promise.race([
+      exited.then(() => false),
+      new Promise<boolean>((resolve) => setTimeout(() => resolve(true), 10_000))
+    ])
+    if (timedOut) {
+      target.sshd.kill('SIGKILL')
+      await exited
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export async function stopLocalSshdTarget(target: LocalSshdHostileHostTarget): Promise<void> {
if (target.sshd.exitCode === null && target.sshd.signalCode === null) {
const exited = new Promise((resolve) => target.sshd.once('exit', resolve))
target.sshd.kill('SIGTERM')
await exited
}
export async function stopLocalSshdTarget(target: LocalSshdHostileHostTarget): Promise<void> {
if (target.sshd.exitCode === null && target.sshd.signalCode === null) {
const exited = new Promise((resolve) => target.sshd.once('exit', resolve))
target.sshd.kill('SIGTERM')
const timedOut = await Promise.race([
exited.then(() => false),
new Promise<boolean>((resolve) => setTimeout(() => resolve(true), 10_000))
])
if (timedOut) {
target.sshd.kill('SIGKILL')
await exited
}
}

@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 — delta since the prior pullfrog review (84e5df54c0): the branch was rebased from the stacked base onto current main, and the new commits rework the driver to adopt main's shared hostile-host harness and observer instead of the PR-local inline helpers.

  • Adopted the shared harness — ssh-relay-hostile-hosts.docker.test.ts and ssh-hostile-host-test-fixture.ts now use ssh-hostile-host-test-harness.ts (deployOnce / assertCell / exerciseLaunchedCell) and ssh-hostile-host-observer.ts (localHostObserver), dropping the PR-local hostileHostOs / fileIdentityCommand split and the inline deploy helpers.
  • legacy_opt_out in the driver — the non-launched branch now skips the refusal assertion for opted-out cells (cell.expect.outcome !== 'legacy_opt_out').
  • Unchanged from the prior review — the Docker/local-sshd cell union, machine-aware selectHostileHostCells, forbiddenToolShimScript, the macos_hosts lane, the at-least-one-cell guard, and the symlinked-parent upload test all carry over intact.

pnpm tc:node is clean and the four targeted suites pass (32 tests).

ℹ️ PR body still describes a prod fix that is no longer in the diff

The "What Changed" section tells a reviewer to look at a bug fix in src/main/ssh/sftp-upload.ts, but that file is not part of this PR's diff against main — the fix already landed there, and this PR now carries only the regression test. Updating the body avoids a reviewer hunting for a prod change that isn't in the PR.

Technical details
# PR body advertises a prod change absent from the diff

## Affected sites
- `src/main/ssh/sftp-upload.ts` — unchanged in this PR; `git diff --stat 0ad77ea2f7..HEAD -- src/main/ssh/sftp-upload.ts` is empty.
- PR body, "What Changed" bullet `**Bug fix**` (`sftp-upload.ts`) — describes a change not present here.

## Required outcome
- Body describes what this PR actually changes, or notes that the SFTP fix already landed on `main` and this PR carries only the regression test.

## Open questions for the human (optional)
- Is the stale text intentional (the PR is a rebase of a stacked branch), or should the body be refreshed?

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

@OrcaWin
OrcaWin merged commit f9940d5 into main Oct 1, 2026
51 checks passed
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.

1 participant