Repository navigation
perf(browser): Phase 2a tab freeze, hibernate plumbing & ExtensionHost discarded support - #1391
Merged
Merged
Conversation
… discarded support
- Wire protocol & capabilities (ENGINE_REVISION 25 -> 26): add Ready.tab_hibernation, fire-and-forget HostMsg::{FreezeTab, HibernateTab} (exempt in refuse_if_controlled_tab_blocked), and EngineMsg::ExtensionWakeTab.
- Engine lifecycle: upgrade TabRenderMode to Hidden { frozen }, apply Page.setWebLifecycleState + Memory.simulatePressureNotification on FreezeTab and auto-unfreeze before was_hidden(0) on wake; add HibernateTab preserving completed agent downloads, staged uploads, and ExtensionHost discarded tab state until real CloseTab.
- CEF 156 media-capture signal: wire DisplayHandler::on_media_access_change to snap.audible without touching CefAudioHandler (preserving speaker audio) and guard Camera/Microphone visit_permissions on desktop.
- ExtensionHost: track ExtTab.{discarded, frozen}, update in-place on wake, exclude discarded tabs from unbound probes/binding, and emit ExtensionWakeTab / clean CloseTab for discarded targets.
- browser-pane & desktop: add explicit TabResidency state machine, freeze_tab / hibernate_tab / wake_tab / wake_tab_to_url, and activate Tier 2 CDP Freeze after 120s hidden with safety predicates and wake-timer scheduling.
Hona
force-pushed
the
feat/browser-ram-phase2a
branch
from
November 27, 2026 09:49
b5a1b33 to
497001d
Compare
…nderer purge, stable ext IDs, freeze/residency guards) - Desktop residency: gate tick_browser_residency/browser_residency_wake/can_freeze_tab on has_live_sidecar() (fixes 40 Hz disconnected spin), block freezing while download_save_requests are queued or Notifications permission is granted, and re-verify extension visibility in drain_extension_wake_tabs. - Passive audio playback: track HTMLMediaElement and AudioContext playback in TabMediaGate alongside on_media_access_change capture, reset on main-frame load_start/crash, and forward audible updates to ExtensionHost. - Engine lifecycle: replace browser-wide Memory.simulatePressureNotification with per-renderer Memory.forciblyPurgeJavaScriptMemory, early-return on RenderModeEffect::None before Linux t.shown write, unfreeze on reconnect/hello and before hidden Navigate/Back/Forward/Reload/CDP/DevTools calls, and keep empty hibernated tabs out of hibernated_downloads so EMPTY_GRACE still reclaims to 0 MB. - ExtensionHost: replace discarded/frozen bools with explicit ExtTabLifecycle enum in extensions/tab_lifecycle.rs (keeping extensions/mod.rs at 1,428 lines), retain stable ext_tab_ids while Discarded (clearing on wake), and harden close_hibernated_tab_from_ext. - browser-pane: encapsulate TabResidency behind getter, ignore late TabUpdate on Hibernated tabs, disallow Active->Hibernated, add WakeFailed/ContextReopened transitions, enforce policy::refusal & non-preview check in wake_tab_to_url, and replay custom zoom on cold-start/reconnect.
…ve audio monitor & hibernated close cleanup - Remove Memory.forciblyPurgeJavaScriptMemory on FreezeTab (triggers Chromium LocalFrame::ForciblyPurgeV8Memory context teardown); keep Page.setWebLifecycleState only. - Harden TabMediaGate passive audio playback monitor: WeakRef/WeakSet storage without dropping paused elements, guarded HTMLMediaElement.prototype.play wrapper, captured locals and literal JSON payloads, shared AudioContext/webkitAudioContext Proxy, 250 ms coalescing throttle, per-(session_id, executionContextId) playback tracking with cleanup on executionContextDestroyed, and forward only sound playback (not mic/cam capture) to ExtensionHost ExtTab.audible. - Run remove_tab_uploads and ext.on_tab_closed unconditionally in close_managed_tab's hibernated branch so hibernated agent_driven tabs always clean up uploads and ExtensionHost entries.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements Phase 2a of browser RAM reclamation: engine +
browser-paneTier 2 CDP Freeze & Tier 3HibernateTab/wake_tabplumbing,ExtensionHostdiscarded/frozensupport, the explicitTabResidencystate machine, and active Tier 2 CDP Freeze (120 s hidden).Tier 3 hibernation triggers (session close / 15 min idle) and Agent RPC auto-wake land atomically together in PR-2b immediately after this PR merges so no tab hibernates on
devwithout agent auto-wake.Changes
ENGINE_REVISION25 -> 26):EngineMsg::Ready.tab_hibernation, fire-and-forgetHostMsg::FreezeTab { tab_id, frozen }andHostMsg::HibernateTab { tab_id }(exempt inrefuse_if_controlled_tab_blocked, omitted fromexpects_answer()), andEngineMsg::ExtensionWakeTab { tab_id, focus, url, reload }.scripts/guardrails/engine-inputs.txtviaengine-revision.mjs --write.apps/browser-engine/src/handlers.rs):CefAudioHandlerredirects/captures PCM output rather than passively reporting speaker playback; leftCefAudioHandleruntouched and wired non-invasiveDisplayHandler::on_media_access_change(active camera/microphone capture) tosnap.audible(reset on crash), paired with desktopCamera/Microphonevisit_permissionschecks.HibernateTab(apps/browser-engine/src/engine/lifecycle.rs,engine.rs,engine/extensions.rs):TabRenderModeto an explicitHidden { frozen: bool } | AwakeBackground | Visiblestate machine withstep_render_mode.FreezeTab { frozen: true }sendsPage.setWebLifecycleState(frozen)+Memory.simulatePressureNotification(critical)only forHidden { frozen: false }; waking or unfreezing sendsPage.setWebLifecycleState(active)beforewas_hidden(0)+invalidate().HibernateTabtears down the CEF browser without emittingTabClosedor deleting completed agent downloads / staged uploads (preserving download generations inhibernated_downloadsacross wake cycles until realCloseTab).ExtensionHostdiscarded&frozensupport (apps/browser-engine/src/extensions/{mod.rs, rpc.rs, cdp.rs}):ExtTab.{discarded, frozen},set_tab_frozen,on_tab_hibernated, in-place wake inon_tab_opened,discarded/frozenserialization and query filtering inrpc.rs, and discarded-tab exclusion in unbound tab probes/reconciliation.ExtEffect::{FocusTab, NavigateTab, ReloadTab}on discarded tabs toEngineMsg::ExtensionWakeTab, andExtEffect::CloseTabto full hibernated cleanup +TabClosed.browser-paneresidency & wake APIs (crates/browser-pane/src/residency.rs,client/residency.rs,client/{mod.rs, poll.rs}):TabResidency(Active,Hidden,Frozen,Hibernated,Waking) + purestep(&mut TabResidency, ResidencyEvent) -> ResidencyEffectsusingrune::time::Instant.BrowserHost::{engine_tab_hibernation, freeze_tab, hibernate_tab, wake_tab, wake_tab_to_url, drain_extension_wake_tabs}with fail-closedRemoteServerproxy refresh, zoom/emulation/lifecycle replay, and automatic engine respawn on wake.apps/desktop/src/surfaces/browser/residency.rs,poll.rs):FREEZE_AFTER = 120s, purecan_freeze_tabsafety predicate (visibility, RPC hold, engine confirmation, loading, audible/media capture, user prompts, pending downloads, save dialog, DevTools, overlays, inspect, app-link review, extension popup, camera/mic visit permissions),tick_browser_residency,browser_residency_wakemerged intobrowser_visibility_wake, anddrain_extension_wake_tabs.Verification
pwsh -NoProfile -File scripts/guardrails.ps1: 9/9 passed (ENGINE_REVISION 26).bun scripts/web-clock.ts: passed (1125 files in 49 crates, zerostd::time::Instant/SystemTime::now).cargo check -p browser-pane --features engine: 0 errors, 0 warnings.cargo check -p browser-pane -p opencode-desktop: 0 errors, 0 warnings in modified files.cargo check --release --manifest-path apps/browser-engine/Cargo.toml: 0 errors, 0 warnings.cargo clippy --no-deps --libonbrowser-pane,opencode-browser-engine, andopencode-desktop: 0 warnings in modified files.