Public: anyone can read this; the crew can change it.
A run cancelled from the page shows 'stopped' with the time and who stopped it, on the run's own page #13493
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/13457-a-run-cancelled-from-the-page-shows-stop → main 2 commits fork 2 threads · 2 unresolved
8 files
changed +191
−8
docs/features/run-state.md +1
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | |
| 3 | 3 | - **One function**: `runState` (`src/runs/state.ts`) names a run *waiting, working, needs input, failed, done* or *silent* from its row, its last sign of life and its plan — never from anything the run says about itself. The runs API rows carry it as `shown`; the runs tab and home badges read it. |
| 4 | 4 | - **Silent**: a running agent run with no log line and no plan update for 10 minutes. One `silent` flow alarm names the one silent longest (home, /boards, the notifier). Signs of life are kept in memory (`runs/activity.ts`); a run started before this process booted is measured from its start. Because the signs are in this process's memory only, during a roll a run that is logging to the other process, or one logging from before a restart, can read silent falsely; the alarm is then a prompt to look, not a verdict. |
| 5 | - **Stopped by a person** (#13457): a run someone cancels from its page reads *Stopped by alice, 2 minutes ago* — one sentence (`stoppedWords`, `src/runs/cancelled.ts`) on the run page, its feed row (kept a post, never folded as a quiet run) and the terminal's run log — in the quiet colour, never red. A run that ended on its own first keeps its real end. | |
| 5 | 6 | - **Repeat stop**: more than 3 agent runs on one issue in 10 minutes, whatever each said (`crew/repeat.ts`), parks the issue with one note and raises one `repeat` alarm; nothing starts until a person who directs the crew speaks. |
| 6 | 7 | - **Plan**: a run keeps up to 12 checklist items on its issue, replaced whole each time: `PUT /api/v1/repos/:owner/:name/issues/:number/plan` `{ items: [{ text, done? }], ask? }`, the MCP tool `keep_plan`, shown on the issue page and in `GET …/issues/:number` as `plan`. `ask` marks the run *needs input* until the next update. Only the agent with a run going on that issue may set its plan (a writer's or another run's call is refused, `forbidden`). Not an event: it is progress, like a log. |
| 7 | 8 | - **Runs tab count** is `runningCount`: running agent runs and checks, the sum of the pipeline's building, review and checking stages. |
src/feed/items.ts +13
| @@ -32,6 +32,7 @@ import { getRunErrorLine } from "../core/runs.ts"; | ||
| 32 | 32 | import { getUserById, type User } from "../core/users.ts"; |
| 33 | 33 | import { watchedBy } from "../core/watches.ts"; |
| 34 | 34 | import { CLOG_NOTE_WINDOW_MS, flattenNote } from "../flow/clog_note.ts"; |
| 35 | import { stoppedWords } from "../runs/cancelled.ts"; | |
| 35 | 36 | import { chooseCandidates } from "./choose.ts"; |
| 36 | 37 | import type { Foldable } from "./fold.ts"; |
| 37 | 38 | import { writeStamp } from "../core/write_clock.ts"; |
| @@ -676,6 +677,18 @@ function fromEvent( | ||
| 676 | 677 | ? `${link}?all=1#L${errorAt}` |
| 677 | 678 | : link; |
| 678 | 679 | const failure = errorLine === "" ? summary : errorLine; |
| 680 | // A person's stop is a calm ending, in the run page's own sentence (#13457). | |
| 681 | const stopped = stoppedWords( | |
| 682 | { state: String(p["state"] ?? ""), summary: typeof p["summary"] === "string" ? p["summary"] : "" }, | |
| 683 | e.createdAt, | |
| 684 | ); | |
| 685 | if (stopped !== undefined) | |
| 686 | return { | |
| 687 | ...common, | |
| 688 | kind: "run", | |
| 689 | link, | |
| 690 | what: `${/^[aeiou]/.test(kind) ? "an" : "a"} ${kind} run${subject}: ${stopped}`, | |
| 691 | }; | |
| 679 | 692 | if (kind === "agent" && cost >= COST_FLOOR_USD && ownerFacts) |
| 680 | 693 | return { |
| 681 | 694 | ...common, |
src/feed/quiet.ts +7 −4
| @@ -1,15 +1,17 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * Quiet runs: an agent run that finished without failing and left nothing |
| 3 | * behind — no push (to the repository or the agent's fork), no pull, no comment, no issue — is noise above the posts | |
| 4 | * that matter. The run's own record says so: its agent, and the window it | |
| 5 | * worked in, against what that agent wrote to the repository in that window. | |
| 6 | * A run the record cannot find is never called quiet. | |
| 3 | * behind — no push (to the repository or the agent's fork), no pull, no comment, no issue — is | |
| 4 | * noise above the posts that matter. The run's own record says so: its agent, and the window it | |
| 5 | * worked in, against what that agent wrote to the repository in that window. A run the record | |
| 6 | * cannot find is never called quiet, nor one a person stopped: they asked for that ending, so it | |
| 7 | * keeps its post (#13457). | |
| 7 | 8 | */ |
| 8 | 9 | |
| 9 | 10 | import type { Database } from "bun:sqlite"; |
| 10 | 11 | import type { ForgeEvent } from "../core/events.ts"; |
| 11 | 12 | import { getForkOf } from "../core/repos.ts"; |
| 12 | 13 | import { getRunsByIds } from "../core/runs.ts"; |
| 14 | import { stoppedBy } from "../runs/cancelled.ts"; | |
| 13 | 15 | |
| 14 | 16 | /** What an agent leaves behind that is worth a post of its own. */ |
| 15 | 17 | const LEFT_BEHIND = [ |
| @@ -57,6 +59,7 @@ export function quietRunEventIds( | ||
| 57 | 59 | run === undefined || |
| 58 | 60 | run.kind !== "agent" || |
| 59 | 61 | run.state === "failed" || |
| 62 | stoppedBy(run) !== undefined || | |
| 60 | 63 | run.actorId === null || |
| 61 | 64 | run.startedAt === null || |
| 62 | 65 | run.finishedAt === null |
src/runs/cancelled.ts +33 −1
| @@ -4,8 +4,16 @@ | ||
| 4 | 4 | * down, ends the run's log with that same line, so the log's last word says |
| 5 | 5 | * the run was cancelled and by whom. A run cancelled any other way (its |
| 6 | 6 | * pull landed, a budget, a restart) keeps the summary its own path writes. |
| 7 | * | |
| 8 | * A person's stop reads as a calm ending (#13457): "Stopped by alice, 2 | |
| 9 | * minutes ago", the one sentence the run page, the feed row and the | |
| 10 | * terminal's run log all say. A run that ended on its own just before the | |
| 11 | * stop keeps its real end: `cancelRun` only marks a queued or running row, | |
| 12 | * so its summary never says a person stopped it. | |
| 7 | 13 | */ |
| 8 | 14 | |
| 15 | import { agoWords } from "../kernel/ago.ts"; | |
| 16 | ||
| 9 | 17 | const PREFIX = "cancelled by "; |
| 10 | 18 | |
| 11 | 19 | /** The summary and the log's last line for a run `username` cancelled. */ |
| @@ -17,9 +25,33 @@ export const cancelledBy = (username: string): string => `${PREFIX}${username}`; | ||
| 17 | 25 | */ |
| 18 | 26 | export function cancelledLine( |
| 19 | 27 | row: { readonly state: string; readonly summary: string } | undefined, |
| 28 | ): string | undefined { | |
| 29 | return stoppedBy(row) === undefined ? undefined : row!.summary; | |
| 30 | } | |
| 31 | ||
| 32 | /** The name of the person who stopped the run, or nothing when nobody did. */ | |
| 33 | export function stoppedBy( | |
| 34 | row: { readonly state: string; readonly summary: string } | undefined, | |
| 20 | 35 | ): string | undefined { |
| 21 | 36 | if (row === undefined || row.state !== "cancelled") return undefined; |
| 22 | 37 | return row.summary.startsWith(PREFIX) && row.summary.length > PREFIX.length |
| 23 | ? row.summary | |
| 38 | ? row.summary.slice(PREFIX.length) | |
| 24 | 39 | : undefined; |
| 25 | 40 | } |
| 41 | ||
| 42 | /** | |
| 43 | * "Stopped by alice, 2 minutes ago" for a run a person stopped, `at` being | |
| 44 | * when it stopped (the row's `finishedAt`, or the event's own time); nothing | |
| 45 | * for any other run, so the caller keeps the summary it already shows. | |
| 46 | */ | |
| 47 | export function stoppedWords( | |
| 48 | row: { readonly state: string; readonly summary: string } | undefined, | |
| 49 | at: string | null, | |
| 50 | now: number = Date.now(), | |
| 51 | ): string | undefined { | |
| 52 | const name = stoppedBy(row); | |
| 53 | if (name === undefined) return undefined; | |
| 54 | return at === null || !Number.isFinite(Date.parse(at)) | |
| 55 | ? `Stopped by ${name}` | |
| 56 | : `Stopped by ${name}, ${agoWords(at, now)}`; | |
| 57 | } |
src/tui/screens/runlog.ts +2 −1
| @@ -17,6 +17,7 @@ import { truncate } from "../term/width.ts"; | ||
| 17 | 17 | import { fill, len, split } from "../ui/layout.ts"; |
| 18 | 18 | import { emptyState } from "../ui/widgets.ts"; |
| 19 | 19 | import { subscribeRunLog } from "../../runs/log.ts"; |
| 20 | import { stoppedWords } from "../../runs/cancelled.ts"; | |
| 20 | 21 | import { Scroll, live, openOnWeb } from "./common.ts"; |
| 21 | 22 | import { costText, envLabel, runTone } from "./runwords.ts"; |
| 22 | 23 | import { jobSandboxWords } from "../../checks/placement.ts"; |
| @@ -116,7 +117,7 @@ export function runLogScreen( | ||
| 116 | 117 | const state = [ |
| 117 | 118 | run.state, |
| 118 | 119 | run.kind === "deploy" ? `deploy ${envLabel(run.env)}` : run.kind, |
| 119 | run.summary, | |
| 120 | stoppedWords(run, run.finishedAt) ?? run.summary, | |
| 120 | 121 | costText(run.costUsd), |
| 121 | 122 | isLive(run.state) ? "live" : "", |
| 122 | 123 | ] |
src/web/studio/run.ts +18 −1
| @@ -22,6 +22,8 @@ import { getPull, openPullsClosing } from "../../core/pulls.ts"; | ||
| 22 | 22 | import { canSeeOwnerFacts, type Repo } from "../../core/repos.ts"; |
| 23 | 23 | import { getRepoRun } from "../../actions/runs.ts"; |
| 24 | 24 | import { runCardPath } from "../og/path.ts"; |
| 25 | import { stoppedBy } from "../../runs/cancelled.ts"; | |
| 26 | import { agoWords } from "../../kernel/ago.ts"; | |
| 25 | 27 | import { isTerminal, type Run } from "../../core/runs.ts"; |
| 26 | 28 | import { listHeldSecrets } from "../../core/run_secret.ts"; |
| 27 | 29 | import { getUserById } from "../../core/users.ts"; |
| @@ -78,6 +80,21 @@ export function vitalsBlock( | ||
| 78 | 80 | return run.kind === "check" && !logHidden ? vitalsTable(looks) : html``; |
| 79 | 81 | } |
| 80 | 82 | |
| 83 | /** | |
| 84 | * The stop sentence `stoppedWords` says, with its time in a `<time>` that | |
| 85 | * holds the exact instant (#13457): the words stay the same, a hover and a | |
| 86 | * screen reader get the real moment rather than a relative one gone stale. | |
| 87 | */ | |
| 88 | function stoppedLine(run: Run): Html | undefined { | |
| 89 | const name = stoppedBy(run); | |
| 90 | if (name === undefined) return undefined; | |
| 91 | const at = run.finishedAt === null ? Number.NaN : Date.parse(run.finishedAt); | |
| 92 | if (!Number.isFinite(at)) return html`Stopped by ${name}`; | |
| 93 | const iso = new Date(at).toISOString(); | |
| 94 | const exact = `${iso.slice(0, 16).replace("T", " ")} UTC`; | |
| 95 | return html`Stopped by ${name}, <time datetime="${iso}" title="${exact}">${agoWords(iso)}</time>`; | |
| 96 | } | |
| 97 | ||
| 81 | 98 | /** |
| 82 | 99 | * GET /:owner/:name/runs/:id: who is on it, the tell it came from, the |
| 83 | 100 | * commit a deploy or a check is about, how long it has gone and what it has |
| @@ -200,7 +217,7 @@ export async function runView( | ||
| 200 | 217 | >`, |
| 201 | 218 | )} |
| 202 | 219 | </div> |
| 203 | <p class="mt" id="run-summary">${run.summary}</p> | |
| 220 | <p class="mt" id="run-summary">${stoppedLine(run) ?? run.summary}</p> | |
| 204 | 221 | ${when(wayIn(ctx.app, ctx.auth.user, run.summary, repo), (way) => html`<div class="small" id="run-way">${blockedWay(way)}</div>`)} |
| 205 | 222 | ${when( |
| 206 | 223 | carried.length > 0, |
test/run-stopped-words.test.ts added +105
| @@ -0,0 +1,105 @@ | ||
| 1 | /** | |
| 2 | * A run a person stopped reads as a calm ending (#13457): "Stopped by | |
| 3 | * <name>, <time>" on the run's own page and on its feed row, in the quiet | |
| 4 | * colour, never the danger red; a run that ended on its own keeps its end. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 7 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { cancelRepoRun } from "../src/actions/runs.ts"; | |
| 11 | import { createRepo } from "../src/actions/repos.ts"; | |
| 12 | import { createApp, type App } from "../src/app.ts"; | |
| 13 | import { claimRun, createRun, finishRun } from "../src/core/runs.ts"; | |
| 14 | import { createSession } from "../src/core/sessions.ts"; | |
| 15 | import { createUser } from "../src/core/users.ts"; | |
| 16 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 17 | import { cancelledBy, cancelledLine, stoppedBy, stoppedWords } from "../src/runs/cancelled.ts"; | |
| 18 | ||
| 19 | describe("the stop sentence", () => { | |
| 20 | const at = "2026-11-15T10:00:00.000Z"; | |
| 21 | const now = Date.parse(at) + 3 * 60_000; | |
| 22 | ||
| 23 | test("names who stopped it and when", () => { | |
| 24 | const row = { state: "cancelled", summary: cancelledBy("alice") }; | |
| 25 | expect(stoppedBy(row)).toBe("alice"); | |
| 26 | expect(stoppedWords(row, at, now)).toBe("Stopped by alice, 3 minutes ago"); | |
| 27 | expect(stoppedWords(row, null, now)).toBe("Stopped by alice"); | |
| 28 | expect(cancelledLine(row)).toBe("cancelled by alice"); | |
| 29 | }); | |
| 30 | ||
| 31 | test("says nothing for a run nobody stopped", () => { | |
| 32 | expect(stoppedWords({ state: "cancelled", summary: "the pull landed" }, at, now)).toBeUndefined(); | |
| 33 | expect(stoppedWords({ state: "ok", summary: cancelledBy("alice") }, at, now)).toBeUndefined(); | |
| 34 | expect(stoppedWords({ state: "cancelled", summary: "cancelled by " }, at, now)).toBeUndefined(); | |
| 35 | }); | |
| 36 | }); | |
| 37 | ||
| 38 | describe("a run stopped from the page", () => { | |
| 39 | let dataDir: string; | |
| 40 | let app: App; | |
| 41 | let servers: Servers; | |
| 42 | let cookie: string; | |
| 43 | let stoppedId: string; | |
| 44 | let endedId: string; | |
| 45 | ||
| 46 | beforeAll(async () => { | |
| 47 | dataDir = await mkdtemp(join(tmpdir(), "forge-run-stopped-")); | |
| 48 | app = createApp({ dataDir, port: 0 }); | |
| 49 | servers = await serve(app); | |
| 50 | const u = await createUser(app.db, { | |
| 51 | origin: "seed", trusted: true, username: "alice", | |
| 52 | email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true, | |
| 53 | }); | |
| 54 | if (!u.ok) throw new Error(u.error); | |
| 55 | cookie = `forge_session=${createSession(app.db, u.value.id).token}`; | |
| 56 | const made = await createRepo(app, u.value, { name: "garden", visibility: "public" }); | |
| 57 | if (!made.ok) throw new Error(String(made.error)); | |
| 58 | const repo = made.value; | |
| 59 | ||
| 60 | const run = createRun(app.db, { repoId: repo.id, kind: "agent", actorId: u.value.id }); | |
| 61 | stoppedId = run.id; | |
| 62 | claimRun(app.db, run.id); | |
| 63 | const stopped = cancelRepoRun(app, u.value, repo, run.id); | |
| 64 | if (!stopped.ok) throw new Error(String(stopped.error)); | |
| 65 | ||
| 66 | // Ended on its own just before the stop: the stop is refused, the real end stays. | |
| 67 | const other = createRun(app.db, { repoId: repo.id, kind: "agent", actorId: u.value.id }); | |
| 68 | endedId = other.id; | |
| 69 | claimRun(app.db, other.id); | |
| 70 | finishRun(app.db, other.id, { state: "ok", summary: "watered the plants" }); | |
| 71 | const late = cancelRepoRun(app, u.value, repo, other.id); | |
| 72 | if (late.ok) throw new Error("a finished run was cancelled"); | |
| 73 | }); | |
| 74 | ||
| 75 | afterAll(async () => { | |
| 76 | servers.stop(); | |
| 77 | app.close(); | |
| 78 | await rm(dataDir, { recursive: true, force: true }); | |
| 79 | }); | |
| 80 | ||
| 81 | test("the run page says who stopped it and when, in the quiet colour", async () => { | |
| 82 | const text = await (await fetch(`${servers.url}/alice/garden/runs/${stoppedId}`, { headers: { cookie } })).text(); | |
| 83 | const summary = text.match(/<p class="mt" id="run-summary">(.*?)<\/p>/s)?.[1] ?? ""; | |
| 84 | // The words are the sentence the feed and the terminal say; the time holds the exact instant. | |
| 85 | expect(summary.replace(/<[^>]*>/g, "")).toBe("Stopped by alice, just now"); | |
| 86 | const time = summary.match(/<time datetime="([^"]+)" title="([^"]+)">just now<\/time>/); | |
| 87 | expect(time).not.toBeNull(); | |
| 88 | expect(Number.isFinite(Date.parse(time![1]!))).toBe(true); | |
| 89 | expect(time![2]).toBe(`${time![1]!.slice(0, 16).replace("T", " ")} UTC`); | |
| 90 | const badge = text.match(/<span[^>]*id="run-word"[^>]*>/)?.[0] ?? ""; | |
| 91 | expect(badge).toContain('data-variant="secondary"'); | |
| 92 | expect(badge).not.toContain("danger"); | |
| 93 | }); | |
| 94 | ||
| 95 | test("the feed row uses the same sentence", async () => { | |
| 96 | const text = await (await fetch(`${servers.url}/feed`, { headers: { cookie: `${cookie}; forge_mode=studio` } })).text(); | |
| 97 | expect(text).toContain("an agent run: Stopped by alice, just now"); | |
| 98 | }); | |
| 99 | ||
| 100 | test("a run that ended on its own before the stop shows its real end", async () => { | |
| 101 | const text = await (await fetch(`${servers.url}/alice/garden/runs/${endedId}`, { headers: { cookie } })).text(); | |
| 102 | expect(text).toContain(`id="run-summary">watered the plants</p>`); | |
| 103 | expect(text).not.toContain("Stopped by"); | |
| 104 | }); | |
| 105 | }); |
test/tui-runlog.test.ts +12 −1
| @@ -4,7 +4,7 @@ import { mkdtemp, rm } from "node:fs/promises"; | ||
| 4 | 4 | import { tmpdir } from "node:os"; |
| 5 | 5 | import { join } from "node:path"; |
| 6 | 6 | import { appendFileSync } from "node:fs"; |
| 7 | import { announceRun } from "../src/actions/runs.ts"; | |
| 7 | import { announceRun, cancelRepoRun } from "../src/actions/runs.ts"; | |
| 8 | 8 | import { createRepo } from "../src/actions/repos.ts"; |
| 9 | 9 | import { createApp, type App as Forge } from "../src/app.ts"; |
| 10 | 10 | import { claimRun, createRun, finishRun, noteRunProgress } from "../src/core/runs.ts"; |
| @@ -75,6 +75,17 @@ test("a finished run shows its state and its last 200 lines, at the end", async | ||
| 75 | 75 | expect(app.screen.toText()).not.toContain("\nline-100\n"); |
| 76 | 76 | }); |
| 77 | 77 | |
| 78 | test("a run a person stopped says who stopped it on its state line (#13457)", async () => { | |
| 79 | const run = createRun(forge.db, { repoId: repo.id, kind: "agent" }); | |
| 80 | claimRun(forge.db, run.id); | |
| 81 | const stopped = cancelRepoRun(forge, alice, repo, run.id); | |
| 82 | if (!stopped.ok) throw new Error(String(stopped.error)); | |
| 83 | const app = await open(alice, run.id); | |
| 84 | const text = app.screen.toText(); | |
| 85 | expect(text).toContain("Stopped by alice, just now"); | |
| 86 | expect(text).not.toContain("cancelled by alice"); | |
| 87 | }); | |
| 88 | ||
| 78 | 89 | test("a check that ran as a Job says, under its state, that its wall rests on the cluster too (#13251)", async () => { |
| 79 | 90 | const run = createRun(forge.db, { repoId: repo.id, kind: "check" }); |
| 80 | 91 | claimRun(forge.db, run.id); |
new above
offline
No test covers this line. Add a runlog screen test (cancelled-by run) that fails if it is reverted.