Skip to content

fix(ssh): sync ~/.ssh/config on import and Manage open - #4899

Merged
Jinwoo-H merged 2 commits into
stablyai:mainfrom
LesleyMurfin:fix/ssh-config-import-port-sync
Jun 8, 2026
Merged

Jinwoo-H merged 2 commits into
stablyai:mainfrom
LesleyMurfin:fix/ssh-config-import-port-sync

Conversation

@LesleyMurfin

Copy link
Copy Markdown
Contributor

Summary

Fixes item #1 of #4684 (remote server / SSH config sync). Item #2 (directory refresh) was fixed separately in #4860.

Importing from ~/.ssh/config previously only inserted hosts that didn't already exist — importFromSshConfig built a set of existing aliases purely to skip them and never updated an existing target. So when a host kept its name but its port changed (the temp-cluster workflow in #4684, where ports rotate each session), clicking Import silently left the stale port in place. The page also never auto-synced.

This change:

  • Makes importFromSshConfig an upsert — an existing config-sourced target has its config-derived fields (host, port, username, identityFile, identityAgent, identitiesOnly, proxyCommand, jumpHost) refreshed in place; genuinely new hosts are inserted; unchanged targets are skipped (no write).
  • Adds an optional SshTarget.source ('ssh-config' | 'manual'). Manual targets are never overwritten by sync, and editing a target in the UI detaches it (re-stamps it manual) so a later sync can't silently revert a user's edit. Legacy persisted targets (no source) are adopted into config-sync the first time they match a config host.
  • Auto-syncs when the SSH Manage pane opens, so rotated ports and new hosts appear without a manual Import click (best-effort; a sync failure still lists known targets).

Screenshots

Visual change: the Import toast now reads Synced N server(s) / ~/.ssh/config already in sync (was Imported N host(s)), and the pane refreshes from config on open.

Testing

  • pnpm lint — clean (no new warnings in changed files)
  • pnpm typecheck — clean (all three TS projects)
  • pnpm test — added/updated tests pass; one pre-existing, unrelated failure (loads legacy pane aliases from very large persisted split layouts, a 130k-leaf perf stress test) times out locally and is untouched by this change
  • pnpm build (build:desktop) — clean
  • Added high-quality tests that catch the regression (see below)

New/updated tests:

  • ssh-connection-store.test.ts: updates an existing config-sourced target when the port changed (primary regression); refreshes host/username/jumpHost; never overwrites a manual target; adopts a legacy unsourced target; no-op when unchanged; addTarget stamps manual by default.
  • persistence.test.ts: source survives add / update / getSshTarget and a disk round-trip (guards against normalizeSshTarget ever stripping it); plus a real-Store integration test driving the full upsert through the real normalizeSshTarget + a disk flush/reload — insert → rotated-port update-in-place → third-sync no-op → exactly one target on disk → survives reload.

Full SSH-subsystem baseline (canonical config/vitest.config.ts): 582/583 passing across 43 SSH test files; 0 regressions. The one failure (ssh-config-loader › expands glob includes in lexical order) is pre-existing and environmental — it reproduces unchanged on origin/main and this change does not touch the config loader/parser.

AI Review Report

Reviewed with two independent AI passes (adversarial code reviewer + NotebookLM):

  • Cross-platform (macOS/Linux/Windows): Clean. All logic is in the main process plus one renderer effect; config path uses join(homedir(), '.ssh', 'config'); no OS branching, shortcuts, or platform-specific paths touched.
  • SSH/remote/local: Correctly scoped to the operator's local ~/.ssh/config; makes no assumption that connection targets are local. No change to relay/ssh -G resolution.
  • Performance: Auto-sync reads ~/.ssh/config once per pane open; the no-op guard skips all disk writes when nothing changed, so repeated opens are no-ops.
  • UI quality: Toast copy updated for accuracy (now "synced", since import can update as well as insert).
  • Found and fixed during review: (1) an initial version let auto-sync-on-mount silently revert a user's manual edit to a config target — fixed by detaching edited targets to source: 'manual'; (2) editing a target to clear an optional field (identity file, proxy command, jump host) silently kept the old value through the partial-merge update — fixed by carrying cleared fields explicitly on the edit path so the removal takes effect. Added a defensive within-pass alias guard so a duplicate candidate can never create a duplicate target.

