Skip to content

Commit 7a835e8

Browse files
committed
fix(chat): honor explicit summary and keep it on empty ladders
CodeRabbit: resolve a validated reasoning.summary before include_reasoning so conflicting knobs cannot leak or hide traces. Codex: an empty effort ladder means no effort control, not no thinking. Strip only reasoning.effort so include_reasoning / summary-only requests still reach parseRequest.
1 parent 3f674dc commit 7a835e8

7 files changed

Lines changed: 70 additions & 8 deletions

File tree

‎docs-site/src/content/docs/guides/grok-build.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ the ladder is advertised. The Chat Completions inbound translator defaults the i
6666
Responses `reasoning.summary` to `auto` in that case, so thinking traces reach Grok as
6767
`delta.reasoning_content` instead of being hidden. Set `include_reasoning: false` (or
6868
`reasoning.summary: "none"`) if a client wants the model to think without returning the
69-
trace.
69+
trace. An explicit `reasoning.summary` wins when both knobs are present.
7070

7171
## Authentication note
7272

‎docs-site/src/content/docs/reference/proxy-formats.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ internal `reasoning.effort`. Because the Responses parser hides thinking unless
150150
`reasoning.summary` is set and is not `none`, Chat Completions requests that ask for an
151151
effort default to `reasoning.summary: "auto"` so thinking streams back as
152152
`delta.reasoning_content`. Clients can still hide traces with `include_reasoning: false` or
153-
`reasoning.summary: "none"`, and an explicit `reasoning.summary` of `auto`, `concise`,
154-
`detailed`, or `none` is preserved.
153+
`reasoning.summary: "none"`. An explicit `reasoning.summary` of `auto`, `concise`,
154+
`detailed`, or `none` wins over `include_reasoning`.
155155

156156
Structured output is part of that translation: `response_format` with `json_object` or
157157
`json_schema` is forwarded to routed `openai-chat` models. On `POST /v1/responses` the

