Skip to content

fix: clear active MCP servers after cleanup - #4586

Merged
seratch merged 6 commits into
openai:mainfrom
sylvesterkaczmarek:fix/mcp-cleanup-active-servers
Aug 22, 2026
Merged

seratch merged 6 commits into
openai:mainfrom
sylvesterkaczmarek:fix/mcp-cleanup-active-servers

Conversation

@sylvesterkaczmarek

@sylvesterkaczmarek sylvesterkaczmarek commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

MCPServerManager.cleanup_all() removes servers from the internal connected set, but previously left active_servers unchanged. With the default drop_failed_servers=True, callers could therefore receive cleaned or disconnected servers from active_servers even though the manager documents that property as the successfully connected subset.

This change consistently derives the active list from the canonical connected-server set and refreshes it in a guaranteed cleanup finally path. A subsequent reconnect(failed_only=True) cannot reintroduce a cleaned server without reconnecting it, and propagated cleanup cancellation cannot leave disconnected servers advertised as active.

Regression coverage

Added focused tests covering:

  • successful cleanup followed by a failed-only reconnect and then connect_all();
  • cleanup cancellation with suppress_cancelled_error=False, verifying the cancellation propagates while active and connected state remain consistent.

Full repository tests were not run locally in this environment; CI should run the MCP test suite.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9ba5bdd0d4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/mcp/manager.py Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fb7978d967

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/mcp/manager.py Resolved
@seratch seratch added this to the 0.22.x milestone Aug 22, 2026
@seratch
seratch merged commit 3e67155 into openai:main Aug 22, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants