Public: anyone can read this; the crew can change it.
The release tick's last beat is readable without a token: when and whether it passed, never its reason, so the v1 probe can prove it through the app proxy #15526
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15524-the-release-tick-s-last-beat-is-readable → main 0 commits fork
7 files
changed +157
−9
docs/REFERENCE.md +1 −1
| @@ -610,7 +610,7 @@ The release keeper (`src/keeper/`, #7557) cuts, promotes and verifies releases o | ||
| 610 | 610 | - **Verify:** it records the known-good version and image before the tag, sets the Deployment's image, and has the new version spend ten minutes under page load probing `/healthz` each second, then opening the home, repository and apps pages at phone size and failing if a dialog, popover or large fixed layer covers the centre of the screen. |
| 611 | 611 | - **Roll back and hold:** three bad probes in a row hold further cuts with the numbers and set the recorded known-good image back by name, never "undo". A pull saying `release hold <N>` lets the fix through, and that release verifying lifts the hold. |
| 612 | 612 | - **Owner's hold:** set and lifted from the card, the terminal (`h`) or MCP `release_hold`, by a person who may roll back, never an agent. |
| 613 | - **Where to see it:** the **Release keeper** card on `/releases`, `Release keeper` in the terminal's palette, the **Maintenance** board under `/boards`, MCP `release_keeper` and `GET /api/v1/keeper` (JSON; 403 for a caller who may not read releases), each gated as `/releases` is: a guest sees none of it. | |
| 613 | - **Where to see it:** the **Release keeper** card on `/releases`, `Release keeper` in the terminal's palette, the **Maintenance** board under `/boards`, MCP `release_keeper` and `GET /api/v1/keeper` (JSON; 403 for a caller who may not read releases); `GET /api/v1/keeper/pulse` answers anyone with the newest beat's `{at, outcome, silent}`, never its reason, each gated as `/releases` is: a guest sees none of it. | |
| 614 | 614 | |
| 615 | 615 | How it works and how to turn it on: [](features/release-keeper.md). |
| 616 | 616 | The release tick's heartbeat (`heartbeat`, and `POST /api/v1/release/heartbeat` for a release path outside the forge): [](features/release-heartbeat.md). |
docs/features/release-heartbeat.md +1
| @@ -11,6 +11,7 @@ Where to see it: | ||
| 11 | 11 | - `/releases`, in the release keeper section: the last heartbeat (`#keeper-heartbeat`) and, while main is green and ahead of production, how far and for how long (`#keeper-ahead`). |
| 12 | 12 | - The terminal: the palette's **Release keeper** screen, gated as /releases is, shows the same two lines under what holds the next cut. |
| 13 | 13 | - `release_keeper` (MCP) and `GET /api/v1/keeper`: `heartbeat` (at, outcome, reason, silent, says). |
| 14 | - `GET /api/v1/keeper/pulse` (#15524), for anyone, no token: `{at, outcome, silent}` of the newest beat, `{at: null}` before the first; never its reason, like a status page. `bun scripts/v1-probe.ts <url>` reads it for its `keeper's last beat` line: FAIL when the beat failed or went silent. | |
| 14 | 15 | |
| 15 | 16 | The flow alarm `main_ahead` (`src/flow/alarm_main_ahead.ts`) fires when main's last finished check passed, its head is not the commit production runs, and main has been ahead for more than 90 minutes. Change the limit with the `release.ahead_minutes` row of `forge_setting` (a whole number, 1 to 10080; anything else is 90). It names production's version and commit, the commits and pulls ahead, how long, and when the tick was last heard from. It is an ask for the owner (home) and one Sentinel issue (`src/crew/sentinel_main_ahead.ts`), which closes itself at the next hunt after production catches up, unless a person commented on it. The issue names the tick's last outcome and time, never its reason: the issue may be public, and the reason is shown only to readers of /releases. |
| 16 | 17 |
scripts/v1-probe.ts +38 −7
| @@ -6,11 +6,13 @@ | ||
| 6 | 6 | * every request goes to `<base-url>`, apart from one GET of `--edition`, and reads only |
| 7 | 7 | * `--repo` (default `trevato/forge`). It never signs in, pays or writes. |
| 8 | 8 | * |
| 9 | * With `FORGE_TOKEN` set (the crew's token for the forge's repository is enough, #15449) it | |
| 10 | * also GETs `/api/v1/keeper` with that token and prints `keeper's last beat`: the release tick's | |
| 11 | * newest outcome and reason, so a stopped release is named from a shell. The token is sent to | |
| 12 | * `<base-url>` only, and to two endpoints only: `/api/v1/keeper`, and `/api/v1/here` when the | |
| 13 | * keeper answers 403, to word the refusal by its cause (#15520). | |
| 9 | * `keeper's last beat` reads `/api/v1/keeper/pulse` with no token (#15524): the release tick's | |
| 10 | * newest outcome, when, and whether it has gone silent; FAIL when it failed or is silent. Only | |
| 11 | * when the pulse is absent (a release before it) and `FORGE_TOKEN` is set (the crew's token for | |
| 12 | * the forge's repository is enough, #15449) does it GET `/api/v1/keeper` with that token, which | |
| 13 | * also names the reason. The token is sent to `<base-url>` only, and to two endpoints only: | |
| 14 | * `/api/v1/keeper`, and `/api/v1/here` when the keeper answers 403, to word the refusal by its | |
| 15 | * cause (#15520). | |
| 14 | 16 | * |
| 15 | 17 | * The schedules line reads `<base-url>/edition` (#15474), the morning paper's edition page; a 404 |
| 16 | 18 | * there is UNKNOWN, `this release predates /edition`. `--edition` is another public page a |
| @@ -338,7 +340,8 @@ export async function probe(base: string, repo: string, fetcher: Fetcher = fetch | ||
| 338 | 340 | else say(`security headers on ${path}`, "FAIL", path, `missing ${missing.join(", ")}`); |
| 339 | 341 | } |
| 340 | 342 | |
| 341 | // 8. The release keeper's newest beat (#15449), only for a caller holding a token. A refusal is | |
| 343 | // 8. The release keeper's newest beat: the public pulse first (#15524), then, when a release | |
| 344 | // before it answers none, `/api/v1/keeper` for a caller holding a token (#15449). A refusal is | |
| 342 | 345 | // worded by its cause (#15520), read from `/api/v1/here` with the same token: a 401 is a token |
| 343 | 346 | // this forge knows no account for; "anonymous" means the header never reached the forge (a proxy |
| 344 | 347 | // in front strips `authorization`, as the hosting forge's app proxy does for every app); a name |
| @@ -354,7 +357,11 @@ export async function probe(base: string, repo: string, fetcher: Fetcher = fetch | ||
| 354 | 357 | const as = typeof you?.as === "string" ? you.as.replace(/[^\w-]/g, "") : "unknown"; |
| 355 | 358 | return `403, this token's account (here a ${as}) may not read the release history: it must write the forge's repository or administer`; |
| 356 | 359 | }; |
| 357 | if (token) { | |
| 360 | const pulseSeen = await get(PULSE_PATH); | |
| 361 | const pulse = typeof pulseSeen === "string" || pulseSeen.status !== 200 ? undefined : pulseOf(json(pulseSeen)); | |
| 362 | if (pulse === null) say(KEEPER_ITEM, "UNKNOWN", PULSE_PATH, "no heartbeat yet: the release tick has not reported"); | |
| 363 | else if (pulse !== undefined) say(KEEPER_ITEM, pulseVerdict(pulse), PULSE_PATH, pulseWords(pulse)); | |
| 364 | else if (token) { | |
| 358 | 365 | const keeper = await get("/api/v1/keeper", { headers: { authorization: `Bearer ${token}` } }); |
| 359 | 366 | const beat = keeperBeat(typeof keeper === "string" ? undefined : json(keeper)); |
| 360 | 367 | if (typeof keeper === "string") say(KEEPER_ITEM, "UNKNOWN", "/api/v1/keeper", keeper); |
| @@ -369,6 +376,30 @@ export async function probe(base: string, repo: string, fetcher: Fetcher = fetch | ||
| 369 | 376 | } |
| 370 | 377 | |
| 371 | 378 | export const KEEPER_ITEM = "keeper's last beat"; |
| 379 | export const PULSE_PATH = "/api/v1/keeper/pulse"; | |
| 380 | ||
| 381 | /** A public pulse's beat (#15524). */ | |
| 382 | export interface Pulse { | |
| 383 | readonly at: string; | |
| 384 | readonly outcome: string; | |
| 385 | readonly silent: boolean; | |
| 386 | } | |
| 387 | ||
| 388 | /** | |
| 389 | * The pulse answer read: null when it says no beat yet (`{at: null}`), undefined when it is not a | |
| 390 | * pulse at all; its words stripped of control characters. | |
| 391 | */ | |
| 392 | export function pulseOf(answer: unknown): Pulse | null | undefined { | |
| 393 | if (answer === null || typeof answer !== "object") return undefined; | |
| 394 | const { at, outcome, silent } = answer as Record<string, unknown>; | |
| 395 | if (at === null) return null; | |
| 396 | if (typeof at !== "string" || typeof outcome !== "string") return undefined; | |
| 397 | const plain = (t: string) => t.replace(/[\u0000-\u001f\u007f-\u009f]/g, " ").slice(0, 60); | |
| 398 | return { at: plain(at), outcome: plain(outcome), silent: silent === true }; | |
| 399 | } | |
| 400 | ||
| 401 | export const pulseVerdict = (p: Pulse): Verdict => (p.outcome === "failed" || p.silent ? "FAIL" : "PASS"); | |
| 402 | export const pulseWords = (p: Pulse): string => `${p.outcome} at ${p.at}${p.silent ? " (silent: no beat for over a day)" : ""}`; | |
| 372 | 403 | |
| 373 | 404 | const NOT_ACCEPTED = (status: number, origin: string) => |
| 374 | 405 | `${status}, token not accepted here: ${origin} knows no account for it (a token from another forge?)`; |
src/contract/openapi/routes/getApiV1KeeperPulse.ts added +10
| @@ -0,0 +1,10 @@ | ||
| 1 | import type { Route } from "../shared.ts"; | |
| 2 | ||
| 3 | export const route: Route = { | |
| 4 | method: "get", | |
| 5 | path: "/api/v1/keeper/pulse", | |
| 6 | summary: "The release tick's last beat", | |
| 7 | detail: "When the release keeper's newest heartbeat was, its outcome (cut, skipped or failed) and whether it has gone silent, for anyone; never its reason. `{at: null}` before the first beat", | |
| 8 | auth: false, | |
| 9 | role: "anonymous", | |
| 10 | }; |
src/contract/openapi/routes/index.ts +1
| @@ -115,6 +115,7 @@ export { route as getApiV1Front } from "./getApiV1Front.ts"; | ||
| 115 | 115 | export { route as getApiV1Health } from "./getApiV1Health.ts"; |
| 116 | 116 | export { route as getApiV1Here } from "./getApiV1Here.ts"; |
| 117 | 117 | export { route as getApiV1Keeper } from "./getApiV1Keeper.ts"; |
| 118 | export { route as getApiV1KeeperPulse } from "./getApiV1KeeperPulse.ts"; | |
| 118 | 119 | export { route as getApiV1MaintenanceDuties } from "./getApiV1MaintenanceDuties.ts"; |
| 119 | 120 | export { route as getApiV1MaintenanceRuns } from "./getApiV1MaintenanceRuns.ts"; |
| 120 | 121 | export { route as getApiV1Map } from "./getApiV1Map.ts"; |
src/http/api/keeper.ts +16 −1
| @@ -3,6 +3,11 @@ | ||
| 3 | 3 | * the next cut, for whoever may read /releases or write the forge repository (#15515) — MCP |
| 4 | 4 | * `release_keeper` over HTTP. The answer is `keeper/landed.ts`'s `keeperAnswer`. |
| 5 | 5 | * |
| 6 | * `GET /api/v1/keeper/pulse` (#15524): the newest heartbeat's `{at, outcome, silent}` for anyone, | |
| 7 | * like a status page, so the v1 probe proves the release tick through a proxy that strips | |
| 8 | * `authorization`. Never the reason, the history or anything else: those stay behind | |
| 9 | * `mayReadKeeper`. `{at: null}` before the first beat. | |
| 10 | * | |
| 6 | 11 | * `POST /api/v1/release/heartbeat` (#11674): a release path outside the forge |
| 7 | 12 | * leaves the same heartbeat the in-process keeper's tick does, `{outcome, |
| 8 | 13 | * reason}`, for an administrator's admin token; anyone else is refused. |
| @@ -11,7 +16,7 @@ | ||
| 11 | 16 | import { INVALID_TOKEN_HINT, INVALID_TOKEN_WORDS } from "../../actions/here.ts"; |
| 12 | 17 | import { notePhase, takeSessionTime } from "../../core/route_timing.ts"; |
| 13 | 18 | import { isOutcome, REASON_MAX, recordBeat } from "../../keeper/beat.ts"; |
| 14 | import { keeperAnswer } from "../../keeper/landed.ts"; | |
| 19 | import { heartbeatOf, keeperAnswer } from "../../keeper/landed.ts"; | |
| 15 | 20 | import { mayReadKeeper } from "../../release/gate.ts"; |
| 16 | 21 | import type { Handler } from "../context.ts"; |
| 17 | 22 | import { holds, weakEtag } from "../etag.ts"; |
| @@ -38,6 +43,16 @@ export function keeperRoutes(router: Router<Handler>): void { | ||
| 38 | 43 | return new Response(text, { headers: { "content-type": "application/json", ...headers } }); |
| 39 | 44 | }); |
| 40 | 45 | |
| 46 | router.add("GET", "/api/v1/keeper/pulse", (ctx) => { | |
| 47 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 48 | const beat = heartbeatOf(ctx.app.db); | |
| 49 | // Named fields only: a new field on the heartbeat never leaks here by spreading it. | |
| 50 | const pulse = beat === null ? { at: null } : { at: beat.at, outcome: beat.outcome, silent: beat.silent }; | |
| 51 | return new Response(JSON.stringify(pulse), { | |
| 52 | headers: { "content-type": "application/json", "cache-control": "no-cache" }, | |
| 53 | }); | |
| 54 | }); | |
| 55 | ||
| 41 | 56 | router.add("POST", "/api/v1/release/heartbeat", async (ctx) => { |
| 42 | 57 | const denied = requireScope(ctx, "admin"); |
| 43 | 58 | if (denied) return denied; |
test/keeper-pulse.test.ts added +90
| @@ -0,0 +1,90 @@ | ||
| 1 | /** | |
| 2 | * `GET /api/v1/keeper/pulse` (#15524): the release tick's newest beat — when, its outcome, whether | |
| 3 | * it went silent — for anyone, never its reason; `/api/v1/keeper` stays behind `mayReadKeeper`. | |
| 4 | * The v1 probe reads the pulse without a token into PASS or FAIL. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, describe, 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 { createRepo } from "../src/actions/repos.ts"; | |
| 11 | import { createApp, type App } from "../src/app.ts"; | |
| 12 | import { createToken } from "../src/core/tokens.ts"; | |
| 13 | import { createUser } from "../src/core/users.ts"; | |
| 14 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 15 | import { recordBeat } from "../src/keeper/beat.ts"; | |
| 16 | import { KEEPER_ITEM, probe, pulseOf, pulseVerdict, pulseWords } from "../scripts/v1-probe.ts"; | |
| 17 | ||
| 18 | describe("the keeper's public pulse", () => { | |
| 19 | let dataDir: string; | |
| 20 | let app: App; | |
| 21 | let servers: Servers; | |
| 22 | let reader: string; | |
| 23 | ||
| 24 | beforeAll(async () => { | |
| 25 | dataDir = await mkdtemp(join(tmpdir(), "forge-keeper-pulse-")); | |
| 26 | app = createApp({ dataDir, port: 0, forgeRepo: "alice/forge" }); | |
| 27 | servers = await serve(app); | |
| 28 | const a = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 29 | if (!a.ok) throw new Error(a.error); | |
| 30 | const forge = await createRepo(app, a.value, { name: "forge", visibility: "public" }); | |
| 31 | if (!forge.ok) throw new Error("repo"); | |
| 32 | const b = await createUser(app.db, { origin: "seed", trusted: true, username: "bob", email: "[email protected]", password: "a-good-passphrase" }); | |
| 33 | if (!b.ok) throw new Error(b.error); | |
| 34 | reader = createToken(app.db, b.value.id, "probe", "ro").token; | |
| 35 | }, 30_000); | |
| 36 | ||
| 37 | afterAll(async () => { | |
| 38 | servers.stop(); | |
| 39 | app.close(); | |
| 40 | await rm(dataDir, { recursive: true, force: true }); | |
| 41 | }); | |
| 42 | ||
| 43 | const pulse = () => fetch(`${servers.url}/api/v1/keeper/pulse`); | |
| 44 | ||
| 45 | test("before the first beat it answers {at: null}", async () => { | |
| 46 | const res = await pulse(); | |
| 47 | expect(res.status).toBe(200); | |
| 48 | expect(await res.json()).toEqual({ at: null }); | |
| 49 | }); | |
| 50 | ||
| 51 | test("anonymous gets 200 with at, outcome and silent only: never the reason", async () => { | |
| 52 | recordBeat(app.db, "failed", "secret-ish reason: tag push refused"); | |
| 53 | const res = await pulse(); | |
| 54 | expect(res.status).toBe(200); | |
| 55 | expect(res.headers.get("x-content-type-options")).toBe("nosniff"); | |
| 56 | const body = (await res.json()) as Record<string, unknown>; | |
| 57 | expect(Object.keys(body).sort()).toEqual(["at", "outcome", "silent"]); | |
| 58 | expect(body).not.toHaveProperty("reason"); | |
| 59 | expect(body.outcome).toBe("failed"); | |
| 60 | expect(body.silent).toBe(false); | |
| 61 | expect(typeof body.at).toBe("string"); | |
| 62 | }); | |
| 63 | ||
| 64 | test("/api/v1/keeper stays 403 to anonymous and to a read-only token", async () => { | |
| 65 | expect((await fetch(`${servers.url}/api/v1/keeper`)).status).toBe(403); | |
| 66 | const res = await fetch(`${servers.url}/api/v1/keeper`, { headers: { authorization: `Bearer ${reader}` } }); | |
| 67 | expect(res.status).toBe(403); | |
| 68 | }); | |
| 69 | ||
| 70 | test("the probe reads the pulse with no token into PASS or FAIL", async () => { | |
| 71 | const line = async () => (await probe(servers.url, "alice/forge", fetch, Date.now())).find((l) => l.item === KEEPER_ITEM)!; | |
| 72 | const failed = await line(); | |
| 73 | expect(failed.verdict).toBe("FAIL"); | |
| 74 | expect(failed.url).toEndWith("/api/v1/keeper/pulse"); | |
| 75 | expect(failed.evidence).not.toContain("tag push"); | |
| 76 | recordBeat(app.db, "cut", "v1.0.0"); | |
| 77 | expect((await line()).verdict).toBe("PASS"); | |
| 78 | }, 30_000); | |
| 79 | ||
| 80 | test("pulseOf parses a pulse, a silent beat fails, and words are stripped", () => { | |
| 81 | expect(pulseOf({ at: null })).toBeNull(); | |
| 82 | expect(pulseOf({ error: "not_found" })).toBeUndefined(); | |
| 83 | expect(pulseOf("x")).toBeUndefined(); | |
| 84 | const cut = pulseOf({ at: "2026-11-22T10:00:00.000Z", outcome: "cut\u001b[2J", silent: false })!; | |
| 85 | expect([pulseVerdict(cut), pulseWords(cut)]).toEqual(["PASS", "cut [2J at 2026-11-22T10:00:00.000Z"]); | |
| 86 | expect(pulseVerdict(pulseOf({ at: "t", outcome: "skipped", silent: false })!)).toBe("PASS"); | |
| 87 | expect(pulseVerdict(pulseOf({ at: "t", outcome: "skipped", silent: true })!)).toBe("FAIL"); | |
| 88 | expect(pulseVerdict(pulseOf({ at: "t", outcome: "failed", silent: false })!)).toBe("FAIL"); | |
| 89 | }); | |
| 90 | }); |
new above
offline