Repository navigation
feat(perf): measure what the app feels like, and bound the tables that grow - #253
Conversation
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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
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 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (21)
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 |
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.
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 theweb-vitalsattribution 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-3is 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=7returns p75 per route, metric and interaction type, plus samples and worst case, ordered worst first. Needsorg:manage, scoped to the caller's workspace, and tests cover both.2. Bounding the operational tables
webhook_deliveryandweb_vitalare both logs with no end.webhook_deliveryalready 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_SECRETit answers503and prunes nothing, rather than becoming an endpoint anyone can call to delete rows. The secret is compared withtimingSafeEqualafter 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
migrateproduces so the two cannot drift. Verified the way CI does it: built a database frommigratealone, randb:check-driftagainst it, clean.Tests
routePatternand the ingest schema: 11 inpackages/sharedWeb 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_SECREThas 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 answers503and says why, so nothing fails silently.What this still does not do
It records; it does not draw. Reading
GET /api/vitalsis 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.
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
Sequence Diagram
Reviews (2): Last reviewed commit: "feat(db): bound the two tables that grow..." | Re-trigger Greptile