fix(core): preserve admitted tool generations (#36177)

This commit is contained in:
Kit Langton 2026-07-09 21:16:00 -04:00 committed by GitHub
commit 3785eddfa0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 127 additions and 51 deletions

View file

@ -173,7 +173,7 @@ const layer = Layer.effect(
sessionID,
assistantMessageID: message.id,
callID: tool.id,
error: { type: "tool.stale", message: `Tool execution interrupted: ${tool.name}` },
error: { type: "aborted", message: `Tool execution interrupted: ${tool.name}` },
executed: tool.executed === true,
})
}
@ -466,9 +466,7 @@ const layer = Layer.effect(
// implementation becomes a failed tool call the model can read, and the step still
// settles so the model may recover. A typed infrastructure failure (tool output
// could not be persisted) also fails the assistant and then fails the drain.
const settledFailure = settledCauses.find(
(cause) => !Cause.hasInterrupts(cause) && !isUserDeclined(cause),
)
const settledFailure = settledCauses.find((cause) => !Cause.hasInterrupts(cause) && !isUserDeclined(cause))
const infraError =
settledFailure === undefined ? undefined : Option.getOrUndefined(Cause.findErrorOption(settledFailure))
if (settledFailure !== undefined) {

View file

@ -37,16 +37,12 @@ type CollectedFiles = {
}
export interface Registration {
readonly identity: object
readonly tool: AnyTool
readonly name: string
readonly group?: string
}
export const create = (options: {
readonly registrations: ReadonlyMap<string, Registration>
readonly current: (name: string) => Registration | undefined
}) => {
export const create = (options: { readonly registrations: ReadonlyMap<string, Registration> }) => {
const runtime = (
invoke: (name: string, registration: Registration, input: unknown) => Effect.Effect<unknown, unknown>,
hooks?: CodeMode.ToolCallHooks,
@ -115,11 +111,8 @@ export const create = (options: {
(name, registration, input) =>
Effect.gen(function* () {
const index = yield* Ref.getAndUpdate(callIndex, (index) => index + 1)
const current = options.current(name)
if (!current || current.identity !== registration.identity)
return yield* Effect.fail(toolError(`Stale tool call: ${name}`))
const output = yield* settle(
current.tool,
registration.tool,
{ type: "tool-call", id: context.toolCallID, name, input },
{
sessionID: context.sessionID,

View file

@ -58,7 +58,6 @@ const registryLayer = Layer.effect(
const resources = yield* ToolOutputStore.Service
const toolHooks = yield* ToolHooks.Service
type Registration = {
readonly identity: object
readonly tool: AnyTool
readonly name: string
readonly group?: string
@ -134,18 +133,6 @@ const registryLayer = Layer.effect(
}
})
const settleWith = Effect.fn("ToolRegistry.settle")(function* (input: ExecuteInput, advertised: object) {
const registration = local.get(input.call.name)?.at(-1)?.registration
if (!registration || registration.identity !== advertised) {
const message = `Stale tool call: ${input.call.name}`
return {
result: { type: "error" as const, value: message },
error: { type: "tool.stale" as const, message },
}
}
return yield* settleTool(input, registration.tool)
})
return Service.of({
register: Effect.fn("ToolRegistry.register")(function* (tools, options) {
const entries = registrationEntries(tools, options?.group)
@ -164,7 +151,6 @@ const registryLayer = Layer.effect(
{
token,
registration: {
identity: {},
tool: entry.tool,
name: entry.name,
group: entry.group,
@ -204,7 +190,6 @@ const registryLayer = Layer.effect(
deferred.size > 0 && !whollyDisabled("execute", input.permissions ?? [])
? ExecuteTool.create({
registrations: deferred,
current: (name) => local.get(name)?.at(-1)?.registration,
})
: undefined
return {
@ -215,7 +200,7 @@ const registryLayer = Layer.effect(
settle: (input) => {
if (input.call.name === "execute" && execute) return settleTool(input, execute)
const registration = direct.get(input.call.name)
if (registration) return settleWith(input, registration.identity)
if (registration) return settleTool(input, registration.tool)
return Effect.succeed({
result: { type: "error", value: `Unknown tool: ${input.call.name}` },
error: { type: "tool.unknown", message: `Unknown tool: ${input.call.name}` },