Public: anyone can read this; the crew can change it.
A build that did not finish says why, and offers Try again (#16489) #16492
Check · Review · Land · Live done — Landed and live in production.
fix/build-card-why → main 0 commits
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. | ||
| 276 | 276 | |
| 277 | 277 | ## The pane while the crew works (#15734) |
| 278 | 278 | |
| 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`. | |
| 280 | 280 | |
| 281 | 281 | 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`). |
| 282 | 282 |
src/core/talk_work.ts +13 −2
| @@ -19,6 +19,8 @@ import { reviewSummary } from "./reviews.ts"; | ||
| 19 | 19 | import { checkSummary } from "./runs.ts"; |
| 20 | 20 | import { callState } from "./talk_steps.ts"; |
| 21 | 21 | import { readRunLogTail } from "../runs/log.ts"; |
| 22 | import { endWhy } from "../runs/end_why.ts"; | |
| 23 | import { roleOf } from "./roles.ts"; | |
| 22 | 24 | import { wallWords } from "../flow/wall_wait.ts"; |
| 23 | 25 | |
| 24 | 26 | /** The part of a turn the reading needs: its role and its stored text. */ |
| @@ -593,6 +595,11 @@ export interface PaneCrew { | ||
| 593 | 595 | readonly issue?: number; |
| 594 | 596 | /** It waits on a hold (`holdNow`): the line says why and names the control, so it is never folded away. */ |
| 595 | 597 | 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; | |
| 596 | 603 | } |
| 597 | 604 | |
| 598 | 605 | /** What a reader may see of a repository's runs, as `actions/runs.ts` decides it. */ |
| @@ -610,7 +617,7 @@ export interface RunsSeen { | ||
| 610 | 617 | export function paneCrew(db: Database, dataDir: string, repoId: string, reader: User | undefined, seen: RunsSeen): PaneCrew | undefined { |
| 611 | 618 | if (!seen.runs) return undefined; |
| 612 | 619 | 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") | |
| 614 | 621 | .get(repoId); |
| 615 | 622 | if (run === null) return undefined; |
| 616 | 623 | const steps: CrewItem[] = seen.logs |
| @@ -631,5 +638,9 @@ export function paneCrew(db: Database, dataDir: string, repoId: string, reader: | ||
| 631 | 638 | } |
| 632 | 639 | if (run.state === "running") return { ...at, state: "running", line: { says: `${who === "the crew" ? "The crew" : who} is working.` } }; |
| 633 | 640 | 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 } : {}) }; | |
| 635 | 646 | } |
src/crew/review.ts +1 −6
| @@ -28,7 +28,7 @@ import { teamsOfPull, teamVerdicts } from "../core/issue_teams.ts"; | ||
| 28 | 28 | import { listReviews, reviewSummariesFor, reviewSummary, type Review } from "../core/reviews.ts"; |
| 29 | 29 | import { verdictForHead } from "../core/runs.ts"; |
| 30 | 30 | 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"; | |
| 32 | 32 | import { createLog } from "../kernel/log.ts"; |
| 33 | 33 | import { guestWaits } from "../origins/guest.ts"; |
| 34 | 34 | import { reviewerPaused } from "./reviewer_paused.ts"; |
| @@ -209,11 +209,6 @@ export const NOT_REVIEWED_PREFIX = "not reviewed:"; | ||
| 209 | 209 | * it). |
| 210 | 210 | */ |
| 211 | 211 | 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:"; | |
| 217 | 212 | /** |
| 218 | 213 | * The summaries of a run that ended before its agent read anything: written from these constants. |
| 219 | 214 | */ |
src/crew/runner.ts +1 −2
| @@ -127,13 +127,12 @@ import { | ||
| 127 | 127 | NOT_REVIEWED_PREFIX, |
| 128 | 128 | noVerdictSummary, |
| 129 | 129 | overranWhere, |
| 130 | RUN_THREW_PREFIX, | |
| 131 | 130 | SEALED_FETCH_PREFIX, |
| 132 | 131 | touchesDesign, |
| 133 | 132 | waitingOnCheck, |
| 134 | 133 | } from "./review.ts"; |
| 135 | 134 | 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"; | |
| 137 | 136 | import { createLog, holdValues, redactValues, releaseValues } from "../kernel/log.ts"; |
| 138 | 137 | import { err, ok, type Result } from "../kernel/result.ts"; |
| 139 | 138 | import { holdLease } from "../runs/lease.ts"; |
src/kernel/budgets.ts +6
| @@ -56,6 +56,12 @@ export type BudgetLimits = { | ||
| 56 | 56 | /** The summary prefix every budget kill carries; vitals and retries read it. */ |
| 57 | 57 | export const BUDGET_PREFIX = "budget:"; |
| 58 | 58 | |
| 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 | ||
| 59 | 65 | /** What a run killed past its budget says as its summary. */ |
| 60 | 66 | export function budgetSummary( |
| 61 | 67 | 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"; | ||
| 34 | 34 | import { talkDisplayScreen } from "./talk_display.ts"; |
| 35 | 35 | import { conversationPulls, liveReceipts, paneCrew, paneFell, paneInfo, type LiveReceipt } from "../../core/talk_work.ts"; |
| 36 | 36 | 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"; | |
| 38 | 39 | import { confirmsScreen } from "./confirms.ts"; |
| 39 | 40 | import { waitingConfirms } from "../../actions/conversation_confirms.ts"; |
| 40 | 41 | 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 | ||
| 205 | 206 | if (crew === undefined) return []; |
| 206 | 207 | const l = crew.line; |
| 207 | 208 | 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}`]; | |
| 209 | 210 | }; |
| 210 | 211 | // Where the terminal's c says words: the pull shown, the crew's run's issue, else the newest receipt's. |
| 211 | 212 | 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 | ||
| 357 | 358 | binding(["v"], "steps open or folded"), |
| 358 | 359 | binding(["D"], "display"), |
| 359 | 360 | binding(["c"], "comment on the receipt's issue"), |
| 361 | binding(["t"], "try the crew's run again"), | |
| 360 | 362 | binding(["a"], "answer what waits"), |
| 361 | 363 | binding(["A", "S"], "the access wall: allow it, or send it back"), |
| 362 | 364 | binding(["d", "x"], "export as Markdown"), |
| @@ -537,6 +539,22 @@ function chatScreen(f: Session, ctx: Ctx, chat: Conversation, hit?: string): Scr | ||
| 537 | 539 | answerTheWall(e.key === "A" ? "allow" : "send_back"); |
| 538 | 540 | return true; |
| 539 | 541 | } |
| 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 | } | |
| 540 | 558 | if (e.key === "c") { |
| 541 | 559 | // As the page's crew box says it: on the pull whose preview the pane shows, else the issue the |
| 542 | 560 | // 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"; | ||
| 37 | 37 | import { notePhase, takeSessionTime } from "../../core/route_timing.ts"; |
| 38 | 38 | import type { Ctx } from "../../http/context.ts"; |
| 39 | 39 | import { loadRepo, notFoundPage, repoBase, signInFirst } from "../chrome.ts"; |
| 40 | import { field, readForm } from "../form.ts"; | |
| 40 | import { backTo, field, readForm } from "../form.ts"; | |
| 41 | 41 | import { html, when, type Html } from "../html.ts"; |
| 42 | 42 | import { badge } from "../ui.ts"; |
| 43 | 43 | import { flashTo, redirect } from "../layout.ts"; |
| @@ -480,7 +480,7 @@ const REQUEUE_REFUSED: Record<string, string> = { | ||
| 480 | 480 | }; |
| 481 | 481 | |
| 482 | 482 | // 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. | |
| 484 | 484 | export async function runRequeue(ctx: Ctx): Promise<Response> { |
| 485 | 485 | const repo = loadRepo(ctx); |
| 486 | 486 | if (!repo) return notFoundPage(ctx); |
| @@ -490,10 +490,10 @@ export async function runRequeue(ctx: Ctx): Promise<Response> { | ||
| 490 | 490 | const queued = requeueRepoRun(ctx.app, ctx.auth.user, repo, ctx.params.id ?? ""); |
| 491 | 491 | if (!queued.ok) { |
| 492 | 492 | if (queued.error === "not_found") return notFoundPage(ctx); |
| 493 | return flashTo(ctx, "/", { | |
| 493 | return flashTo(ctx, backTo(form, "/"), { | |
| 494 | 494 | tone: "danger", |
| 495 | 495 | message: REQUEUE_REFUSED[queued.error] ?? "You need write access to try a run again.", |
| 496 | 496 | }); |
| 497 | 497 | } |
| 498 | return flashTo(ctx, "/", { message: "Queued again." }); | |
| 498 | return flashTo(ctx, backTo(form, "/"), { message: "Queued again." }); | |
| 499 | 499 | } |
src/web/pages/talk_preview.ts +9 −6
| @@ -95,8 +95,8 @@ export async function talkPane(ctx: Ctx, user: User, name: string | undefined, w | ||
| 95 | 95 | : view === "diff" |
| 96 | 96 | ? await diffView(ctx.app, work, ask.version, ask.mine === undefined ? undefined : { ...ask.mine, picked: at.pull }) |
| 97 | 97 | : 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)}`; | |
| 100 | 100 | // The address bar of what runs: which environment, where it lives, reload and open on its own. |
| 101 | 101 | 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>`; |
| 102 | 102 | // 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 { | ||
| 149 | 149 | * whenever the pane is open, so the crew's next run (the person's next change) is picked up on |
| 150 | 150 | * run.* and drawn under the same frame, which the swap never touches. |
| 151 | 151 | */ |
| 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 { | |
| 153 | 153 | return crew === undefined |
| 154 | 154 | ? 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); | |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | /** |
| @@ -163,17 +163,20 @@ function crewRegion(crew: PaneCrew | undefined, repo: { readonly ownerName: stri | ||
| 163 | 163 | * works it folds to its one line (a `<details>`, the fold kept per conversation by the script); a |
| 164 | 164 | * hold or a failure is drawn open and unfoldable, so neither is ever hidden. |
| 165 | 165 | */ |
| 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 { | |
| 167 | 167 | const working = crew.state === "running" ? " talk-crew-working" : ""; |
| 168 | 168 | const line = html`<p class="small${working}">${workLineHtml(crew.line)}</p>`; |
| 169 | 169 | 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>`; |
| 170 | 170 | 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>`; | |
| 171 | 174 | // A pull's words go through its own page's door, an issue's through its own. |
| 172 | 175 | const reply = shows !== undefined ? crewReply(`${base}/pulls/${String(shows)}`, `#${String(shows)}`) : crew.issue === undefined ? null : crewReply(`${base}/issues/${String(crew.issue)}`, `#${String(crew.issue)}`); |
| 173 | 176 | // Its own live region: the crew's next run is read as it is queued, starts or ends, and the frame |
| 174 | 177 | // above it is never redrawn for it. |
| 175 | 178 | 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>`} | |
| 177 | 180 | </div>`; |
| 178 | 181 | } |
| 179 | 182 |
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 | ||
| 148 | 148 | expect(runsOf(hit.issue.id)).toBe(2); |
| 149 | 149 | expect(await home()).not.toContain(`/runs/${hit.id}/requeue`); |
| 150 | 150 | }); |
| 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 @@ | ||
| 7 | 7 | * #16227). Now the line names the cause, and a run the forge failed spends no try, up to |
| 8 | 8 | * `FORGE_FAULTS_FORGIVEN` a head. |
| 9 | 9 | */ |
| 10 | import { RUN_THREW_PREFIX } from "../src/kernel/budgets.ts"; | |
| 10 | 11 | import { seatAs } from "./helpers/seat.ts"; |
| 11 | 12 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; |
| 12 | 13 | import { mkdtemp, rm } from "node:fs/promises"; |
| @@ -26,7 +27,6 @@ import { deniedOf } from "../src/crew/claude.ts"; | ||
| 26 | 27 | import { |
| 27 | 28 | FORGE_FAULTS_FORGIVEN, |
| 28 | 29 | HARNESS_REFUSED, |
| 29 | RUN_THREW_PREFIX, | |
| 30 | 30 | failedAtStart, |
| 31 | 31 | forgeFault, |
| 32 | 32 | 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", () => { | ||
| 83 | 83 | if (!other.ok) throw new Error(other.error); |
| 84 | 84 | promote(app.db, other.value); |
| 85 | 85 | bob = other.value; |
| 86 | ctx = { app } as Ctx; | |
| 86 | ctx = { app, url: new URL("http://forge.test/talk") } as Ctx; | |
| 87 | 87 | }); |
| 88 | 88 | afterAll(async () => { |
| 89 | 89 | servers.stop(); |
| @@ -183,9 +183,11 @@ describe("the pane, by the crew's newest run on the repository", () => { | ||
| 183 | 183 | expect(posted.status).toBe(303); |
| 184 | 184 | 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"); |
| 185 | 185 | // 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]); | |
| 187 | 187 | const failed = (await talkPane(ctx, alice, name, new Map(), "preview", production)).html.text; |
| 188 | expect(failed).toContain("The crew'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'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">`); | |
| 189 | 191 | expect(failed).not.toContain("talk-crew-fold"); |
| 190 | 192 | }); |
| 191 | 193 | |
| @@ -234,8 +236,16 @@ describe("the pane, by the crew's newest run on the repository", () => { | ||
| 234 | 236 | expect(done.html.text).toContain("<p>Pushed its work</p>"); |
| 235 | 237 | expect(done.crew).toBe(false); |
| 236 | 238 | 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]); | |
| 237 | 240 | 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"); | |
| 239 | 249 | expect(ended.html.text).toContain( |
| 240 | 250 | `href="/${failed.name}/runs/${failed.run.id}"`, |
| 241 | 251 | ); |
| @@ -371,6 +381,29 @@ describe("the pane, by the crew's newest run on the repository", () => { | ||
| 371 | 381 | expect(text).toContain(`The whole run: /${name}/runs/${run.id}`); |
| 372 | 382 | }); |
| 373 | 383 | |
| 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 | ||
| 374 | 407 | test("framed, a finished run leaves the crew region empty; the crew's next run is swapped into it under the same frame", async () => { |
| 375 | 408 | const { repo, name } = await withRun("ok", ["→ Read src/a.ts"]); |
| 376 | 409 | const starter = { newestPull: () => undefined, urlOf: (_: unknown, env: string) => (env === "production" ? "https://clicker.apps.test/" : undefined) }; |
new above
offline