‎src/chat/inbound.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,11 @@ function resolveReasoningEffort(raw: Rec): string | undefined {
214214
* sent an effort, default the summary to `"auto"` so traces are not swallowed.
215215
*/
216216
function resolveReasoningSummary(raw: Rec): string | undefined {
217-
if (raw.include_reasoning === false) return "none";
218-
if (raw.include_reasoning === true) return "auto";
219217
if (isRec(raw.reasoning) && typeof raw.reasoning.summary === "string" && OUTPUT_CONFIG_SUMMARIES.has(raw.reasoning.summary)) {
220218
return raw.reasoning.summary;
221219
}
220+
if (raw.include_reasoning === false) return "none";
221+
if (raw.include_reasoning === true) return "auto";
222222
return undefined;
223223
}
224224

‎src/server/chat-completions.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,11 @@ async function handleChatCompletionsWithBudget(
140140
logCtx.usageLogInputTokens = Math.max(1, estimateTokens(parts.join("\n"), requestedModel));
141141
}
142142
if (internalBody.reasoning !== undefined) {
143-
const { supportedLadderFor } = await import("./effort-policy");
143+
const { stripEmptyLadderEffort, supportedLadderFor } = await import("./effort-policy");
144144
const ladder = supportedLadderFor({ provider: route.provider, modelId: route.modelId });
145-
if (ladder !== undefined && ladder.length === 0) delete internalBody.reasoning;
145+
const next = stripEmptyLadderEffort(internalBody.reasoning, ladder);
146+
if (next === undefined) delete internalBody.reasoning;
147+
else internalBody.reasoning = next;
146148
}
147149
} catch (err) {
148150
if (err instanceof NoEligiblePolicyCandidateError) {

‎src/server/effort-policy.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,24 @@ export function effortCapAppliesTo(
9898
* validates against that backend. A custom responses provider (key mode) serving a
9999
* native-looking bare id must NOT inherit the unrelated native ladder.
100100
*/
101+
/**
102+
* Empty ladders mean "no effort control", not "this model cannot emit reasoning".
103+
* Drop only `effort` so a Chat Completions `include_reasoning` / `reasoning.summary`
104+
* request still reaches parseRequest and is not hidden by hideThinkingSummary.
105+
*/
106+
export function stripEmptyLadderEffort(
107+
reasoning: unknown,
108+
ladder: readonly string[] | undefined,
109+
): unknown {
110+
if (ladder === undefined || ladder.length > 0) return reasoning;
111+
if (reasoning === undefined || reasoning === null || typeof reasoning !== "object" || Array.isArray(reasoning)) {
112+
return reasoning;
113+
}
114+
const next = { ...(reasoning as Record<string, unknown>) };
115+
delete next.effort;
116+
return Object.keys(next).length > 0 ? next : undefined;
117+
}
118+
101119
export function supportedLadderFor(route: { provider: OcxProviderConfig; modelId: string }): string[] | undefined {
102120
const { provider, modelId } = route;
103121
if (modelInList(provider.noReasoningModels, modelId)) return [];

‎tests/chat-completions-endpoint.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,28 @@ describe("chatCompletionsToResponsesBody reasoning summary", () => {
272272
expect(parseRequest(body).options.hideThinkingSummary).not.toBe(true);
273273
});
274274

275+
test("explicit reasoning.summary wins over include_reasoning true", () => {
276+
const body = chatCompletionsToResponsesBody({
277+
model: "mock/test-model",
278+
messages: [{ role: "user", content: "hi" }],
279+
include_reasoning: true,
280+
reasoning: { summary: "none" },
281+
});
282+
expect(body.reasoning).toEqual({ summary: "none" });
283+
expect(parseRequest(body).options.hideThinkingSummary).toBe(true);
284+
});
285+
286+
test("explicit reasoning.summary wins over include_reasoning false", () => {
287+
const body = chatCompletionsToResponsesBody({
288+
model: "mock/test-model",
289+
messages: [{ role: "user", content: "hi" }],
290+
include_reasoning: false,
291+
reasoning: { effort: "high", summary: "auto" },
292+
});
293+
expect(body.reasoning).toEqual({ effort: "high", summary: "auto" });
294+
expect(parseRequest(body).options.hideThinkingSummary).not.toBe(true);
295+
});
296+
275297
test("omits reasoning when the client sent no reasoning knobs", () => {
276298
const body = chatCompletionsToResponsesBody({
277299
model: "mock/test-model",

‎tests/effort-policy.test.ts‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { afterEach, describe, expect, test } from "bun:test";
77
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
88
import { tmpdir } from "node:os";
99
import { join } from "node:path";
10-
import { applyEffortCap, effortCapAppliesTo, effortCapFor, isThreadSpawnRequest, resolveCappedEffort, supportedLadderFor } from "../src/server/effort-policy";
10+
import { applyEffortCap, effortCapAppliesTo, effortCapFor, isThreadSpawnRequest, resolveCappedEffort, stripEmptyLadderEffort, supportedLadderFor } from "../src/server/effort-policy";
1111
import { collabSurface } from "../src/server/responses";
1212
import { handleManagementAPI } from "../src/server/management-api";
1313
import { NoEnabledOpenAiProviderError, routeModel } from "../src/router";
@@ -173,6 +173,26 @@ describe("resolveCappedEffort (ladder-aware resolution)", () => {
173173
});
174174
});
175175

176+
describe("stripEmptyLadderEffort", () => {
177+
test("keeps a summary-only object on an empty ladder", () => {
178+
expect(stripEmptyLadderEffort({ summary: "auto" }, [])).toEqual({ summary: "auto" });
179+
});
180+
181+
test("strips effort but keeps summary on an empty ladder", () => {
182+
expect(stripEmptyLadderEffort({ effort: "max", summary: "auto" }, [])).toEqual({ summary: "auto" });
183+
});
184+
185+
test("drops an effort-only object on an empty ladder", () => {
186+
expect(stripEmptyLadderEffort({ effort: "high" }, [])).toBeUndefined();
187+
});
188+
189+
test("leaves reasoning untouched when the ladder is unknown or non-empty", () => {
190+
const reasoning = { effort: "high", summary: "auto" };
191+
expect(stripEmptyLadderEffort(reasoning, undefined)).toBe(reasoning);
192+
expect(stripEmptyLadderEffort(reasoning, ["high"])).toBe(reasoning);
193+
});
194+
});
195+
176196
describe("applyEffortCap strip paths", () => {
177197
test("no-effort model strips even a below-cap effort from BOTH shapes, keeping summary", () => {
178198
const config = makeConfig({ effortCap: "high" });

0 commit comments

Comments
 (0)