Skip to content

Commit 3e8fd49

Browse files
authored
fix: avoid gateway startup event-loop stalls
Defer Gateway channel startup until after readiness, remove startup model prewarm, and move model catalog data onto manifest/static paths so startup no longer loads broad provider runtimes. Verification: - focused gateway/catalog/auth/QA Vitest runs - autoreview clean - Blacksmith Testbox-through-Crabbox tbx_01ksahn65rsrsqz3q1qyxwf929: pnpm check:changed, exit 0 - PR CI green on ee2b631
1 parent f6ab188 commit 3e8fd49

30 files changed

Lines changed: 513 additions & 561 deletions

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ Docs: https://docs.openclaw.ai
7070
- Crabbox: keep AWS hydration compatible with local Actions replay by inlining the hydrate workflow's Node/pnpm setup instead of invoking repo-local composite actions.
7171
- Agents/subagents: simplify native sub-agent completion handoff so children report their latest visible assistant result to the requester without using `message`, while keeping parent-owned message-tool delivery policy intact. Fixes #85070. (#85089) Thanks @brokemac79.
7272
- Docker setup: stop printing the Gateway bearer token in setup logs and printed follow-up commands.
73+
- Gateway: defer channel account startup work until HTTP readiness and remove startup model prewarm, avoiding startup event-loop stalls and timer-delay warnings.
74+
- Models/perf: reuse plugin metadata during models.json planning, keep bundled catalog augmentation manifest/static, and use static provider catalogs for metadata-only startup discovery so provider model normalization, auth discovery, and Gateway startup metadata do not reload broad plugin runtimes.
7375
- Agents: let embedded compaction fallback retries proceed when PI-compatible candidates do not need agent harness plugin preparation.
7476
- Agents/tools: honor configured custom provider API keys when deciding whether media, image-generation, video-generation, music-generation, and PDF tools are available. (#85570)
7577
- StepFun: stop advertising stale generic API key auth choices so onboarding only offers runtime-backed Standard and Step Plan choices.

‎docs/plugins/manifest.md‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -922,12 +922,13 @@ is required.
922922

923923
Top-level fields:
924924

925-
| Field | Type | What it means |
926-
| -------------- | -------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
927-
| `providers` | `Record<string, object>` | Catalog rows for provider ids owned by this plugin. Keys should also appear in top-level `providers`. |
928-
| `aliases` | `Record<string, object>` | Provider aliases that should resolve to an owned provider for catalog or suppression planning. |
929-
| `suppressions` | `object[]` | Model rows from another source that this plugin suppresses for a provider-specific reason. |
930-
| `discovery` | `Record<string, "static" \| "refreshable" \| "runtime">` | Whether the provider catalog can be read from manifest metadata, refreshed into cache, or requires runtime. |
925+
| Field | Type | What it means |
926+
| ---------------- | -------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
927+
| `providers` | `Record<string, object>` | Catalog rows for provider ids owned by this plugin. Keys should also appear in top-level `providers`. |
928+
| `aliases` | `Record<string, object>` | Provider aliases that should resolve to an owned provider for catalog or suppression planning. |
929+
| `suppressions` | `object[]` | Model rows from another source that this plugin suppresses for a provider-specific reason. |
930+
| `discovery` | `Record<string, "static" \| "refreshable" \| "runtime">` | Whether the provider catalog can be read from manifest metadata, refreshed into cache, or requires runtime. |
931+
| `runtimeAugment` | `boolean` | Set to `true` only when the provider runtime must append catalog rows after manifest/config planning. |
931932

932933
`aliases` participates in provider ownership lookup for model-catalog planning.
933934
Alias targets must be top-level providers owned by the same plugin. When a

‎extensions/anthropic/openclaw.plugin.json‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,59 @@
66
"enabledByDefault": true,
77
"providers": ["anthropic"],
88
"providerCatalogEntry": "./provider-discovery.ts",
9+
"modelCatalog": {
10+
"providers": {
11+
"claude-cli": {
12+
"models": [
13+
{
14+
"id": "claude-opus-4-7",
15+
"name": "Claude Opus 4.7 (Claude CLI)",
16+
"reasoning": true,
17+
"input": ["text", "image"],
18+
"contextWindow": 200000
19+
},
20+
{
21+
"id": "claude-sonnet-4-6",
22+
"name": "Claude Sonnet 4.6 (Claude CLI)",
23+
"reasoning": true,
24+
"input": ["text", "image"],
25+
"contextWindow": 200000
26+
},
27+
{
28+
"id": "claude-opus-4-6",
29+
"name": "Claude Opus 4.6 (Claude CLI)",
30+
"reasoning": true,
31+
"input": ["text", "image"],
32+
"contextWindow": 200000
33+
},
34+
{
35+
"id": "claude-opus-4-5",
36+
"name": "Claude Opus 4.5 (Claude CLI)",
37+
"reasoning": true,
38+
"input": ["text", "image"],
39+
"contextWindow": 200000
40+
},
41+
{
42+
"id": "claude-sonnet-4-5",
43+
"name": "Claude Sonnet 4.5 (Claude CLI)",
44+
"reasoning": true,
45+
"input": ["text", "image"],
46+
"contextWindow": 200000
47+
},
48+
{
49+
"id": "claude-haiku-4-5",
50+
"name": "Claude Haiku 4.5 (Claude CLI)",
51+
"reasoning": true,
52+
"input": ["text", "image"],
53+
"contextWindow": 200000
54+
}
55+
]
56+
}
57+
},
58+
"discovery": {
59+
"claude-cli": "static"
60+
}
61+
},
962
"modelSupport": {
1063
"modelPrefixes": ["claude-"]
1164
},

‎extensions/qa-lab/src/gateway-child.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ describe("buildQaRuntimeEnv", () => {
147147
);
148148
expect(env.OPENCLAW_QA_ALLOW_LOCAL_IMAGE_PROVIDER).toBe("1");
149149
expect(env.OPENCLAW_ALLOW_SLOW_REPLY_TESTS).toBe("1");
150-
expect(env.OPENCLAW_SKIP_STARTUP_MODEL_PREWARM).toBe("1");
151150
expect(env.OPENCLAW_BUNDLED_PLUGINS_DIR).toBe("/tmp/openclaw-qa/bundled-plugins");
152151
expect(env.OPENCLAW_COMPATIBILITY_HOST_VERSION).toBe("2026.4.8");
153152
});

