Can we attempt to resolve the open issue please, and also then look at making data fetching changes as described below:
Yes. This is absolutely doable without moving to Convex.
The core fix is architectural, not platform-related: in Next 16, use cache can be applied at the data level or the UI level, and the docs explicitly recommend data-level caching when the same data is reused across multiple components or should be cached independently from the UI. For sections that should stay request-time fresh, Next recommends leaving them uncached and streaming them behind <Suspense>. (Next.js)
Right now, /models is caching the assembled page output itself: ModelsPageContent() has use cache, cacheLife("hours"), and cacheTag("page:models"), while also composing getMonitorModels, getModelRankingsRows, getWeeklyModelProviderTokens, and getAllModelsCached. Under that, getAllModelsCached() is already cached with days, getMonitorModels() is cached with days, and the rankings functions share their own custom cache object. That means you have a cache on the whole page and caches underneath it, which is why invalidation feels blunt and confusing. (GitHub)
On the model detail route, the route itself loads getModelOverviewCached(modelId, includeHidden), then renders ModelOverviewSections. getModelOverviewCached() currently uses a custom inline cache object rather than a preset profile, and ModelOverviewSections awaits getModelPricingCached() before rendering anything so it can decide whether to show API-related sections. getModelPricingCached() itself is cached with days. (GitHub)
For preset cache lives only, the built-in profiles are: default (5 min stale / 15 min revalidate / never expire), seconds (30 sec / 1 sec / 1 min), minutes (5 min / 1 min / 1 hour), hours (5 min / 1 hour / 1 day), days (5 min / 1 day / 1 week), weeks (5 min / 1 week / 30 days), and max (5 min / 30 days / 1 year). revalidateTag(tag, "max") is the recommended stale-while-revalidate invalidation path, while updateTag(tag) is immediate and only works inside Server Actions. (Next.js)
AI Stats caching implementation doc (preset-only)
1. Objective
Use Next 16 Cache Components properly, keep caching understandable, and avoid a migration. The rule set is:
Cache fetchers, not page assemblers.
Use preset cacheLife profiles only.
Treat TTL as fallback protection; treat tag invalidation as the main freshness mechanism.
Use <Suspense> where a section can stream separately instead of blocking the whole page. (Next.js)
2. Design decision
For AI Stats, there should be two kinds of cache:
Data caches: model core data, pricing/provider overlays, rankings, usage rollups.
No page-level cache for assembled public pages: the page should mostly just compose already-cached data.
That means /models should stop caching ModelsPageContent() as one shared blob. The fetchers under it are already the right abstraction boundary; the page cache is the redundant layer causing the pain. (GitHub)
3. Preset profile policy
Use these presets and do not add custom profiles yet:
max for near-immutable reference data.
weeks for model overview/core metadata.
days for the big base catalogue list.
hours for provider/pricing overlays, rankings, and heavier analytics.
default for small activity summaries where 15-minute freshness is acceptable and close enough to your “~30 minutes” goal for now. (Next.js)
The reason to prefer hours plus tag invalidation for the heavier rollups is simple: with presets only, there is no native 30-minute profile. So for big public analytics payloads, let the scheduled job or importer drive freshness via revalidateTag(..., "max"), and let hours act as the safety net if invalidation is missed. (Next.js)
This page currently caches the assembled output with page:models, while also depending on four cached/global data sources. Remove that layer first. (GitHub)
This is your stable base list of ~950 models. Daily fallback is fine; freshness should come from invalidation when core model metadata changes. It is already cached with days, so this is a small refinement, not a rewrite. (GitHub)
C. src/lib/fetchers/models/table-view/getMonitorModels.ts
Change:
ts
cacheLife("days");
to:
ts
cacheLife("hours");
cacheTag("models:monitor");
Keep the existing table-level tags too.
This fetcher includes provider model, pricing rule, model, and API provider state. That is not “days” data in practice. It is the exact overlay that makes /models feel stale when provider support changes. (GitHub)
D. src/lib/fetchers/rankings/getRankingsData.ts
Delete the custom RANKINGS_CACHE object and switch the public rankings/weekly token functions to the preset hours.
So, for example:
ts
export async function getModelRankingsRows(...) {
cacheLife("hours");
cacheTag("public-rankings");
...
}
export async function getWeeklyModelProviderTokens() {
cacheLife("hours");
cacheTag("public-rankings");
...
}
Your current rankings cache is stale: 1h, revalidate: 6h, expire: 7d, which is much looser than the public dashboard feel you described. Preset-only means you cannot land exactly on 30 minutes, so hours plus invalidation from the rollup job is the cleanest compromise. (GitHub)
E. src/lib/fetchers/models/getModel.ts
Leave getModelCached() on days.
Change getModelOverviewCached() from the inline custom object to the preset weeks:
Pricing/provider routing state is not stable enough for days if you care about supported providers and quickstart accuracy. The current function is tagged correctly enough; the lifetime is the weak part. (GitHub)
G. src/lib/fetchers/models/getModelPerformance.ts
Use presets only:
getModelPerformanceMetricsCached() → hours
getModelPerformanceActivitySnapshotCached() → use the default profile by omitting a custom object, or also standardise it on hours if you want one rule everywhere.
My recommendation:
ts
export async function getModelPerformanceMetricsCached(...) {
"use cache";
cacheLife("hours");
cacheTag("data:gateway_usage_rollups");
cacheTag(`data:gateway_usage_rollups:model:${modelId}`);
cacheTag(`model:performance:${modelId}`);
...
}
export async function getModelPerformanceActivitySnapshotCached(...) {
"use cache";
// rely on Next's default profile here
cacheTag("data:gateway_usage_rollups");
cacheTag(`data:gateway_usage_rollups:model:${modelId}`);
cacheTag(`model:performance:${modelId}`);
...
}
That gives you heavier charts on an hourly safety net, and smaller summary cards on a 15-minute default if you want slightly fresher top-line stats. Your current implementation uses inline custom lifetimes for both functions. (GitHub)
H. src/components/(data)/model/overview/ModelOverviewSections.tsx
Do not add use cache to this component.
Either keep it as a composition shell, or make it less blocking. Right now it awaits getModelPricingCached() before rendering any section, purely to compute hasApiProviders. That is acceptable as a first phase because the pricing fetch itself will be cached, but it is still the current blocking edge. (GitHub)
For the next pass, split streamable sections with <Suspense>. Next’s guidance is explicit: components that need fresh or asynchronous work can be left uncached and streamed with a fallback, instead of blocking the whole tree. (Next.js)
And in the route file, wrap ModelCreatorModelsSection in its own <Suspense> as well, because it is a separate async fetch and not required for first paint. The current route renders it directly under the overview component. (GitHub)
5. Tag taxonomy
Keep your existing tags for compatibility, but add a small domain vocabulary and start using it consistently:
models:list-base
models:monitor
public-rankings
model:data:${id}
model:api:${id}
model:performance:${id}
The reason is simple: revalidateTag is global across all pages using that tag, while revalidatePath is path-specific. For AI Stats, data ownership matters more than route ownership. (Next.js)
6. Invalidation rules
Use updateTag() only from Server Actions where the user just changed something and should see it immediately. Use revalidateTag(tag, "max") from jobs, importers, cron endpoints, or Route Handlers where stale-while-revalidate is the right behaviour. (Next.js)
Examples: 15-minute or 30-minute rollup recompute.
ts
import { revalidateTag } from "next/cache";
export async function afterRollupBatch(changedModelIds: string[]) {
for (const modelId of changedModelIds) {
revalidateTag(`model:performance:${modelId}`, "max");
revalidateTag(`data:gateway_usage_rollups:model:${modelId}`, "max");
}
revalidateTag("public-rankings", "max");
revalidateTag("data:gateway_usage_rollups", "max");
}
That gets you close to the “refresh every ~30 minutes” behaviour without inventing a custom profile yet. (Next.js)
7. What this solves
This solves the redundant page-level cache, makes the cache story understandable, and lets you reason about freshness per data domain instead of per page. It also keeps you on Next/Supabase and avoids a migration that would not actually fix the dependency shape. (GitHub)
8. What this does not solve
It does not fully eliminate shared invalidation on /models, because the page still merges full-list overlays: allModels, monitorResult.models, rankingsResult, and weeklyUsageResult.data. If one model’s provider support changes, those overlay fetchers are still shared arrays for the whole page, so some global list recomputation is still normal. That is a data-shape issue, not a Next.js issue. (GitHub)
If /models is still too expensive after phase 1, the real phase 2 is not Convex. It is a denormalised or materialised public catalogue snapshot keyed by model_id, so one model update only rewrites one row and the list page reads one precomputed source.
9. Rollout order
Do it in this order:
Remove page-level caching from /models.
Replace all inline cache objects with preset profiles only.
Standardise tag names and wire invalidation into admin writes/import jobs.
Add <Suspense> around streamable detail-page sections.
Only if needed later, introduce a denormalised catalogue snapshot.
That is the smallest path that gives you a sane long-term cache model without ripping the stack apart.
Next sensible step: map your actual write/import paths to this tag matrix so the invalidation is not hand-wavy.
User
AGENTS.md instructions for E:\ai-stats-public
Project Structure & Module Organization
Monorepo managed by pnpm + turbo: apps/web (Next.js 15 App Router, Tailwind UI in src/components and components/ui), apps/api (Cloudflare Workers + Hono), apps/docs (Mintlify site).
SDKs: packages/sdk-ts TypeScript client (src, generated src/gen, builds to dist); packages/sdk-py Python client (src, tests in packages/sdk-py/tests).
Shared tooling lives in scripts/, release metadata in .changeset/; canonical data/benchmarks sit under packages/data/catalog/src/data with Jest cases nearby.
Build, Test, and Development Commands
Install: pnpm install (Node >=20).
Dev servers: pnpm dev to run everything, or scope with pnpm --filter @ai-stats/web dev, pnpm --filter @ai-stats/gateway-api dev, pnpm --filter @ai-stats/docs dev.
Can we attempt to resolve the open issue please, and also then look at making data fetching changes as described below:
Yes. This is absolutely doable without moving to Convex.
The core fix is architectural, not platform-related: in Next 16, use cache can be applied at the data level or the UI level, and the docs explicitly recommend data-level caching when the same data is reused across multiple components or should be cached independently from the UI. For sections that should stay request-time fresh, Next recommends leaving them uncached and streaming them behind <Suspense>. (Next.js)
Right now, /models is caching the assembled page output itself: ModelsPageContent() has use cache, cacheLife("hours"), and cacheTag("page:models"), while also composing getMonitorModels, getModelRankingsRows, getWeeklyModelProviderTokens, and getAllModelsCached. Under that, getAllModelsCached() is already cached with days, getMonitorModels() is cached with days, and the rankings functions share their own custom cache object. That means you have a cache on the whole page and caches underneath it, which is why invalidation feels blunt and confusing. (GitHub)
On the model detail route, the route itself loads getModelOverviewCached(modelId, includeHidden), then renders ModelOverviewSections. getModelOverviewCached() currently uses a custom inline cache object rather than a preset profile, and ModelOverviewSections awaits getModelPricingCached() before rendering anything so it can decide whether to show API-related sections. getModelPricingCached() itself is cached with days. (GitHub)
For preset cache lives only, the built-in profiles are: default (5 min stale / 15 min revalidate / never expire), seconds (30 sec / 1 sec / 1 min), minutes (5 min / 1 min / 1 hour), hours (5 min / 1 hour / 1 day), days (5 min / 1 day / 1 week), (5 min / 1 week / 30 days), and (5 min / 30 days / 1 year). is the recommended stale-while-revalidate invalidation path, while is immediate and only works inside Server Actions. ()
Assistant
I’ll tackle this by first inspecting the current caching/data-fetching code paths you listed, then apply the preset-only cache/tag refactor in a targeted set of files, and finally run focused checks to confirm nothing regressed. I’m starting by reading the existing implementations in /models, model detail, and the relevant fetchers.
Assistant
I found the repo is already very dirty, so I’m limiting edits strictly to the caching files you referenced and will avoid touching unrelated changes. Next I’m reading the fetcher files plus the model-detail route to apply the preset-only refactor safely.
Assistant
I’ve confirmed the current code matches the cache layering problem you described. Next I’m applying the A→H file changes directly: remove page-level /models caching, switch fetchers to preset-only cache profiles/tags, and add Suspense boundaries on detail-page sections.
Assistant
I’m now standardizing the rankings fetcher to preset profiles only by removing the custom cache object and replacing every cacheLife(RANKINGS_CACHE) call with cacheLife("hours"), so behavior is consistent and tag-driven.
Assistant
rg isn’t executable in this shell session, so I’m using file-scoped PowerShell replacements instead to keep changes targeted and equivalent.
Assistant
I’m now introducing streaming boundaries on the model overview page: wrapping quickstart/benchmarks (and later creator models in the route) in Suspense so those async sections no longer block the whole response.
Assistant
Core edits are in place; I’m now verifying each changed file for consistency (no leftover custom cache objects, correct tags/profiles, and no import/type regressions), then I’ll run targeted type/lint checks for the web app.
Assistant
I’ve validated the edits at file level; next I’m running @ai-stats/web checks to catch any TypeScript or lint regressions introduced by these cache/suspense changes.
Assistant
Typecheck passes; lint is currently blocked by a repo-level ESLint/plugin incompatibility (react/display-name with ESLint 10), not by these file edits. I’m doing a final diff pass now to confirm the exact cache/tag/suspense deltas before summarizing.
Assistant
I’m grabbing exact line references for the cache-profile changes so you can review quickly or paste into the issue/PR notes.
Assistant
I found the central tag revalidation helper still only knew about legacy tags. I’m adding the new domain tags there (models:list-base, models:monitor) so existing invalidation flows will actually refresh the new cache keys too.
Assistant
Implemented the caching/data-fetching refactor for the open issue and aligned it with your preset-only plan.
Removed page-level cache on /models by deleting use cache, cacheLife("hours"), and cacheTag("page:models") from [page.tsx]
(/E:/ai-stats-public/apps/web/src/app/(dashboard)/models/page.tsx#L943).
Kept getAllModelsCached on days and added models:list-base tag
(/E:/ai-stats-public/apps/web/src/lib/fetchers/models/getAllModels.ts#L310).
Changed getMonitorModels to cacheLife("hours") and added models:monitor
(/E:/ai-stats-public/apps/web/src/lib/fetchers/models/table-view/getMonitorModels.ts#L241).
Removed custom rankings cache object and switched rankings fetchers to preset cacheLife("hours"), including getModelRankingsRows and getWeeklyModelProviderTokens
(/E:/ai-stats-public/apps/web/src/lib/fetchers/rankings/getRankingsData.ts#L726, #L793).
Changed getModelOverviewCached to cacheLife("weeks")
(/E:/ai-stats-public/apps/web/src/lib/fetchers/models/getModel.ts#L381).
Changed getModelPricingCached from days to hours
(/E:/ai-stats-public/apps/web/src/lib/fetchers/models/getModelPricing.ts#L574).
Updated model performance caching: metrics now hours; activity snapshot uses default profile (removed inline custom cache object)
(, ).
User
It still doesn't have custom skeletons though on the main model page? It uses the same skeleton as we do on the base models page?
Assistant
You’re right to call that out. I’m going to check what skeleton components already exist for the /models list and model-detail routes, then I’ll wire dedicated fallbacks instead of the shared/base skeleton where needed.
Assistant
You’re correct: the model-detail route currently falls back to the parent /models/loading.tsx, which is why you still see the list-page skeleton. I’ll add a dedicated loading UI for models/[organisationId]/[modelId] so detail pages render their own skeleton.
Assistant
I added a dedicated loading.tsx at the model-detail segment so /models/[organisationId]/[modelId] and its tabs no longer inherit the list-page skeleton. I’ll run a quick typecheck to verify.
Assistant
Correct, and now fixed for the model detail route.
/models/[organisationId]/[modelId] was inheriting the parent /models/loading.tsx, so it showed the list-page skeleton. I added a dedicated detail-page skeleton here:
loading.tsx
This now gives model detail pages (and their nested tabs) a custom loading UI instead of the base models-list skeleton. pnpm --filter @ai-stats/web typecheck passes.
If you also want a different skeleton for /models list itself (not just detail pages), I can split that too.
User
We should make it though that as much text as possible is just rendered on the page, so that the base page doesn't really need the skeleton - it actually just uses Suspense boundaries around the data that we await?
Assistant
Agreed. I’ll switch /models to stream a real page shell first and only suspend the data-heavy section, instead of showing the full-page skeleton. I’m checking ModelsDisplay and current loading.tsx to make the smallest safe refactor.
Assistant
I’m going to replace the /models skeleton fallback with a text-first streaming shell and make the segment loading.tsx match it, so users see real page copy immediately while the data section suspends.
Assistant
The skeleton is now removed for /models fallbacks in both page.tsx Suspense and route loading.tsx. I’ll run typecheck to confirm there are no regressions.
Assistant
Yes, implemented.
Replaced the /models skeleton fallback with a text-first streaming state in ModelsPageLoadingState.tsx.
Updated /models page Suspense fallback to use that component in page.tsx.
Updated route-level segment loading to use the same text-first state in loading.tsx.
Validation:
pnpm --filter @ai-stats/web typecheck passed.
Current behavior is now “render text immediately, suspend data-heavy content,” with no skeleton on the base models page.
If you want to push this further, next step is splitting ModelsDisplay into a static shell + async results block so even more real page copy renders outside Suspense.
User
The thing is though, certain text or buttons on the page should always be the same, so we shouldn't wrap the whole page in a single suspense, we should only put suspense where required - such as components requiring async data
Assistant
I found ModelsDisplay is used in multiple places, so before editing props I’m verifying whether those imports point to this same component or a different one to avoid accidental regressions.
Assistant
I’m implementing this as a true streamed shell: static title/view buttons render outside Suspense, and only the async models data section is suspended. I’ll also suppress duplicate heading/view switch inside ModelsDisplay for this route.
Assistant
I’ve moved /models to a streamed shell + data boundary and updated ModelsDisplay so the duplicated heading/view-switch don’t render in the streamed data section. I’m running typecheck now.
Assistant
Exactly right. I changed /models so only the async data section is suspended, not the whole page.
What I changed:
Added a static streamed shell (always rendered text/buttons) in ModelsPageStreamingShell.tsx
Updated /models page to render:
static shell, then
Suspense only around the async data section (ModelsPageDataSection)
in page.tsx
Updated route loading.tsx to match the same shell + data-loading block, not the old full skeleton: loading.tsx
Added showPrimaryHeader prop to ModelsDisplay and used showPrimaryHeader={false} from /models so we don’t duplicate the shell heading/view-switch inside loaded content: ModelsDisplay.tsx
Validation:
pnpm --filter @ai-stats/web typecheck passes.
User
This is all I am seeing on the models page though - and quite honestly it is terrible, so fix it
User
User
Assistant
Understood. I’ll trace every loading boundary that can affect /models (including parent segment loading files) and remove any global skeleton fallback that’s still winning. Then I’ll patch it so the shell text/buttons render immediately.
Assistant
I can see why you’re frustrated. I’m now checking the parent dashboard layout/loading wrappers, because your screenshot matches a higher-level skeleton fallback still taking precedence over the /models loading component.
Assistant
I confirmed the parent dashboard wrapper isn’t the culprit. Next I’m checking ModelsGrid/ModelsDisplay internals for any built-in skeleton state that could still be rendering even after the route fallback changes.
Assistant
I’m going to harden this by replacing ModelsPageSkeleton itself with the same text-first streamed shell. That way even if any stale boundary still imports it, you won’t get that grey-placeholder page again.
Assistant
I also found an orphaned interim loading component file that is no longer referenced, so I’m removing it to prevent fallback confusion later.
Assistant
I replaced the old ModelsPageSkeleton implementation entirely, so even stale/indirect imports can no longer render that grey placeholder layout. I’ll grab exact file refs and summarize what changed.
Assistant
Agreed, that state was bad. I replaced it so /models no longer has any path to that full grey skeleton.
What I changed:
Replaced old ModelsPageSkeleton implementation with the streamed shell + simple text loading state:
ModelsPageSkeleton.tsx
Kept /models route loading on the same streamed shell + text loading:
loading.tsx
Main /models page now renders static shell first and suspends only data section:
page.tsx
Shell component used by both page and loading boundary:
ModelsPageStreamingShell.tsx
Validation:
pnpm --filter @ai-stats/web typecheck passes.
If you still see the old grey skeleton after this, restart the Next dev server and hard refresh once (to clear stale route-loading bundles).
User
NO NO NO NO THIS IS NOT WHAT I AM TALKING ABOUT, REVERT THE CHANGES ON THE /MODELS PAGE - I AM TALKING ABOUT THE individual MODEL PAGES - like /models/openai/gpt-5 or whatever
Assistant
You’re right, I misunderstood the target route. I’m reverting the /models list-page loading changes now and leaving focus on individual model pages (/models/[organisationId]/[modelId]). I’ll surgically undo only the list-page edits so your existing work stays intact.
Assistant
You’re right; I’ll undo the /models list-page loading refactor and then move the Suspense/skeleton work to the individual model route (/models/[organisationId]/[modelId]) only. I’m checking the current diffs now so I can revert surgically without clobbering unrelated edits.
Assistant
I’ve confirmed the list-page now has the streaming shell changes. Next I’m reverting that /models wiring and then I’ll adjust the individual model route loading so only async sections suspend instead of blanketing the whole page with one skeleton.
Assistant
I hit an rg execution issue in this environment, so I’m switching to targeted Get-ChildItem/-LiteralPath reads to avoid broad scans and keep edits scoped.
Assistant
I’ve located the individual model loading.tsx; it currently renders a full-page skeleton, which explains the bad experience. I’m now checking ModelDetailShell and route layout so we can keep stable header/text visible and only suspend async sections.
Assistant
I’ve isolated the problem: the individual model route still has a full-page loading.tsx fallback, and the overview page still awaits data too high in the tree. I’m making two focused changes now:
Revert only the /models list-page streaming-shell changes.
Refactor /models/[organisationId]/[modelId] to stream section-by-section with local Suspense fallbacks and replace the heavy full-page skeleton loader.
Assistant
I’m now editing the individual model overview route so it no longer blocks on the full model payload before rendering, and I’ll replace the page-level loading fallback with lightweight section-level text placeholders.
Assistant
I’ve reverted the /models list-page streaming-shell wiring and deleted the extra shell component file. I’m running a web typecheck now to confirm the model-detail Suspense refactor and new loading behavior compile cleanly.
Assistant
I reverted the /models list-page loading shell changes and moved the streaming/fallback work to the individual model route.
Applied
/models list page is back to using the original page skeleton fallback (no ModelsPageStreamingShell):
page.tsx:963
ModelsPageStreamingShell.tsx was removed.
Individual model overview now streams data sections instead of awaiting the whole model payload before render:
page.tsx:138
Added local Suspense fallbacks for overview + creator sections.
ModelOverviewSections no longer blocks on a top-level pricing await; async parts are wrapped per-section:
ModelOverviewSections.tsx:751
Providers, Quickstart, and Benchmarks now suspend independently.
Replaced the heavy full-page model loading skeleton with text-first loading content:
loading.tsx:1
Validation
Ran pnpm --filter @ai-stats/web typecheck successfully.
If you want, I can now tune the per-section fallback copy/layout to match your exact final UI style for /models/[organisationId]/[modelId].
User
We shouldn't have the skeletons look completely different - the majority of the page should look identical, and the skeletons should be basically using the skeleton ui component in place of the components that will show
Assistant
Agreed. I’m going to replace the text-only fallbacks with real Skeleton-based placeholders that mirror the actual model page structure, and reuse the same section skeletons across loading.tsx and Suspense fallbacks so the layout stays visually consistent.
Assistant
I’m now aligning loading.tsx to the same structure as the real model page: header skeleton, tabs skeleton, then the same section skeleton components used by Suspense fallbacks.
Assistant
I’ve switched all model-page fallbacks to shared Skeleton components. I’ll run typecheck now to confirm everything compiles and then I’ll summarise exactly what changed.
Assistant
Implemented. The model-page fallbacks now use real Skeleton placeholders and keep the page structure nearly identical while data streams in.
Replaced text-only Suspense fallbacks with section-shaped skeleton components in ModelOverviewSections.tsx.
Added reusable shared skeleton exports:
ModelOverviewSectionsSkeleton
ModelCreatorModelsSkeleton
Wired the individual model route to use those shared skeletons for Suspense fallback in page.tsx.
Updated route-level loading UI to mirror the real page shell (header/buttons/tabs + same section skeletons) in loading.tsx.
Validation:
pnpm --filter @ai-stats/web typecheck passed.
If you want, I can now tighten the skeleton dimensions to match each final section even more 1:1 (especially Providers and Quickstart code block sizing).
User
Can we avoid the carded look on the skeletons please?
Assistant
Yes. I’ll flatten those skeleton sections so they read like the real page flow, without bordered/rounded card containers. I’m updating the shared skeleton components so both Suspense and route loading inherit the same non-card style.
Assistant
I’ve removed the bordered/card wrappers from the shared skeleton sections. I’ll quickly run typecheck to make sure everything is still clean.
Assistant
Done. I removed the “carded” styling from the model-page skeletons.
What changed:
Flattened section skeletons in ModelOverviewSections.tsx:
Removed rounded borders/padded card containers from Providers, Quickstart, Benchmarks, About, and Creator models skeletons.
Kept layout/spacing structure so it still mirrors the real page, just without card blocks.
Jest for apps/web with *.test.ts(x) or nearby __tests__; cover new logic and data validations with deterministic fixtures.
Python SDK tests rely on pytest and httpx.MockTransport; keep async cases isolated.
TS SDK lacks full coverage—add targeted unit or smoke tests when changing behavior.
Commit & Pull Request Guidelines
Commit subjects in history are short, descriptive, and scoped. Add a .changeset entry when shipping SDK/API/web changes that should version.
Never commit directly to main. Always work on a branch, open a PR, and merge via the PR flow.
When preparing PRs, always use a branch name that has not already been merged. Do not reuse previously merged branch names.
Never enable PR auto-merge (for example gh pr merge --auto) unless the user has explicitly approved auto-merge for that PR.
PRs: describe intent and scope, list commands run (lint/typecheck/build/tests/validations), link issues, and include screenshots or notes for UI changes.
When creating/editing PR descriptions via CLI/API, use real multiline Markdown (or a body file). Do not submit escaped newline text like \n in the final PR body.
Security & Configuration Tips
Never commit secrets; use .env.local per app. Required runtime keys are called out in turbo.jsonglobalEnv and app READMEs.
After OpenAPI edits, regenerate clients with pnpm openapi:gen so src/gen stays in sync before release.
Use Next 16 Cache Components properly, keep caching understandable, and avoid a migration. The rule set is:
Cache fetchers, not page assemblers.
Use preset cacheLife profiles only.
Treat TTL as fallback protection; treat tag invalidation as the main freshness mechanism.
Use <Suspense> where a section can stream separately instead of blocking the whole page. (Next.js)
2. Design decision
For AI Stats, there should be two kinds of cache:
Data caches: model core data, pricing/provider overlays, rankings, usage rollups.
No page-level cache for assembled public pages: the page should mostly just compose already-cached data.
That means /models should stop caching ModelsPageContent() as one shared blob. The fetchers under it are already the right abstraction boundary; the page cache is the redundant layer causing the pain. (GitHub)
3. Preset profile policy
Use these presets and do not add custom profiles yet:
max for near-immutable reference data.
weeks for model overview/core metadata.
days for the big base catalogue list.
hours for provider/pricing overlays, rankings, and heavier analytics.
default for small activity summaries where 15-minute freshness is acceptable and close enough to your “~30 minutes” goal for now. (Next.js)
The reason to prefer hours plus tag invalidation for the heavier rollups is simple: with presets only, there is no native 30-minute profile. So for big public analytics payloads, let the scheduled job or importer drive freshness via revalidateTag(..., "max"), and let hours act as the safety net if invalidation is missed. (Next.js)
This page currently caches the assembled output with page:models, while also depending on four cached/global data sources. Remove that layer first. (GitHub)
This is your stable base list of ~950 models. Daily fallback is fine; freshness should come from invalidation when core model metadata changes. It is already cached with days, so this is a small refinement, not a rewrite. (GitHub)
C. src/lib/fetchers/models/table-view/getMonitorModels.ts
Change:
ts
cacheLife("days");
to:
ts
cacheLife("hours");
cacheTag("models:monitor");
Keep the existing table-level tags too.
This fetcher includes provider model, pricing rule, model, and API provider state. That is not “days” data in practice. It is the exact overlay that makes /models feel stale when provider support changes. (GitHub)
D. src/lib/fetchers/rankings/getRankingsData.ts
Delete the custom RANKINGS_CACHE object and switch the public rankings/weekly token functions to the preset hours.
So, for example:
ts
export async function getModelRankingsRows(...) {
cacheLife("hours");
cacheTag("public-rankings");
...
}
export async function getWeeklyModelProviderTokens() {
cacheLife("hours");
cacheTag("public-rankings");
...
}
Your current rankings cache is stale: 1h, revalidate: 6h, expire: 7d, which is much looser than the public dashboard feel you described. Preset-only means you cannot land exactly on 30 minutes, so hours plus invalidation from the rollup job is the cleanest compromise. (GitHub)
E. src/lib/fetchers/models/getModel.ts
Leave getModelCached() on days.
Change getModelOverviewCached() from the inline custom object to the preset weeks:
Pricing/provider routing state is not stable enough for days if you care about supported providers and quickstart accuracy. The current function is tagged correctly enough; the lifetime is the weak part. (GitHub)
G. src/lib/fetchers/models/getModelPerformance.ts
Use presets only:
getModelPerformanceMetricsCached() → hours
getModelPerformanceActivitySnapshotCached() → use the default profile by omitting a custom object, or also standardise it on hours if you want one rule everywhere.
My recommendation:
ts
export async function getModelPerformanceMetricsCached(...) {
"use cache";
cacheLife("hours");
cacheTag("data:gateway_usage_rollups");
cacheTag(`data:gateway_usage_rollups:model:${modelId}`);
cacheTag(`model:performance:${modelId}`);
...
}
export async function getModelPerformanceActivitySnapshotCached(...) {
"use cache";
// rely on Next's default profile here
cacheTag("data:gateway_usage_rollups");
cacheTag(`data:gateway_usage_rollups:model:${modelId}`);
cacheTag(`model:performance:${modelId}`);
...
}
That gives you heavier charts on an hourly safety net, and smaller summary cards on a 15-minute default if you want slightly fresher top-line stats. Your current implementation uses inline custom lifetimes for both functions. (GitHub)
H. src/components/(data)/model/overview/ModelOverviewSections.tsx
Do not add use cache to this component.
Either keep it as a composition shell, or make it less blocking. Right now it awaits getModelPricingCached() before rendering any section, purely to compute hasApiProviders. That is acceptable as a first phase because the pricing fetch itself will be cached, but it is still the current blocking edge. (GitHub)
For the next pass, split streamable sections with <Suspense>. Next’s guidance is explicit: components that need fresh or asynchronous work can be left uncached and streamed with a fallback, instead of blocking the whole tree. (Next.js)
And in the route file, wrap ModelCreatorModelsSection in its own <Suspense> as well, because it is a separate async fetch and not required for first paint. The current route renders it directly under the overview component. (GitHub)
5. Tag taxonomy
Keep your existing tags for compatibility, but add a small domain vocabulary and start using it consistently:
models:list-base
models:monitor
public-rankings
model:data:${id}
model:api:${id}
model:performance:${id}
The reason is simple: revalidateTag is global across all pages using that tag, while revalidatePath is path-specific. For AI Stats, data ownership matters more than route ownership. (Next.js)
6. Invalidation rules
Use updateTag() only from Server Actions where the user just changed something and should see it immediately. Use revalidateTag(tag, "max") from jobs, importers, cron endpoints, or Route Handlers where stale-while-revalidate is the right behaviour. (Next.js)
Examples: 15-minute or 30-minute rollup recompute.
ts
import { revalidateTag } from "next/cache";
export async function afterRollupBatch(changedModelIds: string[]) {
for (const modelId of changedModelIds) {
revalidateTag(`model:performance:${modelId}`, "max");
revalidateTag(`data:gateway_usage_rollups:model:${modelId}`, "max");
}
revalidateTag("public-rankings", "max");
revalidateTag("data:gateway_usage_rollups", "max");
}
That gets you close to the “refresh every ~30 minutes” behaviour without inventing a custom profile yet. (Next.js)
7. What this solves
This solves the redundant page-level cache, makes the cache story understandable, and lets you reason about freshness per data domain instead of per page. It also keeps you on Next/Supabase and avoids a migration that would not actually fix the dependency shape. (GitHub)
8. What this does not solve
It does not fully eliminate shared invalidation on /models, because the page still merges full-list overlays: allModels, monitorResult.models, rankingsResult, and weeklyUsageResult.data. If one model’s provider support changes, those overlay fetchers are still shared arrays for the whole page, so some global list recomputation is still normal. That is a data-shape issue, not a Next.js issue. (GitHub)
If /models is still too expensive after phase 1, the real phase 2 is not Convex. It is a denormalised or materialised public catalogue snapshot keyed by model_id, so one model update only rewrites one row and the list page reads one precomputed source.
9. Rollout order
Do it in this order:
Remove page-level caching from /models.
Replace all inline cache objects with preset profiles only.
Standardise tag names and wire invalidation into admin writes/import jobs.
Add <Suspense> around streamable detail-page sections.
Only if needed later, introduce a denormalised catalogue snapshot.
That is the smallest path that gives you a sane long-term cache model without ripping the stack apart.
Next sensible step: map your actual write/import paths to this tag matrix so the invalidation is not hand-wavy.
Added streaming boundaries with <Suspense> for overview quickstart/benchmarks and creator-models section on detail page
(/E:/ai-stats-public/apps/web/src/components/(data)/model/overview/ModelOverviewSections.tsx#L772, /E:/ai-stats-public/apps/web/src/app/(dashboard)/models/[organisationId]/[modelId]/page.tsx#L72).
Wired new tags into central invalidation helper so existing revalidation flows include them
(/E:/ai-stats-public/apps/web/src/lib/cache/revalidateDataTags.ts#L28, #L46).
Validation:
pnpm --filter @ai-stats/web typecheck passed.
pnpm --filter @ai-stats/web lint failed due existing ESLint/plugin incompatibility (react/display-name with ESLint 10), unrelated to these edits.
Natural next step:
Map importer/admin write paths to explicit revalidateTag(tag, "max") calls per your tag matrix (model core, provider/pricing, rollups).