mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-11-29 10:43:47 +00:00
fix(codex): key cumulative calls on resolved totals
An omitted cumulative field reads as unchanged, but the dedup key still
took it as 0, so {input:150,total:160} and the same record with an
explicit unchanged output:10 got different keys. Key on the resolved
running totals so both forms share one key.
This commit is contained in:
parent
bfd3437236
commit
ea69a08ffb
2 changed files with 23 additions and 1 deletions
|
|
@ -1704,8 +1704,10 @@ function createParser(source: SessionSource, seenKeys: Set<string>, capture?: {
|
|||
// Two rollouts of one thread at identical cumulative totals are the
|
||||
// same calls replayed (resume), so sharing this key is intended. After
|
||||
// a counter restart the same totals are new calls: the epoch tells.
|
||||
// The prev counters hold the resolved totals (an omitted field reads
|
||||
// as unchanged), so omitted and explicit forms share one key.
|
||||
const dedupKey = reportsCumulative
|
||||
? `codex:${forkedFromId || threadId}:${cumulativeTotal}:${total?.input_tokens ?? 0}:${total?.cached_input_tokens ?? 0}:${total?.output_tokens ?? 0}:${total?.reasoning_output_tokens ?? 0}${restartEpoch ? `:r${restartEpoch}` : ''}`
|
||||
? `codex:${forkedFromId || threadId}:${cumulativeTotal}:${prevInput}:${prevCached}:${prevOutput}:${prevReasoning}${restartEpoch ? `:r${restartEpoch}` : ''}`
|
||||
: `codex:record:${JSON.stringify([source.path, tracker.lastCompleteLineOffset])}`
|
||||
|
||||
accountUsage(entry, {
|
||||
|
|
|
|||
|
|
@ -887,6 +887,26 @@ describe('codex provider - JSONL parsing', () => {
|
|||
expect(calls.map(c => [c.inputTokens, c.outputTokens])).toEqual([[8_000, 800], [3_000, 0], [3_000, 300]])
|
||||
})
|
||||
|
||||
it('keys an omitted cumulative field like the same value written out', async () => {
|
||||
const total = (timestamp: string, usage: Record<string, number>) => JSON.stringify({
|
||||
type: 'event_msg', timestamp, payload: { type: 'token_count', info: { total_token_usage: usage } },
|
||||
})
|
||||
const keys: string[][] = []
|
||||
for (const [name, second] of [['omitted', { input_tokens: 150, total_tokens: 160 }], ['explicit', { input_tokens: 150, output_tokens: 10, total_tokens: 160 }]] as const) {
|
||||
const filePath = await writeSession(tmpDir, '2026-04-14', `rollout-key-${name}.jsonl`, [
|
||||
sessionMeta({ session_id: 'sess-key-form', model: 'gpt-5.5' }),
|
||||
total('2026-04-14T10:00:10Z', { input_tokens: 100, output_tokens: 10, total_tokens: 110 }),
|
||||
total('2026-04-14T10:00:20Z', second),
|
||||
])
|
||||
const calls: ParsedProviderCall[] = []
|
||||
for await (const call of createCodexProvider(tmpDir).createSessionParser({ path: filePath, project: 'test', provider: 'codex' }, new Set()).parse()) calls.push(call)
|
||||
keys.push(calls.map(c => c.deduplicationKey))
|
||||
}
|
||||
|
||||
expect(keys[0]).toHaveLength(2)
|
||||
expect(keys[0]).toEqual(keys[1])
|
||||
})
|
||||
|
||||
it('reads a small drop in every field as a correction, not a restart', async () => {
|
||||
const filePath = await writeSession(tmpDir, '2026-04-14', 'rollout-cumulative-downward.jsonl', [
|
||||
sessionMeta({ session_id: 'sess-downward', model: 'gpt-5.5' }),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue