Skip to content

Ready a Spinbox workspace before Remote-SSH connects to it - #27

Merged
aledbf merged 2 commits into
mainfrom
ssh-remote-hook
Nov 12, 2026
Merged

aledbf merged 2 commits into
mainfrom
ssh-remote-hook

Conversation

@aledbf

@aledbf aledbf commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Part of #24. This makes Remote-SSH the default path in Spinbox's hands, following Coder's pattern (coder/vscode-coder ARCHITECTURE.md). It is based on main and does not depend on #26.

  1. Hook. onResolveRemoteAuthority:ssh-remote is in activationEvents, and activate awaits connectWindow (src/remote/index.ts, src/remote/connect.ts). VS Code waits for that activation before Remote-SSH resolves. For a window whose folder is ssh-remote+spin.<ws>, it runs spin code <ws> --no-open --start --vscode-commit … under a cancellable progress notification. That starts the workspace, attaches this VS Code's server, writes the ssh config, and connects once through it, which runs spin ssh-prepare and its launch-claim check. So no separate ssh-prepare call is needed. Run from the extension host, it would also key its session to the wrong pid and go unused.
  2. Errors. A failure goes through the existing showCliError, with its action: add key, sign in, start, sign, retry. Unless its retry succeeds, or when the person cancels, the window runs workbench.action.remote.close (what Coder does), so Remote-SSH never shows its own error.
  3. Proxy status (src/remote/proxy.ts), as spin-stack/spin#1180 writes it: ~/.spin/ssh/status/<ssh pid>.json, version 1 (any other is refused).
    • Which file: of the files there, the one last updated for the window's spin.<ws> host whose started_at is after spin code returned. spin code's own ssh, and the shared connection it leaves, began before that.
    • Not by pid: the file isn't found through Remote-SSH's socksPort log line. Two windows connecting to the same workspace at the same moment could read each other's file.
    • On the way: resolving and connecting are said once each in the status bar.
    • At the end: refused and failed are shown, and the remote is closed. If the contract knows the code, the error is shown through showCliError with its action; otherwise its message is shown with an Open button for its url.
    • Until spin#1180 ships the reader finds no file and stays silent.
  4. Include and server path: already done in spin, nothing added here.
    • spin code/spin ssh-config write ~/.spin/ssh/config and keep an Include of it at the top of ~/.ssh/config (cmd/cli/cmd/sshconfig.go ensureInclude).
    • The control plane links the carried server into Remote-SSH's default install path, /root/.vscode-server/cli/servers/Stable-<commit>/server (internal/controlplane/vscodeserver/tree.go links). So Remote-SSH downloads nothing, and remote.SSH.serverInstallPath would only repeat the default.

The authority comes from the window's folder URI, the same way the status bar reads it. env.remoteAuthority belongs to the resolvers proposal, which Coder reaches by loading vscode as Remote-SSH's module. That is not copied here.

Tests

test/unit/connect.test.ts runs against the fake spin: the hook's command, the authorities it leaves alone, a refusal shown and then the remote closed, a retry that succeeds, and cancel. test/unit/proxy.test.ts runs on fixtures in exactly spin#1180's shape: version, phase, host and time checks, a shared connection, the file picked (other host, older connection, other version), envelope or message plus URL, each phase said once, refused/failed/connected answered, and a quiet timeout. The manifest test checks the activation event. Nine planted bugs each turned a test red and were reverted with Edit:

  • the remote not closed on failure;
  • the ssh-remote check dropped;
  • the activation event removed;
  • the since filter dropped;
  • the version check dropped;
  • the host check dropped;
  • a known code not shown with its action;
  • refused not treated as the end;
  • the watcher not stopping on a failure.

Found: the extension's error codes are behind its pinned spin

spin v20261110.01, the release versions.yaml pins, writes key_not_enrolled (action add_key) and no_extension_release. It no longer writes access_needs_signature, keyring_needs_signature or no_key_held (spin 22c480b66). src/cli/contract.ts, the errors module and the fake spin still have the old codes.

So today key_not_enrolled is not in the contract: spin code's refusal shows as internal, and here a proxy refusal shows its message and the keys page rather than an Add Key action. Fixing that is its own PR, against the contract.

Not tested in a real VS Code: that activation really blocks Remote-SSH's resolve on 1.146. It needs a real Remote-SSH and a stack.

🤖 Generated with Claude Code

aledbf and others added 2 commits November 12, 2026 18:54
Spinbox activates on onResolveRemoteAuthority:ssh-remote, which VS Code waits
for before Remote-SSH resolves, as Coder's extension does. For a window whose
folder is ssh-remote+spin.<workspace> - a reload, a reconnect, a recent
folder - it runs `spin code --start` under a progress notification: the
workspace started, this VS Code's server attached, the ssh config written,
and one connection made through it, which runs ssh-prepare and its
launch-claim check. A failure is the CLI's error with its action (add a key,
sign in, start); unless its retry succeeds, the window leaves the remote
(workbench.action.remote.close), so Remote-SSH does not fail its own way.

Then it reads spin ssh-proxy's status file of the connection while Remote-SSH
connects: each step in the status bar, and a failure shown with its action,
closing the remote. The file is being built in spin; its layout here is
provisional, behind ProxyStatusSource, and tested with fixtures.

The authority is read from the window's folder: env.remoteAuthority is the
resolvers proposal's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
~/.spin/ssh/status/<ssh pid>.json, version 1 (any other refused): phase
resolving, connecting, connected, refused or failed, the host, and on a
refusal the CLI's error envelope. Of the files there, the one last updated for
the window's spin.<ws> whose connection began after spin code returned is
this window's: spin code's own ssh, and the shared connection it leaves,
began before. Resolving and connecting are said in the status bar once each;
refused and failed are shown and close the remote - with the CLI's action when
the contract knows the code, and otherwise its message and the page it names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aledbf
aledbf merged commit 4d5aee5 into main Nov 12, 2026
3 checks passed
@aledbf
aledbf deleted the ssh-remote-hook branch November 12, 2026 22:06
aledbf added a commit that referenced this pull request Nov 12, 2026
#27 and #29 merged from the same base, so main ran #27's tests against #29's
contract: connect.test failed with no_key_held, which the fake spin no longer
writes, and proxy.test still held key_not_enrolled to be a code the contract
does not know. The refusal is key_not_enrolled now, shown with its Add Key;
the unknown code is one no release writes yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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