Skip to content

Commit 296cd8c

Browse files
vincentkocsteipete
andauthored
fix(plugin-sdk): isolate provider catalog projection failures (#88767)
* fix(plugin-sdk): isolate provider catalog projection failures * fix(plugin-sdk): share safe provider catalog projection * fix(cron): preserve raw null clear schema * fix(plugin-sdk): copy provider catalog model rows safely * fix(plugin-sdk): keep id-only catalog models * fix(plugin-sdk): require readable provider catalog base url * fix(ci): satisfy cron and matrix lint checks --------- Co-authored-by: Peter Steinberger <[email protected]>
1 parent 3386bf9 commit 296cd8c

12 files changed

Lines changed: 607 additions & 42 deletions

‎extensions/matrix/src/matrix/monitor/auto-join.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,19 @@ export function registerMatrixAutoJoin(params: {
5858
);
5959
return resolved.filter((roomId): roomId is string => Boolean(roomId));
6060
};
61+
const runInviteTask = (roomId: string, task: () => Promise<void>) => {
62+
void Promise.resolve()
63+
.then(task)
64+
.catch((err: unknown) => {
65+
runtime.error?.(
66+
`matrix: auto-join invite handler failed for room ${roomId}: ${String(err)}`,
67+
);
68+
});
69+
};
6170

6271
// Handle invites directly so both "always" and "allowlist" modes share the same path.
6372
client.on("room.invite", (roomId: string, _inviteEvent: unknown) => {
64-
void (async () => {
73+
runInviteTask(roomId, async () => {
6574
if (autoJoin === "allowlist") {
6675
const allowedAliasRoomIds = await resolveAllowedAliasRoomIds();
6776
const allowed =
@@ -81,6 +90,6 @@ export function registerMatrixAutoJoin(params: {
8190
} catch (err) {
8291
runtime.error?.(`matrix: failed to join room ${roomId}: ${String(err)}`);
8392
}
84-
})();
93+
});
8594
});
8695
}

‎src/agents/tools/cron-tool.schema.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ describe("CronToolSchema", () => {
238238
| Record<string, { properties?: Record<string, { type?: unknown }> }>
239239
| undefined;
240240

241-
// Must be plain "array" — not ["array", "null"] — for provider compat.
241+
// Provider-facing schemas must be plain "array" rather than JSON Schema
242+
// unions so OpenAPI 3.0 subset validators accept them.
242243
expect(patchProps?.payload?.properties?.toolsAllow?.type).toBe("array");
243244
});
244245

@@ -248,7 +249,7 @@ describe("CronToolSchema", () => {
248249
const json = JSON.stringify(providerSchemaRecord);
249250
// type arrays like ["string","null"] are not valid in OpenAPI 3.0
250251
expect(json).not.toMatch(/"type"\s*:\s*\[/);
251-
// "not" composition keyword is not supported by OpenAPI 3.0
252+
// The "not" composition keyword is not supported by OpenAPI 3.0.
252253
expect(json).not.toMatch(/"not"\s*:\s*\{/);
253254
});
254255
});

‎src/agents/tools/cron-tool.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,21 +481,25 @@ describe("cron tool", () => {
481481
"string",
482482
"null",
483483
]);
484+
expect(patch?.properties?.agentId?.type).toBeUndefined();
484485
expect(patch?.properties?.agentId?.description).toContain("null to clear");
485486
expect(patch?.properties?.sessionKey?.anyOf?.map((entry) => entry.type)).toEqual([
486487
"string",
487488
"null",
488489
]);
490+
expect(patch?.properties?.sessionKey?.type).toBeUndefined();
489491
expect(patch?.properties?.sessionKey?.description).toContain("null to clear");
490492
expect(payload?.properties?.toolsAllow?.anyOf?.map((entry) => entry.type)).toEqual([
491493
"array",
492494
"null",
493495
]);
496+
expect(payload?.properties?.toolsAllow?.type).toBeUndefined();
494497
expect(payload?.properties?.toolsAllow?.description).toContain("null to clear");
495498
expect(delivery?.properties?.channel?.anyOf?.map((entry) => entry.type)).toEqual([
496499
"string",
497500
"null",
498501
]);
502+
expect(delivery?.properties?.channel?.type).toBeUndefined();
499503
expect(delivery?.properties?.channel?.description).toContain("null to clear");
500504
expect(delivery?.properties?.failureDestination?.anyOf?.map((entry) => entry.type)).toEqual([
501505
"object",

‎src/plugin-sdk/provider-entry.test.ts‎

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,139 @@ describe("defineSingleProviderPluginEntry", () => {
238238
});
239239
});
240240

241+
it("skips unreadable provider catalog entries while preserving healthy siblings", async () => {
242+
const providers = Object.defineProperty(
243+
{
244+
mockplugin: {
245+
api: "openai-completions" as const,
246+
baseUrl: "https://mockplugin.test/v1",
247+
models: [createModel("mock-model", "Mock Model")],
248+
},
249+
},
250+
"fuzzplugin",
251+
{
252+
enumerable: true,
253+
get() {
254+
throw new Error("fuzzplugin provider catalog entry read failed");
255+
},
256+
},
257+
);
258+
const entry = defineSingleProviderPluginEntry({
259+
id: "mockplugin",
260+
name: "Mock Provider",
261+
description: "Synthetic provider plugin",
262+
provider: {
263+
label: "Mock",
264+
docsPath: "/providers/mockplugin",
265+
catalog: {
266+
run: async () => ({ providers }),
267+
},
268+
},
269+
});
270+
271+
const { unifiedCatalog } = await captureProviderEntry({ entry });
272+
expect(unifiedCatalog).toEqual([
273+
{
274+
kind: "text",
275+
provider: "mockplugin",
276+
model: "mock-model",
277+
label: "Mock Model",
278+
source: "live",
279+
},
280+
]);
281+
});
282+
283+
it("skips unreadable provider catalog model rows while preserving healthy siblings", async () => {
284+
const models = Object.defineProperty([createModel("mock-model", "Mock Model")], "1", {
285+
enumerable: true,
286+
get() {
287+
throw new Error("fuzzplugin provider model row read failed");
288+
},
289+
});
290+
const entry = defineSingleProviderPluginEntry({
291+
id: "mockplugin",
292+
name: "Mock Provider",
293+
description: "Synthetic provider plugin",
294+
provider: {
295+
label: "Mock",
296+
docsPath: "/providers/mockplugin",
297+
catalog: {
298+
run: async () => ({
299+
providers: {
300+
mockplugin: {
301+
api: "openai-completions" as const,
302+
baseUrl: "https://mockplugin.test/v1",
303+
models,
304+
},
305+
},
306+
}),
307+
},
308+
},
309+
});
310+
311+
const { unifiedCatalog } = await captureProviderEntry({ entry });
312+
expect(unifiedCatalog).toEqual([
313+
{
314+
kind: "text",
315+
provider: "mockplugin",
316+
model: "mock-model",
317+
label: "Mock Model",
318+
source: "live",
319+
},
320+
]);
321+
});
322+
323+
it("skips unreadable provider auth option rows while preserving healthy entries", async () => {
324+
const unreadableAuth = Object.defineProperty(
325+
{
326+
methodId: "fuzz-api-key",
327+
label: "Fuzz API key",
328+
optionKey: "fuzzApiKey",
329+
flagName: "--fuzz-api-key" as const,
330+
envVar: "FUZZ_API_KEY",
331+
promptMessage: "Enter Fuzz API key",
332+
},
333+
"label",
334+
{
335+
enumerable: true,
336+
get() {
337+
throw new Error("fuzzplugin provider auth label read failed");
338+
},
339+
},
340+
);
341+
const entry = defineSingleProviderPluginEntry({
342+
id: "mockplugin",
343+
name: "Mock Provider",
344+
description: "Synthetic provider plugin",
345+
provider: {
346+
label: "Mock",
347+
docsPath: "/providers/mockplugin",
348+
auth: [
349+
unreadableAuth,
350+
{
351+
methodId: "mock-api-key",
352+
label: "Mock API key",
353+
optionKey: "mockApiKey",
354+
flagName: "--mock-api-key",
355+
envVar: "MOCK_API_KEY",
356+
promptMessage: "Enter Mock API key",
357+
},
358+
],
359+
catalog: {
360+
buildProvider: () => ({
361+
api: "openai-completions",
362+
baseUrl: "https://mockplugin.test/v1",
363+
models: [],
364+
}),
365+
},
366+
},
367+
});
368+
369+
const { provider } = await captureProviderEntry({ entry });
370+
expect(provider?.envVars).toEqual(["MOCK_API_KEY"]);
371+
expect(provider?.auth.map((method) => method.id)).toEqual(["mock-api-key"]);
372+
});
373+
241374
it("registers extra non-api-key auth methods", async () => {
242375
const entry = defineSingleProviderPluginEntry({
243376
id: "demo",

‎src/plugin-sdk/provider-entry.ts‎

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import type { UnifiedModelCatalogEntry } from "@openclaw/model-catalog-core/model-catalog-types";
2+
import {
3+
normalizeStringEntries,
4+
uniqueStrings,
5+
} from "../../packages/normalization-core/src/string-normalization.js";
26
import { createProviderApiKeyAuthMethod } from "../plugins/provider-api-key-auth.js";
37
import { projectProviderCatalogResultToUnifiedTextRows } from "../plugins/provider-catalog-unified-text.js";
48
import type {
@@ -10,7 +14,7 @@ import type {
1014
UnifiedModelCatalogProviderContext,
1115
ProviderPluginWizardSetup,
1216
} from "../plugins/types.js";
13-
import { normalizeStringEntries, uniqueStrings } from "../../packages/normalization-core/src/string-normalization.js";
17+
import { copyArrayEntries, isRecord, readRecordValue } from "../shared/safe-record.js";
1418
import { definePluginEntry } from "./plugin-entry.js";
1519
import type {
1620
OpenClawPluginApi,
@@ -99,13 +103,21 @@ function resolveWizardSetup(params: {
99103
};
100104
}
101105

106+
function copyProviderAuthOptions(value: unknown): SingleProviderPluginApiKeyAuthOptions[] {
107+
return copyArrayEntries(value).filter(isRecord) as SingleProviderPluginApiKeyAuthOptions[];
108+
}
109+
110+
function copyProviderAuthMethods(value: unknown): ProviderAuthMethod[] {
111+
return copyArrayEntries(value).filter(isRecord) as ProviderAuthMethod[];
112+
}
113+
102114
function resolveEnvVars(params: {
103-
envVars?: string[];
115+
envVars?: unknown;
104116
auth?: SingleProviderPluginApiKeyAuthOptions[];
105117
}): string[] | undefined {
106118
const combined = normalizeStringEntries([
107-
...(params.envVars ?? []),
108-
...(params.auth ?? []).map((entry) => entry.envVar).filter(Boolean),
119+
...copyArrayEntries(params.envVars),
120+
...(params.auth ?? []).map((entry) => readRecordValue(entry, "envVar")).filter(Boolean),
109121
]);
110122
return combined.length > 0 ? uniqueStrings(combined) : undefined;
111123
}
@@ -135,25 +147,33 @@ export function defineSingleProviderPluginEntry(options: SingleProviderPluginOpt
135147
const provider = options.provider;
136148
if (provider) {
137149
const providerId = provider.id ?? options.id;
150+
const providerAuth = copyProviderAuthOptions(provider.auth);
151+
const acceptedProviderAuth: SingleProviderPluginApiKeyAuthOptions[] = [];
152+
const auth = providerAuth.flatMap((entry) => {
153+
try {
154+
const { wizard: _wizard, ...authParams } = entry;
155+
const wizard = resolveWizardSetup({
156+
providerId,
157+
providerLabel: provider.label,
158+
auth: entry,
159+
});
160+
const method = createProviderApiKeyAuthMethod({
161+
...authParams,
162+
providerId,
163+
expectedProviders: entry.expectedProviders ?? [providerId],
164+
...(wizard ? { wizard } : {}),
165+
});
166+
acceptedProviderAuth.push(entry);
167+
return [method];
168+
} catch {
169+
return [];
170+
}
171+
});
138172
const envVars = resolveEnvVars({
139173
envVars: provider.envVars,
140-
auth: provider.auth,
141-
});
142-
const auth = (provider.auth ?? []).map((entry) => {
143-
const { wizard: _wizard, ...authParams } = entry;
144-
const wizard = resolveWizardSetup({
145-
providerId,
146-
providerLabel: provider.label,
147-
auth: entry,
148-
});
149-
return createProviderApiKeyAuthMethod({
150-
...authParams,
151-
providerId,
152-
expectedProviders: entry.expectedProviders ?? [providerId],
153-
...(wizard ? { wizard } : {}),
154-
});
174+
auth: acceptedProviderAuth,
155175
});
156-
auth.push(...(provider.extraAuth ?? []));
176+
auth.push(...copyProviderAuthMethods(provider.extraAuth));
157177
let catalog: ProviderPluginCatalog;
158178
if ("run" in provider.catalog) {
159179
const catalogRun = provider.catalog.run;

0 commit comments

Comments
 (0)