refactor: eliminate NotebookState from save, clone, and reconnect#567
Merged
refactor: eliminate NotebookState from save, clone, and reconnect#567
Conversation
After PR #554 (dead command removal) and #566 (metadata fallback migration), NotebookState is only used in 4 functions. This PR removes those usages by: 1. Add dirty flag to WindowNotebookContext - tracks unsaved changes in context instead of NotebookState 2. Migrate clone_notebook_to_path to daemon - daemon reads from Automerge, clears outputs, generates fresh env_id 3. Decouple initialize_notebook_sync from NotebookState - daemon is source of truth; pass explicit notebook_id and cells rather than NotebookState Step 4 (removing notebook_state field from WindowNotebookContext) is deferred because fallback usages (get_kernelspec, get_dependencies, etc.) read from NotebookState when daemon isn't connected. Removing these requires either removing fallbacks or finding alternative sources. The daemon now owns notebook content via Automerge; NotebookState remains only as a local window cache and for fallback cases.
1. Fix save_notebook_as data loss risk: Read cells and metadata from the old room BEFORE disconnecting. The new room won't have them since it's a different notebook_id, so we need to carry them across to populate the new room if it's empty. 2. Fix clone_notebook_to_disk dropping metadata: Read existing notebook to preserve cell metadata, attachments, and non-snapshot notebook metadata fields. Use split_inclusive for cleaner source line splitting.
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
Removes NotebookState usages from the save, clone, and reconnect paths. After PRs #554 (dead command removal) and #566 (metadata fallback migration), NotebookState was only used in 4 functions. This PR eliminates those usages:
Key Changes
save_notebookandsave_notebook_asnow usecontext.dirtyinstead ofNotebookState.dirtysave_notebook_asreads cells/metadata from old room before disconnecting, then passes them to populate the new room (prevents data loss on room switch)CloneNotebookprotocol added - daemon handles clone with fresh env_id, cleared outputs, preserved cell metadata/attachmentsinitialize_notebook_syncsignature changed to take explicit(notebook_id, cells, metadata)instead ofArc<Mutex<NotebookState>>notebook_id: Arc<Mutex<String>>to WindowNotebookContext for reconnect trackingRemaining Work
NotebookState field remains in WindowNotebookContext for fallback usages (get_kernelspec, get_dependencies, etc.) that read from local state when daemon isn't connected. Full removal requires either removing fallbacks or finding alternative sources - tracked for future PR.
Verification
PR submitted by @rgbkrk's agent, Quill