CodexBar icon indicating copy to clipboard operation
CodexBar copied to clipboard

OpenAI dashboard WebContent spins at one CPU core; JavaScript awaits can outlive refresh deadlines

Open enzonaute opened this issue 1 month ago • 2 comments

Observed problem

CodexBar's ChatGPT WebContent helper can remain busy at approximately 100% of one CPU core while the main CodexBar process is nearly idle. On a 14-logical-core Mac this appears as roughly 7.1% total CPU.

Environment: CodexBar 0.63.0 (151), Apple Silicon, macOS 26.4.1 (25E253). OpenAI web access enabled, refresh frequency five minutes. The affected helper had accumulated about 85.5 CPU hours over 88 hours of lifetime, with a 912.6 MB footprint. These counters do not establish the exact time the problem started.

Open files tied the helper to Library/WebKit/com.steipete.codexbar/. Hostname-only inspection of its already-open cached resources found chatgpt.com, chat.openai.com, and ab.chatgpt.com. No account identifiers, cookies, tokens or full resource URLs are included here.

Native sample

A 30-second sample contained 12,707 main-thread samples; 12,400 (97.6%) were inside the microtask checkpoint. The dominant path was:

WebCore::EventLoop::run
  WebCore::MicrotaskQueue::performMicrotaskCheckpoint
    JSC::runInternalMicrotask
      JSC::moduleLoaderEvaluate
        WebCore::ScriptModuleLoader::evaluate
          WTF::URLParser::URLParser

This establishes sustained JavaScript/module processing. It does not identify the exact ChatGPT module or determine whether the initiating defect belongs to the page or WebKit.

Independently reproducible lifecycle weakness

The surrounding refresh deadline does not bound each await webView.evaluateJavaScript(...):

  • OpenAIDashboardFetcher.probeUsagePage and collectPageSnapshot check the deadline between evaluations.
  • probeReadiness, scrape, fetchDebugHTML, and OpenAIDashboardWebViewCache.resetReusablePageState await evaluations without their own bounded completion.
  • If WebKit never replies, the caller does not reach the lease-release defer.
  • WebKitTeardown uses stopLoading() and window closure. These do not guarantee interruption of running JavaScript.

The relevant fetcher and teardown files were unchanged between v0.63.0 and the inspected main. #2901 is already an ancestor of v0.63.0. Related investigation: #3247. This report isolates the JavaScript-wait/teardown failure rather than attributing all CPU symptoms to cost scanning.

Offline reproduction

Use a fresh nonpersistent WKWebView with local HTML. After navigation finishes, evaluate this finite microtask loop:

const end = Date.now() + 8000;
function spin() {
  if (Date.now() < end) Promise.resolve().then(spin);
}
spin();

After 300 ms, request document.body.innerText. After another 500 ms, call stopLoading() and close the host window.

Measured results:

Variant Readiness wait JavaScript loop
Direct async evaluateJavaScript 7.709 s Finishes at its own eight-second limit
Completion handler with an independent 0.5 s native deadline 0.527 s Still finishes at its own eight-second limit
Deadline plus explicit view detachment 0.526 s Still finishes at its own eight-second limit

The fixture contacts no real account and self-terminates the loop; it reproduces the missing timeout/teardown protection, not the exact production module-loader trigger.

Proposed work

  1. Bound dashboard evaluation callbacks with native deadlines and cancellation, ignoring late replies and preserving already verified API data. Partial hardening PR: #4642 (draft; bounds waits but does not stop a hung WebContent process).
  2. Treat CPU containment separately: avoid automatic page retries after an unresponsive evaluation, and investigate API-only background refresh or a supervised short-lived scraper with verified cleanup of its own WebKit helpers. Killing only a parent process is not proof of orphan cleanup.

Acceptance must include cessation of CPU use and absence of owned WebContent orphans, not merely returning a timeout. The deadline patch alone should not close this issue.

enzonaute avatar Oct 19 '26 14:10 enzonaute

Codex review: this still needs some work.

Summary Keep open: current main still permits dashboard JavaScript waits to exceed refresh deadlines, and the paired draft PR explicitly leaves sustained WebContent CPU use unresolved.

Reproducibility: Current source establishes the missing evaluation deadline and deferred-release dependency; the reporter supplies a finite offline fixture, but this review ran no tests and did not reproduce the production CPU spin.

Root-cause cluster Relationship: canonical Canonical: https://github.com/steipete/codexbar/issues/4641 Summary: This issue retains the broader CPU-containment investigation while the paired draft addresses the source-proven wait gap; earlier performance work does not establish the same production trigger.

