Skip to content

Sessions: detect shell, command execution and SFTP per server; SFTP over exec as fallback; no reconnect loop when the shell ends at once #1666

Backlog

Description

@smart-ssh-planner

Goal

Each session knows which capabilities the server offers – interactive shell, command execution, SFTP – and keeps working with what is there. A shell that ends right after it opens no longer counts as a lost connection.

Context

  • build_session (crates/app-logic/src/connect/session_builder.rs:166) runs uname -a (:191) and id -u (:203) with no time limit; on an SFTP-only server the connect hangs.
  • SFTP opens lazily via ensure_sftp_open (crates/app-logic/src/orchestration/remote_files.rs:61-72); a missing subsystem fails fast (Open the SFTP browser fails fast when the server has no SFTP subsystem #1225) with no fallback. open_sftp_via_exec exists for the elevated browser (crates/app-shell/src/elevated_sftp.rs:791).
  • A shell that ends right away: the terminal actor treats EOF as a lost connection (crates/app-logic/src/session/terminal_actor.rs:72,122) → report_connection_lost (crates/app-logic/src/session/mod.rs:1123-1160) → auto-reconnect (crates/app-shell/src/auto_reconnect.rs:42-66) → the frontend opens a new shell (TerminalView.tsx:190-200) → endless loop.
  • Only per-session probe result today: is_root (session/mod.rs:597,762,778). SessionSummaryDto: crates/app-logic/src/dto/chat.rs:101-115.
  • Requires the transport errors SSH_SHELL_UNAVAILABLE / SSH_EXEC_UNAVAILABLE from the blocking issue.

Requirements

  • SessionCapabilities { shell: Available | Unavailable | Unknown, exec: bool, sftp: bool, sftp_via_exec: bool } on the session, set in build_session; exposed as SessionCapabilitiesDto in SessionSummaryDto, and a command session_capabilities(sessionId); event session-capabilities-changed { sessionId, capabilities } on every change.
  • Exec: the probes run with a time limit of 10 s each. exec = false when the exec request is refused, the probe times out, or uname -a exits with empty stdout. A probe that runs but exits non-zero (restricted shells) keeps exec = true.
  • SFTP is opened during connect (not lazily). If the subsystem is refused or closed and exec = true, open SFTP over exec without elevation (sftp-server at the paths the elevated probe already knows); success → sftp = true, sftp_via_exec = true. Otherwise sftp = false. Opening SFTP never fails the connect on its own.
  • Shell: exec = false → shell = Unavailable without trying. Otherwise Unknown until the terminal opens; SSH_SHELL_UNAVAILABLE, a refused PTY, or a shell that ends within 5 s of opening without user input → Unavailable. That case is not a lost connection: no Disconnected, no auto-reconnect, the session stays usable for SFTP. A normal open → Available.
  • shell = Unavailable (known before the terminal opens): open_terminal returns SSH_SHELL_UNAVAILABLE without opening a channel.
  • No shell, no exec and no SFTP → the connect fails with SERVER_NO_USABLE_CHANNEL and a clear message.
  • exec = false → sftp_elevation_allowed returns false.
  • Reconnect (ADR 0132) keeps the capabilities of the first connect; a reconnected session re-opens SFTP the same way (subsystem, then exec fallback).

Acceptance Criteria

  • Mock transport, exec refused: connect finishes, exec=false, shell=Unavailable, sftp=true.
  • Mock transport, exec hangs: connect finishes within 25 s with exec=false.
  • Mock transport, subsystem refused + exec works: sftp=true, sftp_via_exec=true; file browser list works over it.
  • Mock transport, subsystem refused + exec refused: sftp=false; connect still succeeds when a shell is possible.
  • Mock transport, nothing usable: connect fails with SERVER_NO_USABLE_CHANNEL.
  • Shell ends within 5 s without input: session stays Connected, auto-reconnect is not started, shell=Unavailable, event emitted (test).
  • Shell ends later (normal exit, real connection loss): behaviour unchanged (existing tests stay green).
  • Normal OpenSSH server: shell=Available after the terminal opens, exec=true, sftp=true, sftp_via_exec=false; connect time unchanged apart from the SFTP open.
  • sftp_elevation_allowed is false when exec=false.
  • generated/ipc.ts regenerated; frontend type for the capabilities exists.
  • Relevant automated tests pass

Technical Notes

  • Security: the probes stay in the exec allowlist (crates/app-logic/src/orchestration/tests_exec_guard.rs); the exec-based SFTP fallback is a session-construction probe like the elevated one but without sudo and without elevation; it never runs through AI code (invariant Guarantee and document that no network call happens without user action #14). Probe stderr never reaches the AI context (Adversarial regression suite for command chaining protection #13).
  • AGENTS.md: special cases belong at the session-construction boundary, not in the filter engine.
  • Shell detection lives in the terminal actor / report_connection_lost path; distinguish "ended within 5 s with no input sent" from a connection loss by also checking that the SSH connection itself is still alive.

Files: crates/app-logic/src/connect/session_builder.rs, crates/app-logic/src/session/ (mod.rs, terminal_actor.rs, new capabilities module), crates/app-logic/src/orchestration/remote_files.rs, crates/app-logic/src/start_directory.rs, crates/app-logic/src/dto/chat.rs, crates/app-shell/src/commands/ (terminal.rs, connect/, new command), crates/app-shell/src/elevated_sftp.rs, crates/app-shell/src/auto_reconnect.rs, crates/app-shell/src/lib.rs, apps/smart-ssh-community/frontend/src/generated/ipc.ts, docs/specs/0057-rich-session-model.md, docs/specs/0020-sftp-file-transfer.md, docs/specs/0107-sitzung-neu-verbinden.md, docs/codemap.md, changelog.d/

Spec impact: update 0057

Open questions

  • Where to put the exec-based SFTP fallback helper: reuse open_sftp_via_exec from elevated_sftp.rs by moving the non-sudo part to app-logic (recommended) or call it from app-shell.

Related Work

Metadata

Metadata

Assignees

No one assigned

    Labels

    app-shellenhancementssh

    Fields

    Priority

    P2 - Normal

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions