CodexBar icon indicating copy to clipboard operation
CodexBar copied to clipboard

Release idle WebViews on memory pressure

Open ProspectOre opened this issue 5 months ago โ€ข 3 comments

Summary

  • Add a macOS memory-pressure monitor for warning and critical pressure events.
  • Evict only idle cached OpenAI dashboard WebViews when pressure arrives, preserving active dashboard refreshes.
  • Run malloc pressure relief alongside the WebView cache cleanup.

Proof

  • Real local before profile, installed CodexBar 0.36.1 with trace logging: main app idle averaged 0.152% CPU and 30.6 MB RSS, while the associated WebKit WebContent process held a 306.1 MB physical footprint with a 541.7 MB peak after dashboard work. Samples were idle/mach_msg dominated, pointing to retained WebKit memory rather than a Swift CPU loop.
  • After-fix app-path proof added in 426d7b8a: Memory pressure monitor evicts idle shared WebViews without interrupting busy WebViews seeds the shared dashboard WebView cache with one idle entry and one busy entry, runs the MemoryPressureMonitor warning handler, and proves the idle WebView is evicted while the busy WebView remains cached.
  • swift test --filter OpenAIDashboardWebViewCacheTests: 19 tests passed after 2.022 seconds. The focused run emitted the monitor log line warning com.steipete.codexbar.memory-pressure: level=warning [CodexBarCore] System memory pressure during the new after-fix test.
  • The PR branch app was also packaged and launched from /Users/alec/Dev/CodexBar/CodexBar.app/Contents/MacOS/CodexBar. A local sudo /usr/bin/memory_pressure -S -l warn / critical simulation attempt did not produce CodexBar unified-log entries in this environment, so the PR proof relies on the deterministic app-path test above rather than overclaiming OS delivery evidence.
  • .build/lint-tools/bin/swiftformat Sources Tests --lint: 0/1140 files require formatting.
  • .build/lint-tools/bin/swiftlint --strict: 0 violations in 1139 files.
  • swift build --build-tests: passed.
  • git diff --check: passed.
  • make check: locally blocked before Swift lint by the existing node --check docs/site.js ESM mismatch under Node v25.9.0; the checked upstream/main:docs/site.js starts with an ESM import as well, so this is not introduced by this patch.

ProspectOre avatar Jun 16 '26 08:06 ProspectOre

Codex review: needs maintainer review before merge. Reviewed June 18, 2026, 8:28 PM ET / 00:28 UTC.

Summary The PR adds a macOS memory-pressure monitor that evicts idle OpenAI dashboard WebViews, runs malloc pressure relief off the main actor, and adds DEBUG proof hooks plus focused WebView cache tests.

Reproducibility: not applicable. this is a resource-management improvement rather than a deterministic broken existing-behavior report. The PR body supplies focused tests and after-fix DEBUG runtime logs for the intended path.

Review metrics: 3 noteworthy metrics.

  • Changed surface: 8 files changed, +245/-0. The additive patch spans app lifecycle, WebKit cache lifetime, DEBUG proof plumbing, logging, tests, and release notes.
  • Runtime pressure paths: 1 new DispatchSourceMemoryPressure handler. The handler runs under system pressure, where responsiveness and active refresh preservation matter before merge.
  • Focused tests: 3 added cache/pressure tests. They cover idle-only eviction and off-main malloc relief, while the WebKit cache cases still rely on non-CI execution.

Merge readiness Overall: ๐Ÿš platinum hermit Proof: ๐Ÿฆž diamond lobster Patch quality: ๐Ÿš platinum hermit Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Let the latest required CI jobs finish on head 6a82264f.
  • Maintain deliberate landing order with the stacked follow-up.

Risk before merge

  • [P1] The handler runs during system memory-pressure events, so mistakes in actor hops, idle/busy eviction boundaries, or detached malloc relief scheduling could affect app responsiveness or active OpenAI dashboard refreshes.
  • [P1] The real behavior proof uses a DEBUG distributed-notification hook and runtime logs rather than an observed kernel-delivered memory-pressure event, although it exercises the production handler after seeding caches.
  • [P1] The idle/busy WebKit cache tests skip under CI, so maintainer confidence depends partly on submitted local proof and code review for that behavior.
  • [P1] Latest required macOS CI jobs were still in progress at inspection.
  • [P1] The broader cache-trim follow-up at https://github.com/steipete/CodexBar/pull/1577 is stacked on this branch and currently conflicting, so landing order and restacking should be coordinated.

Maintainer options:

  1. Merge After Checks and Proof Acceptance (recommended)
    If maintainers accept the DEBUG notification proof for this macOS pressure path, merge after required checks pass on the latest head.
  2. Ask for Actual Pressure Proof
    If stronger availability confidence is needed, request a redacted log or recording from an actual system memory-pressure event before merge.
  3. Coordinate the Stacked Follow-Up
    Keep this PR as the base and require https://github.com/steipete/CodexBar/pull/1577 to be restacked or reviewed after this branch lands.

Next step before merge

  • The remaining gate is maintainer acceptance of availability-sensitive runtime behavior, pending required checks, and stacked follow-up ordering rather than a narrow automated code repair.

