Skip to content

Autosave only during code-mode#9453

Merged
kirangadhave merged 2 commits into
mainfrom
kg/autosave-code-mode-only
May 4, 2026
Merged

Autosave only during code-mode#9453
kirangadhave merged 2 commits into
mainfrom
kg/autosave-code-mode-only

Conversation

@kirangadhave
Copy link
Copy Markdown
Member

Summary

  • Tighten Transaction.source to Literal["frontend", "kernel", "code-mode", "file-watch"] so the closed set is type-checked.
  • Rename code-mode's transaction emission from source="kernel" to source="code-mode", and gate _maybe_autosave on it.

Why

run_app_then_export_as_ipynb (and any other path using run_app_until_completion in EDIT mode) was rewriting source .py files as a side effect.

The fix flips the autosave default from "all kernel-sourced transactions persist" to "only code-mode transactions persist."

…eping

Tightens Transaction.source to a Literal and narrows the auto-save gate
in _maybe_autosave to source="code-mode". The instantiation ReorderCells
broadcast (source="kernel") no longer triggers a write-back, so opening
or running a notebook never rewrites it on disk.
@kirangadhave kirangadhave requested a review from mscolnick May 4, 2026 21:28
@kirangadhave kirangadhave added the internal A refactor or improvement that is not user facing label May 4, 2026
@vercel
Copy link
Copy Markdown

vercel Bot commented May 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment May 4, 2026 9:55pm

Request Review

@kirangadhave
Copy link
Copy Markdown
Member Author

@cubic-dev-ai

@cubic-dev-ai
Copy link
Copy Markdown
Contributor

cubic-dev-ai Bot commented May 4, 2026

@cubic-dev-ai

@kirangadhave I have started the AI code review. It will take a few minutes to complete.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Architecture diagram
sequenceDiagram
    participant CM as CodeModeContext
    participant K as Kernel
    participant L as NotificationListener
    participant S as Session
    participant FM as AppFileManager

    Note over CM, FM: Transaction Emission

    alt Code Editor Interaction
        CM->>CM: Generate document operations
        CM->>CM: NEW: Create Transaction(source="code-mode")
        CM->>S: notify(NotebookDocumentTransaction)
    else Kernel Bookkeeping
        K->>K: Internal state change (e.g. cell order)
        K->>K: CHANGED: Create Transaction(source="kernel")
        K->>S: notify(NotebookDocumentTransaction)
    end

    Note over S, L: Middleware / Extension Processing

    S->>L: _on_kernel_message(msg)
    L->>L: Deserialize Transaction
    L->>S: notify(applied_transaction)
    
    rect rgb(240, 240, 240)
        Note right of L: CHANGED: Persistence Gate (_maybe_autosave)
        L->>L: Check TransactionSource
        alt source == "code-mode"
            L->>FM: Save notebook to disk
            FM-->>L: Success/Failure
        else source == "kernel" OR "frontend" OR "file-watch"
            Note over L: Skip autosave to prevent<br/>unintended side effects
        end
    end

    opt Failure during Save
        L->>S: notify(AlertNotification)
    end
Loading

Partial review: This PR has more than 50 files, so cubic reviewed the highest-priority files first. During the trial, paid plans get a higher file limit.
You can try an ultrareview to bypass the file limit, comment @cubic-dev-ai ultrareview. Learn more.

mscolnick
mscolnick previously approved these changes May 4, 2026
@kirangadhave kirangadhave requested a review from mscolnick May 4, 2026 21:48
@github-actions github-actions Bot added the bash-focus Area to focus on during release bug bash label May 4, 2026
@kirangadhave kirangadhave removed the bash-focus Area to focus on during release bug bash label May 4, 2026
@kirangadhave
Copy link
Copy Markdown
Member Author

removing bash-focus label which was auto-added

@github-actions github-actions Bot added the bash-focus Area to focus on during release bug bash label May 4, 2026
@kirangadhave kirangadhave enabled auto-merge (squash) May 4, 2026 21:49
@kirangadhave kirangadhave merged commit e550919 into main May 4, 2026
51 of 52 checks passed
@kirangadhave kirangadhave deleted the kg/autosave-code-mode-only branch May 4, 2026 21:53
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.23.6-dev1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bash-focus Area to focus on during release bug bash internal A refactor or improvement that is not user facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants