fix: wrap compaction start notice onBlockReply in try/catch to prevent unhandled rejection

onAgentEvent is fired fire-and-forget (void ctx.params.onAgentEvent?.(...)
in pi-embedded-subscribe.handlers.compaction.ts), so any rejection from the
awaited onBlockReply call would escape unobserved.

Wrap the delivery in a try/catch that swallows the error and logs a warning
via params.logger, consistent with other non-critical notice delivery paths.
This commit is contained in:
zidongdesign 2026-03-08 14:06:01 +08:00 committed by Josh Lehman
parent 643eb31ea4
commit e7fd0a7b21
No known key found for this signature in database
GPG Key ID: D141B425AC7F876B

View File

@ -430,7 +430,15 @@ export async function runAgentTurnWithFallback(params: {
replyToCurrent: true,
isCompactionNotice: true,
});
await params.opts.onBlockReply(noticePayload);
try {
await params.opts.onBlockReply(noticePayload);
} catch (err) {
// Non-critical notice delivery failure should not
// bubble out of the fire-and-forget event handler.
logVerbose(
`compaction start notice delivery failed (non-fatal): ${String(err)}`,
);
}
}
}
const completed = evt.data?.completed === true;