From 72ea2067dcc1cc45602f54deb37361f80fe23eeb Mon Sep 17 00:00:00 2001 From: Resham Joshi <65915470+iamtoruk@users.noreply.github.com> Date: Fri, 6 Nov 2026 06:32:33 -0800 Subject: [PATCH] fix(codex): count tool-call output toward a null-ping estimate A turn whose only output is a tool call (no assistant text) reached the null-info ping with no pending output, so the ping rule dropped it and a priceable request vanished. A function or custom tool call's name and arguments now count as pending output, so such a turn keeps one estimated call. Owner data: 0 such turns (706 null pings, none after a tool-only turn), so no real figure moves. Restart threshold stays at a tenth. All 10 real total drops fall to at most 0.3% of the prior total; none lies between 0.3% and 100%, so any cut in that range is a judgement. A tenth keeps a 30x margin on the real resets, while the half rule double counted corrections; a reset to 25% (8800 -> 2200) reads as a correction and undercounts, which no real rollout shows. --- src/providers/codex.ts | 6 ++++++ tests/providers/codex.test.ts | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/providers/codex.ts b/src/providers/codex.ts index 857fc7b0..da0c8875 100644 --- a/src/providers/codex.ts +++ b/src/providers/codex.ts @@ -1355,6 +1355,12 @@ function createParser(source: SessionSource, seenKeys: Set, capture?: { pendingTools.push(mapped) const call: ToolCall = { tool: mapped } const rawArgs = (entry.payload as Record)['arguments'] + // The model generated this call, so a tool-only turn still has output + // for the null-ping estimate. + const rawInput = (entry.payload as Record)['input'] + pendingOutputChars += rawName.length + + (typeof rawArgs === 'string' ? rawArgs.length : rawArgs ? JSON.stringify(rawArgs).length : 0) + + (typeof rawInput === 'string' ? rawInput.length : 0) const args = typeof rawArgs === 'string' ? (() => { try { return JSON.parse(rawArgs) as Record } catch { return null } })() : typeof rawArgs === 'object' && rawArgs ? rawArgs as Record : null diff --git a/tests/providers/codex.test.ts b/tests/providers/codex.test.ts index 0fcddda3..adb82074 100644 --- a/tests/providers/codex.test.ts +++ b/tests/providers/codex.test.ts @@ -987,6 +987,21 @@ describe('codex provider - JSONL parsing', () => { expect(calls[0]).toMatchObject({ inputTokens: 5_000, outputTokens: 200, userMessage: 'fix the failing test' }) }) + it('keeps a tool-only turn that ends without measured usage as one estimated call', async () => { + const filePath = await writeSession(tmpDir, '2026-04-14', 'rollout-ping-tool-only.jsonl', [ + sessionMeta({ session_id: 'sess-ping-tool-only', model: 'gpt-5.5' }), + userMessage('run the test suite'), + JSON.stringify({ type: 'response_item', timestamp: '2026-04-14T10:00:03Z', payload: { type: 'function_call', name: 'exec_command', arguments: JSON.stringify({ cmd: 'npm test' }), call_id: 'call-1' } }), + JSON.stringify({ type: 'event_msg', timestamp: '2026-04-14T10:00:04Z', payload: { type: 'token_count', info: null, rate_limits: { primary: { used_percent: 3 } } } }), + ]) + const calls: ParsedProviderCall[] = [] + for await (const call of createCodexProvider(tmpDir).createSessionParser({ path: filePath, project: 'test', provider: 'codex' }, new Set()).parse()) calls.push(call) + + expect(calls).toHaveLength(1) + expect(calls[0]).toMatchObject({ costIsEstimated: true, tools: ['Bash'], userMessage: 'run the test suite' }) + expect(calls[0]!.outputTokens).toBeGreaterThan(0) + }) + it('stays an estimated call when the turn ends without measured usage', async () => { const calls = await parse(false) expect(calls).toHaveLength(1)