fix(core): stop interrupting Claude Agent tool calls when instructions or tools change (#63033)

This commit is contained in:
Dan Smolsky
2026-11-10 00:41:04 -05:00
committed by GitHub
Unverified
parent 3d5ac2dce5
commit 993a280887
2 changed files with 32 additions and 2 deletions
@@ -255,6 +255,14 @@ export function registry() {
}
if (part.type !== "tool_use") continue
const name = ToolNames.original(part.name, request.tools)
if (!name && part.name.startsWith(ToolNames.PREFIX)) {
// A tool removed after this process started is still on its tool server; answer here so the turn goes on.
live.pending.expect(part.id, part.name)
live.pending.resolve(part.id, {
mcp: { isError: true, content: [{ type: "text", text: "This tool is no longer available." }] },
replacement: undefined,
})
}
if (!name) continue
live.pending.expect(part.id, part.name)
waiting.push(part.id)
@@ -372,8 +380,11 @@ export function registry() {
const prepare = Effect.fn("ClaudeSessions.prepare")(function* (entry: Entry, request: Request) {
// Retire an exited or incompatible process first: once we continue its parked turn, open() must not replace it.
// A launch change waits for a parked turn to end: stopping it makes Claude Code record the waiting tool calls as
// refused by the user. A step without tools (the step limit) still stops it, since the old process offers them.
if (entry.process) {
const needsRestart = entry.process.session.ended || entry.process.launch !== launch(request)
const parked = entry.process.waiting && entry.process.session.running && request.tools.length > 0
const needsRestart = entry.process.session.ended || (entry.process.launch !== launch(request) && !parked)
if (needsRestart) yield* stop(entry)
}
@@ -416,7 +427,8 @@ export function registry() {
}
if (collected.aborted) {
// A stopped OpenCode turn needs a fresh Claude turn; addUser would only steer the old one.
yield* interrupt(entry)
// After a launch change it also needs a new process.
yield* live.launch === launch(request) ? interrupt(entry) : stop(entry)
return { start, continuation: undefined }
}
return { start, continuation }
@@ -342,6 +342,24 @@ describe("Claude tool steps", () => {
}),
)
it.effect("a tool list change lets the parked turn finish and answers calls to removed tools", () =>
Effect.gen(function* () {
const claude = FakeClaude.make(FakeClaude.replay("tools"))
const test = yield* TestSessions.start(claude)
const prompt = TestTools.prompt()
TestTools.append(prompt, yield* TestTools.step(test.model, prompt), TestTools.output)
const remaining = TestTools.tools.filter((tool) => tool.name !== "confirm")
yield* TestTools.step(test.model, prompt, remaining)
const last = claude.runs[0]!.received.findLast((message) => message.response?.response?.mcp_response)
expect(last.response.response.mcp_response.result).toEqual({
isError: true,
content: [{ type: "text", text: "This tool is no longer available." }],
})
yield* test.registry.close()
claude.check()
}),
)
it.effect("an unavailable OpenCode server fails closed", () =>
Effect.gen(function* () {
const turn = FakeClaude.expectTurn()