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

Review runs fail at once, at $0.00, so pulls sit with no reviewer answer #16107

Merged opened this in answer to

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

Merged

scout/forge:scout/16096-review-runs-fail-at-once-at-0-00-so-pull → main 0 commits fork 2 threads · 2 unresolved

  • Merged. scout/16096-review-runs-fail-at-once-at-0-00-so-pull was merged into main as 4a5b56b.

Review

Sign in to review this change.
8 files changed +368 −19
docs/features/review-failed-start.md added +36
@@ -0,0 +1,36 @@
1 ---
2 topic: Tell the crew
3 row: A review that never started says "review failed to start"
4 ---
5 # A review that never started says so (#16096)
6
7 A green agent pull goes to the crew's reviewer. A review run can end before its
8 agent reads a word: the run spent its whole 10 min budget in the brief, or the
9 pull's head could not be checked out (`not reviewed: …`), or the sealed head
10 could not be fetched. Such a run ends with no turn and $0.00.
11
12 ## What is new
13
14 - The run is held to its budget as a whole. When the budget runs out the forge
15 aborts the run and, if a step of the brief ignores the abort, leaves it behind
16 after a 5 s grace and ends the run, so a stalled brief no longer holds the run
17 for 15 min or more past the budget.
18 - A head gets two review runs (`REVIEW_TRIES`, as before). When both ended
19 without the reviewer reading the pull, the pull no longer says "the reviewer
20 did not answer"; it says **review failed to start**. A reviewer that read and
21 posted nothing still says "did not answer".
22
23 ## Where it appears
24
25 Home's "waiting for your review" rows, the asks list in the studio, and the
26 terminal's crew rows all use the same sentence (`review_says.ts`).
27
28 ## What a person does
29
30 Look at the review runs' logs on the pull. If the cause was the crew (a clone
31 or fetch that died), review the pull yourself or push again to start a fresh
32 head. The pull waits for you either way; nothing lands on its own.
33
34 The summaries `failedAtStart` reads are written from shared constants
35 (`BUDGET_PREFIX`, `NOT_REVIEWED_PREFIX`, `SEALED_FETCH_PREFIX`), and a test
36 holds the runner to them.
src/crew/review.ts +44 −9
@@ -28,6 +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";
3132 import { createLog } from "../kernel/log.ts";
3233 import { guestWaits } from "../origins/guest.ts";
3334 import { reviewerPaused } from "./reviewer_paused.ts";
@@ -185,11 +186,43 @@ const REVIEW_TRIES = 2;
185186 /** One review run sent for a head: when it was queued, and whether it is still out. */
186187 export interface ReviewAttempt {
187188 readonly createdAt: string;
189 readonly finishedAt?: string | null;
190 readonly cancelled?: boolean;
188191 readonly active: boolean;
189192 /** The reviewer the run was sent to. */
190193 readonly reviewerId?: string | null;
194 /**
outdated

Regex on summary text is the only link to the code that writes those summaries. Share constants or a structured field.

195 * The run ended before its agent took a turn and spent nothing: the reviewer never read the pull.
196 */
197 readonly failedToStart?: boolean;
191198 }
192199
200 /**
201 * What a run's summary starts with when its review head could not be checked out (`runner.ts`
202 * writes it).
203 */
204 export const NOT_REVIEWED_PREFIX = "not reviewed:";
205 /**
206 * What a run's summary starts with when the sealed head could not be fetched (`runner.ts` writes
207 * it).
208 */
209 export const SEALED_FETCH_PREFIX = "fetch of the sealed head failed:";
210 /**
211 * The summaries of a run that ended before its agent read anything: written from these constants.
212 */
213 const START_FAILURES = [BUDGET_PREFIX, NOT_REVIEWED_PREFIX, SEALED_FETCH_PREFIX];
214
215 /**
216 * Whether an ended review run never reached the reviewer's reading (#16096): it failed or was
217 * cut off with no turn and no cost, its words a budget overrun spent in the brief or a head it
218 * could not check out. A review that read and said nothing is `lapsed`; this one is a start
219 * that failed, and the pull says so.
220 */
221 export const failedAtStart = (state: string, summary: string | null, turns: number): boolean =>
222 turns === 0 &&
223 (state === "failed" || state === "cancelled") &&
224 START_FAILURES.some((prefix) => (summary ?? "").trim().toLowerCase().startsWith(prefix.toLowerCase()));
225
193226 /**
194227 * A head that went green this long after the lapse, with no review yet,
195228 * is still sent once, late; past it, nothing was ever going to send.
@@ -268,16 +301,13 @@ export function reviewAttemptsFor(
268301 )
269302 .all(...batch.flatMap((p) => [p.id, p.headOid]));
270303 const released = lastReleasesFor(db, ids);
271 const reviews = new Map<
272 string,
273 { createdAt: string; finishedAt: string | null; cancelled: boolean; active: boolean; reviewerId: string | null }[]
274 >();
304 const reviews = new Map<string, ReviewAttempt[]>();
275305 for (const r of db
276306 .query<
277 { issue_id: string; created_at: string; finished_at: string | null; state: string; actor_id: string | null; summary: string | null },
307 { issue_id: string; created_at: string; finished_at: string | null; state: string; actor_id: string | null; summary: string | null; turns: number },
278308 string[]
279309 >(
280 `SELECT issue_id, created_at, finished_at, state, actor_id, summary FROM run INDEXED BY run_review_attempts
310 `SELECT issue_id, created_at, finished_at, state, actor_id, summary, turns FROM run INDEXED BY run_review_attempts
281311 WHERE kind = 'agent' AND reason = 'review'
282312 AND issue_id IN (${ids.map((_, n) => `?${n + 1}`).join(",")})
283313 ORDER BY created_at, id`,
@@ -286,12 +316,13 @@ export function reviewAttemptsFor(
286316 if (diedBeforeAgent(r.state, r.summary)) continue;
287317 // A run that stood down for the check queue was never an attempt (#16094).
288318 if (r.state === "cancelled" && r.summary === CHECK_PENDING_SUMMARY) continue;
289 const attempt = {
319 const attempt: ReviewAttempt = {
290320 finishedAt: r.finished_at,
291321 cancelled: r.state === "cancelled",
292322 createdAt: r.created_at,
293323 active: r.state === "queued" || r.state === "running",
294324 reviewerId: r.actor_id,
325 failedToStart: failedAtStart(r.state, r.summary, r.turns),
295326 };
296327 const list = reviews.get(r.issue_id);
297328 if (list) list.push(attempt);
@@ -377,7 +408,7 @@ export function stageOf(
377408
378409 /** Why an agent's green pull waits for a person, and since when. */
379410 export interface ReviewWait {
380 readonly why: "no reviewer" | "lapsed" | "rounds";
411 readonly why: "no reviewer" | "lapsed" | "rounds" | "failed to start";
381412 /** When review became owed: the head went green, or the pull was let go. */
382413 readonly since: string;
383414 /** Minutes the check took, when the review was sent late because of it. */
@@ -485,7 +516,11 @@ export function reviewWaitsFor(
485516 ? { why: "no reviewer", since: history.greenAt }
486517 : stage === "lapsed"
487518 ? {
488 why: "lapsed",
519 // Asked twice and neither run reached its agent: say so, not "did not answer".
520 why:
521 history.attempts.length >= REVIEW_TRIES && history.attempts.every((a) => a.failedToStart === true)
522 ? "failed to start"
523 : "lapsed",
489524 since: history.greenAt,
490525 ...(history.lateAt === undefined
491526 ? {}
src/crew/review_says.ts +1
@@ -8,6 +8,7 @@ import type { ReviewWait } from "./review.ts";
88 /** The reason alone, without its date. */
99 export function reviewSays(wait: ReviewWait | undefined, paused: boolean): string {
1010 if (wait?.why === "rounds") return "the reviewer asked for changes three times";
11 if (wait?.why === "failed to start") return "review failed to start";
1112 if (wait?.why === "lapsed" && paused) return "the reviewer is paused";
1213 if (wait?.why === "lapsed" && wait.lateCheckMinutes !== undefined)
1314 return `review ran late: the check took ${wait.lateCheckMinutes} min, and the reviewer did not answer`;
src/crew/runner.ts +44 −9
@@ -122,9 +122,15 @@ import {
122122 namedCommits,
123123 onBase,
124124 } from "./already.ts";
125 import { CHECK_PENDING_SUMMARY, touchesDesign, waitingOnCheck } from "./review.ts";
125 import {
126 CHECK_PENDING_SUMMARY,
127 NOT_REVIEWED_PREFIX,
128 SEALED_FETCH_PREFIX,
129 touchesDesign,
130 waitingOnCheck,
131 } from "./review.ts";
126132 import { fetchSealedHead, SEALED_REMOTE, sealedHeadRepo } from "./sealed_head.ts";
127 import { BUDGETS, budgetSummary } from "../kernel/budgets.ts";
133 import { BUDGETS, BUDGET_PREFIX, budgetSummary } from "../kernel/budgets.ts";
128134 import { createLog, holdValues, redactValues, releaseValues } from "../kernel/log.ts";
129135 import { err, ok, type Result } from "../kernel/result.ts";
130136 import { holdLease } from "../runs/lease.ts";
@@ -241,6 +247,11 @@ export interface CrewOptions {
241247 readonly networkRetryScale?: number | undefined;
242248 /** How long a review run may take. @default BUDGETS.review */
243249 readonly reviewBudgetMs?: number | undefined;
250 /**
251 * How long past its budget a review run is waited for before it is left behind (tests shorten
252 * it).
253 */
254 readonly reviewGraceMs?: number | undefined;
244255 /** A `CLAUDE_CONFIG_DIR` for runs, when the operator wants one. */
245256 readonly configDir?: string | undefined;
246257 /** Hosts an agent's shell may reach beyond the forge and the registry. */
@@ -296,6 +307,9 @@ export function steerRun(app: App, runId: string, text: string): boolean {
296307 return send(text);
297308 }
298309
310 /** After the abort, how long a run gets to wind down before the forge ends it without it. */
311 const OVERRUN_GRACE_MS = 5_000;
312
299313 /**
300314 * What a reviewer reads: the pull's diff (`review_range.ts` — a landed pull's
301315 * is its merge commit's), and its pictures. `landedAs` names the merge commit
@@ -307,6 +321,11 @@ export async function reviewInputs(
307321 pull: Pull,
308322 record: AppRecord | undefined,
309323 bare: string,
324 /**
325 * The run's own: a review past its budget stops reading the diff instead of finishing it
326 * (#16096).
outdated

Only these two git calls honour the abort; the stall is elsewhere in the brief by your own logs. Time-box the whole brief.

327 */
328 signal?: AbortSignal,
310329 ): Promise<{
311330 reviewDiff: string;
312331 looks: string[];
@@ -319,7 +338,7 @@ export async function reviewInputs(
319338 if (range !== undefined) {
320339 const names = await runGitCapture(
321340 ["diff", "--name-only", range.from, range.to],
322 { cwd: bare },
341 { cwd: bare, ...(signal === undefined ? {} : { signal }) },
323342 );
324343 design = touchesDesign(
325344 names.stdout
@@ -329,7 +348,7 @@ export async function reviewInputs(
329348 );
330349 const out = await runGitCapture(
331350 ["diff", "--stat", "-p", range.from, range.to],
332 { cwd: bare },
351 { cwd: bare, ...(signal === undefined ? {} : { signal }) },
333352 );
334353 const text = out.stdout.toString();
335354 if (out.code === 0)
@@ -511,11 +530,23 @@ async function runClaimed(
511530 const started = Date.now();
512531 // A reviewer past its budget is stopped, whatever it is doing.
513532 let overran = false;
533 // The budget ends the run, not only the agent: a step of the brief that ignores the abort (a
534 // stalled read) is left behind once the grace is up, so a review stops at its budget and not
535 // when the stall does (#16096).
536 let giveUp: (o: Outcome) => void = () => {};
537 const gaveUp = new Promise<Outcome>((r) => {
538 giveUp = r;
539 });
540 let grace: ReturnType<typeof setTimeout> | undefined;
514541 const clock =
515542 claimed.reason === "review"
516543 ? setTimeout(() => {
517544 overran = true;
518545 controller.abort();
546 grace = setTimeout(
547 () => giveUp({ state: "failed", summary: `${BUDGET_PREFIX} the run did not stop when aborted` }),
548 options.reviewGraceMs ?? OVERRUN_GRACE_MS,
549 );
519550 }, options.reviewBudgetMs ?? BUDGETS.review)
520551 : undefined;
521552 const meter: Meter = {
@@ -529,7 +560,7 @@ async function runClaimed(
529560 };
530561 let outcome: Outcome;
531562 try {
532 outcome = await work(
563 const working = work(
533564 app,
534565 claimed,
535566 options,
@@ -539,6 +570,9 @@ async function runClaimed(
539570 watch,
540571 began,
541572 );
573 // A run left behind may still reject later: that is no one's to handle.
574 working.catch(() => {});
575 outcome = await Promise.race([working, gaveUp]);
542576 } catch (error) {
543577 log.error("agent run threw", { run: run.id, error: String(error) });
544578 outcome = {
@@ -547,6 +581,7 @@ async function runClaimed(
547581 };
548582 } finally {
549583 clearTimeout(clock);
584 clearTimeout(grace);
550585 untrackAgentRun(run.id);
551586 steering.delete(run.id);
552587 lease();
@@ -1272,7 +1307,7 @@ async function work(
12721307 GIT_TRANSFER_MS,
12731308 );
12741309 if (!fetched.ok)
1275 return { state: "failed", summary: `fetch of the sealed head failed: ${fetched.error}` };
1310 return { state: "failed", summary: `${SEALED_FETCH_PREFIX} ${fetched.error}` };
12761311 write(`sealed head: ${sealedHead.ownerName}/${sealedHead.name} ${pull.headBranch} fetched as ${fetched.ref}`);
12771312 }
12781313 // Counted once made: a clone that failed is no hop on the line.
@@ -1292,9 +1327,9 @@ async function work(
12921327 timeoutMs: GIT_TRANSFER_MS,
12931328 });
12941329 if (!head.ok) {
1295 write(`not reviewed: ${head.why}`);
1330 write(`${NOT_REVIEWED_PREFIX} ${head.why}`);
12961331 noteUnreviewed(app.db, pull, agent.user.id, head.oid, head.why);
1297 return { state: "failed", summary: `not reviewed: ${head.why}` };
1332 return { state: "failed", summary: `${NOT_REVIEWED_PREFIX} ${head.why}` };
12981333 }
12991334 write(`reviewing head ${head.oid.slice(0, 12)}, checked out as ${branch}`);
13001335 }
@@ -1425,7 +1460,7 @@ async function work(
14251460 ...(reason === "review" && pull
14261461 ? {
14271462 // A sealed pull's head is in its builder's sealed fork, not the base (#14917).
1428 ...(await reviewInputs(app, repo, pull, record, await pullDir(app.db, app.reposRoot, repo, pull))),
1463 ...(await reviewInputs(app, repo, pull, record, await pullDir(app.db, app.reposRoot, repo, pull), signal)),
14291464 sourceNote: await reviewSourceNote(app, repo, pull, bare),
14301465 ...(sealedHead === undefined ? {} : { sealedRef: `${SEALED_REMOTE}/${pull.headBranch}` }),
14311466 boxes: boxesOf(app, repo, pull),
test/crew-review-stall.test.ts added +62
@@ -0,0 +1,62 @@
1 /**
2 * A review run whose brief stalls is ended at its budget (#16096). Apart from
3 * `crew-review-budget.test.ts`: two stand-in crews do not share a process.
4 */
5
6 import { seatAs } from "./helpers/seat.ts";
7 import { describe, expect, test } from "bun:test";
8 import { addToCrew, createAgent } from "../src/actions/crew.ts";
9 import { openPull } from "../src/actions/pulls.ts";
10 import { commitToBranch } from "../src/actions/repos.ts";
11 import { queueAgentRun } from "../src/crew/dispatch.ts";
12 import { getIssue } from "../src/core/issues.ts";
13 import { ok } from "../src/kernel/result.ts";
14 import { agentRunSettled, startStandInCrew, stopStandInCrew } from "./helpers/crew-standin.ts";
15
16 describe("the crew, with a stand-in Claude Code: a stalled brief", () => {
17 test("a review that stalls before its agent is ended at its budget, not when the stall ends", async () => {
18 const standIn = await startStandInCrew({
19 reviewBudgetMs: 300,
20 reviewGraceMs: 200,
21 tickMs: 50,
22 files: [{ path: "package.json", content: "{}\n" }],
23 // Never answers and ignores the abort: the stall the production runs sat in for 24 min.
24 // The check passes at once: a review waits on a pending check and would never start.
25 checkStep: async () => ok(),
26 installRunner: () => new Promise(() => {}),
27 });
28 try {
29 const { app, alice, repo } = standIn;
30 const made = await createAgent(app, alice, { username: "stallrev" });
31 if (!made.ok) throw new Error(String(made.error));
32 expect(addToCrew(app, alice, repo, "stallrev").ok).toBe(true);
33 seatAs(app.db, repo.id, made.value.user.id, "reviewer");
34 const branch = await commitToBranch(app, alice, repo, {
35 branch: "stall-fence",
36 base: "main",
37 message: "A stalled fence",
38 files: [{ path: "STALL.md", content: "stall\n" }],
39 });
40 if (!branch.ok) throw new Error(JSON.stringify(branch.error));
41 const opened = await openPull(app, alice, repo, {
42 title: "STALL fence",
43 baseBranch: "main",
44 headBranch: "stall-fence",
45 });
46 if (!opened.ok) throw new Error(String(opened.error));
47 const issue = getIssue(app.db, repo.id, opened.value.number)!;
48 expect(queueAgentRun(app, repo, issue, made.value, "review")).toBeDefined();
49 const failed = await agentRunSettled(
50 app,
51 repo,
52 (r) => r.reason === "review" && r.issueId === issue.id && r.summary?.startsWith("budget:") === true,
53 8_000,
54 );
55 // The first overrun is queued again, the second fails: either ended at the budget.
56 expect(failed.summary).toMatch(/^budget: a review run took/);
57 } finally {
58 await stopStandInCrew(standIn);
59 }
60 }, 15_000);
61 });
62
test/helpers/crew-standin.ts +3
@@ -55,6 +55,8 @@ export const STAND_IN_TICK_MS = 50;
5555 export async function startStandInCrew(
5656 options: {
5757 readonly reviewBudgetMs?: number;
58 /** How long past its budget a review run is waited for. */
59 readonly reviewGraceMs?: number;
5860 readonly tickMs?: number;
5961 /** How often autonomous repositories take a turn (the forge's own minute when unset). */
6062 readonly autonomyEveryMs?: number;
@@ -85,6 +87,7 @@ export async function startStandInCrew(
8587 runTimeoutMs: 60_000,
8688 networkRetryScale: 0,
8789 reviewBudgetMs: options.reviewBudgetMs ?? 4_000,
90 ...(options.reviewGraceMs === undefined ? {} : { reviewGraceMs: options.reviewGraceMs }),
8891 tickMs: options.tickMs ?? STAND_IN_TICK_MS,
8992 ...(options.autonomyEveryMs === undefined ? {} : { autonomyEveryMs: options.autonomyEveryMs }),
9093 ...(options.now === undefined ? {} : { now: options.now }),
test/review-failed-start.test.ts added +176
@@ -0,0 +1,176 @@
1 /**
2 * A review run that fails at its start is retried once, then said on the pull (#16096). On
3 * 2026-11-23 review runs spent their whole 10 min budget in the brief, before the agent took a
4 * turn, ending at $0.00; the pulls then read "the reviewer did not answer", as if it had been
5 * asked and read them. A start that failed twice says "review failed to start".
6 */
7 import { seatAs } from "./helpers/seat.ts";
8 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
9 import { mkdtemp, rm } from "node:fs/promises";
10 import { tmpdir } from "node:os";
11 import { join } from "node:path";
12 import { createApp, type App } from "../src/app.ts";
13 import { addToCrew, createAgent } from "../src/actions/crew.ts";
14 import { openPull } from "../src/actions/pulls.ts";
15 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
16 import { type Pull } from "../src/core/pulls.ts";
17 import { type Repo } from "../src/core/repos.ts";
18 import { createApp as createAppRecord } from "../src/core/apps.ts";
19 import { createRun, listRuns } from "../src/core/runs.ts";
20 import { createUser, getUserByName, type User } from "../src/core/users.ts";
21 import { markVerified } from "../src/core/verify.ts";
22 import { failedAtStart, sendToReview, waitsForPerson } from "../src/crew/review.ts";
23 import { crewNow } from "../src/actions/crew_now.ts";
24 import { reviewWhy } from "../src/web/studio/asks.ts";
25 import { NOT_REVIEWED_PREFIX, SEALED_FETCH_PREFIX } from "../src/crew/review.ts";
26 import { reviewSays } from "../src/crew/review_says.ts";
27 import { budgetSummary } from "../src/kernel/budgets.ts";
28
29 const MIN = 60_000;
30 const OVERRAN = budgetSummary("a review run", 25 * MIN, 10 * MIN);
31
32 describe("what failed at its start", () => {
33 test("a budget overrun or an unreadable head with no turn is a start that failed", () => {
34 expect(failedAtStart("cancelled", OVERRAN, 0)).toBe(true);
35 expect(failedAtStart("failed", OVERRAN, 0)).toBe(true);
36 expect(failedAtStart("failed", "not reviewed: the head is gone", 0)).toBe(true);
37 });
38
39 test("a reviewer that took a turn, or ended otherwise, did not fail at its start", () => {
40 expect(failedAtStart("failed", OVERRAN, 3)).toBe(false);
41 expect(failedAtStart("failed", "reviewed: no verdict was posted", 0)).toBe(false);
42 expect(failedAtStart("ok", OVERRAN, 0)).toBe(false);
43 });
44 });
45
46 describe("the words a start failure is read by are the ones the runner writes", () => {
47 // `failedAtStart` reads the same constants the runner writes its summaries from: reword them
48 // there and both sides move together (#16096).
49 test("each summary built from a shared prefix is a start that failed", () => {
50 expect(failedAtStart("failed", `${NOT_REVIEWED_PREFIX} anything at all`, 0)).toBe(true);
51 expect(failedAtStart("failed", `${SEALED_FETCH_PREFIX} anything at all`, 0)).toBe(true);
52 expect(failedAtStart("cancelled", budgetSummary("a review run", MIN, MIN), 0)).toBe(true);
53 });
54
55 test("the runner writes its summaries from those constants, not its own copies", async () => {
56 const source = await Bun.file(new URL("../src/crew/runner.ts", import.meta.url)).text();
57 expect(source).toContain("`${NOT_REVIEWED_PREFIX} ${head.why}`");
58 expect(source).toContain("`${SEALED_FETCH_PREFIX} ${fetched.error}`");
59 expect(source).not.toMatch(/["`]not reviewed:/);
60 expect(source).not.toMatch(/["`]fetch of the sealed head failed:/);
61 });
62 });
63
64 describe("a review that fails to start", () => {
65 let dataDir: string;
66 let app: App;
67 let alice: User;
68 let repo: Repo;
69
70 beforeAll(async () => {
71 dataDir = await mkdtemp(join(tmpdir(), "forge-review-failed-start-"));
72 app = createApp({ dataDir, port: 0 });
73 const a = await createUser(app.db, {
74 origin: "seed",
75 trusted: true,
76 username: "alice",
77 email: "[email protected]",
78 password: "a-good-passphrase",
79 adminIfFirst: true,
80 });
81 if (!a.ok) throw new Error(a.error);
82 alice = a.value;
83 markVerified(app.db, alice.id, new Date().toISOString());
84 const made = await createRepo(app, alice, { name: "engine", visibility: "private" });
85 if (!made.ok) throw new Error(String(made.error));
86 repo = made.value;
87 await commitToBranch(app, alice, repo, { message: "Start", files: [{ path: "README.md", content: "# engine\n" }] });
88 for (const name of ["scout", "juniper"]) {
89 const agent = await createAgent(app, alice, { username: name, brief: `I am ${name}.` });
90 if (!agent.ok) throw new Error(String(agent.error));
91 expect(addToCrew(app, alice, repo, name).ok).toBe(true);
92 }
93 seatAs(app.db, repo.id, getUserByName(app.db, "juniper")!.id, "reviewer");
94 }, 60_000);
95
96 afterAll(async () => {
97 await app.close?.();
98 await rm(dataDir, { recursive: true, force: true });
99 });
100
101 async function greenPull(name: string): Promise<Pull> {
102 await commitToBranch(app, alice, repo, {
103 branch: `feature/${name}`,
104 base: "main",
105 message: name,
106 files: [{ path: `docs/${name}.md`, content: `${name}\n` }],
107 });
108 const opened = await openPull(app, alice, repo, {
109 title: name,
110 body: "",
111 baseBranch: "main",
112 headBranch: `feature/${name}`,
113 });
114 if (!opened.ok) throw new Error(String(opened.error));
115 const pull = opened.value;
116 createAppRecord(app.db, { repoId: repo.id, slug: "engine", access: "private" });
117 app.db.query("UPDATE issue SET author_id = ?2 WHERE id = ?1").run(pull.id, getUserByName(app.db, "scout")!.id);
118 const check = createRun(app.db, {
119 repoId: repo.id,
120 kind: "check",
121 issueId: pull.id,
122 env: `pull-${pull.number}`,
123 commitOid: pull.headOid,
124 reason: "pull",
125 });
126 const green = new Date(Date.now() - 30 * MIN).toISOString();
127 app.db
128 .query("UPDATE run SET state = 'ok', summary = 'check passed', created_at = ?2, finished_at = ?2 WHERE id = ?1")
129 .run(check.id, green);
130 return { ...pull, authorIsAgent: true };
131 }
132
133 const reviews = (pull: Pull) =>
134 listRuns(app.db, pull.repoId, { issueId: pull.id }).filter((r) => r.reason === "review");
135
136 /** End the pull's newest review run as the runner would. */
137 function end(pull: Pull, state: string, summary: string, turns: number): void {
138 const run = reviews(pull).at(0)!;
139 app.db
140 .query("UPDATE run SET state = ?2, summary = ?3, turns = ?4, finished_at = ?5 WHERE id = ?1")
141 .run(run.id, state, summary, turns, new Date().toISOString());
142 }
143
144 test("is sent once more, then said on the pull as a start that failed, not as silence", async () => {
145 const pull = await greenPull("fails-at-start");
146 expect(await sendToReview(app, repo, pull)).toBe("sent");
147 end(pull, "cancelled", OVERRAN, 0);
148 // The first try failed at its start: the retry goes out, to the one reviewer there is.
149 expect(await sendToReview(app, repo, pull)).toBe("sent");
150 expect(waitsForPerson(app.db, repo.id, pull)).toBeUndefined();
151 end(pull, "failed", OVERRAN, 0);
152 // Two tries are all a head gets: no third run, and the pull says why it waits.
153 expect(await sendToReview(app, repo, pull)).toBe("lapsed");
154 expect(reviews(pull)).toHaveLength(2);
155 const wait = waitsForPerson(app.db, repo.id, pull);
156 expect(wait?.why).toBe("failed to start");
157 expect(reviewSays(wait, false)).toBe("review failed to start");
158 // Both doors: the asks list in the studio, and the crew's rows the terminal reads.
159 expect(reviewWhy(wait)).toStartWith("review failed to start, since ");
160 app.db.query("UPDATE issue SET author_id = ?2 WHERE id = ?1").run(pull.id, getUserByName(app.db, "scout")!.id);
161 const row = crewNow({ app }, alice).find((r) => "says" in r && r.why === "review" && r.on === `#${pull.number} ${pull.title}`);
162 expect(row && "says" in row ? row.says : undefined).toBe("review failed to start");
163 }, 60_000);
164
165 test("a reviewer that read the pull and said nothing is still \"did not answer\"", async () => {
166 const pull = await greenPull("read-and-silent");
167 for (let i = 0; i < 2; i++) {
168 expect(await sendToReview(app, repo, pull)).toBe("sent");
169 end(pull, "failed", "reviewed: no verdict was posted", 7);
170 }
171 expect(await sendToReview(app, repo, pull)).toBe("lapsed");
172 const wait = waitsForPerson(app.db, repo.id, pull);
173 expect(wait?.why).toBe("lapsed");
174 expect(reviewSays(wait, false)).toBe("the reviewer did not answer");
175 }, 60_000);
176 });
test/timers-named.test.ts +2 −1
@@ -168,7 +168,8 @@ const ALLOWED: readonly Allowed[] = [
168168 ["src/crew/first_look.ts", "() => resolve(undefined)"],
169169 ["src/crew/plan.ts", "() => resolve(undefined)"],
170170 ["src/crew/decide.ts", "() => abort.abort()"],
171 ["src/crew/runner.ts", "() => { overran = true; controller.abort(); }"],
171 ["src/crew/runner.ts", "() => { overran = true; controller.abort(); grace"],
172 ["src/crew/runner.ts", "() => giveUp({ state: \"failed\""],
172173 ["src/crew/claude.ts", "() => { input.log("],
173174 ["src/crew/claude.ts", "() => { why = \"timeout\"; stopChild(); }"],
174175 ["src/display/known.ts", "() => resolve(undefined)"],

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs