Skip to content

perf(browser): Phase 2b+3b Tier 3 hibernation, transparent RPC auto-wake & 64 MiB idle capture cap - #1393

Merged
Hona merged 2 commits into
devfrom
feat/browser-ram-phase2b
Nov 27, 2026
Merged

Hona merged 2 commits into
devfrom
feat/browser-ram-phase2b

Conversation

@Hona

@Hona Hona commented Nov 27, 2026

Copy link
Copy Markdown
Member

Summary

Implements Phase 2b + Phase 3b of the browser RAM reduction plan on top of Phase 2a (#1391) without modifying apps/browser-engine/ (ENGINE_REVISION remains at 26):

  1. Tier 3 Hibernation Triggers & Blockers (apps/desktop/src/surfaces/browser/residency.rs, shell/tabs/actions.rs, session/inbox/model.rs, app.rs)

    • Pure 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 open ContextKind::RemoteServer).
    • Canonical App::hibernate_browser_tab: ensures the tab leaves visible_tabs before calling BrowserHost::hibernate_tab, revokes any PreviewTabBinding immediately to free PreviewFetchPool permits, and calls rpc::on_tab_hibernated to clear frames/refs/cdp_bootstrapped/bootstrap_frame_reqs and bump generation on hibernate (never on wake).
    • Triggers:
      • Session close / archive (App::hibernate_browser_tabs_for_session with wasm32 no-op stub): hibernates eligible tabs for the session and its subagent family while preserving BrowserTab metadata and strip entries for ⇧⌘T and Undo Archive.
      • Idle background timer (HIBERNATE_AFTER = 15 min): wired into tick_browser_residency and browser_residency_wake, re-checking eligibility per tab so the last live RemoteServer tab is always retained.
      • Idle rest sweep (App::rest -> App::hibernate_orphaned_browser_tabs): catches tabs that were busy/loading when their session closed and later became idle.
  2. Seamless User Wake (surfaces/browser/{residency.rs, mod.rs, poll.rs}, plugin_host/native/browser*, crates/browser-pane/src/preview.rs)

    • App::wake_browser_tab re-binds PreviewTabBinding for hibernated preview/artifact tabs (failing closed cleanly if the owning server is gone) and delegates to BrowserHost::wake_tab; App::wake_browser_tab_to_url wakes non-preview tabs directly to a new URL.
    • Wired into poll_browser visibility wake (with refusal guard + proxy-reconnect recovery so missing proxies never spin), Navigate, Reload/ReloadFromClick/ReloadIgnoreCache, Find, DevtoolsAsync/SiteCookiesAsync/ClearSiteAsync/ClearCacheAsync, SetViewport, and drain_extension_wake_tabs.
    • Tightened BrowserHost::tab_open_in_engine to require t.has_engine_tab, and stepped ResidencyEvent::BeginWake when reopen_tab_as_{web,preview} reopens a hibernated tab.
  3. Transparent Agent experimental.browser v4 RPC Auto-Wake (apps/desktop/src/surfaces/browser/rpc/exec/wake.rs, exec/mod.rs, exec/nav.rs, exec/capture.rs)

    • Explicit WakePolicy (NoWake, ImmediateStaleRef, DirectTarget, WakeBeforeDispatch) and explicit WakeStage (Confirm -> Load -> EvalContext) state machine in ExecPhase::Wake(WakeState).
    • NoWake commands read desktop-retained diagnostics/captures/downloads without waking (network.get returns responseBody: unavailable cleanly when hibernated).
    • ImmediateStaleRef commands fail immediately with STALE_REF without waking.
    • DirectTarget commands (navigate, navigate.path, preview, reload) wake directly into their target URL/preview without double-loading the prior URL.
    • WakeBeforeDispatch acquires 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 into start_inspect or dispatch_command_after_wake.
  4. 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)

    • Tracks last_activity and capture_lru per SessionAttachment and enforces MAX_GLOBAL_IDLE_CAPTURE_BYTES = 64 MiB by evicting the oldest captures from idle sessions (never evicting the active session or any session with busy turns, active commands, or recordings).
    • Updated the stale FreezeTab doc comment in crates/browser-pane/src/protocol.rs to reference Page.setWebLifecycleState("frozen").

Verification

  • pwsh -NoProfile -File scripts/guardrails.ps1: 10/10 passed (0 errors, ENGINE_REVISION 26 unchanged, 0 files > 800 lines in desktop/features/crates).
  • bun scripts/web-clock.ts: passed (0 std::time::Instant / SystemTime::now violations).
  • 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.

Hona added 2 commits November 27, 2026 20:47
…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.
@Hona
Hona merged commit ec63ae1 into dev Nov 27, 2026
7 checks passed
@Hona
Hona deleted the feat/browser-ram-phase2b branch November 27, 2026 11:09
@Hona Hona mentioned this pull request Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant