Skip to content

Commit b92fcaf

Browse files
committed
Merge origin/main into feat/2231-remote-containers (#2231)
Keep the container hops of the chain and the resume retry of the persistent sessions; the connection log still tells a container apart.
2 parents e1e0d10 + ac80382 commit b92fcaf

35 files changed

Lines changed: 1122 additions & 99 deletions

‎rust/contracts/remote-workspace-protocol-v1.md‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ socket, lock and log under `<dir>` (default `$HOME/.lithe-server`) in
1919
directories only the user can access, and rejects peers with another user
2020
id. A session has one client at a time: a new connection that presents the
2121
session token (see below) replaces the current one. The idle timeout runs
22-
only while the session has neither a client nor running processes or open
23-
terminals; it is 10 minutes unless `server.hello` requests another with
22+
while the session has no client, unless its last client sent `server.keep`
23+
and the session still runs processes or open terminals; when it passes, the
24+
session ends with everything it runs. It is 10 minutes unless `server.hello` requests another with
2425
`idleTimeoutSeconds`, at most 24 hours, and the latest request applies. A
2526
connection the daemon cannot set up is closed without ending the session.
2627
The daemon log is created `0600`, never through a symbolic link, and moves to
@@ -119,6 +120,7 @@ subscribe before creating the resource.
119120
| `server.resume` | `afterSeq?` | `truncated`; then every kept event after `afterSeq`, followed by live events |
120121
| `server.ack` | `seq` | `null`; events up to `seq` may be forgotten |
121122
| `server.shutdown` | — | `null`; the session ends |
123+
| `server.keep` | — | `null`; the running processes and terminals outlast this client; `UNSUPPORTED` on a `--stdio` session |
122124
| `server.ping` | — | `{}` |
123125
| `server.state` | — | running `processes` (`processId`, `pid`, `argv`, `label?`, `runningMs`, `leaderExited`), `terminals` (`terminalId`, `pid`, `argv`, `label?`, `runningMs`, `columns`, `rows`), `watches` |
124126
| `fs.stat` | `path` | metadata of the path itself (links not followed) |
@@ -327,7 +329,13 @@ events after `afterSeq` were dropped; the client re-reads state and rescans
327329
watches.
328330

329331
While no client is attached, a persistent session keeps processes, terminals
330-
and watches running. Tunnels, walks and listeners belong to the connection
332+
and watches running until the idle timeout. A client whose user chose to
333+
leave them running sends `server.keep` before it goes, without
334+
`server.shutdown`; the session then outlasts the idle timeout while any of
335+
its processes or terminals runs, and ends once none does. Each client that
336+
attaches decides again: attaching clears an earlier `server.keep`. So the
337+
programs of a client that crashed or lost its network end with the session
338+
after the idle timeout, unless the user reconnects before it passes. Tunnels, walks and listeners belong to the connection
331339
that opened them and end with it. After `server.shutdown` a persistent session is no
332340
longer reachable, even while it is still terminating its processes; the next
333341
connection with the same key starts a fresh session.

‎rust/contracts/rust-core-api.md‎

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ or removing a command fails until the table changes in the same commit.
804804
| `remote.authRespond` | Answer or cancel a prompt relayed by `remote.probe` or `remote.connect` once |
805805
| `remote.connect` | Open a connection over SSH or to a local WSL distribution, installing the shipped server when needed |
806806
| `remote.readDir` | List a directory over an open remote connection |
807-
| `remote.disconnect` | Close an open connection and its OpenSSH or `wsl.exe` process tree |
807+
| `remote.disconnect` | Close an open connection and its OpenSSH or `wsl.exe` process tree, ending or keeping the programs it runs on the host |
808808
| `remote.closeAll` | Close every open connection; the host calls it at application exit |
809809
| `remote.readFile` | Read a file over an open remote connection |
810810
| `remote.writeFile` | Save a file over an open remote connection |
@@ -834,7 +834,9 @@ or removing a command fails until the table changes in the same commit.
834834
| `remote.devcontainerConfigs` | List the `devcontainer.json` files of a local folder |
835835
| `remote.devcontainerUp` | Build or reuse and start a trusted local folder's dev container with the Dev Container CLI |
836836
| `remote.preferences` | Read the remote workspace settings and what each automatic value resolves to |
837-
| `remote.editPreferences` | Set the SSH program, the reconnect limit or whether reverse forwards are allowed, or make one automatic again |
837+
| `remote.editPreferences` | Set the SSH program, the reconnect limit, whether reverse forwards are allowed or what closing a connection does to its programs, or make one automatic again |
838+
| `remote.runningPrograms` | List the processes and terminals a connection's host session still runs |
839+
| `remote.endPrograms` | End every process and terminal a connection's host session runs, or the listed ones |
838840
| `git.historyRewritePreview` | Review undo, message edit, squash, or drop with complete messages, eligibility, and an immutable checkout expectation |
839841
| `git.remotes` | Return configured fetch remote names and URLs |
840842
| `git.tags` | Return tag names, tag object IDs, target IDs, dates, and annotations |
@@ -4420,6 +4422,15 @@ script file, or a program or interpreter named by a path that is not a file, is
44204422

44214423
Batch runs are `not_supported` outside Windows.
44224424

4425+
In a remote workspace (a request carrying `remoteWorkspace`) every
4426+
`runConfig.*` command reads and checks the host's files, and process runs are
4427+
planned for the host, which is Linux or macOS, so they never get a Windows
4428+
interpreter or a batch script even when the client is Windows. The plan's
4429+
`executable.path`, `arguments` and `inlineScript.path` are host paths, and
4430+
`inlineScriptBase` must name a host temporary directory, so the client starts
4431+
the process on the host without translating the plan. A host that cannot be
4432+
reached fails the request instead of reporting a file as missing.
4433+
44234434
`diagnostics.redactText` accepts `text` and returns `redacted` with
44244435
credentials, tokens, and home-directory paths replaced by stable placeholders
44254436
(`<redacted>` for secrets, `<HOME>` for a macOS/Linux `Users`/`home` path or a
@@ -6022,7 +6033,8 @@ and returns `{ preferences, ssh, reconnect, reverseForwarding, storage,
60226033
sshConfig? }`:
60236034

60246035
- `preferences` is `{ sshProgram, reconnectLimitSeconds,
6025-
allowReverseForwarding }`, the stored values; `null` is automatic.
6036+
allowReverseForwarding, closePrograms }`, the stored values; `null` is
6037+
automatic.
60266038
- `ssh` is `{ source, path, status }`, the OpenSSH client every connection
60276039
starts. `source` is `setting` for a stored program and `automatic`
60286040
otherwise, which is the first executable `ssh` (`ssh.exe` on Windows) in an
@@ -6039,6 +6051,14 @@ sshConfig? }`:
60396051
- `reverseForwarding` is `{ source, allowed }`: whether the ports page may
60406052
start reverse forwards (automatic: not allowed), because every user of the
60416053
host can reach the local port one opens.
6054+
- `closing` is `{ source, programs, idleTimeoutSeconds }`: what happens to
6055+
the processes and terminals still running on the host when a window closes
6056+
its connection. `programs` is `ask` (automatic: the client asks every
6057+
time, and may offer to remember the answer), `end` or `keep`. Nothing
6058+
keeps running on a host, or ends, without the user deciding.
6059+
`idleTimeoutSeconds` (600) is how long the host keeps a session whose
6060+
connection was lost and whose programs nobody kept; the server sets it and
6061+
no document changes it.
60426062
- `storage` is `{ relativePath: "remote/preferences.json", maximumBytes:
60436063
16384 }`.
60446064
- `sshConfig` is `{ path, exists }` for `.ssh/config` below `homeDirectory`,
@@ -6053,6 +6073,8 @@ sshConfig? }`:
60536073
makes the limit automatic with `null`.
60546074
- `reverseForwarding: { allowed: boolean|null }` allows or refuses reverse
60556075
forwards, or makes the switch automatic with `null`.
6076+
- `closePrograms: { programs: "ask"|"end"|"keep"|null }` stores the closing
6077+
choice, or makes it automatic with `null`.
60566078

60576079
The result is `{ changed, document: string|null }`; an unchanged edit
60586080
returns a `null` document and must not create a source. No field or more
@@ -6074,7 +6096,7 @@ user-settings resource does not affect code signatures or update deltas.
60746096
#### Remote connections that stay open
60756097

60766098
`remote.connect` takes `{ connection, servers: [{ target, path, sha256 }],
6077-
serverVersion, installRoot? }`. `servers` are the read-only server builds the
6099+
serverVersion, installRoot?, resume? }`. `servers` are the read-only server builds the
60786100
host ships, by Rust target; `sha256` is the build's SHA-256 as 64 hexadecimal
60796101
digits, taken from the manifest the application ships and signs with the
60806102
builds, never computed from the file Core is about to send. `installRoot`
@@ -6097,8 +6119,26 @@ and `{ stage: "installed", uploaded }` once the server is in place, where
60976119
failed attempt stops after the last stage reached, so a host without a
60986120
matching build stops after `platformChecked`. The result is `{ status, session,
60996121
host, diagnostics }`; `session` is `{ id, uploaded, hostName, userName,
6100-
homeDirectory }` and is set only for `connected`. A host without a matching
6101-
build is `unsupportedPlatform` and nothing is uploaded.
6122+
homeDirectory, sessionKey, sessionToken, resumed, keptPrograms }` and is set
6123+
only for `connected`. A host without a matching build is
6124+
`unsupportedPlatform` and nothing is uploaded.
6125+
6126+
The server runs a persistent session (`--connect <sessionKey>`, with
6127+
`--state-dir <installRoot>` when one is given), so what it runs survives the
6128+
connection. `sessionKey` names that session and `sessionToken` is the secret
6129+
that attaches to it again; the client stores the token like a password and
6130+
never logs it. To attach to a session an earlier connection kept, pass
6131+
`resume: { key, token }` with the values it returned. `resumed` tells whether
6132+
this connection attached to it; `keptPrograms` lists the processes and
6133+
terminals it still runs, as `remote.runningPrograms` does, and is empty for
6134+
a new session. When the host refuses the token, because the session ended
6135+
and another took its key, Core connects once more without `resume`, so the
6136+
user authenticates again but is never locked out; that connection reports
6137+
`resumed: false` and a new key and token. A key that is empty, longer than 64
6138+
characters or not made of ASCII letters, digits, `.`, `_` and `-`, or a token
6139+
that is empty, longer than 128 characters or not hexadecimal, is
6140+
`invalid_request` with `{ field: "resume", reason: "invalid" }`, before
6141+
OpenSSH or `wsl.exe` starts.
61026142

61036143
Instead of `connection`, the request may name a WSL distribution on this
61046144
Windows machine as `wsl: { distribution, user? }`, where `distribution` is a
@@ -6156,9 +6196,18 @@ without sending anything; `details` says which of the two happened and, for a
61566196
mismatch, the SHA-256 Core computed, but never the path. Cancellation and the
61576197
five-minute bound are `cancelled` and `timed_out`.
61586198

6159-
Core keeps an open connection until `remote.disconnect` (`{ sessionId }`,
6160-
returning `{ closed }`) or until the host process exits; ending it terminates
6161-
the OpenSSH or `wsl.exe` process tree. `remote.closeAll` (no payload, returning
6199+
Core keeps an open connection until `remote.disconnect` (`{ sessionId,
6200+
programs? }`, returning `{ closed, kept }`) or until the host process exits;
6201+
ending it terminates the OpenSSH or `wsl.exe` process tree. `programs` is
6202+
`end` (the default), which ends the host session with every process and
6203+
terminal it runs, or `keep`, which tells the host to keep them and leaves
6204+
without ending the session; a later `remote.connect` with `resume` finds
6205+
them. `kept` tells whether the host keeps them: it is `false` for `end`, for
6206+
an unknown or closed connection (`closed: false`) and when the host could not
6207+
be told, whose programs then end like those of a client that crashed. A
6208+
session nobody kept, such as one whose client crashed or lost its network,
6209+
ends with its programs once the server's idle timeout (ten minutes) passes
6210+
without a client; one whose programs were kept lasts until they end. `remote.closeAll` (no payload, returning
61626211
`{ closed }` with the number of connections) ends all of them; the host calls
61636212
it while quitting because exiting without it can leave the OpenSSH tree and
61646213
the remote server running. Requests over it take `sessionId`:
@@ -6175,6 +6224,8 @@ the remote server running. Requests over it take `sessionId`:
61756224
| `remote.runProcess` | `{ sessionId, params: { argv, cwd?, environment?, env?, pipeStdin?, label? } }` | leader exit; relays `process.started`, `process.output`, `process.exit` |
61766225
| `remote.runTerminal` | `{ sessionId, params: { argv?, cwd?, env?, columns, rows, label? } }` | leader exit; relays `terminal.started`, `terminal.output`, `terminal.exit` |
61776226
| `remote.captureProcess` | `{ sessionId, params, timeoutMilliseconds, maxOutputBytes }` | base64 `stdout`, `stderr`, nullable `exitCode` and `signal` |
6227+
| `remote.runningPrograms` | `{ sessionId }` | `{ programs: [{ kind, id, argv, label, runningMs }] }`, processes first; `kind` is `process` or `terminal`, `label` the one the program started with or `null` |
6228+
| `remote.endPrograms` | `{ sessionId, programs? }` | `{ ended }`: every running process gets `SIGTERM` for its process session and every terminal hangs up, or only those `programs` (`[{ kind, id }]` as `remote.runningPrograms` listed them) names; one that ended in the meantime or is not running is not counted, one that ignores the signal is still listed |
61786229

61796230
`remote.writeFile` replaces the file atomically on the host. With
61806231
`expected` (`{ size, modifiedMs }` from the read) a changed file is a

‎rust/crates/core/src/protocol/command.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,12 @@ pub enum RemoteCommand {
10601060
Preferences,
10611061
/// Changes one remote workspace preference (`remote.editPreferences`).
10621062
EditPreferences,
1063+
/// Lists the processes and terminals a host session still runs
1064+
/// (`remote.runningPrograms`).
1065+
RunningPrograms,
1066+
/// Ends every process and terminal a host session runs
1067+
/// (`remote.endPrograms`).
1068+
EndPrograms,
10631069
}
10641070

10651071
#[derive(Debug, Clone)]
@@ -1647,6 +1653,8 @@ impl CoreCommand {
16471653
"remote.devcontainerUp" => Some(Self::Remote(RemoteCommand::DevcontainerUp)),
16481654
"remote.preferences" => Some(Self::Remote(RemoteCommand::Preferences)),
16491655
"remote.editPreferences" => Some(Self::Remote(RemoteCommand::EditPreferences)),
1656+
"remote.runningPrograms" => Some(Self::Remote(RemoteCommand::RunningPrograms)),
1657+
"remote.endPrograms" => Some(Self::Remote(RemoteCommand::EndPrograms)),
16501658
"git.historyRewritePreview" => Some(Self::Git(GitCommand::HistoryRewritePreview)),
16511659
"git.remotes" => Some(Self::Git(GitCommand::Remotes)),
16521660
"git.tags" => Some(Self::Git(GitCommand::Tags)),

‎rust/crates/core/src/runtime/dispatcher.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@ fn execute_parsed(mut parsed: CoreRequest, document: Option<&str>) -> CoreRespon
748748
fn has_remote_workspace_adapter(command: &str) -> bool {
749749
command.starts_with("git.")
750750
|| command.starts_with("build.")
751+
|| command.starts_with("runConfig.")
751752
|| matches!(
752753
command,
753754
"workspace.repositories"

‎rust/crates/core/src/runtime/dispatcher/remote.rs‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,23 @@ pub(super) fn dispatch(command: RemoteCommand, id: Option<String>, payload: Valu
305305
"Invalid remote preferences request",
306306
lithe_workspace::preferences::edit,
307307
),
308+
RemoteCommand::RunningPrograms => answer(
309+
id,
310+
payload,
311+
"Invalid remote programs request",
312+
lithe_workspace::programs::list,
313+
),
314+
RemoteCommand::EndPrograms => answer(
315+
id,
316+
payload,
317+
"Invalid remote programs request",
318+
lithe_workspace::programs::end,
319+
),
308320
RemoteCommand::Disconnect => {
309321
match serde_json::from_value::<lithe_workspace::sessions::DisconnectRequest>(payload) {
310-
Ok(request) => CoreResponse::success(
311-
id,
312-
json!({ "closed": lithe_workspace::sessions::disconnect(request) }),
313-
),
322+
Ok(request) => {
323+
CoreResponse::success(id, json!(lithe_workspace::sessions::disconnect(request)))
324+
}
314325
Err(error) => CoreResponse::failure(
315326
id,
316327
CoreError::new(

‎rust/crates/core/src/runtime/request_trace.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ mod tests {
294294
"remote.startForward",
295295
"remote.startHostForward",
296296
"remote.startReverseForward",
297+
"remote.runningPrograms",
298+
"remote.endPrograms",
297299
"debug.launch",
298300
] {
299301
assert!(!is_hot(method), "{method}");

0 commit comments

Comments
 (0)