Restore OpenRouter balance in menu bar layouts - #2870
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 12, 2026, 1:21 AM ET / 05:21 UTC. ClawSweeper reviewWhat this changesThe PR adds an OpenRouter-only Balance token to stored menu-bar layouts, preserves the legacy Automatic balance during migration, and refreshes the status item when that value changes. Regression provenancePossible regression — probable (reviewed change; known regression link). No predecessor PR is attributed. Merge readinessThis active PR is a focused, proof-positive repair for the linked OpenRouter layout regression. The prior migration finding is resolved and no new correctness or security issue was found on the current head. Priority: P2 Review scores
Verification
How this fits togetherCodexBar converts provider usage snapshots and saved menu-bar layout tokens into the macOS status-item title. The editor persists layouts, while the renderer and observation signature determine what text is shown and when it refreshes. flowchart LR
A[OpenRouter usage snapshot] --> B[Balance resolver]
C[Legacy or stored layout] --> D[Layout migration and editor]
D --> E[Menu-bar renderer]
B --> E
E --> F[Status item title]
B --> G[Refresh signature]
G --> F
Before merge
Agent review detailsSecurityNone. Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Merge this focused repair after the normal required checks complete, then let the linked regression close through the PR’s existing closing reference. Do we have a high-confidence way to reproduce the issue? Yes—current source proves the legacy OpenRouter Automatic path renders Is this the best way to solve the issue? Yes—the provider-gated token reuses the existing AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 26ebaf9d5b09. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 34ae789d89
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| case resetCountdown | ||
| case resetAbsolute | ||
| case runsOut | ||
| case balance |
There was a problem hiding this comment.
Preserve OpenRouter balance during layout migration
For OpenRouter users who are still on the legacy automatic metric, the legacy renderer shows the $ balance via menuBarDisplayText, but MenuBarLayout.migrated(.percent, .automatic, provider: .openrouter) still builds .percent(.automatic). The editor uses that migrated layout when no stored layout exists, and changing size/gap or adding any token activates it, so a simple layout tweak replaces the always-visible balance with a usage percentage unless the user manually discovers and adds this new token. Consider mapping the OpenRouter automatic legacy layout to the balance token when introducing it.
Useful? React with 👍 / 👎.
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
5b82592 to
f2f0a5a
Compare
|
@clawsweeper re-review |
|
@codex review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f2f0a5a3fa
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| let icon: MenuBarLayoutToken = .icon | ||
| // Provider-specific by design: OpenRouter Automatic historically renders remaining credit balance. | ||
| if provider == .openrouter, metricPreference == .automatic { | ||
| return MenuBarLayout(lines: [[icon, .balance]]) |
There was a problem hiding this comment.
Keep Balance out of global layout seeds
When OpenRouter is the representative/first provider in the All layout editor and no stored layout exists, this migrated layout is what MenuBarLayoutEditorPersistence.setSize/setGap persists with provider: nil, so a harmless global size or gap change saves [.icon, .balance] as the global layout. Every non-OpenRouter provider that inherits that global layout then renders Balance unavailable/– because the balance resolver only returns a value for OpenRouter. Consider keeping this migration provider-scoped instead of letting it seed the All-provider layout.
Useful? React with 👍 / 👎.
|
Landed and verified. Proof:
Merged as No release, tag, appcast, package, or artifact publication was performed. |
Summary
Fixes #2866
Root cause and implementation
The legacy OpenRouter menu-bar path rendered the Remaining detail row for Automatic mode, but the composable layout system had no equivalent token. Saving or migrating a layout therefore lost an established provider-specific value.
This patch adds a Balance token at the shared layout boundary while keeping its value provider-scoped: only OpenRouter resolves the Remaining row. Legacy OpenRouter Automatic settings migrate to Icon plus Balance, the editor exposes a synthetic preview only for OpenRouter, and the status-item observation signature includes the balance only when a stored layout actually uses that token.
Real behavior proof
A fresh Developer ID-signed build from head
f2f0a5a3fae8a45f04f371af6de12c6eaaf97a35was exercised through the production stored-layout renderer and a realNSStatusBarButton.$12.34snapshot through the same production status-button path, so it is safe to share while proving the actual AppKit surface rather than only the SwiftUI editor preview.Validation
make checkmake test: 840 selections across 70 groups, all passed with no retries or timeoutscodesign --verify --deep --strict --verbose=4 CodexBar.appspctl --assess --type execute --verbose=4 CodexBar.appThe final bundle is signed by Developer ID Application: Peter Steinberger (Y5PE65HELJ), accepted by Gatekeeper, and was rebuilt after all temporary proof hooks had been removed.