Public: anyone can read this; the crew can change it.

A build that did not finish says why, and offers Try again (#16489) #16492

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

fix/build-card-why → main 0 commits

  • Merged. fix/build-card-why was merged into main as bb215e8.

Review

Sign in to review this change.
13 files changed +195 −28
docs/features/talk.md +1 −1
@@ -276,7 +276,7 @@ A private preview signs the person in inside the frame through their own grant.
276276
277277 ## The pane while the crew works (#15734)
278278
279 Until the app answers, the pane's Preview tab shows what the crew is doing on the repository: its newest run in plain words (`crewNow`, `src/core/talk_work.ts`). A queued run says why it waits (the hold sentence, with the control that changes it); a running one lists its newest six steps (a file read or changed, a search, the checks, a commit, a push), each added as the run writes it, from the forge's own event stream (`run.log`), by the same `plainStep` the server uses; a finished or failed one says how it ended. A log line is the builder's untrusted text: it is only ever drawn as text, and only for a reader who may read the run's log (`mayReadRunLog`: the repository's own facts or the crew); anyone else who may see the runs reads how it stands and the link, never a step, and the live tail is never sent them (`/events` sends `run.log` only to who may read it). "See the whole run" links the run's page, which is all of it without the script. The pane is a live region on the repository's runs, so the first deploy that turns running swaps the frame in; the page names the app's production origin in `frame-src` ahead, and a frame of another origin draws the page once. The pane opens by itself once the crew is on the repository the conversation names; a new app is named by its receipt (`New app owner/name`). In the terminal, the conversation's pane (`p`) prints the same lines and redraws as the run writes. Proof: `test/talk-live-pane.test.ts`.
279 Until the app answers, the pane's Preview tab shows what the crew is doing on the repository: its newest run in plain words (`crewNow`, `src/core/talk_work.ts`). A queued run says why it waits (the hold sentence, with the control that changes it); a running one lists its newest six steps (a file read or changed, a search, the checks, a commit, a push), each added as the run writes it, from the forge's own event stream (`run.log`), by the same `plainStep` the server uses; a finished one says so, and one that did not finish says why from the run's own record (stopped, out of time, the model's window full, the network, a restart, the code it could not fetch, spent model credit, or the error that stopped it, clipped: `endWhy`, `src/runs/end_why.ts`), with **Try again** for a member who may write the repository (the run's `requeue` route, answering back on Talk; in the terminal's pane, `t` in `src/tui/screens/talk_chats.ts`) (#16489). A log line is the builder's untrusted text: it is only ever drawn as text, and only for a reader who may read the run's log (`mayReadRunLog`: the repository's own facts or the crew); anyone else who may see the runs reads how it stands and the link, never a step, and the live tail is never sent them (`/events` sends `run.log` only to who may read it). "See the whole run" links the run's page, which is all of it without the script. The pane is a live region on the repository's runs, so the first deploy that turns running swaps the frame in; the page names the app's production origin in `frame-src` ahead, and a frame of another origin draws the page once. The pane opens by itself once the crew is on the repository the conversation names; a new app is named by its receipt (`New app owner/name`). In the terminal, the conversation's pane (`p`) prints the same lines and redraws as the run writes. Proof: `test/talk-live-pane.test.ts`.
280280
281281 What runs is framed from the start: a new app's starter answers seconds after it is made, so the pane frames production (until a pull's own preview answers) and the crew's block sits under the frame, which gives it room. The block says who works ("cheffry-james is working.", with the same shine Talk's own agent uses while it answers) and lists its newest eight lines: its own words (`plainThought`: the short text between its calls, trimmed to about two lines) and its steps. The block is a live region of its own, so the frame is never redrawn for the crew; a deploy that turns running reloads the frame in place, and a pull's preview that comes up while production is framed draws the page once (its origin joins `frame-src`).
282282
src/core/talk_work.ts +13 −2
@@ -19,6 +19,8 @@ import { reviewSummary } from "./reviews.ts";
1919 import { checkSummary } from "./runs.ts";
2020 import { callState } from "./talk_steps.ts";
2121 import { readRunLogTail } from "../runs/log.ts";
22 import { endWhy } from "../runs/end_why.ts";
23 import { roleOf } from "./roles.ts";
2224 import { wallWords } from "../flow/wall_wait.ts";
2325
2426 /** The part of a turn the reading needs: its role and its stored text. */
@@ -593,6 +595,11 @@ export interface PaneCrew {
593595 readonly issue?: number;
594596 /** It waits on a hold (`holdNow`): the line says why and names the control, so it is never folded away. */
595597 readonly held?: boolean;
598 /**
599 * It did not finish and this reader may queue its task again (a member who writes the
600 * repository).
601 */
602 readonly retry?: boolean;
596603 }
597604
598605 /** What a reader may see of a repository's runs, as `actions/runs.ts` decides it. */
@@ -610,7 +617,7 @@ export interface RunsSeen {
610617 export function paneCrew(db: Database, dataDir: string, repoId: string, reader: User | undefined, seen: RunsSeen): PaneCrew | undefined {
611618 if (!seen.runs) return undefined;
612619 const run = db
613 .query<{ id: string; state: string; actor_id: string | null; issue: number | null }, [string]>("SELECT r.id, r.state, r.actor_id, i.number AS issue FROM run r LEFT JOIN issue i ON i.id = r.issue_id WHERE r.repo_id = ?1 AND r.kind = 'agent' ORDER BY r.id DESC LIMIT 1")
620 .query<{ id: string; state: string; summary: string; actor_id: string | null; issue: number | null }, [string]>("SELECT r.id, r.state, r.summary, r.actor_id, i.number AS issue FROM run r LEFT JOIN issue i ON i.id = r.issue_id WHERE r.repo_id = ?1 AND r.kind = 'agent' ORDER BY r.id DESC LIMIT 1")
614621 .get(repoId);
615622 if (run === null) return undefined;
616623 const steps: CrewItem[] = seen.logs
@@ -631,5 +638,9 @@ export function paneCrew(db: Database, dataDir: string, repoId: string, reader:
631638 }
632639 if (run.state === "running") return { ...at, state: "running", line: { says: `${who === "the crew" ? "The crew" : who} is working.` } };
633640 if (run.state === "ok") return { ...at, state: "ok", line: { says: "The crew finished this run." } };
634 return { ...at, state: "failed", line: { says: "The crew's run did not finish." } };
641 // Why, from the run's own record, and Try again for whoever may queue it (`requeueRepoRun`'s own
642 // gate: a member who writes the repository), so the card never ends on a dead end (#16489).
643 const repo = getRepoById(db, repoId);
644 const retry = reader !== undefined && repo !== undefined && canWrite(db, repo, reader) && reader.kind === "user" && roleOf(db, reader) !== "guest";
645 return { ...at, state: "failed", line: { says: `The crew's run did not finish: ${endWhy(run)}.` }, ...(retry ? { retry: true } : {}) };
635646 }
src/crew/review.ts +1 −6
@@ -28,7 +28,7 @@ import { teamsOfPull, teamVerdicts } from "../core/issue_teams.ts";
2828 import { listReviews, reviewSummariesFor, reviewSummary, type Review } from "../core/reviews.ts";
2929 import { verdictForHead } from "../core/runs.ts";
3030 import { getTeam } from "../core/teams.ts";
31 import { BUDGET_PREFIX } from "../kernel/budgets.ts";
31 import { BUDGET_PREFIX, RUN_THREW_PREFIX } from "../kernel/budgets.ts";
3232 import { createLog } from "../kernel/log.ts";
3333 import { guestWaits } from "../origins/guest.ts";
3434 import { reviewerPaused } from "./reviewer_paused.ts";
@@ -209,11 +209,6 @@ export const NOT_REVIEWED_PREFIX = "not reviewed:";
209209 * it).
210210 */
211211 export const SEALED_FETCH_PREFIX = "fetch of the sealed head failed:";
212 /**
213 * What a run's summary starts with when its launch threw (`runner.ts` writes it, the error after
214 * it).
215 */
216 export const RUN_THREW_PREFIX = "the run failed:";
217212 /**
218213 * The summaries of a run that ended before its agent read anything: written from these constants.
219214 */
src/crew/runner.ts +1 −2
@@ -127,13 +127,12 @@ import {
127127 NOT_REVIEWED_PREFIX,
128128 noVerdictSummary,
129129 overranWhere,
130 RUN_THREW_PREFIX,
131130 SEALED_FETCH_PREFIX,
132131 touchesDesign,
133132 waitingOnCheck,
134133 } from "./review.ts";
135134 import { fetchSealedHead, SEALED_REMOTE, sealedHeadRepo } from "./sealed_head.ts";
136 import { BUDGETS, BUDGET_PREFIX, budgetSummary } from "../kernel/budgets.ts";
135 import { BUDGETS, BUDGET_PREFIX, RUN_THREW_PREFIX, budgetSummary } from "../kernel/budgets.ts";
137136 import { createLog, holdValues, redactValues, releaseValues } from "../kernel/log.ts";
138137 import { err, ok, type Result } from "../kernel/result.ts";
139138 import { holdLease } from "../runs/lease.ts";
src/kernel/budgets.ts +6
@@ -56,6 +56,12 @@ export type BudgetLimits = {
5656 /** The summary prefix every budget kill carries; vitals and retries read it. */
5757 export const BUDGET_PREFIX = "budget:";
5858
59 /**
60 * What a run's summary starts with when its launch threw (`crew/runner.ts` writes it, the error
61 * after it); `runs/end_why.ts` says it to a person.
62 */
63 export const RUN_THREW_PREFIX = "the run failed:";
64
5965 /** What a run killed past its budget says as its summary. */
6066 export function budgetSummary(
6167 what: string,
src/runs/end_why.ts added +40
@@ -0,0 +1,40 @@
1 /**
2 * Why a crew run ended without finishing, in a person's words (#16489): what a build card and the
3 * terminal's pane say after "The crew's run did not finish". Read from the run's own record, its
4 * state and summary: stopped, out of time, cut short by the model's window, the network, a restart
5 * or the code it could not fetch, out of model credit, or the error that stopped it (clipped).
6 * Never a raw "API Error: 402".
7 */
8
9 import { BUDGET_PREFIX, RUN_THREW_PREFIX } from "../kernel/budgets.ts";
10 import { interruptionOf, type Interruption } from "../crew/interrupted.ts";
11 import { clip } from "../text/clip.ts";
12
13 const CUT: Record<Interruption, string> = {
14 "provider limit": "the model's window was full",
15 "network error": "the network to the model failed",
16 restart: "the forge restarted while it worked",
17 clone: "it could not fetch the repository's code",
18 };
19
20 /** How long an error's own words may run in the line. */
21 export const WHY_MAX = 140;
22
23 /** Why the run ended, as a clause; "it gave no reason" when its record says nothing. */
24 export function endWhy(run: {
25 readonly state: string;
26 readonly summary: string;
27 }): string {
28 const said = run.summary.trim();
29 if (run.state === "cancelled") return "it was stopped";
30 if (/\bAPI Error: 402\b/.test(said))
31 return "the model credit it runs on is spent";
32 const cut = interruptionOf(said);
33 if (cut !== undefined) return CUT[cut];
34 if (said.startsWith(BUDGET_PREFIX))
35 return `it ran out of time (${said.slice(BUDGET_PREFIX.length).trim()})`;
36 if (said.startsWith(RUN_THREW_PREFIX))
37 return `an error stopped it: ${clip(said.slice(RUN_THREW_PREFIX.length), WHY_MAX)}`;
38 if (said === "") return "it gave no reason";
39 return clip(said, WHY_MAX).replace(/[.!]+$/, "");
40 }
src/tui/screens/talk_chats.ts +20 −2
@@ -34,7 +34,8 @@ import { setTalkDisplay, talkDisplay } from "../../core/settings.ts";
3434 import { talkDisplayScreen } from "./talk_display.ts";
3535 import { conversationPulls, liveReceipts, paneCrew, paneFell, paneInfo, type LiveReceipt } from "../../core/talk_work.ts";
3636 import { tapRunLogs } from "../../runs/log.ts";
37 import { mayReadRunLog, mayReadRuns } from "../../actions/runs.ts";
37 import { mayReadRunLog, mayReadRuns, requeueRepoRun } from "../../actions/runs.ts";
38 import { words } from "../../fleet/verbs.ts";
3839 import { confirmsScreen } from "./confirms.ts";
3940 import { waitingConfirms } from "../../actions/conversation_confirms.ts";
4041 import { branchDiff, chatBuildOf, mineEmpty, pullChanges, type PullChange } from "../../core/chat_build.ts";
@@ -205,7 +206,7 @@ function chatScreen(f: Session, ctx: Ctx, chat: Conversation, hit?: string): Scr
205206 if (crew === undefined) return [];
206207 const l = crew.line;
207208 const said = l.change === undefined ? l.says : `${l.says} ${l.change.words}: ${f.app.config.url === undefined ? l.change.href : publicOrigin(f.app.config.url, "") + l.change.href}`;
208 return ["", `Crew: ${said}`, ...crew.steps.map((item) => (item.thought ? ` \u201c${item.text}\u201d` : ` ${item.text}`)), `The whole run: /${repo ?? ""}/runs/${crew.runId}`];
209 return ["", `Crew: ${said}`, ...(crew.retry === true ? ["t tries it again."] : []), ...crew.steps.map((item) => (item.thought ? ` \u201c${item.text}\u201d` : ` ${item.text}`)), `The whole run: /${repo ?? ""}/runs/${crew.runId}`];
209210 };
210211 // Where the terminal's c says words: the pull shown, the crew's run's issue, else the newest receipt's.
211212 const replyTarget = (user: User): { owner: string; name: string; number: number; object: string } | undefined => {
@@ -357,6 +358,7 @@ function chatScreen(f: Session, ctx: Ctx, chat: Conversation, hit?: string): Scr
357358 binding(["v"], "steps open or folded"),
358359 binding(["D"], "display"),
359360 binding(["c"], "comment on the receipt's issue"),
361 binding(["t"], "try the crew's run again"),
360362 binding(["a"], "answer what waits"),
361363 binding(["A", "S"], "the access wall: allow it, or send it back"),
362364 binding(["d", "x"], "export as Markdown"),
@@ -537,6 +539,22 @@ function chatScreen(f: Session, ctx: Ctx, chat: Conversation, hit?: string): Scr
537539 answerTheWall(e.key === "A" ? "allow" : "send_back");
538540 return true;
539541 }
542 if (e.key === "t") {
543 // The build card's Try again: the crew's run that did not finish, its task queued once
544 // more.
545 const name = repo === undefined ? undefined : (paneRepo() ?? repo);
546 const ws = name === undefined ? undefined : workspaceOf(f.app, user, name, undefined, pointedAt(choice(), steerOn(name)));
547 const crew = ws === undefined ? undefined : paneCrew(f.app.db, f.app.config.dataDir, ws.repo.id, user, { runs: mayReadRuns(f.app, user, ws.repo), logs: false });
548 if (ws === undefined || crew?.retry !== true) {
549 note = "No run here waits to be tried again.";
550 ctx.invalidate();
551 return true;
552 }
553 const done = requeueRepoRun(f.app, user, ws.repo, crew.runId);
554 note = done.ok ? "Queued again." : `Could not run it again: ${words(done.error)}.`;
555 ctx.invalidate();
556 return true;
557 }
540558 if (e.key === "c") {
541559 // As the page's crew box says it: on the pull whose preview the pane shows, else the issue the
542560 // crew's newest run works; else, as Reply does, the newest receipt's issue. Whoever works on
src/web/pages/runs.ts +4 −4
@@ -37,7 +37,7 @@ import { getUsersByIds, type User } from "../../core/users.ts";
3737 import { notePhase, takeSessionTime } from "../../core/route_timing.ts";
3838 import type { Ctx } from "../../http/context.ts";
3939 import { loadRepo, notFoundPage, repoBase, signInFirst } from "../chrome.ts";
40 import { field, readForm } from "../form.ts";
40 import { backTo, field, readForm } from "../form.ts";
4141 import { html, when, type Html } from "../html.ts";
4242 import { badge } from "../ui.ts";
4343 import { flashTo, redirect } from "../layout.ts";
@@ -480,7 +480,7 @@ const REQUEUE_REFUSED: Record<string, string> = {
480480 };
481481
482482 // POST /:owner/:name/runs/:id/requeue — "Try again": the run's task goes back on the queue.
483 // Only Home posts it, so it answers on Home (/) on purpose.
483 // It answers on the page it was pressed on (`back`: Home, or Talk's build card), Home otherwise.
484484 export async function runRequeue(ctx: Ctx): Promise<Response> {
485485 const repo = loadRepo(ctx);
486486 if (!repo) return notFoundPage(ctx);
@@ -490,10 +490,10 @@ export async function runRequeue(ctx: Ctx): Promise<Response> {
490490 const queued = requeueRepoRun(ctx.app, ctx.auth.user, repo, ctx.params.id ?? "");
491491 if (!queued.ok) {
492492 if (queued.error === "not_found") return notFoundPage(ctx);
493 return flashTo(ctx, "/", {
493 return flashTo(ctx, backTo(form, "/"), {
494494 tone: "danger",
495495 message: REQUEUE_REFUSED[queued.error] ?? "You need write access to try a run again.",
496496 });
497497 }
498 return flashTo(ctx, "/", { message: "Queued again." });
498 return flashTo(ctx, backTo(form, "/"), { message: "Queued again." });
499499 }
src/web/pages/talk_preview.ts +9 −6
@@ -95,8 +95,8 @@ export async function talkPane(ctx: Ctx, user: User, name: string | undefined, w
9595 : view === "diff"
9696 ? await diffView(ctx.app, work, ask.version, ask.mine === undefined ? undefined : { ...ask.mine, picked: at.pull })
9797 : url === undefined || ask.wait !== undefined
98 ? html`<div class="talk-stage talk-stage-wait" data-stage${ask.busy === true ? raw(" data-busy") : null}><p class="talk-stage-note" data-stage-note>${ask.wait ?? ask.idle ?? "Nothing is running yet: the app appears here once it is built."}</p>${crew === undefined ? null : crewBlock(crew, `/${ws.repo.ownerName}/${ws.repo.name}`, ws.repo, liveSrc)}</div>${ask.build === undefined ? null : html`<h2 class="talk-stage-files small muted">The files it starts from</h2>${await codeView(ctx.app, work)}`}`
99 : html`${steer === undefined || steer.try === "" ? null : html`<p class="talk-try small" data-pane-try>Try: ${steer.try}</p>`}<div class="talk-stage" data-stage data-env="${ws.shows === undefined ? "production" : previewEnv(ws.shows)}"><iframe class="talk-frame" data-frame src="${url}" title="Live preview of ${name}" referrerpolicy="no-referrer" sandbox="allow-scripts allow-same-origin allow-forms allow-popups"></iframe><p class="talk-stage-note small" data-stage-note hidden>Updating the preview…</p></div>${crewRegion(crew !== undefined && (going || crew.state === "failed") ? crew : undefined, ws.repo, liveSrc, ws.shows)}`;
98 ? html`<div class="talk-stage talk-stage-wait" data-stage${ask.busy === true ? raw(" data-busy") : null}><p class="talk-stage-note" data-stage-note>${ask.wait ?? ask.idle ?? "Nothing is running yet: the app appears here once it is built."}</p>${crew === undefined ? null : crewBlock(crew, `/${ws.repo.ownerName}/${ws.repo.name}`, ws.repo, liveSrc, () => ctx.url.pathname)}</div>${ask.build === undefined ? null : html`<h2 class="talk-stage-files small muted">The files it starts from</h2>${await codeView(ctx.app, work)}`}`
99 : html`${steer === undefined || steer.try === "" ? null : html`<p class="talk-try small" data-pane-try>Try: ${steer.try}</p>`}<div class="talk-stage" data-stage data-env="${ws.shows === undefined ? "production" : previewEnv(ws.shows)}"><iframe class="talk-frame" data-frame src="${url}" title="Live preview of ${name}" referrerpolicy="no-referrer" sandbox="allow-scripts allow-same-origin allow-forms allow-popups"></iframe><p class="talk-stage-note small" data-stage-note hidden>Updating the preview…</p></div>${crewRegion(crew !== undefined && (going || crew.state === "failed") ? crew : undefined, ws.repo, liveSrc, () => ctx.url.pathname, ws.shows)}`;
100100 // The address bar of what runs: which environment, where it lives, reload and open on its own.
101101 const where = url === undefined ? null : html`<span class="talk-addr small" title="${url}"><span class="muted">${ws.shows === undefined ? "Production" : `Pull #${String(ws.shows)}`}</span> ${new URL(url).host}</span>`;
102102 // Waiting, the pane is a live region on the repository's runs: a deploy that turns running swaps
@@ -149,10 +149,10 @@ function productionOrigin(ctx: Ctx, repoId: string): string | undefined {
149149 * whenever the pane is open, so the crew's next run (the person's next change) is picked up on
150150 * run.* and drawn under the same frame, which the swap never touches.
151151 */
152 function crewRegion(crew: PaneCrew | undefined, repo: { readonly ownerName: string; readonly name: string }, src: string, shows?: number): Html {
152 function crewRegion(crew: PaneCrew | undefined, repo: { readonly ownerName: string; readonly name: string }, src: string, back: () => string, shows?: number): Html {
153153 return crew === undefined
154154 ? html`<div class="talk-crew-now" id="talk-crew-now" data-live="run.*" data-live-repo="${repo.ownerName}/${repo.name}" data-live-src="${src}"></div>`
155 : crewBlock(crew, `/${repo.ownerName}/${repo.name}`, repo, src, shows);
155 : crewBlock(crew, `/${repo.ownerName}/${repo.name}`, repo, src, back, shows);
156156 }
157157
158158 /**
@@ -163,17 +163,20 @@ function crewRegion(crew: PaneCrew | undefined, repo: { readonly ownerName: stri
163163 * works it folds to its one line (a `<details>`, the fold kept per conversation by the script); a
164164 * hold or a failure is drawn open and unfoldable, so neither is ever hidden.
165165 */
166 function crewBlock(crew: PaneCrew, base: string, repo: { readonly ownerName: string; readonly name: string }, src: string, shows?: number): Html {
166 function crewBlock(crew: PaneCrew, base: string, repo: { readonly ownerName: string; readonly name: string }, src: string, back: () => string, shows?: number): Html {
167167 const working = crew.state === "running" ? " talk-crew-working" : "";
168168 const line = html`<p class="small${working}">${workLineHtml(crew.line)}</p>`;
169169 const steps = !crew.tail || (crew.steps.length === 0 && crew.state !== "running") ? null : html`<div class="talk-crew-steps small muted" data-crew-steps="${crew.runId}" aria-live="polite">${crew.steps.map((item) => (item.thought ? html`<p class="talk-crew-thought">${item.text}</p>` : html`<p>${item.text}</p>`))}</div>`;
170170 const run = html`<a class="small" href="${base}/runs/${crew.runId}">See the whole run</a>`;
171 // A run that did not finish offers its next step: Try again queues its task once more, and
172 // answers on this page (`back`, read only then).
173 const again = crew.retry !== true ? null : html`<form class="bar" method="post" action="${base}/runs/${crew.runId}/requeue"><input type="hidden" name="back" value="${back()}">${btn("Try again", { size: "sm", variant: "outline" })}</form>`;
171174 // A pull's words go through its own page's door, an issue's through its own.
172175 const reply = shows !== undefined ? crewReply(`${base}/pulls/${String(shows)}`, `#${String(shows)}`) : crew.issue === undefined ? null : crewReply(`${base}/issues/${String(crew.issue)}`, `#${String(crew.issue)}`);
173176 // Its own live region: the crew's next run is read as it is queued, starts or ends, and the frame
174177 // above it is never redrawn for it.
175178 return html`<div class="talk-crew-now" id="talk-crew-now" data-live="run.*" data-live-repo="${repo.ownerName}/${repo.name}" data-live-src="${src}">
176 ${crew.held === true || crew.state === "failed" ? html`${line}${steps}${run}` : html`<details class="talk-crew-fold" open><summary><span class="small${working}">${workLineHtml(crew.line)}</span></summary>${steps}${run}${reply}</details>`}
179 ${crew.held === true || crew.state === "failed" ? html`${line}${again}${steps}${run}` : html`<details class="talk-crew-fold" open><summary><span class="small${working}">${workLineHtml(crew.line)}</span></summary>${steps}${run}${reply}</details>`}
177180 </div>`;
178181 }
179182
test/home-interrupted-out.test.ts +12
@@ -148,3 +148,15 @@ test("the terminal screen lists the same runs and Enter tries one again", async
148148 expect(runsOf(hit.issue.id)).toBe(2);
149149 expect(await home()).not.toContain(`/runs/${hit.id}/requeue`);
150150 });
151
152 test("Try again answers on the page it was pressed on (Talk's build card), never off the forge (#16489)", async () => {
153 const send = (back: string) =>
154 fetch(`${servers.url}/alice/shop/runs/${failedRun("Again", INTERRUPTED_OUT, new Date().toISOString()).id}/requeue`, {
155 method: "POST",
156 headers: { cookie, origin: servers.url, "content-type": "application/x-www-form-urlencoded" },
157 body: new URLSearchParams({ back }),
158 redirect: "manual",
159 });
160 expect((await send("/talk/c1")).headers.get("location")).toBe("/talk/c1");
161 expect((await send("https://evil.example/")).headers.get("location")).toBe("/");
162 });
test/review-start-failure.test.ts +1 −1
@@ -7,6 +7,7 @@
77 * #16227). Now the line names the cause, and a run the forge failed spends no try, up to
88 * `FORGE_FAULTS_FORGIVEN` a head.
99 */
10 import { RUN_THREW_PREFIX } from "../src/kernel/budgets.ts";
1011 import { seatAs } from "./helpers/seat.ts";
1112 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
1213 import { mkdtemp, rm } from "node:fs/promises";
@@ -26,7 +27,6 @@ import { deniedOf } from "../src/crew/claude.ts";
2627 import {
2728 FORGE_FAULTS_FORGIVEN,
2829 HARNESS_REFUSED,
29 RUN_THREW_PREFIX,
3030 failedAtStart,
3131 forgeFault,
3232 noVerdictSummary,
test/run-end-why.test.ts added +50
@@ -0,0 +1,50 @@
1 /**
2 * Why a crew run did not finish, in a person's words, from its own record (#16489): the build card
3 * and the terminal's pane say it after "The crew's run did not finish".
4 */
5
6 import { expect, test } from "bun:test";
7 import { endWhy, WHY_MAX } from "../src/runs/end_why.ts";
8 import { budgetSummary, RUN_THREW_PREFIX } from "../src/kernel/budgets.ts";
9
10 const failed = (summary: string) => endWhy({ state: "failed", summary });
11
12 test("each way a run ends unfinished has its own words", () => {
13 expect(endWhy({ state: "cancelled", summary: "anything" })).toBe(
14 "it was stopped",
15 );
16 expect(failed(budgetSummary("work", 31 * 60_000, 30 * 60_000))).toBe(
17 "it ran out of time (work took 31 min, limit 30)",
18 );
19 expect(
20 failed(
21 "interrupted: provider limit, resumes 21:22 UTC — You've hit your limit",
22 ),
23 ).toBe("the model's window was full");
24 expect(
25 failed(
26 "interrupted: network error, resumes on the next pass — fetch failed",
27 ),
28 ).toBe("the network to the model failed");
29 expect(failed("clone failed: remote hung up")).toBe(
30 "it could not fetch the repository's code",
31 );
32 expect(failed("API Error: 402 credit balance is too low")).toBe(
33 "the model credit it runs on is spent",
34 );
35 expect(
36 failed(`${RUN_THREW_PREFIX} Error: ENOSPC: no space left on device`),
37 ).toBe("an error stopped it: Error: ENOSPC: no space left on device");
38 expect(failed("")).toBe("it gave no reason");
39 expect(failed("Declined: the ask needs a design first.")).toBe(
40 "Declined: the ask needs a design first",
41 );
42 });
43
44 test("a long error is clipped, never the whole of it", () => {
45 const said = failed(`${RUN_THREW_PREFIX} ${"x".repeat(500)}`);
46 expect(said.length).toBeLessThanOrEqual(
47 "an error stopped it: ".length + WHY_MAX,
48 );
49 expect(said.endsWith("…")).toBe(true);
50 });
test/talk-live-pane.test.ts +37 −4
@@ -83,7 +83,7 @@ describe("the pane, by the crew's newest run on the repository", () => {
8383 if (!other.ok) throw new Error(other.error);
8484 promote(app.db, other.value);
8585 bob = other.value;
86 ctx = { app } as Ctx;
86 ctx = { app, url: new URL("http://forge.test/talk") } as Ctx;
8787 });
8888 afterAll(async () => {
8989 servers.stop();
@@ -183,9 +183,11 @@ describe("the pane, by the crew's newest run on the repository", () => {
183183 expect(posted.status).toBe(303);
184184 expect(app.db.query<{ body: string }, [string]>("SELECT body FROM comment WHERE issue_id = ?1").all(pr.value.id).map((c) => c.body)).toContain("make it green too");
185185 // Failed: drawn open, no fold.
186 app.db.run("UPDATE run SET state = 'failed' WHERE id = ?1", [run.id]);
186 app.db.run("UPDATE run SET state = 'failed', summary = 'budget: work took 31 min, limit 30' WHERE id = ?1", [run.id]);
187187 const failed = (await talkPane(ctx, alice, name, new Map(), "preview", production)).html.text;
188 expect(failed).toContain("The crew&#39;s run did not finish.");
188 // Why, from the run's own record, and its next step: Try again, back to this page (#16489).
189 expect(failed).toContain("The crew&#39;s run did not finish: it ran out of time (work took 31 min, limit 30).");
190 expect(failed).toContain(`action="/${name}/runs/${run.id}/requeue"><input type="hidden" name="back" value="/talk">`);
189191 expect(failed).not.toContain("talk-crew-fold");
190192 });
191193
@@ -234,8 +236,16 @@ describe("the pane, by the crew's newest run on the repository", () => {
234236 expect(done.html.text).toContain("<p>Pushed its work</p>");
235237 expect(done.crew).toBe(false);
236238 const failed = await withRun("failed");
239 app.db.run("UPDATE run SET summary = ?1 WHERE id = ?2", ["interrupted: provider limit, resumes 21:22 UTC — You've hit your limit", failed.run.id]);
237240 const ended = await pane(failed.name);
238 expect(ended.html.text.replace(/&#(?:39|x27);/g, "'")).toContain("The crew's run did not finish.");
241 expect(ended.html.text.replace(/&#(?:39|x27);/g, "'")).toContain("The crew's run did not finish: the model's window was full.");
242 expect(ended.html.text).toContain("Try again");
243 // A reader who may not write it reads why, and is offered nothing to press.
244 const guest = await createUser(app.db, { origin: "seed", trusted: true, username: `g${failed.repo.name}`, email: `g${failed.repo.name}@forge.local`, password: "a-good-passphrase" });
245 if (!guest.ok) throw new Error(guest.error);
246 const seen = (await talkPane(ctx, guest.value, failed.name, new Map(), "preview")).html.text;
247 expect(seen.replace(/&#(?:39|x27);/g, "'")).toContain("The crew's run did not finish: the model's window was full.");
248 expect(seen).not.toContain("/requeue");
239249 expect(ended.html.text).toContain(
240250 `href="/${failed.name}/runs/${failed.run.id}"`,
241251 );
@@ -371,6 +381,29 @@ describe("the pane, by the crew's newest run on the repository", () => {
371381 expect(text).toContain(`The whole run: /${name}/runs/${run.id}`);
372382 });
373383
384 test("the terminal's pane says why a run did not finish, and t tries it again (#16489)", async () => {
385 const { run, name } = await withRun("failed");
386 app.db.run("UPDATE run SET summary = 'budget: work took 31 min, limit 30' WHERE id = ?1", [run.id]);
387 const chat = createConversation(app.db, alice.id);
388 if (!chat.ok) throw new Error(chat.error);
389 appendTurn(app.db, alice.id, chat.value.id, { role: "tool", text: `mcp__forge__read_file ${JSON.stringify({ repo: name, path: "a" })}` });
390 const terminal = headlessTerminal(120, 30);
391 const { app: tui } = createForgeApp(app, { sshUsername: "alice", remoteAddress: "127.0.0.1", fingerprint: "SHA256:test", user: alice }, { terminal, exitHooks: false });
392 tui.start();
393 for (const k of [":", "Conversations", "\r", "\r", "p"]) {
394 terminal.feed(k);
395 await settleApp(tui);
396 }
397 const text = tui.screen.toText();
398 expect(text).toContain("Crew: The crew's run did not finish: it ran out of time (work took 31 min, limit 30).");
399 expect(text).toContain("t tries it again.");
400 terminal.feed("t");
401 await settleApp(tui);
402 // This run has no issue left to work: the refusal is said in the Runs screen's own words.
403 expect(tui.screen.toText()).toContain("Could not run it again: its issue is closed or its agent is gone.");
404 tui.stop();
405 });
406
374407 test("framed, a finished run leaves the crew region empty; the crew's next run is swapped into it under the same frame", async () => {
375408 const { repo, name } = await withRun("ok", ["→ Read src/a.ts"]);
376409 const starter = { newestPull: () => undefined, urlOf: (_: unknown, env: string) => (env === "production" ? "https://clicker.apps.test/" : undefined) };

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs