fix(core): isolate tool hook outcomes (#38571)

This commit is contained in:
Kit Langton 2026-07-23 17:40:42 -04:00 committed by GitHub
commit e7ecee5df2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 40 additions and 37 deletions

View file

@ -365,7 +365,7 @@ describe("PluginV2", () => {
yield* ctx.tool
.hook("execute.after", (event) =>
Effect.sync(() => {
if (event.status === "completed") event.content = [] as never
if (event.status === "completed") (event.content as unknown as unknown[]).splice(0)
}),
)
.pipe(Effect.asVoid)

View file

@ -118,9 +118,7 @@ test("provider-executed success derives content and retains provider result stat
test("interrupted progress metadata remains in the terminal failure snapshot", async () => {
const { published, publisher } = capture("anthropic", { interruptProgress: true })
await Effect.runPromise(publisher.publish(call))
const exit = await Effect.runPromiseExit(
publisher.progress(call.id, { phase: "visible" }),
)
const exit = await Effect.runPromiseExit(publisher.progress(call.id, { phase: "visible" }))
expect(Exit.isFailure(exit) && Cause.hasInterruptsOnly(exit.cause)).toBe(true)
await Effect.runPromise(publisher.failUnsettledTools({ type: "aborted", message: "interrupted" }))
@ -129,6 +127,18 @@ test("interrupted progress metadata remains in the terminal failure snapshot", a
})
})
test("failure snapshot retains canonical progress above the default byte limit", async () => {
const { published, publisher } = capture("anthropic", { interruptProgress: true })
await Effect.runPromise(publisher.publish(call))
const detail = "x".repeat(60 * 1024)
await Effect.runPromiseExit(publisher.progress(call.id, { detail }))
await Effect.runPromise(publisher.failUnsettledTools({ type: "aborted", message: "interrupted" }))
expect(published.find((event) => event.type === "session.tool.failed.2")?.data).toMatchObject({
metadata: { detail },
})
})
test("failure before progress omits partial output fields", async () => {
const { published, publisher } = capture()
await Effect.runPromise(publisher.publish(call))