From b1e97b235e80d622b85cbb987b166d39c2e536fc Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 20 Aug 2026 19:31:53 -0700 Subject: [PATCH] fix: align scoped model parameter consumers --- extensions/openrouter/index.test.ts | 4 +-- extensions/openrouter/index.ts | 33 ++++++++++----------- src/auto-reply/reply/agent-runner-memory.ts | 1 + src/auto-reply/reply/memory-flush.test.ts | 28 +++++++++++++++++ src/auto-reply/reply/memory-flush.ts | 6 ++-- 5 files changed, 51 insertions(+), 21 deletions(-) diff --git a/extensions/openrouter/index.test.ts b/extensions/openrouter/index.test.ts index 61f9a1a2d0f6..eb93f922a539 100644 --- a/extensions/openrouter/index.test.ts +++ b/extensions/openrouter/index.test.ts @@ -593,8 +593,8 @@ describe("openrouter provider hooks", () => { }, } as never); - expect(contribution?.dynamicSuffix).toContain("Analysis models: google/gemini-3.5-flash."); - expect(contribution?.dynamicSuffix).not.toContain("deepseek/deepseek-v4-pro"); + expect(contribution?.dynamicSuffix).toContain("Analysis models: deepseek/deepseek-v4-pro."); + expect(contribution?.dynamicSuffix).not.toContain("google/gemini-3.5-flash"); }); it("reads per-agent Fusion config from the canonical agent roster", async () => { diff --git a/extensions/openrouter/index.ts b/extensions/openrouter/index.ts index 664a34902669..7c56d8f19ddb 100644 --- a/extensions/openrouter/index.ts +++ b/extensions/openrouter/index.ts @@ -149,27 +149,26 @@ function findConfiguredOpenRouterModelParams( return undefined; } -function resolveMergedOpenRouterPromptParams( +function resolveFusionExtraBody( ctx: OpenRouterFusionPromptContext, ): Record | undefined { const agentConfig = ctx.agentId && ctx.config ? resolveAgentConfig(ctx.config, ctx.agentId) : undefined; - const merged = { - ...readRecord(ctx.config?.agents?.defaults?.params), - ...findConfiguredOpenRouterModelParams(ctx.config?.agents?.defaults?.models, ctx.modelId), - ...readRecord(agentConfig?.params), - ...findConfiguredOpenRouterModelParams(agentConfig?.models, ctx.modelId), - }; - return Object.keys(merged).length > 0 ? merged : undefined; -} - -function resolveFusionExtraBody( - ctx: OpenRouterFusionPromptContext, -): Record | undefined { - const params = resolveMergedOpenRouterPromptParams(ctx); - const rawExtraBody = - params && Object.hasOwn(params, "extra_body") ? params.extra_body : params?.extraBody; - return readRecord(rawExtraBody); + const sources = [ + readRecord(ctx.config?.agents?.defaults?.params), + findConfiguredOpenRouterModelParams(ctx.config?.agents?.defaults?.models, ctx.modelId), + readRecord(agentConfig?.params), + findConfiguredOpenRouterModelParams(agentConfig?.models, ctx.modelId), + ]; + let effective: Record | undefined; + for (const source of sources) { + const raw = source && Object.hasOwn(source, "extra_body") ? source.extra_body : source?.extraBody; + const candidate = readRecord(raw); + if (candidate) { + effective = candidate; + } + } + return effective; } function resolveOpenRouterFusionPromptContribution( diff --git a/src/auto-reply/reply/agent-runner-memory.ts b/src/auto-reply/reply/agent-runner-memory.ts index f45ecd4989b7..606188e4744e 100644 --- a/src/auto-reply/reply/agent-runner-memory.ts +++ b/src/auto-reply/reply/agent-runner-memory.ts @@ -793,6 +793,7 @@ export async function runPreflightCompactionIfNeeded(params: { cfg: params.cfg, provider: params.followupRun.run.provider, modelId: params.followupRun.run.model ?? params.defaultModel, + agentId: compactionAgentId, }); const threshold = Math.max( contextWindowTokens - reserveTokensFloor - softThresholdTokens, diff --git a/src/auto-reply/reply/memory-flush.test.ts b/src/auto-reply/reply/memory-flush.test.ts index ed64d1b0381c..dbce6169cb85 100644 --- a/src/auto-reply/reply/memory-flush.test.ts +++ b/src/auto-reply/reply/memory-flush.test.ts @@ -69,6 +69,34 @@ function buildHostConfig(params: { } describe("Responses server compaction host/transport parity", () => { + it("uses the active agent-model compaction threshold", () => { + const modelRef = modelKey("openai", TEST_MODEL_ID); + const cfg: OpenClawConfig = { + agents: { + defaults: { + params: { responsesCompactThreshold: 120_000 }, + }, + entries: [ + { + id: "audit", + models: { + [modelRef]: { params: { responsesCompactThreshold: 175_000 } }, + }, + }, + ], + }, + }; + + expect( + resolveResponsesServerCompactionThreshold({ + cfg, + provider: "openai", + modelId: TEST_MODEL_ID, + agentId: "audit", + }), + ).toBe(175_000); + }); + it.each([ { name: "OpenAI default route without an authored base URL", diff --git a/src/auto-reply/reply/memory-flush.ts b/src/auto-reply/reply/memory-flush.ts index 6656d01d3755..645668ae1e72 100644 --- a/src/auto-reply/reply/memory-flush.ts +++ b/src/auto-reply/reply/memory-flush.ts @@ -46,6 +46,7 @@ export function resolveResponsesServerCompactionThreshold(params: { cfg?: OpenClawConfig; provider?: string; modelId?: string; + agentId?: string; }): number | undefined { const provider = params.provider?.trim(); const modelId = params.modelId?.trim(); @@ -60,12 +61,13 @@ export function resolveResponsesServerCompactionThreshold(params: { models: providerConfig?.models, normalizeModelId, }).get(normalizeModelId(modelId)); - const { defaultParams, modelParams } = resolveModelExtraParamSources({ + const { paramSources } = resolveModelExtraParamSources({ config: params.cfg, provider, modelId, + agentId: params.agentId, }); - const extraParams = { ...defaultParams, ...modelParams }; + const extraParams = Object.assign({}, ...paramSources); if (normalizedProvider === "anthropic") { return resolveAnthropicServerCompactionPlan( {