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
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/16096-review-runs-fail-at-once-at-0-00-so-pull → main 0 commits fork 2 threads · 2 unresolved
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"; | ||
| 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 | 32 | import { createLog } from "../kernel/log.ts"; |
| 32 | 33 | import { guestWaits } from "../origins/guest.ts"; |
| 33 | 34 | import { reviewerPaused } from "./reviewer_paused.ts"; |
| @@ -185,11 +186,43 @@ const REVIEW_TRIES = 2; | ||
| 185 | 186 | /** One review run sent for a head: when it was queued, and whether it is still out. */ |
| 186 | 187 | export interface ReviewAttempt { |
| 187 | 188 | readonly createdAt: string; |
| 189 | readonly finishedAt?: string | null; | |
| 190 | readonly cancelled?: boolean; | |
| 188 | 191 | readonly active: boolean; |
| 189 | 192 | /** The reviewer the run was sent to. */ |
| 190 | 193 | readonly reviewerId?: string | null; |
| 194 | /** | |
| 195 | * The run ended before its agent took a turn and spent nothing: the reviewer never read the pull. | |
| 196 | */ | |
| 197 | readonly failedToStart?: boolean; | |
| 191 | 198 | } |
| 192 | 199 | |
| 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 | ||
| 193 | 226 | /** |
| 194 | 227 | * A head that went green this long after the lapse, with no review yet, |
| 195 | 228 | * is still sent once, late; past it, nothing was ever going to send. |
| @@ -268,16 +301,13 @@ export function reviewAttemptsFor( | ||
| 268 | 301 | ) |
| 269 | 302 | .all(...batch.flatMap((p) => [p.id, p.headOid])); |
| 270 | 303 | 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[]>(); | |
| 275 | 305 | for (const r of db |
| 276 | 306 | .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 }, | |
| 278 | 308 | string[] |
| 279 | 309 | >( |
| 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 | |
| 281 | 311 | WHERE kind = 'agent' AND reason = 'review' |
| 282 | 312 | AND issue_id IN (${ids.map((_, n) => `?${n + 1}`).join(",")}) |
| 283 | 313 | ORDER BY created_at, id`, |
| @@ -286,12 +316,13 @@ export function reviewAttemptsFor( | ||
| 286 | 316 | if (diedBeforeAgent(r.state, r.summary)) continue; |
| 287 | 317 | // A run that stood down for the check queue was never an attempt (#16094). |
| 288 | 318 | if (r.state === "cancelled" && r.summary === CHECK_PENDING_SUMMARY) continue; |
| 289 | const attempt = { | |
| 319 | const attempt: ReviewAttempt = { | |
| 290 | 320 | finishedAt: r.finished_at, |
| 291 | 321 | cancelled: r.state === "cancelled", |
| 292 | 322 | createdAt: r.created_at, |
| 293 | 323 | active: r.state === "queued" || r.state === "running", |
| 294 | 324 | reviewerId: r.actor_id, |
| 325 | failedToStart: failedAtStart(r.state, r.summary, r.turns), | |
| 295 | 326 | }; |
| 296 | 327 | const list = reviews.get(r.issue_id); |
| 297 | 328 | if (list) list.push(attempt); |
| @@ -377,7 +408,7 @@ export function stageOf( | ||
| 377 | 408 | |
| 378 | 409 | /** Why an agent's green pull waits for a person, and since when. */ |
| 379 | 410 | export interface ReviewWait { |
| 380 | readonly why: "no reviewer" | "lapsed" | "rounds"; | |
| 411 | readonly why: "no reviewer" | "lapsed" | "rounds" | "failed to start"; | |
| 381 | 412 | /** When review became owed: the head went green, or the pull was let go. */ |
| 382 | 413 | readonly since: string; |
| 383 | 414 | /** Minutes the check took, when the review was sent late because of it. */ |
| @@ -485,7 +516,11 @@ export function reviewWaitsFor( | ||
| 485 | 516 | ? { why: "no reviewer", since: history.greenAt } |
| 486 | 517 | : stage === "lapsed" |
| 487 | 518 | ? { |
| 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", | |
| 489 | 524 | since: history.greenAt, |
| 490 | 525 | ...(history.lateAt === undefined |
| 491 | 526 | ? {} |
src/crew/review_says.ts +1
| @@ -8,6 +8,7 @@ import type { ReviewWait } from "./review.ts"; | ||
| 8 | 8 | /** The reason alone, without its date. */ |
| 9 | 9 | export function reviewSays(wait: ReviewWait | undefined, paused: boolean): string { |
| 10 | 10 | if (wait?.why === "rounds") return "the reviewer asked for changes three times"; |
| 11 | if (wait?.why === "failed to start") return "review failed to start"; | |
| 11 | 12 | if (wait?.why === "lapsed" && paused) return "the reviewer is paused"; |
| 12 | 13 | if (wait?.why === "lapsed" && wait.lateCheckMinutes !== undefined) |
| 13 | 14 | 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 { | ||
| 122 | 122 | namedCommits, |
| 123 | 123 | onBase, |
| 124 | 124 | } 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"; | |
| 126 | 132 | 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"; | |
| 128 | 134 | import { createLog, holdValues, redactValues, releaseValues } from "../kernel/log.ts"; |
| 129 | 135 | import { err, ok, type Result } from "../kernel/result.ts"; |
| 130 | 136 | import { holdLease } from "../runs/lease.ts"; |
| @@ -241,6 +247,11 @@ export interface CrewOptions { | ||
| 241 | 247 | readonly networkRetryScale?: number | undefined; |
| 242 | 248 | /** How long a review run may take. @default BUDGETS.review */ |
| 243 | 249 | 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; | |
| 244 | 255 | /** A `CLAUDE_CONFIG_DIR` for runs, when the operator wants one. */ |
| 245 | 256 | readonly configDir?: string | undefined; |
| 246 | 257 | /** 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 { | ||
| 296 | 307 | return send(text); |
| 297 | 308 | } |
| 298 | 309 | |
| 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 | ||
| 299 | 313 | /** |
| 300 | 314 | * What a reviewer reads: the pull's diff (`review_range.ts` — a landed pull's |
| 301 | 315 | * is its merge commit's), and its pictures. `landedAs` names the merge commit |
| @@ -307,6 +321,11 @@ export async function reviewInputs( | ||
| 307 | 321 | pull: Pull, |
| 308 | 322 | record: AppRecord | undefined, |
| 309 | 323 | 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, | |
| 310 | 329 | ): Promise<{ |
| 311 | 330 | reviewDiff: string; |
| 312 | 331 | looks: string[]; |
| @@ -319,7 +338,7 @@ export async function reviewInputs( | ||
| 319 | 338 | if (range !== undefined) { |
| 320 | 339 | const names = await runGitCapture( |
| 321 | 340 | ["diff", "--name-only", range.from, range.to], |
| 322 | { cwd: bare }, | |
| 341 | { cwd: bare, ...(signal === undefined ? {} : { signal }) }, | |
| 323 | 342 | ); |
| 324 | 343 | design = touchesDesign( |
| 325 | 344 | names.stdout |
| @@ -329,7 +348,7 @@ export async function reviewInputs( | ||
| 329 | 348 | ); |
| 330 | 349 | const out = await runGitCapture( |
| 331 | 350 | ["diff", "--stat", "-p", range.from, range.to], |
| 332 | { cwd: bare }, | |
| 351 | { cwd: bare, ...(signal === undefined ? {} : { signal }) }, | |
| 333 | 352 | ); |
| 334 | 353 | const text = out.stdout.toString(); |
| 335 | 354 | if (out.code === 0) |
| @@ -511,11 +530,23 @@ async function runClaimed( | ||
| 511 | 530 | const started = Date.now(); |
| 512 | 531 | // A reviewer past its budget is stopped, whatever it is doing. |
| 513 | 532 | 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; | |
| 514 | 541 | const clock = |
| 515 | 542 | claimed.reason === "review" |
| 516 | 543 | ? setTimeout(() => { |
| 517 | 544 | overran = true; |
| 518 | 545 | 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 | ); | |
| 519 | 550 | }, options.reviewBudgetMs ?? BUDGETS.review) |
| 520 | 551 | : undefined; |
| 521 | 552 | const meter: Meter = { |
| @@ -529,7 +560,7 @@ async function runClaimed( | ||
| 529 | 560 | }; |
| 530 | 561 | let outcome: Outcome; |
| 531 | 562 | try { |
| 532 | outcome = await work( | |
| 563 | const working = work( | |
| 533 | 564 | app, |
| 534 | 565 | claimed, |
| 535 | 566 | options, |
| @@ -539,6 +570,9 @@ async function runClaimed( | ||
| 539 | 570 | watch, |
| 540 | 571 | began, |
| 541 | 572 | ); |
| 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]); | |
| 542 | 576 | } catch (error) { |
| 543 | 577 | log.error("agent run threw", { run: run.id, error: String(error) }); |
| 544 | 578 | outcome = { |
| @@ -547,6 +581,7 @@ async function runClaimed( | ||
| 547 | 581 | }; |
| 548 | 582 | } finally { |
| 549 | 583 | clearTimeout(clock); |
| 584 | clearTimeout(grace); | |
| 550 | 585 | untrackAgentRun(run.id); |
| 551 | 586 | steering.delete(run.id); |
| 552 | 587 | lease(); |
| @@ -1272,7 +1307,7 @@ async function work( | ||
| 1272 | 1307 | GIT_TRANSFER_MS, |
| 1273 | 1308 | ); |
| 1274 | 1309 | 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}` }; | |
| 1276 | 1311 | write(`sealed head: ${sealedHead.ownerName}/${sealedHead.name} ${pull.headBranch} fetched as ${fetched.ref}`); |
| 1277 | 1312 | } |
| 1278 | 1313 | // Counted once made: a clone that failed is no hop on the line. |
| @@ -1292,9 +1327,9 @@ async function work( | ||
| 1292 | 1327 | timeoutMs: GIT_TRANSFER_MS, |
| 1293 | 1328 | }); |
| 1294 | 1329 | if (!head.ok) { |
| 1295 | write(`not reviewed: ${head.why}`); | |
| 1330 | write(`${NOT_REVIEWED_PREFIX} ${head.why}`); | |
| 1296 | 1331 | 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}` }; | |
| 1298 | 1333 | } |
| 1299 | 1334 | write(`reviewing head ${head.oid.slice(0, 12)}, checked out as ${branch}`); |
| 1300 | 1335 | } |
| @@ -1425,7 +1460,7 @@ async function work( | ||
| 1425 | 1460 | ...(reason === "review" && pull |
| 1426 | 1461 | ? { |
| 1427 | 1462 | // 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)), | |
| 1429 | 1464 | sourceNote: await reviewSourceNote(app, repo, pull, bare), |
| 1430 | 1465 | ...(sealedHead === undefined ? {} : { sealedRef: `${SEALED_REMOTE}/${pull.headBranch}` }), |
| 1431 | 1466 | 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; | ||
| 55 | 55 | export async function startStandInCrew( |
| 56 | 56 | options: { |
| 57 | 57 | readonly reviewBudgetMs?: number; |
| 58 | /** How long past its budget a review run is waited for. */ | |
| 59 | readonly reviewGraceMs?: number; | |
| 58 | 60 | readonly tickMs?: number; |
| 59 | 61 | /** How often autonomous repositories take a turn (the forge's own minute when unset). */ |
| 60 | 62 | readonly autonomyEveryMs?: number; |
| @@ -85,6 +87,7 @@ export async function startStandInCrew( | ||
| 85 | 87 | runTimeoutMs: 60_000, |
| 86 | 88 | networkRetryScale: 0, |
| 87 | 89 | reviewBudgetMs: options.reviewBudgetMs ?? 4_000, |
| 90 | ...(options.reviewGraceMs === undefined ? {} : { reviewGraceMs: options.reviewGraceMs }), | |
| 88 | 91 | tickMs: options.tickMs ?? STAND_IN_TICK_MS, |
| 89 | 92 | ...(options.autonomyEveryMs === undefined ? {} : { autonomyEveryMs: options.autonomyEveryMs }), |
| 90 | 93 | ...(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[] = [ | ||
| 168 | 168 | ["src/crew/first_look.ts", "() => resolve(undefined)"], |
| 169 | 169 | ["src/crew/plan.ts", "() => resolve(undefined)"], |
| 170 | 170 | ["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\""], | |
| 172 | 173 | ["src/crew/claude.ts", "() => { input.log("], |
| 173 | 174 | ["src/crew/claude.ts", "() => { why = \"timeout\"; stopChild(); }"], |
| 174 | 175 | ["src/display/known.ts", "() => resolve(undefined)"], |
new above
offline
Regex on summary text is the only link to the code that writes those summaries. Share constants or a structured field.