Skip to content

feat(perf): measure what the app feels like, and bound the tables that grow - #253

Merged
imshashank merged 2 commits into
mainfrom
perf/vitals
Aug 8, 2026
Merged

imshashank merged 2 commits into
mainfrom
perf/vitals

Conversation

@imshashank

@imshashank imshashank commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Every number in the speed work so far has been server side or structural: round trips removed, statements made cheaper, calls proven concurrent by tests. Nothing measured the thing the work was for. I have said in three PRs that I cannot show whether the app feels faster. This settles it, and bounds the two tables that grow without a product reason.

1. Measuring what the app feels like

INP, LCP, CLS and TTFB reported from the running app to POST /api/vitals, using the web-vitals attribution build.

INP is the metric for this app. It counts exactly three gesture families: click, tap, and key press. Hover and scroll are excluded. In a keyboard-first tracker, every keystroke that opens the palette, moves selection or applies a label is an INP candidate. Its interactionType, pointer or keyboard, is stored as its own column, because that split is the most useful dimension here and cannot be recovered afterwards.

durationThreshold: 16, not the library default of 40. Event Timing rounds durations to 8ms and buffers at 104ms by default. A fast app reports almost nothing at the defaults, and an absence of data reads like success. If the target is a sub-100ms feel, the floor has to sit below it.

Routes are reduced to a pattern in the browser, before anything is sent. /issue/ORB-3 is recorded as /issue/[identifier]. Raw paths would put issue identifiers and document ids in the table and explode the cardinality of every grouping, which is what makes a vitals table useless. A test asserts no raw identifier survives the reduction.

Reporting requires a session and is scoped to the workspace. CrUX only covers publicly discoverable pages, so it can see the marketing and login routes and nothing behind auth. This is the only field data that will ever exist for the surface that matters, and an unauthenticated ingest is an endpoint anyone can fill.

GET /api/vitals?days=7 returns p75 per route, metric and interaction type, plus samples and worst case, ordered worst first. Needs org:manage, scoped to the caller's workspace, and tests cover both.

2. Bounding the operational tables

webhook_delivery and web_vital are both logs with no end. webhook_delivery already reached 23,000 rows and the largest table in the database before #248 slowed its growth, and slowing growth is not the same as bounding it.

A prune with a window per table, 30 days for deliveries and 90 for vitals, on a Vercel cron at 04:00.

The route fails closed. With no CRON_SECRET it answers 503 and prunes nothing, rather than becoming an endpoint anyone can call to delete rows. The secret is compared with timingSafeEqual after a length check, so a prefix cannot be probed.

The prune refuses a table name that is not a plain identifier and any window shorter than a day. This is the one piece of code in the repo whose whole job is deleting rows, and it should not be possible to talk it into deleting the wrong ones. A test asserts the configured windows only ever name operational tables.

Schema

The table ships with its generated migration and a catchup, already applied to production, with constraint names matching what a fresh migrate produces so the two cannot drift. Verified the way CI does it: built a database from migrate alone, ran db:check-drift against it, clean.

Tests

  • routePattern and the ingest schema: 11 in packages/shared
  • Reporter mapping: 9, including that FID cannot creep back in and that an over-long attribution target is truncated rather than rejected by the column
  • Vitals route: 9, covering batch ingest, four refusals, workspace isolation, the admin gate
  • Prune: 5, including the injection and zero-window refusals
  • Cron route: 5, covering the missing secret, the wrong secret, and a prefix of the right one

Web suite 1646 pass. One db test flaked on a single run while I was reseeding lane databases underneath it; stable across two further runs, and CI is the arbiter.

One manual step

CRON_SECRET has to be added to Doppler for the schedule to do anything, since env flows Doppler → Vercel and that is your call, not mine. Until it is set the route answers 503 and says why, so nothing fails silently.

What this still does not do

It records; it does not draw. Reading GET /api/vitals is a request, not a page. A UI belongs in a follow-up once there is real data, and by then the data will say what the page should show.

Greptile Summary

The PR adds authenticated collection and workspace-scoped aggregation of browser Web Vitals, plus scheduled retention for operational data.

  • Reports INP, LCP, CLS, and TTFB from the authenticated application.
  • Stores normalized route, interaction, attribution, and workspace dimensions.
  • Adds an administrator-only aggregate read endpoint.
  • Schedules daily pruning, including a 90-day retention window for Web Vitals.

Confidence Score: 3/5

The PR is not yet safe to merge because an authenticated member can still generate unrestricted telemetry writes and database growth within the retention window.

The new 90-day pruning policy limits record lifetime, but the ingest endpoint still accepts repeated 20-record batches without rate or workspace-volume enforcement, leaving the previously reported shared-database exhaustion path outstanding.

Files Needing Attention: apps/web/src/app/api/vitals/route.ts, packages/db/src/prune.ts

Important Files Changed

Filename Overview
apps/web/src/app/api/vitals/route.ts Adds authenticated telemetry ingestion and workspace-scoped aggregate reads; ingestion remains unrestricted by request rate or workspace volume.
packages/db/src/prune.ts Adds operational retention, including a 90-day Web Vitals window, but retention does not constrain short-term ingestion volume.
apps/web/src/app/api/cron/prune/route.ts Adds a CRON_SECRET-protected endpoint that invokes operational-table pruning.
apps/web/src/lib/vitals/provider.tsx Registers Web Vitals observers and batches measurements for background reporting.
apps/web/src/lib/vitals/report.ts Maps supported browser metrics into normalized, route-reduced telemetry reports.
packages/db/src/schema/comms.ts Defines the Web Vitals persistence schema, foreign keys, and query indexes.

Sequence Diagram

sequenceDiagram
  participant B as Browser
  participant V as /api/vitals
  participant D as Database
  participant C as Vercel Cron
  participant P as /api/cron/prune

  B->>V: POST normalized Web Vitals
  V->>D: Insert workspace-scoped samples
  B->>V: GET aggregate window
  V->>D: Query p75, count, and worst
  D-->>V: Workspace aggregates
  V-->>B: Metric summaries
  C->>P: Daily request with CRON_SECRET
  P->>D: Delete expired operational rows
Loading

Reviews (2): Last reviewed commit: "feat(db): bound the two tables that grow..." | Re-trigger Greptile

Every number in the speed work so far has been server side or
structural. Nothing measured the thing the work was for, so there was no
way to tell whether any of it helped. This is the instrumentation.

Reports INP, LCP, CLS and TTFB from the running app to /api/vitals,
using the web-vitals attribution build.

Choices worth explaining:

INP is the metric that matters for a keyboard-first app. It counts
click, tap and key press and nothing else, so every keystroke that opens
the palette or moves selection is a candidate. Its interaction type,
pointer or keyboard, is kept as a column, because that split is the most
useful dimension here and it cannot be recovered later.

durationThreshold is 16ms rather than the library default of 40, since a
fast app reports nothing at all at the default and an absence of data
reads like success.

Routes are reduced to a pattern before they leave the browser, so
/issue/ORB-3 is recorded as /issue/[identifier]. Raw paths would put
identifiers in the table and explode the cardinality of any grouping.

Reporting requires a session and is scoped to the workspace. CrUX cannot
see anything behind auth, so this is the only field data that will ever
exist for the surface that matters, and it must not become an open
endpoint anyone can fill.

GET /api/vitals returns p75 per route, metric and interaction type, and
needs org:manage. The table ships with its migration as well as a
catchup, already applied to production, with constraint names matching
what a fresh migrate produces.
@imshashank
imshashank requested a review from pulkitxm as a code owner August 8, 2026 19:21
@vercel

vercel Bot commented Aug 8, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
orbit Ready Ready Preview Aug 8, 2026 7:30pm

Request Review

@coderabbitai

coderabbitai Bot commented Aug 8, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@imshashank, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 41 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

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 reviews.

How do review limits work?

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

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, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 56352c78-ed1f-4489-9e4b-452b6c8ed627

📥 Commits

Reviewing files that changed from the base of the PR and between 373ca37 and f856e06.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (21)
  • apps/web/package.json
  • apps/web/src/app/(app)/layout.tsx
  • apps/web/src/app/api/cron/prune/route.ts
  • apps/web/src/app/api/vitals/route.ts
  • apps/web/src/lib/vitals/provider.tsx
  • apps/web/src/lib/vitals/report.ts
  • apps/web/tests/app/api/cron/prune/route.test.ts
  • apps/web/tests/app/api/vitals/route.test.ts
  • apps/web/tests/lib/vitals/report.test.ts
  • apps/web/vercel.json
  • packages/db/catchup/web-vitals-catchup.sql
  • packages/db/drizzle/0001_lean_satana.sql
  • packages/db/drizzle/meta/0001_snapshot.json
  • packages/db/drizzle/meta/_journal.json
  • packages/db/src/index.ts
  • packages/db/src/prune.ts
  • packages/db/src/schema/comms.ts
  • packages/db/tests/prune.test.ts
  • packages/shared/src/validators/index.ts
  • packages/shared/src/validators/vitals.ts
  • packages/shared/tests/validators/vitals.test.ts

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 added tests Test coverage and test infrastructure area: web The Next.js app and its UI area: database Schema, migrations, queries, seed dependencies Dependency updates labels Aug 8, 2026
Comment thread apps/web/src/app/api/vitals/route.ts Resolved
webhook_delivery and web_vital are both operational logs. Neither has an
end, and webhook_delivery already reached 23,000 rows and the largest
table in the database before the last change slowed it down. Slowing
growth is not the same as bounding it.

A prune with a window per table, 30 days for deliveries and 90 for
vitals, and a Vercel cron at 04:00 to run it.

The route fails closed. With no CRON_SECRET set it answers 503 and
prunes nothing, rather than becoming an endpoint anyone can call to
delete rows. The secret is compared with timingSafeEqual after a length
check, so a prefix cannot be probed.

The prune refuses a table name that is not a plain identifier and a
window shorter than a day, because this is the one piece of code in the
repo whose whole job is deleting rows and it should not be able to be
talked into deleting the wrong ones. A test asserts the configured
windows only ever name operational tables.

CRON_SECRET still has to be added to Doppler for the schedule to do
anything. Until then the route answers 503 and says so.
@imshashank imshashank changed the title feat(perf): measure what the app actually feels like feat(perf): measure what the app feels like, and bound the tables that grow Aug 8, 2026
@imshashank
imshashank merged commit e00a206 into main Aug 8, 2026
13 checks passed
@imshashank
imshashank deleted the perf/vitals branch August 8, 2026 19:36

This branch was successfully deployed

1 active deployment
Preview — f856e06f Deployed Aug 8, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: database Schema, migrations, queries, seed area: web The Next.js app and its UI dependencies Dependency updates tests Test coverage and test infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant