Skip to content

Agent Host: let scheduled automations and remote messages activate an idle-retired SSH agent host #348946

Todo

Description

Summary

On an SSH-managed remote agent host, scheduled Automations and send_remote_message work only while an Agents window is connected. After the last window disconnects (for example, the laptop sleeps), the server idle-retires and nothing brings it back until a window reconnects. Due runs are deferred, not failed. Remote messages to that host are rejected.

The only built-in way to keep a self-hosted host available is GitHub-environment registration. That mode holds the server lifetime and, since #348787, installs CLI-owned execution credentials. It requires the organization's remote-control policy ("Store local sessions in the Cloud" = "View and control") and keeps the host resident indefinitely. Organizations that don't enable cloud session storage have no way to run scheduled agent work on their own SSH hosts while no client is connected.

Environment

  • VS Code 1.146.0 stable, commit 69047191fc427f2f92828279aae1d90d8eeda7ab; behavior re-checked in source at main dcb1ee528d4177b2afb7fcac4d97d421d2740574 (2026-11-17)
  • Linux SSH-managed agent hosts, macOS Agents window, Copilot SDK provider
  • Organization remote-control policy not enabled (--github-environment is refused: "GitHub environment hosting is disabled by remote-control policy")

Current behavior

  1. Lifetime. The server lifetime token is held only by active sessions, connected WebSocket clients, or a registered GitHub environment (serverAgentHostManager.ts#L138, #L384). An enabled automation with an imminent trigger does not hold it. We observed ServerLifetime: all consumers inactive, shutting down about six minutes after the laptop slept, with no turn active.
  2. Credentials. An SSH host's Copilot credential is pushed by the connected client. Host-owned execution credentials are installed only in GitHub-environment mode (#L235-L238). A server restarted without a client reports isReadyForAutomation false (copilotAgent.ts#L3987), so due runs are deferred (agentHostAutomationService.ts#L1240) until a window connects.
  3. Routing. send_remote_message rejects a target whose provider is "not registered and connected in this Agents window" (remoteSessionMessageRouter.ts#L130). Connecting a managed SSH host already launches it on demand, but the router doesn't attempt that connection.
  4. Send Later (scheduled follow-ups into an existing chat) is limited to the local desktop host (AUTOMATIONS.md#L64).

Net effect: a recurring automation on a self-hosted SSH host runs only while some window is connected. Otherwise it waits and catches up, coalesced, on the next connection.

Requested behavior

Any of these would help, in increasing order of reach:

  1. Reconnect on demand. When the Agents window routes a message (or a user sends) to a known SSH/WSL host that is disconnected, attempt the normal managed connection before rejecting. Keep the current error for hosts that can't be reached.
  2. Schedule-aware lifetime. Let enabled automations whose next trigger falls within a configurable horizon hold the lifetime token, so the server, and the client credential it holds, survive until a due run instead of retiring minutes before it. Hosts with no imminent triggers still retire.
  3. Clientless scheduled execution without cloud session storage. Under an explicit local opt-in that doesn't require GitHub-environment registration or the remote-control policy, allow a self-hosted host to use CLI-owned OAuth execution credentials (the agentHost: use CLI host OAuth credentials for Mission Control #348787 path). Have the CLI supervisor relaunch the server at the next due trigger time and let it retire after the run. This makes schedules independent of any client, with no resident process while idle.

Upgrade behavior should stay as today: relaunches use the version-matched CLI the managed SSH launcher already installs.

Related

We'll add a comment describing our interim local stopgap once it is running.

Filed by an AI assistant at the user's explicit request, based on source inspection and one observed idle retirement. No cold-start experiment was run.

Activity

  1. wcushing-st commented on Nov 17, 2026

    @wcushing-st
    Author

    Interim local stopgap, as mentioned above, in case the design helps with item 3:

    • A systemd user timer runs a shell script every 5 minutes on the SSH host. Linger is enabled, so no login is needed. The script does a cheap, read-only check of a shared work queue (in our case, a notebook where the user hands off work). With nothing queued, it exits without any model request.
    • When work is queued, it runs the Copilot CLI headlessly: copilot -p <prompt> --no-ask-user --allow-all-tools --deny-tool 'shell(sudo:*)' --secret-env-vars COPILOT_GITHUB_TOKEN. COPILOT_GITHUB_TOKEN comes from gh auth token, and that existing OAuth login is the only credential. Neither the Agent Host nor any window is involved.
    • Runs are serialized with flock. A failed run (nonzero exit, or the queued items still unclaimed afterwards) is recorded and pauses runs for an hour. The script checks this issue once a day and flags itself for removal when it closes.

    What it lacks, which item 3 would provide:

    • Each run is a new CLI session. It can't continue an existing Agent Host chat or use remote-session routing, and it has no automation definition, run history or catch-up.
    • Unattended tool permission is set by command-line flags, not per-automation configuration.
    • It duplicates scheduling the Agent Host already has. The host is missing only (a) something outside the server that starts it when a trigger is due and (b) a credential usable with no window connected. In this stopgap, (a) is the OS timer and (b) is the user's existing gh OAuth login.

    Posted by an AI assistant at the user's request.

  2. added
    feature-request
    agent-host
    remote-session-tools
    on Nov 26, 2026
  3. miguel-jose-fernandes-meopt commented on Nov 29, 2026

    @miguel-jose-fernandes-meopt

    Same behavior with "code agent host --tunnel" (dev tunnel, not SSH)

    Environment:

    • VS Code 1.148.0 (server commit 661626d), tunnel CLI 1.147.0 -> 1.148.0
    • Linux server, "code agent host --tunnel" run as a systemd --user service with linger
    • Agent host automations on cron triggers (*/7 and */15), workspace target on the tunnel host
    • The code is on a self-hosted GitLab, so cloud automations can't be used. GitHub-environment mode isn't an option for us either.

    What happens:
    Even though the service runs 24/7, the automations stop a few minutes after the last browser/VS Code client disconnects:

    ServerLifetime: all consumers inactive, shutting down
    Server process exited: Ok(ExitStatus(unix_wait_status(0)))
    Agent host supervisor idle for 300s with no connected clients; shutting down

    The tunnel CLI starts the server with --enable-remote-auto-shutdown. This flag is built into the CLI, and neither "code agent host" nor "code tunnel" has an option to turn it off. systemd's Restart=always doesn't help because the tunnel process never exits. Only the server under it retires, and it comes back only when a client reconnects.

    Our workaround:
    We patch ~/.vscode/cli/servers/*/server/bin/code-server to drop that single argument before running server-main.js:

    for a do shift; [ "$a" = "--enable-remote-auto-shutdown" ] || set -- "$@" "$a"; done

    Request:
    A supported, simple way to run Agents Window automations on a specific machine/environment without a user having to stay connected 24/7. For example:

    • A CLI option or setting to opt out of --enable-remote-auto-shutdown, e.g. "code agent host --tunnel --no-auto-shutdown".
    • Or any other recommended approach you suggest for this scenario.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

agent-hostagents-windowfeature-requestremote-session-tools

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions