fix(core): share one tool snapshot per request (#38596)

This commit is contained in:
Kit Langton 2026-07-23 22:54:22 -04:00 committed by GitHub
commit 7456598cde
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 142 additions and 124 deletions

View file

@ -44,12 +44,13 @@ export interface Interface {
}
/**
* One request-scoped snapshot pairing advertised definitions with captured
* tools. A model request executes exactly the tool values it advertised
* even if registration changes while the request is in flight.
* One request-scoped snapshot pairing Code Mode instructions and advertised
* definitions with captured tools. A model request executes exactly the tool
* values it advertised even if registration changes while it is in flight.
*/
export interface ToolSet {
readonly definitions: ReadonlyArray<ToolDefinition>
readonly codeModeInstructions?: string
readonly execute: (input: ExecuteInput) => Effect.Effect<ToolOutcome, ToolOutputStore.Error>
}
@ -320,8 +321,12 @@ const registryLayer = Layer.effect(
if (whollyDisabled(registration.permission, rules)) continue
direct.set(name, registration)
}
const codemodeTool = (yield* codeMode.materialize(permissions)).tool
const codeModeMaterialization = yield* codeMode.materialize(permissions)
const codemodeTool = codeModeMaterialization.tool
return {
...(codeModeMaterialization.instructions === undefined
? {}
: { codeModeInstructions: codeModeMaterialization.instructions }),
definitions: [
// Definitions are prompt-cache prefix bytes, so order only after effective registrations settle.
...Array.from(direct)