Repository navigation
perf: defer per-cell AI completion work - #12243
Merged
Merged
Conversation
Opening the AI prompt in one cell caused every cell editor to commit, and idle cells each retained a chat client. Subscribe by cell and create the client only when a prompt is submitted. Keep requests independent of the visible prompt so switching cells preserves in-flight proposals. Keep the original editor mounted during comparisons to preserve its selection and restore focus.
Contributor
|
All contributors have signed the CLA ✍️ ✅ |
Contributor
|
React Doctor found no new issues. 🎉 Reviewed by React Doctor for commit |
Contributor
Coverage Report for ./frontend
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Delayed autofocus can still refocus the prompt and select an existing draft after the user tabs away, allowing the next keystroke to overwrite it.
2 open issues
What changed in this PR
Defers inline AI completion work in marimo’s notebook editor, reducing work in unrelated cells while preserving proposals across target switches.
Changes:
- Subscribes editors to cell-specific AI targets and creates chat clients on submission.
- Preserves editor instances and improves comparison, acceptance, and focus handling.
- Adds render-isolation, streaming, cancellation, and cursor tests.
| File | Description |
|---|---|
| frontend/src/core/ai/state.ts | Adds cell-specific target subscriptions. |
| frontend/src/components/editor/cell/code/cell-editor.tsx | Integrates targeted subscriptions and content replacement. |
| frontend/src/components/editor/ai/completion-utils.ts | Accepts precomputed notebook context. |
| frontend/src/components/editor/ai/ai-completion-editor.tsx | Defers chat creation and updates completion interactions. |
| frontend/src/components/editor/ai/__tests__/completion-utils.test.ts | Updates context-building tests. |
| frontend/src/components/editor/__tests__/cell-renders.test.tsx | Tests render isolation and completion lifecycle behavior. |
Review effort: Balanced
mscolnick
previously approved these changes
Dec 2, 2026
mscolnick
approved these changes
Dec 3, 2026
Contributor
|
🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.26.1-dev112 |
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
Opening the inline AI prompt used to re-render every cell editor and each cell mounted a chat client. This change subscribes each editor to its own target state and creates a chat client on submit. It addresses the cell-completion portion of MO-8795.
The staged comparison keeps its historical pane read-only. Reject returns focus to the prompt. Accept supports an empty replacement and preserves the selection when the proposed code is identical.
completion.mp4