Skip to content

Commit 07c6c70

Browse files
committed
fix(telegram): resolve native command names from the loaded registry only
Telegram's native-command registration resolved provider names through getChannelPlugin's bundled fallback. With no loaded registry entry (tests, dev tools), that fallback jiti-loads the entire Telegram plugin plus core graph from TypeScript source (~190s CPU, silent), which tripped the 300s no-output CI watchdog on the two test files that register at module scope. Telegram defines no resolveNativeCommandName hook, so the load resolved nothing. Thread the existing includeBundledChannelFallback option through listNativeCommandSpecs/listNativeCommandSpecsForConfig and use loaded-registry-only lookups in the Telegram plugin, matching the Discord sibling fix.
1 parent b694ee1 commit 07c6c70

4 files changed

Lines changed: 68 additions & 22 deletions

File tree

‎extensions/telegram/src/bot-native-command-builtins.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,11 @@ export async function executeTelegramBuiltinCommand(
253253
if (!dispatch) {
254254
return false;
255255
}
256-
const commandDefinition = findCommandByNativeName(params.commandName, "telegram");
256+
// Loaded-registry lookup only: Telegram defines no resolveNativeCommandName
257+
// hook, and the bundled fallback would jiti-load the plugin source in dev/test.
258+
const commandDefinition = findCommandByNativeName(params.commandName, "telegram", {
259+
includeBundledChannelFallback: false,
260+
});
257261
const commandArgs = commandDefinition
258262
? parseCommandArgs(commandDefinition, params.rawText)
259263
: params.rawText

‎extensions/telegram/src/bot-native-commands.test.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ describe("registerTelegramNativeCommands", () => {
184184
const native = listNativeCommandSpecsForConfig(cfg, {
185185
skillCommands,
186186
provider: "telegram",
187+
includeBundledChannelFallback: false,
187188
}).map((command) => ({
188189
command: normalizeTelegramCommandName(command.name),
189190
description: command.description,
@@ -239,7 +240,11 @@ describe("registerTelegramNativeCommands", () => {
239240
"Telegram menu pressure omitted per-skill commands; removing per-skill commands and keeping /skill.",
240241
);
241242
const expectedTotalCommands =
242-
customCommands.length + listNativeCommandSpecsForConfig(cfg, { provider: "telegram" }).length;
243+
customCommands.length +
244+
listNativeCommandSpecsForConfig(cfg, {
245+
provider: "telegram",
246+
includeBundledChannelFallback: false,
247+
}).length;
243248
expect(runtimeLog).toHaveBeenCalledWith(
244249
`Telegram limits bots to 100 commands. ${expectedTotalCommands} configured; registering first 100. Use channels.telegram.commands.native: false to disable, or reduce plugin/skill/custom commands.`,
245250
);

‎extensions/telegram/src/bot-native-commands.ts‎

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,19 @@ export const registerTelegramNativeCommands = ({
104104
: [];
105105
const pluginCommandRuntime = createPluginCommandRuntime();
106106
const pluginCommandSpecs = pluginCommandRuntime.listNativeCandidates("telegram");
107+
// Telegram is the channel here: resolve native names from the loaded registry
108+
// only. The bundled fallback would jiti-load this whole plugin from source in
109+
// dev/test checkouts (minutes of transpile) to call a hook Telegram never defines.
107110
const nativeCommands = nativeEnabled
108-
? listNativeCommandSpecsForConfig(cfg, { skillCommands, provider: "telegram" })
111+
? listNativeCommandSpecsForConfig(cfg, {
112+
skillCommands,
113+
provider: "telegram",
114+
includeBundledChannelFallback: false,
115+
})
109116
: [];
110117
const reservedCommands = new Set(
111-
listNativeCommandSpecs({ provider: "telegram" }).map((command) =>
112-
normalizeTelegramCommandName(command.name),
118+
listNativeCommandSpecs({ provider: "telegram", includeBundledChannelFallback: false }).map(
119+
(command) => normalizeTelegramCommandName(command.name),
113120
),
114121
);
115122
for (const command of skillCommands) {
@@ -131,7 +138,10 @@ export const registerTelegramNativeCommands = ({
131138
runtime.error?.(danger(issue));
132139
}
133140
const firstSkillCommandIndex = nativeEnabled
134-
? listNativeCommandSpecsForConfig(cfg, { provider: "telegram" }).length
141+
? listNativeCommandSpecsForConfig(cfg, {
142+
provider: "telegram",
143+
includeBundledChannelFallback: false,
144+
}).length
135145
: 0;
136146
const nativeMenuCommands = nativeCommands
137147
.map((command, index): TelegramMenuCommand | null => {
@@ -171,8 +181,13 @@ export const registerTelegramNativeCommands = ({
171181
"Telegram menu pressure omitted per-skill commands; removing per-skill commands and keeping /skill.",
172182
);
173183
}
174-
const loginCommand = listNativeCommandSpecsForConfig(cfg, { provider: "telegram" }).find(
175-
(command) => findCommandByNativeName(command.name, "telegram")?.key === "login",
184+
const loginCommand = listNativeCommandSpecsForConfig(cfg, {
185+
provider: "telegram",
186+
includeBundledChannelFallback: false,
187+
}).find(
188+
(command) =>
189+
findCommandByNativeName(command.name, "telegram", { includeBundledChannelFallback: false })
190+
?.key === "login",
176191
);
177192
const nativeCommandsToHandle = nativeEnabled
178193
? nativeCommands
@@ -264,7 +279,10 @@ export const registerTelegramNativeCommands = ({
264279
);
265280
});
266281
}
267-
if (findCommandByNativeName(command.name, "telegram")?.key === "login") {
282+
if (
283+
findCommandByNativeName(command.name, "telegram", { includeBundledChannelFallback: false })
284+
?.key === "login"
285+
) {
268286
handleLoginCallback = handleNativeCommand;
269287
}
270288
}
@@ -300,7 +318,7 @@ export const registerTelegramNativeCommands = ({
300318
.split("@", 1)[0]
301319
?.toLowerCase();
302320
const commandDefinition = commandName
303-
? findCommandByNativeName(commandName, "telegram")
321+
? findCommandByNativeName(commandName, "telegram", { includeBundledChannelFallback: false })
304322
: undefined;
305323
if (commandDefinition?.key !== "login") {
306324
return { handled: false, clearButtons: false };

‎src/auto-reply/commands-registry.ts‎

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,13 @@ function resolveNativeName(
7979
);
8080
}
8181

82-
function toNativeCommandSpec(command: ChatCommandDefinition, provider?: string): NativeCommandSpec {
82+
function toNativeCommandSpec(
83+
command: ChatCommandDefinition,
84+
provider?: string,
85+
options?: NativeCommandProviderLookupOptions,
86+
): NativeCommandSpec {
8387
const spec: NativeCommandSpec = {
84-
name: resolveNativeName(command, provider) ?? command.key,
88+
name: resolveNativeName(command, provider, options) ?? command.key,
8589
description: command.description,
8690
acceptsArgs: Boolean(command.acceptsArgs),
8791
args: command.args,
@@ -92,8 +96,12 @@ function toNativeCommandSpec(command: ChatCommandDefinition, provider?: string):
9296
return spec;
9397
}
9498

95-
function resolveNativeNames(command: ChatCommandDefinition, provider?: string): string[] {
96-
const primary = resolveNativeName(command, provider);
99+
function resolveNativeNames(
100+
command: ChatCommandDefinition,
101+
provider?: string,
102+
options?: NativeCommandProviderLookupOptions,
103+
): string[] {
104+
const primary = resolveNativeName(command, provider, options);
97105
return [primary, ...(command.nativeAliases ?? [])].filter((name): name is string =>
98106
Boolean(name),
99107
);
@@ -115,15 +123,16 @@ function supportsNativeProvider(command: ChatCommandDefinition, provider?: strin
115123
function listNativeSpecsFromCommands(
116124
commands: ChatCommandDefinition[],
117125
provider?: string,
126+
options?: NativeCommandProviderLookupOptions,
118127
): NativeCommandSpec[] {
119128
return commands
120129
.filter(
121130
(command) =>
122131
command.scope !== "text" && command.nativeName && supportsNativeProvider(command, provider),
123132
)
124133
.flatMap((command) => {
125-
const spec = toNativeCommandSpec(command, provider);
126-
return resolveNativeNames(command, provider).map((name, index) => {
134+
const spec = toNativeCommandSpec(command, provider, options);
135+
return resolveNativeNames(command, provider, options).map((name, index) => {
127136
const nativeSpec: NativeCommandSpec = {
128137
name,
129138
description: spec.description,
@@ -145,22 +154,32 @@ function listNativeSpecsFromCommands(
145154
}
146155

147156
/** Lists native command specs registered for a provider, including skill commands. */
148-
export function listNativeCommandSpecs(params?: {
149-
skillCommands?: SkillCommandSpec[];
150-
provider?: string;
151-
}): NativeCommandSpec[] {
157+
export function listNativeCommandSpecs(
158+
params?: {
159+
skillCommands?: SkillCommandSpec[];
160+
provider?: string;
161+
} & NativeCommandProviderLookupOptions,
162+
): NativeCommandSpec[] {
152163
return listNativeSpecsFromCommands(
153164
listChatCommands({ skillCommands: params?.skillCommands }),
154165
params?.provider,
166+
params,
155167
);
156168
}
157169

158170
/** Lists native command specs that are enabled for the provided config. */
159171
export function listNativeCommandSpecsForConfig(
160172
cfg: OpenClawConfig,
161-
params?: { skillCommands?: SkillCommandSpec[]; provider?: string },
173+
params?: {
174+
skillCommands?: SkillCommandSpec[];
175+
provider?: string;
176+
} & NativeCommandProviderLookupOptions,
162177
): NativeCommandSpec[] {
163-
return listNativeSpecsFromCommands(listChatCommandsForConfig(cfg, params), params?.provider);
178+
return listNativeSpecsFromCommands(
179+
listChatCommandsForConfig(cfg, params),
180+
params?.provider,
181+
params,
182+
);
164183
}
165184

166185
export function mergeNativeCommandSpecs(params: {

0 commit comments

Comments
 (0)