perf(ssh): cut warm high-latency connects from 88.7s to 7.7s
Summary
Fixes #9014.
On a controlled ~155 ms RTT SSH link, warm connect took 88.721s even though the same connection with managed hooks disabled took 8.031s. The root cause was 14 serial managed-hook installers issuing 161 high-level SFTP operations, which expanded to roughly 450–600 WAN round trips. Hook installation alone consumed 80.690s.
This substantially reworks the original concurrency/hydration-overlap proposal. Orca now sends one managed-hook RPC to the already-running remote relay, and the relay executes the existing installers through a local-filesystem adapter. Installers remain serial, preserving deterministic config merges while removing the RTT multiplier.
Design
- Add one
agent_hook.installManagedHooksrelay RPC. - Execute managed-hook filesystem work locally inside the remote relay.
- Keep installers serial; do not race shared user configuration.
- Lazy-load
managed-hook-runtime.jsso installer code does not add relay startup parse cost. - Complete hook installation before plugin sync and PTY registration.
- Serialize account-level config writes across relay daemons with an owner-validated lock.
- Scope lock ownership using the negotiated SSH host-key fingerprint when available, a secure durable per-host token, and process-incarnation identity.
- Never reuse a stale ssh2 fingerprint after switching to system SSH transport.
- Skip POSIX managed installers on native Windows SSH; WSL behavior is unchanged.
- Treat individual installer failures as best-effort so SSH/filesystem/Git/terminal startup still succeeds.
Why not the original approach:
- Bounded concurrency still pays hundreds of WAN round trips and introduces shared-config races.
- Content/no-op probes still require the remote filesystem round trips that dominate warm connects.
- Renderer hydration overlap hides work without making the SSH session ready, and can expose plugins or PTYs before hooks exist.
- Moving the filesystem boundary into the relay removes the latency source with one network request.
Controlled SSH results
Measured through Orca's real renderer → IPC → SSH → relay path against an isolated throwaway Linux Docker target and a real /work/demo-project repository. The target used tc netem delay 150ms; established exchanges measured approximately 153.5–156.7 ms.
Timing predicate: immediately before window.api.ssh.connect({ targetId }) until that promise resolved with connected state.
| Scenario | Before | This PR |
|---|---|---|
| Cold deploy/connect | 122.321s | 18.438s |
| Warm connect | 88.721s | 7.724s / 7.741s |
| Managed-hook phase | 80.690s | 26.273ms |
| Hooks disabled baseline | 8.031s | — |
The local and remote relay bundles had matching SHA-256 hashes and sizes. A real Orca PTY ran in /work/demo-project, wrote/read/removed a marker, and left the repository clean.
Failure-path proof
With deliberately malformed Claude settings, exactly one installer failed as expected while SSH still reached connected state in 7.783s. The original configuration was restored, no lock/claim/draft/temp residue remained, and the next clean connection succeeded in 7.751s.
Validation
Passed locally at f8d17d750630924828e9df12b9dbb2da76663e8a:
- Focused managed-hook/SSH suites: 234 passed, 6 skipped; companion lane: 12 passed, 1 skipped.
- Full TypeScript typecheck.
- Relay builds for Linux x64/arm64, macOS x64/arm64, Windows x64/arm64, and WSL.
- Targeted type-aware lint.
- Reliability gates, max-lines ratchet, and
git diff --check. - Fresh correctness, performance/elegance, and real-SSH review lanes: clean.
Known unrelated repository-wide failures:
- Full lint currently stops at the pre-existing non-exhaustive switch in
src/renderer/src/components/skills/skill-freshness-group.tsx:101. - The runtime package contract has one local-environment failure because
node_modulescannot resolve the already-declaredwindows-native-registrydependency.
Native Windows SSH runtime validation is intentionally still pending before land; the Windows relay bundles build successfully and the code path has deterministic unit coverage.
Backward compatibility
Relay builds are content-versioned and installed side-by-side. A new Orca version deploys its matching relay without overwriting a live older relay; old completed directories are garbage-collected only after their sockets are no longer live. The wire handshake rejects accidental cross-version attachment.
As with the existing versioned-relay design, live PTY state does not migrate between relay code generations. Mixed simultaneous old/new Orca versions also cannot share the new managed-hook lock because older clients do not know about it.
Screenshots
No visual change.
[!NOTE]
Reviews paused
It 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
reviews.auto_review.auto_pause_after_reviewed_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.Use the checkboxes below for quick actions:
- [ ] ▶️ Resume reviews
- [ ] 🔍 Trigger review
📝 Walkthrough
Walkthrough
Managed hook installation now uses a packaged runtime that resolves GROK_HOME, adapts local filesystem operations to the installer interface, and serializes installations with identity-aware lock records and recovery claims. A relay RPC forwards cancellation and validated SSH host-key fingerprints to the runtime. SSH sessions invoke this RPC before plugin and provider setup. Relay builds, version hashes, installation probes, fixtures, and tests now include the managed-hook runtime artifact. SSH connection attempts also use generation-based cancellation to prevent stale connections from overwriting newer state.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 17.50% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
✅ Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Linked Issues check | ✅ Passed | The code addresses #9014 by moving managed-hook installs into the relay, keeping installers serial, and ensuring hooks complete before plugins/PTYs. |
| Out of Scope Changes check | ✅ Passed | The changes stay focused on SSH/managed-hook latency, locking, and relay integration, with no clear unrelated additions. |
| Title check | ✅ Passed | The title is concise, specific, and accurately summarizes the main performance-focused SSH change. |
| Description check | ✅ Passed | The description covers the required sections and is detailed enough, including summary, screenshots, testing, review, security, and notes. |
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 @coderabbitai help to get the list of available commands.
thank you for the PR! will get it in ASAP
Windows validation completed and fixes pushed.
SHAs
- Original PR SHA independently validated:
f8d17d750630924828e9df12b9dbb2da76663e8a - Fix commit pushed:
6b81a0426c1d3bb222ae02a2000b41bda32815bc - I fetched the contributor branch immediately before pushing; it was still exactly
f8d17d750....
Environment Windows 11 Home build 26200, x64; Node 25.9.0 (repo requests 24), pnpm 10.24.0, Git 2.53.0.windows.2, OpenSSH 9.5p2, Electron 43.1.0, Docker Desktop 4.38.0 / engine 27.5.1. Timed runs below used normal ssh2 transport.
Real Windows renderer -> IPC -> SSH -> relay timings
| Checkout | Case | Time |
|---|---|---|
f8d17d750 |
cold | 35.035 s |
f8d17d750 |
warm 1 | 7.920 s |
f8d17d750 |
warm 2 | 7.964 s |
f8d17d750 |
malformed Claude config | 7.834 s |
f8d17d750 |
restored clean | 8.262 s |
6b81a0426 |
cold | 37.296 s |
6b81a0426 |
warm 1 | 7.541 s |
6b81a0426 |
warm 2 | 7.536 s |
6b81a0426 |
malformed Claude config | 10.802 s |
6b81a0426 |
restored clean | 7.932 s |
The target was a throwaway node:24-bookworm SSH container with no host mounts, a dedicated key/profile, and a standalone Git repo at /work/demo-project (initial commit 4c8b29a; GitHub demo-project cloning/auth were unavailable, so it was initialized in-container). A toxiproxy downstream 150 ms latency toxic was used because this Docker kernel did not provide tc netem. Fresh OpenSSH exchange measurements were 161.8 ms direct and 1283.5-1307.6 ms through the proxy (average added exchange time 1131.7 ms).
The warm result is at the hooks-disabled floor, not tens of seconds. A direct fixed-commit in-relay hook pass completed all 14 installers with 0 errors in 419.763 ms including module/process startup.
Relay evidence (6b81a0426)
Local out/relay/linux-x64 and remote /root/.orca-remote/relay-0.1.0+659ed501a518 matched:
relay.js: 350,713 bytes, SHA-2564ce8f4c5c45a560860088f0cfcde49e133dab23742988cdf02cc99ced4c37b90relay-watcher.js: 4,330 bytes, SHA-256def44ba32dc800f205ffda9b784d889d45cc17966837b0416d8f5be8aab1efc0managed-hook-runtime.js: 266,224 bytes, SHA-256b75887894304611fa489dff7736b4edd766a7d151b60f54ddee92b9b752fc52e
Artifacts were produced for win32-x64, win32-arm64, linux-x64, and linux-arm64 (also both Darwin targets).
Functional/failure evidence
- Real remote PTY ID
ssh:ssh-1784532866578-rqufjv@@pty-3reached/work/demo-project. - Through the PTY, a marker was written, read as
marker-ok, deleted, and verified absent. window.api.pty.getCwd()returned/work/demo-project;git status --porcelainwas empty.- Malformed Claude JSON did not block connection; the exact file was restored, the next clean connect returned to the warm floor, and both JSON configs parsed afterward.
- No lock, recovery-claim, draft, or temp residue remained.
- The pushed fix's live cancellation race passed: disconnect resolved at 503 ms, the obsolete connect rejected as cancelled at 1.048 s, the immediate replacement connected at 8.249 s, and final state stayed
connected. - Concurrent shared-account installation serialized safely in the exact-SHA exercise; expanded lock tests also pass on Windows and 15/15 under Ubuntu/WSL.
- Final demo repository and local worktree were clean.
Defects found and fixed in 6b81a0426
- High: disconnect + immediate reconnect could let stale IPC/session cleanup affect the replacement, and
SshConnectionManagerseparately rejected the replacement as “already in progress.” Added generation/identity ownership at IPC, ssh2, and manager layers plus live and regression coverage. - Medium: repeated “missing lock” inspection/recovery could retry without a bound. Retries are now bounded, including repeated stale-lock recovery.
- Test portability: fixed Windows path/getuid/mode-bit assumptions, selected Git Bash rather than WSL
bash.exe, recognized Droid's PowerShell carrier, and fixed one changed relay test's unbound-method lint issue.
Static/build commands
pnpm typecheck— passpnpm build:relay— pass- targeted Vitest managed-hook/relay/SSH/session/identity/lock suite — 184 pass, 25 expected platform/environment skips, 0 failures
- final focused Vitest after the manager fix — 117 pass, 15 expected skips
pnpm exec oxlint ...plus type-aware switch-exhaustiveness lint for changed files — passpnpm check:max-lines-ratchet— passpnpm check:reliability-gates— passgit diff --check— passpnpm build:win— TypeScript/Vite desktop compilation passed. Packaging is environment-limited here: one run hit the known WindowswinCodeSignsymlink privilege/Developer Mode extraction failure; a later bounded run reached electron-builder packaging and exceeded 303 s, then emitted EPIPE when terminated. I found no compile defect.
Lane matrix
- Windows client -> Linux target, ssh2: PASS
- Cold/warm performance: PASS
- Relay deploy/hash/version/artifacts: PASS
- Managed hooks and malformed-config recovery: PASS
- PTY/filesystem/Git: PASS
- Cancellation + immediate reconnect: PASS after pushed fix
- Shared-account concurrency/lock safety: PASS
- System OpenSSH fallback: PARTIAL — deterministic integration coverage passes; a wrapper E2E produced one 29.103 s connection then a 30 s harness timeout while direct wrapper commands remained 1.33-1.35 s. I did not attribute that harness-only behavior to product code.
- Older live relay upgrade/PTY generation migration: NOT EXERCISED
- Separate native Windows SSH host/named-pipe relay: NOT EXERCISED (no separate Windows SSH VM/machine was available; localhost was not substituted)
Logs
Observed relay startup included ORCA-RELAY v0.1.0 READY, a successful version=0.1.0+659ed501a518 handshake, and socket-client acceptance. Electron showed platform linux-x64, versioned install/reconnect, and TCP_NODELAY enabled. The isolated Windows daemon started on \\?\pipe\orca-terminal-host-v23-... and accepted control/stream clients. No SSH/relay/daemon error remained; the only unrelated renderer-side warning was an existing Claude credential refresh 401.
Cleanup Removed the SSH target from the isolated profile, stopped only the recorded dev-app process tree, removed both exact containers, removed the private Docker network, and deleted the isolated user-data/key/log directory. No test container, network, process, key, profile, or temp directory remains.
Recommendation: land once CI is green on 6b81a0426. The performance objective passes on real Windows Electron/SSH, and the connection/lock races found during validation are included in the pushed commit.