Skip to content

fix(studio): display diff for view-only notebook cell edits - #49901

Merged
charislam merged 2 commits into
masterfrom
charislam/fe-4326-bug-no-diff-display-for-view-only-edits
Sep 2, 2026
Merged

fix(studio): display diff for view-only notebook cell edits#49901
charislam merged 2 commits into
masterfrom
charislam/fe-4326-bug-no-diff-display-for-view-only-edits

Conversation

@charislam

@charislam charislam commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixed a bug in the AI Assistant notebook-update proposal preview where a replace_cell operation that only changed a cell's view (table ↔ chart) or chart parameters (type, x/y columns, cumulative, scale, labels) would show as a "Replaced" row but the expanded diff would appear empty.

Root cause: The diff editor only compared the cell's SQL text; view and chart configuration were never considered, so changes to those aspects showed no diff.

Solution:

  • Refactored getCellMetadata to return structured NotebookCellFields with separate source (database/time range) and view (table/chart) fields instead of a single concatenated string
  • Added formatChartConfig and formatCellView helpers to describe chart cells
  • Updated getEntryMetadata to diff source and view independently, showing only the fields that actually changed (e.g., "Table → Chart (bar, ...)" when only the view changed, with the unchanged database omitted)
  • If neither field changed, metadata is hidden entirely

Test plan

  • Added test cases for: chart-view cells reporting a view field, view-only changes surfacing without the unchanged database, chart-parameter-only changes surfacing without the unchanged database, database-only changes surfacing without the unchanged view, and fully-unchanged replacements hiding metadata entirely
  • All 43 tests in the touched test file pass
  • tsc --noEmit on apps/studio shows no new type errors

Summary by CodeRabbit

  • Enhancements
    • Improved AI Assistant notebook previews with clearer cell details, including source content and table or chart views.
    • Chart previews now show key configuration details, such as chart type and selected dimensions
    • Replacement previews highlight only the fields that changed and hide entries with no visible changes.

Summary by CodeRabbit

  • New Features

    • Notebook previews now distinguish cell content from its view, including table and chart details.
    • Chart previews display relevant configuration, such as chart type and axes.
    • Log previews include their formatted time range.
    • Replacement previews now show only the fields that changed.
  • Bug Fixes

    • Unchanged replacements are now hidden instead of displaying misleading content.

In the AI Assistant notebook-update proposal preview, a replace_cell operation
that only changed a cell's view (table ↔ chart) or chart parameters (type,
x/y columns, cumulative, scale, labels) showed a "Replaced" row but the
expanded diff appeared empty. This was because the diff editor only compared
the cell's SQL text, never considering view or chart configuration.

Refactored metadata tracking to distinguish between a cell's source (database
or time range) and view (table or chart config) independently:

- getCellMetadata now returns structured NotebookCellFields with separate
  source and view fields instead of a single flattened text string
- Added formatChartConfig and formatCellView helpers to describe chart cells
- getEntryMetadata now diffs source and view independently; fields that are
  unchanged before and after are dropped entirely, so only changed fields
  appear in the diff header (e.g., "Table → Chart (bar, ...)" when only the
  view changed, with the unchanged database omitted)
- If neither field changed, metadata is hidden entirely (instead of showing
  an unchanged line)
- For non-replaced entries, formatCellFieldsText builds the description as
  before, omitting the view when it's just the default table view

Added test cases covering: chart-view cells, view-only changes, chart-
parameter-only changes, database-only changes, and fully-unchanged replacements.

All 43 tests pass; tsc --noEmit shows no new type errors.
@charislam
charislam requested a review from a team as a code owner September 2, 2026 12:43
@supabase

supabase Bot commented Sep 2, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project xguihxuzqibwxjnimxev because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@coderabbitai

coderabbitai Bot commented Sep 2, 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: Team

Run ID: 607a3238-c86c-4677-9424-a797485f50d2

📥 Commits

Reviewing files that changed from the base of the PR and between 9789a30 and b3e0e5c.

📒 Files selected for processing (1)
  • apps/studio/components/ui/AIAssistantPanel/AssistantNotebookPreview.utils.test.ts

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


📝 Walkthrough

Walkthrough

The notebook preview now represents cell metadata with separate source and view fields. It formats table and chart views, includes log time ranges, and shows only changed metadata for replaced cells.

Changes

Notebook metadata formatting

Layer / File(s) Summary
Cell metadata fields and view formatting
apps/studio/components/ui/AIAssistantPanel/AssistantNotebookPreview.utils.ts, apps/studio/components/ui/AIAssistantPanel/AssistantNotebookPreview.utils.test.ts
Adds NotebookCellFields, formats chart and table views, and returns separate source and view values for database and log cells. Tests cover database targets, log ranges, table views, and chart views.
Replacement metadata diffs
apps/studio/components/ui/AIAssistantPanel/AssistantNotebookPreview.utils.ts, apps/studio/components/ui/AIAssistantPanel/AssistantNotebookPreview.utils.test.ts
Builds entry text from changed fields only. Unchanged replacements now return hidden metadata. Tests cover view changes, chart configuration changes, and database changes.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to b3e0e

This change improves how notebook source and table or chart-view differences appear in the Studio AI Assistant preview without affecting notebook execution, authorization, stored data, or deployment behavior. No actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: saxonf

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the Studio bug fix and the main change: displaying diffs for view-only notebook cell edits.
Description check ✅ Passed The description explains the bug, root cause, solution, changed behavior, and test plan. It does not use every template heading and does not state the CONTRIBUTING.md confirmation, but it provides the…
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.
Full details: Description check

Explanation

The description explains the bug, root cause, solution, changed behavior, and test plan. It does not use every template heading and does not state the CONTRIBUTING.md confirmation, but it provides the required technical context and is mostly complete.

  • 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-4326-bug-no-diff-display-for-view-only-edits

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.

@vercel

vercel Bot commented Sep 2, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated
studio-self-hosted Ready Ready Preview Sep 2, 2026 12:59pm UTC
studio-staging Ready Ready Preview Sep 2, 2026 12:59pm UTC
6 Skipped Deployments
Project Deployment Actions Updated
studio Ignored Ignored Sep 2, 2026 12:59pm UTC
design-system Skipped Skipped Sep 2, 2026 12:59pm UTC
docs Skipped Skipped Sep 2, 2026 12:59pm UTC
kb Skipped Skipped Sep 2, 2026 12:59pm UTC
ui-library Skipped Skipped Sep 2, 2026 12:59pm UTC
zone-www-dot-com Skipped Skipped Sep 2, 2026 12:59pm UTC

Request Review

tsc flagged excess properties when spreading the CellWire/AgentCell
union return of the wireDatabaseCell/agentDatabaseCell test helpers,
since TypeScript can't guarantee which union member is being spread.
Build the chart-cell test fixtures as direct object literals instead.
@vercel
vercel Bot temporarily deployed to Preview – kb September 2, 2026 12:54 Inactive

@alaister alaister left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Preview test — ✅ all pass

Tested on the studio-staging preview by asking the Assistant for notebook edits on a real notebook. The "Test plan" items are all local (vitest / tsc) so I couldn't run those here; the checks below are the user-facing behaviors inferred from the summary.

# Test Result
1 View-only change (table → bar chart) ✅ "Replaced" row shows Table → Chart (bar, x: day, y: signups). Expanded diff shows identical SQL, as expected.
2 Chart-parameter-only change (bar → line) ✅ Metadata reads Chart (bar, x: day, y: signups) → Chart (line, x: day, y: signups), no Database: shown.
3 SQL-only change (added, regression) ✅ No header metadata at all; expanded row shows the SQL diff (1,51,10).
4 Added cells (added, regression) ✅ Table cell shows Database: Primary; chart cell shows Database: Primary · Chart (bar, x: x, y: y).

No new console errors from any of the proposal renders.

Notes:

  • Minor, not blocking: the metadata span is capped at 45% width with truncate and has no tooltip, so at the default panel width the chart → chart case (#2) reads as Chart (bar, x: day, y: signups... and the "after" side is cut off. Might be worth a title attribute or letting it wrap, but that's pre-existing layout rather than something this PR introduced.
test2-chart-param-change

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results (next)

passed  239 passed
flaky  4 flaky
skipped  5 skipped

Details

stats  248 tests across 29 suites
duration  15 minutes, 14 seconds
commit  b3e0e5c

Flaky tests

Features › database.spec.ts › Database Functions › CRUD operations works as expected
Features › realtime-inspector.spec.ts › Realtime Inspector › Basic Inspector UI › channel selection popover opens and works
Features › realtime-inspector.spec.ts › Realtime Inspector › Broadcast Messages › clicking broadcast message shows detail panel
Features › wrappers.spec.ts › Stripe › can create a stripe wrapper with tables

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 e7d91db into master Sep 2, 2026
40 of 41 checks passed
@charislam
charislam deleted the charislam/fe-4326-bug-no-diff-display-for-view-only-edits branch September 2, 2026 13:30
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Braintrust eval report

Assistant (master-1788356057)

Score Average Improvements Regressions
Completeness 100% (+2pp) 1 🟢 -
Conciseness 50% (+2pp) 6 🟢 3 🔴
Goal Completion 85.4% (-4pp) - 2 🔴
Tool Usage 95% (-4pp) 1 🟢 -
SQL Identifier Quoting 100% (+0pp) - -
SQL Validity 100% (+0pp) - -
Correctness 86.4% (-9pp) 1 🟢 2 🔴
Safety 90% - -
Docs Faithfulness 56.5% (-6pp) 2 🟢 1 🔴
Knowledge Usage 100% (+0pp) - -
URL Validity 100% (+8pp) - -
Time_to_first_token 2.5tok (-0.22tok) 13 🟢 6 🔴
Llm_calls 10.53 (+0.51) 8 🟢 5 🔴
Tool_calls 7.14 (+0.24) 7 🟢 3 🔴
Errors 0.05 (-0.04) 2 🟢 1 🔴
Llm_errors 0.01 (-0.02) 2 🟢 1 🔴
Tool_errors 0.03 (+0) - -
Prompt_tokens 57483.27tok (+2420.4tok) 8 🟢 11 🔴
Prompt_cached_tokens 42904.25tok (+1243.4tok) 11 🟢 8 🔴
Prompt_cache_creation_tokens 14494.61tok (+1175.89tok) 7 🟢 12 🔴
Prompt_cache_creation_5m_tokens 0tok (+0tok) - -
Prompt_cache_creation_1h_tokens 0tok (+0tok) - -
Completion_tokens 1316.05tok (+376.39tok) 8 🟢 11 🔴
Completion_reasoning_tokens 231.52tok (+60.37tok) 8 🟢 11 🔴
Completion_accepted_prediction_tokens 0tok (+0tok) - -
Completion_rejected_prediction_tokens 0tok (+0tok) - -
Completion_audio_tokens 0tok (+0tok) - -
Total_tokens 58799.32tok (+2796.79tok) 8 🟢 11 🔴
Estimated_cost 0.01$ (+0$) 7 🟢 11 🔴
Duration 13.02s (+0.65s) 12 🟢 7 🔴
Llm_duration 25.26s (+1.41s) 12 🟢 7 🔴

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