Skip to content

Commit 94fbacc

Browse files
committed
fix: avoid orphan function_call outputs when no tools
1 parent a3e0870 commit 94fbacc

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/request/request-transformer.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,14 @@ export async function transformRequestBody(
440440
// DEFAULT MODE: Keep original behavior with tool remap message
441441
body.input = addToolRemapMessage(body.input, !!body.tools);
442442
}
443+
444+
if (!body.tools && body.input) {
445+
body.input = body.input.filter(
446+
(item) =>
447+
item.type !== "function_call" &&
448+
item.type !== "function_call_output",
449+
);
450+
}
443451
}
444452

445453
// Configure reasoning (use normalized model family + model-specific config)

test/request-transformer.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,24 @@ describe('Request Transformer Module', () => {
847847
expect(result.reasoning?.effort).toBe('medium');
848848
});
849849

850+
it('should drop function_call items when no tools present', async () => {
851+
const body: RequestBody = {
852+
model: 'gpt-5-codex',
853+
input: [
854+
{ type: 'message', role: 'user', content: 'hello' },
855+
{ type: 'function_call', role: 'assistant', name: 'write', arguments: '{}' } as any,
856+
{ type: 'function_call_output', role: 'assistant', call_id: 'call_1', output: '{}' } as any,
857+
],
858+
};
859+
860+
const result = await transformRequestBody(body, codexInstructions);
861+
862+
expect(result.tools).toBeUndefined();
863+
expect(result.input).toHaveLength(1);
864+
expect(result.input![0].type).toBe('message');
865+
expect(result.input![0].role).toBe('user');
866+
});
867+
850868
describe('CODEX_MODE parameter', () => {
851869
it('should use bridge message when codexMode=true and tools present (default)', async () => {
852870
const body: RequestBody = {

0 commit comments

Comments
 (0)