Fix stack 06: per-turn Codex usage + session_id fallback parity#30
Merged
ebarti merged 2 commits intoJul 2, 2026
Merged
Conversation
23347cc to
2715737
Compare
f02dec5 to
a471d02
Compare
2715737 to
22d6a8b
Compare
a471d02 to
1af8343
Compare
22d6a8b to
1a81ea9
Compare
…tigravity
- Codex reported thread-cumulative usage ('total'), re-counting every prior
turn's tokens on a resumed thread. Now prefers the per-turn breakdown ('last')
and falls back to 'total' only when absent.
- Codex/Antigravity returned session_id=None whenever the SDK object did not echo
an id, even when the caller passed session_id/resume_from, breaking session
chaining (Claude already fell back to the task id). Both now fall back to the
caller's conversation id.
Refs REVIEW.md §1.6, §4.
…ract The Usage dataclass documents input_tokens as prompt tokens EXCLUDING cache reads (reported separately in cache_read_tokens), and the Antigravity adapter already normalizes that way. Codex passed OpenAI's cache-inclusive input_tokens through while also filling cache_read_tokens, double-counting cached tokens across the two fields and skewing cross-vendor comparisons. Subtract cached from input_tokens (clamped at 0 against vendor misreports). The total_tokens fallback keeps vendor semantics: raw input including cached, plus output.
e222a2a to
eccd48c
Compare
1a81ea9 to
9d1b3ca
Compare
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.
Stacked review-fix PR 6/N (base:
review-fixes/05-permissions).REVIEW.md §1.6, §4:
_codex_usagereadusage.total, so a resumed thread re-reported every prior turn's tokens (inflating usage and cost accounting). Now prefers the per-turnusage.last, falling back tototalwhen absent.session_idfell toNoneon Codex/Antigravity whenever the SDK object didn't echo an id — even when the caller passedsession_id/resume_from— breaking session chaining (Claude already fell back to the task id). Both now fall back to the caller's conversation id.Tests: per-turn usage preference, Codex + Antigravity session-id fallback. Full suite 165 passed / 12 skipped; ruff + mypy strict clean.
Round 2 (re-review follow-up)
Usage.input_tokensnow excludes cached input tokens (OpenAI reports them insideinput_tokens; our contract and the Antigravity adapter report cache reads separately incache_read_tokens). Clamped at 0 against vendor misreports; the vendor-styletotal_tokensfallback keeps raw semantics. Tests added.