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
34 changes: 30 additions & 4 deletions dashboard/e2e/analytics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function days(n: number) {
}

const SUMMARY = {
runs: 42, prs_opened: 30, prs_merged: 21, prs_closed: 3, prs_open: 6, merge_rate: 0.7, failed_runs: 4, failure_rate: 0.095,
runs: 42, prs_opened: 30, prs_merged: 21, prs_closed: 3, prs_open: 6, merge_rate: 0.7, failed_runs: 4, failure_rate: 0.095, failed_then_retried: 2,
cost_usd: 96.4, run_cost_usd: 41.2, cost_basis: "metered", cost_by_feature: [{ feature: "review", cost_usd: 50 }, { feature: "run", cost_usd: 41.2 }, { feature: "feedback", cost_usd: 5.2 }],
cost_per_run: 2.3, cost_per_merged_pr: 4.59, tokens_in: 12_000_000, tokens_out: 900_000,
median_run_minutes: 11.5, median_hours_to_merge: 5.2, time_to_merge_known: 12, merged_untouched: 9, merged_with_edits: 3, edits_known: 12, reviews: 55,
Expand Down Expand Up @@ -108,9 +108,17 @@ function analytics(period: string, repo: string | null, deployState: DeployState
{ person: "Coderhelm (E2E tests)", kind: "coderhelm", runs: 4, merged: 2 },
],
failures: [
{ reason: "Timed out after #s", count: 3, last_run_id: "01RUNFAILED00000000000000A", last_at: new Date().toISOString() },
{ reason: "Branch … already exists", count: 1, last_run_id: "01RUNFAILED00000000000000B", last_at: new Date().toISOString() },
{ reason: "Timed out after #s", count: 3, last_run_id: "01RUNFAILED00000000000000A", last_at: new Date().toISOString(), stage: "implement", retried: 2 },
{ reason: "Branch … already exists", count: 1, last_run_id: "01RUNFAILED00000000000000B", last_at: new Date().toISOString(), stage: "pr", retried: 0 },
],
failures_more: { reasons: 2, runs: 3 },
waiting: {
total: 4,
reasons: [
{ reason: "Review pull request", count: 3, last_run_id: "01RUNWAITING000000000000A", last_at: new Date().toISOString() },
{ reason: "Nothing recorded", count: 1, last_run_id: "01RUNWAITING000000000000B", last_at: new Date().toISOString() },
],
},
ci: {
runs_with_red_ci: 8, fixed_by_coderhelm: 6, fix_rate: 0.75, fix_attempts: 11, fix_commits: 9, red_on_base_runs: 1,
outcomes: { green_after_fix: 6, green_without_fix: 0, flaky: 1, red_on_base: 1, gave_up: 1, running: 0 },
Expand All @@ -135,7 +143,7 @@ function analytics(period: string, repo: string | null, deployState: DeployState
{ run_id: "01RUNMERGED00000000000000B", title: "Retry the sync job once", repo: "your-team/backend", pr_number: 55, pr_url: "https://github.com/your-team/backend/pull/55", hours_to_merge: null, human_commits: null },
],
failed_recent: [
{ run_id: "01RUNFAILED00000000000000A", title: "Update the pricing page", repo: "your-team/web", reason: "Timed out after #s", at: new Date().toISOString() },
{ run_id: "01RUNFAILED00000000000000A", title: "Update the pricing page", repo: "your-team/web", reason: "Timed out after #s", at: new Date().toISOString(), stage: "implement", retried: true },
],
repo_names: ["your-team/backend", "your-team/web"],
};
Expand Down Expand Up @@ -272,6 +280,24 @@ test("stops and blocks show the unnecessary and the nuisance ones, with examples
await shot(page, "analytics-decisions");
});

test("failures show their step and retries, the rest summed, and what waiting runs wait for", async ({ page }) => {
await mockApi(page);
await page.goto("/analytics?tab=reliability");
const failures = page.getByRole("table", { name: "Failures by reason" });
await expect(failures.locator("tbody tr td:first-child")).toHaveText(["Timed out after #s", "Branch … already exists", "2 other reasons"]);
await expect(failures.locator("tbody tr").first()).toContainText("Writing code");
await expect(failures.locator("tbody tr").nth(1)).toContainText("Opening the PR");
const waiting = page.getByRole("table", { name: "Runs waiting on a person" });
await expect(page.getByTestId("waiting")).toContainText("Waiting on a person (4)");
await expect(waiting.locator("tbody tr td:first-child")).toHaveText(["Review pull request", "Nothing recorded: open the run, then retry or close it"]);
await expect(waiting.getByRole("link", { name: "Open run" }).first()).toHaveAttribute("href", /id=01RUNWAITING000000000000A$/);
await expect(page.getByRole("table", { name: "Recently failed" })).toContainText("retried by a person");
await page.getByRole("table", { name: "Failures by reason" }).scrollIntoViewIfNeeded();
await shot(page, "analytics-failures");
await page.goto("/analytics");
await expect(page.getByTestId("tile-failed")).toContainText("2 retried by a person");
});

