fix(core): cap the MCP startup wait before a model call at two seconds (#62386)

Co-authored-by: exe.dev user <exedev@anton.exe.xyz>
This commit is contained in:
Aiden Cline
2026-11-06 10:58:53 -06:00
committed by GitHub
Unverified
parent 9cc63ddd2e
commit 5de6a1399d
2 changed files with 6 additions and 37 deletions
+3 -8
View File
@@ -117,8 +117,7 @@ type AttachedEntry = {
tools: ReadonlyArray<Tool>
}
// How long a model call may wait for a server that is still connecting and configures no `timeout.startup`,
// counted from when it began. A server with a startup timeout gets that window instead.
// How long a model call may wait for a server that is still connecting, counted from when it began.
const STARTUP_GRACE_MS = 2_000
// Bounds re-listing the tools of an attached connection that takes over the top of its stack.
@@ -161,8 +160,7 @@ export interface Interface extends State.Transformable<Editor> {
readonly tools: () => Effect.Effect<Tool[]>
/**
* Waits for servers that are still connecting, each until it settles or until its startup grace
* window ends: `timeout.startup` when the server configures one, else `STARTUP_GRACE_MS`. Servers
* past their window never wait.
* window ends. Servers past their window never wait.
*/
readonly awaitStartup: () => Effect.Effect<void>
readonly callTool: (input: {
@@ -804,10 +802,7 @@ export const layer = (options?: Options) =>
yield* Effect.all(
Array.from(entries.values()).flatMap((entry) => {
if (entry.status.status !== "pending" || !entry.attempt) return []
// A configured startup timeout is the window the connection itself is allowed, so wait as long
// as the caller asked for rather than dropping a server that is still mid-handshake.
const grace = entry.config.timeout?.startup ?? STARTUP_GRACE_MS
const remaining = entry.attempt.started + grace - now
const remaining = entry.attempt.started + STARTUP_GRACE_MS - now
return remaining > 0 ? [entry.attempt.settled.await.pipe(Effect.raceFirst(Effect.sleep(remaining)))] : []
}),
{ concurrency: "unbounded", discard: true },
+3 -29
View File
@@ -2745,13 +2745,9 @@ const gatedServer = Effect.gen(function* () {
})
// The real Mcp layer behind the tool registry; the bus never delivers, so only flush can register tools.
const startupRegistry = (url: string, timeout?: ConfigMCP.Timeout) =>
const startupRegistry = (url: string) =>
AppNodeBuilder.build(LayerNode.group([Mcp.node, Tool.node, McpTool.node]), [
Mcp.node.replace(
resourceMcpLayer(
new ConfigMCP.Remote({ type: "remote", url, oauth: false, codemode: false, ...(timeout ? { timeout } : {}) }),
),
),
Mcp.node.replace(resourceMcpLayer(new ConfigMCP.Remote({ type: "remote", url, oauth: false, codemode: false }))),
Permission.node.replace(permissions),
Bus.node.replace(events),
Image.node.replace(imagePassthrough),
@@ -2779,7 +2775,7 @@ testEffect(Layer.empty).effect("flush waits for a server that connects within it
}),
)
testEffect(Layer.empty).effect("flush stops waiting for a hung server when the default startup window ends", () =>
testEffect(Layer.empty).effect("flush stops waiting for a hung server when its startup window ends", () =>
Effect.gen(function* () {
const gated = yield* gatedServer
yield* Effect.gen(function* () {
@@ -2803,28 +2799,6 @@ testEffect(Layer.empty).effect("flush stops waiting for a hung server when the d
}),
)
testEffect(Layer.empty).effect("flush waits as long as a server's own startup timeout", () =>
Effect.gen(function* () {
const gated = yield* gatedServer
yield* Effect.gen(function* () {
const registry = yield* Tool.Service
const registration = yield* McpTool.Service
yield* Deferred.await(gated.started)
const flush = yield* registration.flush.pipe(Effect.forkChild({ startImmediately: true }))
// Well past the default window, which would have dropped a server that is still handshaking.
yield* TestClock.adjust("3500 millis")
expect(flush.pollUnsafe()).toBeUndefined()
yield* Deferred.succeed(gated.release, undefined)
yield* Fiber.join(flush)
expect((yield* toolDefinitions(registry)).map((tool) => tool.name)).toContain("resources_echo")
}).pipe(
Effect.ensuring(Deferred.succeed(gated.release, undefined)),
Effect.provide(startupRegistry(gated.server.url, new ConfigMCP.Timeout({ startup: 10_000 }))),
)
}),
)
it.effect("advertises MCP output schemas to Code Mode", () =>
Effect.gen(function* () {
const registry = yield* Tool.Service