Skip to content

Commit d4ea16b

Browse files
Ralph Sto. Domingoclaude
andcommitted
fix(mcp): keep an older successful refresh when a newer one fails
Refreshes commit unless a newer one already has, so an out-of-order completion never overwrites newer tools, and a failed newer refresh no longer discards an older one that succeeded. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0172qrhMa5TQgETASi5hxMqD
1 parent cf571e2 commit d4ea16b

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎packages/opencode/src/mcp/index.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -758,22 +758,25 @@ export const layer = Layer.effect(
758758
)
759759

760760
if (!client.getServerCapabilities()?.tools) return
761-
// altimate_change start — overlapping refreshes: only the latest one commits.
761+
// altimate_change start — overlapping refreshes: an older one never overwrites a newer.
762762
let refreshes = 0
763+
let committed = 0
763764
// altimate_change end
764765
client.setNotificationHandler(ToolListChangedNotificationSchema, async () => {
765766
if (s.clients[name] !== client || s.status[name]?.status !== "connected") return
766767

767768
// altimate_change start — matches create(): McpCatalog.defsWithMeta() tolerates
768769
// annotation-null tools on a live tool-list refresh (#792) and hands back the
769-
// listing with its own `_meta`. A refresh that a later one overtook while it
770-
// awaited drops its listing, so an out-of-order completion never writes an
771-
// older tool set or report over a newer one. (bot review)
770+
// listing with its own `_meta`. A refresh commits unless a newer one already
771+
// has, so an out-of-order completion never writes an older tool set or report
772+
// over a newer one, and a newer refresh that fails does not discard an older
773+
// one that succeeded. (bot review)
772774
const refresh = ++refreshes
773775
const listing = await bridge.promise(McpCatalog.defsWithMeta(client, timeout))
774776
if (!listing) return
775777
if (s.clients[name] !== client || s.status[name]?.status !== "connected") return
776-
if (refresh !== refreshes) return
778+
if (refresh < committed) return
779+
committed = refresh
777780
// altimate_change end
778781

779782
// altimate_change start — tools and THEIR report land in one statement: the

0 commit comments

Comments
 (0)