Trim app caches on memory pressure
Summary
Trims rebuildable app caches when the existing memory-pressure monitor fires.
This is stacked on #1575. Until #1575 merges, GitHub may show the WebView memory-pressure commits in this PR's diff as well.
What changed
- Adds a memory-pressure cache trim callback to
MemoryPressureMonitor. - Wires
AppDelegateinto that callback so pressure handling also trims app-level caches. - Clears rebuildable menu sizing/content caches and the transient menu-card recycle pool.
- Clears the OpenAI web debug ring buffer while leaving provider/session/auth/refresh state intact.
- Logs trim counts when anything was released.
Why
Low-memory machines benefit from releasing cached UI/debug data as soon as macOS reports memory pressure. These caches are local and rebuildable, so trimming them does not force provider probes, drop credentials, cancel refreshes, or clear usage snapshots.
Proof
swift test --filter MemoryPressureCacheTrimTests- 3 tests passed.
- Proves the monitor invokes the app trim handler.
- Proves menu cache counts before/after: 1 height cache, 1 width cache, 2 merged switcher selections, 1 recycled menu-card view trimmed to empty.
- Proves OpenAI web debug lines before/after: 3 debug lines trimmed to empty while
isRefreshing,refreshingProviders,tokenRefreshInFlight, refresh key, and refresh token stay unchanged.
swift test --filter OpenAIDashboardWebViewCacheTests- 19 tests passed.
- Reconfirms the same memory-pressure path still evicts idle shared WebViews without interrupting busy WebViews.
swiftlint --strict- 0 violations, 0 serious in 1141 files.
swiftformat Sources/CodexBar/MemoryPressureMonitor.swift Sources/CodexBar/CodexbarApp.swift Sources/CodexBar/StatusItemController.swift Sources/CodexBar/StatusItemController+MemoryPressure.swift Sources/CodexBar/UsageStore+MemoryPressure.swift Tests/CodexBarTests/MemoryPressureCacheTrimTests.swift- Completed cleanly.
git diff --check- Passed.
@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: 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/27635534002
- Updated: 2026-06-16T17:44:51.975Z
Codex review: needs maintainer review before merge. Reviewed June 18, 2026, 8:59 PM ET / 00:59 UTC.
Summary Adds memory-pressure trimming for rebuildable status-menu caches and OpenAI web debug buffers, with DEBUG proof seeding, focused tests, and a changelog entry.
Reproducibility: not applicable. this is a resource-management improvement rather than a deterministic broken-behavior report. The PR body supplies focused test results and copied runtime logs for the simulated pressure path.
Review metrics: 3 noteworthy metrics.
- Patch surface: 9 files, +297/-9. The diff spans app lifecycle wiring, the memory-pressure monitor, menu/cache trim helpers, tests, and changelog context.
- Reported focused validation: 25 tests plus make check. The PR body reports targeted memory-pressure and OpenAI WebView cache tests plus lint/format checks for the changed path.
- Latest check state: 6 pending, 1 passed. The latest head still needs the queued macOS Swift-test and Linux build checks to complete before final merge.
Merge readiness Overall: ๐ platinum hermit Proof: ๐ platinum hermit 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:
- Wait for the pending macOS Swift-test and Linux build checks to finish.
- Maintainer should accept the DEBUG-notification proof for this memory-pressure path or request a real pressure-event log.
Risk before merge
- [P1] The changed handler runs during macOS system memory pressure; incorrect actor handoff or cache clearing could affect app responsiveness or active menu/OpenAI refresh state even though the focused tests cover the intended boundaries.
- [P1] The live proof uses the DEBUG distributed-notification hook and seeded caches rather than a kernel-delivered memory-pressure event, so maintainers need to decide whether that proof is sufficient for this availability path.
- The latest GitHub CI run was still pending during this review; contributor-reported focused tests and make check are positive but final merge should wait for required checks.
Maintainer options:
- Land after CI with availability sign-off (recommended)
If CI passes, maintainers can merge with the existing DEBUG log proof and focused tests as the acceptance criteria for this memory-pressure path. - Request real pressure-event proof
If DEBUG notification proof is not enough, ask for a redacted runtime log or recording from a real macOS memory-pressure event before merge.
Next step before merge
- [P2] Human maintainer review is the remaining action because the patch has no narrow repair finding, but it changes an availability-sensitive runtime path and CI was pending.
Security Cleared: No concrete security or supply-chain concern was found; the diff adds local cache cleanup, DEBUG-only proof seeding, tests, and logging without new dependencies, scripts, permissions, or credential handling.
Review details
Best possible solution:
Land the cache-trim increment after pending CI and maintainer acceptance of the DEBUG/log proof for the memory-pressure path, keeping the rebuildable-only trim boundary and active refresh preservation tests intact.
Do we have a high-confidence way to reproduce the issue?
Not applicable: this is a resource-management improvement rather than a deterministic broken-behavior report. The PR body supplies focused test results and copied runtime logs for the simulated pressure path.
Is this the best way to solve the issue?
Yes, conditionally: trimming only rebuildable caches and preserving refresh state is a narrow maintainable path. The remaining question is maintainer acceptance of DEBUG/log proof plus completed CI for an availability-sensitive runtime handler.
AGENTS.md: found and applied where relevant.
Codex review notes: model internal, reasoning high; reviewed against f6f76ff9d01e.
Label changes
Label justifications:
P2: This is a normal-priority memory/resource-management improvement with limited blast radius across rebuildable app caches and OpenAI debug buffers.merge-risk: ๐จ availability: The PR changes runtime memory-pressure handling and cache teardown, where a mistake could affect app responsiveness or active refresh behavior.rating: ๐ platinum hermit: Overall readiness is ๐ platinum hermit; proof is ๐ platinum hermit 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 copied logs from a fresh debug executable showing a seeded pressure notification trimming caches and the app remaining running.proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes copied logs from a fresh debug executable showing a seeded pressure notification trimming caches and the app remaining running.
Evidence reviewed
What I checked:
- Repository policy read: AGENTS.md was present and read fully; its guidance on focused tests, avoiding live provider/Keychain validation, and conservative AppKit verification shaped this read-only review. (
AGENTS.md:1, f6f76ff9d01e) - Current main does not include this increment: The current main checkout has the merged memory-pressure monitor from the base PR, but no MemoryPressureCacheTrimSummary, trimRebuildableCachesForMemoryPressure, or MemoryPressureCacheTrimTests symbols. (f6f76ff9d01e)
- PR head trims app caches in the pressure handler: At PR head, MemoryPressureMonitor invokes the main-actor cache trim handler before dispatching allocator relief off the main actor. (
Sources/CodexBar/MemoryPressureMonitor.swift:116, b7022f095da2) - PR head wires status and store trimming: AppDelegate builds the memory-pressure monitor with a closure that merges StatusItemController and UsageStore trim summaries. (
Sources/CodexBar/CodexbarApp.swift:356, b7022f095da2) - PR head cache boundaries are rebuildable state: The status-controller extension clears menu height, width, merged-switcher, and recycle-pool caches; UsageStore clears OpenAI web debug buffers without touching refresh state. (
Sources/CodexBar/StatusItemController+MemoryPressure.swift:5, b7022f095da2) - Focused tests cover the intended trim behavior: The new test file checks that the monitor invokes cache trim and allocator relief, menu caches are emptied, and OpenAI refresh state survives debug-buffer trimming. (
Tests/CodexBarTests/MemoryPressureCacheTrimTests.swift:10, b7022f095da2)
Likely related people:
- ProspectOre: The merged base memory-pressure monitor and idle WebView eviction path on current main came from https://github.com/steipete/CodexBar/pull/1575, which this PR extends with app-cache trimming. (role: current-main memory-pressure feature introducer; confidence: high; commits: f6f76ff9d01e, 540f25f0c3e5, 77ba8fd6778d; files:
Sources/CodexBar/MemoryPressureMonitor.swift,Sources/CodexBarCore/OpenAIWeb/OpenAIDashboardWebViewCache.swift,Tests/CodexBarTests/OpenAIDashboardWebViewCacheTests.swift) - steipete: Recent history shows work on OpenAI WebView lifecycle, release state, menu/cache internals, and the PR-head combined cleanup test commit. (role: recent area contributor and PR-head repair author; confidence: high; commits: b7022f095da2, 5db1a04718e7, 06fea2c897cc; files:
Tests/CodexBarTests/MemoryPressureCacheTrimTests.swift,Sources/CodexBar/UsageStore+OpenAIWeb.swift,Sources/CodexBar/StatusItemController.swift) - bcssewl: GitHub commit history for the menu-card recycling and merged-switcher cache files points to the work that owns cache pools trimmed by this PR. (role: introduced adjacent menu-cache behavior; confidence: medium; commits: f927e8ad90ae; files:
Sources/CodexBar/StatusItemController+MenuCardRecycling.swift,Sources/CodexBar/StatusItemController+MergedSwitcherContentCache.swift,Tests/CodexBarTests/MenuCardViewRecyclingTests.swift) - naoterumaker: Recent WebView-cache history includes the idle-prune scheduling fix that the merged memory-pressure path builds on. (role: adjacent OpenAI WebView-cache contributor; confidence: medium; commits: 1246ec6fc3f7; files:
Sources/CodexBarCore/OpenAIWeb/OpenAIDashboardWebViewCache.swift,Tests/CodexBarTests/OpenAIDashboardWebViewCacheTests.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/27637981278
- Updated: 2026-06-16T18:28:23.463Z
@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: 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/27737060077
- Updated: 2026-06-18T05:14:23.272Z
@clawsweeper re-review
Landed after exact-head verification at b7022f095da258c0a2e21f535b762ef5375c64e5.
Proof:
- Focused memory-pressure and WebView-cache suite: 25 tests passed.
- Runtime hook: idle WebViews reduced from 2 to 1; active WebView retained; 7 rebuildable cache entries trimmed; allocator relief stayed off the main actor.
make check: passed; SwiftLint reported 0 violations.- Maintainer autoreview: no actionable findings.
- CI: all four macOS shards, Linux x64/arm64, lint aggregate, and security checks passed on the exact head.
Thanks @ProspectOre.