Skip to content

Commit 10ff220

Browse files
committed
fix(responses): strip all structured-output traces from routed compaction
1 parent db284da commit 10ff220

5 files changed

Lines changed: 53 additions & 3 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ non-empty `messages` array. It translates system, user, assistant, and tool mess
138138
Responses items; translates function tools, tool choice, images, reasoning effort, and supported
139139
response formats; runs the normal Responses routing pipeline; then translates the result back.
140140

141+
Structured output is part of that translation: `response_format` with `json_object` or
142+
`json_schema` is forwarded to routed `openai-chat` models as-is, and rides the raw request body
143+
on native Responses routes. A backend without structured-output support returns its own error
144+
instead of the proxy rejecting the request locally. The same applies to `text.format` on
145+
`POST /v1/responses` when the model routes to an `openai-chat` provider.
146+
141147
Non-streaming output has `object: "chat.completion"`. Streaming output uses SSE objects with
142148
`object: "chat.completion.chunk"`, choice deltas, a terminal choice with `finish_reason`, and
143149
`data: [DONE]`. Tool-call and usage information are translated back where the source events carry

‎src/adapters/openai-responses.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,8 @@ function stripInputImagesDeep(value: unknown): unknown {
10481048
*/
10491049
function buildRoutedCompactionBody(body: unknown): unknown {
10501050
if (!isPlainObject(body)) return body;
1051-
const { tools: _tools, tool_choice: _toolChoice, parallel_tool_calls: _parallel, ...rest } = body;
1051+
// `text` goes with the tool fields: the summary must be prose, not schema-constrained JSON.
1052+
const { tools: _tools, tool_choice: _toolChoice, parallel_tool_calls: _parallel, text: _text, ...rest } = body;
10521053
const input = Array.isArray(body.input) ? body.input : [];
10531054
const kept = input.filter(item => !isPlainObject(item)
10541055
// `additional_tools` is how Codex Desktop's responses-lite shape carries tools;

‎src/server/responses/core.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1665,8 +1665,14 @@ async function handleResponsesInner(
16651665
delete parsed.options.toolChoice;
16661666
delete parsed.options.parallelToolCalls;
16671667
// The compaction turn is a plain prose summary; a surviving structured-output format
1668-
// would force schema-constrained JSON into the synthetic compaction item.
1668+
// would force schema-constrained JSON into the synthetic compaction item. The flag and
1669+
// the raw `text` controls go too: Kiro's capability guard reads both and would reject
1670+
// the turn outright, and the key-mode openai-responses adapter builds from _rawBody.
16691671
delete parsed.options.textFormat;
1672+
delete parsed._structuredOutput;
1673+
if (parsed._rawBody && typeof parsed._rawBody === "object") {
1674+
delete (parsed._rawBody as Record<string, unknown>).text;
1675+
}
16701676
parsed.context.messages.push({ role: "user", content: COMPACT_PROMPT, timestamp: Date.now() });
16711677
}
16721678

‎tests/responses-compaction-routing.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,9 @@ describe("routed compaction for key-mode openai-responses (#422)", () => {
398398
}) as typeof fetch;
399399

400400
const res = await handleResponses(
401-
compactionRequest(baseCompactionBody()),
401+
compactionRequest(baseCompactionBody({
402+
text: { format: { type: "json_schema", name: "answer", schema: { type: "object" } } },
403+
})),
402404
keyProviderConfig(),
403405
{ model: "", provider: "" },
404406
);
@@ -411,6 +413,8 @@ describe("routed compaction for key-mode openai-responses (#422)", () => {
411413
expect(sent.tools).toBeUndefined();
412414
expect(sent.tool_choice).toBeUndefined();
413415
expect(sent.parallel_tool_calls).toBeUndefined();
416+
// The summarizer must stay prose: a surviving text.format would force schema JSON.
417+
expect(sent.text).toBeUndefined();
414418
expect(JSON.stringify(input)).toContain("CONTEXT CHECKPOINT COMPACTION");
415419

416420
const json = await res.json() as { output?: Array<{ type?: string }> };

‎tests/server-kiro-completion-e2e.test.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,37 @@ describe("Kiro completion through public server endpoints", () => {
216216
upstream.server.stop(true);
217217
}
218218
});
219+
220+
test("routed compaction with text.format summarizes instead of tripping the capability guard", async () => {
221+
const upstream = scriptedKiroUpstream([
222+
[textFrame("Compaction summary of the earlier turns.")],
223+
]);
224+
saveConfig(kiroConfig(upstream.server.url.toString()));
225+
const proxy = startServer(0);
226+
try {
227+
const response = await originalFetch(new URL("/v1/responses", proxy.url), {
228+
method: "POST",
229+
headers: { "content-type": "application/json" },
230+
body: JSON.stringify({
231+
model: "kiro-test/gpt-5.6-sol",
232+
stream: false,
233+
input: [
234+
{ type: "message", role: "user", content: [{ type: "input_text", text: "earlier turn" }] },
235+
{ type: "compaction_trigger" },
236+
],
237+
// Routed compaction must strip the structured-output request; before the strip,
238+
// Kiro's capability guard rejected the whole turn as unsupported text controls.
239+
text: { format: { type: "json_schema", name: "answer", schema: { type: "object" } } },
240+
}),
241+
});
242+
243+
expect(response.status).toBe(200);
244+
const json = await response.json() as { output?: Array<{ type?: string }> };
245+
expect((json.output ?? []).filter(item => item.type === "compaction")).toHaveLength(1);
246+
expect(upstream.requests).toHaveLength(1);
247+
} finally {
248+
await proxy.stop(true);
249+
upstream.server.stop(true);
250+
}
251+
});
219252
});

0 commit comments

Comments
 (0)