Release idle WebViews on memory pressure
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 WebViewsseeds the shared dashboard WebView cache with one idle entry and one busy entry, runs theMemoryPressureMonitorwarning 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 linewarning com.steipete.codexbar.memory-pressure: level=warning [CodexBarCore] System memory pressureduring 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 localsudo /usr/bin/memory_pressure -S -l warn/criticalsimulation 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 existingnode --check docs/site.jsESM mismatch under Node v25.9.0; the checkedupstream/main:docs/site.jsstarts with an ESM import as well, so this is not introduced by this patch.
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:
- 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. - 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. - 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:
- Repository policy read: AGENTS.md was read fully; its focused SwiftPM testing guidance, no live credential probing guidance, and Swift concurrency caution around memory-pressure paths shaped the review. (
AGENTS.md:1, 518764ead945) - Current main behavior: Current main exposes full WebView cache eviction but does not include the PR's idle-only memory-pressure eviction entry point. (
Sources/CodexBarCore/OpenAIWeb/OpenAIDashboardFetcher.swift:422, 518764ead945) - Memory-pressure handler: At PR head, MemoryPressureMonitor registers warning/critical DispatchSource events, hops cache work to the main actor, and dispatches malloc relief to a detached utility task. (
Sources/CodexBar/MemoryPressureMonitor.swift:20, 6a82264f5bd4) - Idle-only eviction boundary: The added cache method filters out busy entries before clearing preserved pages, closing hosts, and removing idle WebViews. (
Sources/CodexBarCore/OpenAIWeb/OpenAIDashboardWebViewCache.swift:472, 6a82264f5bd4) - Focused coverage: The PR adds tests for idle-only eviction, monitor-driven shared-cache eviction, and off-main malloc pressure relief scheduling. (
Tests/CodexBarTests/OpenAIDashboardWebViewCacheTests.swift:404, 6a82264f5bd4) - PR proof and checks: The PR body reports focused tests, make check, a successful development-signed launch, and DEBUG runtime logs showing before=2 after=1 evicted=1; latest macOS CI jobs were still in progress at inspection. (6a82264f5bd4)
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-reviewcomments, 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-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only. - Maintainers can also comment
@clawsweeper reviewto 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 explainto ask for more context, or@clawsweeper stopto stop active automation.
@clawsweeper re-review
๐ฆ๐งน 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 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 re-review
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 checkpassed. - 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!