Skip to content

Commit 7a8eee4

Browse files
authored
perf(agents): keep turn-path model catalog reads off the full live build (#120834)
* perf(agents): keep turn-path model catalog reads off the full live build First agent turns (embedded and cron) resolved thinking capability through loadPreparedModelCatalogSnapshot without readOnly, which materialized the full live model-runtime catalog: ambient synthetic-auth discovery fanned out to every registered provider and loaded plugin discovery modules through jiti source transform (3,172 TS modules, 36s event-loop block, +600MB heap, 58.7s model-selection on a cold gateway). - add loadProviderScopedThinkingCatalog: manifest metadata first, then a provider-scoped read-only static catalog, then scoped live discovery only for runtime-discovery providers (preserves #116584 Ollama semantics) - route scopedLiveProviderDiscovery through the scoped read-only loader - scope live-mode ambient synthetic-auth refs to the requested providers - bound the last-resort synthetic-auth sweep to discovery entry modules - memoize per-turn plugin skill dir resolution/republish (single-slot, lifecycle-cleared; was a full walk + symlink republish every turn) Cold first turn 72.7s -> ~22s wall (remaining cost is provider prefill of the ~19.5k-token default prompt); model-selection 58,726ms -> 124ms. * test(agents): align model-catalog.runtime mocks with scoped thinking catalog seam Explicit vi.mock factories must export every binding prod touches; the new loadProviderScopedThinkingCatalog export is now mocked everywhere the module is stubbed, and the live-model-switch Ollama hydration test asserts the new provider-scoped seam instead of the retired unscoped snapshot call shape. * test(agents): export scoped thinking catalog from every prepared-catalog mock; split synthetic-auth helpers - add loadProviderScopedThinkingCatalog to all explicit prepared-model-catalog and model-catalog.runtime mock factories (vi.mock factories must export every binding prod touches) - move synthetic-auth ref scoping/resolution into prepared-model-runtime.synthetic-auth.ts; keeps facts under the max-lines cap * test(agents): prove scoped thinking hydration for runtime-only models Boundary proof for the ClawSweeper review gap: the three-tier helper stops at manifest or scoped-static when they resolve, and runs provider-scoped live discovery (no broad fanout) only for runtime-only models; cron selection hydrates through the same scoped helper and skips it entirely for thinking=off. * test(agents): accept rest args in scoped thinking catalog mocks
1 parent 562129d commit 7a8eee4

50 files changed

Lines changed: 422 additions & 69 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎src/agents/agent-command.compaction-rotation.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ vi.mock("./model-catalog.js", () => ({
8787
}));
8888

8989
vi.mock("./model-catalog.runtime.js", () => ({
90+
loadProviderScopedThinkingCatalog: vi.fn(async () => []),
9091
loadPreparedModelCatalogSnapshot: vi.fn(async () => ({
9192
entries: [],
9293
routeVariants: [],

‎src/agents/agent-command.live-model-switch.test.ts‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ const state = vi.hoisted(() => ({
9797
resolveSupportedThinkingLevelMock: vi.fn(({ level }: { level?: string }) => level),
9898
resolveThinkingDefaultMock: vi.fn((_args: unknown) => "low"),
9999
loadManifestModelCatalogMock: vi.fn(() => []),
100+
loadProviderScopedThinkingCatalogMock: vi.fn((_params: unknown) => undefined),
100101
loadPreparedModelCatalogSnapshotMock: vi.fn(
101102
async (): Promise<ModelCatalogSnapshot> => ({
102103
entries: [],
@@ -551,6 +552,11 @@ vi.mock("./model-catalog.js", () => ({
551552
}));
552553

553554
vi.mock("./model-catalog.runtime.js", () => ({
555+
// The scoped thinking catalog hydrates from the same runtime snapshot the test controls.
556+
loadProviderScopedThinkingCatalog: async (params: unknown) => {
557+
state.loadProviderScopedThinkingCatalogMock(params);
558+
return (await state.loadPreparedModelCatalogSnapshotMock()).entries;
559+
},
554560
loadPreparedModelCatalogSnapshot: state.loadPreparedModelCatalogSnapshotMock,
555561
}));
556562

@@ -3523,11 +3529,15 @@ describe("agentCommand – LiveSessionModelSwitchError retry", () => {
35233529
allowModelOverride: true,
35243530
});
35253531

3526-
expect(state.loadPreparedModelCatalogSnapshotMock).toHaveBeenCalledWith({
3527-
config: state.runtimeConfigMock,
3528-
agentId: "default",
3529-
workspaceDir: "/tmp/workspace",
3530-
});
3532+
expect(state.loadProviderScopedThinkingCatalogMock).toHaveBeenCalledWith(
3533+
expect.objectContaining({
3534+
config: state.runtimeConfigMock,
3535+
provider: "ollama",
3536+
model: "minimax-m3:cloud",
3537+
agentId: "default",
3538+
workspaceDir: "/tmp/workspace",
3539+
}),
3540+
);
35313541
const thinkingArgs = requireRecord(
35323542
mockCallArg(state.isThinkingLevelSupportedMock),
35333543
"thinking args",

‎src/agents/command/assistant-transcript-repair.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ vi.mock("../model-catalog.js", () => ({
9696
}));
9797

9898
vi.mock("../model-catalog.runtime.js", () => ({
99+
loadProviderScopedThinkingCatalog: vi.fn(async () => []),
99100
loadPreparedModelCatalogSnapshot: vi.fn(async () => ({
100101
entries: [],
101102
routeVariants: [],

‎src/agents/command/model-selection.ts‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -512,15 +512,16 @@ export async function resolveEmbeddedModelSelection(params: {
512512
primaryConfiguredThinkLevel !== "off" &&
513513
!hasResolvedThinkingCatalogEntry({ catalog: catalogForThinking, provider, model })
514514
) {
515-
const { loadPreparedModelCatalogSnapshot } = await import("../model-catalog.runtime.js");
515+
// Thinking capability is a per-model fact; never materialize the full live catalog here.
516+
const { loadProviderScopedThinkingCatalog } = await import("../model-catalog.runtime.js");
516517
const runtimeCatalog = normalizeThinkingCatalogProviders(
517-
(
518-
await loadPreparedModelCatalogSnapshot({
519-
config: params.cfg,
520-
agentId: params.sessionAgentId,
521-
workspaceDir: params.workspaceDir,
522-
})
523-
).entries,
518+
await loadProviderScopedThinkingCatalog({
519+
config: params.cfg,
520+
provider,
521+
model,
522+
...(params.sessionAgentId ? { agentId: params.sessionAgentId } : {}),
523+
...(params.workspaceDir ? { workspaceDir: params.workspaceDir } : {}),
524+
}),
524525
);
525526
const allowedRuntimeCatalog = createModelVisibilityPolicy({
526527
cfg: params.cfg,

‎src/agents/context.lookup.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ vi.mock("../config/runtime-source-projection.js", () => ({
6565
}));
6666

6767
vi.mock("./prepared-model-catalog.js", () => ({
68+
loadProviderScopedThinkingCatalog: vi.fn(async () => []),
6869
loadPreparedModelCatalogOwnerSnapshot: contextTestState.loadModelCatalogOwnerSnapshot,
6970
getPublishedPreparedModelCatalogOwnerSnapshot:
7071
contextTestState.getPublishedModelCatalogOwnerSnapshot,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ export { loadManifestModelCatalog } from "./model-catalog.js";
33
export {
44
loadPreparedModelCatalog,
55
loadPreparedModelCatalogSnapshot,
6+
loadProviderScopedThinkingCatalog,
67
} from "./prepared-model-catalog.js";

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const authProfilesMocks = vi.hoisted(() => ({
6666
}));
6767

6868
vi.mock("./prepared-model-catalog.js", () => ({
69+
loadProviderScopedThinkingCatalog: vi.fn(async () => []),
6970
loadPreparedModelCatalogOwnerSnapshot: async (params?: unknown) => ({
7071
...(modelCatalogMocks.ownerWorkspaceDir
7172
? { workspaceDir: modelCatalogMocks.ownerWorkspaceDir }

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { runProviderAuthWarmWorkerInput } from "./model-provider-auth.worker.js"
1515
const tempDirs: string[] = [];
1616

1717
vi.mock("./prepared-model-catalog.js", () => ({
18+
loadProviderScopedThinkingCatalog: vi.fn(async () => []),
1819
loadPreparedModelCatalogOwnerSnapshot: vi.fn(
1920
async (params: { agentDir: string; agentId?: string; config: OpenClawConfig }) => ({
2021
agentDir: params.agentDir,

‎src/agents/model-selection.plugin-runtime.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ vi.mock("../plugins/current-plugin-metadata-snapshot.js", () => ({
3232

3333
vi.mock("./model-catalog.runtime.js", () => ({
3434
loadManifestModelCatalog: () => [],
35+
loadProviderScopedThinkingCatalog: async () => [],
3536
loadPreparedModelCatalog: async () => [],
3637
loadPreparedModelCatalogSnapshot: loadPreparedModelCatalogSnapshotMock,
3738
}));

‎src/agents/openclaw-tools.session-status.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ function createConfigModuleMock() {
200200

201201
function createModelCatalogModuleMock() {
202202
return {
203+
loadProviderScopedThinkingCatalog: async () => [],
203204
loadPreparedModelCatalog: async () => [
204205
{
205206
provider: "anthropic",

0 commit comments

Comments
 (0)