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]
### 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.5] - 2026-04-16

View File

@@ -571,23 +571,28 @@ async function finalizeExecutedToolCall(
let isError = executed.isError;
if (config.afterToolCall) {
const afterResult = await config.afterToolCall(
{
assistantMessage,
toolCall: prepared.toolCall,
args: prepared.args,
result,
isError,
context: currentContext,
},
signal,
);
if (afterResult) {
result = {
content: afterResult.content ?? result.content,
details: afterResult.details ?? result.details,
};
isError = afterResult.isError ?? isError;
try {
const afterResult = await config.afterToolCall(
{
assistantMessage,
toolCall: prepared.toolCall,
args: prepared.args,
result,
isError,
context: currentContext,
},
signal,
);
if (afterResult) {
result = {
content: afterResult.content ?? result.content,
details: afterResult.details ?? result.details,
};
isError = afterResult.isError ?? isError;
}
} catch (error) {
result = createErrorToolResult(error instanceof Error ? error.message : String(error));
isError = true;
}
}