Public: anyone can read this; the crew can change it.
An edge-kept finding goes to the owner as an assigned issue, so no builder is handed a fix that lives outside the repository #17027
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/17014-an-edge-kept-finding-goes-to-the-owner-a → main 0 commits fork 2 threads · 2 unresolved
4 files
changed +37
−4
docs/features/maintenance-duties.md +1 −1
| @@ -34,7 +34,7 @@ Tests: `test/maintain-wait-split.test.ts`. | ||
| 34 | 34 | |
| 35 | 35 | ## Edge kept (#14663) |
| 36 | 36 | |
| 37 | The `edge-kept` duty notices when the edge is not keeping the pages the forge marks shareable. Hourly, it sends two signed-out GETs (no cookie) to each of `/` and `/explore`, and only at `config.url` (the forge's own public origin), never a host from a request. If the forge marked the answer shareable (`Cache-Control: public` with a positive `s-maxage`) and the `cf-cache-status` header says the edge went to the forge both times (`DYNAMIC`, `MISS` or `BYPASS`), it files one issue per page, once, and leaves it open. A `HIT`, `STALE` or `REVALIDATED` on either read counts as kept. No edge header, an unshared page, a non-200 answer, a host the forge's gate refuses, or a forge with no `FORGE_URL` say nothing but an action line; so does a forge without its own repository row, which has nowhere to file. The one fix is the owner's, outside this repository: an edge cache rule that caches signed-out HTML and keys on `Cookie, Authorization`. The duty's lines (one per page) show on the maintenance runs lists (`/api/v1/maintenance/runs`, the terminal) after its first run, an hour after boot. | |
| 37 | The `edge-kept` duty notices when the edge is not keeping the pages the forge marks shareable. Hourly, it sends two signed-out GETs (no cookie) to each of `/` and `/explore`, and only at `config.url` (the forge's own public origin), never a host from a request. If the forge marked the answer shareable (`Cache-Control: public` with a positive `s-maxage`) and the `cf-cache-status` header says the edge went to the forge both times (`DYNAMIC`, `MISS` or `BYPASS`), it files one issue per page, once, and leaves it open. A `HIT`, `STALE` or `REVALIDATED` on either read counts as kept. No edge header, an unshared page, a non-200 answer, a host the forge's gate refuses, or a forge with no `FORGE_URL` say nothing but an action line; so does a forge without its own repository row, which has nowhere to file. The one fix is the owner's, outside this repository: an edge cache rule that caches signed-out HTML and keys on `Cookie, Authorization, X-Plat-User, X-Plat-Edge-Token` (`EDGE_VARY`). The issue is assigned to the repository's owner, so the crew's dispatcher (which starts only agent assignees) hands no builder a fix that lives outside the repository; an open one with no assignee is assigned to the owner on the next run, with an action line saying so. The duty's lines (one per page) show on the maintenance runs lists (`/api/v1/maintenance/runs`, the terminal) after its first run, an hour after boot. | |
| 38 | 38 | |
| 39 | 39 | Tests: `test/maintain-edge-kept.test.ts`. |
| 40 | 40 |
src/checks/flake.ts +3 −2
| @@ -10,7 +10,7 @@ | ||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | import type { Database } from "bun:sqlite"; |
| 13 | import { createIssue, createLabel, getLabel, setIssueLabels } from "../core/issues.ts"; | |
| 13 | import { createIssue, createLabel, getLabel, setAssignee, setIssueLabels } from "../core/issues.ts"; | |
| 14 | 14 | import type { Repo } from "../core/repos.ts"; |
| 15 | 15 | import type { EventBus } from "../core/events.ts"; |
| 16 | 16 | import { id } from "../kernel/id.ts"; |
| @@ -321,7 +321,7 @@ export function fileIssueOnce( | ||
| 321 | 321 | db: Database, |
| 322 | 322 | bus: EventBus, |
| 323 | 323 | repo: Pick<Repo, "id" | "ownerId">, |
| 324 | issue: { title: string; body: string; labelId?: string; labelIds?: readonly string[] }, | |
| 324 | issue: { title: string; body: string; labelId?: string; labelIds?: readonly string[]; assigneeId?: string }, | |
| 325 | 325 | ): { number: number; opened: boolean } { |
| 326 | 326 | const open = db |
| 327 | 327 | .query<{ number: number }, [string, string]>( |
| @@ -333,6 +333,7 @@ export function fileIssueOnce( | ||
| 333 | 333 | if (!made.ok) return { number: 0, opened: false }; |
| 334 | 334 | const labelIds = [...(issue.labelId === undefined ? [] : [issue.labelId]), ...(issue.labelIds ?? [])]; |
| 335 | 335 | if (labelIds.length > 0) setIssueLabels(db, made.value.id, labelIds); |
| 336 | if (issue.assigneeId !== undefined) setAssignee(db, made.value.id, issue.assigneeId); | |
| 336 | 337 | bus.append({ |
| 337 | 338 | kind: "issue.opened", |
| 338 | 339 | repoId: repo.id, |
src/maintain/duties/edge_kept.ts +5 −1
| @@ -13,6 +13,7 @@ | ||
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | 15 | import { fileIssueOnce } from "../../checks/flake.ts"; |
| 16 | import { getIssue, setAssignee } from "../../core/issues.ts"; | |
| 16 | 17 | import { getRepo } from "../../core/repos.ts"; |
| 17 | 18 | import { EDGE_VARY } from "../../http/edge_cache.ts"; |
| 18 | 19 | import { ownRepoPath } from "../../kernel/own_repo.ts"; |
| @@ -36,6 +37,7 @@ export const title = (path: string): string => `The edge is not keeping ${path}, | ||
| 36 | 37 | |
| 37 | 38 | const body = (path: string, seen: string): string => |
| 38 | 39 | `A signed-out GET of ${path} was marked shareable by the forge (\`Cache-Control: public, s-maxage\`), but twice in a row the edge did not serve it from its copy (${seen}).\n\n` + |
| 40 | "This is the owner's to do; a builder has nothing to change here.\n\n" + | |
| 39 | 41 | `The one fix is the owner's, outside this repository: an edge cache rule that caches signed-out HTML and keys on \`${EDGE_VARY}\`.\n\n` + |
| 40 | 42 | "This issue is filed once per page and left open until it is fixed; the hourly duty `edge-kept` checks again."; |
| 41 | 43 | |
| @@ -85,11 +87,13 @@ export function edgeKept(read: Get = get, inCell: () => boolean = inACell): Duty | ||
| 85 | 87 | actions.push(`${path}: not kept, but this forge's own repository is not here to file it in`); |
| 86 | 88 | continue; |
| 87 | 89 | } |
| 88 | const filed = fileIssueOnce(db, bus, repo, { title: title(path), body: body(path, seen) }); | |
| 90 | const filed = fileIssueOnce(db, bus, repo, { title: title(path), body: body(path, seen), assigneeId: repo.ownerId }); | |
| 89 | 91 | if (filed.opened) { |
| 90 | 92 | findings.push({ summary: `${summary}; filed ${owner}/${name}#${String(filed.number)}`, probe }); |
| 91 | 93 | actions.push(`filed issue #${String(filed.number)}`); |
| 92 | 94 | } else if (filed.number === 0) actions.push(`${path}: not kept, and the issue could not be filed`); |
| 95 | else if (getIssue(db, repo.id, filed.number)?.assigneeId === null && setAssignee(db, getIssue(db, repo.id, filed.number)!.id, repo.ownerId) !== undefined) | |
| 96 | actions.push(`already filed as issue #${String(filed.number)}; assigned it to the owner, whose fix it is`); | |
| 93 | 97 | else actions.push(`already filed as issue #${String(filed.number)}`); |
| 94 | 98 | } |
| 95 | 99 | return { findings, actions }; |
test/maintain-edge-kept.test.ts +28
| @@ -11,6 +11,9 @@ import { edgeKept, edgeVerdict, marked } from "../src/maintain/edge_kept.ts"; | ||
| 11 | 11 | import { sharedCache } from "../src/http/edge_cache.ts"; |
| 12 | 12 | import { createUser } from "../src/core/users.ts"; |
| 13 | 13 | import { createRepo } from "../src/actions/repos.ts"; |
| 14 | import { getIssue } from "../src/core/issues.ts"; | |
| 15 | import { getRepo } from "../src/core/repos.ts"; | |
| 16 | import { agentFor } from "../src/crew/dispatch.ts"; | |
| 14 | 17 | import { ownRepoPath } from "../src/kernel/own_repo.ts"; |
| 15 | 18 | |
| 16 | 19 | const h = (o: Record<string, string>) => new Headers(o); |
| @@ -89,6 +92,31 @@ test("not kept files one issue per page, and a second run adds nothing", async ( | ||
| 89 | 92 | expect(body.body).toContain("Cookie, Authorization"); |
| 90 | 93 | }); |
| 91 | 94 | |
| 95 | test("a new filing is assigned to the owner, says so, and the crew starts no run on it (#17014)", async () => { | |
| 96 | const { app, once } = await run(shareable({ "cf-cache-status": "DYNAMIC" })); | |
| 97 | await once(); | |
| 98 | const [owner = "", name = ""] = ownRepoPath().split("/"); | |
| 99 | const repo = getRepo(app.db, owner, name)!; | |
| 100 | const row = app.db.query("SELECT number FROM issue WHERE title = ?1").get(title("/")) as { number: number }; | |
| 101 | const issue = getIssue(app.db, repo.id, row.number)!; | |
| 102 | expect(issue.assigneeId).toBe(repo.ownerId); | |
| 103 | expect(issue.body).toContain("owner's to do; a builder has nothing to change here"); | |
| 104 | expect(agentFor(app, issue)).toBeUndefined(); | |
| 105 | }); | |
| 106 | ||
| 107 | test("an open filing with no assignee is assigned to the owner, once, with an action line", async () => { | |
| 108 | const { app, once } = await run(shareable({ "cf-cache-status": "DYNAMIC" })); | |
| 109 | await once(); | |
| 110 | const [owner = "", name = ""] = ownRepoPath().split("/"); | |
| 111 | const repo = getRepo(app.db, owner, name)!; | |
| 112 | app.db.query("UPDATE issue SET assignee_id = NULL WHERE title = ?1").run(title("/")); | |
| 113 | const r = await once(); | |
| 114 | expect(r.actions.some((a) => a.includes("assigned it to the owner"))).toBe(true); | |
| 115 | const row = app.db.query("SELECT number FROM issue WHERE title = ?1").get(title("/")) as { number: number }; | |
| 116 | expect(getIssue(app.db, repo.id, row.number)?.assigneeId).toBe(repo.ownerId); | |
| 117 | expect((await once()).actions.some((a) => a.includes("assigned it to the owner"))).toBe(false); | |
| 118 | }); | |
| 119 | ||
| 92 | 120 | test("no edge header, an unshared page, a refused host or no URL say nothing", async () => { |
| 93 | 121 | expect((await (await run(shareable({}))).once()).findings).toEqual([]); |
| 94 | 122 | expect((await (await run(async () => h({ "cache-control": "no-cache", "cf-cache-status": "DYNAMIC" }))).once()).findings).toEqual([]); |
new above
offline
This line and the next both say the fix is the owner's. One sentence would do.