Public: anyone can read this; the crew can change it.
A repository's page lists its open crash groups with their issues and pulls, within the page's SQL budget #18293
Merged 5h 6m ago, live in production
scout/forge:scout/18127-a-repository-s-page-lists-its-open-crash → main 0 commits fork 2 threads · 2 unresolved
6 files
changed +176
−27
docs/features/crash-reports.md +2
| @@ -13,4 +13,6 @@ A crash an app reports becomes an ordinary `bug` issue on the app's own reposito | ||
| 13 | 13 | - **Reopening.** A group closed for an older build reopens when a report comes from a newer build than any seen. A report from an older build only adds to the count. |
| 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 | - **Now.** The owner's Now card on the app page holds one row for a group that needs a decision, however many reports it has had; the row says to open the issue and tell the crew what to do. Three cases need the owner, and only the third is built: a behaviour-changing fix and a crash the builder cannot place are not built, so they show no Now row; a group growing across builds (seen in 3 builds and 10 reports with no fix pull yet) shows one, and only the owner sees it. Every open group stays in the crash list. | |
| 17 | - **One read.** The list is one joined read of the groups and their issues, plus the open pulls that close them (`openPullsClosing`, the one way the forge finds a closing pull) (`openGroups` in `src/core/crash_groups.ts`): three statements however many groups. A page reads them once and shares the rows between Now and the crash list. | |
| 16 | 18 | - **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. |
src/actions/crash_reports.ts +5 −18
| @@ -17,14 +17,14 @@ import { | ||
| 17 | 17 | getGroup, |
| 18 | 18 | groupCount, |
| 19 | 19 | groupKey, |
| 20 | groupsOf, | |
| 20 | openGroups, | |
| 21 | type OpenGroup, | |
| 21 | 22 | newerBuild, |
| 22 | 23 | startGroup, |
| 23 | 24 | type CrashGroup, |
| 24 | 25 | type CrashReport, |
| 25 | 26 | } from "../core/crash_groups.ts"; |
| 26 | import { addComment, createIssue, createLabel, getIssueById, getLabel, setIssueLabels, setIssueState, updateIssueText, type Issue } from "../core/issues.ts"; | |
| 27 | import { openPullsClosing, type Pull } from "../core/pulls.ts"; | |
| 27 | import { addComment, createIssue, createLabel, getIssueById, getLabel, setIssueLabels, setIssueState, updateIssueText } from "../core/issues.ts"; | |
| 28 | 28 | import type { Repo } from "../core/repos.ts"; |
| 29 | 29 | import { LABEL_COLORS } from "../hunt/finding.ts"; |
| 30 | 30 | import { err, ok, type Result } from "../kernel/result.ts"; |
| @@ -131,22 +131,9 @@ export function reportCrashes(app: App, repo: Repo, reports: readonly CrashRepor | ||
| 131 | 131 | } |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | export interface CrashRow { | |
| 135 | readonly issue: Issue; | |
| 136 | readonly group: CrashGroup; | |
| 137 | /** The open pull that closes the issue, when one does. */ | |
| 138 | readonly pull?: Pull; | |
| 139 | } | |
| 134 | export type CrashRow = OpenGroup; | |
| 140 | 135 | |
| 141 | 136 | /** The repository's crash groups whose issue is open, newest sighting first. */ |
| 142 | 137 | export function openCrashGroups(app: App, repo: Repo): CrashRow[] { |
| 143 | const out: CrashRow[] = []; | |
| 144 | const groups = groupsOf(app.db, repo.id); | |
| 145 | if (groups.length === 0) return out; | |
| 146 | const closing = openPullsClosing(app.db, repo.id); | |
| 147 | for (const group of groups) { | |
| 148 | const issue = getIssueById(app.db, group.issueId); | |
| 149 | if (issue !== undefined && issue.state === "open") out.push({ issue, group, ...(closing.has(issue.number) ? { pull: closing.get(issue.number)! } : {}) }); | |
| 150 | } | |
| 151 | return out; | |
| 138 | return openGroups(app.db, repo.id); | |
| 152 | 139 | } |
src/core/crash_groups.ts +38 −4
| @@ -11,6 +11,7 @@ | ||
| 11 | 11 | |
| 12 | 12 | import { createHash } from "node:crypto"; |
| 13 | 13 | import type { Database } from "bun:sqlite"; |
| 14 | import { openPullsClosing } from "./pulls.ts"; | |
| 14 | 15 | |
| 15 | 16 | export const KINDS = ["crash", "hang", "cpu", "disk"] as const; |
| 16 | 17 | export type CrashKind = (typeof KINDS)[number]; |
| @@ -245,10 +246,6 @@ export function getGroup(db: Database, repoId: string, key: string): CrashGroup | ||
| 245 | 246 | return row ? fromRow(row) : undefined; |
| 246 | 247 | } |
| 247 | 248 | |
| 248 | export function groupsOf(db: Database, repoId: string): CrashGroup[] { | |
| 249 | return db.query<Row, [string]>("SELECT * FROM crash_group WHERE repo_id = ?1 ORDER BY last_at DESC").all(repoId).map(fromRow); | |
| 250 | } | |
| 251 | ||
| 252 | 249 | export function groupCount(db: Database, repoId: string): number { |
| 253 | 250 | return db.query<{ n: number }, [string]>("SELECT COUNT(*) AS n FROM crash_group WHERE repo_id = ?1").get(repoId)?.n ?? 0; |
| 254 | 251 | } |
| @@ -285,3 +282,40 @@ export function addSighting(db: Database, g: CrashGroup, build: string | undefin | ||
| 285 | 282 | ); |
| 286 | 283 | return { ...g, count: g.count + 1, builds, latestBuild: latest, lastAt: now }; |
| 287 | 284 | } |
| 285 | ||
| 286 | /** A group whose issue is open, as the repository page and the terminal list it. */ | |
| 287 | export interface OpenGroup { | |
| 288 | readonly issue: { readonly number: number; readonly title: string }; | |
| 289 | readonly group: CrashGroup; | |
| 290 | /** The open pull whose description closes the issue, when there is one. */ | |
| 291 | readonly pull?: { readonly number: number; readonly title: string }; | |
| 292 | } | |
| 293 | ||
| 294 | /** Builds and reports past which a group is growing across builds: the owner decides. */ | |
| 295 | export const GROWING_BUILDS = 3; | |
| 296 | export const GROWING_REPORTS = 10; | |
| 297 | ||
| 298 | /** | |
| 299 | * The repository's crash groups whose issue is open, newest sighting first, with the open pull that | |
| 300 | * closes each: one joined read for the groups and their issues, and `openPullsClosing` for the | |
| 301 | * pulls, only when a group is open (no read per row). | |
| 302 | */ | |
| 303 | export function openGroups(db: Database, repoId: string): OpenGroup[] { | |
| 304 | const rows = db | |
| 305 | .query<Row & { number: number; title: string }, [string]>( | |
| 306 | `SELECT g.*, i.number AS number, i.title AS title FROM crash_group g JOIN issue i ON i.id = g.issue_id | |
| 307 | WHERE g.repo_id = ?1 AND i.state = 'open' ORDER BY g.last_at DESC`, | |
| 308 | ) | |
| 309 | .all(repoId); | |
| 310 | if (rows.length === 0) return []; | |
| 311 | const closing = openPullsClosing(db, repoId); | |
| 312 | return rows.map((r) => ({ issue: { number: r.number, title: r.title }, group: fromRow(r), ...(closing.has(r.number) ? { pull: { number: closing.get(r.number)!.number, title: closing.get(r.number)!.title } } : {}) })); | |
| 313 | } | |
| 314 | ||
| 315 | /** | |
| 316 | * The groups that need the owner to decide, not one per report: a group seen in | |
| 317 | * `GROWING_BUILDS` builds and `GROWING_REPORTS` reports with no fix pull yet is growing across | |
| 318 | * builds. Ten reports of one group are one row. | |
| 319 | */ | |
| 320 | export const needDecision = (rows: readonly OpenGroup[]): OpenGroup[] => | |
| 321 | rows.filter((r) => r.pull === undefined && r.group.builds.length >= GROWING_BUILDS && r.group.count >= GROWING_REPORTS); |
src/web/studio/crash_card.ts +13 −5
| @@ -1,7 +1,6 @@ | ||
| 1 | import { openCrashGroups } from "../../actions/crash_reports.ts"; | |
| 1 | import { openCrashGroups, type CrashRow } from "../../actions/crash_reports.ts"; | |
| 2 | 2 | import { keyWords } from "../../actions/report_key.ts"; |
| 3 | 3 | import type { AppRecord } from "../../core/apps.ts"; |
| 4 | import { groupCount } from "../../core/crash_groups.ts"; | |
| 5 | 4 | import type { Repo } from "../../core/repos.ts"; |
| 6 | 5 | import type { Ctx } from "../../http/context.ts"; |
| 7 | 6 | import { repoBase } from "../chrome.ts"; |
| @@ -9,6 +8,15 @@ import { html, type Html } from "../html.ts"; | ||
| 9 | 8 | import { reportKeyMadeAt } from "../../core/report_key.ts"; |
| 10 | 9 | import { btn, confirmAction, row, rowList } from "../ui.ts"; |
| 11 | 10 | |
| 11 | const read = new WeakMap<Ctx, CrashRow[]>(); | |
| 12 | ||
| 13 | /** The open groups, read once per request: the Now card and the crash card share the rows. */ | |
| 14 | export function groupsOf(ctx: Ctx, repo: Repo): CrashRow[] { | |
| 15 | let rows = read.get(ctx); | |
| 16 | if (rows === undefined) read.set(ctx, (rows = openCrashGroups(ctx.app, repo))); | |
| 17 | return rows; | |
| 18 | } | |
| 19 | ||
| 12 | 20 | /** |
| 13 | 21 | * The repository's open crash groups (#18081), each beside its issue and the pull that closes it: |
| 14 | 22 | * the issues are ordinary `bug` issues the forge filed for reports. A repository without an app |
| @@ -17,9 +25,9 @@ import { btn, confirmAction, row, rowList } from "../ui.ts"; | ||
| 17 | 25 | */ |
| 18 | 26 | export function crashCard(ctx: Ctx, repo: Repo, record?: AppRecord): Html | null { |
| 19 | 27 | const base = repoBase(repo); |
| 20 | // An app page already counted its groups; the others count them in one read. | |
| 21 | if ((record === undefined ? groupCount(ctx.app.db, repo.id) : (record.crashGroups ?? 0)) === 0) return null; | |
| 22 | const rows = openCrashGroups(ctx.app, repo); | |
| 28 | // An app page already counted its groups; the others ask once, the one read that lists them. | |
| 29 | if (record !== undefined && (record.crashGroups ?? 0) === 0) return null; | |
| 30 | const rows = groupsOf(ctx, repo); | |
| 23 | 31 | if (rows.length === 0) return null; |
| 24 | 32 | return html`<section class="settings-block" id="crash-groups"> |
| 25 | 33 | <h2>Open crash groups</h2> |
src/web/studio/now.ts +19
| @@ -13,8 +13,10 @@ import { envPull, previewEnv } from "../../apps/data.ts"; | ||
| 13 | 13 | import { appsRuntime, envsFor } from "../../apps/runtime_registry.ts"; |
| 14 | 14 | import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts"; |
| 15 | 15 | import { listCrewRoles } from "../../core/agents.ts"; |
| 16 | import { needDecision } from "../../core/crash_groups.ts"; | |
| 16 | 17 | import { getAppByRepo, type AppRecord } from "../../core/apps.ts"; |
| 17 | 18 | import { getIssuesByIds, listIssues } from "../../core/issues.ts"; |
| 19 | import { groupsOf } from "./crash_card.ts"; | |
| 18 | 20 | import { openPullsClosing, type Pull } from "../../core/pulls.ts"; |
| 19 | 21 | import { canSeeOwnerFacts, type Repo } from "../../core/repos.ts"; |
| 20 | 22 | import { latestRunsForIssues, listRuns, type Run } from "../../core/runs.ts"; |
| @@ -265,6 +267,21 @@ export async function nowCard( | ||
| 265 | 267 | }); |
| 266 | 268 | }); |
| 267 | 269 | |
| 270 | // Only the owner decides, and only for a group that grows across builds: one row per group. | |
| 271 | const crashDecisions = | |
| 272 | ownerFacts && (record.crashGroups ?? 0) > 0 | |
| 273 | ? needDecision(groupsOf(ctx, repo)).map(({ issue, group }) => | |
| 274 | row({ | |
| 275 | href: tellHref(base, issue.number), | |
| 276 | num: issue.number, | |
| 277 | nav: true, | |
| 278 | lead: avatar("crew"), | |
| 279 | title: issue.title, | |
| 280 | meta: html`${group.count} reports across ${group.builds.length} builds, no fix pull yet. Open the issue and tell the crew what to do.`, | |
| 281 | }), | |
| 282 | ) | |
| 283 | : []; | |
| 284 | ||
| 268 | 285 | const nowRows: Html[] = [ |
| 269 | 286 | ...busyRows, |
| 270 | 287 | ...(await Promise.all( |
| @@ -317,6 +334,8 @@ export async function nowCard( | ||
| 317 | 334 | // `personHeld` has already established the holder is a person, so |
| 318 | 335 | // `voiceFor` names them to every viewer who can see the row. |
| 319 | 336 | ...heldRows, |
| 337 | // A crash group asks the owner once, however many reports it has had (#18127). | |
| 338 | ...crashDecisions, | |
| 320 | 339 | ...stuck.map((i) => { |
| 321 | 340 | return row({ |
| 322 | 341 | lead: avatar("crew"), |
test/crash-groups-page.test.ts added +99
| @@ -0,0 +1,99 @@ | ||
| 1 | /** | |
| 2 | * The repository's crash list in one query (#18127): two groups, one with a fix pull, read in at | |
| 3 | * most three statements however many groups there are, and the owner's Now holds one row for a | |
| 4 | * group that grows across builds, not one per report. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 7 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { createApp, type App } from "../src/app.ts"; | |
| 11 | import { openCrashGroups, reportCrash } from "../src/actions/crash_reports.ts"; | |
| 12 | import { needDecision, openGroups, parseReports } from "../src/core/crash_groups.ts"; | |
| 13 | import { createPull } from "../src/core/pulls.ts"; | |
| 14 | import { repoDir } from "../src/git/repos.ts"; | |
| 15 | import type { User } from "../src/core/users.ts"; | |
| 16 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 17 | import { getRepo, type Repo } from "../src/core/repos.ts"; | |
| 18 | import type { AppRecord } from "../src/core/apps.ts"; | |
| 19 | import type { Ctx } from "../src/http/context.ts"; | |
| 20 | import { groupsOf } from "../src/web/studio/crash_card.ts"; | |
| 21 | import { nowCard } from "../src/web/studio/now.ts"; | |
| 22 | import type { WordCtx } from "../src/web/studio/words.ts"; | |
| 23 | import { seedAdmin } from "./helpers/admin.ts"; | |
| 24 | import { crashLines } from "../src/tui/screens/crash_groups.ts"; | |
| 25 | import { once } from "./helpers/statements.ts"; | |
| 26 | ||
| 27 | let dir = ""; | |
| 28 | let app: App; | |
| 29 | let repo: Repo; | |
| 30 | let alice: User; | |
| 31 | const file = (build: string, frame: string) => { | |
| 32 | const r = parseReports({ v: 1, build, frames: [frame] }); | |
| 33 | if (!r.ok) throw new Error(r.error); | |
| 34 | const filed = reportCrash(app, repo, r.value[0]!); | |
| 35 | if (!filed.ok) throw new Error("not filed"); | |
| 36 | return filed.value; | |
| 37 | }; | |
| 38 | ||
| 39 | beforeAll(async () => { | |
| 40 | dir = await mkdtemp(join(tmpdir(), "forge-crash-page-")); | |
| 41 | app = createApp({ dataDir: dir, port: 0 }); | |
| 42 | const made0 = await seedAdmin(app, { username: "alice", email: "[email protected]", password: "a-good-passphrase" }); | |
| 43 | if (!made0.ok) throw new Error(made0.error); | |
| 44 | alice = made0.value; | |
| 45 | const made = await createRepo(app, alice, { name: "shop", visibility: "public" }); | |
| 46 | if (!made.ok) throw new Error(made.error); | |
| 47 | repo = getRepo(app.db, "alice", "shop")!; | |
| 48 | }); | |
| 49 | afterAll(() => rm(dir, { recursive: true, force: true })); | |
| 50 | ||
| 51 | test("two groups, one with a pull: rows, escaped words and at most three statements", async () => { | |
| 52 | const a = file("1", "<b>Alpha</b> +1"); | |
| 53 | const b = file("1", "Beta +1"); | |
| 54 | const done = await commitToBranch(app, alice, repo, { message: "seed", files: [{ path: "seed.txt", content: "x\n" }] }); | |
| 55 | if (!done.ok) throw new Error(String(done.error)); | |
| 56 | const side = await commitToBranch(app, alice, repo, { message: "fix", branch: "fix-beta", files: [{ path: "fix.txt", content: "x\n" }] } as any); | |
| 57 | if (!side.ok) throw new Error(String(side.error)); | |
| 58 | const pull = await createPull(app.db, repoDir(app.reposRoot, "alice", "shop"), { repoId: repo.id, authorId: repo.ownerId, title: "Fix beta", body: `Closes #${b.number}`, baseBranch: "main", headBranch: "fix-beta" }); | |
| 59 | if (!pull.ok) throw new Error(String(pull.error)); | |
| 60 | const rows = openGroups(app.db, repo.id); | |
| 61 | expect(rows.map((r) => r.issue.number).sort()).toEqual([a.number, b.number].sort()); | |
| 62 | expect(rows.find((r) => r.issue.number === b.number)!.pull?.number).toBe(pull.value.number); | |
| 63 | expect(rows.find((r) => r.issue.number === a.number)!.pull).toBeUndefined(); | |
| 64 | const text = crashLines(openCrashGroups(app, repo)).join("\n"); | |
| 65 | expect(text).toContain(`Fix: Pull #${pull.value.number}`); | |
| 66 | expect(text).toContain("Fix: No fix pull yet"); | |
| 67 | const n = await once(app.db, () => void openGroups(app.db, repo.id)); | |
| 68 | expect(n).toBeLessThanOrEqual(3); | |
| 69 | file("1", "Gamma +1"); | |
| 70 | file("1", "Delta +1"); | |
| 71 | expect(await once(app.db, () => void openGroups(app.db, repo.id))).toBe(n); | |
| 72 | expect(await once(app.db, () => void openGroups(app.db, "none"))).toBe(1); | |
| 73 | }); | |
| 74 | ||
| 75 | test("ten reports of one group over three builds are one decision, not ten", () => { | |
| 76 | const first = file("1", "Growing +1"); | |
| 77 | for (let i = 0; i < 9; i++) file(String(1 + (i % 3)), "Growing +1"); | |
| 78 | const rows = needDecision(openGroups(app.db, repo.id)); | |
| 79 | expect(rows.map((r) => r.issue.number)).toEqual([first.number]); | |
| 80 | expect(rows[0]!.group.count).toBe(10); | |
| 81 | }); | |
| 82 | ||
| 83 | test("the owner's Now card holds one row for ten reports; a non-owner's holds none; the page reads the groups once", async () => { | |
| 84 | const first = file("1", "NowRow +1"); | |
| 85 | for (let i = 0; i < 9; i++) file(String(1 + (i % 3)), "NowRow +1"); | |
| 86 | const record = { crashGroups: 1 } as unknown as AppRecord; | |
| 87 | const ctx = { app, auth: { user: undefined } } as unknown as Ctx; | |
| 88 | const wordCtx = { db: app.db, dir: dir, runtime: undefined, record, history: {}, viewer: undefined } as unknown as WordCtx; | |
| 89 | const card = (ownerFacts: boolean) => | |
| 90 | nowCard(ctx, repo, record, { openPulls: [], builderCount: 1, ownerFacts, wordCtx, deployTailing: false }).then((c) => String(c.card)); | |
| 91 | const owner = await card(true); | |
| 92 | expect(owner.split(`#${first.number}`).length - 1).toBe(1); | |
| 93 | expect(owner).toContain("10 reports across 3 builds"); | |
| 94 | expect(owner).toContain("Open the issue and tell the crew"); | |
| 95 | expect(await card(false)).not.toContain("10 reports across 3 builds"); | |
| 96 | // Now and the crash card on one request share one read of the groups. | |
| 97 | const n = await once(app.db, () => void groupsOf(ctx, repo)); | |
| 98 | expect(await once(app.db, () => void (groupsOf(ctx, repo), groupsOf(ctx, repo)))).toBeLessThanOrEqual(n); | |
| 99 | }); |
new above
offline
Second way to find the closing pull;
openPullsClosingin core/pulls.ts does this already. Keep one and delete the other.