Repository navigation
Description
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) runsuname -a(:191) andid -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_execexists 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_UNAVAILABLEfrom the blocking issue.
Requirements
SessionCapabilities { shell: Available | Unavailable | Unknown, exec: bool, sftp: bool, sftp_via_exec: bool }on the session, set inbuild_session; exposed asSessionCapabilitiesDtoinSessionSummaryDto, and a commandsession_capabilities(sessionId); eventsession-capabilities-changed { sessionId, capabilities }on every change.- Exec: the probes run with a time limit of 10 s each.
exec = falsewhen the exec request is refused, the probe times out, oruname -aexits with empty stdout. A probe that runs but exits non-zero (restricted shells) keepsexec = 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-serverat the paths the elevated probe already knows); success →sftp = true, sftp_via_exec = true. Otherwisesftp = false. Opening SFTP never fails the connect on its own. - Shell:
exec = false→shell = Unavailablewithout trying. OtherwiseUnknownuntil 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: noDisconnected, no auto-reconnect, the session stays usable for SFTP. A normal open →Available. shell = Unavailable(known before the terminal opens):open_terminalreturnsSSH_SHELL_UNAVAILABLEwithout opening a channel.- No shell, no exec and no SFTP → the connect fails with
SERVER_NO_USABLE_CHANNELand a clear message. exec = false→sftp_elevation_allowedreturnsfalse.- 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=Availableafter the terminal opens,exec=true,sftp=true, sftp_via_exec=false; connect time unchanged apart from the SFTP open. -
sftp_elevation_allowedisfalsewhenexec=false. -
generated/ipc.tsregenerated; 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_lostpath; 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_execfromelevated_sftp.rsby moving the non-sudo part to app-logic (recommended) or call it from app-shell.
Related Work
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity