From fa6ff39b9b521aba7a449b393c95435910d84da3 Mon Sep 17 00:00:00 2001 From: Frank Yang Date: Fri, 13 Mar 2026 14:32:07 +0800 Subject: [PATCH] fix: recover outbound plugins from the active registry --- src/infra/outbound/channel-resolution.ts | 22 +++++++++++++++++++++- src/infra/outbound/targets.test.ts | 24 ++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/infra/outbound/channel-resolution.ts b/src/infra/outbound/channel-resolution.ts index 8d17294d024..041e8c60480 100644 --- a/src/infra/outbound/channel-resolution.ts +++ b/src/infra/outbound/channel-resolution.ts @@ -58,6 +58,22 @@ function maybeBootstrapChannelPlugin(params: { } } +function resolveDirectFromActiveRegistry( + channel: DeliverableMessageChannel, +): ChannelPlugin | undefined { + const activeRegistry = getActivePluginRegistry(); + if (!activeRegistry) { + return undefined; + } + for (const entry of activeRegistry.channels) { + const plugin = entry?.plugin; + if (plugin?.id === channel) { + return plugin; + } + } + return undefined; +} + export function resolveOutboundChannelPlugin(params: { channel: string; cfg?: OpenClawConfig; @@ -72,7 +88,11 @@ export function resolveOutboundChannelPlugin(params: { if (current) { return current; } + const directCurrent = resolveDirectFromActiveRegistry(normalized); + if (directCurrent) { + return directCurrent; + } maybeBootstrapChannelPlugin({ channel: normalized, cfg: params.cfg }); - return resolve(); + return resolve() ?? resolveDirectFromActiveRegistry(normalized); } diff --git a/src/infra/outbound/targets.test.ts b/src/infra/outbound/targets.test.ts index 73f77aee8c1..6a8b50403b5 100644 --- a/src/infra/outbound/targets.test.ts +++ b/src/infra/outbound/targets.test.ts @@ -1,5 +1,8 @@ import { describe, expect, it } from "vitest"; +import { telegramOutbound } from "../../channels/plugins/outbound/telegram.js"; import type { OpenClawConfig } from "../../config/config.js"; +import { setActivePluginRegistry } from "../../plugins/runtime.js"; +import { createOutboundTestPlugin, createTestRegistry } from "../../test-utils/channel-plugins.js"; import { resolveHeartbeatDeliveryTarget, resolveOutboundTarget, @@ -64,6 +67,27 @@ describe("resolveOutboundTarget defaultTo config fallback", () => { }); expect(res.ok).toBe(false); }); + + it("falls back to the active registry when the cached channel map is stale", () => { + const registry = createTestRegistry([]); + setActivePluginRegistry(registry, "stale-registry-test"); + + // Warm the cached channel map before mutating the registry in place. + expect(resolveOutboundTarget({ channel: "telegram", to: "123", mode: "explicit" }).ok).toBe( + false, + ); + + registry.channels.push({ + pluginId: "telegram", + plugin: createOutboundTestPlugin({ id: "telegram", outbound: telegramOutbound }), + source: "test", + }); + + expect(resolveOutboundTarget({ channel: "telegram", to: "123", mode: "explicit" })).toEqual({ + ok: true, + to: "123", + }); + }); }); describe("resolveSessionDeliveryTarget", () => {