Skip to content

Address problem(s) in OpenAI Dashboard#825

Merged
ratulsarna merged 1 commit intosteipete:mainfrom
xiaoqianWX:main
May 1, 2026
Merged

Address problem(s) in OpenAI Dashboard#825
ratulsarna merged 1 commit intosteipete:mainfrom
xiaoqianWX:main

Conversation

@xiaoqianWX
Copy link
Copy Markdown
Contributor

Problems addressed

  1. The OpenAI Codex analytics page could load in a non-English locale, which made DOM text scraping unreliable.
  2. The dashboard route changed to the newer cloud analytics URL, so older route assumptions could fail.
  3. The dashboard could return too early before the usage breakdown or credits history had hydrated, causing “No usage breakdown data”.
  4. API-derived limits/credits could make the refresh look successful even when dashboard-only data was still missing.
  5. Usage breakdown sometimes included Skillusage:* entries, which belong to a different dashboard and should not appear in Codex usage.
  6. Credit amounts could be parsed incorrectly when commas were used as thousands separators or localized decimal separators.
  7. Web refresh timeouts and network failures surfaced as raw system errors instead of actionable guidance.
  8. The credits history table can be lazy-loaded, so it was sometimes missed unless the page was scrolled.

Implemented fixes

  1. Prefer English for OpenAI dashboard requests and WebView page execution.
  2. Recognize both old usage routes and the current Codex cloud analytics route.
  3. Keep waiting for a real dashboard page signal before returning dashboard data.
  4. Use API data only to enrich the scrape, not to replace the dashboard scrape.
  5. Filter Skillusage:* services from Codex usage breakdowns before display, cache use, and historical backfill.
  6. Improve credit amount parsing for English thousands separators and localized decimal commas.
  7. Retry OpenAI web refresh after timeouts and show clearer user-facing error messages.
  8. Scroll/wait for the credits history section so lazy-loaded rows have time to appear.
  9. Add focused tests for route handling, localization headers, parsing, timeout retry, Skillusage filtering, and dashboard refresh behavior.

It is not entirely perfect, but at least it's in a much more usable state than before

Copilot AI review requested due to automatic review settings May 1, 2026 02:04
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves robustness of CodexBar’s OpenAI Dashboard integration by stabilizing locale/route handling, waiting for full dashboard hydration, enriching scrape results with API data, filtering out non-Codex “Skillusage:*” services, and improving error messaging/timeouts.

Changes:

  • Force English localization for dashboard WebView loads and API requests; support current/legacy usage routes; improve dashboard “ready” signaling.
  • Filter “Skillusage:*” entries out of Codex usage breakdown everywhere it’s ingested/decoded/rendered.
  • Improve credit parsing for localized formats; add retry behavior and clearer user-facing errors; add targeted test coverage.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Tests/CodexBarTests/OpenAIDashboardParserTests.swift Adds tests for spaced limit labels and localized/thousands credit parsing.
Tests/CodexBarTests/OpenAIDashboardModelsTests.swift New tests for Skillusage filtering and snapshot decoding behavior.
Tests/CodexBarTests/OpenAIDashboardFetcherCreditsWaitTests.swift Tests for English headers, API request construction, route handling, and API payload mapping.
Tests/CodexBarTests/CodexUserFacingErrorTests.swift Tests for mapping timeout/network dashboard errors into actionable guidance.
Tests/CodexBarTests/CodexManagedOpenAIWebRefreshTests.swift Tests retry-after-timeout behavior and updated fetch timeout expectations.
Sources/CodexBarCore/OpenAIWeb/OpenAIDashboardWebViewCache.swift Injects preferred language script + uses a localized URLRequest for WebView loads.
Sources/CodexBarCore/OpenAIWeb/OpenAIDashboardScrapeScript.swift Improves usage breakdown extraction + filters Skillusage services + better credits-history scraping/scroll behavior.
Sources/CodexBarCore/OpenAIWeb/OpenAIDashboardParser.swift Enhances credit amount parsing and adds more flexible “5 h / 7 d” limit detection.
Sources/CodexBarCore/OpenAIWeb/OpenAIDashboardFetcher.swift Adds API preflight enrichment, English request headers, improved “ready” gating, Skillusage filtering on decode.
Sources/CodexBarCore/OpenAIDashboardModels.swift Ensures snapshots sanitize usage breakdown and adds centralized Skillusage filtering utilities.
Sources/CodexBar/UsageStore+OpenAIWeb.swift Increases primary timeout; retries after WebView timeout by importing cookies and re-fetching; extends cookie import API.
Sources/CodexBar/UsageStore+HistoricalPace.swift Prevents historical backfill from using Skillusage-contaminated breakdowns.
Sources/CodexBar/UsageBreakdownChartMenuView.swift Ensures displayed breakdown excludes Skillusage entries.
Sources/CodexBar/StatusItemController+Menu.swift Hides usage breakdown submenu when filtered breakdown is empty.
Sources/CodexBar/StatusItemController+HostedSubmenus.swift Filters Skillusage services before rendering breakdown chart submenu item.
Sources/CodexBar/Providers/Codex/CodexConsumerProjection.swift Maps OpenAI web timeout/network errors into clearer user-facing messages; filters Skillusage for display logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +787 to +811
var queue: [Any] = [json]
var seen = 0
while !queue.isEmpty, seen < 2000 {
let current = queue.removeFirst()
seen += 1
if let string = current as? String, string.contains("@") {
return string
}
if let dictionary = current as? [String: Any] {
for (key, value) in dictionary {
if key.lowercased() == "email",
let string = value as? String,
string.contains("@")
{
return string
}
queue.append(value)
}
} else if let array = current as? [Any] {
queue.append(contentsOf: array)
}
}
return nil
}

Comment on lines +484 to +487
const allTableRows = () => Array.from(document.querySelectorAll('tbody tr')).map(tr => {
const cells = Array.from(tr.querySelectorAll('td')).map(td => textOf(td));
return cells;
}).filter(looksLikeCreditsEventRow);
}

private static func looksOpenAIWebNetworkError(lower: String) -> Bool {
lower.contains("nsurlerrordomain")
@ratulsarna ratulsarna merged commit cbd5956 into steipete:main May 1, 2026
7 of 8 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.

3 participants