Repository navigation
Keep Codex model pricing when the history window changes #1059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -153,3 +153,59 @@ fn codex_month_to_date_excludes_the_previous_month() { | |
| ); | ||
| assert_eq!(mtd, 100); | ||
| } | ||
|
|
||
| #[test] | ||
| fn changing_history_windows_keeps_source_model_pricing_complete() { | ||
| let root = tempfile::tempdir().unwrap(); | ||
| let sessions = root.path().join("sessions"); | ||
| let cache = root.path().join("cache"); | ||
| let today = Local::now().date_naive(); | ||
| let folder = sessions.join(today.format("%Y/%m/%d").to_string()); | ||
| std::fs::create_dir_all(&folder).unwrap(); | ||
| let mut lines = Vec::new(); | ||
| for age in [8, 1, 0] { | ||
| let timestamp = Local | ||
| .from_local_datetime(&(today - Duration::days(age)).and_hms_opt(12, 0, 0).unwrap()) | ||
| .earliest() | ||
| .unwrap() | ||
| .with_timezone(&Utc) | ||
| .to_rfc3339(); | ||
| lines.push( | ||
| serde_json::json!({ | ||
| "type": "turn_context", "timestamp": timestamp, | ||
| "payload": {"model": "gpt-5"} | ||
| }) | ||
| .to_string(), | ||
| ); | ||
| lines.push(serde_json::json!({ | ||
| "type": "event_msg", "timestamp": timestamp, | ||
| "payload": {"type": "token_count", "info": { | ||
| "last_token_usage": {"input_tokens": 100, "cached_input_tokens": 0, "output_tokens": 0} | ||
| }} | ||
| }).to_string()); | ||
| } | ||
| std::fs::write(folder.join("history.jsonl"), lines.join("\n") + "\n").unwrap(); | ||
| for days in [30, 1, 7, 30, 1, 30] { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| let summary = CostScanner::new(days) | ||
| .with_options(CostScanOptions::app_driven()) | ||
| .with_cache_root(&cache) | ||
| .with_sessions_dirs(vec![sessions.clone()]) | ||
| .scan_codex(); | ||
| assert!(summary.history_coverage_established); | ||
| assert!( | ||
| !summary.model_pricing_completeness.is_partial(), | ||
| "known source models lost pricing after switching to {days} days: {:?}", | ||
| summary.model_pricing_completeness | ||
| ); | ||
| assert_eq!( | ||
| summary.input_tokens, | ||
| if days >= 9 { | ||
| 300 | ||
| } else if days > 1 { | ||
| 200 | ||
| } else { | ||
| 100 | ||
| } | ||
| ); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
sed -n 1,140p rust/src/cost_scanner/codex/scan.rs rg -n 'priority_days|scan_since_key|scan_until_key|was_read_for|record_scan_range' rust/srcRepository: nesszer/Win-CodexBar
Length of output: 21614
Script executed:
Repository: nesszer/Win-CodexBar
Length of output: 42228
Script executed:
Repository: nesszer/Win-CodexBar
Length of output: 41527
Script executed:
Repository: nesszer/Win-CodexBar
Length of output: 41588
Script executed:
Repository: nesszer/Win-CodexBar
Length of output: 19801
Script executed:
Repository: nesszer/Win-CodexBar
Length of output: 14451
Script executed:
Repository: nesszer/Win-CodexBar
Length of output: 6537
Script executed:
Repository: nesszer/Win-CodexBar
Length of output: 4328
Keep
usage.daysaligned with the current source rows before applying Priority pricing.When a file grows after a wider scan and the next scan uses a shorter range, the incremental parser preserves the older
usage.days. The newwas_read_forfilter rejects the wider cached rows, but the replacement rows cover only the shorter range. Because no recovery is requested,usage.daysis not rebuilt.priority_daysthen rejects the rows because their totals differ, so Priority pricing is not applied.Rebuild
usage.daysfrom the current source rows when the cached range does not match, or retain a source-row set whose totals coverusage.daysbefore applying the overlay.