Repository navigation
Fix Codex cumulative-as-delta usage; add subtractUsage helper - #6
Merged
Merged
Conversation
- codex adapter: track last cumulative per threadId (LRU-capped) and emit delta = current_cumulative - prior in result.usage. Underlying `codex exec --experimental-json` reports cumulative session totals (openai/codex#17539); unified contract requires per-execute() delta. - usage: add subtractUsage helper, exported from index. - testing: relax assertResumeUsageIndependence to a cumulative-leak bound so cache-heavy adapters (single-digit inputTokens) aren't flaky while still catching the 2x cumulative regression. - new codex.usage.test.ts mocks the SDK and asserts delta across 3 turns. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
result.usage(the unified contract requires per-execute()delta).codex exec --experimental-jsonemits cumulative usage onturn.completed— see Include per-API-call token usage (last) in turn.completed JSONL events openai/codex#17539. Adapter now tracks last-seen cumulative perthreadId(LRU-capped to 256) and yieldscurrent − prior.subtractUsagehelper insrc/usage.ts, exported fromsrc/index.ts.assertResumeUsageIndependencerelaxed to a cumulative-leak bound (max(2× t1, t1+100)) so adapters with single-digitinputTokens(cache-heavy SDKs) aren't flaky from natural variance, while still catching the 2× cumulative regression.src/adapters/codex.usage.test.tsmocks@openai/codex-sdkand asserts delta across three sequential turns on the same thread.Test plan
npm run typecheckpassesnpm test— 145/145 unit tests pass (incl. newcodex.usage.test.ts)🤖 Generated with Claude Code