Skip to content

fix(mcp): scope error teardown to the erroring session; serialize ref… - #3468

Open
joestump-agent wants to merge 1 commit into
charmbracelet:mainfrom
joestump-agent:upstream-pr/mcp-error-teardown-scope
Open

fix(mcp): scope error teardown to the erroring session; serialize ref…#3468
joestump-agent wants to merge 1 commit into
charmbracelet:mainfrom
joestump-agent:upstream-pr/mcp-error-teardown-scope

Conversation

@joestump-agent

Copy link
Copy Markdown
Contributor

…reshers

A StateError transition closed and deregistered whatever session was currently in the sessions map. When the error was reported by a stale path — a refresh whose list call failed after a renewal had already swapped in a fresh session — the teardown killed the healthy replacement and wiped its tool/prompt/resource registrations, leaving the server 'connected' with no capabilities until the next renewal.

updateState now closes exactly the session the error was reported against: if the registry holds a different (newer) session, it and its registrations are left alone. Error transitions with no specific session (connect failures) keep the old tear-everything behavior. The published state never carries a dead session pointer.

RefreshTools/RefreshPrompts/RefreshResources now run under the same per-server renew lock as session renewal, so the registered session cannot be swapped between their Get and their state update, and they report failures against the exact session that failed.

  • I have read CONTRIBUTING.md.
  • I have created a discussion that was approved by a maintainer (for new features).

@charmcli

charmcli commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@joestump-agent

Copy link
Copy Markdown
Contributor Author

recheck

@joestump-agent

Copy link
Copy Markdown
Contributor Author

I have read the Contributor License Agreement (CLA) and hereby sign the CLA.

@joestump-agent
joestump-agent force-pushed the upstream-pr/mcp-error-teardown-scope branch from 69f5d27 to e7bf77b Compare August 16, 2026 07:08
…reshers

A StateError transition closed and deregistered whatever session was
currently in the sessions map. When the error was reported by a stale
path — a refresh whose list call failed after a renewal had already
swapped in a fresh session — the teardown killed the healthy
replacement and wiped its tool/prompt/resource registrations, leaving
the server 'connected' with no capabilities until the next renewal.

updateState now closes exactly the session the error was reported
against: if the registry holds a different (newer) session, it and its
registrations are left alone. Error transitions with no specific
session (connect failures) keep the old tear-everything behavior. The
published state never carries a dead session pointer.

RefreshTools/RefreshPrompts/RefreshResources now run under the same
per-server renew lock as session renewal, so the registered session
cannot be swapped between their Get and their state update, and they
report failures against the exact session that failed.

Co-authored-by: Joe Stump <joe@stu.mp>
@joestump-agent
joestump-agent force-pushed the upstream-pr/mcp-error-teardown-scope branch from e7bf77b to 5e2e561 Compare August 16, 2026 07:12
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