Skip to content

fix(history): persist generic provider utilization#1588

Merged
steipete merged 4 commits into
steipete:mainfrom
kiranmagic7:kiran/all-provider-history-1585
Jun 18, 2026
Merged

fix(history): persist generic provider utilization#1588
steipete merged 4 commits into
steipete:mainfrom
kiranmagic7:kiran/all-provider-history-1585

Conversation

@kiranmagic7

Copy link
Copy Markdown
Contributor

Summary

  • Enables plan utilization history support for providers that expose a weekly usage window instead of restricting it to Codex/Claude.
  • Keeps the history menu hidden for providers with no saved history and no current sampleable weekly window.
  • Adds a regression showing Z.ai writes zai.json when historicalTrackingEnabled is true.

Tests

  • swift test --filter UsageStorePlanUtilizationTests
  • make check
  • git diff --check
  • swift test reports unrelated timing/process-control failures in AntigravityDeadlineTests, DeepSeekUsageFetcherTests, CommandCodeUsageFetcherTests, KiroStatusProbeTests, and SubprocessRunnerTests.

Fixes #1585

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

Copy link
Copy Markdown

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: 22689ec510

ℹ️ 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".

Comment on lines +21 to +25
} else if let snapshot = self.snapshots[provider] {
!self.planUtilizationSeriesSamples(
provider: provider,
snapshot: snapshot,
capturedAt: snapshot.updatedAt).isEmpty

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep primary-only weekly histories visible

For generic providers whose only sampleable weekly lane is primary (for example Z.ai when it returns a single tokenLimit and no timeLimit), this branch now reports plan history support and the removed guard lets .weekly samples be persisted, but PlanUtilizationHistoryChartMenuView.visibleSeriesNames still treats a primary-only snapshot as allowing only .session. In that normal current-snapshot state the newly persisted .weekly history is filtered out, so the user sees an empty Subscription Utilization chart despite having data; align the generic visibility filter/lane naming with windowMinutes before enabling the submenu from these samples.

Useful? React with 👍 / 👎.

@kiranmagic7

kiranmagic7 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Current head 22689ec has all visible GitHub checks passing (lint-build-test, Linux x64 CLI, Linux ARM64 CLI, GitGuardian). This is ready for review on the green head.

@clawsweeper

clawsweeper Bot commented Jun 17, 2026

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@steipete
steipete force-pushed the kiran/all-provider-history-1585 branch from 22689ec to fb8936e Compare June 18, 2026 07:50
@steipete

Copy link
Copy Markdown
Owner

Maintainer repair pushed at fb8936e25c95cc9c9ea17d1fa6e22648b2f440d0.

Changes:

  • Keep Codex and Claude plan-history recording always on.
  • Require the existing historical-tracking opt-in before generic providers record new history.
  • Keep already-saved generic history visible after opt-out.
  • Detect generic weekly charts by actual 10,080-minute windows, including primary-only and extra-window snapshots.
  • Use extra weekly windows only as fallback, preserving a provider's standard weekly quota.
  • Ignore reset-only usageKnown=false extras for persistence and chart filtering.
  • Add changelog credit for @kiranmagic7.

Proof:

  • swift test --filter 'UsageStorePlanUtilizationTests|PlanUtilizationHistoryChartMenuViewTests' - 44 tests passed.
  • make check - format, locale, and strict lint gates passed with zero violations.
  • Full branch Codex autoreview - no accepted/actionable findings (0.86 confidence), after fixing two P2 findings.
  • Ad-hoc exact-head package passed deep strict code-sign verification.
  • Packaged app E2E with isolated config and a live local z.ai HTTP fixture: app stayed alive, made 3 provider requests, and persisted schema v1 weekly history with windowMinutes: 10080 and usedPercent: 42.
  • Existing historicalTrackingEnabled state and z.ai history were restored byte-for-byte/absence-for-absence; normal app relaunched; worktree clean.

A real-account z.ai run was attempted first. 1Password was visibly locked after inactivity and op could not proceed without the master unlock, so no secret was read or exposed. The packaged fixture still exercises the exact app startup, provider HTTP fetch, refresh, opt-in gate, persistence coordinator, and on-disk provider-history document path.

@steipete
steipete force-pushed the kiran/all-provider-history-1585 branch from fb8936e to eda0636 Compare June 18, 2026 08:27
@steipete

Copy link
Copy Markdown
Owner

Post-#1572 rebase: exact candidate is now eda0636.

Only the adjacent changelog insertion conflicted; both contributor credits were preserved. The 44 focused history/chart tests passed again and the branch diff check is clean. CI restarted on this head.

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

Copy link
Copy Markdown

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: eda063622c

ℹ️ 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".

case .codex, .claude:
true
default:
self.settings.historicalTrackingEnabled

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use a clear opt-in before saving other providers

When any non-Codex/Claude provider with a weekly window refreshes, this default branch now persists that provider's utilization history whenever historicalTrackingEnabled is true. The only UI that sets this flag is the Codex provider toggle (Sources/CodexBar/Providers/Codex/CodexProviderImplementation.swift:77-79), whose subtitle says it stores local Codex usage history for Pace, so a user who opted into Codex history has not clearly opted into local history files for Z.ai/Factory/etc.; please gate generic recording behind a provider/global consent surface or update the setting before saving those histories.

Useful? React with 👍 / 👎.

@steipete
steipete merged commit 6afbaca into steipete:main Jun 18, 2026
4 checks passed
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.

writing history to json for all providers? historicalTrackingEnabled

2 participants