Agent Host: let scheduled automations and remote messages activate an idle-retired SSH agent host
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 maindcb1ee528d4177b2afb7fcac4d97d421d2740574(2026-11-17) - Linux SSH-managed agent hosts, macOS Agents window, Copilot SDK provider
- Organization remote-control policy not enabled (
--github-environmentis refused: "GitHub environment hosting is disabled by remote-control policy")
Current behavior
- 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 downabout six minutes after the laptop slept, with no turn active. - 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
isReadyForAutomationfalse (copilotAgent.ts#L3987), so due runs are deferred (agentHostAutomationService.ts#L1240) until a window connects. - Routing.
send_remote_messagerejects 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. - 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:
- 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.
- 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.
- 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 #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
- #338392 keeps remote hosts alive while agents are running; it covers active turns, not future triggers.
- #347402 / #348787 share self-hosted hosts as GitHub environments with CLI-owned credentials; this is the policy-gated path described above.
- #344932 (chat created while the remote host is disconnected can't be restored) is a different failure: restore, not activation.
- #348798 (restart a remote agent host from the UI) is manual recovery, not activation.
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.
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_TOKENcomes fromgh 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
ghOAuth login.
Posted by an AI assistant at the user's request.