fix(ssh): exec managed servers without npm wrappers #9843
main fromrefs/pull/9843/head·merged by juliusmarminge View on GitHubSSH-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 result | Before | After |
|---|---|---|
| Recorded PID | 270404 | 291786 |
| Server PID | 270440 | 291786 |
| Stop reports success | Yes | Yes |
| Server still answers after stop | Yes | No |
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 --checkpassed.
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.
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
execthe resolvedT3_CLI_PATHrather than invoking the package manager with the package spec as the final process. - Package managers are still used by
require_installed_t3_clito locate thet3executable; 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_PATHand 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/npminvocation now end withexecof the resolved CLI path; out-of-tree consumers of the generated script will see a different final command.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XS
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Approvability#
Verdict: Approved at
af2b6beMacroscope'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).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.
juliusmarminge merged thisf33fdc9
juliusmarminge closed this
Sign in to join this conversation.
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline:
087cfb8· PR result:af2b6be· Source CI: successScenario 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.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.