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)