Skip to content

Commit 8620789

Browse files
PR Batch Testerclaude
andcommitted
fix(ssh): take over another key's server only once it answers
A stalled server under another key no longer costs this key its own working server: the takeover waits for readiness first, as the external-adoption path does, and keeps the current server otherwise. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent e9e99c0 commit 8620789

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

‎packages/ssh/src/tunnel.ts‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -664,22 +664,26 @@ elif [ -n "$DEFAULT_REMOTE_PORT" ] && PREVIOUS_STATE_DIR="$(launcher_state_dir_f
664664
# Adopting it as external would keep it on its old version through every
665665
# update. It runs the runner its previous state wrote, so that runner decides
666666
# whether this launch is an update.
667-
if cmp -s "$PREVIOUS_STATE_DIR/run-t3.sh" "$RUNNER_FILE"; then
668-
RUNNER_CHANGED=0
667+
REMOTE_PORT="$DEFAULT_REMOTE_PORT"
668+
if wait_ready "@@T3_REUSE_READY_TIMEOUT_MS@@"; then
669+
if cmp -s "$PREVIOUS_STATE_DIR/run-t3.sh" "$RUNNER_FILE"; then
670+
RUNNER_CHANGED=0
671+
else
672+
RUNNER_CHANGED=1
673+
fi
674+
if [ "$REMOTE_MANAGED" = "managed" ] && [ -n "$REMOTE_PID" ] && kill -0 "$REMOTE_PID" 2>/dev/null; then
675+
kill "$REMOTE_PID" 2>/dev/null || true
676+
wait_for_pid_exit "$REMOTE_PID"
677+
fi
678+
REMOTE_PID="$DEFAULT_RUNTIME_PID"
679+
REMOTE_MANAGED="managed"
680+
printf '%s\\n' "$REMOTE_PID" >"$PID_FILE"
681+
printf '%s\\n' "$REMOTE_PORT" >"$PORT_FILE"
682+
printf 'managed\\n' >"$MANAGED_FILE"
683+
rm -f "$PREVIOUS_STATE_DIR/pid" "$PREVIOUS_STATE_DIR/managed"
669684
else
670-
RUNNER_CHANGED=1
671-
fi
672-
if [ "$REMOTE_MANAGED" = "managed" ] && [ -n "$REMOTE_PID" ] && kill -0 "$REMOTE_PID" 2>/dev/null; then
673-
kill "$REMOTE_PID" 2>/dev/null || true
674-
wait_for_pid_exit "$REMOTE_PID"
685+
REMOTE_PORT="$(cat "$PORT_FILE" 2>/dev/null || true)"
675686
fi
676-
REMOTE_PID="$DEFAULT_RUNTIME_PID"
677-
REMOTE_PORT="$DEFAULT_REMOTE_PORT"
678-
REMOTE_MANAGED="managed"
679-
printf '%s\\n' "$REMOTE_PID" >"$PID_FILE"
680-
printf '%s\\n' "$REMOTE_PORT" >"$PORT_FILE"
681-
printf 'managed\\n' >"$MANAGED_FILE"
682-
rm -f "$PREVIOUS_STATE_DIR/pid" "$PREVIOUS_STATE_DIR/managed"
683687
elif [ -n "$DEFAULT_REMOTE_PORT" ]; then
684688
REMOTE_PORT="$DEFAULT_REMOTE_PORT"
685689
if wait_ready "@@T3_REUSE_READY_TIMEOUT_MS@@"; then

0 commit comments

Comments
 (0)