Security Audit

No new attack surface. The ssh:importConfig IPC handler takes no arguments. Values originate from a file the user already controls (~/.ssh/config); parsing is unchanged and ssh -G resolution (already ---guarded) is untouched. ProxyCommand is stored as data, not executed by this change. No new input handling, path traversal, secret, or command-execution surface introduced.

Notes

  • Known limitation (documented): a manually-created target whose alias exactly matches a Host entry in ~/.ssh/config reserves that alias — the config host won't import under the same name. Legacy targets created before the source field that happen to share an alias with a config host are adopted into config-sync on next import. Both are low-likelihood and the conservative (non-clobbering for explicit manual targets) behavior is intentional.
  • Intentionally out of scope: config-sourced targets whose Host block is later removed from ~/.ssh/config are not auto-deleted — auto-removing targets on every pane open would be a destructive default. Pruning can be added later behind an explicit action.
  • Single-topic change; no packaging/release/version changes.

importFromSshConfig only inserted unknown hosts and never updated an
existing target, so a rotated port (or any changed config field) was
silently ignored on re-import. Make it an upsert: config-sourced targets
are refreshed in place, genuinely new hosts are inserted, and the SSH
Manage pane auto-syncs when it opens so changes appear without a manual
Import click.

A new optional SshTarget.source ('ssh-config' | 'manual') protects
user-created and user-edited targets from being overwritten by sync —
editing a target in the UI detaches it from config-sync. Unchanged
targets are skipped so a repeat sync performs no disk write. Editing a
target now also carries cleared optional fields (identity file, proxy
command, jump host) so removing a config-derived value actually deletes
it instead of silently keeping the stale value through the partial merge.

Resolves item #1 of stablyai#4684 (item #2 was fixed in stablyai#4860).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Jinwoo-H
Jinwoo-H self-requested a review June 8, 2026 21:41

@Jinwoo-H Jinwoo-H 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.

Thanks, this fixes the stale SSH config import path nicely.

I made one follow-up fix before shipping: legacy targets without the new source field are now only adopted into config sync when they match the old config-import shape. That keeps older manual targets from being silently overwritten when the SSH Hosts pane auto-syncs on open.

Validated with targeted tests, typecheck, lint, and an Electron run covering auto-import, rotated-port update-in-place, and manual-edit protection.

@Jinwoo-H
Jinwoo-H merged commit 2338c42 into stablyai:main Jun 8, 2026
@LesleyMurfin
LesleyMurfin deleted the fix/ssh-config-import-port-sync branch June 8, 2026 22:52
@LesleyMurfin
LesleyMurfin restored the fix/ssh-config-import-port-sync branch June 8, 2026 22:53
@Gnonymous

Copy link
Copy Markdown

Thanks!

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* fix(ssh): sync ~/.ssh/config on import and Manage open

importFromSshConfig only inserted unknown hosts and never updated an
existing target, so a rotated port (or any changed config field) was
silently ignored on re-import. Make it an upsert: config-sourced targets
are refreshed in place, genuinely new hosts are inserted, and the SSH
Manage pane auto-syncs when it opens so changes appear without a manual
Import click.

A new optional SshTarget.source ('ssh-config' | 'manual') protects
user-created and user-edited targets from being overwritten by sync —
editing a target in the UI detaches it from config-sync. Unchanged
targets are skipped so a repeat sync performs no disk write. Editing a
target now also carries cleared optional fields (identity file, proxy
command, jump host) so removing a config-derived value actually deletes
it instead of silently keeping the stale value through the partial merge.

Resolves item stablyai#1 of stablyai#4684 (item stablyai#2 was fixed in stablyai#4860).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(ssh): preserve legacy manual targets during config sync

Co-authored-by: Orca <help@stably.ai>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Jinwoo-H <jinwoo0825@gmail.com>
Co-authored-by: Orca <help@stably.ai>
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.

3 participants