Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(ssh): exec managed servers without npm wrappers #9843

Mergedjuliusmarmingemerged 1 commit intomain fromrefs/pull/9843/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

SSH-managed servers started through npx/npm can outlive Disconnect or app shutdown. The launcher records the npm wrapper's PID, so its stop script signals npm while the actual server keeps its listener and database open.

Exec the CLI path already resolved by the install preflight. This keeps the launcher's PID attached to the server without changing package selection, install-error handling, Node discovery, WSL routing, or external-server ownership.

Closes #2614.

Verification

Reproduced on main 087cfb8a using the generated launch/stop scripts, actual npm/npx, and an offline local fixture package. Only the fixture's state path was substituted. No production data, remote machines, or provider processes were used.

Generated launch/stop resultBeforeAfter
Recorded PID270404291786
Server PID270440291786
Stop reports successYesYes
Server still answers after stopYesNo

The new regression runs the real POSIX runner with controlled npm/npx executables and a real Node listener. Both cases fail on the original runner with a PID mismatch. With this change, both preserve arguments and pinned package selection, receive SIGTERM, shut down gracefully, and restart on the same port.

  • vp test run packages/ssh/src/runnerProcess.test.ts packages/ssh/src/tunnel.test.ts --maxWorkers=2: 15 passed.
  • Scoped SSH typecheck and lint for the three changed files passed.
  • git diff --check passed.

This is Linux process evidence, not a Windows desktop or macOS end-to-end run. The POSIX test skips native Windows. Existing orphaned processes are not retroactively removed. Screenshots do not apply to this process-lifecycle change.

GPT 6 Astra via Codex in T3 Code.


Note

Medium Risk Changes remote process lifecycle and shutdown for SSH-managed servers; behavior is well-covered by new integration tests but affects production disconnect/stop paths on Linux/macOS remotes.

Overview Fixes SSH-managed remote servers orphaning after disconnect or shutdown: the launch script stored the npm/npx wrapper PID, so stop only killed the wrapper while the real t3 serve process kept listening.

After the existing require_installed_t3_cli preflight, the remote runner now execs the resolved T3_CLI_PATH instead of re-invoking npx/npm exec, so the recorded PID is the server process. Install checks, package pinning, and error messages are unchanged.

Adds runnerProcess.test.ts, a POSIX live test (skipped on Windows) that feeds the generated script through fake npx/npm and asserts PID match, argument forwarding, SIGTERM graceful shutdown, and port reuse. tunnel.test.ts expectations were updated for the new exec "$T3_CLI_PATH" lines.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit af2b6be644801b8d878b92df8381c9dbe74b79cb. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Fix buildRemoteT3RunnerScript to exec resolved T3_CLI_PATH instead of npm wrappers

  • The npx and npm fallback branches in the generated remote shell script now exec the resolved T3_CLI_PATH rather than invoking the package manager with the package spec as the final process.
  • Package managers are still used by require_installed_t3_cli to locate the t3 executable; only the final launch step changes.
  • Because the launcher replaces itself with the CLI process, the PID it records is the CLI server's PID and signals (e.g. SIGTERM) are delivered directly to that process.
  • Updates tunnel script generation tests to assert execution through T3_CLI_PATH and adds a live test suite verifying PID preservation, argument forwarding, and graceful shutdown for both npx and npm fallback paths.
  • Behavioral Change: generated remote runner scripts that previously ended with npx/npm invocation now end with exec of the resolved CLI path; out-of-tree consumers of the generated script will see a different final command.
Macroscope summarized af2b6be.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire13.5 KiB13.6 KiB+32 B (+0.2%)15.1 KiB✅
      CodexThread snapshot wire7.0 KiB7.0 KiB−8 B (−0.1%)7.3 KiB✅
      CodexLive turn WebSocket wire6.5 KiB6.6 KiB+40 B (+0.6%)7.8 KiB✅
      CodexLive turn WebSocket decoded57.0 KiB57.1 KiB+88 B (+0.2%)66.4 KiB✅
      CodexLive turn messages810+2 (+25.0%)21✅
      ClaudeTotal thread wire13.5 KiB13.6 KiB+24 B (+0.2%)15.1 KiB✅
      ClaudeThread snapshot wire7.0 KiB7.0 KiB−4 B (−0.1%)7.3 KiB✅
      ClaudeLive turn WebSocket wire6.5 KiB6.5 KiB+28 B (+0.4%)7.8 KiB✅
      ClaudeLive turn WebSocket decoded57.8 KiB57.8 KiB+44 B (+0.1%)66.4 KiB✅
      ClaudeLive turn messages89+1 (+12.5%)21✅

      Baseline: 087cfb8 · PR result: af2b6be · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 113.8 KiB
      • Claude decoded thread snapshot: 114.5 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    3. Approvability

      Verdict: Approved at af2b6be

      Macroscope's review found this PR approvable — This is a focused SSH process-lifecycle fix: managed servers now retain the actual CLI PID, allowing existing stop and shutdown handling to reach the server instead of an npm wrapper. Installation behavior remains unchanged, and targeted live tests cover both npx and npm fallback paths.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. Orchestrator audit: reviewed the complete three-file change and its surrounding launcher/stop behavior. The existing install preflight still resolves the pinned CLI; the final exec now makes the recorded PID the server PID. The real-process before/after regression covers both package-manager paths, argument preservation, SIGTERM and port reuse. All current-head checks and bot reviews are green, with no unresolved review threads. This is a focused repair within the requested automatic-merge scope. Merging head af2b6be644801b8d878b92df8381c9dbe74b79cb. GPT 6 Astra via Codex in T3 Code.

    5. juliusmarminge merged thisf33fdc9

    6. juliusmarminge closed this

Sign in to join this conversation.