diff --git a/src/auto-reply/reply/session-delivery.ts b/src/auto-reply/reply/session-delivery.ts index 9a112a6829e..e69c3c7267f 100644 --- a/src/auto-reply/reply/session-delivery.ts +++ b/src/auto-reply/reply/session-delivery.ts @@ -117,6 +117,14 @@ export function resolveLastChannelRaw(params: { resolved = sessionKeyChannelHint; } } + // Fix #34308: When channel is INTERNAL but session has a persisted external channel + // (deliveryContext), use the persisted channel for reply delivery. + if ( + originatingChannel === INTERNAL_MESSAGE_CHANNEL && + isExternalRoutingChannel(persistedChannel) + ) { + resolved = persistedChannel; + } return resolved; } @@ -151,6 +159,15 @@ export function resolveLastToRaw(params: { } } + // Fix #34308: When channel is INTERNAL but session has a persisted external channel + // (deliveryContext), use the persisted to address for reply delivery. + if ( + originatingChannel === INTERNAL_MESSAGE_CHANNEL && + isExternalRoutingChannel(persistedChannel) + ) { + return params.persistedLastTo; + } + return params.originatingToRaw || params.toRaw || params.persistedLastTo; }