fix(sdk): guard success-path channel reaction callbacks so a throw can't fail a delivered turn

The turn-start 'working' resolver and the success-path 'done' resolver both
awaited user-supplied reactions.working / reactions.done callbacks unguarded. A
rejection propagated into the turn catch, which then posted an error to the
channel and skipped onTurnComplete / the snapshot write, turning an
already-delivered answer into a reported failure. Wrapped both in try/catch that
degrade to a warn, matching the error-path reaction handling.
This commit is contained in:
Eric Allam
2026-08-17 01:02:01 +01:00
parent 7ddc72d5d2
commit b9797ec886
+32 -20
View File
@@ -7083,13 +7083,19 @@ function chatAgent<
}
}
}
channelWorkingReaction = await resolveReactionChoice(
channelConn.reactions?.working,
wireChannelEvent.event
);
if (channelWorkingReaction) {
await applyChannelReaction(channelConn, wireChannelEvent, {
name: channelWorkingReaction,
try {
channelWorkingReaction = await resolveReactionChoice(
channelConn.reactions?.working,
wireChannelEvent.event
);
if (channelWorkingReaction) {
await applyChannelReaction(channelConn, wireChannelEvent, {
name: channelWorkingReaction,
});
}
} catch (reactionError) {
logger.warn("chat.agent: channel working reaction failed", {
error: reactionError,
});
}
}
@@ -8406,19 +8412,25 @@ function chatAgent<
// Lifecycle reaction: turn done. Remove "working", mark "done".
if (wireChannelEvent && channelConn?.react) {
if (channelWorkingReaction) {
await applyChannelReaction(channelConn, wireChannelEvent, {
name: channelWorkingReaction,
remove: true,
});
}
const doneReaction = await resolveReactionChoice(
channelConn.reactions?.done,
wireChannelEvent.event
);
if (doneReaction) {
await applyChannelReaction(channelConn, wireChannelEvent, {
name: doneReaction,
try {
if (channelWorkingReaction) {
await applyChannelReaction(channelConn, wireChannelEvent, {
name: channelWorkingReaction,
remove: true,
});
}
const doneReaction = await resolveReactionChoice(
channelConn.reactions?.done,
wireChannelEvent.event
);
if (doneReaction) {
await applyChannelReaction(channelConn, wireChannelEvent, {
name: doneReaction,
});
}
} catch (reactionError) {
logger.warn("chat.agent: channel done reaction failed", {
error: reactionError,
});
}
}