Skip to content

agentHost: Keep remote hosts alive while agents are running - #338392

Merged
Logan Ramos (lramos15) merged 4 commits into
mainfrom
lramos15/agents/ssh-agent-session-timeout-issue
Sep 29, 2026
Merged

Logan Ramos (lramos15) merged 4 commits into
mainfrom
lramos15/agents/ssh-agent-session-timeout-issue

Conversation

@lramos15

Copy link
Copy Markdown
Member

Remote agent hosts started with --idle-timeout (managed SSH, WSL, and dedicated tunnel hosts) shut down 300 seconds after the last client disconnected, even while an agent was still running, which killed the in-progress turn.

The CLI supervisor now counts the agent host server process as activity. The server already stays up while a turn is running and exits on its own once idle, so running agents no longer count as idle. Server exit is now detected from the process itself instead of its output closing, so a leftover child process can't keep the supervisor alive.

Notes for reviewers:

  • An idle host frees the server on the same schedule as before. Only the small supervisor process stays up about 5 minutes longer.
  • A turn waiting for approval also keeps the host alive, with no upper limit.

The --idle-timeout supervisor on remote agent hosts only counted connected clients, so it shut the agent host down 300s after the last client disconnected, even while a turn was still running. It now also counts the agent host server process as activity. The server already stays up while a turn is running and exits on its own once idle. Server exit is detected from the process itself rather than from its output pipes closing.

Co-authored-by: Copilot <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Process reaping introduces a PID-reuse race that could terminate an unrelated process tree.

Review effort: Balanced
Findings: 1 High severity

Open (1)
What changed in this PR

Keeps remote agent hosts alive while agent turns remain active and improves process-exit tracking.

Changes:

  • Treats the server process as idle-timeout activity.
  • Detects exit directly from the child process.
  • Adds lifecycle and forced-kill regression tests.
File Description
src/​vs/​platform/​agentHost/​node/​sshRemoteAgentHostHelpers.ts Updates lifecycle documentation.
cli/​src/​tunnels/​idle_timeout.rs Documents server activity semantics.
cli/​src/​tunnels/​agent_host.rs Refactors process ownership, termination, and tests.
cli/​src/​commands/​args.rs Updates idle-timeout help text.
cli/​src/​commands/​agent_host.rs Shares activity tracking with the manager.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread cli/src/tunnels/agent_host.rs Resolved
The task that owns the server process reaps it before the running-server state is cleared, so kill_running_server could run kill_tree on a PID the OS had already reassigned. Kill requests now go through that task, which either reaps a process that exited on its own or kills it before reaping.

Co-authored-by: Copilot <[email protected]>
@connor4312

Copy link
Copy Markdown
Member

Non-blocking simplification suggestion: start_server already spawns run_server and awaits only its readiness barrier. Could run_server continue into the new select! that waits for process exit or a kill request, rather than spawning another task to own/wait on the child after readiness? The output-reader task should stay separate because descendants can keep the pipes open after the server exits. This would leave one clear owner task for the child throughout startup, kill, and reap, and remove the extra process-wait task/manager clone without changing the idle-timeout behavior. The new tests that call run_server directly would need to spawn it and await readiness. I would keep the kill request and exit synchronization: those are important to avoid signaling a reused PID.

start_server already spawns run_server and awaits only its readiness barrier, so run_server now waits for the process to exit or a kill request itself instead of handing the process to a second task. This leaves one owner for the process through startup, kill, and reap. The output reader stays a separate task because descendants can keep the pipes open after the server exits.

Co-authored-by: Copilot <[email protected]>
@lramos15
Logan Ramos (lramos15) merged commit bd991c7 into main Sep 29, 2026
54 of 56 checks passed
@lramos15
Logan Ramos (lramos15) deleted the lramos15/agents/ssh-agent-session-timeout-issue branch September 29, 2026 23:53
@vs-code-engineering vs-code-engineering Bot added this to the 1.141.0 milestone Sep 29, 2026
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Nov 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants