Repository navigation
feat(ssh): plain SSH terminals and SFTP browsing when no Orca runtime can run - #24147
Conversation
|
| return await Promise.race([ | ||
| this.realpath('.').then( | ||
| () => true, | ||
| () => false | ||
| ), | ||
| timeout |
There was a problem hiding this comment.
SFTP failure closes working shells. If a host allows SSH shells but has no SFTP subsystem, plain mode can connect, yet every resume probe fails because it checks only SFTP. After two failures, the resume handler reconnects the SSH transport and ends working shells. An unavailable SFTP subsystem should not be treated as proof that the SSH connection has died.
| async readFile(filePath: string, _limits?: FileReadLimits): Promise<FileReadResult> { | ||
| const path = toSftpPath(filePath) | ||
| return this.run(async (sftp) => { | ||
| const stats = await statViaSftp(sftp, path) | ||
| const mimeType = PREVIEW_MIME_TYPES[extname(filePath).toLowerCase()] | ||
| const sizeLimit = mimeType ? MAX_PREVIEWABLE_BINARY_SIZE : MAX_TEXT_FILE_SIZE | ||
| if (stats.size > sizeLimit) { | ||
| throw new Error( | ||
| `File too large: ${(stats.size / 1024 / 1024).toFixed(1)}MB exceeds ${sizeLimit / 1024 / 1024}MB limit` | ||
| ) | ||
| } | ||
| const buffer = await new Promise<Buffer>((resolve, reject) => | ||
| sftp.readFile(path, (err, data) => (err ? reject(err) : resolve(data))) |
There was a problem hiding this comment.
| shell.channel.on('exit', (code: number | null) => { | ||
| shell.exitCode = typeof code === 'number' ? code : SIGNALLED_EXIT_CODE | ||
| }) |
There was a problem hiding this comment.
There was a problem hiding this comment.
Important
Two filesystem methods diverge from the relay provider they stand in for: createDir is neither recursive nor idempotent, and non-append base64 writes truncate instead of creating exclusively. Both break real plain-mode flows.
Reviewed changes
- Plain SSH PTY provider — one ssh2
shellchannel per terminal with pty-req, UTF-8-decoded output, resize, POSIXcd, and an exited-vs-unverifiable verdict; reattach starts a fresh shell. - SFTP filesystem provider — read/list/stat/write/rename/delete/download over one reused channel; relay-only features refuse with the classified reason.
- Plain-mode session wiring —
SshPlainSshModeSessionregisters the providers and feeds output/exit through the existing intake;SshRelaySessionfalls back at rung D and clears the mode on teardown. - Connect / sleep handling — a live plain session is treated as a refresh, and host resume probes the SFTP transport before reconnecting.
- Surface —
plainSshonSshConnectionState, field-by-field admission, and the target card label + reason.
ℹ️ Nitpicks
SshSftpFilesystemProvider.readFileignores itslimitsargument and uses hardcoded 10/50 MB caps, throwing a genericErrorrather thanFileReadCapExceededError(src/main/providers/ssh-sftp-filesystem-provider.ts:180). The callers I traced re-check size, so impact is contained, but it is not contract-faithful to the relay reader.SshPlainSshModeSession.leave()clears the module-global plain mode unconditionally, while the provider unregistrations directly below it are identity-guarded (src/main/ssh/ssh-plain-ssh-session.ts:112). I could not construct an interleaving that reaches it today, but clearing only whengetSshPlainSshMode(targetId) === this.modewould remove the asymmetry.SshPlainShellPtyProvider.spawnre-checksthis.disposedbut notopts.signal?.abortedafteropenShellresolves (src/main/providers/ssh-plain-shell-pty-provider.ts:86-90), so a spawn cancelled while the channel opens still registers a live shell.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| async createDir(dirPath: string): Promise<void> { | ||
| await this.call((sftp, cb) => sftp.mkdir(toSftpPath(dirPath), cb)) | ||
| } |
There was a problem hiding this comment.
createDir is neither recursive nor idempotent, unlike the relay path it replaces: createRelayDir runs mkdir(dirPath, { recursive: true }), and callers invoke createDir unconditionally on directories that commonly already exist. On a plain-SSH target where .orca is present, sftp.mkdir returns SFTP Failure and the flow fails with a raw error.
Technical details
# `createDir` must match `mkdir -p` semantics
## Affected sites
- `src/main/providers/ssh-sftp-filesystem-provider.ts:295-297` — single non-recursive `sftp.mkdir`, fails when the path or a parent is missing/exists
- `src/main/runtime/runtime-repository-issue-command.ts:90` — `createDir(joinWorktreeRelativePath(repo.path, '.orca'))`, unconditional
- `src/main/ipc/hooks/register-worktree-hook-file-handlers.ts:115` — same unconditional `.orca` create
- `src/main/ipc/filesystem-import-ssh.ts:262,270`, `src/main/ipc/repos/remote-repo-clone.ts:85`, `src/main/ipc/worktree-remote.ts:1498` — same pattern
- `src/relay/fs-path-mutation-requests.ts:49-52` — relay equivalent is idempotent and recursive
## Required outcome
- `createDir` succeeds when the directory (and parents) already exist.
- `createDirNoClobber` (`:299-301`) keeps fail-on-exists semantics, so it must no longer delegate to the idempotent `createDir`.
## Suggested approach
- SFTP has no recursive MKDIR: walk the path components and `mkdir` each, swallowing `SSH_FX_FAILURE`/already-exists for the created ancestors (or the final component for `createDir`). Keep `createDirNoClobber` on a plain single `sftp.mkdir`.
## Open questions for the human
- `filesystem-mutations.ts:77` (user "New Folder") currently inherits relay's silent success on an existing dir; confirm the intended error behavior once `createDir` is idempotent.| async writeFileBase64Chunk( | ||
| filePath: string, | ||
| contentBase64: string, | ||
| append: boolean | ||
| ): Promise<void> { | ||
| const data = Buffer.from(contentBase64, 'base64') | ||
| const path = toSftpPath(filePath) | ||
| await this.call((sftp, cb) => | ||
| append ? sftp.appendFile(path, data, cb) : sftp.writeFile(path, data, cb) | ||
| ) |
There was a problem hiding this comment.
Non-append chunks are written with sftp.writeFile, which truncates/creates, but both peer implementations create exclusively when !append: the relay path passes exclusive: !append to uploadBuffer (flags 'wx'), and the local runtime uses flag: 'wx'. Plain mode therefore silently overwrites an existing remote file where relay/local refuse, and writeFileBase64 (:224-227) inherits this.
Technical details
# Non-append base64 writes must create exclusively
## Affected sites
- `src/main/providers/ssh-sftp-filesystem-provider.ts:224-227` — `writeFileBase64` calls `sftp.writeFile`
- `src/main/providers/ssh-sftp-filesystem-provider.ts:229-238` — non-append branch uses `sftp.writeFile`
- `src/main/providers/ssh-filesystem-provider.ts:196-216` — relay uses `uploadBuffer(..., { append, exclusive: !append })`
- `src/main/ssh/sftp-upload.ts:127-128` — `exclusive ? 'wx' : 'w'`
- `src/main/runtime/runtime-file-commands-write-file-explorer-file.ts:104` — local uses `flag: append ? 'a' : 'wx'`
## Required outcome
- A non-append write must fail (as `EEXIST`) rather than clobber an existing path, matching relay and local behavior.
## Suggested approach
- For `append === false`, `sftp.open(path, 'wx', ...)` then write/close (or a create-write-stream with `flags: 'wx'`); for `append === true` keep `appendFile`.| shell.channel.on('exit', (code: number | null) => { | ||
| shell.exitCode = typeof code === 'number' ? code : SIGNALLED_EXIT_CODE | ||
| }) |
There was a problem hiding this comment.
The exit handler reads only code and reports 129 for every signalled shell, but ssh2 emits 'exit' as (null, 'SIG<name>', coreDumped, message) on exit-signal (node_modules/ssh2/lib/client.js:673-678). A SIGINT-killed shell should surface as 130, SIGTERM as 143, etc., so this misreports the termination and contradicts the 128+n comment on line 33-34.
Technical details
# Map signalled exits to their real code
## Affected sites
- `src/main/providers/ssh-plain-shell-pty-provider.ts:34` — single `SIGNALLED_EXIT_CODE = 129`
- `src/main/providers/ssh-plain-shell-pty-provider.ts:125-127` — handler discards the signal argument
- `node_modules/ssh2/lib/client.js:673-678` — exit-signal emits `(null, 'SIG<name>', ...)`
## Required outcome
- Report `128 + signo` for the common signals (`SIGHUP` 129, `SIGINT` 130, `SIGQUIT` 131, `SIGABRT` 134, `SIGKILL` 137, `SIGTERM` 143), or a single explicit "signalled" sentinel if the code cannot be derived — never a fabricated 129.
## Suggested approach
- Change the signature to `(code: number | null, signal: string | null)` and map `signal` through a small `SIGNAL_EXIT_CODES` record; fall back to a sentinel for unknown signals.…the host Runtime ladder rung D (design D6): instead of failing the connect, register an ssh2 shell-channel PTY provider and an SFTP-only filesystem provider and publish the classified reason on the SSH connection state.
…and tilde cwd - Only the current connect or reconnect attempt may enter plain SSH mode; a superseded reconnect whose ladder ends at rung D no longer registers a second provider set. - Host-sleep resume probes a plain session over SFTP instead of always reconnecting, which ended every open plain shell. - A home-relative cwd keeps its tilde outside the quotes so the shell expands it. - The SFTP provider implements folder download, which the connect state advertises.
69a9da6 to
638902a
Compare
Comments Outside DiffThese findings could not be posted inline.
|
There was a problem hiding this comment.
ℹ️ No new issues in this commit set — the plain-SSH hardening is clean and well covered. This is not an approval: the three earlier review threads on
createDir, non-append base64 writes and the signalled-exit code are unchanged here and remain open.
Reviewed changes
This run re-reviewed the delta since the prior pullfrog review. The branch was rebased, so the previously reviewed feature commit now appears as 746a563120 (same content) and the new work is the hardening commit 638902aa.
- Only the current attempt enters plain SSH —
deployRelayOrEnterPlainSshnow takes anisAttemptCurrentpredicate;establishpasses_state === 'deploying'andreconnectpasses itsAbortControlleridentity, so a superseded reconnect that ends at rung D rethrows instead of registering a second provider set. - Host-sleep resume probes the plain transport —
isRelayLinkAliveAfterResumeasksSshPlainSshModeSession.probeTransport(one SFTPrealpath('.')round trip per attempt, two attempts) instead of treating the absent mux as dead, so waking from sleep no longer tears down every open plain shell. - Home-relative
cdexpands —posixCdTargetleaves the leading~outside the quotes (~→~,~/x→~/'x') so the shell expands it, while absolute paths stay fully quoted. - Folder download in plain mode —
SshSftpFilesystemProvider.downloadFolderdelegates todownloadFolderViaSftpwith the host'swindowsRemotePaths, matching the relay provider it stands in for.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
When no Orca runtime can run on a host (for example, the home directory is mounted noexec), Orca now still connects. You get plain SSH terminals and SFTP file browsing, with the reason shown, instead of a failed connection.
What Changed
ssh-plain-shell-pty-provider.ts: each terminal is an ssh2 session channel with pty-req and shell. Resize usessetWindow, output is decoded as UTF-8, andcwdis applied withcd.exitedonly after the host sends an exit status. Transport loss makes itunverifiable.ssh-sftp-filesystem-provider.ts(SFTP only): list, stat, read, write, rename, delete and download.~/paths now expand incd.Why
Design D6: "degraded, not dead". A hardened host should still give you a shell.
Linked Issue
Part of the Node runtime plan (Phase 2). Stacked on
OrcaWin/node-rt-p2-integration.Visual Proof
To add: a screenshot of the target card showing the plain-mode reason, and of a plain terminal. The existing e2e harness can capture these.
Testing
Unit tests cover the shell provider (exit, unverifiable, resize, UTF-8 split across chunks, cwd), the SFTP provider, and the session mode switch.
Not done:
cwd.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.