Skip to content

Commit fa6ff39

Browse files
committed
fix: recover outbound plugins from the active registry
1 parent 402f255 commit fa6ff39

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

src/infra/outbound/channel-resolution.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,22 @@ function maybeBootstrapChannelPlugin(params: {
5858
}
5959
}
6060

61+
function resolveDirectFromActiveRegistry(
62+
channel: DeliverableMessageChannel,
63+
): ChannelPlugin | undefined {
64+
const activeRegistry = getActivePluginRegistry();
65+
if (!activeRegistry) {
66+
return undefined;
67+
}
68+
for (const entry of activeRegistry.channels) {
69+
const plugin = entry?.plugin;
70+
if (plugin?.id === channel) {
71+
return plugin;
72+
}
73+
}
74+
return undefined;
75+
}
76+
6177
export function resolveOutboundChannelPlugin(params: {
6278
channel: string;
6379
cfg?: OpenClawConfig;
@@ -72,7 +88,11 @@ export function resolveOutboundChannelPlugin(params: {
7288
if (current) {
7389
return current;
7490
}
91+
const directCurrent = resolveDirectFromActiveRegistry(normalized);
92+
if (directCurrent) {
93+
return directCurrent;
94+
}
7595

7696
maybeBootstrapChannelPlugin({ channel: normalized, cfg: params.cfg });
77-
return resolve();
97+
return resolve() ?? resolveDirectFromActiveRegistry(normalized);
7898
}

src/infra/outbound/targets.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { describe, expect, it } from "vitest";
2+
import { telegramOutbound } from "../../channels/plugins/outbound/telegram.js";
23
import type { OpenClawConfig } from "../../config/config.js";
4+
import { setActivePluginRegistry } from "../../plugins/runtime.js";
5+
import { createOutboundTestPlugin, createTestRegistry } from "../../test-utils/channel-plugins.js";
36
import {
47
resolveHeartbeatDeliveryTarget,
58
resolveOutboundTarget,
@@ -64,6 +67,27 @@ describe("resolveOutboundTarget defaultTo config fallback", () => {
6467
});
6568
expect(res.ok).toBe(false);
6669
});
70+
71+
it("falls back to the active registry when the cached channel map is stale", () => {
72+
const registry = createTestRegistry([]);
73+
setActivePluginRegistry(registry, "stale-registry-test");
74+
75+
// Warm the cached channel map before mutating the registry in place.
76+
expect(resolveOutboundTarget({ channel: "telegram", to: "123", mode: "explicit" }).ok).toBe(
77+
false,
78+
);
79+
80+
registry.channels.push({
81+
pluginId: "telegram",
82+
plugin: createOutboundTestPlugin({ id: "telegram", outbound: telegramOutbound }),
83+
source: "test",
84+
});
85+
86+
expect(resolveOutboundTarget({ channel: "telegram", to: "123", mode: "explicit" })).toEqual({
87+
ok: true,
88+
to: "123",
89+
});
90+
});
6791
});
6892

6993
describe("resolveSessionDeliveryTarget", () => {

0 commit comments

Comments
 (0)