Public: anyone can read this; the crew can change it.
A cancelled run ends its whole process tree, proven with a run that spawned a grandchild #15758
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15741-a-cancelled-run-ends-its-whole-process-t → main 0 commits fork 2 threads · 2 unresolved
6 files
changed +87
−4
docs/features/run-cancel-ended.md added +14
| @@ -0,0 +1,14 @@ | ||
| 1 | --- | |
| 2 | topic: Tell the crew | |
| 3 | row: A stopped run says nothing is left running | |
| 4 | --- | |
| 5 | # A stopped run says nothing is left running (#15741) | |
| 6 | ||
| 7 | Stopping a run ends its whole process group: SIGTERM first, SIGKILL once the 1.5 s grace runs out (`src/runs/grace.ts`), a grandchild started by a shell command included (`test/run-cancel-tree.test.ts`). Both doors now say so on the stop's own line, once: | |
| 8 | ||
| 9 | - **The run's page:** "Stopped by alice, 2 minutes ago. Nothing it started is still running." | |
| 10 | - **The terminal's run log:** the same sentence on the state line. | |
| 11 | ||
| 12 | While the worker in this process is still ending the run's processes (`src/runs/ending.ts`), both say "Ending the processes it started." instead, and the page's head stays live until it turns. A run cancelled another way (its pull landed, a restart) closes its own summary with the same sentence. The words live in `src/runs/ended_words.ts`. | |
| 13 | ||
| 14 | Left out: the feed row keeps "Stopped by …" alone, a short row in a list of many. |
src/runs/ended_words.ts added +21
| @@ -0,0 +1,21 @@ | ||
| 1 | /** | |
| 2 | * What a cancel left behind, said once (#15741), by every door that shows a | |
| 3 | * cancelled run (the run's page and the terminal's run log). While the | |
| 4 | * run's worker is still ending its processes (`runs/ending.ts`) it says so; | |
| 5 | * once it has let go, that nothing it started is still running, the promise | |
| 6 | * a cancel keeps by ending the whole process group (`runs/grace.ts`). | |
| 7 | */ | |
| 8 | ||
| 9 | /** The sentence for a cancelled run, `ending` while its processes still end. */ | |
| 10 | export const endedWords = (ending: boolean): string => | |
| 11 | ending ? "Ending the processes it started." : "Nothing it started is still running."; | |
| 12 | ||
| 13 | /** What goes between `lead` and the sentence: nothing, a space, or a full stop. */ | |
| 14 | export function endedJoin(lead: string): string { | |
| 15 | const said = lead.trim(); | |
| 16 | return said === "" ? "" : /[.!?]$/.test(said) ? " " : ". "; | |
| 17 | } | |
| 18 | ||
| 19 | /** `lead` (the stop line or the summary) followed by `endedWords`, as one line. */ | |
| 20 | export const withEnded = (lead: string, ending: boolean): string => | |
| 21 | `${lead.trim()}${endedJoin(lead)}${endedWords(ending)}`; |
src/tui/screens/runlog.ts +5 −1
| @@ -18,6 +18,8 @@ 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 | 20 | import { stoppedWords } from "../../runs/cancelled.ts"; |
| 21 | import { withEnded } from "../../runs/ended_words.ts"; | |
| 22 | import { stillEnding } from "../../runs/ending.ts"; | |
| 21 | 23 | import { Scroll, live, openOnWeb } from "./common.ts"; |
| 22 | 24 | import { costText, envLabel, runTone } from "./runwords.ts"; |
| 23 | 25 | import { priceWords } from "../../core/run_price.ts"; |
| @@ -132,7 +134,9 @@ export function runLogScreen( | ||
| 132 | 134 | const state = [ |
| 133 | 135 | run.state, |
| 134 | 136 | run.kind === "deploy" ? `deploy ${envLabel(run.env)}` : run.kind, |
| 135 | stoppedWords(run, run.finishedAt) ?? run.summary, | |
| 137 | run.state === "cancelled" | |
| 138 | ? withEnded(stoppedWords(run, run.finishedAt) ?? run.summary, stillEnding(f.app.db, run.id)) | |
| 139 | : run.summary, | |
| 136 | 140 | costText(run.costUsd), |
| 137 | 141 | isLive(run.state) ? "live" : "", |
| 138 | 142 | ] |
src/web/studio/run.ts +13 −1
| @@ -24,6 +24,7 @@ import { canSeeOwnerFacts, type Repo } from "../../core/repos.ts"; | ||
| 24 | 24 | import { getRepoRun } from "../../actions/runs.ts"; |
| 25 | 25 | import { runCardPath } from "../og/path.ts"; |
| 26 | 26 | import { stoppedBy } from "../../runs/cancelled.ts"; |
| 27 | import { endedJoin, endedWords } from "../../runs/ended_words.ts"; | |
| 27 | 28 | import { agoWords } from "../../kernel/ago.ts"; |
| 28 | 29 | import { isTerminal, type Run } from "../../core/runs.ts"; |
| 29 | 30 | import { listHeldSecrets } from "../../core/run_secret.ts"; |
| @@ -95,6 +96,17 @@ function stoppedLine(run: Run): Html | undefined { | ||
| 95 | 96 | return html`Stopped by ${name}, ${time(iso, { text: agoWords(iso) })}`; |
| 96 | 97 | } |
| 97 | 98 | |
| 99 | /** | |
| 100 | * The ended sentence a cancelled run's summary closes with (#15741), on | |
| 101 | * the summary's own line so the stop is said once (`runs/ended_words.ts`, | |
| 102 | * which the terminal's run log says too). | |
| 103 | */ | |
| 104 | function endedTail(run: Run, ending: boolean): Html { | |
| 105 | // The stop line ends with its time, never a stop; else the summary itself leads. | |
| 106 | const lead = stoppedBy(run) === undefined ? run.summary : "Stopped"; | |
| 107 | return html`${endedJoin(lead)}${endedWords(ending)}`; | |
| 108 | } | |
| 109 | ||
| 98 | 110 | /** |
| 99 | 111 | * GET /:owner/:name/runs/:id: who is on it, the tell it came from, the |
| 100 | 112 | * commit a deploy or a check is about, how long it has gone and what it has |
| @@ -220,7 +232,7 @@ export async function runView( | ||
| 220 | 232 | >`, |
| 221 | 233 | )} |
| 222 | 234 | </div> |
| 223 | <p class="mt" id="run-summary">${stoppedLine(run) ?? run.summary}</p> | |
| 235 | <p class="mt" id="run-summary">${stoppedLine(run) ?? run.summary}${when(run.state === "cancelled", () => endedTail(run, word === "stopping"))}</p> | |
outdated
Both doors: the terminal run log does not show this sentence, so a person in the terminal cannot read that nothing is still running. Reuse endedWords in the tui run screen and test it. Principle 1: this sits right under "Stopped by …" and says the run ended again; say it once, e.g. extend the stop line with "Nothing it started is still running." |
||
| 224 | 236 | ${when(wayIn(ctx.app, ctx.auth.user, run.summary, repo), (way) => html`<div class="small" id="run-way">${blockedWay(way)}</div>`)} |
| 225 | 237 | ${when( |
| 226 | 238 | carried.length > 0, |
test/run-stopped-words.test.ts +14 −1
| @@ -14,6 +14,7 @@ import { claimRun, createRun, finishRun } from "../src/core/runs.ts"; | ||
| 14 | 14 | import { createSession } from "../src/core/sessions.ts"; |
| 15 | 15 | import { createUser } from "../src/core/users.ts"; |
| 16 | 16 | import { serve, type Servers } from "../src/http/server.ts"; |
| 17 | import { endedWords, withEnded } from "../src/runs/ended_words.ts"; | |
| 17 | 18 | import { cancelledBy, cancelledLine, stoppedBy, stoppedWords } from "../src/runs/cancelled.ts"; |
| 18 | 19 | |
| 19 | 20 | describe("the stop sentence", () => { |
| @@ -35,6 +36,16 @@ describe("the stop sentence", () => { | ||
| 35 | 36 | }); |
| 36 | 37 | }); |
| 37 | 38 | |
| 39 | describe("the ended line", () => { | |
| 40 | test("says the processes are ending while the run is stopping, and that nothing runs once it has", () => { | |
| 41 | expect(endedWords(true)).toBe("Ending the processes it started."); | |
| 42 | expect(endedWords(false)).toBe("Nothing it started is still running."); | |
| 43 | expect(withEnded("Stopped by alice", false)).toBe("Stopped by alice. Nothing it started is still running."); | |
| 44 | expect(withEnded("the pull landed.", false)).toBe("the pull landed. Nothing it started is still running."); | |
| 45 | expect(withEnded("", true)).toBe("Ending the processes it started."); | |
| 46 | }); | |
| 47 | }); | |
| 48 | ||
| 38 | 49 | describe("a run stopped from the page", () => { |
| 39 | 50 | let dataDir: string; |
| 40 | 51 | let app: App; |
| @@ -82,7 +93,8 @@ describe("a run stopped from the page", () => { | ||
| 82 | 93 | const text = await (await fetch(`${servers.url}/alice/garden/runs/${stoppedId}`, { headers: { cookie } })).text(); |
| 83 | 94 | const summary = text.match(/<p class="mt" id="run-summary">(.*?)<\/p>/s)?.[1] ?? ""; |
| 84 | 95 | // 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"); | |
| 96 | // Said once, on the stop's own line: who stopped it, when, and that nothing is left (#15741). | |
| 97 | expect(summary.replace(/<[^>]*>/g, "")).toBe("Stopped by alice, just now. Nothing it started is still running."); | |
| 86 | 98 | const time = summary.match(/<time datetime="([^"]+)" title="([^"]+)"\s*>just now<\/time\s*>/); |
| 87 | 99 | expect(time).not.toBeNull(); |
| 88 | 100 | expect(Number.isFinite(Date.parse(time![1]!))).toBe(true); |
| @@ -101,5 +113,6 @@ describe("a run stopped from the page", () => { | ||
| 101 | 113 | const text = await (await fetch(`${servers.url}/alice/garden/runs/${endedId}`, { headers: { cookie } })).text(); |
| 102 | 114 | expect(text).toContain(`id="run-summary">watered the plants</p>`); |
| 103 | 115 | expect(text).not.toContain("Stopped by"); |
| 116 | expect(text).not.toContain("still running"); | |
| 104 | 117 | }); |
| 105 | 118 | }); |
test/tui-runlog.test.ts +20 −1
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | /** `enter` on a run opens its log in the terminal, as MCP `run_log` reads it (#7306). */ |
| 2 | import { workBegins, workEnds } from "../src/runs/ending.ts"; | |
| 2 | 3 | import { afterAll, beforeAll, expect, test } from "bun:test"; |
| 3 | 4 | import { mkdtemp, rm } from "node:fs/promises"; |
| 4 | 5 | import { tmpdir } from "node:os"; |
| @@ -83,10 +84,28 @@ test("a run a person stopped says who stopped it on its state line (#13457)", as | ||
| 83 | 84 | if (!stopped.ok) throw new Error(String(stopped.error)); |
| 84 | 85 | const app = await open(alice, run.id); |
| 85 | 86 | const text = app.screen.toText(); |
| 86 | expect(text).toContain("Stopped by alice, just now"); | |
| 87 | // And, on the same line, that nothing it started is left running (#15741). | |
| 88 | expect(text).toContain("Stopped by alice, just now. Nothing it started is still running."); | |
| 87 | 89 | expect(text).not.toContain("cancelled by alice"); |
| 88 | 90 | }); |
| 89 | 91 | |
| 92 | test("a stopped run whose processes are still ending says so on its state line, then that nothing is left (#15741)", async () => { | |
| 93 | const run = createRun(forge.db, { repoId: repo.id, kind: "agent" }); | |
| 94 | claimRun(forge.db, run.id); | |
| 95 | workBegins(forge.db, run.id); | |
| 96 | try { | |
| 97 | const stopped = cancelRepoRun(forge, alice, repo, run.id); | |
| 98 | if (!stopped.ok) throw new Error(String(stopped.error)); | |
| 99 | const app = await open(alice, run.id); | |
| 100 | expect(app.screen.toText()).toContain("Stopped by alice, just now. Ending the processes it started."); | |
| 101 | expect(app.screen.toText()).not.toContain("still running"); | |
| 102 | } finally { | |
| 103 | workEnds(forge.db, run.id); | |
| 104 | } | |
| 105 | const after = await open(alice, run.id); | |
| 106 | expect(after.screen.toText()).toContain("Nothing it started is still running."); | |
| 107 | }); | |
| 108 | ||
| 90 | 109 | test("a check that ran as a Job says, under its state, that its wall rests on the cluster too (#13251)", async () => { |
| 91 | 110 | const run = createRun(forge.db, { repoId: repo.id, kind: "check" }); |
| 92 | 111 | claimRun(forge.db, run.id); |
new above
offline
A web module exporting a helper that the terminal should share: move endedWords to a small module under src/runs/ (next to cancelled.ts) so both doors import it rather than the TUI reaching into src/web.