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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/forge:mason/17014-an-edge-kept-finding-goes-to-the-owner-a → main 0 commits fork 2 threads · 2 unresolved

  • Merged. mason/17014-an-edge-kept-finding-goes-to-the-owner-a was merged into main as df949fc.

Review

Sign in to review this change.
4 files changed +37 −4
docs/features/maintenance-duties.md +1 −1
@@ -34,7 +34,7 @@ Tests: `test/maintain-wait-split.test.ts`.
3434
3535 ## Edge kept (#14663)
3636
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.
3838
3939 Tests: `test/maintain-edge-kept.test.ts`.
4040
src/checks/flake.ts +3 −2
@@ -10,7 +10,7 @@
1010 */
1111
1212 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";
1414 import type { Repo } from "../core/repos.ts";
1515 import type { EventBus } from "../core/events.ts";
1616 import { id } from "../kernel/id.ts";
@@ -321,7 +321,7 @@ export function fileIssueOnce(
321321 db: Database,
322322 bus: EventBus,
323323 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 },
325325 ): { number: number; opened: boolean } {
326326 const open = db
327327 .query<{ number: number }, [string, string]>(
@@ -333,6 +333,7 @@ export function fileIssueOnce(
333333 if (!made.ok) return { number: 0, opened: false };
334334 const labelIds = [...(issue.labelId === undefined ? [] : [issue.labelId]), ...(issue.labelIds ?? [])];
335335 if (labelIds.length > 0) setIssueLabels(db, made.value.id, labelIds);
336 if (issue.assigneeId !== undefined) setAssignee(db, made.value.id, issue.assigneeId);
336337 bus.append({
337338 kind: "issue.opened",
338339 repoId: repo.id,
src/maintain/duties/edge_kept.ts +5 −1
@@ -13,6 +13,7 @@
1313 */
1414
1515 import { fileIssueOnce } from "../../checks/flake.ts";
16 import { getIssue, setAssignee } from "../../core/issues.ts";
1617 import { getRepo } from "../../core/repos.ts";
1718 import { EDGE_VARY } from "../../http/edge_cache.ts";
1819 import { ownRepoPath } from "../../kernel/own_repo.ts";
@@ -36,6 +37,7 @@ export const title = (path: string): string => `The edge is not keeping ${path},
3637
3738 const body = (path: string, seen: string): string =>
3839 `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" +

This line and the next both say the fix is the owner's. One sentence would do.

3941 `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` +
4042 "This issue is filed once per page and left open until it is fixed; the hourly duty `edge-kept` checks again.";
4143
@@ -85,11 +87,13 @@ export function edgeKept(read: Get = get, inCell: () => boolean = inACell): Duty
8587 actions.push(`${path}: not kept, but this forge's own repository is not here to file it in`);
8688 continue;
8789 }
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 });
8991 if (filed.opened) {
9092 findings.push({ summary: `${summary}; filed ${owner}/${name}#${String(filed.number)}`, probe });
9193 actions.push(`filed issue #${String(filed.number)}`);
9294 } 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`);

Read the issue once (const held = getIssue(...)) and drop the ! and the double lookup; the line is hard to read as it stands.

9397 else actions.push(`already filed as issue #${String(filed.number)}`);
9498 }
9599 return { findings, actions };
test/maintain-edge-kept.test.ts +28
@@ -11,6 +11,9 @@ import { edgeKept, edgeVerdict, marked } from "../src/maintain/edge_kept.ts";
1111 import { sharedCache } from "../src/http/edge_cache.ts";
1212 import { createUser } from "../src/core/users.ts";
1313 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";
1417 import { ownRepoPath } from "../src/kernel/own_repo.ts";
1518
1619 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 (
8992 expect(body.body).toContain("Cookie, Authorization");
9093 });
9194
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
92120 test("no edge header, an unshared page, a refused host or no URL say nothing", async () => {
93121 expect((await (await run(shareable({}))).once()).findings).toEqual([]);
94122 expect((await (await run(async () => h({ "cache-control": "no-cache", "cf-cache-status": "DYNAMIC" }))).once()).findings).toEqual([]);

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

Keyboard shortcuts

Docs