Public: anyone can read this; the crew can change it.
Defect on the v1.0.0 path: production's /api/v1/keeper/pulse answers {at:null} on the running release, so the keeper line of the v1 probe is still UNKNOWN #15532
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15530-defect-on-the-v1-0-0-path-production-s-a → main 0 commits fork 2 threads · 2 unresolved
4 files
changed +139
−2
src/keeper/beat.ts +50
| @@ -106,3 +106,53 @@ export function beatFact(beat: Beat | null, now: Date): string { | ||
| 106 | 106 | const age = now.getTime() - Date.parse(beat.at); |
| 107 | 107 | return `${beat.outcome}, ${agoWords(age)}${age > SILENT_MS ? " (silent)" : ""}: ${beat.reason}`; |
| 108 | 108 | } |
| 109 | ||
| 110 | /** | |
| 111 | * The release tick of a hosted forge (#15530). A forge run as an app of another (its host signs | |
| 112 | * calls with `FORGE_APP_IDENTITY_KEY`) is released by that host: production follows the default | |
| 113 | * branch and is deployed on every merge. Its in-process keeper is off and no host timer posts a | |
| 114 | * heartbeat, so the pulse said `{at: null}` forever. This tick runs at boot and every | |
| 115 | * {@link HOSTED_EVERY_MS} and records a `skipped` beat saying why. It runs only hosted with the | |
| 116 | * keeper not asked for: on a forge whose beats come from its own host timer, a beat from this | |
| 117 | * would hide a dead timer from the quiet-release alarm. | |
| 118 | */ | |
| 119 | export const HOSTED_EVERY_MS = 60 * 60_000; | |
| 120 | ||
| 121 | /** Whether this forge's releases are its host's: run as an app, with the keeper not asked for. */ | |
| 122 | export function releasedByHost(env: Record<string, string | undefined>): boolean { | |
| 123 | const hosted = (env.FORGE_APP_IDENTITY_KEY ?? "").trim() !== ""; | |
| 124 | const asked = env.FORGE_RELEASE_KEEPER === "on" || env.FORGE_RELEASE_KEEPER === "swap"; | |
| 125 | return hosted && !asked; | |
| 126 | } | |
| 127 | ||
| 128 | /** | |
| 129 | * One hosted tick: nothing to cut here, and the beat says so. Always `skipped`: a fresh one shows | |
| 130 | * this process is up and ticking, never that a release went through; the host's deploy is that. | |
| 131 | */ | |
| 132 | export function hostedStep(): Step { | |
| 133 | return { | |
| 134 | outcome: "skipped", | |
| 135 | line: "released by the host forge's deploy of the default branch, not by this tick; this beat shows the forge is up, not that a release went through", | |
| 136 | }; | |
| 137 | } | |
| 138 | ||
| 139 | /** | |
| 140 | * Start the hosted tick: the first beat now, then one every {@link HOSTED_EVERY_MS} through | |
| 141 | * `repeat`, which owns the timer and returns its stop (main.ts: a `setInterval` timed by `during` | |
| 142 | * as the `release-hosted` job; a test fires it by hand). Returns that stop, or undefined when | |
| 143 | * {@link releasedByHost} says releases are not the host's and nothing starts. | |
| 144 | */ | |
| 145 | export function startHostedTick( | |
| 146 | db: Database, | |
| 147 | env: Record<string, string | undefined>, | |
| 148 | repeat: (tick: () => void, ms: number) => () => void, | |
| 149 | now: () => Date = () => new Date(), | |
| 150 | ): (() => void) | undefined { | |
| 151 | if (!releasedByHost(env)) return undefined; | |
| 152 | const tick = () => { | |
| 153 | const step = hostedStep(); | |
| 154 | writeBeat(db, step.outcome, step.line, now()); | |
| 155 | }; | |
| 156 | tick(); | |
| 157 | return repeat(tick, HOSTED_EVERY_MS); | |
| 158 | } |
src/main.ts +8 −1
| @@ -121,7 +121,7 @@ import { ownTagsReader } from "./release/own_tags.ts"; | ||
| 121 | 121 | import { recordByHand } from "./keeper/by_hand.ts"; |
| 122 | 122 | import { settleLiveNow } from "./actions/estimates_settle.ts"; |
| 123 | 123 | import { rollProbe, tickStep as keeperTick } from "./keeper/keeper.ts"; |
| 124 | import { stepWithBeat } from "./keeper/beat.ts"; | |
| 124 | import { startHostedTick, stepWithBeat } from "./keeper/beat.ts"; | |
| 125 | 125 | import { keeperEnv, keeperPorts } from "./keeper/wire.ts"; |
| 126 | 126 | import { noteKeeperAtBoot } from "./keeper/at_boot.ts"; |
| 127 | 127 | import { snapshotPlace } from "./actions/health.ts"; |
| @@ -1041,6 +1041,7 @@ if (app.config.forgeRepo) { | ||
| 1041 | 1041 | // named known-good image and hold. Off unless FORGE_RELEASE_KEEPER=on in a cluster |
| 1042 | 1042 | // (keeper/wire.ts). |
| 1043 | 1043 | const keeperOn = keeperEnv(process.env); |
| 1044 | let stopHostedTick: (() => void) | undefined; | |
| 1044 | 1045 | if (keeperOn.on) { |
| 1045 | 1046 | const ports = keeperPorts( |
| 1046 | 1047 | app, |
| @@ -1069,6 +1070,11 @@ if (keeperOn.on) { | ||
| 1069 | 1070 | } else { |
| 1070 | 1071 | noteKeeperAtBoot(keeperOn); |
| 1071 | 1072 | app.log.info("the release keeper is off", { why: keeperOn.why }); |
| 1073 | // Hosted, the release is the host's deploy; the tick says so at boot and hourly (#15530). | |
| 1074 | stopHostedTick = startHostedTick(app.db, process.env, (tick, ms) => { | |
| 1075 | const timer = setInterval(() => during("release-hosted", tick, undefined, app), ms); | |
| 1076 | return () => clearInterval(timer); | |
outdated
Untested boot wiring and a bare setInterval. Move this into a function that tests can call, and use the repo's usual tracked-timer pattern. |
||
| 1077 | }); | |
| 1072 | 1078 | } |
| 1073 | 1079 | // Only an agent is on a crew (the `repo_crew_agents_only` trigger refuses anyone else). A person |
| 1074 | 1080 | // put on one before that is reported here for the owner to take off — the |
| @@ -1165,6 +1171,7 @@ function drain(signal: NodeJS.Signals): Promise<unknown> { | ||
| 1165 | 1171 | if (ledgerTimer !== undefined) clearInterval(ledgerTimer); |
| 1166 | 1172 | clearInterval(followTimer); |
| 1167 | 1173 | landingsWatch(); |
| 1174 | stopHostedTick?.(); | |
| 1168 | 1175 | stopClogTick(); |
| 1169 | 1176 | stopKeeper(); |
| 1170 | 1177 | clearInterval(processTimer); |
test/job-slices.test.ts +1
| @@ -293,6 +293,7 @@ const UNTIMED: Record<string, string> = { | ||
| 293 | 293 | drill: "restores a snapshot into a scratch forge: nightly, I/O", |
| 294 | 294 | "release-behind": "reads the forge's own release tags with git; needs FORGE_REPO and its repository", |
| 295 | 295 | "release-keeper": "cluster only (FORGE_RELEASE_KEEPER=on): talks to the cluster's API", |
| 296 | "release-hosted": "hosted only (FORGE_APP_IDENTITY_KEY set): one INSERT of a skipped beat hourly; test/keeper-pulse.test.ts runs the step", | |
| 296 | 297 | "roll-probe": "cluster only (FORGE_RELEASE_KEEPER=on): one HTTP probe", |
| 297 | 298 | "apps-sweep": "AppsRuntime's sweep over running app processes; the fixture has no apps", |
| 298 | 299 | "profiler-drain": "drains the sampling profiler's stack traces on a timer (perf/sample.ts) so they do not pile up; runs only where the profiler is on, and the fixture samples nothing", |
test/keeper-pulse.test.ts +80 −1
| @@ -12,7 +12,7 @@ import { createApp, type App } from "../src/app.ts"; | ||
| 12 | 12 | import { createToken } from "../src/core/tokens.ts"; |
| 13 | 13 | import { createUser } from "../src/core/users.ts"; |
| 14 | 14 | import { serve, type Servers } from "../src/http/server.ts"; |
| 15 | import { recordBeat } from "../src/keeper/beat.ts"; | |
| 15 | import { HOSTED_EVERY_MS, recordBeat, releasedByHost, SILENT_MS, startHostedTick } from "../src/keeper/beat.ts"; | |
| 16 | 16 | import { KEEPER_ITEM, probe, pulseOf, pulseVerdict, pulseWords } from "../scripts/v1-probe.ts"; |
| 17 | 17 | |
| 18 | 18 | describe("the keeper's public pulse", () => { |
| @@ -88,3 +88,82 @@ describe("the keeper's public pulse", () => { | ||
| 88 | 88 | expect(pulseVerdict(pulseOf({ at: "t", outcome: "failed", silent: false })!)).toBe("FAIL"); |
| 89 | 89 | }); |
| 90 | 90 | }); |
| 91 | ||
| 92 | describe("the hosted forge's release tick (#15530)", () => { | |
| 93 | let dataDir: string; | |
| 94 | let app: App; | |
| 95 | let servers: Servers; | |
| 96 | ||
| 97 | beforeAll(async () => { | |
| 98 | dataDir = await mkdtemp(join(tmpdir(), "forge-keeper-hosted-")); | |
| 99 | app = createApp({ dataDir, port: 0 }); | |
| 100 | servers = await serve(app); | |
| 101 | }, 30_000); | |
| 102 | ||
| 103 | afterAll(async () => { | |
| 104 | servers.stop(); | |
| 105 | app.close(); | |
| 106 | await rm(dataDir, { recursive: true, force: true }); | |
| 107 | }); | |
| 108 | ||
| 109 | test("runs only when hosted and the keeper is not asked for", () => { | |
| 110 | expect(releasedByHost({ FORGE_APP_IDENTITY_KEY: "k" })).toBe(true); | |
| 111 | expect(releasedByHost({ FORGE_APP_IDENTITY_KEY: " " })).toBe(false); | |
| 112 | expect(releasedByHost({})).toBe(false); | |
| 113 | expect(releasedByHost({ FORGE_APP_IDENTITY_KEY: "k", FORGE_RELEASE_KEEPER: "on" })).toBe(false); | |
| 114 | expect(releasedByHost({ FORGE_APP_IDENTITY_KEY: "k", FORGE_RELEASE_KEEPER: "swap" })).toBe(false); | |
| 115 | expect(HOSTED_EVERY_MS).toBeLessThan(SILENT_MS); | |
| 116 | }); | |
| 117 | ||
| 118 | test("off the host, starting it starts nothing and the pulse stays {at: null}", async () => { | |
| 119 | const never = () => { | |
| 120 | throw new Error("no timer off the host"); | |
| 121 | }; | |
| 122 | expect(startHostedTick(app.db, {}, never)).toBeUndefined(); | |
| 123 | expect(startHostedTick(app.db, { FORGE_APP_IDENTITY_KEY: "k", FORGE_RELEASE_KEEPER: "on" }, never)).toBeUndefined(); | |
| 124 | expect(await (await fetch(`${servers.url}/api/v1/keeper/pulse`)).json()).toEqual({ at: null }); | |
| 125 | }); | |
| 126 | ||
| 127 | type Pulse = { at: string | null; outcome?: string; silent?: boolean }; | |
| 128 | const read = async (): Promise<Pulse> => (await (await fetch(`${servers.url}/api/v1/keeper/pulse`)).json()) as Pulse; | |
| 129 | ||
| 130 | test("hosted, starting it beats at once, the pulse returns {at, outcome, silent}, and every interval beats again", async () => { | |
| 131 | let n = 0; | |
| 132 | const base = Date.now() - 60 * 60_000; | |
| 133 | const times = [new Date(base), new Date(base + 30 * 60_000)]; | |
| 134 | let fire: (() => void) | undefined; | |
| 135 | let every = 0; | |
| 136 | let stopped = false; | |
| 137 | const stop = startHostedTick( | |
| 138 | app.db, | |
| 139 | { FORGE_APP_IDENTITY_KEY: "k" }, | |
| 140 | (tick, ms) => { | |
| 141 | fire = tick; | |
| 142 | every = ms; | |
| 143 | return () => { | |
| 144 | stopped = true; | |
| 145 | }; | |
| 146 | }, | |
| 147 | () => times[Math.min(n++, 1)]!, | |
| 148 | ); | |
| 149 | // The first beat is written before startHostedTick returns: no interval stands before it. | |
| 150 | expect(await read()).toEqual({ at: times[0]!.toISOString(), outcome: "skipped", silent: false }); | |
| 151 | expect(every).toBe(HOSTED_EVERY_MS); | |
| 152 | fire!(); | |
| 153 | const later = await read(); | |
| 154 | expect(later.at).toBe(times[1]!.toISOString()); | |
| 155 | expect(Object.keys(later).sort()).toEqual(["at", "outcome", "silent"]); | |
| 156 | stop!(); | |
| 157 | expect(stopped).toBe(true); | |
| 158 | }); | |
| 159 | ||
| 160 | test("a fresh hosted beat is a PASS on the probe, and its reason says it proves the forge is up, not a release", async () => { | |
| 161 | startHostedTick(app.db, { FORGE_APP_IDENTITY_KEY: "k" }, () => () => {})!(); | |
| 162 | const body = await read(); | |
| 163 | expect(body.outcome).toBe("skipped"); | |
| 164 | expect(body.silent).toBe(false); | |
| 165 | expect(pulseVerdict(pulseOf(body)!)).toBe("PASS"); | |
| 166 | const row = app.db.query<{ reason: string }, []>("SELECT reason FROM keeper_beat_tick ORDER BY id DESC LIMIT 1").get()!; | |
| 167 | expect(row.reason).toContain("not that a release went through"); | |
| 168 | }); | |
| 169 | }); |
new above
offline
async with no await. Return the Step through a plain function or Promise.resolve if the signature demands a promise.