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

Merged opened this

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

Merged

scout/forge:scout/15741-a-cancelled-run-ends-its-whole-process-t → main 0 commits fork 2 threads · 2 unresolved

  • Merged. scout/15741-a-cancelled-run-ends-its-whole-process-t was merged into main as 86c2c06.

Review

Sign in to review this change.
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";
1818 import { emptyState } from "../ui/widgets.ts";
1919 import { subscribeRunLog } from "../../runs/log.ts";
2020 import { stoppedWords } from "../../runs/cancelled.ts";
21 import { withEnded } from "../../runs/ended_words.ts";
22 import { stillEnding } from "../../runs/ending.ts";
2123 import { Scroll, live, openOnWeb } from "./common.ts";
2224 import { costText, envLabel, runTone } from "./runwords.ts";
2325 import { priceWords } from "../../core/run_price.ts";
@@ -132,7 +134,9 @@ export function runLogScreen(
132134 const state = [
133135 run.state,
134136 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,
136140 costText(run.costUsd),
137141 isLive(run.state) ? "live" : "",
138142 ]
src/web/studio/run.ts +13 −1
@@ -24,6 +24,7 @@ import { canSeeOwnerFacts, type Repo } from "../../core/repos.ts";
2424 import { getRepoRun } from "../../actions/runs.ts";
2525 import { runCardPath } from "../og/path.ts";
2626 import { stoppedBy } from "../../runs/cancelled.ts";
27 import { endedJoin, endedWords } from "../../runs/ended_words.ts";
2728 import { agoWords } from "../../kernel/ago.ts";
2829 import { isTerminal, type Run } from "../../core/runs.ts";
2930 import { listHeldSecrets } from "../../core/run_secret.ts";
@@ -95,6 +96,17 @@ function stoppedLine(run: Run): Html | undefined {
9596 return html`Stopped by ${name}, ${time(iso, { text: agoWords(iso) })}`;
9697 }
9798
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 {
outdated

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.

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
98110 /**
99111 * GET /:owner/:name/runs/:id: who is on it, the tell it came from, the
100112 * 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(
220232 >`,
221233 )}
222234 </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."

224236 ${when(wayIn(ctx.app, ctx.auth.user, run.summary, repo), (way) => html`<div class="small" id="run-way">${blockedWay(way)}</div>`)}
225237 ${when(
226238 carried.length > 0,
test/run-stopped-words.test.ts +14 −1
@@ -14,6 +14,7 @@ import { claimRun, createRun, finishRun } from "../src/core/runs.ts";
1414 import { createSession } from "../src/core/sessions.ts";
1515 import { createUser } from "../src/core/users.ts";
1616 import { serve, type Servers } from "../src/http/server.ts";
17 import { endedWords, withEnded } from "../src/runs/ended_words.ts";
1718 import { cancelledBy, cancelledLine, stoppedBy, stoppedWords } from "../src/runs/cancelled.ts";
1819
1920 describe("the stop sentence", () => {
@@ -35,6 +36,16 @@ describe("the stop sentence", () => {
3536 });
3637 });
3738
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
3849 describe("a run stopped from the page", () => {
3950 let dataDir: string;
4051 let app: App;
@@ -82,7 +93,8 @@ describe("a run stopped from the page", () => {
8293 const text = await (await fetch(`${servers.url}/alice/garden/runs/${stoppedId}`, { headers: { cookie } })).text();
8394 const summary = text.match(/<p class="mt" id="run-summary">(.*?)<\/p>/s)?.[1] ?? "";
8495 // 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.");
8698 const time = summary.match(/<time datetime="([^"]+)" title="([^"]+)"\s*>just now<\/time\s*>/);
8799 expect(time).not.toBeNull();
88100 expect(Number.isFinite(Date.parse(time![1]!))).toBe(true);
@@ -101,5 +113,6 @@ describe("a run stopped from the page", () => {
101113 const text = await (await fetch(`${servers.url}/alice/garden/runs/${endedId}`, { headers: { cookie } })).text();
102114 expect(text).toContain(`id="run-summary">watered the plants</p>`);
103115 expect(text).not.toContain("Stopped by");
116 expect(text).not.toContain("still running");
104117 });
105118 });
test/tui-runlog.test.ts +20 −1
@@ -1,4 +1,5 @@
11 /** `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";
23 import { afterAll, beforeAll, expect, test } from "bun:test";
34 import { mkdtemp, rm } from "node:fs/promises";
45 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
8384 if (!stopped.ok) throw new Error(String(stopped.error));
8485 const app = await open(alice, run.id);
8586 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.");
8789 expect(text).not.toContain("cancelled by alice");
8890 });
8991
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
90109 test("a check that ran as a Job says, under its state, that its wall rests on the cluster too (#13251)", async () => {
91110 const run = createRun(forge.db, { repoId: repo.id, kind: "check" });
92111 claimRun(forge.db, run.id);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs