microsoft / microsoft/vscode

Codex Agent Host restarts the full MCP server set in an existing thread

Open
#336,735 0 comments 0 reactions 1 assignee Assigned to @roblourens View on GitHub
agent-host new release
Dominant language
TypeScript
Stars
193k
Forks
42.4k
PR merge metrics
PR metrics pending

Description

- Copilot Chat Extension Version: Built-in
- VS Code Version: 1.138.0
- OS Version: macOS 26.6.2 (arm64)
- Feature: Chat view / Agents window, Codex on Agent Host
- Selected model: GPT-6 Astra, ChatGPT-backed Codex
- Codex Agent Host SDK: 0.153.0

## Problem

The Codex Agent Host reinitializes the complete MCP server set in an existing chat/thread. The restart can happen again on the next turn even though the user did not edit MCP configuration.

In one VS Code 1.138.0 session, the same Codex thread ID started all 15 configured MCP servers at 17:24:27 and started the same set again at 18:01:45 when the existing chat continued. Both local stdio and remote HTTP servers were affected.

This is expensive for `npx`-launched servers, adds roughly 10–30 seconds before a turn can proceed, repeats OAuth failures/prompts, and repeatedly rebuilds the tool inventory.

The standalone OpenAI Codex extension path does not show the same behavior in the same environment: its MCP connection initializes once, while the Agent Host path produces a new full `starting → ready` wave.

## Steps to reproduce

1. Enable `chat.agentHost.codexAgent.enabled` and `chat.editor.codex.preferAgentHost`.
2. Sign in to ChatGPT and select the Codex Agent Host target.
3. Configure multiple MCP servers, including at least one local stdio server. The issue is easier to notice with an `npx`-launched server.
4. Start a Codex chat in a workspace and send a request.
5. After the first response, send another request in the same chat. A task that edits a workspace file reproduces this reliably.
6. Inspect `agenthost.log` or the running MCP processes.

## Expected behavior

MCP processes should remain alive for the existing Codex thread/session. An individual server should restart only when that server's effective configuration changes.

## Actual behavior

The existing thread receives another full MCP startup wave. Example with identifiers and server names redacted:

```text
17:24:27.806 [Codex] thread/start for session= with MCP servers
17:24:27.982 [Codex] MCP server '' startup status for : starting
...
17:24:27.990 [Codex] MCP server '' startup status for : starting

18:01:45.504 [Codex] MCP server '' startup status for : starting
...
18:01:45.514 [Codex] MCP server '' startup status for : starting
```

The installed 1.138.0 Agent Host bundle still recomputes `_buildSessionMcpServers()` in `_ensureCurrentLaunchBeforeTurn()`. When the materialized MCP signature differs after the first turn, it marks the session for reload; the resume path then sends the full MCP set again. Workspace/customization change notifications appear able to invalidate the materialized signature even when no MCP configuration changed.

A longer sanitized log excerpt showing both startup waves for the same thread is attached below.

[vscode-agenthost-mcp-restart-sanitized.txt](https://github.com/user-attachments/files/32375196/vscode-agenthost-mcp-restart-sanitized.txt)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.