Skip to content

Fix stack 06: per-turn Codex usage + session_id fallback parity#30

Merged
ebarti merged 2 commits into
review-fixes/05-permissionsfrom
review-fixes/06-usage-session
Jul 2, 2026
Merged

Fix stack 06: per-turn Codex usage + session_id fallback parity#30
ebarti merged 2 commits into
review-fixes/05-permissionsfrom
review-fixes/06-usage-session

Conversation

@ebarti

@ebarti ebarti commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Stacked review-fix PR 6/N (base: review-fixes/05-permissions).

REVIEW.md §1.6, §4:

  • Codex usage was thread-cumulative. _codex_usage read usage.total, so a resumed thread re-reported every prior turn's tokens (inflating usage and cost accounting). Now prefers the per-turn usage.last, falling back to total when absent.
  • session_id fell to None on Codex/Antigravity whenever the SDK object didn't 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.

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_tokens now excludes cached input tokens (OpenAI reports them inside input_tokens; our contract and the Antigravity adapter report cache reads separately in cache_read_tokens). Clamped at 0 against vendor misreports; the vendor-style total_tokens fallback keeps raw semantics. Tests added.

@ebarti ebarti force-pushed the review-fixes/06-usage-session branch from 23347cc to 2715737 Compare July 2, 2026 10:00
@ebarti ebarti force-pushed the review-fixes/05-permissions branch from f02dec5 to a471d02 Compare July 2, 2026 10:00
@ebarti ebarti force-pushed the review-fixes/06-usage-session branch from 2715737 to 22d6a8b Compare July 2, 2026 10:26
@ebarti ebarti force-pushed the review-fixes/05-permissions branch from a471d02 to 1af8343 Compare July 2, 2026 10:26
@ebarti ebarti force-pushed the review-fixes/06-usage-session branch from 22d6a8b to 1a81ea9 Compare July 2, 2026 10:41
ebarti added 2 commits July 2, 2026 16:52
…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.
@ebarti ebarti force-pushed the review-fixes/05-permissions branch from e222a2a to eccd48c Compare July 2, 2026 15:13
@ebarti ebarti force-pushed the review-fixes/06-usage-session branch from 1a81ea9 to 9d1b3ca Compare July 2, 2026 15:13
@ebarti ebarti merged commit 9d1b3ca into review-fixes/05-permissions Jul 2, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant