From a032cb6fbbc67c01e3f4e1fdd670e198611aed1a Mon Sep 17 00:00:00 2001 From: Nam Rodriguez Date: Tue, 27 Oct 2026 11:53:14 -0400 Subject: [PATCH 1/3] Run page: an open PR whose last fix round didn't finish says so, with Resume When the gateway reports round_incomplete on a finished run, the run page shows "Pull request open; the last fix round didn't finish", why, and the commits the round pushed, with a Resume button that calls the run's retry path (the gateway resumes the round on the same run). The header badge reads "PR open, fix unfinished" instead of Done. Viewers see the state without the button. openapi-fields regenerated from CoderHelm/coderhelm-platform@ce18d85 (Run.round_incomplete, RoundIncomplete, PushedCommit). New e2e spec with 1440 and 390 screenshots. --- dashboard/e2e/round-incomplete.spec.ts | 110 ++++++++++++++++++++++++ dashboard/src/app/runs/detail/page.tsx | 48 ++++++++++- dashboard/src/components/run-status.tsx | 7 +- dashboard/src/lib/api.ts | 19 ++++ 4 files changed, 180 insertions(+), 4 deletions(-) create mode 100644 dashboard/e2e/round-incomplete.spec.ts diff --git a/dashboard/e2e/round-incomplete.spec.ts b/dashboard/e2e/round-incomplete.spec.ts new file mode 100644 index 00000000..dfa66e7d --- /dev/null +++ b/dashboard/e2e/round-incomplete.spec.ts @@ -0,0 +1,110 @@ +import { expect, test, type Page, type Route } from "@playwright/test"; +import fs from "node:fs"; +import path from "node:path"; + +// A run whose pull request is open while its last fix round didn't finish: +// the run page says so plainly (never "failed") and offers Resume, which calls +// the run's retry path. Every API call is answered here. + +const SHOTS_DIR = process.env.E2E_SHOTS_DIR || path.join("test-results", "shots"); + +const now = Date.now(); +const iso = (minsAgo: number) => new Date(now - minsAgo * 60_000).toISOString(); + +const RUN = { + run_id: "01RUNR", + status: "completed", + ticket_source: "jira", + ticket_id: "ABC-7", + title: "Add the gallery block", + repo: "your-team/web", + branch: "abc-7-gallery-block", + pr_url: "https://github.com/your-team/web/pull/41", + pr_number: 41, + cost_usd: 4.2, + tokens_in: 1000, + tokens_out: 1000, + duration_s: 2400, + current_pass: "done", + created_at: iso(120), + updated_at: iso(5), + pass_history: [], + progress_notes: [], + round_incomplete: { + kind: "review_fix", + number: 3, + reason: "the review fix round ran out of its time budget 3 times in a row", + summary: "Pull request open; the last fix round didn't finish: the review fix round ran out of its time budget 3 times in a row.", + pushed: [ + { sha: "4f2a9c1e7b3d", message: "ABC-7: Add the gallery tabs" }, + { sha: "9b0c4d2a1e6f", message: "ABC-7: Add the tab tests" }, + ], + files: ["src/blocks/gallery/tabs.tsx", "src/blocks/gallery/tabs.test.tsx"], + at: iso(5), + can_resume: true, + }, +}; + +async function mockApi(page: Page, role = "member") { + const calls: string[] = []; + const json = (route: Route, body: unknown, status = 200) => + route.fulfill({ status, contentType: "application/json", body: JSON.stringify(body) }); + await page.route((url) => url.hostname !== "localhost", (route) => route.abort()); + await page.route((url) => url.hostname === "localhost" && /^\/(api|auth)\//.test(url.pathname), async (route) => { + const req = route.request(); + const p = new URL(req.url()).pathname; + calls.push(`${req.method()} ${p}`); + if (p === "/api/me") return json(route, { user_id: "u_1", team_id: "t_1", github_login: "sam", email: "sam@example.com", avatar_url: "", role }); + if (p === "/api/usage") return json(route, { month: "2026-01", total_tokens: 0, tokens_in: 0, tokens_out: 0, total_runs: 0, max_tokens: 0 }); + if (p === "/api/banners") return json(route, { banners: [] }); + if (p === "/api/teams") return json(route, { teams: [{ team_id: "t_1", org: "your-team", status: "active", current: true }] }); + if (p === "/api/repos") return json(route, { repos: [{ name: "your-team/web", enabled: true, ticket_source: "jira" }] }); + if (p === "/api/plugins/catalog") return json(route, { plugins: [] }); + if (p === "/api/runs/01RUNR") return json(route, RUN); + if (p === "/api/runs/01RUNR/retry" && req.method() === "POST") return json(route, { status: "resuming" }); + if (p === "/api/runs/01RUNR/openspec") return json(route, {}); + if (p === "/api/runs/01RUNR/traces") return json(route, { traces: [] }); + if (p === "/api/runs/01RUNR/agent-log") return json(route, { passes: [], live_events: [] }); + if (p === "/api/runs/01RUNR/asks") return json(route, { asks: [] }); + return json(route, { error: `Not mocked: ${p}` }, 404); + }); + return calls; +} + +async function shot(page: Page, name: string) { + fs.mkdirSync(SHOTS_DIR, { recursive: true }); + await page.screenshot({ path: path.join(SHOTS_DIR, `${name}.png`), fullPage: true }); +} + +for (const [label, width, height] of [ + ["desktop", 1440, 900], + ["phone", 390, 844], +] as const) { + test(`an open PR whose last fix round stopped reads plainly and resumes (${label})`, async ({ page }) => { + await page.setViewportSize({ width, height }); + const calls = await mockApi(page); + await page.goto("/runs/detail?id=01RUNR"); + const outcome = page.getByTestId("run-outcome"); + await expect(outcome).toContainText("Pull request open; the last fix round didn't finish"); + await expect(outcome).toContainText("The review fix round ran out of its time budget 3 times in a row."); + await expect(page.getByTestId("round-incomplete")).toContainText("It pushed 2 commits to the pull request first (4f2a9c1, 9b0c4d2)"); + await expect(outcome).not.toContainText(/failed/i); + await expect(page.getByText("PR open, fix unfinished")).toBeVisible(); + await expect(outcome.getByRole("link", { name: /Open pull request #41/ })).toBeVisible(); + const overflow = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth); + expect(overflow).toBeLessThanOrEqual(0); + await shot(page, `round-incomplete-${width}`); + + await page.getByTestId("resume-round").click(); + await expect(page.getByText("Resuming the fix round on the same pull request")).toBeVisible(); + expect(calls).toContain("POST /api/runs/01RUNR/retry"); + await expect(page.getByTestId("round-incomplete")).toHaveCount(0); + }); +} + +test("a viewer sees the state but no Resume", async ({ page }) => { + await mockApi(page, "viewer"); + await page.goto("/runs/detail?id=01RUNR"); + await expect(page.getByTestId("round-incomplete")).toContainText("Ask someone with member access to resume it."); + await expect(page.getByTestId("resume-round")).toHaveCount(0); +}); diff --git a/dashboard/src/app/runs/detail/page.tsx b/dashboard/src/app/runs/detail/page.tsx index 454cc062..aa70c02e 100644 --- a/dashboard/src/app/runs/detail/page.tsx +++ b/dashboard/src/app/runs/detail/page.tsx @@ -520,6 +520,22 @@ function RunDetailInner() { const openPrs = run.pr_number && run.status !== "merged" ? [...new Set([run.pr_number, ...(run.pr_numbers ?? [])])] : []; const limitTitle = limitHit ? `The monthly ${limitName(limitHit.kind)} limit is reached` : undefined; + // The pull request is open but its last fix round didn't finish: Retry + // resumes that round on the same run (the gateway's retry path). + const unfinished = run.round_incomplete ?? null; + const canResume = !!unfinished?.can_resume; + const resumeRound = async () => { + setBusy("retry"); + try { + await api.retryRun(runId); + setRun((r) => (r ? { ...r, status: "awaiting_ci", round_incomplete: null } : r)); + toast("Resuming the fix round on the same pull request"); + } catch (e) { + toast(actionError(e, "resume this fix round"), "error"); + } finally { + setBusy(null); + } + }; const retry = async () => { setBusy("retry"); try { @@ -654,7 +670,35 @@ function RunDetailInner() { ); let outcome: React.ReactNode; - if (run.status === "failed") { + if (done && unfinished) { + outcome = ( + + {canAct && canResume && ( + + )} + {openPrButtons("secondary")} + + } + > +
+

