[codex] collect Codex usage events#31
Conversation
- Add native Codex UsageEvent collection with last-token precedence, cumulative delta recovery, reset handling, and CODEX_HOME source resolution.\n- Keep legacy Codex session parsing compatible while sharing delta recovery and bounded parallel event parsing.\n- Add EBTA-003 OpenSpec/workspace artifacts and focused regression coverage.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cf24c105ca
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
Adds native UsageEvent production for the Codex provider by parsing local rollout JSONL token_count records into timestamped token deltas, while keeping legacy session collection compatible and improving file parsing throughput via bounded parallelism.
Changes:
- Implement
Provider.CollectUsageEventsfor Codex with delta recovery (last_token_usagepreferred; otherwise cumulativetotal_token_usagediffs with reset handling). - Refactor Codex source-dir resolution to honor
$CODEX_HOME/sessionswhenbaseDiris empty, shared across sessions and events. - Add a generic
provider.ParseUsageEventsParallelhelper and comprehensive Codex tests for the new behaviors.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
provider/codex/parser.go |
Adds Codex usage-event parsing/collection, shared path discovery, CODEX_HOME resolution, and shared delta/reset logic for sessions + events. |
provider/codex/parser_test.go |
Adds tests for Codex native usage events, reset handling, metadata stability, and CODEX_HOME / explicit-dir precedence. |
provider/parallel.go |
Introduces ParseUsageEventsParallel to parse event files with bounded concurrency. |
workspace/EBTA-003/test_strategy.md |
Test strategy and targeted behaviors for EBTA-003. |
workspace/EBTA-003/review.md |
Captures review findings and the implemented fixes. |
workspace/EBTA-003/original_impl.md |
Documents pre-change Codex behavior and test coverage gaps. |
workspace/EBTA-003/new_impl.md |
Implementation plan describing the intended approach and constraints. |
workspace/EBTA-003/final_impl_v1.md |
Finalized implementation spec for the task scope. |
workspace/EBTA-003/final_impl.md |
Pointers/summary for the approved final implementation doc. |
openspec/changes/codex-native-usage-events/.openspec.yaml |
Registers the OpenSpec change (schema + created date). |
openspec/changes/codex-native-usage-events/proposal.md |
Motivation and high-level change summary. |
openspec/changes/codex-native-usage-events/design.md |
Design decisions, trade-offs, and risks. |
openspec/changes/codex-native-usage-events/tasks.md |
Task checklist for tests/implementation/validation. |
openspec/changes/codex-native-usage-events/specs/codex-native-usage-events/spec.md |
Requirements/spec for Codex native event emission and directory resolution. |
docs/plans/2026-04-16-event-based-token-aggregation-task.md |
Updates EBTA task board status to mark EBTA-003 done with verification notes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
UsageEventcollection from local rollouttoken_countrecords.last_token_usage, recover deltas from cumulativetotal_token_usage, handle cumulative counter resets, and honor$CODEX_HOME/sessionswhen no explicit Codex directory is provided.Validation
go test ./provider ./provider/codex -run 'Test(ParseCodexUsageEvents|ParseCodexSession_KeepsFirstSessionMetadataAndSumsResetUsage|CollectCodexUsageEvents|CodexHome)'go test ./provider ./provider/codexmake fmtmake testmake vetmake buildmake lintReview Notes