test("where it struggles places every red CI run in one outcome, base-branch failures apart", async ({ page }) => {
await mockApi(page);
await page.goto("/analytics?tab=reliability");
Expand Down
67 changes: 53 additions & 14 deletions dashboard/src/app/analytics/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function actorLabel(a: string) {
return ({ reviewer: "Reviewer", planner: "Planner", coder: "Coding agent", people: "People in the dashboard" } as Record<string, string>)[a] ?? a;
}
function stepLabel(s: string) {
return ({ triage: "Triage", plan: "Planning", implement: "Writing code", ci_fix: "Fixing CI", review: "Self-review", feedback: "Answering feedback", pr: "Opening the PR", security: "Security check" } as Record<string, string>)[s] ?? s.replace(/_/g, " ");
return ({ triage: "Triage", plan: "Planning", implement: "Writing code", test: "Testing", ci_fix: "Fixing CI", review: "Self-review", feedback: "Answering feedback", pr: "Opening the PR", security: "Security check" } as Record<string, string>)[s] ?? s.replace(/_/g, " ");
}
function sourceLabel(s: string) {
return ({ github: "GitHub issues", jira: "Jira", alert: "Alerts", other: "Other" } as Record<string, string>)[s] ?? s;
Expand Down Expand Up @@ -261,7 +261,7 @@ function Body({ data, loading, stats, tab }: { data: Analytics; loading: boolean
<Tile testId="tile-untouched" label="Merged as written" value={s.edits_known ? pct(s.merged_untouched / s.edits_known) : "—"} basis={s.edits_known ? `${count(s.merged_untouched)} of ${plural(s.edits_known, "merged PR")} had no commits from people` : "Recorded for PRs merged from now on"} />
<Tile testId="tile-ci" label="Red CI fixed by Coderhelm" value={pct(data.ci.fix_rate)} basis={data.ci.runs_with_red_ci ? `${count(data.ci.fixed_by_coderhelm)} of ${plural(data.ci.runs_with_red_ci, "run")} went green after its fixes` : "No red CI on Coderhelm's PRs"} />
<Tile testId="tile-findings" label="Review findings acted on" value={pct(data.reviews.acted_on_rate)} basis={data.reviews.outcomes_known_reviews ? `${count(data.reviews.findings_fixed)} fixed in code, ${count(data.reviews.findings_settled_by_person)} settled by a person` : "Counted from re-reviews from now on"} />
<Tile testId="tile-failed" label="Failed runs" value={count(s.failed_runs)} change={delta(s.failed_runs, p.failed_runs, "count", vs)} basis={s.runs ? `${pct(s.failure_rate)} of runs${s.closed_runs ? ` · ${plural(s.closed_runs, "run")} closed by a person, not counted` : ""}` : undefined} />
<Tile testId="tile-failed" label="Failed runs" value={count(s.failed_runs)} change={delta(s.failed_runs, p.failed_runs, "count", vs)} basis={s.runs ? `${pct(s.failure_rate)} of runs${s.failed_then_retried ? ` · ${count(s.failed_then_retried)} retried by a person` : ""}${s.closed_runs ? ` · ${plural(s.closed_runs, "run")} closed by a person, not counted` : ""}` : undefined} />
</StatGrid>
<UsageNote stats={stats} />
</Section>
Expand Down Expand Up @@ -320,17 +320,8 @@ function Body({ data, loading, stats, tab }: { data: Analytics; loading: boolean

{tab === "reliability" && (
<>
<Section title="Where it struggles" id="struggles" description="Failed runs grouped by what went wrong. Open the latest run of a group to see its steps.">
<Table
label="Failures by reason"
head={["Reason", "Runs", "Latest"]}
rows={data.failures.map((f) => [
f.reason,
f.count,
<Link key={f.last_run_id} href={`/runs/detail?id=${f.last_run_id}`} className="text-zinc-100 underline-offset-2 hover:underline">Open run</Link>,
])}
empty={`No failed runs in ${span}.`}
/>
<Section title="Where it struggles" id="struggles" description="Failed runs grouped by what went wrong, those a person retried included. Open the latest run of a group: its page says what to do next.">
<FailureTable data={data} span={span} />
{(data.ci.runs_with_red_ci > 0 || (data.ci.red_on_base_runs ?? 0) > 0) && (
<p className="mt-3 text-sm text-zinc-400" data-testid="ci-line">
CI went red on {plural(data.ci.runs_with_red_ci, "run")}
Expand All @@ -340,6 +331,7 @@ function Body({ data, loading, stats, tab }: { data: Analytics; loading: boolean
)}
{data.ci.outcomes && <CiOutcomes ci={data.ci} outcomes={data.ci.outcomes} />}
{!!data.loops_stopped?.total && <LoopsStopped stopped={data.loops_stopped} />}
{!!data.waiting?.total && <Waiting waiting={data.waiting} />}
</Section>

<DecisionsSection days={d} />
Expand Down Expand Up @@ -370,7 +362,11 @@ function Body({ data, loading, stats, tab }: { data: Analytics; loading: boolean
rows={data.failed_recent.map((r) => [
<span key={r.run_id} className="block min-w-0">
<Link href={`/runs/detail?id=${r.run_id}`} className="text-zinc-100 underline-offset-2 hover:underline">{r.title || `Run ${r.run_id}`}</Link>
<span className="block text-xs text-zinc-400">{r.repo}</span>
<span className="block text-xs text-zinc-400">
{r.repo}
{r.stage && <>{" · "}{stepLabel(r.stage)}</>}
{r.retried && <>{" · "}retried by a person</>}
</span>
</span>,
<span key="reason" className="text-xs text-zinc-300" title={r.reason}>{r.reason}</span>,
])}
Expand Down Expand Up @@ -728,6 +724,49 @@ function CiOutcomes({ ci, outcomes }: { ci: Analytics["ci"]; outcomes: Analytics
);
}

/** Failed runs by reason, with the step they failed in and how many a person retried. */
function FailureTable({ data, span }: { data: Analytics; span: string }) {
const more = data.failures_more;
const rows: ReactNode[][] = data.failures.map((f) => [
<span key="reason" className="block min-w-0 text-zinc-200" title={f.reason}>{f.reason}</span>,
f.stage ? stepLabel(f.stage) : "—",
f.count,
f.retried == null ? "—" : f.retried,
<Link key={f.last_run_id} href={`/runs/detail?id=${f.last_run_id}`} className="text-zinc-100 underline-offset-2 hover:underline">Open run</Link>,
]);
if (more && more.reasons > 0) {
rows.push([
<span key="more" className="text-zinc-400">{`${plural(more.reasons, "other reason")}`}</span>,
"—",
more.runs,
"—",
"",
]);
}
return <Table label="Failures by reason" head={["Reason", "Step", "Runs", "Retried", "Latest"]} rows={rows} empty={`No failed runs in ${span}.`} />;
}

/** Runs that stopped for a person and still wait: what each waits for. */
function Waiting({ waiting }: { waiting: NonNullable<Analytics["waiting"]> }) {
const rows: ReactNode[][] = waiting.reasons.map((r) => [
r.reason === "Nothing recorded" ? (
<span key="reason" className="text-amber-300" title="The run stopped for a person without saying what for. Open it, read its last notes, then retry or close it.">
Nothing recorded: open the run, then retry or close it
</span>
) : (
r.reason
),
r.count,
<Link key={r.last_run_id} href={`/runs/detail?id=${r.last_run_id}`} className="text-zinc-100 underline-offset-2 hover:underline">Open run</Link>,
]);
return (
<div className="mt-4" data-testid="waiting">
<h3 className="mb-2 text-sm font-medium text-zinc-200">Waiting on a person ({count(waiting.total)})</h3>
<Table label="Runs waiting on a person" head={["Waiting for", "Runs", "Latest"]} rows={rows} empty="None." />
</div>
);
}

/** Runs Coderhelm stopped for making no progress, handing them to a person. */
function LoopsStopped({ stopped }: { stopped: NonNullable<Analytics["loops_stopped"]> }) {
const rows: ReactNode[][] = stopped.reasons.map((r) => [r.reason, r.count]);
Expand Down
16 changes: 14 additions & 2 deletions dashboard/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3693,8 +3693,11 @@ export interface AnalyticsSummary {
prs_open: number;
/** Merged out of opened, 0-1; null with no PRs. */
merge_rate: number | null;
/** Failed runs, those a person then retried or started over included. */
failed_runs: number;
failure_rate: number | null;
/** Of the failed runs, those a person retried. Older backends leave it out. */
failed_then_retried?: number;
/** Runs a person closed on purpose: not failures. Older backends leave it out. */
closed_runs?: number;
/**
Expand Down Expand Up @@ -3744,7 +3747,16 @@ export interface Analytics {
repos: { repo: string; runs: number; prs: number; merged: number; failed: number; cost_usd: number; tokens?: number; merge_rate: number | null; reviews: number }[];
/** One row per person (however Jira, GitHub or the dashboard named them), Coderhelm's own work, and runs that recorded nobody. */
people: { person: string; kind?: "person" | "coderhelm" | "not_recorded"; runs: number; merged: number }[];
failures: { reason: string; count: number; last_run_id: string; last_at: string }[];
/**
* Failed runs by reason, most first. `stage` is the step most of the group
* failed in and `retried` how many a person retried (older backends leave
* both out).
*/
failures: { reason: string; count: number; last_run_id: string; last_at: string; stage?: string; retried?: number }[];
/** Reasons past the ones listed, summed. Missing from older backends. */
failures_more?: { reasons: number; runs: number };
/** Runs that stopped for a person and still wait, by what for. Missing from older backends. */
waiting?: { total: number; reasons: { reason: string; count: number; last_run_id: string; last_at: string }[] };
ci: {
/** Runs whose own CI went red (runs red only on base-branch checks are counted apart). */
runs_with_red_ci: number;
Expand Down Expand Up @@ -3775,7 +3787,7 @@ export interface Analytics {
steps: { step: string; count: number; tokens_in: number; tokens_out: number; avg_seconds: number }[];
steps_window_days: number;
merged_recent: { run_id: string; title: string; repo: string; pr_number: number; pr_url: string; hours_to_merge: number | null; human_commits: number | null }[];
failed_recent: { run_id: string; title: string; repo: string; reason: string; at: string }[];
failed_recent: { run_id: string; title: string; repo: string; reason: string; at: string; stage?: string; retried?: boolean }[];
repo_names: string[];
/** Absent from servers older than the comparison. */
comparison?: AnalyticsComparison;
Expand Down
Loading