Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/server/chat-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions tests/codex-integration/model-pinned-effort.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
Loading