fix(hooks): preserve observers after inbound claim

This commit is contained in:
Vincent Koc 2026-03-13 14:10:43 -07:00
parent 99759acc98
commit ad1fedd6ba
1 changed files with 8 additions and 5 deletions

View File

@ -186,6 +186,7 @@ export async function dispatchReplyFromConfig(params: {
const hookContext = deriveInboundMessageHookContext(ctx, { messageId: messageIdForHook });
const { isGroup, groupId } = hookContext;
let pluginClaimedInbound = false;
if (hookRunner?.hasHooks("inbound_claim")) {
const inboundClaim = await hookRunner.runInboundClaim(
toPluginInboundClaimEvent(hookContext, {
@ -195,11 +196,7 @@ export async function dispatchReplyFromConfig(params: {
}),
toPluginInboundClaimContext(hookContext),
);
if (inboundClaim?.handled) {
markIdle("plugin_claim");
recordProcessed("completed", { reason: "plugin-claimed" });
return { queuedFinal: false, counts: dispatcher.getQueuedCounts() };
}
pluginClaimedInbound = inboundClaim?.handled === true;
}
// Trigger plugin hooks (fire-and-forget)
@ -226,6 +223,12 @@ export async function dispatchReplyFromConfig(params: {
);
}
if (pluginClaimedInbound) {
markIdle("plugin_claim");
recordProcessed("completed", { reason: "plugin-claimed" });
return { queuedFinal: false, counts: dispatcher.getQueuedCounts() };
}
// Check if we should route replies to originating channel instead of dispatcher.
// Only route when the originating channel is DIFFERENT from the current surface.
// This handles cross-provider routing (e.g., message from Telegram being processed