Skip to content

Commit e1769b5

Browse files
SOSANAnoreply
andauthored
fix(server): default store:false on /v1/responses inbound when omitted (#1743)
* fix(server): default store:false on /v1/responses inbound when omitted Generic Responses-API clients (AI-SDK apps such as ZCode) omit store, but the Codex backend rejects a native request without an explicit store:false ("Store must be set to false"). The chat-completions inbound already defaults store:false when absent (src/server/chat-completions.ts); apply the same default to the /v1/responses inbound so generic Responses clients work against native openai routes. Explicit values are never overridden. Adjacent context: #882 covered the outbound forward path. * fix(server): scope store:false default to the canonical forward Codex backend The unconditional /v1/responses inbound default also hit stateful key-auth Responses upstreams (official OpenAI API, gateways), where an omitted store intentionally enables server-side storage for later previous_response_id continuation. Apply the default only after routing settles and only for authMode "forward" + openai-responses providers, mirroring the provider-level forward predicate in usesCodexForwardPoolAuth. Explicit store values are never overridden. Adds a key-auth negative regression test alongside the forward positive cases. * test(responses): pin forward-route explicit store:false preservation Completes the auth-mode x explicit-value matrix in the store-default regression suite: forward-auth routes must keep an explicit store:false untouched, not just an explicit store:true. * fix(server): gate store:false default on the canonical Codex forward base URL Per review: reuse isCanonicalOpenAiForwardProvider() so custom Responses- compatible forward gateways keep the omitted-store server-side default instead of receiving an injected store:false. Adds the requested negative regression (non-canonical forward gateway + omitted store stays omitted) and points the forward fixtures at the canonical Codex base URL. --------- Co-authored-by: SOSANA <[email protected]>
1 parent 7d4ac11 commit e1769b5

2 files changed

Lines changed: 135 additions & 0 deletions

File tree

‎src/server/responses/core.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,19 @@ async function applyFinalRouteRequestNormalization(args: {
10801080
}
10811081
}
10821082

1083+
// Generic Responses clients (e.g. AI-SDK apps) omit `store`, but the canonical
1084+
// forward Codex backend rejects a native request without an explicit store:false.
1085+
// Default it only there — every other Responses upstream (key-auth providers and
1086+
// custom forward gateways) intentionally keeps the omitted-store server-side
1087+
// default for previous_response_id reuse — and never override an explicit value.
1088+
if (
1089+
isCanonicalOpenAiForwardProvider(route.provider)
1090+
&& parsed._rawBody && typeof parsed._rawBody === "object"
1091+
&& (parsed._rawBody as Record<string, unknown>).store === undefined
1092+
) {
1093+
(parsed._rawBody as Record<string, unknown>).store = false;
1094+
}
1095+
10831096
// Final selected model before virtual wire-model rewriting (Pro aliases).
10841097
const finalSelectedModelId = route.modelId;
10851098

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/**
2+
* Generic Responses-API clients (AI-SDK apps such as ZCode) omit `store`, but the
3+
* canonical forward Codex backend rejects a native request without an explicit
4+
* store:false ("Store must be set to false"). The default is applied only after
5+
* routing settles and only on the canonical Codex forward backend
6+
* (isCanonicalOpenAiForwardProvider: adapter + forward auth + the canonical base
7+
* URL). Every other Responses upstream — key-auth providers and custom forward
8+
* gateways alike — intentionally keeps the omitted-store server-side default so a
9+
* later turn can continue through an unexpanded previous_response_id. These tests
10+
* pin the scoped default (forward positive cases), the key-auth and custom-gateway
11+
* negatives, and explicit-value survival on both sides.
12+
*
13+
* End-to-end cases assert the captured upstream request body — the externally
14+
* observable payload. Pattern mirrors tests/responses-compaction-routing.test.ts
15+
* and tests/github-copilot-wire-defaults.test.ts.
16+
*/
17+
import { afterEach, describe, expect, test } from "bun:test";
18+
import { CODEX_FORWARD_BASE_URL } from "../src/providers/openai-tiers";
19+
import { handleResponses } from "../src/server/responses";
20+
import type { OcxConfig, OcxProviderConfig } from "../src/types";
21+
22+
function providerConfig(overrides: Partial<OcxProviderConfig> = {}): OcxConfig {
23+
return {
24+
defaultProvider: "gw",
25+
providers: {
26+
gw: {
27+
adapter: "openai-responses",
28+
baseUrl: CODEX_FORWARD_BASE_URL,
29+
authMode: "key",
30+
apiKey: "test-key",
31+
...overrides,
32+
},
33+
},
34+
} as unknown as OcxConfig;
35+
}
36+
37+
describe("/v1/responses defaults store:false only for the canonical forward Codex backend", () => {
38+
const originalFetch = globalThis.fetch;
39+
afterEach(() => { globalThis.fetch = originalFetch; });
40+
41+
function captureUpstream(): { urls: string[]; bodies: string[] } {
42+
const urls: string[] = [];
43+
const bodies: string[] = [];
44+
globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
45+
urls.push(String(input));
46+
const body =
47+
input instanceof Request ? await input.clone().text()
48+
: typeof init?.body === "string" ? init.body
49+
: "";
50+
bodies.push(body);
51+
return new Response("data: [DONE]\n\n", {
52+
status: 200,
53+
headers: { "content-type": "text/event-stream" },
54+
});
55+
}) as typeof fetch;
56+
return { urls, bodies };
57+
}
58+
59+
async function drive(
60+
config: OcxConfig,
61+
store: unknown,
62+
): Promise<{ url: string; body: Record<string, unknown> | null }> {
63+
const { urls, bodies } = captureUpstream();
64+
await handleResponses(
65+
new Request("http://localhost/v1/responses", {
66+
method: "POST",
67+
headers: { "content-type": "application/json" },
68+
body: JSON.stringify({
69+
model: "gw/some-model",
70+
input: [{ type: "message", role: "user", content: [{ type: "input_text", text: "ping" }] }],
71+
stream: true,
72+
...(store === undefined ? {} : { store }),
73+
}),
74+
}),
75+
config,
76+
{ model: "", provider: "" },
77+
);
78+
let parsed: Record<string, unknown> | null = null;
79+
try { parsed = bodies[0] ? (JSON.parse(bodies[0]) as Record<string, unknown>) : null; } catch { parsed = null; }
80+
return { url: urls[0] ?? "", body: parsed };
81+
}
82+
83+
test("forward route: omitted store reaches the upstream Responses request as false", async () => {
84+
const { url, body } = await drive(providerConfig({ authMode: "forward" }), undefined);
85+
expect(url).toContain("/responses");
86+
expect(body).not.toBeNull();
87+
expect((body as Record<string, unknown>).store).toBe(false);
88+
});
89+
90+
test("key-auth route: omitted store is NOT injected (stateful upstream keeps its default)", async () => {
91+
const { body } = await drive(providerConfig(), undefined);
92+
expect(body).not.toBeNull();
93+
expect(!("store" in (body as Record<string, unknown>))).toBe(true);
94+
});
95+
96+
test("custom forward gateway: omitted store is NOT injected (non-canonical base URL keeps its default)", async () => {
97+
const { body } = await drive(
98+
providerConfig({ authMode: "forward", baseUrl: "https://gateway.example/v1" }),
99+
undefined,
100+
);
101+
expect(body).not.toBeNull();
102+
expect(!("store" in (body as Record<string, unknown>))).toBe(true);
103+
});
104+
105+
test("forward route: explicit store:true is preserved", async () => {
106+
const { body } = await drive(providerConfig({ authMode: "forward" }), true);
107+
expect(body).not.toBeNull();
108+
expect((body as Record<string, unknown>).store).toBe(true);
109+
});
110+
111+
test("forward route: explicit store:false is preserved", async () => {
112+
const { body } = await drive(providerConfig({ authMode: "forward" }), false);
113+
expect(body).not.toBeNull();
114+
expect((body as Record<string, unknown>).store).toBe(false);
115+
});
116+
117+
test("key-auth route: explicit store:false is preserved", async () => {
118+
const { body } = await drive(providerConfig(), false);
119+
expect(body).not.toBeNull();
120+
expect((body as Record<string, unknown>).store).toBe(false);
121+
});
122+
});

0 commit comments

Comments
 (0)