Members:

  • partial_overlap: https://github.com/steipete/codexbar/pull/4642 - Bounds JavaScript waits but explicitly leaves sustained helper CPU and orphan cleanup unresolved.
  • partial_overlap: https://github.com/steipete/codexbar/pull/2901 - Reduced dashboard scraping and idle retention, but current evaluation calls remain unbounded.
  • adjacent_distinct: https://github.com/steipete/codexbar/issues/3247 - Its discussion isolates cost-scanner failures and leaves the older WebContent ownership unconfirmed.

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Next step Review the paired draft at https://github.com/steipete/CodexBar/pull/4642 with a failing stalled-callback regression, then verify current-build CPU cessation and owned-helper cleanup before resolving this issue.

Review details

Best possible solution:

Bound dashboard waits while preserving verified account data, then demonstrate recovery without sustained CPU use or owned WebContent orphans.

Do we have a high-confidence way to reproduce the issue?

Current source establishes the missing evaluation deadline and deferred-release dependency; the reporter supplies a finite offline fixture, but this review ran no tests and did not reproduce the production CPU spin.

Is this the best way to solve the issue?

Native callback deadlines are appropriate partial hardening, provided cancellation, late replies, verified API fallback, and lease cleanup are covered; CPU containment needs separate process-lifecycle evidence.

AGENTS.md: found and applied where relevant.

Remaining risk / open question:

  • The exact production JavaScript trigger and its recurrence on the latest release remain unverified.
  • Returning a timeout and releasing a lease do not demonstrate cessation of CPU use or removal of owned WebContent helpers.

Codex review notes: model internal, reasoning medium; reviewed against 8fa003e092fe.

Label changes

Label changes:

  • add P1: A released app reportedly leaves its optional dashboard helper consuming a full CPU core for prolonged periods, and current source still permits refresh waits to remain suspended.
  • add impact:other: The principal impact is sustained CPU, battery, and memory consumption by a dashboard helper.
  • add issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.
  • add clawsweeper:source-repro: Current issue advisory state selects this label.

Label justifications:

  • P1: A released app reportedly leaves its optional dashboard helper consuming a full CPU core for prolonged periods, and current source still permits refresh waits to remain suspended.
  • impact:other: The principal impact is sustained CPU, battery, and memory consumption by a dashboard helper.
Evidence reviewed

What I checked:

  • Current source establishes the deadline gap: The page loop checks its deadline before awaiting probeReadiness, which directly awaits evaluateJavaScript without a native deadline; extraction and debug HTML use the same unbounded pattern. (Sources/CodexBarCore/OpenAIWeb/OpenAIDashboardFetcher+PageScrape.swift:49, 8fa003e092fe)
  • Lease cleanup depends on the awaited scrape returning: loadLatestDashboard installs lease release in a defer before awaiting collectPageSnapshot; a suspended evaluation prevents that scope from finishing. (Sources/CodexBarCore/OpenAIWeb/OpenAIDashboardFetcher.swift:286, 8fa003e092fe)
  • Preserved-page preparation has the same gap: Preserved-page reset awaits evaluateJavaScript before navigation's cancellation handler and timer are installed; idle pruning excludes busy entries. (Sources/CodexBarCore/OpenAIWeb/OpenAIDashboardWebViewCache.swift:633, 8fa003e092fe)
  • Teardown does not establish CPU containment: Shared teardown stops loading, clears delegates, closes or hides the window, and releases retained owners; it has no verification that page JavaScript or owned WebContent helpers have stopped. (Sources/CodexBarCore/WebKit/WebKitTeardown.swift:73, 8fa003e092fe)
  • Existing tests cover narrower contracts: Deadline tests verify time calculations, cache tests cover acquisition ownership and navigation retries, and the teardown test checks owner registration with nil views; these do not establish bounded JavaScript completion or cessation of helper CPU use. (Tests/CodexBarTests/WebKitTeardownTests.swift:11, 8fa003e092fe)
  • Reporter separates observed CPU use from synthetic deadline proof: The full issue describes v0.63.0 helper CPU measurements and a microtask sample, then reports an offline finite-loop experiment that reproduces delayed evaluation completion without claiming the production module-loader trigger was reproduced.
How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge; those execution lanes are retired.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

Reviewed October 19, 2026, 10:55 AM ET / 14:55 UTC.

clawsweeper[bot] avatar Oct 19 '26 14:10 clawsweeper[bot]

Fixed in #4645 (cd733e47b6a9). Thanks @enzonaute for the detailed report and the investigation in #4642! Dashboard refreshes now own their deadline for the whole page lease: when it passes, the WebContent page is terminated and evicted instead of continuing to run JavaScript, and the verified API fallback still answers. It will be in the next release.

steipete avatar Oct 20 '26 06:10 steipete