fix(codex): deduplicate copied branch history#989
Conversation
|
Thanks a lot for the incredibly quick turnaround on this. From reading the PR, the fix looks aligned with the issue I reported in #988: Codex Desktop branched conversations should not cause historical usage to be counted again. From the reporter side, this looks like the right direction. Happy to see this merged once CI is green and the maintainers are comfortable with it. |
c5a2e1f to
54abc64
Compare
|
Maintainer check after rebasing this onto current main:
Validation run locally:
Decision: merge once bot checks finish. This one is directly reproduced by local real data and matches #988. |
@ccusage/amp
ccusage
@ccusage/codex
@ccusage/opencode
@ccusage/pi
commit: |
54abc64 to
a263355
Compare
|
Follow-up: replaced the initial JSON.stringify-based fingerprint with a fixed-separator string key. Local Codex data timing for loadTokenUsageEvents(), 5 runs each:
So the previous CI large-fixture slowdown was likely from JSON.stringify allocation/serialization overhead. The branch has been force-pushed and CI is running again. |
Deduplicate Codex token usage events with a session-independent fingerprint so branched or repeated session files do not count copied history more than once. Add regression coverage for copied branch history and validate against local Codex logs, where the current parser produced thousands of duplicate token events.
a263355 to
6a8c825
Compare
|
Updated after merging #1013 into main and rebasing this PR. Head SHA: 6a8c825 Local validation after rebase:
The perf workflow should now always write results to the Actions job summary and attempt the PR comment best-effort. |

Fixes duplicated Codex Desktop usage when a branch/forked conversation copies historical JSONL token events into another session file.
What changed:
@ccusage/codexso copied historicaltoken_countevents are counted once across session files.Verification:
npx -y pnpm@10.30.1 --filter @ccusage/codex test src/data-loader.tsnpx -y pnpm@10.30.1 --filter @ccusage/codex typechecknpx -y pnpm@10.30.1 run lint --fixfromapps/codexgit diff --checkCloses #988.
Summary by CodeRabbit
Bug Fixes
Tests