Repository navigation
feat(responses): degrade background mode to synchronous execution #2164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
diegosouzapw
merged 3 commits into
cheaper-inference:release/v3.8.0
from
NomenAK:upstream/responses-background-degrade
May 12, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,7 +110,7 @@ test("Responses -> Chat filters orphan tool outputs and supports role-based mess | |
| }); | ||
| }); | ||
|
|
||
| test("Responses -> Chat rejects unsupported built-in tools and background mode", () => { | ||
| test("Responses -> Chat rejects unsupported built-in tools", () => { | ||
| assert.throws( | ||
| () => | ||
| openaiResponsesToOpenAIRequest( | ||
|
|
@@ -124,20 +124,77 @@ test("Responses -> Chat rejects unsupported built-in tools and background mode", | |
| ), | ||
| (error: any) => error.statusCode === 400 && error.errorType === "unsupported_feature" | ||
| ); | ||
| }); | ||
|
|
||
| assert.throws( | ||
| () => | ||
| openaiResponsesToOpenAIRequest( | ||
| "gpt-4o", | ||
| { | ||
| input: [], | ||
| background: true, | ||
| }, | ||
| false, | ||
| null | ||
| ), | ||
| (error: any) => error.statusCode === 400 && error.errorType === "unsupported_feature" | ||
| ); | ||
| test("Responses -> Chat strips background flag and degrades to synchronous execution", () => { | ||
| // Previously this threw 400 unsupported_feature. OmniRoute is a forward proxy | ||
| // and cannot host the deferred run + poll contract, so background=true is | ||
| // silently dropped and the request runs synchronously. Clients that set the | ||
| // flag opportunistically (Capy Captain Pro, Codex agents) work unchanged. | ||
| const warnLog: string[] = []; | ||
| const originalWarn = console.warn; | ||
| console.warn = (msg: unknown) => warnLog.push(String(msg)); | ||
| try { | ||
| const result = openaiResponsesToOpenAIRequest( | ||
| "gpt-5.5", | ||
| { | ||
| input: [{ role: "user", content: [{ type: "input_text", text: "hi" }] }], | ||
| background: true, | ||
| }, | ||
| true, | ||
| { provider: "codex" } | ||
| ); | ||
| const r = result as Record<string, unknown>; | ||
| assert.equal(r.background, undefined, "background flag must be stripped from output"); | ||
| assert.ok(Array.isArray(r.messages), "translation must complete and produce messages"); | ||
| assert.equal((r.messages as unknown[]).length, 1, "user message must be preserved"); | ||
| assert.ok( | ||
| warnLog.some((m) => m.startsWith("BACKGROUND_DEGRADE provider=codex model=gpt-5.5")), | ||
| "BACKGROUND_DEGRADE warning log must be emitted when background=true" | ||
| ); | ||
| } finally { | ||
| console.warn = originalWarn; | ||
| } | ||
| }); | ||
|
|
||
| test("Responses -> Chat passes through when background flag is unset or false (no degrade log)", () => { | ||
| // Verifies the inverse of the degradation case: when background is absent or | ||
| // explicitly false, no warning should be emitted and the request body should | ||
| // not carry a residual background field. Guards against accidental log spam | ||
| // and confirms the degradation logic is conditional on background === true. | ||
| const warnLog: string[] = []; | ||
| const originalWarn = console.warn; | ||
| console.warn = (msg: unknown) => warnLog.push(String(msg)); | ||
| try { | ||
| // Case 1: background unset | ||
| const r1 = openaiResponsesToOpenAIRequest( | ||
| "gpt-5.5", | ||
| { input: [{ role: "user", content: [{ type: "input_text", text: "hi" }] }] }, | ||
| true, | ||
| { provider: "codex" } | ||
| ) as Record<string, unknown>; | ||
| assert.equal(r1.background, undefined, "background must be absent on output (unset case)"); | ||
|
|
||
| // Case 2: background explicitly false | ||
| const r2 = openaiResponsesToOpenAIRequest( | ||
| "gpt-5.5", | ||
| { | ||
| input: [{ role: "user", content: [{ type: "input_text", text: "hi" }] }], | ||
| background: false, | ||
| }, | ||
| true, | ||
| { provider: "codex" } | ||
| ) as Record<string, unknown>; | ||
| assert.equal(r2.background, undefined, "background must be stripped on output (false case)"); | ||
|
|
||
| assert.equal( | ||
| warnLog.filter((m) => m.startsWith("BACKGROUND_DEGRADE")).length, | ||
| 0, | ||
| "BACKGROUND_DEGRADE must NOT be emitted for unset or false values" | ||
| ); | ||
| } finally { | ||
| console.warn = originalWarn; | ||
| } | ||
| }); | ||
|
Comment on lines
+129
to
198
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| test("Chat -> Responses converts messages, tool calls, tool outputs, tools and pass-through params", () => { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation is missing the warning log (
BACKGROUND_DEGRADE) mentioned in the PR description. This log is important for operators to identify clients that are requesting background mode and being degraded to synchronous execution.Additionally, the current logic strips the
backgroundfield even when it isfalse, which contradicts the "passthrough" behavior described in the PR summary for that case. While stripping it is generally safer for the downstream Chat API, the logging should be conditional onbackground: true.