Repository navigation
feat(desktop): finish SUPER-1545 — alt-screen exemption, persist guard, hidden-webview LRU - #5754
Conversation
… hidden-webview LRU - Terminal eviction never selects runtimes in the alternate screen (in-place TUIs restore as garbled snapshots); exempt entries still occupy the parked count so plain shells evict sooner in their place. - Eviction is skipped (runtime kept alive, warn once) when the buffer cannot be persisted to localStorage, instead of silently losing it. - v2 browser panes get the same treatment: hidden webviews are LRU-destroyed past a cap of 3 (each is a full guest process) and rebuilt from the pane's persisted URL on next attach, reusing the shared pure eviction policy.
|
Ready to review this PR? Stage has broken it down into 5 individual chapters for you: Chapters generated by Stage for commit cd09fdd on Jul 19, 2026 6:14am UTC. |
📝 WalkthroughWalkthroughThe PR extends terminal runtime eviction with exempt entries and persistence safeguards, and adds deferred LRU eviction for detached browser webviews. Documentation records both eviction paths as shipped and CDP-verified. ChangesRuntime eviction lifecycle
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant BrowserRuntimeRegistryImpl
participant selectRuntimesToEvict
participant electronTrpcClient
BrowserRuntimeRegistryImpl->>BrowserRuntimeRegistryImpl: detach hidden webview
BrowserRuntimeRegistryImpl->>selectRuntimesToEvict: select excess hidden entries by LRU
selectRuntimesToEvict-->>BrowserRuntimeRegistryImpl: return eviction victims
BrowserRuntimeRegistryImpl->>electronTrpcClient: unregister destroyed webview
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/BrowserPane/browserRuntimeRegistry.ts (1)
434-440: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider using the map function of
Array.fromto avoid intermediate array allocation.You can pass the map function directly to
Array.fromas its second argument, which prevents the creation of an intermediate array before mapping.💡 Proposed refactor
- const candidates = Array.from(this.entries.entries()).map( - ([paneId, entry]) => ({ - paneId, - runtime: { container: entry.visible ? entry : null }, - lastUsedAt: entry.lastUsedAt, - }), - ); + const candidates = Array.from( + this.entries.entries(), + ([paneId, entry]) => ({ + paneId, + runtime: { container: entry.visible ? entry : null }, + lastUsedAt: entry.lastUsedAt, + }), + );🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/`$workspaceId/hooks/usePaneRegistry/components/BrowserPane/browserRuntimeRegistry.ts around lines 434 - 440, Update the candidates construction in the browser runtime registry to pass the existing entry-mapping callback as the second argument to Array.from, rather than calling .map on the intermediate array. Preserve the paneId, visible-container, and lastUsedAt values unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In
`@apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/`$workspaceId/hooks/usePaneRegistry/components/BrowserPane/browserRuntimeRegistry.ts:
- Around line 434-440: Update the candidates construction in the browser runtime
registry to pass the existing entry-mapping callback as the second argument to
Array.from, rather than calling .map on the intermediate array. Preserve the
paneId, visible-container, and lastUsedAt values unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 15a52ca9-c262-4782-8f8a-fcb132142eba
📒 Files selected for processing (6)
apps/desktop/docs/MEMORY_AND_WORKERS_REVIEW.mdapps/desktop/src/renderer/lib/terminal/terminal-runtime-eviction.test.tsapps/desktop/src/renderer/lib/terminal/terminal-runtime-eviction.tsapps/desktop/src/renderer/lib/terminal/terminal-runtime-registry.tsapps/desktop/src/renderer/lib/terminal/terminal-runtime.tsapps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/BrowserPane/browserRuntimeRegistry.ts
Greptile SummaryThis PR completes SUPER-1545 by adding three safety features on top of the terminal LRU eviction shipped in #5751: an alternate-screen exemption (vim/less TUIs are never evicted), a persist guard (eviction skips if the buffer can't be written to localStorage), and a hidden-webview LRU for browser panes (capped at 3 alive Chromium guest processes, oldest-first rebuild from persisted URL on re-open).
Confidence Score: 3/5The terminal-side changes are well-constructed and well-tested, but the browser webview LRU has a structural defect that leaves pane UI permanently stale after eviction and re-open. The eviction path in browserRuntimeRegistry.ts — the
|
| Filename | Overview |
|---|---|
| apps/desktop/src/renderer/lib/terminal/terminal-runtime-eviction.ts | Adds optional isExempt predicate to selectRuntimesToEvict; excess computed over all parked entries, only non-exempt selected. Logic and tests are correct. |
| apps/desktop/src/renderer/lib/terminal/terminal-runtime-eviction.test.ts | Three new test cases cover exemption ordering, early-stop when only exempt entries remain, and exempt-slot semantics. All cases are mutation-verified per the PR description. |
| apps/desktop/src/renderer/lib/terminal/terminal-runtime.ts | New tryPersistRuntimeState export correctly gates eviction on a successful localStorage write. Dimensions are persisted outside the try block but persistDimensions swallows its own errors. Calling this before disposeEntry({clearPersistedState:false}) results in the buffer being serialized twice. |
| apps/desktop/src/renderer/lib/terminal/terminal-runtime-registry.ts | Wires alt-screen exemption and persist guard into the eviction sweep. The !entry.runtime guard in the eviction loop is dead code (selectRuntimesToEvict already guarantees non-null runtime). Double persist path is a P2 efficiency issue. |
| apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/BrowserPane/browserRuntimeRegistry.ts | Adds hidden-webview LRU capped at 3. The eviction candidate adapter is correct. However, destroy() deletes the listenersByPaneId entry, silently severing any active React subscriptions; after evict+re-attach, state notifications are never delivered to live subscribers. |
| apps/desktop/docs/MEMORY_AND_WORKERS_REVIEW.md | Status row updated to reflect shipped state and CDP verification date. No code impact. |
Sequence Diagram
%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant React as React BrowserPane
participant Reg as browserRuntimeRegistry
participant Policy as selectRuntimesToEvict
React->>Reg: attach(paneId, placeholder, url, onPersist)
Reg->>Reg: "createEntry / set visible=true, lastUsedAt=++seq"
React->>Reg: onStateChange(paneId, listener)
Note over React,Reg: User switches away
React->>Reg: "detach(paneId) - visible=false, lastUsedAt=++seq"
Reg->>Reg: scheduleHiddenEviction() [setTimeout 0]
Reg->>Policy: "selectRuntimesToEvict(candidates, cap=3)"
Policy-->>Reg: [victim paneIds]
Reg->>Reg: destroy(victim) - entries.delete + listenersByPaneId.delete
Note over React,Reg: User re-opens evicted pane
React->>Reg: attach(paneId, placeholder, url, onPersist)
Reg->>Reg: createEntry (new webview, loads url)
Reg->>Reg: setState - notify(paneId)
Note over Reg: listenersByPaneId has no entry for paneId
Note over React: listener never fires - stale state displayed
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant React as React BrowserPane
participant Reg as browserRuntimeRegistry
participant Policy as selectRuntimesToEvict
React->>Reg: attach(paneId, placeholder, url, onPersist)
Reg->>Reg: "createEntry / set visible=true, lastUsedAt=++seq"
React->>Reg: onStateChange(paneId, listener)
Note over React,Reg: User switches away
React->>Reg: "detach(paneId) - visible=false, lastUsedAt=++seq"
Reg->>Reg: scheduleHiddenEviction() [setTimeout 0]
Reg->>Policy: "selectRuntimesToEvict(candidates, cap=3)"
Policy-->>Reg: [victim paneIds]
Reg->>Reg: destroy(victim) - entries.delete + listenersByPaneId.delete
Note over React,Reg: User re-opens evicted pane
React->>Reg: attach(paneId, placeholder, url, onPersist)
Reg->>Reg: createEntry (new webview, loads url)
Reg->>Reg: setState - notify(paneId)
Note over Reg: listenersByPaneId has no entry for paneId
Note over React: listener never fires - stale state displayed
Comments Outside Diff (2)
-
apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/BrowserPane/browserRuntimeRegistry.ts, line 449-458 (link)Eviction severs existing React subscriptions
destroydeletes thelistenersByPaneIdentry before any React component listening on thatpaneIdhas a chance to re-subscribe. When the evicted pane is later re-opened,attachcreates a newRegistryEntry, and subsequentsetState→notifycalls find no Set for thatpaneId(becauselistenersByPaneId.get(paneId)returnsundefined). Any component that subscribed viaonStateChangebefore eviction — URL bar, loading indicator, favicon, nav-state — will never receive another notification, leaving the pane UI permanently stale after the first navigate on the rebuilt webview.The fix is to not delete the listener Set in
destroy. Subscribers already hold a reference to the Set via their closure cleanup; when the component eventually unmounts, it callslisteners.delete(listener), draining the Set naturally. Not deleting indestroymeansnotifycontinues to reach live subscribers across the evict-and-rebuild cycle without any component having to re-subscribe.Prompt To Fix With AI
This is a comment left during a code review. Path: apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/BrowserPane/browserRuntimeRegistry.ts Line: 449-458 Comment: **Eviction severs existing React subscriptions** `destroy` deletes the `listenersByPaneId` entry before any React component listening on that `paneId` has a chance to re-subscribe. When the evicted pane is later re-opened, `attach` creates a new `RegistryEntry`, and subsequent `setState` → `notify` calls find no Set for that `paneId` (because `listenersByPaneId.get(paneId)` returns `undefined`). Any component that subscribed via `onStateChange` before eviction — URL bar, loading indicator, favicon, nav-state — will never receive another notification, leaving the pane UI permanently stale after the first navigate on the rebuilt webview. The fix is to not delete the listener Set in `destroy`. Subscribers already hold a reference to the Set via their closure cleanup; when the component eventually unmounts, it calls `listeners.delete(listener)`, draining the Set naturally. Not deleting in `destroy` means `notify` continues to reach live subscribers across the evict-and-rebuild cycle without any component having to re-subscribe. How can I resolve this? If you propose a fix, please make it concise.
-
apps/desktop/src/renderer/lib/terminal/terminal-runtime-registry.ts, line 288-302 (link)Redundant double-serialize on every terminal eviction
tryPersistRuntimeStatealready serializes the xterm buffer and writes it to localStorage. Immediately after,disposeEntry(entry, { clearPersistedState: false })callsdisposeRuntimewhich — whenclearPersistedStateisfalse— callspersistBuffera second time (serializing the same unchanged buffer again). For a large scrollback this doubles both the CPU cost and the localStorage write. SincetryPersistRuntimeStatehas already guaranteed the state is on disk, consider passing a flag sodisposeRuntimeskips the second persist.Prompt To Fix With AI
This is a comment left during a code review. Path: apps/desktop/src/renderer/lib/terminal/terminal-runtime-registry.ts Line: 288-302 Comment: **Redundant double-serialize on every terminal eviction** `tryPersistRuntimeState` already serializes the xterm buffer and writes it to localStorage. Immediately after, `disposeEntry(entry, { clearPersistedState: false })` calls `disposeRuntime` which — when `clearPersistedState` is `false` — calls `persistBuffer` a second time (serializing the same unchanged buffer again). For a large scrollback this doubles both the CPU cost and the localStorage write. Since `tryPersistRuntimeState` has already guaranteed the state is on disk, consider passing a flag so `disposeRuntime` skips the second persist. How can I resolve this? If you propose a fix, please make it concise.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/BrowserPane/browserRuntimeRegistry.ts:449-458
**Eviction severs existing React subscriptions**
`destroy` deletes the `listenersByPaneId` entry before any React component listening on that `paneId` has a chance to re-subscribe. When the evicted pane is later re-opened, `attach` creates a new `RegistryEntry`, and subsequent `setState` → `notify` calls find no Set for that `paneId` (because `listenersByPaneId.get(paneId)` returns `undefined`). Any component that subscribed via `onStateChange` before eviction — URL bar, loading indicator, favicon, nav-state — will never receive another notification, leaving the pane UI permanently stale after the first navigate on the rebuilt webview.
The fix is to not delete the listener Set in `destroy`. Subscribers already hold a reference to the Set via their closure cleanup; when the component eventually unmounts, it calls `listeners.delete(listener)`, draining the Set naturally. Not deleting in `destroy` means `notify` continues to reach live subscribers across the evict-and-rebuild cycle without any component having to re-subscribe.
### Issue 2 of 2
apps/desktop/src/renderer/lib/terminal/terminal-runtime-registry.ts:288-302
**Redundant double-serialize on every terminal eviction**
`tryPersistRuntimeState` already serializes the xterm buffer and writes it to localStorage. Immediately after, `disposeEntry(entry, { clearPersistedState: false })` calls `disposeRuntime` which — when `clearPersistedState` is `false` — calls `persistBuffer` a second time (serializing the same unchanged buffer again). For a large scrollback this doubles both the CPU cost and the localStorage write. Since `tryPersistRuntimeState` has already guaranteed the state is on disk, consider passing a flag so `disposeRuntime` skips the second persist.
```suggestion
private evictExcessParkedRuntimes() {
const victims = selectRuntimesToEvict(
this.entries.values(),
this.parkedRuntimeCap,
// Alternate-screen TUIs restore as a garbled static snapshot — never evict them.
(entry) => entry.runtime?.terminal.buffer.active.type === "alternate",
);
for (const entry of victims) {
if (!entry.runtime || !tryPersistRuntimeState(entry.runtime)) {
warnPersistFailureOnce(entry.terminalId);
continue;
}
// State was already persisted by tryPersistRuntimeState; skip the
// second serialize+write that disposeRuntime would otherwise do.
this.disposeEntry(entry, { clearPersistedState: false, skipPersist: true });
}
}
```
Reviews (1): Last reviewed commit: "docs(desktop): mark terminal eviction sh..." | Re-trigger Greptile
There was a problem hiding this comment.
1 issue found across 6 files
You’re at about 95% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/desktop/src/renderer/lib/terminal/terminal-runtime-registry.ts">
<violation number="1" location="apps/desktop/src/renderer/lib/terminal/terminal-runtime-registry.ts:296">
P2: A runtime can be evicted even when its complete persisted state was not saved: `tryPersistRuntimeState` treats a failed dimensions write as success. Returning failure when either buffer or dimensions persistence fails would keep the runtime alive until its state is safely restorable.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| (entry) => entry.runtime?.terminal.buffer.active.type === "alternate", | ||
| ); | ||
| for (const entry of victims) { | ||
| if (!entry.runtime || !tryPersistRuntimeState(entry.runtime)) { |
There was a problem hiding this comment.
P2: A runtime can be evicted even when its complete persisted state was not saved: tryPersistRuntimeState treats a failed dimensions write as success. Returning failure when either buffer or dimensions persistence fails would keep the runtime alive until its state is safely restorable.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/desktop/src/renderer/lib/terminal/terminal-runtime-registry.ts, line 296:
<comment>A runtime can be evicted even when its complete persisted state was not saved: `tryPersistRuntimeState` treats a failed dimensions write as success. Returning failure when either buffer or dimensions persistence fails would keep the runtime alive until its state is safely restorable.</comment>
<file context>
@@ -288,8 +289,14 @@ class TerminalRuntimeRegistryImpl {
+ (entry) => entry.runtime?.terminal.buffer.active.type === "alternate",
);
for (const entry of victims) {
+ if (!entry.runtime || !tryPersistRuntimeState(entry.runtime)) {
+ warnPersistFailureOnce(entry.terminalId);
+ continue;
</file context>
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/desktop/src/renderer/lib/terminal/terminal-runtime.ts (1)
393-419: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
disposeRuntime's"persist"branch drops write failures silently.The eviction path now checks
tryPersistRuntimeState's boolean and keeps the runtime alive with a warning on failure (seeterminal-runtime-registry.tsevictExcessParkedRuntimes), but here (used byrelease())persistBuffer/persistDimensionsfailures are discarded with no fallback or signal — a quota-exceeded write during pane release silently loses scrollback/dimensions with no way to detect it later.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/desktop/src/renderer/lib/terminal/terminal-runtime.ts` around lines 393 - 419, Update disposeRuntime’s "persist" branch to use tryPersistRuntimeState and inspect its success result instead of discarding persistBuffer/persistDimensions failures. On failure, preserve the runtime’s state and emit the same warning or fallback signal used by evictExcessParkedRuntimes, while keeping the existing disposal flow for successful persistence and other persistedState values.
🧹 Nitpick comments (2)
apps/desktop/src/renderer/lib/terminal/terminal-runtime-registry.ts (1)
568-574: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win
warnPersistFailureOnceonly ever warns once per process lifetime, across all terminals.Once any single terminal fails to persist,
persistFailureWarnedis permanentlytrue, so later persist failures for different terminals — each of which remains pinned above the parked-runtime cap as a result — never surface a warning. This can silently mask a systemic quota problem that defeats the eviction cap's purpose.Consider keying the warning per-terminal (e.g. a
Set<string>) or resetting the flag on the next successful persist, so recurring failures across the fleet of parked terminals stay observable.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/desktop/src/renderer/lib/terminal/terminal-runtime-registry.ts` around lines 568 - 574, Update warnPersistFailureOnce to track warning state per terminal rather than using the process-wide persistFailureWarned flag. Use a Set keyed by terminalId (or reset the terminal’s warning state after a successful persist) so each terminal’s first persist failure is reported while duplicate warnings for that terminal remain suppressed.apps/desktop/src/renderer/lib/terminal/terminal-runtime.ts (1)
81-86: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUnify
persistBufferwith the inline buffer-write intryPersistRuntimeState.
persistDimensionswas updated to return a boolean and is now shared by both call sites, butpersistBufferwas left as a void, error-swallowing helper, sotryPersistRuntimeStatehad to re-implement the same serialize+localStorage.setItemlogic inline instead of reusing it. This duplicates the write logic and leaves two divergent error-handling conventions for the same operation.♻️ Suggested refactor: give `persistBuffer` a boolean return and reuse it
-function persistBuffer(terminalId: string, serializeAddon: SerializeAddon) { +function persistBuffer(terminalId: string, serializeAddon: SerializeAddon): boolean { try { const data = serializeAddon.serialize({ scrollback: SERIALIZE_SCROLLBACK }); localStorage.setItem(`${STORAGE_KEY_PREFIX}${terminalId}`, data); + return true; } catch {} + return false; }export function tryPersistRuntimeState(runtime: TerminalRuntime): boolean { - try { - const data = runtime.serializeAddon.serialize({ - scrollback: SERIALIZE_SCROLLBACK, - }); - localStorage.setItem(`${STORAGE_KEY_PREFIX}${runtime.terminalId}`, data); - } catch { - return false; - } + if (!persistBuffer(runtime.terminalId, runtime.serializeAddon)) return false; return persistDimensions( runtime.terminalId, runtime.lastCols, runtime.lastRows, ); }Also applies to: 99-113
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/desktop/src/renderer/lib/terminal/terminal-runtime.ts` around lines 81 - 86, Update persistBuffer to return a boolean indicating whether serialization and localStorage.setItem succeeded, returning false when either operation throws. Replace the duplicated inline buffer serialization/write logic in tryPersistRuntimeState with a call to persistBuffer, preserving its existing success/failure handling alongside persistDimensions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@apps/desktop/src/renderer/lib/terminal/terminal-runtime.ts`:
- Around line 393-419: Update disposeRuntime’s "persist" branch to use
tryPersistRuntimeState and inspect its success result instead of discarding
persistBuffer/persistDimensions failures. On failure, preserve the runtime’s
state and emit the same warning or fallback signal used by
evictExcessParkedRuntimes, while keeping the existing disposal flow for
successful persistence and other persistedState values.
---
Nitpick comments:
In `@apps/desktop/src/renderer/lib/terminal/terminal-runtime-registry.ts`:
- Around line 568-574: Update warnPersistFailureOnce to track warning state per
terminal rather than using the process-wide persistFailureWarned flag. Use a Set
keyed by terminalId (or reset the terminal’s warning state after a successful
persist) so each terminal’s first persist failure is reported while duplicate
warnings for that terminal remain suppressed.
In `@apps/desktop/src/renderer/lib/terminal/terminal-runtime.ts`:
- Around line 81-86: Update persistBuffer to return a boolean indicating whether
serialization and localStorage.setItem succeeded, returning false when either
operation throws. Replace the duplicated inline buffer serialization/write logic
in tryPersistRuntimeState with a call to persistBuffer, preserving its existing
success/failure handling alongside persistDimensions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 0952c8b8-b641-42b0-a586-6f5ba92f9490
📒 Files selected for processing (6)
apps/desktop/docs/MEMORY_AND_WORKERS_REVIEW.mdapps/desktop/src/renderer/lib/terminal/terminal-runtime-registry.test.tsapps/desktop/src/renderer/lib/terminal/terminal-runtime-registry.tsapps/desktop/src/renderer/lib/terminal/terminal-runtime.tsapps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/BrowserPane/browserRuntimeRegistry.test.tsapps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/BrowserPane/browserRuntimeRegistry.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- apps/desktop/docs/MEMORY_AND_WORKERS_REVIEW.md
- apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/usePaneRegistry/components/BrowserPane/browserRuntimeRegistry.ts
🧹 Preview Cleanup CompleteThe following preview resources have been cleaned up:
Thank you for your contribution! 🎉 |
Links
Summary
How It Works
terminal-runtime-eviction.ts) gains an optionalisExemptpredicate: excess is computed over all parked entries, but only non-exempt ones are selectable, so eviction stops early when only exempt entries remain. The terminal registry passesbuffer.active.type === "alternate"; the browser registry reuses the same function through a small candidate adapter (visible→ container).tryPersistRuntimeState(new export fromterminal-runtime.ts) reports persist success; the sweep only disposes runtimes whose buffers are safely on disk.browserRuntimeRegistrymirrors the terminal design:lastUsedAtbumped on attach/detach, deferred one-tick sweep (so pane switches re-adopt before counting), eviction via the existingdestroy()(which also unregisters main-process handlers), restore via the existingattach(initialUrl)path.Manual QA Checklist
Exercised live over CDP (dev app):
lessrunning in tab 0 (buffer typealternateconfirmed), cap lowered to 2, 6 other tabs cycled → TUI survives parked and occupies a cap slot; 1 recent shell kept; 5 plain shells evictedTesting
bun run lint,bun run typecheck— cleanbun test(full desktop suite) — 0 failslicealready clamps; dropped a redundantMath.min).Design Decisions
Known Limitations
onPersistis detached), so an evicted webview restores to its last visible URL. Same class as app-restart behavior.Infra note
This worktree's Neon dev branch had been deleted by the daily cleanup; re-provisioned (
br-curly-scene-afdvq3jq) to run the CDP verification. No code impact.Summary by cubic
Finishes SUPER-1545 by protecting TUIs and scrollback while keeping background memory bounded. Adds alt-screen exemption, a persist guard, and an LRU cap for hidden webviews, plus tighter eviction timing and cleanup.
New Features
selectRuntimesToEvictinbrowserRuntimeRegistry.Bug Fixes
onPersistafter detach to capture late navigation completion; unregister errors are now logged; hidden-webview eviction is deferred one tick to avoid pane-switch races.Written for commit cd09fdd. Summary will update on new commits.
Summary by CodeRabbit
New Features
Bug Fixes
Tests