Render a chart for saved reports in chat instead of a fallback card - #480
Conversation
Asking the chat to run a saved report showed "Report data returned but no renderable config" where the chart belonged. The data was fetched fine; the renderer just had nothing to draw with. `runReport` returned only summary meta plus `data`, with no `report` key. The chat renderer needs a `zReportInput`-shaped config to hand to `ReportChart`, and bails early when it is missing. `runReportFromConfig` already returns one, which is why ad-hoc charts render and saved ones did not. Attach the config `runReport` has already loaded. `transformReport` maps the DB row onto `IReport` (the `events` column arrives as `series`), so the only thing to drop is `layout`, the dashboard grid position. `id` stays on so the renderer can tell a saved report from an ad-hoc one and keep the Save button hidden. The MCP tool strips the config again: an MCP client reads numbers and should not pay tokens for a config it cannot draw. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthrough
ChangesReport configuration flow
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to Saved reports now provide chart configuration to chat while MCP report-data responses retain their existing shape. No merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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. Comment |
Ask the AI chat to run a saved report and you get the text "Report data returned but no renderable config" where the chart should be. The numbers are fetched correctly; the renderer just has nothing to draw with.
What changed
runReportnow returns the saved report's config under areportkey, alongside the meta and data it already returned. That is the same keyrunReportFromConfigreturns for ad-hoc charts, which is why charts fromgenerate_reporthave always rendered and saved ones have not.The config comes from the report row
runReportalready loads, so there is no extra query.transformReportin the db package already maps the row ontoIReport, including turning theeventsJson column intoseries, so the only field dropped islayout(the dashboard grid position, not part of a chart config).idis kept deliberately: the renderer uses!report.idto decide whether to offer a Save button, and a report that is already saved should not offer one.The MCP
get_report_datatool strips the config back off. An MCP client reads numbers out of the response and cannot draw a chart, so its output shape is unchanged and it does not pay tokens for a config it has no use for.No change was needed in
apps/api/src/agents/tools/base.ts— itsget_report_datareturnsrunReport's result directly, so the config flows through.Evidence
packages/mcp/src/tools/analytics/reports.ts:287-296(before this change) built the meta object with id, name, chartType, range, interval, startDate, endDate and dashboard_url. Noreportkey anywhere in the function.apps/api/src/agents/tools/base.ts:140-146returnsrunReport(...)unmodified, so the gap reaches the frontend.apps/start/src/components/chat/tool-results/chat-report-result.tsx:56-65readsvalue.reportand returns the "no renderable config" card when it is missing or has nochartType.packages/mcp/src/tools/analytics/reports.ts:342shows the shape that does work:report: { ...input.config, projectId }.packages/db/src/services/reports.service.ts:83-116is where the DB row becomes anIReport,report.events→seriesat line 98.apps/start/src/components/report-chart/context.tsx:26types the prop asIReportInput & { id?: string }, which the stored config satisfies.Requested in
UserJot: "Chat conversation lost on refresh, and wants chat-generated reports insertable into a dashboard". Found while investigating that report; it is a separate bug in the same component area and ships on its own.
Deliberately left out
chat-report-result.tsxis untouched. The!reportguard is correct defensive behaviour for genuinely malformed results, and the fix belongs in the data.chat-report-result.tsx:86(value.dashboard_url &&) is a separate bug with its own root cause. Not fixed here.range/startDate/endDaterather than the resolved dates the engine used, so the chart renders the same window the dashboard shows for that report. This matches howshare.report.$shareId.tsxfeeds a saved report toReportChart.reports.ts. They are identical before and after this change, so the file was left unformatted rather than reformatted in an unrelated diff.Verification
pnpm typecheckpasses clean inpackages/mcp,apps/apiandpackages/db. The mcp unit tests pass (8 of 9 files);src/integration/tools.test.tsfails with 41 errors, identically on this branch and on the base commit, because it needs local Postgres and ClickHouse and there is no Docker in this environment.Not verified by running: the end-to-end chat behaviour. A reviewer with a real project should ask the chat to run a saved report and confirm a chart renders, the "Open in dashboard" link still appears, no Save button appears, and reports using breakdowns or global filters render too.
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes