Protect visible browser web views from discard
Summary
- Add workspace-layout protection to browser hidden-webview discard blockers.
- Feed browser panels from the same rendered-panel visibility set used by hibernation protection.
- Add a regression test covering a workspace-visible browser whose WebView was transiently reported hidden.
Testing
xcodebuild test -project cmux.xcodeproj -scheme cmux-unit -configuration Debug -destination 'platform=macOS' -derivedDataPath /tmp/cmux-bhib-test -only-testing:cmuxTests/BrowserHiddenWebViewDiscardManagerTests/testWorkspaceVisibleBrowserPanelBlocksHiddenWebViewDiscard\n-./scripts/reload-cloud.sh --tag bhib\n\n## Issues\n- Closes https://github.com/manaflow-ai/cmux/issues/6189
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.
[!NOTE]
Medium Risk
Touches browser memory lifecycle and workspace/portal visibility reconciliation; wrong gating could leave WebViews undiscarded or discard too aggressively, but behavior is scoped with explicit blockers and tests.
Overview
Adds a workspace_visible hidden-webview discard blocker so browser panels in the rendered layout are not memory-discarded when SwiftUI or the portal briefly reports the WebView hidden.
Workspace tracks presentation visibility (setWorkspacePresentationVisible from WorkspaceContentView) and drives setWorkspaceVisibilityProtectsHiddenWebViewDiscard during browser portal reconciliation, using the same rendered-panel set as layout visibility but only while the workspace is presented. Canvas inline hosting clears that protection on mount/render/occlude/unmount so discard follows canvas visibility instead.
Clearing protection while the WebView is still hidden resets the hidden-at timestamp so the discard timer does not fire immediately after a stale hide. Portal hide and workspace retire clear the blocker as well.
Regression coverage is in BrowserWorkspaceVisibleDiscardTests (visible panel + transient hide, clock restart, canvas-inline exclusion, background-mounted workspace).
Reviewed by Cursor Bugbot for commit d43d4043d4648421c53243f74530e1dd3264989f. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by cubic
Prevents discarding browser WebViews that are still visible by adding a workspace_visible blocker keyed off the presentation-visible rendered layout. Canvas-inline hosts are excluded, and clearing protection while hidden restarts the discard timer.
- Bug Fixes
- Added
workspace_visibleto discard blockers/lifecycle payload; toggling re-schedules; clearing while hidden resets the hidden-at timestamp. - Protection syncs from presentation-visible rendered panel IDs via
Workspace.setWorkspacePresentationVisible; portal hide, canvas mount/render/unmount, and workspace retire clear it. Tests cover the blocker, clock restart, canvas-inline exclusion, workspace retire clearing, and background-mounted workspace exclusion.
- Added
Summary by CodeRabbit
-
New Features
- Added workspace visibility-based protection mechanism to prevent hidden browser web views from being unexpectedly discarded during resource cleanup.
-
Tests
- Added test suite verifying workspace visibility discard protection behavior, including scenarios for visible panels, protection state changes, and canvas inline panels.