fix(agent): guard afterToolCall hook errors in finalization

closes #3084
This commit is contained in:
Mario Zechner
2026-04-16 23:51:26 +02:00
parent b789900570
commit b9cd557d1d
2 changed files with 26 additions and 17 deletions

View File

@@ -2,6 +2,10 @@
## [Unreleased] ## [Unreleased]
### Fixed
- Fixed parallel tool-call finalization to convert `afterToolCall` hook throws into error tool results instead of aborting the batch ([#3084](https://github.com/badlogic/pi-mono/issues/3084))
## [0.67.6] - 2026-04-16 ## [0.67.6] - 2026-04-16
## [0.67.5] - 2026-04-16 ## [0.67.5] - 2026-04-16

View File

@@ -571,6 +571,7 @@ async function finalizeExecutedToolCall(
let isError = executed.isError; let isError = executed.isError;
if (config.afterToolCall) { if (config.afterToolCall) {
try {
const afterResult = await config.afterToolCall( const afterResult = await config.afterToolCall(
{ {
assistantMessage, assistantMessage,
@@ -589,6 +590,10 @@ async function finalizeExecutedToolCall(
}; };
isError = afterResult.isError ?? isError; isError = afterResult.isError ?? isError;
} }
} catch (error) {
result = createErrorToolResult(error instanceof Error ? error.message : String(error));
isError = true;
}
} }
return await emitToolCallOutcome(prepared.toolCall, result, isError, emit); return await emitToolCallOutcome(prepared.toolCall, result, isError, emit);