fix(core): stop running tools from keeping the request hook event alive (#59098)

This commit is contained in:
Luke Parker
2026-10-26 09:37:07 +10:00
committed by GitHub
Unverified
parent d1cf7dd04a
commit 91b5a7c25d
+26 -14
View File
@@ -229,20 +229,32 @@ const layer = Layer.effect(
initial: loaded.initial,
messages: loaded.messages,
})
const prepared = yield* context.request.primary({
session: loaded.session,
agent: loaded.agent.id,
model: loaded.model,
tools: loaded.tools,
system: transcript.system,
messages: stepLimitReached
? [...transcript.messages, Message.assistant(MAX_STEPS_PROMPT)]
: transcript.messages,
// Keep tool definitions on the final Step to preserve the provider's cached prefix.
toolChoice: stepLimitReached ? "none" : undefined,
webSocket: "session",
inputTokens: SessionCompaction.estimatePrompt(loaded),
})
const prepared = yield* context.request
.primary({
session: loaded.session,
agent: loaded.agent.id,
model: loaded.model,
tools: loaded.tools,
system: transcript.system,
messages: stepLimitReached
? [...transcript.messages, Message.assistant(MAX_STEPS_PROMPT)]
: transcript.messages,
// Keep tool definitions on the final Step to preserve the provider's cached prefix.
toolChoice: stepLimitReached ? "none" : undefined,
webSocket: "session",
inputTokens: SessionCompaction.estimatePrompt(loaded),
})
.pipe(
// The hook event holds every message from before images are bounded, screenshots included, and is a separate
// copy once a plugin hook has rewritten it. The step and its tool callbacks live as long as the slowest tool,
// so they keep only what they use.
Effect.map((prepared) => ({
request: prepared.request,
options: prepared.options,
retry: prepared.retry,
executeTool: prepared.executeTool,
})),
)
const outcome = yield* steps.attempt({
isLocationClosed: lifecycle.isClosed,
sessionID,