Skip to content

fix(notebooks): reset insert offset when anchor cell moves - #49694

Merged
charislam merged 1 commit into
masterfrom
charislam/fe-4308-insert-anchored-to-a-previously-moved-cell-lands-after-the
Aug 28, 2026
Merged

charislam merged 1 commit into
masterfrom
charislam/fe-4308-insert-anchored-to-a-previously-moved-cell-lands-after-the

Conversation

@charislam

@charislam charislam commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

I have read the CONTRIBUTING.md file.

YES

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

When a cell gets moved via move_cell operation in deriveNotebookDiff, the insertedAfter offset map is not cleared for that anchor cell. This causes later insert_cell operations anchored on the same (now-moved) cell to apply the stale offset on top of the correct current-position lookup, resulting in the new cell landing after the wrong position.

What is the new behavior?

The offset for an anchor cell is now cleared from insertedAfter when it gets moved, since cells previously inserted after it stay behind at its old location and should not affect subsequent inserts at its new position.

A regression test has been added that reproduces the exact ticket scenario (insert after cell-1, move cell-1 after cell-3, insert after cell-1 again) and verifies the correct final cell order.

Additional context

Fixes: https://linear.app/supabase/issue/FE-4308/insert-anchored-to-a-previously-moved-cell-lands-after-the-wrong-cell

Summary by CodeRabbit

  • Bug Fixes
    • Fixed notebook cell insertions after moving an anchor cell, ensuring new inserts appear relative to the anchor’s updated position.
    • Preserved the placement of inserts made before the anchor cell was moved.

When a cell gets moved via move_cell operation in deriveNotebookDiff, the
insertedAfter offset map was never cleared for that anchor cell. This caused
later insert_cell operations anchored on the same (now-moved) cell to apply
the stale offset on top of the correct current-position lookup, resulting in
the new cell landing after the wrong position.

The fix: clear the offset for an anchor cell from insertedAfter when it gets
moved, since cells previously inserted after it stayed behind at its old
location and should not affect subsequent inserts at its new position.

Regression test added: reproduces the exact ticket scenario (insert after
cell-1, move cell-1, insert after cell-1 again) and verifies correct final
cell order.

Fixes: FE-4308
@charislam
charislam requested a review from a team as a code owner August 28, 2026 15:15
@vercel

vercel Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
studio-self-hosted Ready Ready Preview Aug 28, 2026 3:20pm
studio-staging Ready Ready Preview Aug 28, 2026 3:20pm
5 Skipped Deployments
Project Deployment Actions Updated (UTC)
studio Ignored Ignored Aug 28, 2026 3:20pm
design-system Skipped Skipped Aug 28, 2026 3:20pm
docs Skipped Skipped v0 Aug 28, 2026 3:20pm
ui-library Skipped Skipped Aug 28, 2026 3:20pm
zone-www-dot-com Skipped Skipped v0 Aug 28, 2026 3:20pm

Request Review

@coderabbitai

coderabbitai Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: a8b83b69-e7d0-4870-8075-ef73924eff7c

📥 Commits

Reviewing files that changed from the base of the PR and between f1e0808 and 1905923.

📒 Files selected for processing (2)
  • apps/studio/data/content/notebooks/notebook-operations.test.ts
  • apps/studio/data/content/notebooks/notebook-operations.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

Moving a cell now clears its previous insertedAfter tracking. A regression test verifies that inserts before the move keep their original position and later inserts use the anchor’s new position.

Changes

Notebook insertion tracking

Layer / File(s) Summary
Reset tracking when moving an anchor
apps/studio/data/content/notebooks/notebook-operations.ts, apps/studio/data/content/notebooks/notebook-operations.test.ts
The move operation clears the moved cell’s insertion offset before reinsertion. The regression test covers inserts before and after the move.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 19059

This localized fix clears stale insertion offsets when an anchor cell moves and adds regression coverage for the affected ordering behavior. No actionable merge-blocking risk remains beyond normal checks and review.

Suggested reviewers: alaister

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description includes all required template sections. It clearly identifies the bug fix, current behavior, new behavior, regression test, and related issue.
Title check ✅ Passed The title clearly and concisely describes the main change: resetting notebook insert offsets when an anchor cell moves.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch charislam/fe-4308-insert-anchored-to-a-previously-moved-cell-lands-after-the

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results (next)

passed  241 passed
flaky  2 flaky
skipped  5 skipped

Details

stats  248 tests across 29 suites
duration  6 minutes, 3 seconds
commit  1905923

Flaky tests

Features › queue-table-operations.spec.ts › Queue Table Operations › pending changes persist when switching between tables
Features › table-editor.spec.ts › table editor › should show rls accordingly

Skipped tests

Features › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled
Features › sql-editor.spec.ts › SQL Editor › snippet favourite works as expected
Features › sql-editor.spec.ts › SQL Editor › share with team works as expected
Features › sql-editor.spec.ts › SQL Editor › folders works as expected
Features › sql-editor.spec.ts › SQL Editor › other SQL snippets actions work as expected

@charislam
charislam merged commit 86c813e into master Aug 28, 2026
39 checks passed
@charislam
charislam deleted the charislam/fe-4308-insert-anchored-to-a-previously-moved-cell-lands-after-the branch August 28, 2026 16:12
@github-actions

github-actions Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Braintrust eval report

Assistant (master-1787933730)

Score Average Improvements Regressions
Completeness 98.9% (-1pp) - 1 🔴
Conciseness 47.9% (-6pp) 7 🟢 22 🔴
Goal Completion 83.9% (-2pp) 4 🟢 9 🔴
SQL Identifier Quoting 100% (+0pp) - -
SQL Validity 97.5% (-1pp) 1 🟢 2 🔴
Tool Usage 89.8% (+2pp) 4 🟢 1 🔴
Correctness 81.4% (+2pp) 9 🟢 10 🔴
Docs Faithfulness 67.4% (+6pp) 5 🟢 3 🔴
Safety 80% (+0pp) 2 🟢 2 🔴
Knowledge Usage 92.9% (-7.000000000000001pp) - 2 🔴
URL Validity 100% - -
Time_to_first_token 3.34tok (+0.14tok) 20 🟢 43 🔴
Llm_calls 7.12 (-0.01) 16 🟢 20 🔴
Tool_calls 3.04 (-0.03) 18 🟢 25 🔴
Errors 0.02 (-0.01) 1 🟢 -
Llm_errors 0 (-0.01) 1 🟢 -
Tool_errors 0.02 (+0) - -
Prompt_tokens 25090.05tok (-1524.5tok) 35 🟢 24 🔴
Prompt_cached_tokens 18242.37tok (-135.45tok) 22 🟢 25 🔴
Prompt_cache_creation_tokens 0tok (+0tok) - -
Prompt_cache_creation_5m_tokens 0tok (+0tok) - -
Prompt_cache_creation_1h_tokens 0tok (+0tok) - -
Completion_tokens 560.37tok (+15.94tok) 33 🟢 30 🔴
Completion_reasoning_tokens 140.1tok (+7.78tok) 31 🟢 27 🔴
Completion_accepted_prediction_tokens 0tok (+0tok) - -
Completion_rejected_prediction_tokens 0tok (+0tok) - -
Completion_audio_tokens 0tok (+0tok) - -
Total_tokens 25650.42tok (-1508.57tok) 36 🟢 27 🔴
Estimated_cost 0$ (0$) 24 🟢 26 🔴
Duration 14.16s (+0.48s) 27 🟢 36 🔴
Llm_duration 13.76s (+0.4s) 29 🟢 34 🔴

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.

2 participants