Public: anyone can read this; the crew can change it.
A review that failed to start is retried once, then shows on the pull as 'review failed to start' #16397
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/16178-a-review-that-failed-to-start-is-retried → main 0 commits fork 1 thread · 1 unresolved
7 files
changed +416
−13
docs/features/review-failed-start.md +12
| @@ -26,8 +26,20 @@ could not be fetched. Such a run ends with no turn and $0.00. | ||
| 26 | 26 | Home's "waiting for your review" rows, the asks list in the studio, and the |
| 27 | 27 | terminal's crew rows all use the same sentence (`review_says.ts`). |
| 28 | 28 | |
| 29 | The pull itself says it too (#16178): its page shows a **Review failed to | |
| 30 | start** card to everyone who can read it, and the terminal's pull screen | |
| 31 | (`src/tui/screens/pull.ts`) reads `review failed to start` on its header line. | |
| 32 | ||
| 29 | 33 | ## What a person does |
| 30 | 34 | |
| 35 | A person who writes the repository can send the review once more: | |
| 36 | **Re-run review** on the pull's card, or `F` ("re-run the review") on the | |
| 37 | terminal's pull screen. Both call `retryFailedStart` behind the same gate | |
| 38 | (`mayRetryReview`): it sends one run only while the pull reads "failed to | |
| 39 | start", no review is out, a reviewer is seated and not paused, and the crew | |
| 40 | can run; otherwise it says why and sends nothing. While the run is out the | |
| 41 | card and the header word are gone; if it too fails at its start, they return. | |
| 42 | ||
| 31 | 43 | Look at the review runs' logs on the pull. If the cause was the crew (a clone |
| 32 | 44 | or fetch that died), review the pull yourself or push again to start a fresh |
| 33 | 45 | head. The pull waits for you either way; nothing lands on its own. |
src/crew/review.ts +47 −12
| @@ -660,14 +660,33 @@ export async function sendToReview( | ||
| 660 | 660 | (repo.autonomy === "autonomous" || stale); |
| 661 | 661 | if (stage === "wait" || (stage === "lapsed" && !unreviewed)) return stage; |
| 662 | 662 | const late = stage === "late" || unreviewed; |
| 663 | const reviewer = await queueReview(app, repo, pull, reviewers, history); | |
| 664 | if (reviewer === undefined) return "wait"; | |
| 665 | log.info("green; queued for review", { | |
| 666 | repo: `${repo.ownerName}/${repo.name}`, | |
| 667 | pull: pull.number, | |
| 668 | reviewer: reviewer.user.username, | |
| 669 | attempt: history.attempts.length + 1, | |
| 670 | ...(late ? { late: true, checkMinutes: history.checkMinutes } : {}), | |
| 671 | }); | |
| 672 | return "sent"; | |
| 673 | } | |
| 674 | ||
| 675 | /** | |
| 676 | * Queue one review run for the pull, to the reviewer best placed for its diff. A review that came | |
| 677 | * back with no verdict is sent to the other reviewer when the crew has one; with only one, the same | |
| 678 | * reviewer tries again. Undefined when nobody could be asked. | |
| 679 | */ | |
| 680 | async function queueReview( | |
| 681 | app: App, | |
| 682 | repo: Repo, | |
| 683 | pull: Pull, | |
| 684 | reviewers: readonly Agent[], | |
| 685 | history: ReviewHistory, | |
| 686 | ): Promise<Agent | undefined> { | |
| 663 | 687 | const issue = getIssueById(app.db, pull.id); |
| 664 | if (!issue) return "wait"; | |
| 665 | const { diff } = await pullDiff( | |
| 666 | await pullDir(app.db, app.reposRoot, repo, pull), | |
| 667 | pull, | |
| 668 | ); | |
| 669 | // A review that came back with no verdict is sent to the other reviewer | |
| 670 | // when the crew has one; with only one, the same reviewer tries again. | |
| 688 | if (!issue) return undefined; | |
| 689 | const { diff } = await pullDiff(await pullDir(app.db, app.reposRoot, repo, pull), pull); | |
| 671 | 690 | const failed = history.attempts.at(-1)?.reviewerId; |
| 672 | 691 | const others = reviewers.filter((r) => r.user.id !== failed); |
| 673 | 692 | const reviewer = pickReviewer( |
| @@ -676,15 +695,31 @@ export async function sendToReview( | ||
| 676 | 695 | getTeam(app.db, "design")?.members, |
| 677 | 696 | reviewLoad(app.db), |
| 678 | 697 | ); |
| 698 | if (reviewer === undefined) return undefined; | |
| 699 | return queueAgentRun(app, repo, issue, reviewer, "review") === undefined ? undefined : reviewer; | |
| 700 | } | |
| 701 | ||
| 702 | /** What a person's re-run of a review that failed to start did (`retryFailedStart`). */ | |
| 703 | export type RetryOutcome = "sent" | "not failed" | "wait"; | |
| 704 | ||
| 705 | /** | |
| 706 | * A person's one tap on a pull that reads "review failed to start" (#16178): one more review run is | |
| 707 | * sent, past the head's spent tries, since the reviewer never read it. `not failed` when the pull | |
| 708 | * does not read that, so the tap cannot buy a run the sweep would not; `wait` while a review is | |
| 709 | * out, the crew cannot run, or nobody could be asked. | |
| 710 | */ | |
| 711 | export async function retryFailedStart(app: App, repo: Repo, pull: Pull, now = new Date()): Promise<RetryOutcome> { | |
| 712 | if (waitsForPerson(app.db, repo.id, pull, now)?.why !== "failed to start") return "not failed"; | |
| 713 | const history = reviewAttempts(app.db, pull, now); | |
| 714 | if (history === undefined || history.attempts.some((a) => a.active)) return "wait"; | |
| 715 | const reviewers = reviewersOf(app.db, repo.id); | |
| 716 | if (reviewers.length === 0 || reviewerPaused(repo) || crewDownNow(app.db, now.getTime())) return "wait"; | |
| 717 | const reviewer = await queueReview(app, repo, pull, reviewers, history); | |
| 679 | 718 | if (reviewer === undefined) return "wait"; |
| 680 | if (queueAgentRun(app, repo, issue, reviewer, "review") === undefined) | |
| 681 | return "wait"; | |
| 682 | log.info("green; queued for review", { | |
| 719 | log.info("review failed to start; sent again by a person", { | |
| 683 | 720 | repo: `${repo.ownerName}/${repo.name}`, |
| 684 | 721 | pull: pull.number, |
| 685 | 722 | reviewer: reviewer.user.username, |
| 686 | attempt: history.attempts.length + 1, | |
| 687 | ...(late ? { late: true, checkMinutes: history.checkMinutes } : {}), | |
| 688 | 723 | }); |
| 689 | 724 | return "sent"; |
| 690 | 725 | } |
src/http/server.ts +2
| @@ -348,6 +348,7 @@ import { notesOverrule, notesSave, notesView } from "../web/pages/notes.ts"; | ||
| 348 | 348 | import { reviewPage } from "../web/studio/review_page.ts"; |
| 349 | 349 | import { reviewAnswersPage, reviewAnswersSend, reviewStepOpen } from "../web/studio/review_guide.ts"; |
| 350 | 350 | import { reviewAct } from "../web/studio/review_act.ts"; |
| 351 | import { reviewRetrySubmit } from "../web/studio/review_start.ts"; | |
| 351 | 352 | import { |
| 352 | 353 | asksBulkSubmit, |
| 353 | 354 | asksBulkUndo, |
| @@ -1509,6 +1510,7 @@ export function buildRouter(): Router<Handler> { | ||
| 1509 | 1510 | router.add("POST", "/:owner/:name/pulls/:number/take-back", takeBackSubmit); |
| 1510 | 1511 | router.add("POST", "/:owner/:name/pulls/:number/hold", holdSubmit); |
| 1511 | 1512 | router.add("POST", "/:owner/:name/pulls/:number/release", releaseSubmit); |
| 1513 | router.add("POST", "/:owner/:name/pulls/:number/review-retry", reviewRetrySubmit); | |
| 1512 | 1514 | // What an issue waits for: link and unlink, from the issue page. |
| 1513 | 1515 | router.add( |
| 1514 | 1516 | "POST", |
src/tui/screens/pull.ts +20 −1
| @@ -28,6 +28,8 @@ | ||
| 28 | 28 | |
| 29 | 29 | import { OFFER_PULL_WORDS, offerPull, previewOfferPull } from "../../actions/offer_pull.ts"; |
| 30 | 30 | import { outsideClause } from "../../web/outside.ts"; |
| 31 | import { mayRetryReview, RETRY_WORDS, reviewFailedToStart } from "../../web/studio/review_start.ts"; | |
| 32 | import { retryFailedStart } from "../../crew/review.ts"; | |
| 31 | 33 | import { teamHoldRefusal, waitingOnTeams } from "../../core/teams_words.ts"; |
| 32 | 34 | import { crewFilters, guardedRefusal, isStrangerPull, strangerGuard, strangerNext } from "../../crew/stranger.ts"; |
| 33 | 35 | import { redMain } from "../../checks/red_main.ts"; |
| @@ -366,6 +368,10 @@ export function pullScreen( | ||
| 366 | 368 | /** `h` is a person's key: an agent's hold is refused by the action, so it is not offered. */ |
| 367 | 369 | const mayHold = (): boolean => |
| 368 | 370 | mayWrite() && f.user?.kind === "user" && issueRow !== undefined; |
| 371 | /** This open agent pull's review failed to start twice (#16178); `F` sends it again. */ | |
| 372 | let reviewFailed = false; | |
| 373 | /** `F` is the page's "Re-run review", gated as the page gates it (`mayRetryReview`). */ | |
| 374 | const mayRerunReview = (): boolean => reviewFailed && repo !== undefined && mayRetryReview(f.db, repo, f.user); | |
| 369 | 375 | /** A writer, on a pull that is one of several variants. */ |
| 370 | 376 | const mayVote = (): boolean => |
| 371 | 377 | mayWrite() && |
| @@ -400,6 +406,7 @@ export function pullScreen( | ||
| 400 | 406 | threads = row === undefined ? [] : readThreads(row); |
| 401 | 407 | issueRow = repo === undefined ? undefined : getIssue(f.db, repo.id, number); |
| 402 | 408 | hold = row === undefined ? undefined : getHold(f.db, row.id); |
| 409 | reviewFailed = repo !== undefined && row !== undefined && reviewFailedToStart(f.db, repo, row); | |
| 403 | 410 | // The cost-ledger line, gated as the page gates it (owner facts only). |
| 404 | 411 | ledgerLine = |
| 405 | 412 | settings === undefined || issueRow === undefined ? "" : costLineFor(f.db, settings, f.user, issueRow, "pull"); |
| @@ -1228,6 +1235,7 @@ export function pullScreen( | ||
| 1228 | 1235 | ...(isApp ? [binding(["P"], "open production")] : []), |
| 1229 | 1236 | ...(isApp ? [binding(["I"], "looks")] : []), |
| 1230 | 1237 | ...(takeBackKey ? [binding(["T"], "take it back")] : []), |
| 1238 | ...(mayRerunReview() ? [binding(["F"], "re-run the review")] : []), | |
| 1231 | 1239 | ...(isApp && preview !== undefined && !takeBackKey |
| 1232 | 1240 | ? [binding(["T"], "the preview's terminal")] |
| 1233 | 1241 | : []), |
| @@ -1351,7 +1359,7 @@ export function pullScreen( | ||
| 1351 | 1359 | x1, |
| 1352 | 1360 | head!.y + 1, |
| 1353 | 1361 | truncate( |
| 1354 | ` ${facts?.mergedAt != null ? "merged" : issue.state} · opened by ${who(issue.authorName, issue.originAuthor)} ${ago(issue.createdAt)}${outsideOf(issue)}${guestWaiting() ? ` · ${isContribHead(facts?.headBranch ?? "") ? OUTSIDE_NOTE : repo !== undefined && crewFilters(repo) ? GUEST_NOTE_FILTERED : GUEST_NOTE}` : ""}${assignedText(issueRow, ctx.icons)}${facts?.proposal ? ` · ${proposedByText(facts.proposal)}` : ""}${facts?.proposal?.attestation ? ` · ${attestationLine(facts.proposal.child, facts.proposal.attestation, facts.proposal.headTree)}` : ""}${hold === undefined ? "" : ` · held by ${hold.heldByName}: ${hold.why}`}${step === null ? "" : ` · step: ${stepLine(step)}`}${landing === null ? "" : ` · ${landing}`}${next === null ? "" : ` · next: ${next.who}, ${next.why}`}${ledgerLine === "" ? "" : ` · ${ledgerLine}`}`, | |
| 1362 | ` ${facts?.mergedAt != null ? "merged" : issue.state} · opened by ${who(issue.authorName, issue.originAuthor)} ${ago(issue.createdAt)}${outsideOf(issue)}${guestWaiting() ? ` · ${isContribHead(facts?.headBranch ?? "") ? OUTSIDE_NOTE : repo !== undefined && crewFilters(repo) ? GUEST_NOTE_FILTERED : GUEST_NOTE}` : ""}${assignedText(issueRow, ctx.icons)}${facts?.proposal ? ` · ${proposedByText(facts.proposal)}` : ""}${facts?.proposal?.attestation ? ` · ${attestationLine(facts.proposal.child, facts.proposal.attestation, facts.proposal.headTree)}` : ""}${hold === undefined ? "" : ` · held by ${hold.heldByName}: ${hold.why}`}${reviewFailed ? " · review failed to start" : ""}${step === null ? "" : ` · step: ${stepLine(step)}`}${landing === null ? "" : ` · ${landing}`}${next === null ? "" : ` · next: ${next.who}, ${next.why}`}${ledgerLine === "" ? "" : ` · ${ledgerLine}`}`, | |
| 1355 | 1363 | Math.max(0, edge - x1), |
| 1356 | 1364 | ), |
| 1357 | 1365 | style(c.mutedFg, c.bg), |
| @@ -1548,6 +1556,17 @@ export function pullScreen( | ||
| 1548 | 1556 | void openAppTerminal(f, ctx, repo, previewEnv(number)); |
| 1549 | 1557 | return true; |
| 1550 | 1558 | } |
| 1559 | if (e.key === "F" && mayRerunReview() && repo !== undefined) { | |
| 1560 | const target = repo; | |
| 1561 | const row = getPull(f.db, target.id, number); | |
| 1562 | if (row === undefined) return true; | |
| 1563 | runAsync(ctx, async () => { | |
| 1564 | const done = await retryFailedStart(f.app, target, row); | |
| 1565 | ctx.toast(RETRY_WORDS[done], done === "sent" ? "success" : "danger"); | |
| 1566 | await reload(); | |
| 1567 | }); | |
| 1568 | return true; | |
| 1569 | } | |
| 1551 | 1570 | if (e.key === "a" && mayWrite()) { |
| 1552 | 1571 | assign(); |
| 1553 | 1572 | return true; |
src/web/studio/change.ts +2
| @@ -107,6 +107,7 @@ import { offerPullCard } from "../pages/offer-upstream.ts"; | ||
| 107 | 107 | import { pullRoster } from "./pull_roster.ts"; |
| 108 | 108 | import { readableNotes } from "../../actions/desk.ts"; |
| 109 | 109 | import { holdLines } from "../desk_strip.ts"; |
| 110 | import { reviewStartCard } from "./review_start.ts"; | |
| 110 | 111 | |
| 111 | 112 | /** The pull and its repo, or the response that refuses to say why not. */ |
| 112 | 113 | export function pullContext(ctx: Ctx): { repo: Repo; pull: Pull } | Response { |
| @@ -763,6 +764,7 @@ async function changeConversation( | ||
| 763 | 764 | spent, |
| 764 | 765 | "gate", |
| 765 | 766 | () => html`${held ? holdCard(ctx, repo, pull, { act: true }) : null} |
| 767 | ${reviewStartCard(ctx, repo, pull)} | |
| 766 | 768 | ${reach} |
| 767 | 769 | ${combined} |
| 768 | 770 | ${next} |
src/web/studio/review_start.ts added +91
| @@ -0,0 +1,91 @@ | ||
| 1 | /** | |
| 2 | * A review that failed to start, as the pull's page says it (#16178): the | |
| 3 | * crew sent the head to review, tried once more, and neither run reached | |
| 4 | * its reviewer. The page says so to everyone who reads it, never silence, | |
| 5 | * and a person who writes the repository gets the one tap that sends it | |
| 6 | * again (`retryFailedStart`), posted under `/pulls/:number/review-retry`. | |
| 7 | */ | |
| 8 | ||
| 9 | import type { Database } from "bun:sqlite"; | |
| 10 | import { mayView } from "../../core/sealed.ts"; | |
| 11 | import { getPull, type Pull } from "../../core/pulls.ts"; | |
| 12 | import { canWrite, type Repo } from "../../core/repos.ts"; | |
| 13 | import type { User } from "../../core/users.ts"; | |
| 14 | import { retryFailedStart, waitsForPerson, type RetryOutcome } from "../../crew/review.ts"; | |
| 15 | import { reviewSays } from "../../crew/review_says.ts"; | |
| 16 | import type { Ctx } from "../../http/context.ts"; | |
| 17 | import { forbiddenPage, loadRepo, notFoundPage, repoBase, signInFirst } from "../chrome.ts"; | |
| 18 | import { parseNumber } from "../pages/thread.ts"; | |
| 19 | import { readForm } from "../form.ts"; | |
| 20 | import { html, when, type Html } from "../html.ts"; | |
| 21 | import { flashTo } from "../layout.ts"; | |
| 22 | import { btn, card, icon } from "../ui.ts"; | |
| 23 | ||
| 24 | /** The words the button's answer says, by what the re-run did. */ | |
| 25 | export const RETRY_WORDS: Record<RetryOutcome, string> = { | |
| 26 | sent: "Review sent again. Its run is on the pull's trail.", | |
| 27 | "not failed": "Review did not fail to start on this head, so nothing was sent.", | |
| 28 | wait: "Review could not be sent just now: a review is out, or the crew cannot run. Try again shortly.", | |
| 29 | }; | |
| 30 | ||
| 31 | /** | |
| 32 | * The people the re-run lets through, on the page and in the terminal: a person who writes here. | |
| 33 | */ | |
| 34 | export const mayRetryReview = (db: Database, repo: Repo, user: User | undefined): boolean => | |
| 35 | user !== undefined && user.kind === "user" && canWrite(db, repo, user); | |
| 36 | ||
| 37 | const mayRetry = (ctx: Ctx, repo: Repo): boolean => mayRetryReview(ctx.app.db, repo, ctx.auth.user); | |
| 38 | ||
| 39 | /** | |
| 40 | * Whether this pull reads "review failed to start": an open agent pull whose two review runs never | |
| 41 | * reached a reviewer. | |
| 42 | */ | |
| 43 | export function reviewFailedToStart(db: Database, repo: Repo, pull: Pull): boolean { | |
| 44 | if (!pull.authorIsAgent || pull.state !== "open" || pull.mergedAt !== null) return false; | |
| 45 | return waitsForPerson(db, repo.id, pull)?.why === "failed to start"; | |
| 46 | } | |
| 47 | ||
| 48 | /** The notice, on an open agent pull whose review failed to start; nothing on any other. */ | |
| 49 | export function reviewStartCard(ctx: Ctx, repo: Repo, pull: Pull): Html | null { | |
| 50 | if (!pull.authorIsAgent || pull.state !== "open" || pull.mergedAt !== null) return null; | |
| 51 | const wait = waitsForPerson(ctx.app.db, repo.id, pull); | |
| 52 | if (wait?.why !== "failed to start") return null; | |
| 53 | const thread = `${repoBase(repo)}/pulls/${pull.number}`; | |
| 54 | return card( | |
| 55 | html`<p data-review-start> | |
| 56 | ${reviewSays(wait, false)}: the crew sent this head to review twice, and | |
| 57 | neither run reached its reviewer. | |
| 58 | </p> | |
| 59 | ${when( | |
| 60 | mayRetry(ctx, repo), | |
| 61 | () => | |
| 62 | html`<form class="bar mt" method="post" action="${thread}/review-retry" data-now="Sent" data-now-once> | |
| 63 | ${btn("Re-run review", { size: "sm", icon: "eye" })} | |
| 64 | </form>`, | |
| 65 | )}`, | |
| 66 | { | |
| 67 | tone: "attn", | |
| 68 | id: "review-start", | |
| 69 | head: html`${icon("alert")} | |
| 70 | <h2>Review failed to start</h2>`, | |
| 71 | }, | |
| 72 | ); | |
| 73 | } | |
| 74 | ||
| 75 | // POST /:owner/:name/pulls/:number/review-retry — a writer re-runs a review that failed to start. | |
| 76 | export async function reviewRetrySubmit(ctx: Ctx): Promise<Response> { | |
| 77 | const repo = loadRepo(ctx); | |
| 78 | if (!repo) return notFoundPage(ctx); | |
| 79 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 80 | const form = await readForm(ctx, "rw"); | |
| 81 | if (form instanceof Response) return form; | |
| 82 | const number = parseNumber(ctx.params.number); | |
| 83 | const found = number === undefined ? undefined : getPull(ctx.app.db, repo.id, number); | |
| 84 | if (!found || !mayView(ctx.app.db, repo, found, ctx.auth.user)) return notFoundPage(ctx); | |
| 85 | if (!mayRetry(ctx, repo)) return forbiddenPage(ctx, "Only a person who writes this repository can re-run its review."); | |
| 86 | const done = await retryFailedStart(ctx.app, repo, found); | |
| 87 | return flashTo(ctx, `${repoBase(repo)}/pulls/${found.number}`, { | |
| 88 | ...(done === "sent" ? {} : { tone: "danger" as const }), | |
| 89 | message: RETRY_WORDS[done], | |
| 90 | }); | |
| 91 | } |
test/review-retry.test.ts added +242
| @@ -0,0 +1,242 @@ | ||
| 1 | /** | |
| 2 | * A review that failed to start is retried once, then shown on the pull (#16178). The crew sends a | |
| 3 | * head to review and sends it again when the first run never reached its reviewer; when the retry | |
| 4 | * reaches it, the verdict lands and the pull says nothing more. When both fail at their start, the | |
| 5 | * pull's own page says "Review failed to start" to everyone who reads it, and a person who writes | |
| 6 | * the repository gets one tap that sends it again (`retryFailedStart`); the terminal's pull screen | |
| 7 | * says the same and offers the same re-run on `F`, to a writer only. | |
| 8 | */ | |
| 9 | import { seatAs } from "./helpers/seat.ts"; | |
| 10 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 11 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 12 | import { tmpdir } from "node:os"; | |
| 13 | import { join } from "node:path"; | |
| 14 | import { createApp, type App } from "../src/app.ts"; | |
| 15 | import { addToCrew, createAgent } from "../src/actions/crew.ts"; | |
| 16 | import { openPull } from "../src/actions/pulls.ts"; | |
| 17 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 18 | import { createApp as createAppRecord } from "../src/core/apps.ts"; | |
| 19 | import { getPull, type Pull } from "../src/core/pulls.ts"; | |
| 20 | import { type Repo } from "../src/core/repos.ts"; | |
| 21 | import { submitReview } from "../src/core/reviews.ts"; | |
| 22 | import { createRun, listRuns } from "../src/core/runs.ts"; | |
| 23 | import { createUser, getUserByName, type User } from "../src/core/users.ts"; | |
| 24 | import { markVerified } from "../src/core/verify.ts"; | |
| 25 | import { FORGE_FAULTS_FORGIVEN, retryFailedStart, sendToReview, waitsForPerson } from "../src/crew/review.ts"; | |
| 26 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 27 | import { budgetSummary } from "../src/kernel/budgets.ts"; | |
| 28 | import { quietLogs } from "./helpers/globals.ts"; | |
| 29 | import { signInCookie } from "./helpers/studio-signin.ts"; | |
| 30 | import { openPullScreen } from "./helpers/tui-pull.ts"; | |
| 31 | ||
| 32 | quietLogs(); | |
| 33 | ||
| 34 | const MIN = 60_000; | |
| 35 | const OVERRAN = budgetSummary("a review run", 25 * MIN, 10 * MIN); | |
| 36 | ||
| 37 | let dataDir: string; | |
| 38 | let app: App; | |
| 39 | let servers: Servers; | |
| 40 | let alice: User; | |
| 41 | let repo: Repo; | |
| 42 | let writer = ""; | |
| 43 | let reader = ""; | |
| 44 | ||
| 45 | beforeAll(async () => { | |
| 46 | dataDir = await mkdtemp(join(tmpdir(), "forge-review-retry-")); | |
| 47 | app = createApp({ dataDir, port: 0 }); | |
| 48 | servers = await serve(app); | |
| 49 | for (const name of ["alice", "bob"]) { | |
| 50 | const u = await createUser(app.db, { | |
| 51 | origin: "seed", | |
| 52 | trusted: true, | |
| 53 | username: name, | |
| 54 | email: `${name}@forge.local`, | |
| 55 | password: "a-good-passphrase", | |
| 56 | adminIfFirst: name === "alice", | |
| 57 | }); | |
| 58 | if (!u.ok) throw new Error(u.error); | |
| 59 | markVerified(app.db, u.value.id, new Date().toISOString()); | |
| 60 | if (name === "alice") alice = u.value; | |
| 61 | } | |
| 62 | const made = await createRepo(app, alice, { name: "engine", visibility: "public" }); | |
| 63 | if (!made.ok) throw new Error(String(made.error)); | |
| 64 | repo = made.value; | |
| 65 | await commitToBranch(app, alice, repo, { message: "Start", files: [{ path: "README.md", content: "# engine\n" }] }); | |
| 66 | for (const name of ["scout", "juniper"]) { | |
| 67 | const agent = await createAgent(app, alice, { username: name, brief: `I am ${name}.` }); | |
| 68 | if (!agent.ok) throw new Error(String(agent.error)); | |
| 69 | expect(addToCrew(app, alice, repo, name).ok).toBe(true); | |
| 70 | } | |
| 71 | seatAs(app.db, repo.id, getUserByName(app.db, "juniper")!.id, "reviewer"); | |
| 72 | createAppRecord(app.db, { repoId: repo.id, slug: "engine", access: "public" }); | |
| 73 | writer = await signInCookie(servers.url, "alice"); | |
| 74 | reader = await signInCookie(servers.url, "bob"); | |
| 75 | }, 60_000); | |
| 76 | ||
| 77 | afterAll(async () => { | |
| 78 | servers.stop?.(); | |
| 79 | await app.close?.(); | |
| 80 | await rm(dataDir, { recursive: true, force: true }); | |
| 81 | }); | |
| 82 | ||
| 83 | /** An agent's pull whose head went green half an hour ago. */ | |
| 84 | async function greenPull(name: string): Promise<Pull> { | |
| 85 | await commitToBranch(app, alice, repo, { | |
| 86 | branch: `feature/${name}`, | |
| 87 | base: "main", | |
| 88 | message: name, | |
| 89 | files: [{ path: `docs/${name}.md`, content: `${name}\n` }], | |
| 90 | }); | |
| 91 | const opened = await openPull(app, alice, repo, { title: name, body: "", baseBranch: "main", headBranch: `feature/${name}` }); | |
| 92 | if (!opened.ok) throw new Error(String(opened.error)); | |
| 93 | app.db.query("UPDATE issue SET author_id = ?2 WHERE id = ?1").run(opened.value.id, getUserByName(app.db, "scout")!.id); | |
| 94 | const pull = getPull(app.db, repo.id, opened.value.number)!; | |
| 95 | expect(pull.authorIsAgent).toBe(true); | |
| 96 | const check = createRun(app.db, { | |
| 97 | repoId: repo.id, | |
| 98 | kind: "check", | |
| 99 | issueId: pull.id, | |
| 100 | env: `pull-${pull.number}`, | |
| 101 | commitOid: pull.headOid, | |
| 102 | reason: "pull", | |
| 103 | }); | |
| 104 | const green = new Date(Date.now() - 30 * MIN).toISOString(); | |
| 105 | app.db | |
| 106 | .query("UPDATE run SET state = 'ok', summary = 'check passed', created_at = ?2, finished_at = ?2 WHERE id = ?1") | |
| 107 | .run(check.id, green); | |
| 108 | return pull; | |
| 109 | } | |
| 110 | ||
| 111 | const reviews = (pull: Pull) => listRuns(app.db, pull.repoId, { issueId: pull.id }).filter((r) => r.reason === "review"); | |
| 112 | ||
| 113 | /** | |
| 114 | * End the pull's newest review run before its reviewer took a turn, cut off as a budget overrun is. | |
| 115 | */ | |
| 116 | function failAtStart(pull: Pull): void { | |
| 117 | const run = reviews(pull).at(0)!; | |
| 118 | expect(run.state).toBe("queued"); | |
| 119 | app.db | |
| 120 | .query("UPDATE run SET state = 'cancelled', summary = ?2, turns = 0, finished_at = ?3 WHERE id = ?1") | |
| 121 | .run(run.id, OVERRAN, new Date().toISOString()); | |
| 122 | } | |
| 123 | ||
| 124 | const page = async (pull: Pull, cookie: string): Promise<string> => { | |
| 125 | const res = await fetch(`${servers.url}/alice/engine/pulls/${pull.number}`, { headers: { cookie } }); | |
| 126 | expect(res.status).toBe(200); | |
| 127 | return res.text(); | |
| 128 | }; | |
| 129 | ||
| 130 | const retry = (pull: Pull, cookie: string): Promise<Response> => | |
| 131 | fetch(`${servers.url}/alice/engine/pulls/${pull.number}/review-retry`, { | |
| 132 | method: "POST", | |
| 133 | headers: { cookie, origin: servers.url }, | |
| 134 | redirect: "manual", | |
| 135 | }); | |
| 136 | ||
| 137 | describe("a review that fails to start", () => { | |
| 138 | test("is sent again, and when the retry reaches its reviewer the pull carries its verdict, no notice", async () => { | |
| 139 | const pull = await greenPull("retry-succeeds"); | |
| 140 | expect(await sendToReview(app, repo, pull)).toBe("sent"); | |
| 141 | failAtStart(pull); | |
| 142 | expect(await sendToReview(app, repo, pull)).toBe("sent"); | |
| 143 | expect(reviews(pull)).toHaveLength(2); | |
| 144 | // The retry reached its reviewer, who approved the head. | |
| 145 | const juniper = getUserByName(app.db, "juniper")!; | |
| 146 | const run = reviews(pull).at(0)!; | |
| 147 | app.db.query("UPDATE run SET state = 'ok', summary = 'approved', turns = 6, finished_at = ?2 WHERE id = ?1").run(run.id, new Date().toISOString()); | |
| 148 | const verdict = submitReview(app.db, { issueId: pull.id, authorId: juniper.id, state: "approved", body: "Reads well.", commitOid: pull.headOid }); | |
| 149 | if (!verdict.ok) throw new Error(verdict.error); | |
| 150 | expect(await sendToReview(app, repo, pull)).toBe("done"); | |
| 151 | expect(waitsForPerson(app.db, repo.id, pull)).toBeUndefined(); | |
| 152 | expect(await page(pull, writer)).not.toContain("data-review-start"); | |
| 153 | // Nothing to re-run: the tap buys no run the sweep would not send. | |
| 154 | expect(await retryFailedStart(app, repo, pull)).toBe("not failed"); | |
| 155 | expect(reviews(pull)).toHaveLength(2); | |
| 156 | }, 60_000); | |
| 157 | ||
| 158 | test("fails again, and the pull says so, with one tap to re-run it for a writer only", async () => { | |
| 159 | const pull = await greenPull("retry-fails"); | |
| 160 | // The forge's own failures are forgiven first (#16177), then the head's two tries are spent. | |
| 161 | for (let i = 0; i < FORGE_FAULTS_FORGIVEN + 2; i++) { | |
| 162 | expect(await sendToReview(app, repo, pull)).toBe("sent"); | |
| 163 | failAtStart(pull); | |
| 164 | } | |
| 165 | expect(await sendToReview(app, repo, pull)).toBe("lapsed"); | |
| 166 | expect(waitsForPerson(app.db, repo.id, pull)?.why).toBe("failed to start"); | |
| 167 | const tries = reviews(pull).length; | |
| 168 | ||
| 169 | // Everyone who reads the pull sees it; only a writer is offered the re-run. | |
| 170 | const seen = await page(pull, writer); | |
| 171 | expect(seen).toContain("data-review-start"); | |
| 172 | expect(seen).toContain("Review failed to start"); | |
| 173 | expect(seen).toContain(`/pulls/${pull.number}/review-retry`); | |
| 174 | const read = await page(pull, reader); | |
| 175 | expect(read).toContain("data-review-start"); | |
| 176 | expect(read).not.toContain(`/pulls/${pull.number}/review-retry`); | |
| 177 | ||
| 178 | // A reader's post is refused and sends nothing; one from another site is refused too. | |
| 179 | expect((await retry(pull, reader)).status).toBe(403); | |
| 180 | const elsewhere = await fetch(`${servers.url}/alice/engine/pulls/${pull.number}/review-retry`, { | |
| 181 | method: "POST", | |
| 182 | headers: { cookie: writer, origin: "https://elsewhere.example" }, | |
| 183 | redirect: "manual", | |
| 184 | }); | |
| 185 | expect(elsewhere.status).toBe(403); | |
| 186 | expect(reviews(pull)).toHaveLength(tries); | |
| 187 | ||
| 188 | // The writer's tap sends one review run; while it is out, the notice is gone and a second tap | |
| 189 | // waits. | |
| 190 | const tapped = await retry(pull, writer); | |
| 191 | expect(tapped.status).toBeGreaterThanOrEqual(300); | |
| 192 | expect(tapped.status).toBeLessThan(400); | |
| 193 | expect(reviews(pull)).toHaveLength(tries + 1); | |
| 194 | expect(reviews(pull).at(0)!.state).toBe("queued"); | |
| 195 | expect(await page(pull, writer)).not.toContain("data-review-start"); | |
| 196 | expect(await retryFailedStart(app, repo, pull)).not.toBe("sent"); | |
| 197 | expect(reviews(pull)).toHaveLength(tries + 1); | |
| 198 | ||
| 199 | // When that one too fails at its start, the pull says so again. | |
| 200 | failAtStart(pull); | |
| 201 | expect(waitsForPerson(app.db, repo.id, pull)?.why).toBe("failed to start"); | |
| 202 | expect(await page(pull, writer)).toContain("data-review-start"); | |
| 203 | }, 60_000); | |
| 204 | ||
| 205 | test("the terminal's pull screen says it, and F re-runs it for a writer only", async () => { | |
| 206 | const pull = await greenPull("retry-terminal"); | |
| 207 | for (let i = 0; i < FORGE_FAULTS_FORGIVEN + 2; i++) { | |
| 208 | expect(await sendToReview(app, repo, pull)).toBe("sent"); | |
| 209 | failAtStart(pull); | |
| 210 | } | |
| 211 | expect(waitsForPerson(app.db, repo.id, pull)?.why).toBe("failed to start"); | |
| 212 | const tries = reviews(pull).length; | |
| 213 | ||
| 214 | // A reader reads it and has no F; pressing it sends nothing. | |
| 215 | const bob = getUserByName(app.db, "bob")!; | |
| 216 | const r = await openPullScreen(app, bob, repo, pull.number); | |
| 217 | try { | |
| 218 | expect(r.text()).toContain("review failed to start"); | |
| 219 | expect(r.text()).not.toContain("re-run the review"); | |
| 220 | await r.press("F"); | |
| 221 | expect(reviews(pull)).toHaveLength(tries); | |
| 222 | } finally { | |
| 223 | r.tui.stop(); | |
| 224 | } | |
| 225 | ||
| 226 | // A writer is offered F; it sends one run, says so, and the header word is gone while it is | |
| 227 | // out. | |
| 228 | const w = await openPullScreen(app, alice, repo, pull.number); | |
| 229 | try { | |
| 230 | expect(w.text()).toContain("review failed to start"); | |
| 231 | expect(w.text()).toContain("re-run the review"); | |
| 232 | await w.press("F"); | |
| 233 | expect(reviews(pull)).toHaveLength(tries + 1); | |
| 234 | expect(w.text()).toContain("Review sent again"); | |
| 235 | expect(w.text()).not.toContain("review failed to start"); | |
| 236 | await w.press("F"); | |
| 237 | expect(reviews(pull)).toHaveLength(tries + 1); | |
| 238 | } finally { | |
| 239 | w.tui.stop(); | |
| 240 | } | |
| 241 | }, 60_000); | |
| 242 | }); |
new above
offline
Both doors: this re-run is page-only. Add the matching terminal action in src/tui/ (entry per AGENTS.md), gated by canWrite like mayRetry, calling retryFailedStart, and add docs/features/<name>.md for the how-to.