From b9797ec8865cd3163e3031c301693c3011d69bb3 Mon Sep 17 00:00:00 2001 From: Eric Allam Date: Mon, 17 Aug 2026 01:02:01 +0100 Subject: [PATCH] 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. --- packages/trigger-sdk/src/v3/ai.ts | 52 +++++++++++++++++++------------ 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/packages/trigger-sdk/src/v3/ai.ts b/packages/trigger-sdk/src/v3/ai.ts index 303344254..e10306681 100644 --- a/packages/trigger-sdk/src/v3/ai.ts +++ b/packages/trigger-sdk/src/v3/ai.ts @@ -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, }); } }