agentHost: Remember and reuse CLI processes for ssh#307770
Merged
roblourens merged 3 commits intomainfrom Apr 5, 2026
Merged
Conversation
Co-authored-by: Copilot <copilot@github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds SSH remote agent-host process reuse by persisting remote CLI agent-host state (PID/port/token) in a state file and attempting to reconnect to an existing process before starting a new one, reducing orphaned code agent-host processes on reconnect.
Changes:
- Add reusable SSH helper utilities to read/write/validate a remote
.agent-host-statefile and to clean up stale processes. - Update the SSH connect flow to (1) detect an existing remote agent-host, (2) reuse it when possible, and (3) fall back to cleanup + fresh start when reuse is not connectable.
- Add node tests covering helper behavior and the end-to-end connect/reuse/cleanup flow via in-process mocks.
Show a summary per file
| File | Description |
|---|---|
| src/vs/platform/agentHost/node/sshRemoteAgentHostService.ts | Integrates remote agent-host reuse into the SSH connect flow; refactors to allow test overrides and uses DisposableMap for connection lifecycle. |
| src/vs/platform/agentHost/node/sshRemoteAgentHostHelpers.ts | New helper module for shell-safe paths, platform detection, token redaction, and state-file based process reuse/cleanup. |
| src/vs/platform/agentHost/test/node/sshRemoteAgentHostHelpers.test.ts | Unit tests for helper utilities (token validation, state parsing/cleanup, state writing). |
| src/vs/platform/agentHost/test/node/sshRemoteAgentHostService.test.ts | Connect-flow tests validating caching, reuse via state, stale cleanup, relay-failure fallback, and sanitization behavior. |
Copilot's findings
- Files reviewed: 4/4 changed files
- Comments generated: 3
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the SSH-based remote agent host bootstrap to persist and reuse a previously-started code agent-host process by recording its PID/port/token on the remote machine, reducing orphaned processes and reconnect overhead.
Changes:
- Add remote “agent host state file” helpers to record and detect an existing running agent host via PID/port/token.
- Update
SSHRemoteAgentHostMainService.connect()to reuse an existing agent host when possible, and fall back to starting fresh on relay failures. - Add new unit tests for the helper utilities and the connect/reuse/fallback flow.
Show a summary per file
| File | Description |
|---|---|
| src/vs/platform/agentHost/node/sshRemoteAgentHostService.ts | Implements process reuse via remote state file lookup + relay fallback behavior; refactors native module loading for testability. |
| src/vs/platform/agentHost/node/sshRemoteAgentHostHelpers.ts | New helper module for shell-safe paths, state file read/write, reuse detection, and cleanup. |
| src/vs/platform/agentHost/test/node/sshRemoteAgentHostHelpers.test.ts | Adds coverage for state parsing/validation, shell escaping, URL building, and cleanup/write behavior. |
| src/vs/platform/agentHost/test/node/sshRemoteAgentHostService.test.ts | Adds connect-flow tests for caching, reuse via state file, stale PID behavior, and relay-failure fallback. |
| src/vs/workbench/contrib/chat/test/common/model/objectMutationLog.perf.test.ts | Adds an opt-in perf benchmark for Chat ObjectMutationLog (appears unrelated to agentHost SSH changes). |
Copilot's findings
- Files reviewed: 5/5 changed files
- Comments generated: 2
src/vs/workbench/contrib/chat/test/common/model/objectMutationLog.perf.test.ts
Show resolved
Hide resolved
justschen
approved these changes
Apr 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Co-authored-by: Copilot copilot@github.com