Skip to content

fix: bucket Codex usage by token_count deltas#11

Merged
aqua5230 merged 1 commit into
aqua5230:mainfrom
ericweichun:codex/upstream-codex-delta
May 27, 2026
Merged

fix: bucket Codex usage by token_count deltas#11
aqua5230 merged 1 commit into
aqua5230:mainfrom
ericweichun:codex/upstream-codex-delta

Conversation

@ericweichun
Copy link
Copy Markdown
Contributor

Summary

  • split Codex cumulative token_count snapshots into per-event deltas before aggregation
  • keep duplicate-session handling by choosing the better complete session log, then flattening its delta entries
  • fixes period buckets like Today / 7d / 30d so older cumulative usage does not leak into newer ranges

Test plan

  • .venv/bin/python -m ruff check codex_loader.py tests/test_codex_loader.py
  • .venv/bin/python -m mypy .
  • .venv/bin/python -m pytest tests/test_codex_loader.py tests/test_analyzer_pipeline.py tests/test_menubar.py

Notes for reviewer

This keeps the rate-limit parser unchanged. It only changes the historical usage entries emitted from Codex session logs so downstream aggregators can bucket usage by each token_count event timestamp.

Copy link
Copy Markdown
Owner

@aqua5230 aqua5230 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the careful change. The semantic shift from cumulative to delta makes sense for accurate bucketing, but it
leaves v0.11.6's fast path inconsistent: analyzer/reporter.py:115-212 (_load_recent_codex_entries and
_parse_codex_file) still reads the final cumulative snapshot and uses session-start time as the entry timestamp, so
today/week/month reports will diverge from what the popover shows once your new loader lands.

Could you:

  1. Either reuse codex_loader's new delta logic in the reporter fast path, or update _load_recent_codex_entries to
    bucket by token_count event timestamp the same way?
  2. Add a reporter-layer test proving today/week/month reports pick up the deltas (not just the loader-level test)?

Happy to merge once these are in.

@ericweichun ericweichun force-pushed the codex/upstream-codex-delta branch from 446f377 to 3d24caa Compare May 27, 2026 01:02
@ericweichun
Copy link
Copy Markdown
Contributor Author

Updated, thanks. I rebased onto current main and removed the separate reporter Codex cumulative fast parser. The reporter recent path now reuses codex_loader.load_entries(hours_back=...), so today/week/month reports use the same token_count delta logic as the popover. I also added a reporter-layer today test that exercises a cross-day cumulative Codex session and verifies only the current-day delta is counted.\n\nValidation run locally:\n- .venv/bin/python -m pytest tests/test_codex_loader.py tests/test_analyzer_pipeline.py\n- .venv/bin/python -m ruff check analyzer/reporter.py tests/test_analyzer_pipeline.py\n- .venv/bin/python -m mypy .

@aqua5230 aqua5230 merged commit dbebe8e into aqua5230:main May 27, 2026
1 check passed
aqua5230 added a commit that referenced this pull request May 27, 2026
- fix(badge): clear update hint immediately after upgrade past cached latest
- fix(reporter): bucket Codex usage by token_count deltas (#11, @ericweichun)
- fix(reports): tie All Time reports to project range selector (#15, @ericweichun)
- fix(refresh): queue manual refresh while busy (#12, @ericweichun)
- docs(setup): make setup guidance agent-neutral (#16, @ericweichun)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

2 participants