fix(headroom): skip unsafe responses tool history (#2132)

Guard openai-responses compression: skip Headroom when body.input
contains non-message items (function_call, function_call_output,
reasoning) to preserve the Responses contract instead of collapsing
them into chat messages.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Sutarto Jordan Chrisfivo
2026-06-29 15:59:21 +07:00
committed by decolua
co-authored by Cursor
parent 749c2e3f9c
commit 373850ee36
2 changed files with 69 additions and 0 deletions
@@ -47,4 +47,61 @@ describe("compressWithHeadroom openai-responses format (#1998)", () => {
expect(Array.isArray(body.input[0].content)).toBe(true);
expect(typeof body.input[0].content).not.toBe("string");
});
it("skips Responses tool/reasoning history instead of collapsing it into a message (#2132)", async () => {
global.fetch = vi.fn(async () => ({
ok: true,
json: async () => ({
messages: [{ role: "user", content: "compressed tool history" }],
tokens_saved: 10,
}),
}));
const input = [
{
type: "message",
role: "user",
content: [{ type: "input_text", text: "investigate bug" }],
},
{
type: "function_call",
call_id: "call_apply_patch_123",
name: "apply_patch",
arguments: "*** Begin Patch\n*** End Patch",
},
{
type: "function_call_output",
call_id: "call_apply_patch_123",
output: "ok",
},
{
type: "reasoning",
summary: [{ type: "summary_text", text: "Need a plan" }],
},
];
const body = {
input: structuredClone(input),
tools: [
{
type: "custom",
name: "apply_patch",
format: { type: "grammar", syntax: "lark", definition: "start: /.+/" },
},
],
};
const diagnostics = {};
const data = await compressWithHeadroom(body, {
enabled: true,
url: "http://headroom.test",
model: "gpt-5",
format: "openai-responses",
diagnostics,
});
expect(data).toBeNull();
expect(global.fetch).not.toHaveBeenCalled();
expect(body.input).toEqual(input);
expect(diagnostics.reason).toBe("skipped: openai-responses tool/reasoning input is not safe to compress");
});
});