Security Cleared: No concrete security or supply-chain concern was found; the diff adds local memory-pressure handling, DEBUG-only proof plumbing, logging, tests, and a release note without new dependencies, scripts, permissions, or credential handling.

Review details

Best possible solution:

Land this narrow base memory-pressure WebView release after required checks finish and maintainers accept the DEBUG/log proof level, then restack or review the broader cache-trim follow-up separately.

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

Not applicable: this is a resource-management improvement rather than a deterministic broken existing-behavior report. The PR body supplies focused tests and after-fix DEBUG runtime logs for the intended path.

Is this the best way to solve the issue?

Yes, conditionally: evicting only nonbusy cached dashboard WebViews fits the existing cache lifecycle, and the latest head moves malloc relief off the main actor. The remaining decision is whether simulated pressure proof is enough for this availability-sensitive path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 518764ead945.

Label changes

Label justifications:

  • P2: This is a normal-priority resource-management improvement with limited blast radius to OpenAI dashboard WebView caching.
  • merge-risk: ๐Ÿšจ availability: Merging changes runtime memory-pressure handling, WebView cache eviction, and malloc relief scheduling, which could affect responsiveness if wrong.
  • rating: ๐Ÿš platinum hermit: Overall readiness is ๐Ÿš platinum hermit; proof is ๐Ÿฆž diamond lobster and patch quality is ๐Ÿš platinum hermit.
  • status: ๐Ÿ‘€ ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): The PR body includes after-fix runtime logs from a fresh DEBUG executable and package launch showing one idle WebView evicted, the busy WebView retained, and the app still running.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix runtime logs from a fresh DEBUG executable and package launch showing one idle WebView evicted, the busy WebView retained, and the app still running.
Evidence reviewed

What I checked:

Likely related people:

  • steipete: Current-main history ties memory relief and recent OpenAI WebKit cache/deadline work to this author, and the latest PR head adds the off-main malloc-relief repair commit. (role: recent area contributor and PR-head repair author; confidence: high; commits: 06fea2c897cc, 5db1a04718e7, 6a82264f5bd4; files: Sources/CodexBar/MemoryPressureRelief.swift, Sources/CodexBar/UsageStore+MemoryPressure.swift, Sources/CodexBarCore/OpenAIWeb/OpenAIDashboardWebViewCache.swift)
  • naoterumaker: Authored the merged scheduled idle-prune change for cached dashboard WebViews that this PR extends with pressure-triggered idle eviction. (role: adjacent WebView-cache contributor; confidence: high; commits: 1246ec6fc3f7; files: Sources/CodexBarCore/OpenAIWeb/OpenAIDashboardWebViewCache.swift, Tests/CodexBarTests/OpenAIDashboardWebViewCacheTests.swift)
  • ProspectOre: Current-main history includes adjacent OpenAI dashboard route reload work in the same fetcher path, beyond authoring this proposed branch. (role: recent adjacent contributor; confidence: medium; commits: 51a8e23f6418; files: Sources/CodexBarCore/OpenAIWeb/OpenAIDashboardFetcher.swift, Tests/CodexBarTests/OpenAIDashboardFetcherCreditsWaitTests.swift)
What the crustacean ranks mean
  • ๐Ÿฆ€ challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • ๐Ÿฆž diamond lobster: very strong readiness with only minor maintainer review expected.
  • ๐Ÿš platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • ๐Ÿฆ gold shrimp: useful signal, but proof or patch confidence is still limited.
  • ๐Ÿฆช silver shellfish: thin signal; proof, validation, or implementation needs work.
  • ๐Ÿง‚ unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • ๐ŸŒŠ off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

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.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

clawsweeper[bot] avatar Jun 16 '26 08:06 clawsweeper[bot]

@clawsweeper re-review

ProspectOre avatar Jun 16 '26 17:06 ProspectOre

๐Ÿฆž๐Ÿงน 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:

  • State: Failed
  • Detail: The targeted re-review timed out or failed while waiting for exact-review Codex capacity. Retry after capacity recovers.
  • Run: https://github.com/openclaw/clawsweeper/actions/runs/27635548469
  • Updated: 2026-06-16T17:42:02.446Z

clawsweeper[bot] avatar Jun 16 '26 17:06 clawsweeper[bot]

๐Ÿฆž๐Ÿงน 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:

  • State: Complete
  • Detail: The targeted re-review finished, the durable review comment was updated, and the synced verdict was routed.
  • Run: https://github.com/openclaw/clawsweeper/actions/runs/27738452481
  • Updated: 2026-06-18T05:43:13.890Z

clawsweeper[bot] avatar Jun 16 '26 18:06 clawsweeper[bot]

@clawsweeper re-review

ProspectOre avatar Jun 18 '26 04:06 ProspectOre

Maintainer verification on exact head 6a82264f:

  • Hosted CI passed all four macOS test shards, Linux x64/arm64 build-test-smoke lanes, aggregate lint, and security checks.
  • 22 focused WebView cache/memory-pressure tests passed locally; make check passed.
  • Full branch autoreview found no accepted/actionable findings.
  • DEBUG runtime proof released one idle WebView while retaining the busy view (before=2, after=1, evicted=1); the freshly signed package launched and remained alive.

Squash-merging this exact head. Thanks @ProspectOre!

steipete avatar Jun 19 '26 00:06 steipete