fix tool execute after hook boundary

This commit is contained in:
Enoch
2026-05-07 20:45:27 +08:00
committed by YeonGyu-Kim
parent ad10450b5c
commit d11613999a
2 changed files with 35 additions and 2 deletions
+25 -1
View File
@@ -92,7 +92,6 @@ describe("createToolExecuteAfterHandler", () => {
expect(output.title).toBe("stored title")
expect(output.metadata).toEqual({ sessionId: "ses_native", agent: "hephaestus" })
})
it("#given native session linkage without model #when stored metadata exists #then required task metadata is preserved", async () => {
// given
const model = { providerID: "openai", modelID: "gpt-5.5" }
@@ -122,4 +121,29 @@ describe("createToolExecuteAfterHandler", () => {
expect(output.title).toBe("stored title")
expect(output.metadata).toEqual({ sessionId: "ses_native", agent: "hephaestus", model })
})
it("#given a non-extract hook throws #when tool.execute.after runs #then the handler absorbs the failure", async () => {
// given
const handler = createToolExecuteAfterHandler({
ctx: { directory: "/repo" } as never,
hooks: {
directoryAgentsInjector: {
"tool.execute.after": async () => {
throw new TypeError("output output is undefined")
},
},
} as never,
})
const output = { title: "result", output: "read output", metadata: {} }
// when
await handler(
{ tool: "read", sessionID: "ses_parent", callID: "call_read" },
output
)
// then
expect(output).toEqual({ title: "result", output: "read output", metadata: {} })
})
})
+10 -1
View File
@@ -182,6 +182,15 @@ export function createToolExecuteAfterHandler(args: {
return
}
await runToolExecuteAfterHooks()
try {
await runToolExecuteAfterHooks()
} catch (error) {
log("[tool-execute-after] Failed to process hooks", {
tool: input.tool,
sessionID: input.sessionID,
callID: input.callID ?? input.callId ?? input.call_id,
error,
})
}
}
}