Skip to content

Keep Codex cost fixtures on the local day - #721

Open
Finesssee wants to merge 1 commit into
mainfrom
fix/cost-scanner-midnight-fixtures
Open

Finesssee wants to merge 1 commit into
mainfrom
fix/cost-scanner-midnight-fixtures

Conversation

@Finesssee

@Finesssee Finesssee commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Three cost scanner tests fail on CircleCI when a build runs between 00:00 and 01:00 UTC. This PR fixes the test fixtures; production code is unchanged.

Failing builds, all with the same three tests (2157 passed, 3 failed):

Build Branch Started (UTC)
977 port/micro-0.67.0-codex-direct-fork-baselines 2026-10-01 00:00:43
978 port/micro-0.69.0-kimi-stale-cli-guidance 2026-10-01 00:37:17
979 fix/reset-timer-overflow (#720) 2026-10-01 00:39:54
  • codex_source_recovery_keeps_appended_duplicate_unpriced_after_cache_reload (tests.rs:1584)
  • paginated_continuation_raises_inherited_baseline_from_total_last (paginated.rs:169)
  • paginated_history_base_equal_parent_keeps_true_fork_subtraction (paginated.rs:230)

Cause

The Codex session fixtures stamped their events at now - 1h but filed the session under today's local date folder. In the first hour after local midnight that hour falls on yesterday:

  • the recovery test read today's day bucket while the rows were filed under yesterday;
  • the fork fixtures landed in two date folders (the fork fixture in today's, the continuation in yesterday's), which flipped the folder scan order the paginated tests depend on.

Fix

  • New test helper recent_codex_fixture_time(): now - 1h, or the start of the local day when that hour reaches back into yesterday.
  • write_codex_session_fixture and write_codex_session_fixture_with_inputs take both the event time and the date folder from it.
  • The recovery test appends its row 30 minutes after the fixture time and reads that row's local day.
  • Both paginated tests use the helper for their base time.
  • recent_codex_fixture_time_stays_on_the_local_day pins the helper at fixed times around midnight in UTC+7 and UTC (the CI runner).

Validation

Run in a worktree on this branch (base main 7695471), through the local build gate:

Check Result
cargo +1.98.0 fmt --all --check pass
cargo +1.98.0 clippy --workspace --all-targets -- -D warnings pass
cargo test -p codexbar cost_scanner 90 passed, 0 failed
cargo test -p codexbar 2161 passed, 0 failed, 1 ignored
cargo test -p codexbar-desktop-tauri 459 passed, 0 failed (bootstrap_payload_exposes_every_provider_variant filtered; it needs #711)

Affected areas

  • rust/src/cost_scanner/tests.rs, rust/src/cost_scanner/tests/paginated.rs (tests only)

UI proof

Not applicable: test-only change, no UI or runtime behaviour changes.

Summary by CodeRabbit

  • Tests
    • Updated cost-scanner test fixtures to account for local dates and timezone differences, including cases near midnight. Coverage also checks date handling when continuing paginated results and reloading cached data. These updates make automated checks more consistent across time zones and reduce the chance of misleading failures around day boundaries.

Codex session fixtures in the cost scanner tests stamped their events
at now - 1h but filed the session under today's local date folder. In
the first hour after local midnight (00:00-01:00Z on the UTC CircleCI
runner) that hour fell on yesterday, so the tests read the wrong day
bucket, and the fork fixtures landed in two different date folders,
which flipped the folder scan order.

CircleCI builds 977, 978 and 979 failed this way:
codex_source_recovery_keeps_appended_duplicate_unpriced_after_cache_reload,
paginated_continuation_raises_inherited_baseline_from_total_last and
paginated_history_base_equal_parent_keeps_true_fork_subtraction.

A shared helper now returns now - 1h, or the start of the local day
when that hour reaches back into yesterday, and the fixtures take both
the event time and the date folder from it. A unit test pins the helper
at fixed times around midnight in UTC and UTC+7. Production code is
unchanged.
@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 2b21c916-8b6e-4bdd-af88-2426593988bd

📥 Commits

Reviewing files that changed from the base of the PR and between 7695471 and 400f805.

📒 Files selected for processing (2)
  • rust/src/cost_scanner/tests.rs
  • rust/src/cost_scanner/tests/paginated.rs

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The cost scanner test fixtures now use timezone-aware timestamps that align with their local-date directories. Cache-reload and paginated tests use the shared fixture-time helper.

Changes

Fixture timestamps

Layer / File(s) Summary
Recent fixture time and fixture writers
rust/src/cost_scanner/tests.rs
A helper selects a recent timestamp that remains on the current local date. Codex fixture writers use that timestamp for both the directory date and event timestamp.
Cost scanner test timestamps
rust/src/cost_scanner/tests.rs, rust/src/cost_scanner/tests/paginated.rs
Cache-reload and paginated tests use the shared fixture time. The cache-reload test derives its expected day from the appended event timestamp.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 400f8

The test-only changes address midnight fixture failures without changing production behavior. No merge-blocking issue is identified; merge after normal checks pass.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 77.78% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: keeping Codex cost-scanner fixtures aligned with the local calendar day.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Adversarial validation passed at afe1b747c816d0e1535e5c234f18545abf48701c

Scope: keep Codex cost fixtures on the local day (#721, GAP row FIX-MIDNIGHT), validated as merged into release/v0.70.0 (merge afe1b74 = merge of 400f805).

Attacks:

  • The claim is a CI flake fix: fixtures stamped now - 1h could land on yesterday's local date folder when the CI runner runs in the 00:00–01:00 local window, so tests reading "today's" bucket failed in that hour. Verified in the merged tree: recent_codex_fixture_time() clamps the event time to now.date_naive().and_time(NaiveTime::MIN) when now - 1h reaches back into yesterday, and recent_codex_fixture_time_stays_on_the_local_day covers 00:40, 01:00, 00:00, the 08:30 normal case, and a UTC CI runner at 00:45 — the exact failure window.
  • Test honesty: the helper is used by write_codex_session_fixture, write_codex_session_fixture_with_inputs, and the recovery test's appended row (appended_time = fixture time + 30 min so both rows share one local day). The paginated fork tests also switched from Utc::now() - 1h to the helper. That covers the three originally-flaking tests (codex_source_recovery_keeps_appended_duplicate_unpriced_after_cache_reload, plus both paginated fork tests).
  • Looked for shortcuts: the helper is a pure function of now (testable via recent_fixture_time_at), so the clamp logic itself is directly tested instead of being buried in fixture-writing code. The production scanner is untouched — this is test-only, matching the PR body and the "n/a (test-only)" proof column.
  • Windows-specific check: the clamp uses Local::now() and Local.from_local_datetime(...).earliest() (DST-safe); on a UTC CI runner the local day equals the UTC day, so the clamp reduces to start-of-day, which the dedicated test pins.

No defects found. READY for the un-draft rule.

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.

1 participant