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
57 changes: 46 additions & 11 deletions dashboard/e2e/token-limit-pauses.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,23 @@ function run(over: Partial<Run> = {}): Run {
const LIMIT_LINE = "Paused: this month's token limit is used up (40.3M of 40M). Resumes by itself on Tue, Dec 1, 00:00 UTC when the month turns, or as soon as an admin raises the limit.";
const ROOM_LINE = "Waiting for token room: this month's limit has 1.5M left and a run like this takes about 4M. Starts by itself on Tue, Dec 1, 00:00 UTC when the month turns, or as soon as an admin raises the limit.";

const LIMIT_PAUSE = { kind: "token_limit", limit: "new tokens", used: 40_300_000, max: 40_000_000, resumes_at: RESUMES, line: LIMIT_LINE, settings_path: "/settings/budget" };
const ROOM_PAUSE = { kind: "token_room", limit: "new tokens", used: 38_500_000, max: 40_000_000, room: 1_500_000, need: 4_000_000, resumes_at: RESUMES, line: ROOM_LINE, settings_path: "/settings/budget" };

const RUNS: Record<string, Run> = {
"01RUNPAUSE": run({
waiting_on: {
action: LIMIT_LINE,
detail: "",
pause: { kind: "token_limit", limit: "new tokens", used: 40_300_000, max: 40_000_000, resumes_at: RESUMES, line: LIMIT_LINE, settings_path: "/settings/budget" },
},
waiting_on: { action: LIMIT_LINE, detail: "", pause: LIMIT_PAUSE },
// The runs list and the search carry the pause itself.
pause: LIMIT_PAUSE,
}),
"01RUNROOM": run({
run_id: "01RUNROOM",
title: "Add a reading list export",
ticket_id: "acme/bookstore-web#14",
current_pass: "triage",
pass_history: [{ pass: "triage", started_at: "2026-11-27T15:00:00Z" }],
waiting_on: {
action: ROOM_LINE,
detail: "",
pause: { kind: "token_room", limit: "new tokens", used: 38_500_000, max: 40_000_000, room: 1_500_000, need: 4_000_000, resumes_at: RESUMES, line: ROOM_LINE, settings_path: "/settings/budget" },
},
waiting_on: { action: ROOM_LINE, detail: "", pause: ROOM_PAUSE },
pause: ROOM_PAUSE,
}),
"01RUNPERSON": run({
run_id: "01RUNPERSON",
Expand Down Expand Up @@ -112,7 +110,13 @@ async function mockApi(page: Page, init: Partial<Backend> = {}): Promise<Backend
if (p === "/api/teams") return json(route, { teams: [{ team_id: "t_1", org: "acme", status: "active", current: true }] });
if (p === "/api/repos") return json(route, { repos: [{ name: "acme/bookstore-web", enabled: true, ticket_source: "github" }] });
if (p === "/api/plugins/catalog") return json(route, { plugins: [] });
if (p === "/api/search") return json(route, { q: url.searchParams.get("q"), runs: [], reviews: [], releases: [], plans: [] });
if (p === "/api/search") {
const q = (url.searchParams.get("q") ?? "").toLowerCase();
const runs = Object.values(RUNS)
.filter((r) => String(r.title).toLowerCase().includes(q))
.map((r) => ({ run_id: r.run_id, title: r.title, ticket_id: r.ticket_id, repo: r.repo, status: r.status, created_at: r.created_at, pause: r.pause ?? null }));
return json(route, { q, runs, reviews: [], releases: [], plans: [] });
}
if (p === "/api/runs" && req.method() === "GET") return json(route, { runs: Object.values(RUNS), next: null });
const m = p.match(/^\/api\/runs\/([^/]+)(?:\/(.+))?$/);
if (m) {
Expand Down Expand Up @@ -160,6 +164,12 @@ test.describe("a run held by the token limit", () => {
const link = page.getByTestId("run-pause-settings");
await expect(link).toHaveText("Token limit settings");
await expect(link).toHaveAttribute("href", /\/settings\/budget\/?$/);
// The full sentence is said once, in the box; the last step says only what holds it.
await expect(page.getByText(/Resumes by itself on/)).toHaveCount(1);
const last = page.locator('[data-testid="run-step"][data-pass="end"]');
await expect(last).toContainText("Paused by the token limit");
await expect(last).toContainText("Waiting");
await expect(last).not.toContainText("this month's token limit");
});

test("a run waiting for token room says how much is left and what it needs", async ({ page }) => {
Expand All @@ -184,6 +194,31 @@ test.describe("a run held by the token limit", () => {
});
});

test.describe("a paused run in the runs list and the palette", () => {
test("the runs list says when a paused run resumes, never that it needs an answer", async ({ page }) => {
await mockApi(page, { usage: usage([REACHED]) });
await page.goto("/");
const row = (title: string) => page.getByTestId("run-row").filter({ hasText: title });
await expect(row("Show the gift card balance at checkout")).toContainText(`Paused, resumes ${RESUMES_LOCAL}`);
await expect(row("Show the gift card balance at checkout")).not.toContainText("Needs your answer");
await expect(row("Add a reading list export")).toContainText(`Waiting for token room, starts ${RESUMES_LOCAL}`);
// A run waiting on a person keeps its own words.
await expect(row("Fix the shelf sort order")).not.toContainText("Paused");
});

test("the command palette says the same", async ({ page }) => {
await mockApi(page, { usage: usage([REACHED]) });
await page.goto("/");
await expect(page.getByTestId("run-row").first()).toBeVisible();
await page.keyboard.press("Control+k");
const palette = page.getByRole("dialog", { name: "Search and commands" });
await palette.getByRole("combobox").fill("gift card");
const hit = palette.getByRole("group", { name: "Runs" }).getByRole("option", { name: /Show the gift card balance/ });
await expect(hit).toContainText(`Paused, resumes ${RESUMES_LOCAL}`);
await expect(hit).not.toContainText("Needs your answer");
});
});

test.describe("warning admins before the limit runs out", () => {
test("80%, then 95%: each shows the projected date, dismisses, and stays dismissed that month", async ({ page }) => {
const db = await mockApi(page, { usage: usage([AT_80]) });
Expand Down
14 changes: 7 additions & 7 deletions dashboard/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import { useCan } from "@/hooks/use-can";
import { Suspense, useEffect, useRef, useState } from "react";
import Link from "next/link";
import { api, type CloseResult, type CloseRunRequest, type Run } from "@/lib/api";
import { RUN_GROUP_STATUSES, runCanClose, runStatusLook } from "@/components/run-status";
import { api, type CloseResult, type CloseRunRequest, type Run, type RunListItem } from "@/lib/api";
import { RUN_GROUP_STATUSES, runCanClose, runListLook } from "@/components/run-status";
import { runHref } from "@/lib/plugins";
import { CloseRunDialog } from "@/components/close-run-dialog";
import { useToast } from "@/components/toast";
Expand Down Expand Up @@ -46,15 +46,15 @@ const TAB_TONE = { active: "live", waiting: "waiting", done: "success", failed:

interface RunGroup {
ticket_id: string;
attempts: Run[]; // newest first
attempts: RunListItem[]; // newest first
}

function runTitle(run: Run): string {
return run.title || run.ticket_id || "Untitled run";
}

/** One row per ticket: its newest attempt, with older ones inside. */
function groupRunsByTicket(runs: Run[]): RunGroup[] {
function groupRunsByTicket(runs: RunListItem[]): RunGroup[] {
const map = new Map<string, Run[]>();
for (const run of runs) {
// Each plugin run is its own row (they share a ticket id per plugin).
Expand Down Expand Up @@ -91,7 +91,7 @@ function RunsPage() {
const filtered = !!(q || status || repo || startedBy);
const clear = () => setParams({ q: "", status: "all", repo: "", started_by: "" });

const { items: runs, next, loading, loadingMore, error, moreFailed, loadMore, reload } = usePagedList<Run>(
const { items: runs, next, loading, loadingMore, error, moreFailed, loadMore, reload } = usePagedList<RunListItem>(
(cursor) => api.listRuns(cursor, { q, status, repo, started_by: startedBy || undefined }).then((d) => ({ items: d.runs, next: d.next })),
[q, status, repo, startedBy],
);
Expand Down Expand Up @@ -359,7 +359,7 @@ function ticketWords(run: Run, showRepo: boolean): string | null {

function RunItem({ group, showRepo, select, spacer }: { group: RunGroup; showRepo: boolean; select?: RowSelect; spacer?: boolean }) {
const [latest, ...earlier] = group.attempts;
const look = runStatusLook(latest.status);
const look = runListLook(latest.status, latest.pause);
const title = runTitle(latest);
const ticket = ticketWords(latest, showRepo);
const isPlugin = latest.ticket_source === "plugin";
Expand Down Expand Up @@ -412,7 +412,7 @@ function RunItem({ group, showRepo, select, spacer }: { group: RunGroup; showRep
>
{runTitle(run)}
</Link>
<StatusText look={runStatusLook(run.status)} />
<StatusText look={runListLook(run.status, run.pause)} />
<Time iso={run.created_at} className="text-zinc-400" />
{run.duration_s ? <span className="text-zinc-400">took {formatDuration(run.duration_s)}</span> : null}
</li>
Expand Down
4 changes: 2 additions & 2 deletions dashboard/src/components/command-palette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { api, ApiError, type SearchResults } from "@/lib/api";
import { kindLabel, whereLabel } from "@/lib/data-sources";
import { pageHref, skillsApi } from "@/lib/skills";
import { helpHref, helpTargetFromUrl } from "@/lib/support";
import { runStatusLabel } from "./run-status";
import { runListLook } from "./run-status";
import { timeAgo } from "./list/time";
import { focusRing } from "./ui";

Expand Down Expand Up @@ -399,7 +399,7 @@ function serverEntries(r: SearchResults): Entry[] {
id: `run:${x.run_id}`,
group: "runs",
label: x.title || x.ticket_id || "Untitled run",
sub: [x.ticket_id && x.ticket_id !== x.title ? x.ticket_id : "", x.repo, runStatusLabel(x.status), timeAgo(x.created_at)].filter(Boolean).join(" · "),
sub: [x.ticket_id && x.ticket_id !== x.title ? x.ticket_id : "", x.repo, runListLook(x.status, x.pause).label, timeAgo(x.created_at)].filter(Boolean).join(" · "),
href: `/runs/detail?id=${encodeURIComponent(x.run_id)}`,
})),
...r.reviews.map<Entry>((x) => ({
Expand Down
14 changes: 14 additions & 0 deletions dashboard/src/components/run-status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// which colour it is (the shared tones in ./list/status) or which group it
// belongs to.

import type { RunPause } from "@/lib/api";
import { formatWhenLocal } from "@/lib/usage";
import { StatusDot, TONES, statusWords, type StatusGroup, type StatusLook } from "./list/status";

type RunLook = StatusLook & { group?: StatusGroup };
Expand Down Expand Up @@ -99,6 +101,18 @@ const PAUSED: Record<"token_limit" | "token_room", RunLook> = {
token_room: { label: "Waiting for token room", tone: "info", group: "waiting" },
};

/**
* A run's look in a list (the runs list, the command palette): a run held by
* the token limit reads "Paused, resumes <when, in the viewer's zone>", never
* "Needs your answer".
*/
export function runListLook(status: string | null | undefined, pause?: RunPause | null): RunLook {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 FYI: A parallel structure next to an existing one (scope, not verified)

dashboard/src/components/run-status.tsx adds runListLook next to the existing runStatusLook. Extend the existing one (add the entries or the parameter there) and remove the new one. If the ticket truly needs it, say why on a line Wider than the ticket: dashboard/src/components/run-status.tsx: <why>.

FYI, not a block: on the whole picture this is not a named correctness, security or data-loss problem to hold the merge on.

const paused = runPauseLook(status, pause?.kind);
if (!paused || !pause) return runStatusLook(status);
const when = formatWhenLocal(pause.resumes_at);
return { ...paused, label: pause.kind === "token_room" ? `Waiting for token room, starts ${when}` : `Paused, resumes ${when}` };
}

/** The look of a run held by the token limit, or null when it isn't. */
export function runPauseLook(status: string | null | undefined, pauseKind: string | null | undefined): RunLook | null {
if (status !== "needs_input") return null;
Expand Down
4 changes: 2 additions & 2 deletions dashboard/src/lib/api-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Nothing here runs; it is checked by the compiler only.

import type { OpenApiFields } from "./openapi-fields";
import type { ActivityGroup, ActivityItem, AnswerRunResult, OverviewFile, Plan, Review, ReviewOverview, ReviewSession, Run, RunAnswer, RunCheck, RunChecks, RunPrReview, RunDetail, RunDraftHold, RunDraftHoldReason, RunMergeStanding, RunPreview, RunPreviewCheck, RunPreviewShot, RunQuestion, RunTrigger, SessionStep, Task, api } from "./api";
import type { ActivityGroup, ActivityItem, AnswerRunResult, OverviewFile, Plan, Review, ReviewOverview, ReviewSession, Run, RunAnswer, RunListItem, RunCheck, RunChecks, RunPrReview, RunDetail, RunDraftHold, RunDraftHoldReason, RunMergeStanding, RunPreview, RunPreviewCheck, RunPreviewShot, RunQuestion, RunTrigger, SessionStep, Task, api } from "./api";

type Answer<K extends keyof typeof api> = Awaited<ReturnType<(typeof api)[K]>>;

Expand All @@ -18,7 +18,7 @@ type None<T extends never> = T;

// The runs list and one run (the run detail page).
export type RunsPageContract = None<Undocumented<Answer<"listRuns">, "RunsPage">>;
export type RunListContract = None<Undocumented<Run, "RunSummary">>;
export type RunListContract = None<Undocumented<RunListItem, "RunSummary">>;
export type RunContract = None<Undocumented<RunDetail, "Run">>;
// The checks on a run's pull request, and the reviewer's verdict on it.
export type RunChecksContract = None<Undocumented<RunChecks, "RunChecks">>;
Expand Down
10 changes: 8 additions & 2 deletions dashboard/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ export const api = {
* can be short or empty while `next` is still set.
*/
listRuns: (cursor?: string, filters: { q?: string; status?: string; repo?: string; started_by?: string } = {}) =>
request<{ runs: Run[]; next?: string | null }>(
request<{ runs: RunListItem[]; next?: string | null }>(
`/api/runs${qs({ cursor, q: filters.q, status: filters.status, repo: filters.repo, started_by: filters.started_by })}`,
),
/**
Expand Down Expand Up @@ -2462,6 +2462,12 @@ export interface Run {
trigger?: RunTrigger;
}

/** A run as the runs list returns it (`RunSummary`). */
export interface RunListItem extends Run {
/** Held by the team's monthly token limit: shown as paused, never as waiting on a person. Older backends leave it out. */
pause?: RunPause | null;
}

/** What started a run, as the runs list filters it. */
export type RunTriggerKind = "jira" | "github" | "coderhelm" | "alert" | "plan" | "dashboard" | "chat";

Expand Down Expand Up @@ -3004,7 +3010,7 @@ export interface AgentLog {

export interface SearchResults {
q: string;
runs: { run_id: string; title: string; ticket_id: string; repo: string; status: string; created_at: string }[];
runs: { run_id: string; title: string; ticket_id: string; repo: string; status: string; created_at: string; pause?: RunPause | null }[];
reviews: { sk: string; repo: string; pr_number: number; title: string; verdict: string; created_at: string }[];
releases: { repo: string; tag: string; headline: string; updated_at: string }[];
plans: { plan_id: string; title: string; repo: string; status: string; created_at: string }[];
Expand Down
12 changes: 7 additions & 5 deletions dashboard/src/lib/openapi-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// docs/api/openapi.json. Do not edit; run `npm run openapi:fields` instead.

/** The platform commit this was generated from. */
export const OPENAPI_REF = "4cf19f559b9e6e71206d42a6c5c6d02d2985dd57";
export const OPENAPI_REF = "c0206416f191a0c9bde29d3a6bb87622dd13a77a";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 FYI: Generated from an unmerged platform commit (question)

OPENAPI_REF points at the head of the open platform pull request. The regeneration also pulled in unrelated fields (own_review, RunOwnReview, UsageLimit.projected_at and warn_level). If that branch is squashed or force-pushed, the ref may stop resolving. It is worth checking that npm run openapi:fields is rerun against the merged platform commit once the paired pull request lands.


/** The fields each public API schema has. */
export interface OpenApiFields {
Expand Down Expand Up @@ -66,7 +66,7 @@ export interface OpenApiFields {
RotateBody: "overlap_hours";
RotatedSecret: "previous_secret_expires_at" | "secret";
RoundIncomplete: "at" | "can_resume" | "files" | "kind" | "number" | "pushed" | "reason" | "summary" | "wip_branch";
Run: "answers" | "answers_url" | "applied_standards" | "branch" | "branches" | "cache_read_tokens" | "cache_write_tokens" | "checks" | "close_reason" | "closed_at" | "closed_by" | "closed_from" | "codegen_env_missing" | "continued_run_id" | "cost_usd" | "covered_by" | "created_at" | "current_pass" | "draft_hold" | "duration_s" | "error" | "exploration" | "files_modified" | "fix_location" | "github_wait" | "lesson" | "mcp_servers" | "merge_standing" | "no_change" | "outside_change_report" | "pass_history" | "policy_approval" | "policy_note" | "pr_number" | "pr_numbers" | "pr_review" | "pr_review_comments" | "pr_url" | "pr_urls" | "preview" | "progress_notes" | "prs" | "questions" | "questions_url" | "repo" | "round_incomplete" | "run_id" | "sign_in_prompts" | "status" | "stop_kind" | "ticket_id" | "ticket_source" | "title" | "tokens_in" | "tokens_out" | "tooling_failure" | "traceability" | "trigger" | "updated_at" | "waiting_line" | "waiting_on";
Run: "answers" | "answers_url" | "applied_standards" | "branch" | "branches" | "cache_read_tokens" | "cache_write_tokens" | "checks" | "close_reason" | "closed_at" | "closed_by" | "closed_from" | "codegen_env_missing" | "continued_run_id" | "cost_usd" | "covered_by" | "created_at" | "current_pass" | "draft_hold" | "duration_s" | "error" | "exploration" | "files_modified" | "fix_location" | "github_wait" | "lesson" | "mcp_servers" | "merge_standing" | "no_change" | "outside_change_report" | "own_review" | "pass_history" | "policy_approval" | "policy_note" | "pr_number" | "pr_numbers" | "pr_review" | "pr_review_comments" | "pr_url" | "pr_urls" | "preview" | "progress_notes" | "prs" | "questions" | "questions_url" | "repo" | "round_incomplete" | "run_id" | "sign_in_prompts" | "status" | "stop_kind" | "ticket_id" | "ticket_source" | "title" | "tokens_in" | "tokens_out" | "tooling_failure" | "traceability" | "trigger" | "updated_at" | "waiting_line" | "waiting_on";
RunActionResult: "status";
RunAnswer: "answer" | "answered_at" | "author" | "question" | "question_id";
RunCheck: "completed_at" | "conclusion" | "name" | "required" | "started_at" | "state" | "url";
Expand All @@ -83,21 +83,23 @@ export interface OpenApiFields {
RunNoChange: "checks" | "open_pr" | "reason";
RunNoChangePr: "closed" | "line" | "number" | "repo" | "title" | "url" | "verdict" | "why";
RunNote: "message" | "timestamp";
RunOwnReview: "for_a_person" | "noted" | "open" | "open_findings" | "rounds";
RunPass: "pass" | "started_at";
RunPause: "kind" | "limit" | "line" | "max" | "need" | "resumes_at" | "room" | "settings_path" | "used";
RunPrReview: "at" | "review_sk" | "reviewed_sha" | "session_id" | "verdict";
RunPreview: "checks" | "e2e_covered" | "e2e_required" | "labels_added" | "shots" | "stage" | "url" | "why";
RunPreviewCheck: "name" | "outcome" | "url";
RunPreviewShot: "page" | "src" | "width";
RunQuestion: "decision" | "evidence" | "id" | "question" | "suggestions" | "why";
RunSummary: "cost_usd" | "created_at" | "current_pass" | "duration_s" | "pr_number" | "pr_url" | "repo" | "run_id" | "status" | "ticket_id" | "ticket_source" | "title" | "tokens_in" | "tokens_out" | "trigger";
RunSummary: "cost_usd" | "created_at" | "current_pass" | "duration_s" | "pause" | "pr_number" | "pr_url" | "repo" | "run_id" | "status" | "ticket_id" | "ticket_source" | "title" | "tokens_in" | "tokens_out" | "trigger";
RunSupersededPr: "closed" | "closed_by" | "number" | "repo" | "title" | "url";
RunToolingFailure: "command" | "error" | "tried";
RunTrace: "head" | "rows";
RunTraceCode: "path" | "symbols";
RunTraceProof: "by" | "detail" | "state";
RunTraceRow: "code" | "criterion" | "page" | "proof" | "source" | "tests";
RunTrigger: "by" | "kind" | "label" | "ref" | "ref_url";
RunWaitingOn: "action" | "detail" | "since" | "url";
RunWaitingOn: "action" | "detail" | "pause" | "since" | "url";
RunsPage: "next" | "runs" | "scanned";
SecretView: "previous_secret_expires_at" | "secret";
SessionStep: "at" | "detail" | "text";
Expand All @@ -110,7 +112,7 @@ export interface OpenApiFields {
UpdateEndpointBody: "description" | "enabled" | "events" | "url";
Usage: "cache_hit_rate" | "cache_read_tokens" | "cache_write_tokens" | "counted_tokens" | "features" | "limit_counts_cache" | "limits" | "limits_legacy" | "max_tokens" | "models" | "month" | "new_tokens" | "tokens_in" | "tokens_out" | "total_runs" | "total_tokens";
UsageFeature: "cache_read_tokens" | "cache_write_tokens" | "feature" | "tokens_in" | "tokens_out" | "total_tokens";
UsageLimit: "kind" | "max" | "used";
UsageLimit: "kind" | "max" | "projected_at" | "used" | "warn_level";
UsageModel: "cache_hit_rate" | "cache_read_tokens" | "cache_write_tokens" | "calls" | "model" | "tokens_in" | "tokens_out" | "total_tokens";
WebhookDelivery: "attempts" | "created_at" | "event" | "event_id" | "headers" | "id" | "next_retry_at" | "outcome" | "payload_preview" | "reason" | "reason_fix" | "reason_message" | "status";
WebhookEndpoint: "created_at" | "created_by" | "description" | "disabled_reason" | "enabled" | "events" | "failing_since" | "id" | "last_failure_at" | "last_success_at" | "previous_secret_expires_at" | "secret_hint" | "updated_at" | "url";
Expand Down
Loading
Loading