Repository navigation
perf(memory): hibernate idle background tabs and completed subagent transcripts - #2560
Merged
Merged
Conversation
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
Evicts reloadable heavy session payloads for idle background tabs and completed non-visible subagents via an explicit state machine in
apps/desktop/src/shell/tab_hibernate.rs, bounding steady-state live heap without altering tab state, scroll position, composer drafts, or animation framerate.Evidence
In live profiling (
opencode-desktop.exev0.0.0-dev-543),Heap liveclimbed from 81.9 MB (cold start, 8 tabs) to 211.4 MB (+129.5 MB) over 6.8 min across 9 open tabs, with single-tab jumps of+17.8 MB,+14.7 MB,+22.1 MB, and+37.2 MB.memory_reclaim::sweep_current_serverkeeps full transcripts, page caches, context windows, review diffs, and every completed descendant subagent transcript resident for all open tabs indefinitely.Changes
apps/desktop/src/shell/tab_hibernate.rs(419 lines,#![forbid(unsafe_code)]):60 sgrace): Unloads finished, non-visible subagent sessions (SessionInfo.parent.is_some()and not open as their own tab) even while their parent tab remains active or runs sibling subagents. Active/running subagents protect their ancestor chain (s.ancestors(id)), leaving completed siblings eligible.180 sgrace): Hibernates open session tabs outside the 2 most-recently-visited background tabs per window (WARM_BACKGROUND_TABS = 2). Viewing a child subagent tracks its root tab asactive_tabso the parent tab does not consume one of the 2 MRU slots.TabWarmth(Active,Busy,WarmMru { left_at },Cooling { idle_since, kind }) viastep_warmth.SweepPhase(Idle,Armed { due }) viastep_phase— arms a singletx.wake_at(due)for the earliest cooling deadline and returns toIdle(zero wakeups) when nothing is cooling.Fingerprint(route,tabs,running,pending,requests,inboxes,checkoutversions,transcripts.len(),opening.is_some(),live,online). Omitstranscriptsversion so streaming token deltas never trigger scans, allocations, orDerefMutbumps. Always returnsfalse(offscreen eviction alters no pixels).opening.id/opening.from, and all ancestors.windows::other_windows_shown), and all servers whilewindows::any_other_window_unreportedis true.2most-recently-visited background session tabs across active and parked servers.running, stopping (stops), optimistic starts (queue.starts), queued (inboxes), awaitingpendingpermission/form prompts orrequests, holdingunsentprompts, localechoes, held submits (queue.submit), active queue ops (QUEUE_OPS), busy rewinds (REWIND), open fork dialog (FORK), running shells/stopping items/open shell panel, or running background jobs (SHELLS).TabKind::Draft).!Source::Live,!pages.has_pool(),reconnect::down, orfixture_run.stage.is_some()).s.pages.forget(sid),s.transcript_edits.remove(&mut s.transcripts, sid),s.context_windows.forget(server, sid), staleSTREAM_GAPSentries, per-windowreview::REVIEW.sessions+prune_cache(&warm_ids, &warm_dirs)andturn_diffs(only when not warm on any server half), globalretain_user_messages, andpurge_free_pages_soft()on native targets.App::tabs,App::sessions(titles, badges, unread/failed dots), saved scroll places (restore::RESTORE/KEPT_PLACES,timeline_fx.ends), and composer drafts & attachments.apps/desktop/src/shell/mod.rs(+1 line): Exportpub mod tab_hibernate;.apps/desktop/src/kernel.rs(+3 lines): RegisterHIBERNATEslot and scheduletab_hibernate.pollinstage::PERSIST_FLUSHafterwindows.persist.Rehydration proof (no tab-switch edits required)
Ctrl+Tab/⌘1–9:App::select_tab(shell/tabs/actions.rs:377) callsservers::runtime::switchthenApp::open(session/meta/open.rs:11). Withpages.has_pool() && !transcripts.contains_key(id),heldistrue, invokingApp::begin_open(session/pages/mod.rs:412).begin_open->open_now+open_page: Holds the prior frame duringHOLD(zero blank flash), restores scroll mode (timeline_fx.ends.reopen), composer draft (show_draft),context_windowsentry (window_opened), and Review source/refresh (plugin_host::native::diff::prepare_route->set_session_change_mode->ensure_sessionor immediate refresh).open_pageenqueues a deduplicated foreground explicit read (pages.request(key, true)).poll_pages/merge_joined/poll_open): Repopulatestranscriptsandcontext_windows(window_read), markspages.sync.server_read, clearsopening, restores exact saved scroll offset (land_place), and schedules history pagination (schedule_history).App::navigate(shell/nav/history.rs:157) andopen_subagent_sessionroute throughApp::open; any direct route assignment falls back toApp::read_shown_session(session/pages/shown.rs:11).TurnDiffs::viewre-fetches lazily on draw; reopening the Review panel triggersopen_review->ensure_session.events/mod.rs:307usestranscript_edits.edit(no-op if absent), andpoll_pages(session/pages/mod.rs:684) ignores speculative pages for unrouted absent transcripts.Verification
cargo check -p opencode-desktop --no-default-features --features knobs— pass (0 warnings in touched files)cargo check -p opencode-web --target wasm32-unknown-unknown— pass (0 warnings in touched files)pwsh scripts/guardrails.ps1— pass (12/12 passed)git diff --check— cleantab_hibernate.rs: 419 lines (<= 450), zero tests, zero.cursor(...), zerostd::time::Instant/SystemTime::now