Skip to content

fix: dashboard chart panel updates - #736

Merged
ilyabo merged 4 commits into
mainfrom
codex/dashboard-chart-panel-updates
Jun 21, 2026
Merged

ilyabo merged 4 commits into
mainfrom
codex/dashboard-chart-panel-updates

Conversation

@ilyabo

@ilyabo ilyabo commented Jun 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fix dashboard chart tools so agent-driven dashboard edits can update an existing chart panel instead of always adding a duplicate panel.

What changed

  • Added optional panelId to shared chart tool input.
  • Threaded panelId through all built-in Mosaic chart tools.
  • Updated dashboard chart tool wiring to call updatePanel when panelId is supplied, while preserving add-panel behavior when omitted.
  • Added dashboard-agent prompt guidance to inspect panels and pass panelId for edit/update/fix requests.
  • Added focused coverage for updating an existing histogram panel by panelId.

Why

After dashboard requests were routed through dashboard_agent, update-style prompts such as "change the existing histogram to use depth" could list panel IDs but had no chart update path. The agent would create a duplicate panel instead of mutating the intended panel.

Validation

  • Commit hook: turbo lint --filter=@sqlrooms/* --
  • Pre-push hook: knip
  • Pre-push hook: turbo typecheck (51 tasks successful)
  • Pre-push hook: turbo test (24 tasks successful)
  • Focused local checks before commit included Mosaic/Deck tests and typechecks.

Summary by CodeRabbit

  • New Features

    • Added AI tool support for updating existing dashboard chart panels by providing an optional panelId (instead of always creating new panels).
    • Chart tools now validate that the target is an existing chart panel; invalid targets return failure without making changes.
    • When updating, omitting title preserves the existing panel title; chart tool wiring was updated across chart types.
  • Documentation

    • Updated the Dashboard AI Tools section to describe editing behavior and title preservation.

@coderabbitai

coderabbitai Bot commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@ilyabo, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 14 minutes and 32 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b2f3c758-bbaf-4ab5-9622-722b883170a7

📥 Commits

Reviewing files that changed from the base of the PR and between 2de7c84 and 2485762.

📒 Files selected for processing (2)
  • packages/mosaic/__tests__/dashboard-ai-tools.test.ts
  • packages/mosaic/src/ai/dashboard/createDashboardChartTools.ts
📝 Walkthrough

Walkthrough

Adds an optional panelId field to BaseChartToolInput (Zod schema) and AddChartFunctionArgs (TypeScript type), removing the title default to require explicit fallback logic. createDashboardChartTools.addChart now branches on panelId: if provided, it validates and updates the existing panel; otherwise it creates a new one. All six chart tools' execute handlers are updated to accept and forward panelId. Agent instructions are updated to require list_dashboard_panels calls before edits, worksheet chart tools use explicit title fallback for consistency, and comprehensive tests validate both success and error paths.

Changes

Dashboard chart panel update via panelId

Layer / File(s) Summary
panelId schema and type contract
packages/mosaic/src/ai/tool-schemas.ts, packages/mosaic/src/charts/chart-types/tool-types.ts
BaseChartToolInput Zod schema and AddChartFunctionArgs type each gain an optional panelId?: string field; title default is removed to enable explicit fallback logic in chart tools.
createDashboardChartTools update/create branching
packages/mosaic/src/ai/dashboard/createDashboardChartTools.ts
Imports MOSAIC_DASHBOARD_CHART_PANEL_TYPE and rewrites addChart to validate panel existence and type when panelId is supplied, calling updatePanel with preserved or updated title; falls back to addPanel with 'Chart' default when absent.
panelId forwarded through all chart tool execute handlers
packages/mosaic/src/charts/chart-types/histogram/tool.ts, packages/mosaic/src/charts/chart-types/box-plot/tool.ts, packages/mosaic/src/charts/chart-types/count-plot/tool.ts, packages/mosaic/src/charts/chart-types/heatmap/tool.ts, packages/mosaic/src/charts/chart-types/line-chart/tool.ts, packages/mosaic/src/charts/chart-types/scatter-plot/tool.ts
Each chart tool's execute handler destructures panelId from its input and passes it through to addChart.
Agent instructions and worksheet chart tool fallback
packages/mosaic/src/ai/dashboard/createDashboardAgentTool.ts, packages/mosaic/src/ai/worksheet/createWorksheetChartTools.ts
Embedded agent instructions now require calling list_dashboard_panels and passing panelId when editing an existing panel, with a new bullet clarifying create vs. update usage; worksheet chart tools use explicit title fallback (title ?? 'Chart') for caption consistency.
Test coverage for panel updates and feature documentation
packages/mosaic/__tests__/dashboard-ai-tools.test.ts, packages/mosaic/README.md
New Jest tests validate histogram panel update with existing panel (asserts updatePanel called, not addPanel) and error paths for missing or non-chart panels; README documents panelId-driven update behavior and title preservation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • sqlrooms/sqlrooms#634: Implements the same panelId-driven update-vs-create pattern for mosaic dashboard tools, overlapping in schema and chart tool execution contract changes.

Suggested reviewers

  • dmitriy-kostianetskiy

Poem

🐇 Hop, hop! No more panels lost in the heap,
With panelId in hand, updates run deep.
If the chart exists, we patch it in place,
No duplicate panels to clutter the space.
The histogram stays, the title shines bright —
This bunny's refactor is done just right! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: dashboard chart panel updates' directly summarizes the main change: enabling dashboard chart tools to update existing chart panels instead of creating duplicates.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/dashboard-chart-panel-updates

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 and usage tips.

@ilyabo ilyabo changed the title [codex] Fix dashboard chart panel updates fix: dashboard chart panel updates Jun 20, 2026
@ilyabo
ilyabo marked this pull request as ready for review June 20, 2026 07:13

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 40f7e0c3b6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +12 to +17
panelId: z
.string()
.optional()
.describe(
'Optional existing dashboard panel ID to update instead of creating a new panel.',
),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Document the new chart tool panelId API

This adds panelId to BaseChartToolInput, which is exported from @sqlrooms/mosaic, so it changes the package's public API. The repo instructions in /workspace/sqlrooms/AGENTS.md say public API changes in @sqlrooms/* packages must update the package README, but packages/mosaic/README.md's Dashboard AI Tools section still does not describe that chart tools can update an existing panel by passing panelId; downstream users wiring these tools directly would not discover the new update path.

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
packages/mosaic/src/charts/chart-types/tool-types.ts (1)

10-17: 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Add tsdoc to exported type.

AddChartFunctionArgs is used across multiple chart tools but lacks tsdoc. As per coding guidelines, exported types and functions in packages/**/*.{ts,tsx} should include tsdoc.

