Skip to content

Add Codex historical pace with risk forecasting and backfill#438

Open
tristanmanchester wants to merge 3 commits intosteipete:mainfrom
tristanmanchester:codex/historical-pace-v1-4-hardening
Open

Add Codex historical pace with risk forecasting and backfill#438
tristanmanchester wants to merge 3 commits intosteipete:mainfrom
tristanmanchester:codex/historical-pace-v1-4-hardening

Conversation

@tristanmanchester
Copy link

@tristanmanchester tristanmanchester commented Feb 26, 2026

Summary

  • add opt-in historical tracking for Codex weekly pace using local JSONL history
  • switch Codex weekly pace computation to a historical model when enough data is available, with linear fallback preserved
  • add run-out probability support in UsagePace and include rounded risk text in pace detail when eligibility is met
  • add dashboard-based historical backfill for missing weeks, including partial-day handling and idempotent synthesis
  • improve model/data robustness with reset normalization, account-key scoping, coverage tolerance, and per-week conditioning consistency
  • route menu/menu-bar/card pace rendering through store-provided pace values for consistent output

Key Implementation Details

  • new history/model actor: HistoricalUsageHistoryStore
  • new store integration path: UsageStore.weeklyPace(...) and UsageStore+HistoricalPace
  • historical records now support source (live/backfill) and optional accountKey
  • records are normalized and grouped with reset bucketing to avoid week fragmentation
  • backfill remains local-only and bounded by retention rules

Tests

  • added HistoricalUsagePaceTests and HistoricalUsagePaceTestSupport
  • added/updated tests for:
    • reconstruction anchoring and monotonicity
    • reset jitter grouping
    • backfill timestamp guard, partial-day handling, idempotency, and incomplete-week fill
    • account-key filtering
    • smoothed probability and no-negative-ETA behavior
    • menu/menu-bar pace rendering consistency

Validation

  • pnpm check
  • swift test --filter HistoricalUsagePaceTests --filter UsagePaceTextTests --filter menuBarDisplayTextFormatsPercentAndPace --filter menuBarDisplayTextRequiresProvidedPaceForCodex
  • ./Scripts/compile_and_run.sh

Note

  • full swift test still hits an existing unrelated crash in this repo (NSConcreteTask terminationStatus in provider version detection / Gemini path)

@tristanmanchester tristanmanchester changed the title Harden Codex historical pace and backfill Ship Personalized Codex Historical Pace (Risk + ETA + Backfill) Feb 26, 2026
@tristanmanchester tristanmanchester changed the title Ship Personalized Codex Historical Pace (Risk + ETA + Backfill) Add Codex historical pace with risk forecasting and backfill Feb 26, 2026
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: de11d1a0cb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

func weeklyPace(provider: UsageProvider, window: RateWindow, now: Date = .init()) -> UsagePace? {
guard provider == .codex || provider == .claude else { return nil }
guard window.remainingPercent > 0 else { return nil }
let codexAccountKey = self.codexHistoricalAccountKey()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Gate Codex account-key lookup to Codex pace path

weeklyPace computes codexHistoricalAccountKey() unconditionally before the provider-specific branch, so Claude pace rendering also runs Codex account resolution. That path can fall through to codexAccountEmailForOpenAIDashboard() and UsageFetcher.loadAccountInfo() (which synchronously reads ~/.codex/auth.json) while this method is @MainActor, adding avoidable disk I/O to menu-bar updates for non-Codex providers. Move the account-key lookup inside the .codex historical branch so Claude pace stays purely in-memory.

Useful? React with 👍 / 👎.

@EthanLipnik
Copy link

Curious how this compares to my PR #401 yours looks more developed though

@tristanmanchester
Copy link
Author

Curious how this compares to my PR #401 yours looks more developed though

I completely missed your PR! Looks we have different approaches. I guess Peter will merge the best bits of both if he implements this feature.

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.

2 participants