diff --git a/src/server/chat-native.ts b/src/server/chat-native.ts index 9abb99683e..a835f71990 100644 --- a/src/server/chat-native.ts +++ b/src/server/chat-native.ts @@ -106,16 +106,21 @@ function normalizePinnedChatEffort(options: HandleNativeChatOptions): void { const pinned = chatBody.compaction_trigger === undefined ? resolvePinnedEffort(route, selector, config) : undefined; + let normalizeForWire = false; if (pinned !== undefined) { logCtx.requestedEffort = from ? `${from}->${pinned}` : pinned; if (pinned === "none") delete chatBody.reasoning_effort; else chatBody.reasoning_effort = pinned; - // The native lane historically passes caller effort through, including with caps set. - // Only a newly operator-pinned value enters the cap and provider-mapping pipeline. - if (effortCapAppliesTo(chatCollabSurface(chatBody), req.headers, config)) { - const capped = applyChatEffortCap(chatBody, req.headers, config, supportedLadderFor(route)); - if (capped) logCtx.requestedEffort = `${logCtx.requestedEffort}->${capped.to}`; + normalizeForWire = true; + } + if (effortCapAppliesTo(chatCollabSurface(chatBody), req.headers, config)) { + const capped = applyChatEffortCap(chatBody, req.headers, config, supportedLadderFor(route)); + if (capped) { + logCtx.requestedEffort = `${logCtx.requestedEffort ?? capped.from}->${capped.to}`; + normalizeForWire = true; } + } + if (normalizeForWire) { const effort = typeof chatBody.reasoning_effort === "string" ? chatBody.reasoning_effort : undefined; const wireEffort = mapReasoningEffort(route.provider, route.modelId, effort); if (wireEffort === undefined) delete chatBody.reasoning_effort; diff --git a/tests/codex-integration/model-pinned-effort.test.ts b/tests/codex-integration/model-pinned-effort.test.ts index 7c7b15401c..096b104cc5 100644 --- a/tests/codex-integration/model-pinned-effort.test.ts +++ b/tests/codex-integration/model-pinned-effort.test.ts @@ -428,9 +428,10 @@ describe("operator pins on the actual request wire", () => { expect(wire.reasoning).toEqual({ effort: "max", summary: "auto" }); }); - test("native Chat without pins preserves caller wire spelling and existing cap behavior", async () => { + test("native Chat without pins enforces applicable caps and preserves unqualified caller spelling", async () => { const c = config({ reasoningEfforts: ["low"], reasoningEffortMap: { max: "enabled" } }, { effortCap: "low", subagentEffortCap: "low" }); - expect((await request(c, "chat", { reasoning_effort: "ultra" }, { "x-openai-subagent": "collab_spawn" })).reasoning_effort).toBe("ultra"); + expect((await request(c, "chat", { reasoning_effort: "ultra" }, { "x-openai-subagent": "collab_spawn" })).reasoning_effort).toBe("low"); + expect((await request(c, "chat", { reasoning_effort: "ultra" })).reasoning_effort).toBe("ultra"); expect(Object.hasOwn(await request(c, "chat", { reasoning_effort: undefined }), "reasoning_effort")).toBe(false); });