‎extensions/qa-lab/src/gateway-child.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ export function buildQaRuntimeEnv(params: {
219219
OPENCLAW_SKIP_BROWSER_CONTROL_SERVER: "1",
220220
OPENCLAW_SKIP_GMAIL_WATCHER: "1",
221221
OPENCLAW_SKIP_CANVAS_HOST: "1",
222-
OPENCLAW_SKIP_STARTUP_MODEL_PREWARM: "1",
223222
OPENCLAW_NO_RESPAWN: "1",
224223
OPENCLAW_TEST_FAST: "1",
225224
OPENCLAW_QA_PARENT_PID: String(process.pid),

‎src/agents/model-auth.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,6 @@ function shouldResolvePluginSyntheticAuth(params: {
412412
if (!syntheticAuthProviderRefs) {
413413
return true;
414414
}
415-
if (resolveProviderConfig(params.cfg, params.provider)) {
416-
return true;
417-
}
418415
const eligibleRefs = new Set(
419416
syntheticAuthProviderRefs.map((ref) => normalizeProviderId(ref)).filter(Boolean),
420417
);

‎src/agents/model-catalog.test.ts‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,75 @@ describe("loadModelCatalog", () => {
10311031
expect(entry.contextWindow).toBe(128_000);
10321032
});
10331033

1034+
it("merges manifest model catalog rows on the normal catalog path", async () => {
1035+
mockSingleOpenAiCatalogModel();
1036+
currentPluginMetadataSnapshotMock.mockReturnValue({
1037+
...emptyPluginMetadataSnapshot(),
1038+
plugins: [
1039+
{
1040+
id: "byteplus",
1041+
origin: "bundled",
1042+
providers: ["byteplus"],
1043+
modelCatalog: {
1044+
providers: {
1045+
byteplus: {
1046+
baseUrl: "https://ark.ap-southeast.bytepluses.com/api/v3",
1047+
api: "openai-completions",
1048+
models: [
1049+
{
1050+
id: "seed-1-8-251228",
1051+
name: "Doubao Seed 1.8",
1052+
input: ["text", "image"],
1053+
contextWindow: 256_000,
1054+
},
1055+
],
1056+
},
1057+
},
1058+
},
1059+
},
1060+
],
1061+
});
1062+
1063+
const result = await loadModelCatalog({ config: {} as OpenClawConfig });
1064+
1065+
const entry = requireCatalogEntry(result, "byteplus", "seed-1-8-251228");
1066+
expect(entry.name).toBe("Doubao Seed 1.8");
1067+
expect(entry.input).toEqual(["text", "image"]);
1068+
expect(entry.contextWindow).toBe(256_000);
1069+
});
1070+
1071+
it("keeps configured LM Studio models visible without runtime catalog augmentation", async () => {
1072+
mockSingleOpenAiCatalogModel();
1073+
augmentCatalogMock.mockResolvedValueOnce([]);
1074+
1075+
const result = await loadModelCatalog({
1076+
config: {
1077+
models: {
1078+
providers: {
1079+
lmstudio: {
1080+
baseUrl: "http://127.0.0.1:1234/v1",
1081+
models: [
1082+
{
1083+
id: "qwen3.6-27b@iq3_xxs",
1084+
name: "Qwen 3.6 27B",
1085+
input: ["text"],
1086+
reasoning: false,
1087+
contextWindow: 128_000,
1088+
maxTokens: 8192,
1089+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
1090+
},
1091+
],
1092+
},
1093+
},
1094+
},
1095+
} as OpenClawConfig,
1096+
});
1097+
1098+
const entry = requireCatalogEntry(result, "lmstudio", "qwen3.6-27b@iq3_xxs");
1099+
expect(entry.name).toBe("Qwen 3.6 27B");
1100+
expect(entry.contextWindow).toBe(128_000);
1101+
});
1102+
10341103
it("dedupes configured models against discovered provider aliases", async () => {
10351104
mockPiDiscoveryModels([{ id: "glm-5", provider: "z.ai", name: "GLM-5" }]);
10361105

‎src/agents/model-catalog.ts‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,14 +415,19 @@ export async function loadModelCatalog(params?: {
415415
const sortModels = sortModelCatalogEntries;
416416
try {
417417
const cfg = params?.config ?? getRuntimeConfig();
418+
let manifestMetadataSnapshot: PluginMetadataSnapshot | undefined;
418419
let manifestPlugins: ProviderModelIdNormalizationOptions["manifestPlugins"];
419-
const getManifestPlugins = () => {
420-
manifestPlugins ??=
421-
params?.metadataSnapshot?.plugins ??
420+
const getManifestMetadataSnapshot = () => {
421+
manifestMetadataSnapshot ??=
422+
params?.metadataSnapshot ??
422423
loadManifestMetadataSnapshot({
423424
config: cfg,
424425
env: process.env,
425-
}).plugins;
426+
});
427+
return manifestMetadataSnapshot;
428+
};
429+
const getManifestPlugins = () => {
430+
manifestPlugins ??= getManifestMetadataSnapshot().plugins;
426431
return manifestPlugins;
427432
};
428433
if (!readOnly) {
@@ -493,6 +498,15 @@ export async function loadModelCatalog(params?: {
493498
compat,
494499
});
495500
}
501+
appendCatalogEntriesIfAbsent(
502+
models,
503+
loadManifestModelCatalog({
504+
config: cfg,
505+
env: process.env,
506+
metadataSnapshot: getManifestMetadataSnapshot(),
507+
}),
508+
);
509+
logStage("manifest-models-merged", `entries=${models.length}`);
496510
if (!readOnly) {
497511
const supplemental = await augmentModelCatalogWithProviderPlugins({
498512
config: cfg,

‎src/agents/model-provider-auth.test.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { OpenClawConfig } from "../config/types.openclaw.js";
33
import type { ModelCatalogEntry } from "./model-catalog.types.js";
44

55
const modelCatalogMocks = vi.hoisted(() => ({
6-
loadModelCatalog: vi.fn<() => Promise<ModelCatalogEntry[]>>(),
6+
loadModelCatalog: vi.fn<(params?: unknown) => Promise<ModelCatalogEntry[]>>(),
77
}));
88

99
const modelAuthMocks = vi.hoisted(() => ({
@@ -94,6 +94,21 @@ describe("prepared provider auth state", () => {
9494
expect(firstLookup).toBe(secondLookup);
9595
});
9696

97+
it("uses the read-only model catalog while warming provider auth", async () => {
98+
const cfg = {} as OpenClawConfig;
99+
modelCatalogMocks.loadModelCatalog.mockResolvedValue([
100+
{ id: "gpt", name: "gpt", provider: "openai" },
101+
]);
102+
modelAuthMocks.hasRuntimeAvailableProviderAuth.mockReturnValue(false);
103+
104+
await warmCurrentProviderAuthState(cfg);
105+
106+
expect(modelCatalogMocks.loadModelCatalog).toHaveBeenCalledWith({
107+
config: cfg,
108+
readOnly: true,
109+
});
110+
});
111+
97112
it("hasAuthForModelProvider returns the prepared answer after warm and falls through to compute after clear", async () => {
98113
const cfg = {} as OpenClawConfig;
99114
modelCatalogMocks.loadModelCatalog.mockResolvedValue([

‎src/agents/model-provider-auth.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ export async function warmCurrentProviderAuthState(
206206
const ownGeneration = currentProviderAuthStateGeneration;
207207
const isWarmStale = () =>
208208
options.isCancelled?.() === true || ownGeneration !== currentProviderAuthStateGeneration;
209-
const catalog = await loadModelCatalog({ config: cfg });
209+
const catalog = await loadModelCatalog({ config: cfg, readOnly: true });
210210
if (isWarmStale()) {
211211
return;
212212
}

0 commit comments

Comments
 (0)