Repository navigation
refactor(notebook): one document model per open notebook, owned outside the viewer - #28995
brennanb2025 wants to merge 8 commits into
Conversation
…de the viewer Kernel output, cell edits and Clear All now change one structured document per open notebook (keyed by the tab's file id), which writes the editor draft at save, the 400 ms source pause, structural edits and run finish. A run that finishes while its notebook tab is in the background now marks the notebook dirty and its output is saved, instead of waiting for the viewer to remount. - ipynb-document-store: document, version/savedVersion dirty rules, adoption of drafts and disk text it did not write, discard, Source view, 256 Mi output cap - editor-buffer-owners (was editor-pending-flush): hasChange / skipOnAutosave split, version for autosave, discard, change notifications - CellRun keeps execution state only; the viewer's commit effect, per-pane source drafts and CellRun.outputs are gone
|
A notebook could finish running in a background tab without keeping its result in the saved document because only the visible page copied output into the file. This PR gives each open notebook one document that receives edits and execution results while hidden. Saving during a run leaves later results unsaved for the next Save. Review status: blocked; this PR remains in draft. Three review rounds and the final design ruling produced corrections through At Remote rendered QA could not start: Grok required sign-in, both permitted standalone DeepSeek models were unavailable, and the final permitted model was rate-limited. Windows alternatives had less than the required 30% free memory. The hidden app and all recorded driver processes were stopped; no screenshots or performance results were obtained. No credentials were copied and no sign-in was attempted. Unfinished: actual notebook/Source/Changes flows and main-versus-branch screenshots; same-host performance measurements; large-output Save/content/heap proof near the 224 Mi recording limit; a visible output-loss notice and final diagnostics beyond the bounded output window; final stack-base sync and complete exact-head PR CI. The recording limit counts UTF-16 units rather than serialized JSON size, so the Save/memory claim remains unverified. Output admission and autosave fanout findings from the performance scan still require measurements. The previous head’s full PR workflow failed typecheck. The local test typing error is corrected; a newer test from the stack base also calls the serializer API removed here and still needs integration. CI on the new head is pending. The pre-existing reload-failure presentation is deferred; the output-loss notice remains open. For Brennan’s review: main-versus-branch screenshots are unavailable because rendered QA was blocked. The deliberate Reload behavior is in accepted read settlement; the unresolved large-output boundary is in output admission and its notice. Neither item is a merge-readiness claim. |
ELI5
A notebook could finish running in a background tab without showing unsaved changes. Closing that tab could silently lose the result because only a visible notebook page copied finished output into the file. Each open notebook now owns one document that receives cell edits and execution results even when its page is hidden.
What Changed
Running a cell and switching tabs keeps its output and marks the notebook unsaved. Saving during a run leaves later output unsaved for the next save. Both editor panes read the same notebook document.
Reload from disk keeps the existing edits until the read succeeds. The accepted read replaces cell source with the disk version and retains execution results received during the read, including a cell that finishes before the read returns. A newer Save, Keep My Edits, or edit supersedes that read. Reload also finishes when the notebook page is hidden.
Source view preserves the exact JSON being edited. Saving there writes that text; live execution results remain in the document and are reconciled when returning to the notebook view. A same-file owner transition on the same execution host transfers the document and queued or running cells together.
Execution changes the document directly. Finished cells share a fixed 400 ms publication window, avoiding a whole-notebook serialization after every cell in Run All. Save and other existing flush boundaries can request the text immediately. Typing retains its separate debounce.
Recorded output is limited to 224 Mi UTF-16 units per notebook. The recording limit and the bounded display are separate limits. A failed serialization reports that the notebook is too large to save.
Why
The structural problem was that the output owner outlived the page responsible for saving it. One versioned document removes that split. Accepted reads own their settlement, and materializing text is independent of execution completion. This follows the common pattern for notebook working copies while using the existing editor save and draft contracts.
Differences from the common pattern:
Linked Issue
Tracked in Linear STA-8495. Stacked on #28967.
Visual Proof
Pending remote Electron screenshots and before/after comparison on the final commit. This PR remains in draft.
Testing
On commit
475952c5f8, seven targeted test files passed on a separate macOS machine: 64 tests. Three controls each removed one relevant behavior and failed at the expected assertion: early paste must supersede Reload, a programmatic echo must preserve Reload, and an older pane read must not replace a newer accepted read. The unchanged seven-file suite passed all 64 tests again after removing the controls.Windows formatting and the normal commit hook passed. Full PR CI, rendered Electron flows and screenshots, and same-host performance and large-output Save/content/memory measurements remain pending. The prior static-analysis run found the corrected test typing error and an integration error in a newer stack-base test calling the removed serializer API. These unit tests exercise notebook ownership and editor hooks with mocked file and kernel APIs; they do not prove actual Monaco paste timing or a real kernel flow.
AI Disclosure
Review
Three review rounds and the design ruling are recorded. The final correction received a fresh independent source review; its one test-isolation finding is fixed in
475952c5f8. A final test-only typing correction incfe8e81b165preserves the source-restoration assertion. Its normal commit hook passed; the new-head targeted repeat was blocked before launch by remote machine load. Production is unchanged from the tested475952c5f8head. Rendered QA and performance proof remain blocked; the loop status comment records those gaps.Agent skill upstream boundary
Notes
Notebook execution remains local. Remote notebook loading and saving use existing runtime file APIs; this change adds no saved or wire fields. No mobile-facing surface changes.
Checklist