Conversation
…gree `node9 scan --days 30` counted EVERY Codex session ever recorded. Measured on real data: 41 sessions / $13.69 from scan against 25 / $1.04 from `node9 report --period 30d` — same shared pricing function, 13x apart, because one windowed and the other did not. `scanCodexHistory` takes `startDate` and used it exactly once, on a guard that runs only for `response_item` / `function_call` rows. That filters findings and loops. Token counts arrive as `event_msg` and never reach it, and `total_token_usage` is cumulative, so the cost added was always the session's whole lifetime regardless of the window. Now windowed at session level, matching report-audit.ts:658. scan --days 30 $13.69 -> $1.04 (report says $1.04) scan --all $13.69 (unchanged) DELIBERATELY NOT the ccusage per-event-delta approach. Converting cumulative usage into deltas is the more correct model for a session straddling the window edge, and I proposed it yesterday. Then I measured: ZERO of 41 sessions straddle. It would have solved a case this data does not contain while leaving the real defect — a filter that was never applied — untouched. Recorded with the evidence in doc/roadmap/active/cost-accuracy-and-plans.md for when a straddling session actually appears. A session with no `session_meta` timestamp is excluded once a window is set, matching report-audit.ts:656. It cannot be placed in time and the whole point here is that the two paths agree. Mutation testing earned its keep twice. It killed removing the filter and killed a variant that breaks `--all` — the trap I flagged before writing any code, since the obvious filter also silences full-history scans. And it exposed that my no-timestamp test asserted only "did not crash", which every variant passed; it now asserts the behaviour, and a variant that counts an unplaceable session turns it red.
Contributor
🛡️ node9 agent-security · ✅No agent-security findings — no injectable workflows, unsafe agent configs, or unpinned MCP servers. |
Contributor
Author
|
🎉 This PR is included in version 2.7.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
node9 scan --days 30counted every Codex session ever recorded. Measured on real data: 41 sessions /$13.69from scan against 25 /$1.04fromnode9 report --period 30d— same shared pricing function, 13x apart, because one windowed and the other did not.Why it hid
scanCodexHistorytakesstartDateand used it exactly once, on a guard that runs only forresponse_item/function_callrows. That filters findings and loops. Token counts arrive asevent_msgand never reach it, andtotal_token_usageis cumulative — so the cost added was always the session's whole lifetime, regardless of the window.Now windowed at session level, matching
report-audit.ts:658.All three agents now agree across both paths:
Deliberately NOT the ccusage delta approach
Converting cumulative usage into per-event deltas is the more correct model for a session straddling the window edge, and I proposed exactly that yesterday. Then I measured: zero of 41 sessions straddle. It would have solved a case this data does not contain while leaving the real defect — a filter that was never applied — untouched. Recorded with the evidence in
doc/roadmap/active/cost-accuracy-and-plans.mdfor when a straddling session actually shows up.A session with no
session_metatimestamp is excluded once a window is set, matchingreport-audit.ts:656. It cannot be placed in time, and the point of this change is that the two paths agree.Verification
Both binaries built and run back to back. Seven fields differ; exactly one is the fix:
Claude went UP $3.39 between runs while Codex went down $12.65, and
-12.65 + 3.39matches the total delta exactly — a code change does not raise an agent it never touched.An earlier attempt at this comparison was worthless:
git stashfound nothing to stash after the commit, so it diffed today against a leftover file from yesterday and showed a $12,880 -> $509 "regression".4,290 tests, typecheck, lint, format clean. Mutation testing killed removing the filter, killed a variant that breaks
--all(the trap flagged before any code was written), and exposed that the no-timestamp test asserted only "did not crash" — every variant passed it. It now asserts behaviour.🤖 Generated with Claude Code