Skip to content

Agent host: chat created while the remote host connection is down cannot be restored (Session identity was not advertised) #344932

Open

Description

When the connection to a remote agent host is down and VS Code has stopped reconnecting, sending the first message in a new chat for that host still creates a chat session on the client only. The host never creates it. After a reload, that chat's editor can't be restored and shows "The editor could not be opened due to an unexpected error". Try Again keeps failing, and the prompt is lost.

Version: 1.145.0-insider (commit c5f99e8), Windows, remote agent host over WebSocket (copilotcli provider).

What happened (reconstructed from the renderer log)

  1. The WebSocket connection to the remote agent host closed. RemoteAgentHostProtocol retried in rounds (Automatic reconnect to <host> gave up after 10 attempts., followed by Connection closed and another round). After about 20 minutes, the rounds stopped. The window then stayed disconnected from that host for about 12 hours, with no further reconnect attempts in the log.
  2. In that state, I opened a new chat for that host and sent a message:
    [info]  ChatService#materializeUntitledSession: Materialized untitled session <host>-copilotcli:/untitled-<uuid> into real session <host>-copilotcli:/<id>
    [info]  [AgentHost] _invokeAgent called for resource: <host>-copilotcli:/<id>
    [error] Error while handling chat request: Automatic reconnect gave up after 10 attempts.: Error: Automatic reconnect gave up after 10 attempts.
    
    The request failed immediately, but the editor kept the materialized resource /<id>. The same failure had already happened once with an earlier new chat.
  3. Later, the window reconnected to the host and was reloaded. Restoring that chat editor fails, and so does every Try Again:
    [error] ChatService#loadRemoteSession: failed to restore <host>-copilotcli:/<id> Session identity was not advertised by its agent host: <host>-copilotcli:/<id>
    [error] Error: Failed to get model for chat editor. resource: <host>-copilotcli:/<id>
    
    The error comes from _discoverSessionIdentity in agentHostSessionHandler.ts. It refreshes identities through connection.listSessions(), and the ID isn't listed. I confirmed with an AHP listSessions call directly against the host: neither a session nor a chat with that ID exists. The host never received the session.

Problems

  1. No recovery after reconnect gives up. Once automatic reconnect stops, the host connection stays dead indefinitely, but the UI still lets you start chats and send messages to that host. The failure only appears after sending.
  2. The untitled session is materialized before the host confirms it. If creating the session or sending the first message fails, the editor keeps a resource that will never exist on the host. That leaves an editor that can't be restored, and the user's prompt is lost.

Expected

  • Keep reconnecting periodically (or on window focus or network change), or clearly show that the host is disconnected and block sending until it is reachable again.
  • If the first request fails before the host creates the session, keep or revert the chat as untitled and keep the prompt, so the user can resend it once the host is back.
  • When a restored chat refers to a session the host doesn't know, show a specific message instead of the generic "editor could not be opened" error.

Activity

  1. added
    bug
    on Oct 29, 2026
  2. maxpatiiuk commented on Nov 25, 2026

    @maxpatiiuk

    I hit the same reconnect failure in VS Code 1.147.0 (8a14f0cc) on macOS using code serve-web. After waking the laptop, Send button stayed blue in new Copilot harness chats, but the first message didn’t send. Local harness still worked. Reloading the browser tab restored Copilot.

    Browser console:

    [RemoteAgentHostProtocol] Automatic reconnect … gave up after 10 attempts.
    [AgentHost:remote] Protocol client closed
    [remote-connection][Management] reconnected!
    [AgentHostProvisional] Failed to create provisional session …: Automatic reconnect gave up after 10 attempts.
    

    🤖 copilot suggested this fix in

    this._register(this._protocolClient.onDidChangeConnectionState(state => {

    +		this._register(connection.onDidStateChange(event => {
    +			if (event.type === PersistentConnectionEventType.ConnectionGain && event.attempt > 0) {
    +				this._protocolClient?.reconnectFromClosed();
    +			}
    +		}));
  3. davetapley commented on Nov 25, 2026

    @davetapley

    Send button stayed blue in new Copilot harness chats, but the first message didn’t send. Local harness still worked.

    Same, but with app, not in browser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions