Public: anyone can read this; the crew can change it.
A `bug` issue, filed by the forge or by hand, is queued ahead of feature work for its repository's crew #18292
Merged 6h 18m ago, live in production
mason/forge:mason/18126-a-bug-issue-filed-by-the-forge-or-by-han → main 0 commits fork 2 threads · 2 unresolved
5 files
changed +140
−0
docs/features/crash-reports.md +2
| @@ -14,3 +14,5 @@ A crash an app reports becomes an ordinary `bug` issue on the app's own reposito | ||
| 14 | 14 | - **The queue.** Any open issue labelled `bug`, or titled "Diagnostics from forge ...", goes before feature work in the crew's queue (the title counts only when someone who can write to the repository wrote it); an order a person gave (first, ranked, limbs) still wins. The issue asks the builder to say what it found with file and line, to open a fix pull that closes it, and to open no guess when it finds no cause. |
| 15 | 15 | - **Where to see it.** The app's page lists its open crash groups with their issues and the pull that closes each. In the terminal, "Crash groups of a repository" in the palette lists the same rows (reports, builds, fix pull); the issues themselves are in the issues screen like any other. |
| 16 | 16 | - **Limits.** 5 reports a minute from one address and 60 in all, each counted per app. A repository remembers 200 groups; past that the least recently seen closed group is forgotten (its issue stays) and no report is refused. |
| 17 | ||
| 18 | A builder given a bug (the label, or a writer's "Diagnostics from forge ..." title) is told to comment the likely cause with file and line, reproduce it when the checks can, close the issue with its pull, and open no guess pull when it finds no cause. When the check names an outside runner label (`check.label`), the pull says in words that it waits for that runner (#18126). |
src/crew/brief.ts +24
| @@ -300,6 +300,13 @@ export interface TaskInput extends BriefInput { | ||
| 300 | 300 | readonly comments: readonly Comment[]; |
| 301 | 301 | /** The names of the labels on the issue or pull. */ |
| 302 | 302 | readonly labels?: readonly string[] | undefined; |
| 303 | /** The issue is a bug for the queue (`core/bug_label.ts`, #18126). */ | |
| 304 | readonly bug?: boolean | undefined; | |
| 305 | /** | |
| 306 | * The label of an outside runner the repository's check needs (`forge.json` `check.label`, | |
| 307 | * #18037). | |
| 308 | */ | |
| 309 | readonly checkLabel?: string | undefined; | |
| 303 | 310 | /** Verdicts on the pull, oldest first. */ |
| 304 | 311 | readonly reviews: readonly Review[]; |
| 305 | 312 | /** Line comments on the pull's diff. */ |
| @@ -479,6 +486,22 @@ export function taskPrompt(input: TaskInput): string { | ||
| 479 | 486 | const MCP_SIZE_RULE = |
| 480 | 487 | "This issue touches the MCP. Run `bun test test/mcp-size.test.ts` before pushing; it names the five costliest tools when it fails. Prefer an `action` or `kind` on an existing tool (docs/MCP.md, \"Room for a new tool\") over a new tool, and never raise the ceilings."; |
| 481 | 488 | |
| 489 | /** | |
| 490 | * What a builder does with a bug (#18126): say what it found, reproduce, close the issue with a fix | |
| 491 | * pull, or say nothing was found and open no guess. A check on a machine the forge lacks is waited | |
| 492 | * for. | |
| 493 | */ | |
| 494 | function bugLines(issueNumber: number, checkLabel: string | undefined): string[] { | |
| 495 | const out = [ | |
| 496 | "This issue is a bug, and the queue put it ahead of feature work. Before you change anything, comment on the issue with what you found: the likely cause with file and line. Reproduce it with a failing test when the repository's checks can. Then open a pull that fixes it and ends with `Closes #" + issueNumber + "`. If you find no cause, say so on the issue and what would help (a log, steps, a build); open no guess pull.", | |
| 497 | ]; | |
| 498 | if (checkLabel !== undefined && checkLabel !== "") | |
| 499 | out.push( | |
| 500 | `This repository's check runs only on an outside runner labelled \`${checkLabel}\` (a machine the forge does not have). Say in the pull description, in words, that it waits for that runner's check and is not to be merged on a Linux check alone.`, | |
| 501 | ); | |
| 502 | return out; | |
| 503 | } | |
| 504 | ||
| 482 | 505 | /** |
| 483 | 506 | * Prior art before new code (#14619): a hand trial found 3 of 14 pulls adding a helper the forge |
| 484 | 507 | * already had in another shape. The clone carries the finder, so the brief names it; only the |
| @@ -616,6 +639,7 @@ function taskBody(input: TaskInput): string { | ||
| 616 | 639 | "", |
| 617 | 640 | ); |
| 618 | 641 | out.push(...told()); |
| 642 | if (input.pull === undefined && input.bug === true) out.push("", ...bugLines(issue.number, input.checkLabel)); | |
| 619 | 643 | const talk = input.comments.filter((c) => !isAgent(c.authorName)); |
| 620 | 644 | if (talk.length > 0) { |
| 621 | 645 | out.push("", "Discussion so far:"); |
src/crew/run_prompt.ts +17
| @@ -5,6 +5,9 @@ | ||
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | import { join } from "node:path"; |
| 8 | import { readFileAt } from "../apps/checkout.ts"; | |
| 9 | import { parseCheck } from "../apps/manifest.ts"; | |
| 10 | import { flowAndBugs } from "../core/bug_label.ts"; | |
| 8 | 11 | import { UPSTREAM_TITLE, sourceFollowing, upstreamFollowing } from "../actions/upstream_follow.ts"; |
| 9 | 12 | import type { App } from "../app.ts"; |
| 10 | 13 | import type { Agent } from "../core/agents.ts"; |
| @@ -65,6 +68,19 @@ export interface PromptState { | ||
| 65 | 68 | readonly lessons?: readonly Lesson[] | undefined; |
| 66 | 69 | } |
| 67 | 70 | |
| 71 | /** | |
| 72 | * Whether the issue is a bug for the queue, and the runner label its repository's check needs | |
| 73 | * (#18126). | |
| 74 | */ | |
| 75 | export async function bugBrief(app: App, repo: Repo, issueId: string, bare: string): Promise<{ bug?: true; checkLabel?: string }> { | |
| 76 | if (!flowAndBugs(app.db, repo.id).bugs.has(issueId)) return {}; | |
| 77 | const head = await resolveOid(bare, `refs/heads/${repo.defaultBranch}`); | |
| 78 | const forgeJson = head === undefined ? undefined : await readFileAt(bare, head, "forge.json", 1 << 20); | |
| 79 | const check = parseCheck(forgeJson, undefined); | |
| 80 | const label = check.ok ? check.value?.label : undefined; | |
| 81 | return { bug: true, ...(label === undefined || label === "" ? {} : { checkLabel: label }) }; | |
| 82 | } | |
| 83 | ||
| 68 | 84 | export async function promptFor(s: PromptState): Promise<string> { |
| 69 | 85 | const { app, run, repo, issue, agent, pull, foreign, reason, brief, branch, bare, forkBare, record, sealedHead, since, signal, lessons } = s; |
| 70 | 86 | const role = brief.role; |
| @@ -101,6 +117,7 @@ export async function promptFor(s: PromptState): Promise<string> { | ||
| 101 | 117 | labels: (labelsForIssues(app.db, [issue.id]).get(issue.id) ?? []).map( |
| 102 | 118 | (label) => label.name, |
| 103 | 119 | ), |
| 120 | ...(pull === undefined ? await bugBrief(app, repo, issue.id, bare) : {}), | |
| 104 | 121 | reviews, |
| 105 | 122 | reviewComments, |
| 106 | 123 | readers: readersAmong( |
test/brief-bug-wiring.test.ts added +62
| @@ -0,0 +1,62 @@ | ||
| 1 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 2 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 3 | import { tmpdir } from "node:os"; | |
| 4 | import { join } from "node:path"; | |
| 5 | import { createRepo } from "../src/actions/repos.ts"; | |
| 6 | import { createApp, type App } from "../src/app.ts"; | |
| 7 | import { seedAdmin } from "./helpers/admin.ts"; | |
| 8 | import { createIssue, createLabel, setIssueLabels } from "../src/core/issues.ts"; | |
| 9 | import { getRepo, type Repo } from "../src/core/repos.ts"; | |
| 10 | import { bugBrief } from "../src/crew/run_prompt.ts"; | |
| 11 | import { repoDir } from "../src/git/repos.ts"; | |
| 12 | import { commitFiles } from "../src/git/write.ts"; | |
| 13 | ||
| 14 | const mk = (input: Parameters<typeof createIssue>[1]) => { | |
| 15 | const made = createIssue(app.db, input); | |
| 16 | if (!made.ok) throw new Error(made.error); | |
| 17 | return made.value; | |
| 18 | }; | |
| 19 | let dir = ""; | |
| 20 | let app: App; | |
| 21 | let repo: Repo; | |
| 22 | let bare = ""; | |
| 23 | ||
| 24 | beforeAll(async () => { | |
| 25 | dir = await mkdtemp(join(tmpdir(), "forge-bugbrief-")); | |
| 26 | app = createApp({ dataDir: dir, port: 0 }); | |
| 27 | const alice = await seedAdmin(app, { username: "alice", email: "[email protected]", password: "a-good-passphrase" }); | |
| 28 | if (!alice.ok) throw new Error(alice.error); | |
| 29 | const made = await createRepo(app, alice.value, { name: "ios", visibility: "public" }); | |
| 30 | if (!made.ok) throw new Error(JSON.stringify(made.error)); | |
| 31 | repo = getRepo(app.db, "alice", "ios")!; | |
| 32 | bare = repoDir(app.reposRoot, repo.ownerName, repo.name); | |
| 33 | const forgeJson = JSON.stringify({ check: { run: "xcodebuild test", label: "macos" } }); | |
| 34 | const c = await commitFiles(bare, { | |
| 35 | branch: repo.defaultBranch, | |
| 36 | message: "forge.json", | |
| 37 | files: [{ path: "forge.json", content: forgeJson }], | |
| 38 | author: { name: "T", email: "[email protected]" }, | |
| 39 | }); | |
| 40 | if (!c.ok) throw new Error(JSON.stringify(c.error)); | |
| 41 | }, 30_000); | |
| 42 | afterAll(() => rm(dir, { recursive: true, force: true })); | |
| 43 | ||
| 44 | describe("bugBrief (#18126)", () => { | |
| 45 | test("a bug-labelled issue is a bug and carries the runner label of the check", async () => { | |
| 46 | const issue = mk({ repoId: repo.id, authorId: repo.ownerId, title: "Crash on launch" }); | |
| 47 | const label = createLabel(app.db, repo.id, "bug", "d73a4a"); | |
| 48 | if (!label.ok) throw new Error(label.error); | |
| 49 | setIssueLabels(app.db, issue.id, [label.value.id]); | |
| 50 | expect(await bugBrief(app, repo, issue.id, bare)).toEqual({ bug: true, checkLabel: "macos" }); | |
| 51 | }); | |
| 52 | ||
| 53 | test("a feature issue is neither", async () => { | |
| 54 | const issue = mk({ repoId: repo.id, authorId: repo.ownerId, title: "Add a dark theme" }); | |
| 55 | expect(await bugBrief(app, repo, issue.id, bare)).toEqual({}); | |
| 56 | }); | |
| 57 | ||
| 58 | test("a writer's Diagnostics title is a bug too", async () => { | |
| 59 | const issue = mk({ repoId: repo.id, authorId: repo.ownerId, title: "Diagnostics from forge 0.1 (3)" }); | |
| 60 | expect((await bugBrief(app, repo, issue.id, bare)).bug).toBe(true); | |
| 61 | }); | |
| 62 | }); |
test/brief-bug.test.ts added +35
| @@ -0,0 +1,35 @@ | ||
| 1 | import { describe, expect, test } from "bun:test"; | |
| 2 | import { taskPrompt, type TaskInput } from "../src/crew/brief.ts"; | |
| 3 | ||
| 4 | const build = (extra: Partial<TaskInput>): string => | |
| 5 | taskPrompt({ | |
| 6 | agent: { user: { username: "bot", displayName: "" }, brief: "" }, | |
| 7 | repo: { ownerName: "alice", name: "app", defaultBranch: "main" }, | |
| 8 | issue: { number: 7, title: "Crash on open", body: "it crashes", authorName: "alice" }, | |
| 9 | comments: [], | |
| 10 | reviews: [], | |
| 11 | reason: "assigned", | |
| 12 | branch: "bot/7", | |
| 13 | forgeUrl: "http://forge.test", | |
| 14 | ...extra, | |
| 15 | } as unknown as TaskInput); | |
| 16 | ||
| 17 | describe("a bug's brief (#18126)", () => { | |
| 18 | test("says to name the cause, reproduce, close the issue, and open no guess pull", () => { | |
| 19 | const out = build({ bug: true }); | |
| 20 | expect(out).toContain("likely cause with file and line"); | |
| 21 | expect(out).toContain("Closes #7"); | |
| 22 | expect(out).toContain("open no guess pull"); | |
| 23 | expect(out).not.toContain("outside runner"); | |
| 24 | }); | |
| 25 | ||
| 26 | test("a check on an outside runner is waited for in words", () => { | |
| 27 | const out = build({ bug: true, checkLabel: "macos" }); | |
| 28 | expect(out).toContain("labelled `macos`"); | |
| 29 | expect(out).toContain("not to be merged on a Linux check alone"); | |
| 30 | }); | |
| 31 | ||
| 32 | test("a feature issue's brief has none of it", () => { | |
| 33 | expect(build({ checkLabel: "macos" })).not.toContain("likely cause"); | |
| 34 | }); | |
| 35 | }); |
new above
offline
This block lands between the
PRIOR_ART_RULEdoc comment (lines above, aboutscripts/similar.ts) andPRIOR_ART_RULEitself, which orphans that comment. MovebugLinesabove it.