Skip to content

Port upstream 0.65.0: confirm unused rolling weekly Codex resets - #629

Open
Finesssee wants to merge 2 commits into
port/upstream-0.65.0from
port/micro-0.65.0-codex-weekly-reset-rolling
Open

Finesssee wants to merge 2 commits into
port/upstream-0.65.0from
port/micro-0.65.0-codex-weekly-reset-rolling

Conversation

@Finesssee

Copy link
Copy Markdown
Collaborator

Summary

Codex delayed weekly-reset confirmation now also accepts an unused rolling weekly window. When the provider advances the weekly reset date with each zero-use observation, the candidate and current boundaries differ by more than 120 s across normal refresh intervals. Previously that pair was discarded as InconsistentResetBoundary, so stale pre-reset usage persisted.

In delayed_candidate_decision (rust/src/providers/codex/weekly_reset.rs), boundaries more than 120 s apart are accepted only when all of these hold:

  • candidate and current weekly windows are both exactly 0% used;
  • both have window_minutes == Some(10080);
  • each resets_at is within 120 s of its own capture time + 604800 s (candidate.snapshot_updated_at, current.updated_at);
  • current_boundary >= candidate_boundary.

The equivalent-boundary rule (< 120 s apart) is unchanged. Every other guard is unchanged: exact OAuth, plan match, unchanged credit inventory, 60 s minimum age, 30 min expiry, supported_delayed_boundary, and the threshold checks.

Upstream reference

Ported / Deferred

  • Ported: the unusedWeeklyWindows relaxation and the upstream test matrix (rolling positive at 180/300/900 s offsets, ordinary publication unchanged, nonzero usage, wrong boundary, plan/inventory guards).
  • Not ported: the initialDecision restructuring in the same upstream commit (behavior-preserving), and the Swift persistence/UsageStore test (persisted stale baseline recovers ... rollingBoundary), which exercises Swift store plumbing with no Windows counterpart.
  • Known pre-existing difference, unchanged here: with no published baseline and a weekly window without resets_at, upstream publishes above 1% used, while local initial_decision preserves because is_valid_boundary fails first.
  • Rounding: upstream compares fractional seconds; local compares whole seconds (num_seconds()), consistent with the existing 120 s checks in this module.

Validation

Toolchain pinned cargo +1.98.0, process-local CARGO_TARGET_DIR.

  • cargo +1.98.0 fmt --all: clean
  • cargo +1.98.0 clippy --workspace --all-targets -- -D warnings: pass
  • cargo +1.98.0 test -p codexbar weekly_reset: 14 passed, 0 failed
  • cargo +1.98.0 test -p codexbar providers::codex: 54 passed, 0 failed

New tests: positive rolling case (180/300/900 s), minimum age still applies, ordinary publication unchanged; negatives for nonzero usage (current and candidate), wrong window minutes (current and candidate), boundary not near capture+7d (current and candidate), current boundary earlier than candidate, changed credit inventory, expired candidate.

Affected areas

  • Provider logic (Codex weekly-reset confirmation)
  • Settings / UI / tray / float bar
  • CLI, docs, CI

UI proof

Not applicable. No UI surface is touched.

@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 26e2b825-7f1d-4782-a4c5-5655a7f21d27

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • 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.

…tests

- Compare the unused rolling weekly offset at full timestamp precision, like
  upstream's floating-point |boundary - capturedAt - 604800| < 120 check; the
  seconds-truncated version rejected resets 119.x s short of one week.
- Split delayed-candidate revalidation into a pure evaluation that returns
  the decision and its fixed reason code, and report a missing current
  credit inventory as missingCreditInventory instead of changedCreditInventory.
- Port the upstream rejection table (plan mismatch, changed and missing
  credit inventory, non-exact source) with reason codes, the confirmed
  observation reason, and the persisted relaunch test for fixed and rolling
  boundaries through the StateFile envelope.
@Finesssee

Copy link
Copy Markdown
Collaborator Author

Lane B review: fixes at 4a1674e

Reviewed the full diff against port/upstream-0.65.0 (b585d48) and upstream steipete#3851 (commit 8c8dfd2, in v0.65.0): CodexWeeklyResetConfirmation.evaluateDelayedCandidate, CodexWeeklyResetDiagnosticsTests and CodexWeeklyResetPublicationTests.

Defects fixed (4a1674e)

  • The rolling check truncated the boundary offset to whole seconds before comparing it with one week. A reset 119.8 s short of capturedAt + 604_800 was rejected on Windows but accepted upstream (abs(boundary - capturedAt - 604_800) < 120 on floating seconds). is_unused_rolling_weekly now compares full-precision TimeDeltas, and the non-decreasing check compares the two boundaries directly (currentBoundary >= candidateBoundary).
  • A refresh without a current reset-credit inventory was logged as changedCreditInventory. Upstream reports missingCreditInventory. The delayed path is now a pure delayed_candidate_evaluation that returns the decision and its fixed reason code (upstream DelayedEvaluation); delayed_candidate_decision logs it. Decisions are unchanged.

Upstream tests ported

  • The rejection table from unused weekly boundaries advancing with observation time confirm on later refreshes, now asserting reason codes:

    • inconsistentResetBoundary for 0.5 % usage, +604_921 and 600_000;
    • planMismatch, changedCreditInventory and missingCreditInventory;
    • sourceNotExactOAuth, the Windows form of confidenceNotExact.

    Account mismatch has no row, because state is scoped per account (scope_key).

  • confirmedObservation reason for offsets 180, 300 and 900.

  • Full-precision tolerance edges: +/-119.8 s publishes; -120.0 s, -120.2 s and +120.2 s discard.

  • persisted stale baseline recovers after delayed reset confirmation across relaunch for fixed and rolling boundaries. The test runs the same decisions CodexApi::fetch_usage makes and round-trips the StateFile envelope: seed at 81 %, first low refresh admits the candidate while 81 % stays published, a credits-only phase keeps the candidate, and after the relaunch the later low refresh publishes its own used percent and reset and clears the candidate.

Not ported: the upstream docs/codex.md bullet. No Windows doc covers weekly-reset confirmation.

Validation (Windows, toolchain 1.98.0)

  • cargo fmt --all --check: pass
  • cargo clippy --workspace --all-targets -- -D warnings: pass
  • cargo test -p codexbar providers::codex::weekly_reset: 16 passed
  • cargo test -p codexbar: 2168 passed, 1 failed, 1 ignored. The failure is cost_scanner::codex::tests::codex_source_recovery_keeps_appended_duplicate_unpriced_after_cache_reload, a time-of-day flake on main: it fails between 00:00 and 01:00 local time (the run was at 00:3x UTC+7).
  • cargo test -p codexbar-desktop-tauri: 461 passed, 1 failed. The failure is commands::tests::bootstrap_payload_exposes_every_provider_variant, which reads host settings where a deprecated provider is enabled. Neither file is touched by this PR.

UI proof: not applicable (backend decision logic only).

#690 is stacked on this branch; I will merge this head into it next.

Finesssee added a commit that referenced this pull request Sep 30, 2026
Move the plan-change weekly-reset tests into weekly_reset/tests/plan_change.rs
so tests.rs stays under 1000 lines after merging #629, and port the upstream
CodexPlanTransitionPublicationTests cases that were missing:

- a new plan without a weekly window cannot borrow the old plan's window;
- the new plan's own usage and reset become the stored baseline at 0 % and 5 %;
- same-plan (any case or spacing) or blank-plan near-zero readings keep the
  old evidence.
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