Repository navigation
perf(browser): Phase 2b+3b Tier 3 hibernation, transparent RPC auto-wake & 64 MiB idle capture cap - #1393
Merged
Conversation
…ake & 64 MiB idle capture cap - Add Tier 3 hibernation triggers (session close/archive, 15 min idle background timer, App::rest orphaned tab sweep) and full blocker predicates (active RPC/profiling/session turns, unthrottled holds, pending downloads, dialogs, private tabs, last live RemoteServer tab). - Clear renderer-scoped RPC state (frames/refs/cdp_bootstrapped) and bump generation on hibernate (never on wake), preserving wire tab IDs, diagnostics, captures, and downloads. - Add seamless user wake across poll_browser visibility sync, address-bar Navigate, Reload, Find, DevTools/Site async methods, SetViewport, and extension wake requests (re-binding preview tabs on wake). - Add explicit WakePolicy + WakeState machine for transparent experimental.browser v4 RPC auto-wake (NoWake, ImmediateStaleRef, DirectTarget, WakeBeforeDispatch with eval-context settling). - Enforce a 64 MiB global idle desktop capture LRU cap across inactive sessions without evicting active or busy sessions. - Update stale FreezeTab protocol doc comment and tighten BrowserHost::tab_open_in_engine + preview reopen residency transitions.
- Keep TabResidency::Waking across EngineReset and preserve original hidden_since on Hidden -> Frozen so HIBERNATE_AFTER is 15 min from hide. - Fix WakeState 100 Hz cold-start spin (Confirm wakes at deadline), measure WAKE_COMMIT_GRACE from confirmed_at, fail early on refusal, fail DOCUMENT_CHANGED on direct authorized commands targeting hibernated/waking tabs, and guard WakeState::cancel_cleanup against visible tabs or concurrent wakes. - Route agent navigate through App::navigate_browser_tab, treat hibernated/waking as is_new_tab in WaitLoad, fail back/forward cleanly on hibernated tabs, classify scroll/press with ref as ImmediateStaleRef, and default unknown tab_id commands to WakeBeforeDispatch. - Guard child subagent tabs on parent close/archive, block hibernation on refusal banners and anchored extension popups, cap browser.proxy.required auto-recovery to one attempt per proxy endpoint, skip spawning offline remote/artifact previews, ensure preview bindings on reload, and fail fast with wake-in-progress on Luau DevTools/Site/ClearCache/Find. - Return Option<usize> from evict_oldest_capture so 0-byte captures never stall LRU eviction, protect the full active panel_root family, and cleanly unwrap single-line multi-statement formatting while keeping all files <= 800 lines.
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 2b + Phase 3b of the browser RAM reduction plan on top of Phase 2a (#1391) without modifying
apps/browser-engine/(ENGINE_REVISIONremains at 26):Tier 3 Hibernation Triggers & Blockers (
apps/desktop/src/surfaces/browser/residency.rs,shell/tabs/actions.rs,session/inbox/model.rs,app.rs)can_hibernate_tab(app, tab_id, for_session_close)gating hard blockers (loading, JS/auth/permission prompts, pending downloads/save dialogs, in-flight DevTools, active RPC commands/recordings or busy owning session/subtree, unthrottled holds,about:blank/unnamed tabs) and idle-only blockers (visible, audible, notification/camera/mic grants, overlay/inspecting/app-link reviews/extension popup,ContextKind::Private, and the last live tab of an openContextKind::RemoteServer).App::hibernate_browser_tab: ensures the tab leavesvisible_tabsbefore callingBrowserHost::hibernate_tab, revokes anyPreviewTabBindingimmediately to freePreviewFetchPoolpermits, and callsrpc::on_tab_hibernatedto clearframes/refs/cdp_bootstrapped/bootstrap_frame_reqsand bumpgenerationon hibernate (never on wake).App::hibernate_browser_tabs_for_sessionwithwasm32no-op stub): hibernates eligible tabs for the session and its subagent family while preservingBrowserTabmetadata and strip entries for⇧⌘Tand Undo Archive.HIBERNATE_AFTER = 15 min): wired intotick_browser_residencyandbrowser_residency_wake, re-checking eligibility per tab so the last liveRemoteServertab is always retained.App::rest->App::hibernate_orphaned_browser_tabs): catches tabs that were busy/loading when their session closed and later became idle.Seamless User Wake (
surfaces/browser/{residency.rs, mod.rs, poll.rs},plugin_host/native/browser*,crates/browser-pane/src/preview.rs)App::wake_browser_tabre-bindsPreviewTabBindingfor hibernated preview/artifact tabs (failing closed cleanly if the owning server is gone) and delegates toBrowserHost::wake_tab;App::wake_browser_tab_to_urlwakes non-preview tabs directly to a new URL.poll_browservisibility wake (with refusal guard + proxy-reconnect recovery so missing proxies never spin),Navigate,Reload/ReloadFromClick/ReloadIgnoreCache,Find,DevtoolsAsync/SiteCookiesAsync/ClearSiteAsync/ClearCacheAsync,SetViewport, anddrain_extension_wake_tabs.BrowserHost::tab_open_in_engineto requiret.has_engine_tab, and steppedResidencyEvent::BeginWakewhenreopen_tab_as_{web,preview}reopens a hibernated tab.Transparent Agent
experimental.browserv4 RPC Auto-Wake (apps/desktop/src/surfaces/browser/rpc/exec/wake.rs,exec/mod.rs,exec/nav.rs,exec/capture.rs)WakePolicy(NoWake,ImmediateStaleRef,DirectTarget,WakeBeforeDispatch) and explicitWakeStage(Confirm->Load->EvalContext) state machine inExecPhase::Wake(WakeState).NoWakecommands read desktop-retained diagnostics/captures/downloads without waking (network.getreturnsresponseBody: unavailablecleanly when hibernated).ImmediateStaleRefcommands fail immediately withSTALE_REFwithout waking.DirectTargetcommands (navigate,navigate.path,preview,reload) wake directly into their target URL/preview without double-loading the prior URL.WakeBeforeDispatchacquires the unthrottle hold synchronously, wakes, waits for engine confirmation + initial load + optional main-frame eval context (bounded by 2 s grace), and re-dispatches cleanly intostart_inspectordispatch_command_after_wake.Phase 3b — Global 64 MiB Idle Desktop Capture LRU Cap (
apps/desktop/src/surfaces/browser/rpc/session/captures.rs,rpc/session.rs,rpc/mod.rs) + protocol doc fix (crates/browser-pane/src/protocol.rs)last_activityandcapture_lruperSessionAttachmentand enforcesMAX_GLOBAL_IDLE_CAPTURE_BYTES = 64 MiBby evicting the oldest captures from idle sessions (never evicting the active session or any session with busy turns, active commands, or recordings).FreezeTabdoc comment incrates/browser-pane/src/protocol.rsto referencePage.setWebLifecycleState("frozen").Verification
pwsh -NoProfile -File scripts/guardrails.ps1: 10/10 passed (0 errors,ENGINE_REVISION 26unchanged, 0 files > 800 lines in desktop/features/crates).bun scripts/web-clock.ts: passed (0std::time::Instant/SystemTime::nowviolations).cargo check -p browser-pane -p opencode-desktop: passed (0 errors, 0 warnings in modified/new files).cargo check -p browser-pane --no-default-features: passed.