Skip to content

refactor(notebook): one document model per open notebook, owned outside the viewer - #28995

Draft
brennanb2025 wants to merge 8 commits into
brennanb2025/notebook-bounded-output-drawingfrom
brennanb2025/notebook-document-model
Draft

brennanb2025 wants to merge 8 commits into
brennanb2025/notebook-bounded-output-drawingfrom
brennanb2025/notebook-document-model

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 22 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​766 $\color{#cf222e}{\Huge{\mathbf{−}}}$​448 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​318
Prod 45 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1569 $\color{#cf222e}{\Huge{\mathbf{−}}}$​727 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​842

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:

  • Intended: a recording ceiling bounds retained output growth. It is separate from the size of saved JSON; Save and memory measurements remain pending.
  • Intended: Source view exposes raw JSON and preserves the user's exact text.
  • Intended: Reload combines disk source with execution results received during the read.

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.

  • Remote rendered before/after QA complete.
  • Automated regression tests added and targeted files passed.
  • Final unchanged-suite repeat passed on the current head.
  • Full PR workflow passed on the current head.

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 in cfe8e81b165 preserves 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 tested 475952c5f8 head. Rendered QA and performance proof remain blocked; the loop status comment records those gaps.

Agent skill upstream boundary

  • Not applicable; this change copies no upstream skill-installer implementation.

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

  • Explained the problem, before/after behavior and mechanism.
  • Considered execution hosts, folder workspaces and paired-client compatibility.
  • Final review loop, remote Electron proof and performance measurements complete.
  • Full PR workflow green on the current head.

…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
@brennanb2025
brennanb2025 marked this pull request as ready for review October 15, 2026 05:23
@brennanb2025
brennanb2025 marked this pull request as draft October 15, 2026 21:20
@brennanb2025

Copy link
Copy Markdown
Contributor Author

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 cfe8e81b16529063917271de99ab26831c42d735. A successful disk Reload now replaces source while retaining results received during the read, including cells that finish before the read returns. A newer edit, Save, Keep My Edits or permitted Reload Undo supersedes that read. Actual Source edits, including early large-paste chunks, take precedence; programmatic same-draft updates do not. Exact Source JSON stays authoritative until returning to the notebook view. Finished cells share a fixed publication window instead of serializing the whole notebook before every next cell.

At 475952c5f8, seven targeted files passed all 64 tests on another macOS machine. Three single-change negative controls failed at their intended behavioral assertions, and the unchanged suite then passed all 64 tests again. A fresh independent source review agreed with the correction; its test-isolation finding is fixed. That production build also passed. The later cfe8e81b165 commit changes only the restored-source test matcher, correcting a TypeScript error while preserving the expected source value; its normal commit hook passed. A targeted repeat on that new head was blocked before launch by machine load. Production is unchanged. These tests use mocked kernel and file APIs and do not prove actual rendered paste scheduling or real kernel behavior.

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.

This branch has not been deployed

No deployments
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