Skip to content

fix(ssh): don't import a config alias for a machine already in Orca - #35792

Merged
nwparker merged 3 commits into
mainfrom
fix/ssh-import-route-dedupe-15478
Oct 29, 2026
Merged

nwparker merged 3 commits into
mainfrom
fix/ssh-import-route-dedupe-15478

Conversation

@nwparker

@nwparker nwparker commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​469 $\color{#cf222e}{\Huge{\mathbf{−}}}$​44 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​425
Prod 12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​471 $\color{#cf222e}{\Huge{\mathbf{−}}}$​59 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​412

ELI5

If you added a machine to Orca by its IP address and also had it in ~/.ssh/config under a name, Orca added it a second time from the config. You then had two hosts that were really one machine, sharing one set of sessions. Now Orca asks OpenSSH where each config entry actually connects, and doesn't add a second copy of a machine that's already there.

What Changed

Before: the config import (on launch, from the hosts menu, from Settings, and from Add all) de-duplicated by alias name only. So Host aimp / HostName 172.16.203.131 was imported next to a saved 172.16.203.131 target.

After:

  • Import skips route duplicates. Each import resolves new aliases, and the saved targets, with ssh -G. It skips an alias whose route (host, port, user, and jump host or proxy command) an existing target already has.
  • One snapshot per run: each import builds one snapshot (the config it read, and which new aliases duplicate a saved route). The duplicate check and the inserts both read only that snapshot.
  • One queue: imports and picker refreshes run one at a time, so none can race another.
  • The picker reads the import's own decision. Its In Orca flags and Add all count come from the latest snapshot. The picker never waits on ssh -G; until a snapshot exists, its flags are by name only, as today.
  • Routes only match when both transports agree. A route counts only when Orca's two connection paths (built-in ssh2 and system ssh) resolve it to the same host, port, user and proxy. The system side is asked of OpenSSH itself, with the exact arguments system ssh passes, including the saved endpoint it restores when an alias's Host block is gone. Each path's token rules are applied (%h %p %r %n %%).
  • Unknown means no match. If anything is uncertain, or ssh -G fails or times out (5s), the route is unknown and nothing is matched.
  • Bounded process use: at most four ssh -G run at once, and a snapshot is reused while nothing it was built from changed (up to 5 minutes).
  • Unchanged: Restore still brings back every host it lists, and "previously removed" stays name-based. DNS isn't consulted. An alias with no HostName connects to its own name, so it matches an IP target only if HostName is set to that IP; that covers the reporter's config once HostName is set.

This builds on @kaluli123123's work in #15750. Their commit is kept with their authorship, and the follow-up commits credit them as co-author. They found that the duplicate came from comparing names, and they added the route fields (jump host, proxy command) to the identity. This PR supersedes #15750. Thank you @kaluli123123 for the careful investigation and the iterations.

Why

The identity has to match where Orca actually connects, so it comes from OpenSSH's own answer, not a partial parse of the config. Running imports one at a time against one snapshot keeps the decision simple: the picker and the import can't disagree.

Known trade-offs:

  • A target added or removed while an import is resolving routes is reflected by the next import, not that one.
  • Two different hosts that share a name in /etc/hosts or DNS aren't matched.

Linked Issue

Fixes #15478

Visual Proof

N/A: no visual change. The In Orca badge and Add all count already exist; they now reflect route matches. Reproducing it needs real SSH config and hosts, so the tests drive the import and picker with a fake ssh -G.

Testing

  • I manually tested these changes locally

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

  • New tests fail without their fix and pass with it:

    • the route key and its token rules (ssh-target-identity.test.ts);
    • the ssh2/system-ssh agreement cases: a saved target's own jump host conflicting with an inherited proxy, a host the two transports resolve differently, and an alias the config no longer claims;
    • the duplicate skip and picker parity;
    • snapshot reuse, and overlapping imports running one after another;
    • the rebuild after an import changes targets;
    • Restore;
    • the four-process budget;
    • the IPC wiring.
  • Checked that OpenSSH's ssh -G reports the route system ssh takes (-J, -o ProxyCommand, -o Hostname/-p/-l) using throwaway -F configs. No connections are made.

  • All SSH, IPC, persistence and managed-server tests that import changed modules pass. pnpm tc:node, oxlint, the changed-code quality gate, React Doctor and the ratchets pass.

  • Local static job: passes except the Node 18 process-host smoke (no local Node 18; process-host is untouched). The orcad terminal smoke runs on this machine only under heavy load, so CI covers it.

  • No manual test against real SSH hosts.

Review

Codex and an independent reviewer reviewed this design once each. The reviewer found nothing at P0–P2. Codex's two findings: one is fixed here (the picker's flags after an import changes targets); the other is the first trade-off above.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Platforms: works the same on macOS, Linux and Windows; it uses the existing process wrappers and Windows OpenSSH's ssh -G.
  • Compatibility: the IPC result shapes are unchanged, so mixed versions are fine.
  • Mobile and web: the web client stubs this picker and mobile has none.
  • Paired hosts: runtime-owned (paired) hosts are excluded as before.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

kaluli123123 and others added 3 commits October 29, 2026 00:15
…another name

The ssh-config picker compared names only, so a machine added by IP showed up
again under its config alias. It now also compares the endpoint: hostname
(case-insensitive), validated port, case-sensitive user, jump host and proxy
command. Entries without HostName still match by alias only.

Squashed from #15750 (3c3a3c6, a5575ce, 8daf213, a29d91e).
… in Orca

Each config import now builds one snapshot: the config it read, and which new
aliases resolve, through ssh -G, to a route an existing target already has.
The duplicate check and the inserts both read only that snapshot. Imports and
picker refreshes run one at a time through a single queue, so none can race
another, and the picker reads the latest snapshot for its In Orca flags and
Add all count without waiting (alias-only until one exists).

A route is keyed only when ssh2's rules and system ssh's (OpenSSH run with
system ssh's own destination args, including an unclaimed alias's stored
endpoint) agree on host, port, user and proxy, with each transport's token
rules. Anything uncertain, or a failed ssh -G, gives no key, so nothing is
matched by guess. At most four ssh -G run at once. Restore brings back the
hosts it lists, previouslyRemoved stays alias-only, and DNS isn't consulted.

Co-authored-by: vam <[email protected]>
An import that inserts or updates a target outdates its own snapshot, which
left the picker alias-only until the next refresh. It now queues a rebuild
behind itself. The picker also ignores a snapshot past its reuse window, and
the system-route shortcut requires a config alias.

Co-authored-by: vam <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 3 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7290a99d-0b82-40a6-90e5-f740b237aab6
Commits

Reviewing files that changed from the base of the PR and between 016cbe3 and a001bcb.

Files selected for processing: 20
  • docs/site/content/docs/ssh.mdx
  • src/main/ipc/ssh/ssh-ipc-mock-shapes.ts
  • src/main/ipc/ssh/ssh-ipc-module-mocks.ts
  • src/main/ipc/ssh/ssh-ipc-test-harness.ts
  • src/main/ipc/ssh/ssh-target-crud-handlers.ts
  • src/main/ipc/ssh/ssh-target-registry.test.ts
  • src/main/persistence/terminal-topology/persistence-ssh-targets-and-pane-keys.test.ts
  • src/main/ssh/config/ssh-config-host-picker.test.ts
  • src/main/ssh/config/ssh-config-host-picker.ts
  • src/main/ssh/config/ssh-config-parser.ts
  • src/main/ssh/config/ssh-g-config-resolution.ts
  • src/main/ssh/connection/ssh-connect-config.ts
  • src/main/ssh/connection/ssh-connection-store-orcad-ownership.test.ts
  • src/main/ssh/connection/ssh-connection-store-route-dedupe.test.ts
  • src/main/ssh/connection/ssh-connection-store.test.ts
  • src/main/ssh/connection/ssh-connection-store.ts
  • src/main/ssh/targets/ssh-target-identity.test.ts
  • src/main/ssh/targets/ssh-target-identity.ts
  • src/main/ssh/targets/ssh-target-route-resolution.test.ts
  • src/main/ssh/targets/ssh-target-route-resolution.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change affects SSH host imports and the config picker.

The PR appears safe to merge, with a non-blocking performance concern in picker searches.

Findings

  1. P2 Searching rereads SSH config ▶

Summary

Imports now skip SSH config aliases that share a saved target's resolved route.

  • SSH imports skip aliases that resolve to a saved target’s route.
  • The SSH config picker shows route matches as already in Orca.

Acknowledged trade-off: nwparker explicitly noted that a target added or removed during resolution is reflected by the next import.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Import or snapshot refresh] --> B[Shared queue]
  B --> C{Snapshot still current?}
  C -->|Yes| G[Use saved route decisions]
  C -->|No| D[Resolve new aliases and saved targets]
  D --> E{Both SSH paths agree?}
  E -->|Yes| F[Compare route keys]
  E -->|No| H[Do not match uncertain route]
  F --> G
  H --> G
  G --> I[Import skips matching aliases]
  G --> J[Picker reads duplicate flags]
Loading

Reviews (1) · Last reviewed commit: "fix(ssh): rebuild the route snapshot aft..." · Reviewed by Greptile

const snapshot = this.latestRouteSnapshot
return snapshot &&
Date.now() - snapshot.builtAt < ROUTE_SNAPSHOT_TTL_MS &&
snapshot.fingerprint === this.routeSnapshotFingerprint(loadUserSshConfigWithText().text)

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 Searching rereads SSH config

Once a snapshot exists, currentSshRouteSnapshot() reloads the SSH config on every picker search. Each debounced search expands Include files, parses every host, and hashes the result synchronously in the main process. This bypasses the picker's existing parse cache and repeats disk work for large generated configs.

Check for changes on picker refresh or through a cached file-change check instead.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@nwparker
nwparker merged commit be29a19 into main Oct 29, 2026
68 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.

[Bug]: Same machine can be added twice as an SSH host (manual IP + ssh-config alias); duplicate entries share one remote server so they act as one host

2 participants