Repository navigation
fix(pairing): adding a server you already saved updates it instead of saving it twice - #31080
Conversation
…d of saving it twice
…add paths refuse the duplicate
…bs; raw add refuses; match any endpoint key
…t publishes verified status only for the pairing still saved
…eadable store skips the stamp instead of failing a saved pairing
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🔵 Low · up to
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
4ffba11b-f54f-4a2d-b7a2-7fa5f87c9c11
📒 Files selected for processing: 32
src/cli/runtime/environments.test.tssrc/main/ipc/runtime-environments/runtime-environment-connectivity-handlers.tssrc/main/ipc/runtime-environments/runtime-environment-pairing-verification.tssrc/main/ipc/runtime-environments/runtime-environment-preference.test.tssrc/main/ipc/runtime-environments/runtime-environment-repair-handler.tssrc/main/ipc/runtime-environments/runtime-environment-session-tabs-delta.integration.test.tssrc/main/ipc/runtime-environments/runtime-environment-verified-pairing-publish.tssrc/main/ipc/runtime-environments/runtime-environments-pairing.test.tssrc/main/ipc/runtime-environments/runtime-environments-repair.test.tssrc/renderer/src/components/settings/RuntimeEnvironmentsPane.tsxsrc/renderer/src/components/settings/use-runtime-environment-mutation-actions.test.tsxsrc/renderer/src/components/settings/use-runtime-environment-mutation-actions.tssrc/renderer/src/components/sidebar/AddRemoteHostDialog.tsxsrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/i18n/locales/es.jsonsrc/renderer/src/i18n/locales/fr.jsonsrc/renderer/src/i18n/locales/ja.jsonsrc/renderer/src/i18n/locales/ko.jsonsrc/renderer/src/i18n/locales/zh.jsonsrc/renderer/src/store/slices/runtime-environment-peer-replacement.test.tssrc/renderer/src/store/slices/runtime-environment-peer-replacement.tssrc/renderer/src/store/slices/runtime-managed-repair-keeps-workspaces.test.tssrc/shared/remote-pairing-verification.tssrc/shared/runtime-environment-pairing-replace-guards.tssrc/shared/runtime-environment-sidecar.test.tssrc/shared/runtime-environment-ssh-access-store.test.tssrc/shared/runtime-environment-store-same-server.test.tssrc/shared/runtime-environment-store-unreadable-records.test.tssrc/shared/runtime-environment-store.test.tssrc/shared/runtime-environment-store.tssrc/shared/runtime-environments.tssrc/shared/wsl-host-deployment-store.test.ts
💤 Files with no reviewable changes: 1
- src/renderer/src/components/settings/RuntimeEnvironmentsPane.tsx
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.
…erprint stays put
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
bf891e04-dcc9-465e-b15a-1c517ef4dd5c
📒 Files selected for processing: 3
src/shared/runtime-environment-host-key-match.tssrc/shared/runtime-environment-store-same-server.test.tssrc/shared/runtime-environment-store.ts
🚧 Files skipped from review as they are similar to previous changes: 2
- src/shared/runtime-environment-store-same-server.test.ts
- src/shared/runtime-environment-store.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
|
|
||
| /** Why: pairing links accept unpadded and URL-safe Base64, which decode to the same key. */ | ||
| function canonicalHostKeyB64(publicKeyB64: string): string { | ||
| return publicKeyB64.trim().replace(/-/g, '+').replace(/_/g, '/').replace(/=+$/, '') |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
# Inspect whether pairing-code parsing rejects noncanonical host-key Base64.
ast-grep outline src/shared/pairing.ts --match 'parseRemotePairingCode|PairingOffer' --view expanded
ast-grep outline src/shared/runtime-environments.ts --match 'KnownRuntimeEnvironmentSchema' --view expanded
rg -n -C 5 'publicKeyB64|parseRemotePairingCode|base64url|base64' src/shared/pairing.ts src/shared/runtime-environments.tsRepository: stablyai/orca
Length of output: 8027
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- pairing.ts ---'
nl -ba src/shared/pairing.ts | sed -n '1,115p'
printf '%s\n' '--- runtime-environment-host-key-match.ts ---'
nl -ba src/shared/runtime-environment-host-key-match.ts | sed -n '1,180p'
printf '%s\n' '--- direct consumers ---'
rg -n -F --glob '*.ts' -e 'findEnvironmentWithHostKey' -e 'savedHostKeySpelling' -e 'parsePairingCode' srcRepository: stablyai/orca
Length of output: 22112
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- PairingOfferSchema ---'
rg -n -C 12 -F -- 'PairingOfferSchema' src/shared/mobile-relay-pairing-offer.ts
printf '%s\n' '--- runtime-environment-store pairing branch ---'
nl -ba src/shared/runtime-environment-store.ts | sed -n '65,125p'Repository: stablyai/orca
Length of output: 4599
🏁 Script executed:
nl -ba src/shared/mobile-relay-pairing-offer.ts | sed -n '1,112p'Repository: stablyai/orca
Length of output: 4992
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- parseRemotePairingCode binding ---'
rg -n -C 8 -F -- 'parseRemotePairingCode' src/shared src/main src/cli
printf '%s\n' '--- runtime-environment-store imports ---'
nl -ba src/shared/runtime-environment-store.ts | sed -n '1,35p'Repository: stablyai/orca
Length of output: 5946
🏁 Script executed:
nl -ba src/shared/runtime-environment-store.ts | sed -n '137,164p'Repository: stablyai/orca
Length of output: 1754
Match decoded host keys for non-relay pairing offers.
parseRemotePairingCode accepts noncanonical publicKeyB64 values for non-relay offers. The current matcher only normalizes the string, so equivalent decoded keys with different unused Base64 padding bits can compare differently. The update path can then create a duplicate saved server instead of refreshing the existing entry. Compare validated decoded keys while preserving savedHostKeySpelling for storage.
…39198) Since #31080 a client keeps one saved entry per server, so pairing the same host a second time under another name is refused. The steady 'Direct host' is now a different server than the interrupted one. Tooltip checks name the host so a closing tooltip from the previous card cannot match. Route the spec from its pairing-store and runtime-status sources.
ELI5
If you add a server you already have (for example over a new network address, or with a fresh pairing code), Orca now updates the saved server instead of saving it a second time.
What Changed
Before: Orca only refused a second server with the same name. Pairing the same machine again under a new name (LAN plus a different address, or a re-pair) saved two servers. Both then listed the same workspaces, so every edit, delete or terminal write to those workspaces failed with "Workspace identity is ambiguous across hosts. Refresh projects and try again." Refreshing never fixed it.
After:
orca environment add, cloud workspaces and the unverified add channel refuse instead, naming the saved server: "This server is already paired as "". To update its connection, add it again under Settings > Remote Orca Servers."Mechanism:
saveEnvironmentFromPairingCode) looks the code's host public key up in every saved server's endpoints, including servers hidden because this build can't read their extra settings. Unpadded and URL-safe Base64 spellings of a key count as the same key, and a refresh keeps the saved spelling, so the host-key fingerprint doesn't change. A match is the same machine: the key is the server's persisted identity, which the pairing handshake proves.replaceEnvironmentPairing, shared withupdateEnvironmentFromPairingCode), so the pairing revision advances exactly as a repair does.invalidateTransport). A newpublishVerifiedPairinghelper, now shared by add and repair, publishes the verified status only if the saved pairing revision is still the one that was verified. This closes a window where an overlapping save could be stamped with stale status.Why
updatedExistingis an optional field on the desktop's own main-to-renderer IPC, which always ships in the same build. The paired host never sees it.ref-oss check (after 3 review rounds): a comparable remote-host registry keys saved hosts by server identity and updates the existing entry in place, keeping its label. It merges addresses only because it fails over between them, which Orca does not. The approach stayed the same.
Linked Issue
N/A (internal follow-up from the SSH reliability review)
Visual Proof
The only visible change is the success toast text after re-adding a saved server. There is no layout change. The behavior is covered by renderer tests (toast text, no removal on failed connect, same-name entry reaches main).
Testing
New tests (each fails on origin/main):
src/shared/runtime-environment-store-same-server.test.ts: refresh in place; refuse where it can't switch connections; same-name refresh; tunnel dependency follows the new code; managed and cloud refusals.src/shared/runtime-environment-store-unreadable-records.test.ts: a hidden server still refuses a second entry.src/main/ipc/runtime-environments/runtime-environments-pairing.test.ts: the verified add refreshes and retires the old connection; an overtaken refresh is not stamped with stale status.src/renderer/src/components/settings/use-runtime-environment-mutation-actions.test.tsx: no removal of a refreshed server, the toast, and the saved server's own name reaching main.src/renderer/src/store/slices/runtime-managed-repair-keeps-workspaces.test.ts: a same-key refresh keeps workspaces and tabs; a different key drops them.src/cli/runtime/environments.test.ts: the CLI refuses the duplicate.Fixtures that paired "different" servers with one shared test key now use distinct keys.
Locally:
pnpm tc.src/shared/runtime-environment*,src/shared/wsl-host*,src/main/ipc/runtime-environments,src/cli/runtime,src/renderer/src/components/settings,src/renderer/src/runtime,src/renderer/src/store/slices.Verified live: none. Covered by unit and integration tests only. The pairing integration test runs a real runtime server over WebSocket.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Notes
Follow-up: the existing repair flow (
verifyAndRepairRuntimeEnvironmentFromPairingCode) still compares keys as raw strings, so a repair link with a differently spelled key reads as a different server. That predates this PR.Managed-server and WSL-host registration (
addManagedOrcadEnvironment, the WSL host store) can still save an entry whose key matches a hand-paired one. That is out of scope here.Records this build cannot parse at all are still invisible to the check. This predates the change.