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

Crew: an adversarial validator pass before merge on risky pulls (box agent, game door, auth, print path) #18262

opened this in answer to

Merged 5h 50m ago, live in production

scout/forge:scout/18250-crew-an-adversarial-validator-pass-befor → main 0 commits fork 5 threads · 5 unresolved

  • Merged. scout/18250-crew-an-adversarial-validator-pass-befor was merged into main as 23727ff.

Review

Sign in to review this change.
5 files changed +119 −6
docs/features/adversarial-review.md added +19
@@ -0,0 +1,19 @@
1 ---
2 topic: Tell the crew
3 row: A risky pull is read by a reviewer told to break it
4 ---
5 # A risky pull is read by a reviewer told to break it (#18250)
6
7 When a pull changes the box agent (`src/games/agent.sh`), the game door
8 (`src/games/door.ts`, `src/http/games_*.ts`), sign-in or permissions
9 (`src/auth/`, `contract.json`), a release script, or a print path, the
10 reviewer's brief gains an adversarial pass: read-only, fresh context, narrow
11 brief: break it. Its findings arrive as the review's line comments, a change
12 request when one can be shown. The paths are listed in `src/crew/risky.ts`.
13
14 There is no screen for it: it is the review that already appears on the pull,
15 on the page and over the API alike; it adds no screen or action of its own.
16
17 Not built, tracked in #18271 and #18272, linked to #18250: running the game
18 agent tests in ubuntu:24.04 before an agent.sh release, and watching the box
19 after one.
src/crew/brief.ts +7
@@ -17,6 +17,7 @@ import type { Pull } from "../core/pulls.ts";
1717 import { saysFromApp } from "../actions/app_notes.ts";
1818 import { OUTSIDE_LABEL, OUTSIDE_TITLE, saysOutside } from "../core/reports.ts";
1919 import type { Repo } from "../core/repos.ts";
20 import { adversarialLines } from "./risky.ts";
2021 import { DESIGN_POINTER, DESIGN_PRINCIPLES } from "./design_principles.ts";
2122 import { READER } from "./direct.ts";
2223 import { deviceLines } from "./devices.ts";
@@ -364,6 +365,11 @@ export interface TaskInput extends BriefInput {
364365 readonly sealedRef?: string | undefined;
365366 /** For `review`: the change touches `src/web/`, so the review is held to docs/DESIGN.md. */
366367 readonly design?: boolean | undefined;
368 /**
369 * For `review`: the risky areas the change touches (`risky.ts`), so the review is the adversarial
370 * one.
371 */
372 readonly risky?: readonly string[] | undefined;
367373 /** For `review`: an earlier review run on this pull ended with no verdict. */
368374 readonly retry?: boolean | undefined;
369375 /** For `review`: pictures of the preview at this head, phone and desktop. */
@@ -693,6 +699,7 @@ function taskBody(input: TaskInput): string {
693699 "- The contract: every action asks `permit` and none compares roles by hand; a new door has its row in `src/contract.test.ts`; and no cell in `contract.json` is loosened unless the issue asked for exactly that — a loosened cell is a wall a person crosses, so a pull that loosens one without being asked is a change request, whatever else it does well.",
694700 ]),
695701 ...(isForge(input.repo) ? hostDoorFor(input.reviewDiff) : []),
702 ...adversarialLines(input.risky ?? []),
696703 ...boxLines(input),
697704 "",
698705 ...roundLines(input.reviews.filter((r) => r.authorName === me)),
src/crew/risky.ts added +36
@@ -0,0 +1,36 @@
1 /**
2 * Which pulls are risky enough for a reviewer who reads to break them (#18250): the box agent, the
3 * game door, sign-in and permissions, the release scripts, and a print path. Plain paths in, the
4 * named areas out; the brief turns them into the adversarial pass (`brief.ts`).
5 */
6
7 const AREAS: readonly { readonly area: string; readonly path: RegExp }[] = [
8 { area: "the box agent", path: /^src\/games\/(agent\.sh|fetch\.sh|agent_sh\.d\.ts)$/ },
9 { area: "the game door", path: /^src\/games\/(door|hold|lend|heal)[^/]*\.ts$|^src\/http\/games_[^/]*\.ts$/ },
10 { area: "sign-in or permissions", path: /^src\/auth\/|^contract\.json$|^src\/contract|^src\/(.*\/)?permit[^/]*\.ts$/ },
outdated

permit[^/]\.ts matches src/x/permit.test.ts, while src/contract excludes tests. Make the two agree: exclude .test.ts in both. The same applies to release-.ts on line 11.

11 { area: "a release script", path: /^scripts\/(cut-release|release-[^/]*)\.ts$|^src\/release\// },

This pattern matches print in any path, including docs and tests. Anchor it to src/ or scripts/ and exclude .md and .test.ts. Add a negative case to the test.

12 { area: "a print path", path: /^(src|scripts)\/(?!.*\.md$)(.*[/_.-])?print([/_.-]|$)/i },
outdated

src/print.ts and scripts/print.ts do not match: src\/ consumes the slash, then (^|[/_.-]) needs a separator and ^ cannot match mid-string. Fix: allow a separator-or-start after the directory prefix, e.g. ^(src|scripts)\/(?!.\.(md|test\.ts)$)(.[/_.-])?print([/_.-]|$), and add both paths to the test.

13 ];
14
15 /**
16 * A test file is never the risky change itself: every area skips `*.test.ts`, so the rules agree.
17 */
18 const isTest = (p: string): boolean => /\.test\.ts$/.test(p);
19
20 /** The risky areas these changed paths touch, in a fixed order; none for an ordinary change. */
21 export function riskyAreas(paths: readonly string[]): string[] {
22 const source = paths.filter((p) => !isTest(p));
23 return AREAS.filter((a) => source.some((p) => a.path.test(p))).map((a) => a.area);
24 }
25
outdated

"it is read twice" is false: this is the only review the pull gets, as the pull description says. Say what is true, e.g. "this review is the adversarial one".

26 /** What a reviewer of such a pull is told: break it, read-only, and say what held. */
27 export function adversarialLines(areas: readonly string[]): string[] {
28 if (areas.length === 0) return [];
29 return [
30 "",
31 `This pull touches ${areas.join(", ")}: this review is the adversarial one. Your brief is narrow: break it. You stay read-only — do not write code, push or change anything — and a fresh pair of eyes is the point, so judge the diff itself, not the author's account of it.`,
32 "- Ask of every changed line what runs it when nobody is watching: a loop that never sleeps, a retry with no backoff, a restart or a write while people are online, an error that reaches every player or every user instead of one, a statement in a printed or shown text that is not true.",
33 "- Try the empty case, the repeated case, the slow case and the hostile case (a name, a path or a number someone chose to hurt it) against the code, and name the input that breaks it.",
34 "- Each finding is a line comment that says what breaks, for what input, and what the change should do; one finding you can show is a change request. If you try hard and find nothing, say what you tried in the verdict's words.",
35 ];
36 }
src/crew/run_prompt.ts +10 −6
@@ -33,6 +33,7 @@ import { parkReasons, parkedTwice } from "./parks.ts";
3333 import { resolutionBrief } from "./proposal.ts";
3434 import { reviewRange } from "./review_range.ts";
3535 import { touchesDesign } from "./review.ts";
36 import { riskyAreas } from "./risky.ts";
3637 import { SEALED_REMOTE } from "./sealed_head.ts";
3738 import { reviewSourceNote } from "./source_held.ts";
3839 import { pureRevertOf } from "../checks/revert_lane.ts";
@@ -201,22 +202,24 @@ export async function reviewInputs(
201202 reviewDiff: string;
202203 looks: string[];
203204 design: boolean;
205 risky: string[];
204206 landedAs?: string;
205207 }> {
206208 const range = await reviewRange(bare, pull);
207209 let reviewDiff = "(no diff available)";
208210 let design = false;
211 let risky: string[] = [];
209212 if (range !== undefined) {
210213 const names = await runGitCapture(
211214 ["diff", "--name-only", range.from, range.to],
212215 { cwd: bare, ...(signal === undefined ? {} : { signal }) },
213216 );
214 design = touchesDesign(
215 names.stdout
216 .toString()
217 .split("\n")
218 .filter((n) => n !== ""),
219 );
217 const changed = names.stdout
218 .toString()
219 .split("\n")
220 .filter((n) => n !== "");
221 design = touchesDesign(changed);
222 risky = riskyAreas(changed);
220223 const out = await runGitCapture(
221224 ["diff", "--stat", "-p", range.from, range.to],
222225 { cwd: bare, ...(signal === undefined ? {} : { signal }) },
@@ -249,6 +252,7 @@ export async function reviewInputs(
249252 reviewDiff,
250253 looks,
251254 design,
255 risky,
252256 ...(range?.landed === true && reviewDiff !== "(no diff available)"
253257 ? { landedAs: range.to }
254258 : {}),
test/crew-risky.test.ts added +47
@@ -0,0 +1,47 @@
1 /** A pull on a risky path is read by an adversarial reviewer (#18250). */
2 import { expect, test } from "bun:test";
3 import { taskPrompt, type TaskInput } from "../src/crew/brief.ts";
4 import { adversarialLines, riskyAreas } from "../src/crew/risky.ts";
5
6 test("the risky paths are named, an ordinary change is not", () => {
7 expect(riskyAreas(["src/games/agent.sh"])).toEqual(["the box agent"]);
8 expect(riskyAreas(["src/games/door.ts", "src/http/games_routes.ts"])).toEqual(["the game door"]);
9 expect(riskyAreas(["src/auth/cookies.ts", "contract.json"])).toEqual(["sign-in or permissions"]);
10 expect(riskyAreas(["scripts/cut-release.ts"])).toEqual(["a release script"]);
11 expect(riskyAreas(["src/web/pages/print.ts"])).toEqual(["a print path"]);
12 expect(riskyAreas(["docs/features/print-sheet.md", "test/print-x.test.ts", "src/web/print.md"])).toEqual([]);
13 expect(riskyAreas(["src/print.ts"])).toEqual(["a print path"]);
14 expect(riskyAreas(["scripts/print.ts"])).toEqual(["a print path"]);
15 expect(riskyAreas(["src/auth/permit.ts"])).toEqual(["sign-in or permissions"]);
16 expect(riskyAreas(["test/permit-x.test.ts", "docs/permit.ts", "src/auth/permit.test.ts", "src/x/permit.test.ts"])).toEqual([]);
17 expect(riskyAreas(["scripts/release-notes.test.ts", "src/release/x.test.ts"])).toEqual([]);
18 expect(riskyAreas(["src/contract.test.ts", "test/auth-x.test.ts"])).toEqual([]);
outdated

This tests the text builder only. Add a test through the review task prompt (taskBody) showing that risky reaches the brief, so removing the wiring in brief.ts fails a test.

19 expect(riskyAreas(["src/web/pages/home.ts", "README.md", "src/games/ask.ts", "src/blueprint.ts"])).toEqual([]);
20 });
21
22 test("the adversarial brief is read-only and says to break it; nothing for an ordinary pull", () => {
23 expect(adversarialLines([])).toEqual([]);
24 const text = adversarialLines(["the box agent"]).join("\n");
25 expect(text).toContain("the box agent");
26 expect(text).toContain("break it");
27 expect(text).toContain("read-only");
28 });
29
30 const input = (over: object): TaskInput =>
31 ({
32 agent: { user: { username: "bot", displayName: "" }, brief: "" },
33 repo: { ownerName: "alice", name: "forge", defaultBranch: "main", autonomyDirection: "" },
34 issue: { number: 1, title: "t", body: "b", authorName: "alice" },
35 comments: [],
36 reviews: [],
37 branch: "bot/1",
38 forgeUrl: "http://forge.test",
39 reason: "review",
40 ...over,
41 }) as unknown as TaskInput;
42
43 test("risky reaches the review task prompt; without it the prompt has no adversarial pass", () => {
44 expect(taskPrompt(input({ risky: ["the box agent"] }))).toContain("this review is the adversarial one");
45 expect(taskPrompt(input({}))).not.toContain("adversarial");
46 expect(taskPrompt(input({ risky: [] }))).not.toContain("adversarial");
47 });

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs