GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(ssh): reconnecting keeps the remote server and its agents running by t3dotgg · Pull Request #19432 · pingdotgg/t3code

fix(ssh): reconnecting keeps the remote server and its agents running #19432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
t3dotgg merged 4 commits into main from t3/ssh-reconnect-keeps-agents
Oct 14, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

fix(ssh): reconnecting keeps the remote server and its agents running #19432

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit Hold shift + click to select a range
eb2dcde
fix(ssh): reconnecting no longer restarts the managed remote server
puccez Oct 10, 2026
7fc462d
fix(ssh): keep remote agents running across reconnects
luke2x Oct 14, 2026
4061610
test(ssh): cover busy and updated managed servers on reconnect
t3dotgg Oct 14, 2026
4572c6b
fix(ssh): replace a managed server that exited but was not reaped
t3dotgg Oct 14, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Prev Previous commit
fix(ssh): replace a managed server that exited but was not reaped
kill -0 also succeeds for a zombie. Now that reconnect waits for a live
managed server instead of replacing it, a crashed server left unreaped
(for example under an init that does not reap orphans) would block every
reconnect. Managed reuse now uses the same zombie check as adoption.
Without ps to tell, both trust kill -0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@t3dotgg @claude
t3dotgg and claude committed Oct 14, 2026
commit 4572c6bec9b7a12a518d1361b1474a7539ab6b3b

There are no files selected for viewing

44 changes: 43 additions & 1 deletion 44 packages/ssh/src/tunnel.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ describe("ssh tunnel scripts", () => {

assert.include(
launch,
'[ -n "$REMOTE_PID" ] && [ -n "$REMOTE_PORT" ] && kill -0 "$REMOTE_PID" 2>/dev/null',
'[ -n "$REMOTE_PID" ] && [ -n "$REMOTE_PORT" ] && server_running "$REMOTE_PID"',
);
assert.include(launch, "RUNNER_CHANGED=1");
assert.include(launch, "ensure_remote_node_path()");
Expand Down Expand Up @@ -1079,6 +1079,7 @@ server.listen(Number(flag("--port")), "127.0.0.1", () => {
return Number(Option.getOrThrow(port));
});
return {
home,
stateDir,
launch,
readManagedPid,
Expand Down Expand Up @@ -1197,6 +1198,47 @@ server.listen(Number(flag("--port")), "127.0.0.1", () => {
60_000,
);

it.effect.skipIf(windowsHost)(
"replaces a managed server that exited but was not reaped",
() =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
const { home, stateDir, readManagedPid, runLaunch, launchManaged } = yield* prepareLaunch;
const { launched, pid } = yield* launchManaged;
process.kill(pid, "SIGKILL");

// A crashed server whose parent never reaps it stays a zombie, which
// kill -0 still reports. Its pid file and runtime record keep naming it.
const parent = yield* spawner.spawn(
ChildProcess.make("sh", ["-c", "sleep 600 & echo $!; exec sleep 600"]),
);
const zombie = Number(
Option.getOrThrow(
yield* parent.stdout.pipe(Stream.decodeText(), Stream.splitLines, Stream.runHead),
),
);
process.kill(zombie, "SIGKILL");
assert.include((yield* runScript(home, ["-c", `ps -o stat= -p ${zombie}`])).stdout, "Z");
yield* fs.writeFileString(`${stateDir}/pid`, `${zombie}\n`);
yield* fs.writeFileString(
`${home}/.t3/userdata/server-runtime.json`,
JSON.stringify({
version: 1,
pid: zombie,
port: launched.remotePort,
origin: `http://127.0.0.1:${launched.remotePort}`,
}),
);

assert.equal((yield* runLaunch).serverKind, "managed");
const replacementPid = yield* readManagedPid;
assert.notEqual(replacementPid, zombie);
assert.isTrue(isAlive(replacementPid));
}).pipe(Effect.provide(NodeServices.layer)),
60_000,
);

it.effect.skipIf(windowsHost)(
"adopts a server it has no managed record for instead of restarting it",
() =>
Expand Down
14 changes: 7 additions & 7 deletions 14 packages/ssh/src/tunnel.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -621,11 +621,11 @@ wait_for_pid_exit() {
done
}
# kill -0 also succeeds for a server that exited but was not reaped yet, so
# a zombie, or a host without ps to tell, does not count as running.
adopted_server_running() {
[ -n "$ADOPTED_PID" ] && kill -0 "$ADOPTED_PID" 2>/dev/null || return 1
case "$(ps -o stat= -p "$ADOPTED_PID" 2>/dev/null || true)" in
"" | *Z*) return 1 ;;
# a zombie does not count as running. Without ps to tell, trust kill -0.
server_running() {
[ -n "$1" ] && kill -0 "$1" 2>/dev/null || return 1
case "$(ps -o stat= -p "$1" 2>/dev/null || true)" in
*Z*) return 1 ;;
esac
}
resolve_default_runtime_port() {
Expand Down Expand Up @@ -701,14 +701,14 @@ fi
if [ "$REMOTE_MANAGED" = "external" ]; then
# A server adopted above has just answered. While it is still alive, probing
# it again could catch a momentary stall and launch a second server beside it.
if adopted_server_running; then
if server_running "$ADOPTED_PID"; then
:
elif [ -z "$REMOTE_PORT" ] || ! wait_ready "@@T3_REUSE_READY_TIMEOUT_MS@@"; then
REMOTE_PID=""
REMOTE_PORT=""
REMOTE_MANAGED=""
fi
elif [ -n "$REMOTE_PID" ] && [ -n "$REMOTE_PORT" ] && kill -0 "$REMOTE_PID" 2>/dev/null; then
elif [ -n "$REMOTE_PID" ] && [ -n "$REMOTE_PORT" ] && server_running "$REMOTE_PID"; then
# Reconnect owns the local tunnel, not the lifetime of an already running
# server. A changed runner is the update path and still replaces it.
if [ "$RUNNER_CHANGED" -eq 1 ]; then
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402809 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.