📝 Suggested tsdoc
+/**
+ * Arguments for adding or updating a chart panel.
+ * 
+ * `@property` tableName - Optional table name (required for worksheet charts, inherited for dashboard charts)
+ * `@property` panelId - Optional panel ID to update an existing panel instead of creating new
+ * `@property` title - Chart title
+ * `@property` config - Chart configuration object
+ */
 type AddChartFunctionArgs = {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/mosaic/src/charts/chart-types/tool-types.ts` around lines 10 - 17,
Add tsdoc comments to the exported types AddChartFunctionArgs and
AddChartFunction. For AddChartFunctionArgs, document what the type represents
and provide JSDoc-style descriptions for each property including tableName,
panelId, title, and config. For AddChartFunction, document its purpose as a
function type. Follow the project's tsdoc conventions using /** */ comment
blocks placed directly above each type definition.

Source: Coding guidelines

packages/mosaic/src/ai/tool-schemas.ts (1)

3-19: 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Add tsdoc to exported schema.

BaseChartToolInput is exported and imported by multiple chart tools, but lacks tsdoc. As per coding guidelines, exported types and functions in packages/**/*.{ts,tsx} should include tsdoc.

📝 Suggested tsdoc
+/**
+ * Base input schema for chart AI tools.
+ * 
+ * `@property` tableName - Required table name to create the chart from
+ * `@property` title - Optional title for the chart artifact (defaults to "Chart")
+ * `@property` panelId - Optional existing dashboard panel ID to update instead of creating a new panel
+ * `@property` reasoning - Brief rationale for the chart choice
+ */
 export const BaseChartToolInput = z.object({
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/mosaic/src/ai/tool-schemas.ts` around lines 3 - 19, The exported
BaseChartToolInput schema is missing tsdoc documentation, which is required by
coding guidelines for all exported types in packages. Add a tsdoc comment block
above the BaseChartToolInput constant that describes its purpose as a base input
schema for chart tools, and briefly documents the main fields including
tableName, title, panelId, and reasoning. Ensure the documentation follows
standard tsdoc conventions with appropriate JSDoc tags.

Source: Coding guidelines

🧹 Nitpick comments (1)
packages/mosaic/__tests__/dashboard-ai-tools.test.ts (1)

76-128: ⚡ Quick win

Consider adding edge case test coverage.

The test covers the happy path where the panel exists and is the correct type. Consider adding tests for edge cases:

  • panelId provided but panel doesn't exist (getPanel returns undefined)
  • panelId provided but panel has wrong type (not MOSAIC_DASHBOARD_CHART_PANEL_TYPE)

These edge cases would verify the validation logic in the update path.

📋 Suggested edge case tests
it('throws error when panelId references non-existent panel', async () => {
  const dashboardAdapter: DashboardAiAdapter = {
    getPanel: () => undefined, // Panel not found
    setSelectedTable: () => {},
    addPanel: jest.fn(),
    updatePanel: jest.fn(),
    removePanel: () => {},
  };

  const databaseAdapter: DatabaseAiAdapter = {
    getTables: () => [],
    findTable: () => ({
      tableName: 'earthquakes',
      columns: [{name: 'depth', type: 'DOUBLE'}],
    }) as any,
  };

  const tools = createDashboardAiTools({
    databaseAdapter,
    dashboardAdapter,
  });

  const result = await (tools.create_dashboard_panel_histogram as any).execute({
    tableName: 'earthquakes',
    panelId: 'non-existent',
    title: 'Depth histogram',
    settings: {field: 'depth'},
    reasoning: 'update non-existent panel',
  });

  expect(result.success).toBe(false);
  expect(result.errorMessage).toContain('Panel not found');
});

it('throws error when panelId references wrong panel type', async () => {
  const dashboardAdapter: DashboardAiAdapter = {
    getPanel: () => ({
      id: 'panel-1',
      type: 'data-table-explorer', // Wrong type
      title: 'Data Explorer',
      config: {},
    }),
    setSelectedTable: () => {},
    addPanel: jest.fn(),
    updatePanel: jest.fn(),
    removePanel: () => {},
  };

  const databaseAdapter: DatabaseAiAdapter = {
    getTables: () => [],
    findTable: () => ({
      tableName: 'earthquakes',
      columns: [{name: 'depth', type: 'DOUBLE'}],
    }) as any,
  };

  const tools = createDashboardAiTools({
    databaseAdapter,
    dashboardAdapter,
  });

  const result = await (tools.create_dashboard_panel_histogram as any).execute({
    tableName: 'earthquakes',
    panelId: 'panel-1',
    title: 'Depth histogram',
    settings: {field: 'depth'},
    reasoning: 'update wrong type panel',
  });

  expect(result.success).toBe(false);
  expect(result.errorMessage).toContain('not a chart panel');
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/mosaic/__tests__/dashboard-ai-tools.test.ts` around lines 76 - 128,
The test suite for the dashboard AI tools in dashboard-ai-tools.test.ts only
covers the happy path scenario where the panel exists and is the correct type.
Add two new test cases to cover edge cases: one where getPanel returns undefined
when a non-existent panelId is provided to create_dashboard_panel_histogram, and
verify it returns an error with a message indicating the panel was not found;
another where getPanel returns a panel with the wrong type (not
MOSAIC_DASHBOARD_CHART_PANEL_TYPE) and verify it returns an error indicating the
panel is not a chart panel. Both tests should verify that the result has success
set to false and contains appropriate error messages in the errorMessage
property.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@packages/mosaic/src/ai/tool-schemas.ts`:
- Around line 3-19: The exported BaseChartToolInput schema is missing tsdoc
documentation, which is required by coding guidelines for all exported types in
packages. Add a tsdoc comment block above the BaseChartToolInput constant that
describes its purpose as a base input schema for chart tools, and briefly
documents the main fields including tableName, title, panelId, and reasoning.
Ensure the documentation follows standard tsdoc conventions with appropriate
JSDoc tags.

In `@packages/mosaic/src/charts/chart-types/tool-types.ts`:
- Around line 10-17: Add tsdoc comments to the exported types
AddChartFunctionArgs and AddChartFunction. For AddChartFunctionArgs, document
what the type represents and provide JSDoc-style descriptions for each property
including tableName, panelId, title, and config. For AddChartFunction, document
its purpose as a function type. Follow the project's tsdoc conventions using /**
*/ comment blocks placed directly above each type definition.

---

Nitpick comments:
In `@packages/mosaic/__tests__/dashboard-ai-tools.test.ts`:
- Around line 76-128: The test suite for the dashboard AI tools in
dashboard-ai-tools.test.ts only covers the happy path scenario where the panel
exists and is the correct type. Add two new test cases to cover edge cases: one
where getPanel returns undefined when a non-existent panelId is provided to
create_dashboard_panel_histogram, and verify it returns an error with a message
indicating the panel was not found; another where getPanel returns a panel with
the wrong type (not MOSAIC_DASHBOARD_CHART_PANEL_TYPE) and verify it returns an
error indicating the panel is not a chart panel. Both tests should verify that
the result has success set to false and contains appropriate error messages in
the errorMessage property.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a94de26b-8a01-4c5a-873b-6ef6d501376c

📥 Commits

Reviewing files that changed from the base of the PR and between 0f40da8 and 40f7e0c.

📒 Files selected for processing (11)
  • packages/mosaic/__tests__/dashboard-ai-tools.test.ts
  • packages/mosaic/src/ai/dashboard/createDashboardAgentTool.ts
  • packages/mosaic/src/ai/dashboard/createDashboardChartTools.ts
  • packages/mosaic/src/ai/tool-schemas.ts
  • packages/mosaic/src/charts/chart-types/box-plot/tool.ts
  • packages/mosaic/src/charts/chart-types/count-plot/tool.ts
  • packages/mosaic/src/charts/chart-types/heatmap/tool.ts
  • packages/mosaic/src/charts/chart-types/histogram/tool.ts
  • packages/mosaic/src/charts/chart-types/line-chart/tool.ts
  • packages/mosaic/src/charts/chart-types/scatter-plot/tool.ts
  • packages/mosaic/src/charts/chart-types/tool-types.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3f8da827c3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

);
}

dashboardAdapter.updatePanel(panelId, {title, config});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve existing titles when updating charts

When a chart tool is called with panelId for an update but the user did not ask to rename the panel, title is still optional/defaulted by the shared schema, so this always patches the existing panel title to the default "Chart" (or undefined for direct execute callers). In update/edit/fix flows like “change the existing histogram to use depth”, this clobbers the user's current panel title even though only the chart config should change; use the existing panel.title unless a title was explicitly provided.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2de7c8444b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +58 to +61
dashboardAdapter.updatePanel(panelId, {
title: title ?? panel.title,
config,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Select the tool table before updating chart panels

In direct createDashboardAiTools usage, the new panelId update path validates settings against the tool's tableName, but this patch only changes the panel title/config. I checked MosaicDashboardChartRenderer, and chart panels render from dashboard.selectedTable, so updating a panel for a different table leaves it rendering against the previous selected table (often as missing-column errors) even though the tool returns success; set the dashboard selected table from the tool input before applying the update.

Useful? React with 👍 / 👎.

@ilyabo
ilyabo merged commit 31cdd95 into main Jun 21, 2026
3 checks passed
@ilyabo
ilyabo deleted the codex/dashboard-chart-panel-updates branch June 21, 2026 10:06
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.

1 participant