Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@
NPM_VERSION = "12.0.2"
# Serve the static export directly; no Next runtime/functions are needed.
NETLIFY_NEXT_PLUGIN_SKIP = "true"

# Next names everything under /_next/static/ after a hash of its contents, so a changed file always gets a
# new URL. Browsers can keep these for a year without re-checking them on every visit.
[[headers]]
for = "/_next/static/*"
[headers.values]
Cache-Control = "public, max-age=31536000, immutable"
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 16 additions & 8 deletions website/scripts/build-public-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,21 @@ import {
import { buildRegionalSummary, historyEntry, findCell, type Summary, type TargetSet } from '../src/lib/aggregate';
import { COST_MIN_SESSION_S } from '../src/config';
import { fmtDate } from '../src/lib/format';
import { summaryDataPath } from '../src/lib/summary-data';
import { rowsDataPath, summaryDataPath, withoutRows } from '../src/lib/summary-data';
import { buildBenchmarkVersions } from '../src/lib/versions';

/**
* Prebuild step: emit static data artifacts consumed as plain files.
* - public/api/results.json full precomputed summary (typed)
* - public/api/table.csv full results table, one row per provider × target set
* - public/api/runs/<file> raw JSONL copies, linked from every chart
* - public/api/summaries/<month>-<region>.json
* one homepage view each, rows included; the
* homepage inlines only its default view and
* fetches these on demand
* - public/api/views/<month>-<region>.json
* one homepage view each, without rows; the
* homepage inlines its default view and fetches
* the others when selected
* - public/api/rows/<month>-<region>.json
* that view's per-target rows, fetched only when
* the row detail or failure explorer needs them
*
* Runs as the first step of `npm run website:build`.
*/
Expand Down Expand Up @@ -145,9 +148,14 @@ const versions = buildBenchmarkVersions();
let summaryFiles = 0;
for (const version of versions) {
for (const { region, summary: view } of version.regions) {
const file = path.join(OUT, '..', summaryDataPath(version.id, region));
fs.mkdirSync(path.dirname(file), { recursive: true });
fs.writeFileSync(file, JSON.stringify(view));
for (const [publicPath, data] of [
[summaryDataPath(version.id, region), withoutRows(view)],
[rowsDataPath(version.id, region), view.rows],
] as const) {
const file = path.join(OUT, '..', publicPath);
fs.mkdirSync(path.dirname(file), { recursive: true });
fs.writeFileSync(file, JSON.stringify(data));
}
summaryFiles++;
}
}
Expand Down
71 changes: 46 additions & 25 deletions website/src/components/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use client';

import { useEffect, useMemo, useRef, useState } from 'react';
import { hasFullStealthCoverage, type Summary, type TargetSet } from '@/lib/aggregate';
import { DEFAULT_REGION, summaryDataPath, type SummaryWithoutRows } from '@/lib/summary-data';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { hasFullStealthCoverage, type SlimRow, type Summary, type TargetSet } from '@/lib/aggregate';
import { DEFAULT_REGION, rowsDataPath, summaryDataPath, type SummaryWithoutRows } from '@/lib/summary-data';
import { antibotName, fmtDate, formatRunnerRegion } from '@/lib/format';
import { buildMarkdownSummary } from '@/lib/markdown';
import { resolveTargetSetSelection, type GlobalFilters, type TargetSetSelection } from '@/lib/select';
Expand Down Expand Up @@ -33,24 +33,20 @@ export interface BenchmarkVersion {

const KNOWN_REGIONS = ['us-west', 'us-east', 'eu-west'];

/**
* Loads one view's full summary from /api/summaries/ and caches it per URL.
* The homepage HTML only inlines the default view without its rows, so this
* runs right after hydration for the default view too (for the rows).
*/
function useViewSummary(url: string, enabled: boolean) {
const [loaded, setLoaded] = useState<Record<string, Summary>>({});
/** Fetches JSON from `url` once `enabled`, caching each URL's result (or failure) for the session. */
function useCachedJson<T>(url: string, enabled: boolean) {
const [loaded, setLoaded] = useState<Record<string, T>>({});
const [failed, setFailed] = useState<Record<string, true>>({});
useEffect(() => {
if (!enabled || loaded[url] || failed[url]) return;
if (!enabled || url in loaded || failed[url]) return;
let cancelled = false;
fetch(url)
.then((res) => {
if (!res.ok) throw new Error(`${res.status} ${url}`);
return res.json() as Promise<Summary>;
return res.json() as Promise<T>;
})
.then((summary) => {
if (!cancelled) setLoaded((prev) => ({ ...prev, [url]: summary }));
.then((data) => {
if (!cancelled) setLoaded((prev) => ({ ...prev, [url]: data }));
})
.catch(() => {
if (!cancelled) setFailed((prev) => ({ ...prev, [url]: true }));
Expand All @@ -59,7 +55,7 @@ function useViewSummary(url: string, enabled: boolean) {
cancelled = true;
};
}, [url, enabled, loaded, failed]);
return { summary: loaded[url] ?? null, failed: !!failed[url] };
return { data: url in loaded ? loaded[url] : null, failed: !!failed[url] };
}

export function Dashboard({
Expand All @@ -77,18 +73,31 @@ export function Dashboard({
? DEFAULT_REGION
: activeVersion.regions[0];
const isInitialView = activeVersion.id === initial.versionId && activeRegion === initial.region;
const view = useViewSummary(summaryDataPath(activeVersion.id, activeRegion), ready);
const initialSummary = useMemo<Summary>(() => ({ ...initial.summary, rows: [] }), [initial.summary]);
// The default view is already in the HTML; other views are fetched once the URL has been read.
const view = useCachedJson<SummaryWithoutRows>(
summaryDataPath(activeVersion.id, activeRegion),
ready && !isInitialView,
);
// Rows are fetched only after something asks for them (the failure explorer nearing the viewport, or a
// results-table row being expanded), then for every view shown after that.
const [rowsWanted, setRowsWanted] = useState(false);
const requestRows = useCallback(() => setRowsWanted(true), []);
const rows = useCachedJson<SlimRow[]>(rowsDataPath(activeVersion.id, activeRegion), ready && rowsWanted);
// While another view loads, keep the last one on screen (dimmed) instead of blanking the page.
const lastShown = useRef<Summary>(initialSummary);
const summary = view.summary ?? (isInitialView ? initialSummary : lastShown.current);
const activeLite = isInitialView ? initial.summary : view.data;
const lastShown = useRef<SummaryWithoutRows>(initial.summary);
const lite = activeLite ?? lastShown.current;
useEffect(() => {
lastShown.current = summary;
}, [summary]);
const rowsReady = view.summary != null;
lastShown.current = lite;
}, [lite]);
// Another view's data is on screen: dim it while loading, and keep it dimmed if loading failed.
const showingStaleView = !view.summary && !isInitialView;
const showingStaleView = activeLite == null;
const viewPending = showingStaleView && !view.failed;
const rowsReady = !showingStaleView && rows.data != null;
const summary = useMemo<Summary>(
() => ({ ...lite, rows: rowsReady && rows.data ? rows.data : [] }),
[lite, rowsReady, rows.data],
);
const hasFullStealth = hasFullStealthCoverage(summary);
const protectedFrom = summary.protectedMeasuredFrom ? formatRunnerRegion(summary.protectedMeasuredFrom) : null;

Expand Down Expand Up @@ -343,10 +352,22 @@ export function Dashboard({
}}
/>
</div>
<ResultsTable summary={summary} rowsReady={rowsReady} params={params} setParams={set} />
<ResultsTable
summary={summary}
rowsReady={rowsReady}
rowsFailed={rows.failed}
onNeedRows={requestRows}
params={params}
setParams={set}
/>
</section>

<FailureExplorer summary={summary} rowsReady={rowsReady} />
<FailureExplorer
summary={summary}
rowsReady={rowsReady}
rowsFailed={rows.failed}
onNeedRows={requestRows}
/>
<FaqSection summary={summary} />
<RunHistorySection summary={summary} />
</div>
Expand Down
18 changes: 14 additions & 4 deletions website/src/components/ResultsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { COST_MIN_SESSION_S, MIN_SAMPLES } from '@/config';
import type { Cell, Summary, TargetSet } from '@/lib/aggregate';
import { findCell } from '@/lib/aggregate';
import { antibotName, fmtMs, fmtPct, fmtUsd, fmtUsdPerHour } from '@/lib/format';
import { Fragment, useMemo, useState } from 'react';
import { Fragment, useEffect, useMemo, useState } from 'react';
import { LabeledSelect, ProviderLabel, ProviderTableRow, Toggle } from './ui';

/**
Expand Down Expand Up @@ -249,10 +249,15 @@ export function ResultsTable({
params,
setParams,
rowsReady = true,
rowsFailed = false,
onNeedRows,
}: {
summary: Summary;
/** False while the per-target rows are still being fetched. */
/** False until the per-target rows have been fetched. */
rowsReady?: boolean;
rowsFailed?: boolean;
/** Called when a row is expanded before the per-target rows have loaded. */
onNeedRows?: () => void;
params: Record<string, string>;
setParams: (u: Record<string, string | null>) => void;
}) {
Expand All @@ -267,6 +272,9 @@ export function ResultsTable({
const sortCol = params.sort ?? 'frt';
const sortDir: 'asc' | 'desc' | null = params.dir === 'asc' || params.dir === 'desc' ? params.dir : null;
const [openRow, setOpenRow] = useState<string | null>(null);
useEffect(() => {
if (openRow != null && !rowsReady) onNeedRows?.();
}, [openRow, rowsReady, onNeedRows]);

const columns = useMemo(() => makeColumns(expanded, summary), [expanded, summary]);

Expand Down Expand Up @@ -576,8 +584,10 @@ export function ResultsTable({
{rowsReady ? (
<RowDetail rows={detailRows(r)} />
) : (
<p className="text-xs text-ink-3" aria-busy>
Loading per-target rows…
<p className="text-xs text-ink-3" aria-busy={!rowsFailed}>
{rowsFailed
? "Couldn't load per-target rows. Reload the page to try again."
: 'Loading per-target rows…'}
</p>
)}
</td>
Expand Down
35 changes: 30 additions & 5 deletions website/src/components/Sections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { antibotName, formatRunnerRegion, providerName } from '@/lib/format';
import { generateFaq, leaderSummaries, type LeaderContext } from '@/lib/leaders';
import { githubResultFile, monthlyRunHistory } from '@/lib/run-history';
import { Check, ChevronDown, Copy } from 'lucide-react';
import { useEffect, useMemo, useState } from 'react';
import { useEffect, useMemo, useRef, useState } from 'react';
import { LabeledSelect, SectionHeading } from './ui';

/**
Expand Down Expand Up @@ -345,7 +345,32 @@ export function FaqSection({ summary }: { summary: Summary }) {
}

/** Failure explorer (§4.16): every non-passing row, grouped by classification, filterable by provider. */
export function FailureExplorer({ summary, rowsReady = true }: { summary: Summary; rowsReady?: boolean }) {
export function FailureExplorer({
summary,
rowsReady = true,
rowsFailed = false,
onNeedRows,
}: {
summary: Summary;
/** False until the per-target rows have been fetched. */
rowsReady?: boolean;
rowsFailed?: boolean;
/** Called when the section nears the viewport, so the rows load before anyone reaches it. */
onNeedRows?: () => void;
}) {
const sectionRef = useRef<HTMLElement>(null);
useEffect(() => {
const el = sectionRef.current;
if (rowsReady || !onNeedRows || !el) return;
const observer = new IntersectionObserver(
(entries) => {
if (entries.some((entry) => entry.isIntersecting)) onNeedRows();
},
{ rootMargin: '800px 0px' },
);
observer.observe(el);
return () => observer.disconnect();
}, [rowsReady, onNeedRows]);
const [group, setGroup] = useState<'harness_error' | 'infra_failure' | 'blocked'>('blocked');
const [provider, setProvider] = useState<string>('all');
const scoped = summary.rows.filter((r) => provider === 'all' || r.provider === provider);
Expand All @@ -365,7 +390,7 @@ export function FailureExplorer({ summary, rowsReady = true }: { summary: Summar
harness_error: `Not benchmarked; config/billing errors (${counts.harness_error})`,
} as const;
return (
<section>
<section ref={sectionRef}>
<SectionHeading id="failures" title="Failure explorer" />
<p className="mb-3 max-w-3xl text-sm text-ink-2">
Every non-passing row in the current run, with its raw error text. Blocked (the antibot won), infrastructure
Expand Down Expand Up @@ -459,8 +484,8 @@ export function FailureExplorer({ summary, rowsReady = true }: { summary: Summar
))}
{!rowsReady && (
<tr>
<td colSpan={5} className="p-4 text-center text-ink-3" aria-busy>
Loading rows…
<td colSpan={5} className="p-4 text-center text-ink-3" aria-busy={!rowsFailed}>
{rowsFailed ? "Couldn't load the rows. Reload the page to try again." : 'Loading rows…'}
</td>
</tr>
)}
Expand Down
2 changes: 1 addition & 1 deletion website/src/lib/aggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export interface Summary {
providerRowStats: Record<string, ProviderRowStats>;
/**
* Per-target detail rows. The homepage inlines its summary without them
* (see SummaryWithoutRows) and fetches them from /api/summaries/ after load.
* (see SummaryWithoutRows) and fetches them from /api/rows/ only when needed.
*/
rows: SlimRow[];
history: HistoryEntry[];
Expand Down
19 changes: 15 additions & 4 deletions website/src/lib/summary-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,23 @@ export const DEFAULT_REGION = 'us-west';
export type SummaryWithoutRows = Omit<Summary, 'rows'>;

/**
* Public path of one month × region summary, rows included. Written by
* scripts/build-public-data.ts so the homepage HTML only has to carry the
* default view; other views and the row-level detail are fetched on demand.
* Public path of one month × region summary without its rows. Written by
* scripts/build-public-data.ts; the homepage inlines the default view and
* fetches others from here when the visitor switches month or region.
* (Not /api/summaries/: older pages still open in a browser expect rows in
* those files, and a 404 makes them show their load error instead of crashing.)
*/
export function summaryDataPath(versionId: string, region: string): string {
return `/api/summaries/${versionId}-${region}.json`;
return `/api/views/${versionId}-${region}.json`;
}

/**
* Public path of one view's per-target rows (`SlimRow[]`). They are most of a
* view's size and only the row detail and failure explorer need them, so the
* homepage fetches them only when one of those is about to be used.
*/
export function rowsDataPath(versionId: string, region: string): string {
return `/api/rows/${versionId}-${region}.json`;
}

export function withoutRows(summary: Summary): SummaryWithoutRows {
Expand Down