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.
This commit is contained in:
Resham Joshi 2026-11-06 06:32:33 -08:00
parent 8eca0cdc9e
commit 72ea2067dc
2 changed files with 21 additions and 0 deletions

View file

@ -1355,6 +1355,12 @@ function createParser(source: SessionSource, seenKeys: Set<string>, capture?: {
pendingTools.push(mapped)
const call: ToolCall = { tool: mapped }
const rawArgs = (entry.payload as Record<string, unknown>)['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<string, unknown>)['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<string, unknown> } catch { return null } })()
: typeof rawArgs === 'object' && rawArgs ? rawArgs as Record<string, unknown> : null

View file

@ -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)