Skip to content

chore(cost-insights): remove frontend pages, components, and tRPC routers - #4993

Merged
RSO merged 2 commits into
mainfrom
shutdown-cost-insights
Aug 4, 2026
Merged

chore(cost-insights): remove frontend pages, components, and tRPC routers#4993
RSO merged 2 commits into
mainfrom
shutdown-cost-insights

Conversation

@RSO

@RSO RSO commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

First of three PRs shutting down Cost Insights. This one removes every user-facing surface and the API it depended on. Follow-ups stop writing to the cost_insight_* tables, then drop the tables.

Removed

  • Routes — personal and organization route trees, including the admin gate and the cost-insights release-toggle layout.
  • Components — all of apps/web/src/components/cost-insights/ plus the Storybook stories and fixtures.
  • APIcostInsights and organizations.costInsights tRPC routers (19 procedures) and their registrations in root-router.ts / organization-router.ts.
  • Router-only server libpresenter.ts, tracking.ts, posthog-tracking.ts. presenter.ts was the blocker for deleting the component directory: it imported 11 types from @/components/cost-insights/types.
  • Navigation — Cost Insights entries in both sidebars, plus the duplicated formatReviewItemBadge helpers and the orphaned useQuery / useTRPC wiring left behind.
  • Dev seeddev/seed/cost-insights/, which existed only to populate the deleted dashboards and printed login URLs to the removed routes.

Spend Alert emails now stop

The alert email's only CTA deep-linked to the deleted dashboard, so leaving delivery on would have shipped a 404 CTA. dispatchPendingCostInsightNotifications now drains claimed rows to skipped with reason feature_discontinued instead of sending. The template (costInsightSpendAlert.html), subject entry, sendCostInsightSpendAlertEmail, and the costInsightOwnerBasePath URL builder are deleted.

Discontinued notice

Both former base paths serve a short notice via an optional catch-all ([[...segments]]), so old bookmarks and previously sent emails land on an explanation instead of a 404 — including deep links like /cost-insights/config and /cost-insights/activity. Personal keeps getUserFromAuthOrRedirect; organization keeps OrganizationByPageLayout authorization.

Doc correction

CONTEXT.md stated Spend Alerts were "sent only to Kilo platform admins... organization owners or billing managers who are also platform admins". The code disagreed for organizations: both listCostInsightNotificationRecipientUserIds and hasCurrentCostInsightAccess checked membership role owner/billing_manager only — no is_admin check and no status = 'active' filter. Corrected along with the now-false frontend claims about routes, sidebar placement, dashboards, and settings.

Retained for follow-ups

vercel.json cron entries, both cron routes, jobs, evaluation, notifications claim/terminalize machinery, repository, rollup-maintenance, rollup-repairs, spend-repository, canonical-sources, suggestion-eligibility, owner, policy, hourly-sweep-repository, and all spend-capture call sites. Each is transitively required by the cron jobs or the spend-write paths. repository.ts still exports settings/acknowledge/dismiss helpers that no longer have callers; they belong with PR2's write removal.

Verification

  • apps/web typecheck, apps/storybook typecheck, oxlint (0 warnings, 0 errors), oxfmt.
  • 21 jest suites / 156 tests covering lib/cost-insights, lib/email, both cron routes, and root-router; plus 8 suites / 336 tests over the spend paths (processUsage, exa-usage, coding-plans, kiloclaw-billing-router, usage-post-commit-work).
  • Updated the notification integration test to assert the discontinued skip path.
  • Browser-checked against a local stack with an admin fake user: /cost-insights, /cost-insights/config, and /organizations/<id>/cost-insights all return 200 with the notice, "View usage" navigates to /usage, and no Cost Insights entry appears in the sidebar for an admin.

RSO added 2 commits August 4, 2026 10:56
…ters

First step of the Cost Insights shutdown. This removes every user-facing
surface and the API it depended on. Follow-ups stop writing to the
cost_insight_* tables and then drop the tables.

Removed:
- personal and organization route trees, including the release-toggle and
  admin layout gates
- apps/web/src/components/cost-insights/ and its Storybook stories
- costInsights and organizations.costInsights tRPC routers (19 procedures)
  and their registrations
- router-only server lib: presenter, tracking, posthog-tracking
- Cost Insights sidebar entries plus the now-dead formatReviewItemBadge
  helpers and orphaned query wiring
- dev/seed/cost-insights, which only existed to populate the deleted UI

Spend Alert emails deep-linked to the deleted dashboard, so delivery now
stops: dispatchPendingCostInsightNotifications drains claimed rows to
'skipped' instead of sending, and the email template, subject, sender, and
URL builder are gone.

The removed routes serve a discontinued notice through an optional
catch-all so old bookmarks and previously sent alert emails do not 404.

CONTEXT.md claimed Spend Alerts reached only platform admins. That was
wrong for organization owners: recipient selection and revalidation
checked membership role only, with no is_admin or active-status filter.
Corrected alongside the removed frontend claims.

Retained for the follow-up PRs: cron routes, jobs, evaluation, rollup
maintenance, and the spend-capture paths.
@kilo-code-bot

kilo-code-bot Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

Clean removal of the Cost Insights frontend surface, tRPC routers, and alert email path; all deleted modules verified free of dangling references, the notification drain-to-skipped behavior is covered by an updated integration test, and the catch-all tombstone pages are correctly wired.

Files Reviewed (76 files)

Modified / added:

  • CONTEXT.md - doc corrections match the code (org recipients were role-gated only, no admin filter)
  • apps/storybook/stories/OrganizationSwitcher.stories.tsx
  • apps/storybook/stories/Sidebar.stories.tsx
  • apps/web/src/app/(app)/components/OrganizationAppSidebar.tsx - removed queries/imports verified unused
  • apps/web/src/app/(app)/components/PersonalAppSidebar.tsx - badge correctly retained on kiloClawItems only
  • apps/web/src/app/(app)/cost-insights/[[...segments]]/page.tsx - new tombstone; imports verified
  • apps/web/src/app/(app)/organizations/[id]/cost-insights/[[...segments]]/page.tsx - new tombstone; OrganizationByPageLayout usage verified
  • apps/web/src/components/cost-insights/CostInsightsDiscontinuedNotice.tsx - new notice component
  • apps/web/src/emails/AGENTS.md
  • apps/web/src/lib/cost-insights/notifications.integration.test.ts - asserts the feature_discontinued skip path
  • apps/web/src/lib/cost-insights/notifications.ts - drain logic correct; callers (jobs.ts, evaluation.ts) unaffected
  • apps/web/src/lib/cost-insights/owner.ts
  • apps/web/src/lib/cost-insights/repository.ts - remaining imports all still used
  • apps/web/src/lib/email.ts - TemplateName = keyof typeof subjects keeps template/type consistent
  • apps/web/src/routers/organizations/organization-router.ts
  • apps/web/src/routers/root-router.ts

Deleted (60 files): cost-insights route pages/layouts, components/cost-insights/ (except the notice), both tRPC routers and their tests, Storybook stories/fixtures, presenter.ts/tracking.ts/posthog-tracking.ts, costInsightSpendAlert.html, and dev/seed/cost-insights/ - all verified to have no remaining references (routers, procedures, feature flag string, seed registry, sidebar entries, sitemap/middleware).


Reviewed by kimi-k3 · Input: 148.8K · Output: 19.7K · Cached: 2.7M

Review guidance: REVIEW.md from base branch main

@RSO
RSO merged commit cfc2cbf into main Aug 4, 2026
22 checks passed
@RSO
RSO deleted the shutdown-cost-insights branch August 4, 2026 09:25
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