Skip to content

perf(editor): ask to save huge notebooks before a restart instead of backing them up - #28088

Closed
brennanb2025 wants to merge 1 commit into
mainfrom
brennanb2025/perf-notebook-backup-limit
Closed

brennanb2025 wants to merge 1 commit into
mainfrom
brennanb2025/perf-notebook-backup-limit

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​211 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​210
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​116 $\color{#cf222e}{\Huge{\mathbf{−}}}$​19 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​97

ELI5

So that unsaved work survives an update restart, Orca copies every unsaved file into its restart-recovery store, and does it again after every change. A notebook holding hundreds of MB of cell output made that copy hundreds of MB, rewritten each time the notebook changed, and Orca's background process grew by gigabytes. Now a notebook too large to back up is left out of that copy. Before an update or app restart, Orca asks whether to save it, the same way quitting already does.

What Changed

Before:

  • Every dirty file's full text went into the restart-recovery session on each change (150 ms after the last one). That session is saved by the main process into profile-state.db.
  • With a 200 MiB cell output in an open notebook, that database reached 426 MB after a few cell runs. Main-process memory swung between about 1.5 and 4.3 GB.
  • A restart for an update skipped the unsaved-changes prompt entirely, because it relied on that copy to bring the changes back.

After:

  • A notebook whose unsaved text is over 10,000 KB is not copied into the restart-recovery session. Other files, and smaller notebooks, are backed up exactly as before.
  • Before an update or app restart, Orca shows the usual "Unsaved Changes" prompt (Cancel / Don't Save / Save) for each such notebook:
    • Save and Don't Save let the restart continue, exactly as they do on quit.
    • Cancel stops the restart, and the notebook keeps its unsaved changes.
    • If no prompt can be shown, the restart is refused rather than losing the changes silently.
  • On the next launch such a notebook reopens from disk.

This is the common pattern for notebooks: outputs past a size limit (10,000 KB) are not backed up for restart, and the user is asked to save instead.

How it works:

  1. One rule, one place. canBackUpEditorDraft is applied in the single function that builds the editor part of the session, so every path that persists the session gets it: the debounced save, the shutdown checkpoint, and the mobile-triggered full save. The draft's length stands in for the size of its outputs, which avoids parsing hundreds of MB on every session save.
  2. The prompt. The restart's existing "prepare unsaved editors" step now asks about those notebooks through the existing close prompt, which gained a "cancelled" callback next to its "closed" one.
  3. No stale latch. While a restart is in progress, the "skip the unsaved-changes prompt" shortcut now re-checks at each close that every dirty file really has a backup. A notebook that outgrew the limit after the prompt is still asked about, instead of being trusted to a flag.

Why

The large-notebook case comes from #28087, which keeps every byte of a cell's output instead of dropping it. Large notebooks opened from disk and edited hit the same cost today. Keeping the restart copy for them would mean rewriting hundreds of MB after every edit. Asking once before a restart is cheaper, and matches the common pattern.

Alternatives considered:

  • Refuse the restart until the user saves. The restart path already does this for tab kinds it cannot back up. Rejected because it blocks the user; the prompt lets them choose "Don't Save" and carry on.
  • Back up only the notebook's source, without outputs. Rejected: restoring a notebook with its outputs silently stripped would be surprising.

Linked Issue

STA-8495 (duplicate STA-8641). Companion to #28087; independent of it (no shared files, mergeable on its own).

Visual Proof

The prompt shown by the pre-restart step, in a hidden production build with a notebook too large to back up:

Unsaved Changes prompt shown before a restart

Testing

Setup: same Mac, hidden production builds, a real Python kernel cell printing 200 MiB. After the run, a one-line second cell runs five times, so the notebook changes and the session is saved repeatedly. Three fresh launches each, interleaved A (#28087 only) → A+B (#28087 with this PR) → #27721.

median (range), n = 3 each A (#28087 only) A + this PR #27721
profile-state.db after five one-line runs 426 MB (426–426) 0.1 MB (0.1–0.1) 4.3 MB
Main-process memory after five one-line runs 3.45 GB (2.99–4.28) 367 MiB (367–367) 386 MiB (384–387)
Highest main-process memory seen 3.45 GB (2.99–4.28) 441 MiB (441–442) 450 MiB (447–452)
Whole app memory after those runs 4.9 GB (4.1–5.6) 1.8 GB (1.8–1.8) 1.2 GB (1.2–1.2)
Renderer heap after those runs (unchanged by this PR) 650 MiB 650 MiB 50 MiB

Prompt check, real app: after the run, I fired the same pre-restart step an update uses. The "Unsaved Changes" prompt appeared for nb.ipynb; pressing Cancel refused the restart with "Restart cancelled: a large notebook has unsaved changes." and left the notebook dirty.

Automated tests:

  • the limit itself, and that the session leaves the draft (and its disk baseline) out;
  • the pre-restart step: asks, then continues after Save; refuses after Cancel; refuses when nothing can ask; doesn't ask about small drafts;
  • the close prompt's Cancel calls every pending "cancelled" callback, and a second request for the same file keeps the first one's callbacks.

2,778 tests across the editor, session and close-queue suites pass.

  • I manually tested these changes locally
  • Automated tests added/updated

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • SSH and folder workspaces: drafts are handled the same before the session is split by host, so remote notebooks follow the same rule. Save on a disconnected SSH host fails and re-shows the prompt, leaving Cancel to stop the restart.
  • Mobile: unaffected.
  • Platforms: no platform-specific code. Measured on macOS only.
  • After Cancel: the restart failure message also appears where restart errors already show (the update card or a toast).

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…backing them up

Orca copied every dirty file's whole text into the restart-recovery session
on every change. A notebook holding hundreds of MB of output made that copy
hundreds of MB, rewritten after each edit, and grew main-process memory by
gigabytes. Notebooks whose unsaved text exceeds 10,000 KB are now left out of
that copy; before an update or app restart Orca asks to save them with the
usual Save / Don't Save / Cancel prompt, and Cancel stops the restart.

STA-8495, STA-8641
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Large unsaved notebooks can make restart-recovery storage and memory grow substantially. This PR limits the notebook text copied into recovery and asks for Save, Don’t Save or Cancel before a deliberate restart or update, while deliberate Save retains the complete notebook.

Review status: blocked; not ready to merge. Three review rounds and the architecture challenge found these unresolved problems:

  • A notebook can grow past the cap while the restart checkpoint is being written. The latest recovery draft is then omitted, but direct relaunch proceeds without the real window unload check. The shutdown decision must protect the final document state before irreversible cleanup or profile changes.
  • Don’t Save requires a successful host disk read. A disconnected remote host can therefore block the choice the user already affirmed.
  • The latest local fix allows a concurrent Save to complete while an older Discard read is pending, then replaces the clean editor with that older result. Disk retains the saved content, but the tab shows stale content as clean.

Local review commits preserve notebook tabs, protect newer edits during Save, apply cell changes synchronously, and present prompts without waking sleeping workspaces. They remain unpushed candidates; the entire second commit is not independently ready because of the Discard regression. The model-edit and prompt changes may be separated from the required shutdown/Discard redesign.

The requested proactive Unsaved Changes prompt and full-text limit are policy differences from the common pattern. Backup-size errors there veto shutdown with an error/force-shutdown choice; size accounting counts output bytes, whereas this PR uses full-draft string length. The original matching claim should not be relied on.

Verified: first-hand source inspection, controlled executions of the actual main/branch serialization and Save/Discard paths, and 107 targeted tests plus renderer typecheck and changed-code checks on the latest local fix. These checks do not override the reproduced defects. Final readiness, renewed performance measurements, CI and remote rendered Electron comparison remain outstanding. No merge was attempted.

@nwparker

Copy link
Copy Markdown
Contributor

Closing: with #27721 capping retained output, notebooks no longer reach the size that bloats the restart backup (4.3 MB vs 426 MB measured), so the extra pre-restart prompt isn't needed.

@nwparker nwparker closed this Oct 19, 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.

2 participants