Skip to content

Commit 93d879d

Browse files
authored
fix(agents): scope fall-through plugin registry loads to the active runtime registry (#130167)
First hook/cron isolated-run dispatch in a gateway process cold-loaded every discovered plugin (~70 bundled providers) because the registry loader's startup-scope fallback chain came up empty on that path and dropped onlyPluginIds entirely. In dev checkouts each provider plugin loads from TypeScript source through jiti's synchronous babel transform: a CPU profile of a live 13-message gmail hook burst showed one contiguous 42.6s event-loop block (36.2s extension module loading; amazon-bedrock 16.8s, opencode 13.1s), the gateway HTTP server unresponsive for ~31s, and the fan-out handler's own 8s response deadline unable to fire - the livelock recorded in #130002. The fallback chain now consults the process's active plugin registry before giving up to full discovery: explicit base -> request-scope registry -> metadata snapshot pluginIds -> active runtime plugin ids -> unrestricted. resolveAgentRuntimePluginLoadPlan still adds the run's selected provider, harness, memory, and context-engine owners on top, so any selected provider outside the startup set keeps joining the immutable run generation. Hosts with no active registry (pure library use) keep full discovery. Live re-verification on the same rig: cold burst answered in 8.03s with the designed 503 partial fan-out response, probe max latency 4.56s (was a 31.5s outage), longest event-loop block 5.5s (was 42.6s), and only startup-registry plugins load. Follow-up of the gmail hook fan-out landing (#130002); same defect family as the channel-path fix in #125596.
1 parent a0d6467 commit 93d879d

2 files changed

Lines changed: 59 additions & 3 deletions

File tree

‎src/agents/runtime-plugins.test.ts‎

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ vi.mock("./harness/runtime-plugin-load-plan.js", () => ({
4848
resolveAgentRuntimePluginSelections: hoisted.resolveAgentRuntimePluginSelections,
4949
}));
5050

51+
import { createEmptyPluginRegistry } from "../plugins/registry-empty.js";
5152
import {
5253
getPluginRuntimeGatewayRequestScope,
5354
withPluginRuntimeRegistryScope,
5455
} from "../plugins/runtime/gateway-request-scope.js";
56+
import { createPluginRecord } from "../plugins/status.test-helpers.js";
5557
import {
5658
createPreparedInboundRegistryLoader,
5759
prepareWorkspacePluginRegistries,
@@ -103,7 +105,7 @@ describe("agent runtime plugin registries", () => {
103105
});
104106

105107
it("adopts full-only runtime capabilities from the active composition-root registry", () => {
106-
const activeRegistry = { active: true };
108+
const activeRegistry = createEmptyPluginRegistry();
107109
const contextEnginesAdopted = { handle: "context-engines" };
108110
const presentersAdopted = { handle: "presenters" };
109111
hoisted.getActivePluginRegistry.mockReturnValue(activeRegistry);
@@ -121,6 +123,49 @@ describe("agent runtime plugin registries", () => {
121123
contextEnginesAdopted,
122124
activeRegistry,
123125
);
126+
expect(hoisted.loadPluginRegistryHandle).toHaveBeenCalledWith(
127+
expect.not.objectContaining({ onlyPluginIds: expect.anything() }),
128+
);
129+
});
130+
131+
it("bounds unscoped agent loads to active runtime plugins and selected owners", async () => {
132+
const runtime =
133+
await vi.importActual<typeof import("../plugins/runtime.js")>("../plugins/runtime.js");
134+
const previousRegistry = runtime.captureActivePluginRegistrySnapshot();
135+
const activeRegistry = createEmptyPluginRegistry();
136+
activeRegistry.plugins.push(
137+
createPluginRecord({ id: "startup-channel" }),
138+
createPluginRecord({ id: "startup-provider" }),
139+
createPluginRecord({ id: "deferred-plugin", format: "openclaw", imported: false }),
140+
);
141+
hoisted.resolveAgentRuntimePluginLoadPlan.mockImplementation(({ config, basePluginIds }) => ({
142+
config,
143+
pluginIds: [...(basePluginIds ?? []), "selected-provider"],
144+
}));
145+
146+
try {
147+
runtime.setActivePluginRegistry(activeRegistry);
148+
hoisted.getActivePluginRegistry.mockImplementation(runtime.getActivePluginRegistry);
149+
150+
loadAgentRuntimePluginRegistryHandle({
151+
config: {} as never,
152+
workspaceDir: "/tmp/workspace",
153+
selections: [{ provider: "selected", modelId: "model" }],
154+
});
155+
156+
expect(hoisted.resolveAgentRuntimePluginLoadPlan).toHaveBeenCalledWith(
157+
expect.objectContaining({ basePluginIds: ["startup-channel", "startup-provider"] }),
158+
);
159+
expect(hoisted.loadPluginRegistryHandle).toHaveBeenCalledWith(
160+
expect.objectContaining({
161+
onlyPluginIds: ["startup-channel", "startup-provider", "selected-provider"],
162+
}),
163+
);
164+
} finally {
165+
activeRegistry.plugins.length = 0;
166+
runtime.restoreActivePluginRegistrySnapshot(previousRegistry);
167+
hoisted.getActivePluginRegistry.mockReset().mockReturnValue(undefined);
168+
}
124169
});
125170

126171
it("reuses the current Gateway generation and loads only the imported-plugin delta", () => {
@@ -302,6 +347,9 @@ describe("agent runtime plugin registries", () => {
302347
it("keeps an explicit metadata generation source-default without Gateway selection", () => {
303348
const config = {} as never;
304349
const metadataSnapshot = createMetadataSnapshot();
350+
hoisted.getActivePluginRegistry.mockReturnValue({
351+
plugins: [{ id: "broader-process-owner", status: "loaded" }],
352+
});
305353

306354
loadAgentRuntimePluginRegistryHandle({
307355
config,

‎src/agents/runtime-plugins.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import type { OpenClawConfig } from "../config/types.openclaw.js";
22
import { adoptRuntimeContextEngineRegistrations } from "../context-engine/registry.js";
3-
import { listRuntimePluginIdsFromRegistry } from "../plugins/active-runtime-registry.js";
3+
import {
4+
listLoadedRuntimePluginIds,
5+
listRuntimePluginIdsFromRegistry,
6+
} from "../plugins/active-runtime-registry.js";
47
import { normalizePluginsConfig } from "../plugins/config-state.js";
58
import { extractPluginInstallRecordsFromInstalledPluginIndex } from "../plugins/installed-plugin-index-install-records.js";
69
import { loadPluginRegistryHandle } from "../plugins/loader.js";
@@ -68,14 +71,19 @@ function resolveAgentRuntimePluginRegistryLoad(params: AgentRuntimePluginRegistr
6871
...(workspaceDir ? { workspaceDir } : {}),
6972
};
7073
const requestPluginRegistry = getPluginRuntimeGatewayRequestScope()?.pluginRegistry;
74+
// Gateway-hosted fall-through must not cold-load every plugin (30-45s event-loop convoy);
75+
// startup runtime plugin ids plus selected run owners bound the registry scope.
76+
const activePluginIds = listLoadedRuntimePluginIds();
7177
const startupPluginIds =
7278
params.basePluginIds !== undefined
7379
? [...params.basePluginIds]
7480
: requestPluginRegistry
7581
? listRuntimePluginIdsFromRegistry(requestPluginRegistry)
7682
: metadataSnapshot.pluginIds
7783
? [...metadataSnapshot.pluginIds]
78-
: undefined;
84+
: activePluginIds.length > 0
85+
? activePluginIds
86+
: undefined;
7987
const planParams = {
8088
config: params.config,
8189
workspaceDir: workspaceDir ?? process.cwd(),

0 commit comments

Comments
 (0)