{unfinished.reason ? `${unfinished.reason.charAt(0).toUpperCase()}${unfinished.reason.slice(1)}.` : "It stopped before it finished."}

+

+ {unfinished.pushed.length + ? `It pushed ${unfinished.pushed.length} commit${unfinished.pushed.length === 1 ? "" : "s"} to the pull request first (${unfinished.pushed.map((p) => p.sha.slice(0, 7)).join(", ")}). Nothing it wrote was lost.` + : "It pushed no commits before it stopped."}{" "} + {canAct && canResume ? "Resume runs the round again on the same pull request with a fresh time budget." : "Ask someone with member access to resume it."} +

+
+
+ ); + } else if (run.status === "failed") { outcome = ( } + status={} lead={ {run.repo || "Choosing a repository…"} diff --git a/dashboard/src/components/run-status.tsx b/dashboard/src/components/run-status.tsx index 2f2404ba..e653a247 100644 --- a/dashboard/src/components/run-status.tsx +++ b/dashboard/src/components/run-status.tsx @@ -65,8 +65,11 @@ export function runIsLive(status: string | null | undefined): boolean { return !!status && !!LOOKS[status]?.live; } -export function RunStatusBadge({ status }: { status: string | null | undefined }) { - const look = runStatusLook(status); +/** A finished run whose pull request is open while its last fix round didn't finish. */ +const UNFINISHED_ROUND: RunLook = { label: "PR open, fix unfinished", tone: "attention", group: "done" }; + +export function RunStatusBadge({ status, unfinishedRound }: { status: string | null | undefined; unfinishedRound?: boolean }) { + const look = unfinishedRound ? UNFINISHED_ROUND : runStatusLook(status); return ( diff --git a/dashboard/src/lib/api.ts b/dashboard/src/lib/api.ts index 6cc27ef9..39e85f43 100644 --- a/dashboard/src/lib/api.ts +++ b/dashboard/src/lib/api.ts @@ -1838,6 +1838,23 @@ export interface BulkCloseAnswer { failed: number; } +/** The last fix round on a run's open pull request that didn't finish. */ +export interface RoundIncomplete { + /** `ci_fix`, `review_fix` or `feedback`. */ + kind?: string | null; + number: number; + /** Why it stopped, in plain words. */ + reason: string; + /** "Pull request open; the last fix round didn't finish: …" */ + summary: string; + /** Commits it pushed before it stopped, oldest first. */ + pushed: { sha: string; message: string }[]; + files: string[]; + at: string; + /** Retry resumes the round on the same pull request. */ + can_resume: boolean; +} + export interface RunDetail extends Run { /** Why an agent loop stopped (agents paused, an approval nobody answered). */ policy_note?: string | null; @@ -1860,6 +1877,8 @@ export interface RunDetail extends Run { /** Team standards the run's passes were given in full ("Always apply"). */ applied_standards?: string[]; progress_notes?: { message: string; timestamp: string }[]; + /** Set when the pull request is open but the last fix round on it didn't finish. */ + round_incomplete?: RoundIncomplete | null; /** Where the planner decided the fix belongs: code, outside_code, both or unknown. */ fix_location?: string | null; /** Markdown report when the fix is (partly) a change outside the code. */ From c30ffd83452f97c14cadaf8e4d314f7bc9486fd3 Mon Sep 17 00:00:00 2001 From: Nam Rodriguez Date: Tue, 27 Oct 2026 13:17:34 -0400 Subject: [PATCH 2/3] Codegen environment settings; runs name missing codegen values; WIP wording - Settings, Repositories: each repository links to its Codegen environment (admins only): the public values its code generators read in the sandbox, with a warning never to put secrets there (the gateway refuses names and values that look like credentials, and the page shows why). - A run stopped because a generator needed public values the repository doesn't set names them, says where to set them, and links there with the names pre-filled; Retry after. - The unfinished-round card says the pull request is unchanged and where the round's work is saved (its coderhelm-wip branch), and that Resume lands it as one commit. openapi-fields regenerated from CoderHelm/coderhelm-platform@123a42c (Run.codegen_env_missing, RoundIncomplete.wip_branch). New e2e spec codegen-env.spec.ts with 1440 and 390 screenshots. --- dashboard/e2e/codegen-env.spec.ts | 130 ++++++++++++++ dashboard/e2e/round-incomplete.spec.ts | 3 +- dashboard/src/app/runs/detail/page.tsx | 49 ++++- .../src/app/settings/repos/codegen/page.tsx | 169 ++++++++++++++++++ dashboard/src/app/settings/repos/page.tsx | 9 + dashboard/src/lib/api.ts | 28 ++- dashboard/src/lib/routes.ts | 1 + 7 files changed, 383 insertions(+), 6 deletions(-) create mode 100644 dashboard/e2e/codegen-env.spec.ts create mode 100644 dashboard/src/app/settings/repos/codegen/page.tsx diff --git a/dashboard/e2e/codegen-env.spec.ts b/dashboard/e2e/codegen-env.spec.ts new file mode 100644 index 00000000..3054f233 --- /dev/null +++ b/dashboard/e2e/codegen-env.spec.ts @@ -0,0 +1,130 @@ +import { expect, test, type Page, type Route } from "@playwright/test"; +import fs from "node:fs"; +import path from "node:path"; + +// A run that stopped before its pull request because a code generator needed +// public values the repository doesn't set: the run page names them and links +// to the repository's codegen environment, where an admin sets public values +// (secrets are refused). Every API call is answered here. + +const SHOTS_DIR = process.env.E2E_SHOTS_DIR || path.join("test-results", "shots"); +const now = Date.now(); +const iso = (minsAgo: number) => new Date(now - minsAgo * 60_000).toISOString(); + +const RUN = { + run_id: "01RUNG", + status: "failed", + ticket_source: "jira", + ticket_id: "ABC-8", + title: "Add the hero block", + repo: "your-team/web", + branch: "abc-8-hero-block", + cost_usd: 1, + tokens_in: 10, + tokens_out: 10, + duration_s: 600, + current_pass: "review", + created_at: iso(30), + updated_at: iso(2), + error: + "Stopped before opening a pull request: regenerating the generated files failed because `pnpm run typegen` needs public values the sandbox doesn't have.", + pass_history: [], + progress_notes: [], + codegen_env_missing: { + repo: "your-team/web", + command: "pnpm run typegen", + vars: ["SANITY_STUDIO_DATASET", "SANITY_STUDIO_PROJECT_ID"], + }, +}; + +async function mockApi(page: Page, role = "admin") { + const puts: unknown[] = []; + const json = (route: Route, body: unknown, status = 200) => + route.fulfill({ status, contentType: "application/json", body: JSON.stringify(body) }); + await page.route((url) => url.hostname !== "localhost", (route) => route.abort()); + await page.route((url) => url.hostname === "localhost" && /^\/(api|auth)\//.test(url.pathname), async (route) => { + const req = route.request(); + const p = new URL(req.url()).pathname; + if (p === "/api/me") return json(route, { user_id: "u_1", team_id: "t_1", github_login: "sam", email: "sam@example.com", avatar_url: "", role }); + if (p === "/api/usage") return json(route, { month: "2026-01", total_tokens: 0, tokens_in: 0, tokens_out: 0, total_runs: 0, max_tokens: 0 }); + if (p === "/api/banners") return json(route, { banners: [] }); + if (p === "/api/teams") return json(route, { teams: [{ team_id: "t_1", org: "your-team", status: "active", current: true }] }); + if (p === "/api/repos") return json(route, { repos: [{ name: "your-team/web", enabled: true, onboard_status: "ready" }] }); + if (p === "/api/plugins/catalog") return json(route, { plugins: [] }); + if (p === "/api/runs/01RUNG") return json(route, RUN); + if (/^\/api\/runs\/01RUNG\//.test(p)) return json(route, p.endsWith("traces") ? { traces: [] } : p.endsWith("agent-log") ? { passes: [], live_events: [] } : p.endsWith("asks") ? { asks: [] } : {}); + if (p === "/api/repos/your-team/web/codegen-env" && req.method() === "GET") return json(route, { repo: "your-team/web", vars: [{ name: "SANITY_STUDIO_DATASET", value: "production" }] }); + if (p === "/api/repos/your-team/web/codegen-env" && req.method() === "PUT") { + const body = JSON.parse(req.postData() ?? "{}"); + puts.push(body); + const bad = (body.vars as { name: string }[]).find((v) => /TOKEN|SECRET|PASSWORD/.test(v.name)); + if (bad) return json(route, { error: `\`${bad.name}\` looks like a secret. Only public values (ones that already ship to the browser) belong here.` }, 400); + return json(route, { repo: "your-team/web", count: body.vars.length }); + } + return json(route, { error: `Not mocked: ${p}` }, 404); + }); + return puts; +} + +async function shot(page: Page, name: string) { + fs.mkdirSync(SHOTS_DIR, { recursive: true }); + await page.screenshot({ path: path.join(SHOTS_DIR, `${name}.png`), fullPage: true }); +} + +for (const [label, width, height] of [ + ["desktop", 1440, 900], + ["phone", 390, 844], +] as const) { + test(`a run stopped for missing codegen values names them and links to where they're set (${label})`, async ({ page }) => { + await page.setViewportSize({ width, height }); + const puts = await mockApi(page); + await page.goto("/runs/detail?id=01RUNG"); + const box = page.getByTestId("codegen-env-missing"); + await expect(box).toContainText("SANITY_STUDIO_PROJECT_ID"); + await expect(box).toContainText("SANITY_STUDIO_DATASET"); + await expect(box).toContainText("Codegen environment"); + const overflow = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth); + expect(overflow).toBeLessThanOrEqual(0); + await shot(page, `codegen-env-run-${width}`); + + await page.getByTestId("codegen-env-link").click(); + await expect(page).toHaveURL(/\/settings\/repos\/codegen\/?\?repo=your-team%2Fweb&need=/); + await expect(page.getByTestId("codegen-env-warning")).toContainText("Never put tokens"); + // The one already set is kept; the one the run asked for is pre-filled. + const names = page.getByRole("textbox", { name: "Name" }); + await expect(names).toHaveCount(2); + await expect(names.nth(1)).toHaveValue("SANITY_STUDIO_PROJECT_ID"); + await page.getByRole("textbox", { name: "Value" }).nth(1).fill("abc123xy"); + await shot(page, `codegen-env-settings-${width}`); + await page.getByRole("button", { name: "Save" }).click(); + await expect(page.getByText("Saved. The next run uses these values.")).toBeVisible(); + expect(puts.at(-1)).toEqual({ + vars: [ + { name: "SANITY_STUDIO_DATASET", value: "production" }, + { name: "SANITY_STUDIO_PROJECT_ID", value: "abc123xy" }, + ], + }); + }); +} + +test("a secret is refused with the reason", async ({ page }) => { + await mockApi(page); + await page.goto("/settings/repos/codegen?repo=your-team%2Fweb"); + await page.getByRole("button", { name: "Add a variable" }).click(); + await page.getByRole("textbox", { name: "Name" }).last().fill("sanity_auth_token"); + await page.getByRole("textbox", { name: "Value" }).last().fill("x"); + await page.getByRole("button", { name: "Save" }).click(); + await expect(page.getByTestId("codegen-env-error")).toContainText("looks like a secret"); +}); + +test("the repositories list links each repo to its codegen environment", async ({ page }) => { + await mockApi(page); + await page.goto("/settings/repos"); + await expect(page.getByRole("link", { name: "Codegen environment" })).toHaveAttribute("href", "/settings/repos/codegen?repo=your-team%2Fweb"); +}); + +test("members don't get the settings page", async ({ page }) => { + await mockApi(page, "member"); + await page.goto("/settings/repos/codegen?repo=your-team%2Fweb"); + await expect(page.getByTestId("codegen-env-form")).toHaveCount(0); +}); diff --git a/dashboard/e2e/round-incomplete.spec.ts b/dashboard/e2e/round-incomplete.spec.ts index dfa66e7d..8a7e018a 100644 --- a/dashboard/e2e/round-incomplete.spec.ts +++ b/dashboard/e2e/round-incomplete.spec.ts @@ -40,6 +40,7 @@ const RUN = { { sha: "9b0c4d2a1e6f", message: "ABC-7: Add the tab tests" }, ], files: ["src/blocks/gallery/tabs.tsx", "src/blocks/gallery/tabs.test.tsx"], + wip_branch: "coderhelm-wip/abc-7-gallery-block", at: iso(5), can_resume: true, }, @@ -87,7 +88,7 @@ for (const [label, width, height] of [ const outcome = page.getByTestId("run-outcome"); await expect(outcome).toContainText("Pull request open; the last fix round didn't finish"); await expect(outcome).toContainText("The review fix round ran out of its time budget 3 times in a row."); - await expect(page.getByTestId("round-incomplete")).toContainText("It pushed 2 commits to the pull request first (4f2a9c1, 9b0c4d2)"); + await expect(page.getByTestId("round-incomplete")).toContainText("The pull request is unchanged. Its work so far (2 checkpoint commits) is saved on branch coderhelm-wip/abc-7-gallery-block."); await expect(outcome).not.toContainText(/failed/i); await expect(page.getByText("PR open, fix unfinished")).toBeVisible(); await expect(outcome.getByRole("link", { name: /Open pull request #41/ })).toBeVisible(); diff --git a/dashboard/src/app/runs/detail/page.tsx b/dashboard/src/app/runs/detail/page.tsx index aa70c02e..6ea145d4 100644 --- a/dashboard/src/app/runs/detail/page.tsx +++ b/dashboard/src/app/runs/detail/page.tsx @@ -690,10 +690,51 @@ function RunDetailInner() {

{unfinished.reason ? `${unfinished.reason.charAt(0).toUpperCase()}${unfinished.reason.slice(1)}.` : "It stopped before it finished."}

- {unfinished.pushed.length - ? `It pushed ${unfinished.pushed.length} commit${unfinished.pushed.length === 1 ? "" : "s"} to the pull request first (${unfinished.pushed.map((p) => p.sha.slice(0, 7)).join(", ")}). Nothing it wrote was lost.` - : "It pushed no commits before it stopped."}{" "} - {canAct && canResume ? "Resume runs the round again on the same pull request with a fresh time budget." : "Ask someone with member access to resume it."} + {unfinished.pushed.length && unfinished.wip_branch + ? `The pull request is unchanged. Its work so far (${unfinished.pushed.length} checkpoint commit${unfinished.pushed.length === 1 ? "" : "s"}) is saved on branch ${unfinished.wip_branch}.` + : "The pull request is unchanged; the round saved no work before it stopped."}{" "} + {canAct && canResume ? "Resume continues the round from there with a fresh time budget and pushes it to the pull request as one commit when it's done." : "Ask someone with member access to resume it."} +

+
+ + ); + } else if (run.status === "failed" && run.codegen_env_missing?.vars.length) { + // A generator needed public values the repository doesn't set: say which, + // and where to set them; Retry once they're in. + const missing = run.codegen_env_missing; + outcome = ( + + {canAct && ( + + Set the values + + )} + {retryButton} + + } + > +
+

+ The pull request didn't open: {missing.command} needs public values {missing.repo} doesn't set for Coderhelm's sandbox: +

+
    + {missing.vars.map((v) => ( +
  • + {v} +
  • + ))} +
+

+ Set them in Settings, Repositories, {missing.repo}, Codegen environment (public values only, never secrets), then retry.

diff --git a/dashboard/src/app/settings/repos/codegen/page.tsx b/dashboard/src/app/settings/repos/codegen/page.tsx new file mode 100644 index 00000000..ef3e2ea5 --- /dev/null +++ b/dashboard/src/app/settings/repos/codegen/page.tsx @@ -0,0 +1,169 @@ +"use client"; + +// A repository's codegen environment: the PUBLIC values its code generators +// need in the sandbox (a CMS project id and dataset, for example). The +// sandbox holds no secrets, so these must be values that already ship to the +// browser; the gateway refuses names and values that look like credentials. + +import Link from "next/link"; +import { Suspense, useCallback, useEffect, useState } from "react"; +import { useSearchParams } from "next/navigation"; +import { api, type CodegenVar } from "@/lib/api"; +import { RoleGuard } from "@/components/role-guard"; +import { Callout } from "@/components/callout"; +import { Page, PageHeader } from "@/components/page"; +import { buttonClass, inputClass, primaryButton, secondaryButton } from "@/components/ui"; +import { useToast } from "@/components/toast"; + +export default function CodegenEnvPageGuarded() { + return ( + + + + + + ); +} + +const empty = (): CodegenVar => ({ name: "", value: "" }); + +function CodegenEnvPage() { + const params = useSearchParams(); + const repo = params.get("repo") ?? ""; + // Names a stopped run asked for, pre-filled so the person only adds values. + const asked = (params.get("need") ?? "").split(",").map((n) => n.trim()).filter(Boolean); + const { toast } = useToast(); + const [vars, setVars] = useState([]); + const [loading, setLoading] = useState(true); + const [loadError, setLoadError] = useState(false); + const [saving, setSaving] = useState(false); + const [error, setError] = useState(""); + + const load = useCallback(() => { + if (!repo) return; + setLoading(true); + setLoadError(false); + api + .getCodegenEnv(repo) + .then((r) => { + const have = r.vars; + const add = asked.filter((n) => !have.some((v) => v.name === n)).map((name) => ({ name, value: "" })); + const all = [...have, ...add]; + setVars(all.length ? all : [empty()]); + }) + .catch(() => setLoadError(true)) + .finally(() => setLoading(false)); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [repo]); + useEffect(load, [load]); + + const set = (i: number, field: keyof CodegenVar, value: string) => + setVars((prev) => prev.map((v, j) => (j === i ? { ...v, [field]: field === "name" ? value.toUpperCase() : value } : v))); + + const save = async () => { + setSaving(true); + setError(""); + try { + const kept = vars.filter((v) => v.name.trim()); + await api.setCodegenEnv(repo, kept); + toast("Saved. The next run uses these values."); + } catch (e) { + setError(e instanceof Error ? e.message : "Couldn't save. Try again."); + } finally { + setSaving(false); + } + }; + + if (!repo) { + return ( + + +

+ Pick a repository on Repositories. +

+
+ ); + } + + return ( + + +
+ +

+ These values are copied into the build sandbox. Only put values that already ship to the browser, such as a + project id or a dataset name. Never put tokens, passwords or keys here; names and values that look like + secrets are refused. +

+
+ {loading ? ( +

Loading…

+ ) : loadError ? ( + Try again}> +

Nothing has changed.

+
+ ) : ( +
{ + e.preventDefault(); + void save(); + }} + className="space-y-3" + data-testid="codegen-env-form" + > + {vars.map((v, i) => ( +
+ + + +
+ ))} + {error && ( +

+ {error} +

+ )} +
+ + +
+
+ )} +
+
+ ); +} diff --git a/dashboard/src/app/settings/repos/page.tsx b/dashboard/src/app/settings/repos/page.tsx index 243172af..e68d414b 100644 --- a/dashboard/src/app/settings/repos/page.tsx +++ b/dashboard/src/app/settings/repos/page.tsx @@ -276,6 +276,15 @@ function ReposPage() { chips={ <> {repo.enabled && } + {repo.enabled && canManage && ( + + Codegen environment + + )} {repo.enabled && !canManage ? ( repo.role ? {ROLE_NAMES[repo.role] ?? repo.role} : undefined ) : repo.enabled ? ( diff --git a/dashboard/src/lib/api.ts b/dashboard/src/lib/api.ts index 39e85f43..d8eb9041 100644 --- a/dashboard/src/lib/api.ts +++ b/dashboard/src/lib/api.ts @@ -411,6 +411,15 @@ export const api = { method: "POST", body: JSON.stringify({ enabled }), }), + /** A repository's public codegen environment (admins). */ + getCodegenEnv: (repo: string) => + request<{ repo: string; vars: CodegenVar[] }>(`/api/repos/${repo}/codegen-env`), + /** Replaces it; the gateway refuses anything that looks like a secret, with the reason. */ + setCodegenEnv: (repo: string, vars: CodegenVar[]) => + request<{ repo: string; count: number }>(`/api/repos/${repo}/codegen-env`, { + method: "PUT", + body: JSON.stringify({ vars }), + }), setRepoRole: (repo: string, role: string) => request(`/api/repos/${repo}/role`, { method: "POST", @@ -1838,6 +1847,19 @@ export interface BulkCloseAnswer { failed: number; } +/** One public value a repository's code generators read in the sandbox. */ +export interface CodegenVar { + name: string; + value: string; +} + +/** A run stopped before its pull request: a generator needed public values the repo doesn't set. */ +export interface CodegenEnvMissing { + repo: string; + command: string; + vars: string[]; +} + /** The last fix round on a run's open pull request that didn't finish. */ export interface RoundIncomplete { /** `ci_fix`, `review_fix` or `feedback`. */ @@ -1847,9 +1869,11 @@ export interface RoundIncomplete { reason: string; /** "Pull request open; the last fix round didn't finish: …" */ summary: string; - /** Commits it pushed before it stopped, oldest first. */ + /** Checkpoint commits it saved on `wip_branch` before it stopped, oldest first. */ pushed: { sha: string; message: string }[]; files: string[]; + /** The branch holding its work so far; the pull request itself is unchanged. */ + wip_branch: string; at: string; /** Retry resumes the round on the same pull request. */ can_resume: boolean; @@ -1879,6 +1903,8 @@ export interface RunDetail extends Run { progress_notes?: { message: string; timestamp: string }[]; /** Set when the pull request is open but the last fix round on it didn't finish. */ round_incomplete?: RoundIncomplete | null; + /** The run stopped before its pull request: a generator needed these public values. */ + codegen_env_missing?: CodegenEnvMissing | null; /** Where the planner decided the fix belongs: code, outside_code, both or unknown. */ fix_location?: string | null; /** Markdown report when the fix is (partly) a change outside the code. */ diff --git a/dashboard/src/lib/routes.ts b/dashboard/src/lib/routes.ts index a276aa04..5138358d 100644 --- a/dashboard/src/lib/routes.ts +++ b/dashboard/src/lib/routes.ts @@ -85,6 +85,7 @@ export const ROUTES: Record = { "/settings/sign-in": { label: "Sign-in", parent: "/settings" }, "/settings/support-access": { label: "Support access", parent: "/settings" }, "/settings/repos": { label: "Repositories", parent: "/settings" }, + "/settings/repos/codegen": { label: "Codegen environment", parent: "/settings/repos" }, "/settings/workflow": { label: "Workflow", parent: "/settings" }, "/settings/agents": { label: "Agent permissions", parent: "/settings" }, "/settings/guardrails": { label: "Guardrails", parent: "/settings" }, From 4052023add88ca2d811848ec1b41201489de0acb Mon Sep 17 00:00:00 2001 From: Nam Rodriguez Date: Tue, 27 Oct 2026 15:58:48 -0400 Subject: [PATCH 3/3] openapi-fields: regenerate from CoderHelm/coderhelm-platform@2be1858 (rebased on main) --- dashboard/src/lib/openapi-fields.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dashboard/src/lib/openapi-fields.ts b/dashboard/src/lib/openapi-fields.ts index 88630cc5..217122fc 100644 --- a/dashboard/src/lib/openapi-fields.ts +++ b/dashboard/src/lib/openapi-fields.ts @@ -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 = "3d0ddc4ab9a1acd97adbcf713032bb3a9b625212"; +export const OPENAPI_REF = "2be1858fafcf8530adf42ee3a01167ca8bd6e434"; /** The fields each public API schema has. */ export interface OpenApiFields { @@ -10,6 +10,7 @@ export interface OpenApiFields { AnswerRunResult: "comment_url" | "posted" | "run_id" | "status"; Backfill: "complete"; CiUploadResult: "ok"; + CodegenEnvMissing: "command" | "repo" | "vars"; CreateEndpointBody: "description" | "enabled" | "events" | "url"; CreatePlan: "description" | "destination" | "repo" | "tasks" | "title"; CreatedEndpoint: "endpoint" | "secret"; @@ -40,6 +41,7 @@ export interface OpenApiFields { PlanWithTasks: "chat_id" | "created_at" | "description" | "destination" | "executed_at" | "executed_by" | "mcp_servers" | "plan_id" | "repo" | "status" | "task_count" | "tasks" | "title" | "tokens_in" | "tokens_out" | "updated_at"; PlansPage: "next" | "next_cursor" | "plans"; Point: "deliveries" | "end" | "failed" | "ok" | "p95_ms" | "previous_deliveries" | "start" | "success_rate"; + PushedCommit: "message" | "sha"; Quarantine: "playwright_grep_invert" | "tests"; QuarantinedTest: "file" | "framework" | "id" | "project" | "title"; RatingComment: "at" | "by" | "rating" | "text"; @@ -53,7 +55,8 @@ export interface OpenApiFields { ReviewsPage: "next" | "reviews"; RotateBody: "overlap_hours"; RotatedSecret: "previous_secret_expires_at" | "secret"; - Run: "answers" | "answers_url" | "applied_standards" | "branch" | "branches" | "cache_read_tokens" | "cache_write_tokens" | "close_reason" | "closed_at" | "closed_by" | "closed_from" | "continued_run_id" | "cost_usd" | "created_at" | "current_pass" | "duration_s" | "error" | "files_modified" | "fix_location" | "lesson" | "mcp_servers" | "outside_change_report" | "pass_history" | "policy_approval" | "policy_note" | "pr_number" | "pr_numbers" | "pr_url" | "pr_urls" | "progress_notes" | "questions" | "questions_url" | "repo" | "run_id" | "sign_in_prompts" | "status" | "ticket_id" | "ticket_source" | "title" | "tokens_in" | "tokens_out" | "trigger" | "updated_at"; + 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" | "close_reason" | "closed_at" | "closed_by" | "closed_from" | "codegen_env_missing" | "continued_run_id" | "cost_usd" | "created_at" | "current_pass" | "duration_s" | "error" | "files_modified" | "fix_location" | "lesson" | "mcp_servers" | "outside_change_report" | "pass_history" | "policy_approval" | "policy_note" | "pr_number" | "pr_numbers" | "pr_url" | "pr_urls" | "progress_notes" | "questions" | "questions_url" | "repo" | "round_incomplete" | "run_id" | "sign_in_prompts" | "status" | "ticket_id" | "ticket_source" | "title" | "tokens_in" | "tokens_out" | "trigger" | "updated_at"; RunActionResult: "status"; RunAnswer: "answer" | "answered_at" | "author" | "question" | "question_id"; RunNote: "message" | "timestamp";