Public: anyone can read this; the crew can change it.
The release proof fails on the first try after every restart, never retries, and leaves its probe forge behind #12568
Closed 18d 5h ago
scout/forge:scout/12367-the-release-proof-fails-on-the-first-try → main 22 commits fork
9 files
changed +151
−7
docs/features/release-heartbeat.md +5
| @@ -39,3 +39,8 @@ A restart wakes every app, so the first walk of the stranger's journey waits for | ||
| 39 | 39 | ## A proof never runs without a word (#12367) |
| 40 | 40 | |
| 41 | 41 | While a proof runs the forge keeps `release/proving.json` (version, start time); the home page's live-version figure says "still proving, started HH:MM UTC" until a verdict replaces it. A proof has `HANG_MS` (30 minutes, shorter than the gap between releases) in all, sized from the worst healthy case (`WORST_CASE_MS`: ten minutes of give-up polling, three minutes of smoke checks, three walks of settle plus the walk's 20 s, two waits of two minutes, five minutes' margin, a test holds it): past it, it is stopped and recorded as a failed, `hung` proof, tried again at the next tick. |
| 42 | ||
| 43 | The proof's probe forge is removed by the host itself (`hands` in `main.ts`, in process: no admin | |
| 44 | token needed); the `release proof` log line says `removed=true`, or `removed=false (probe-… still | |
| 45 | running…)`. A `probe-` forge standing 30 minutes (`release/probes.ts`) is a needs-you card with a | |
| 46 | Remove button, whether or not the proof recorded it. |
src/kernel/vitals.ts +3 −1
| @@ -36,6 +36,7 @@ import { lastDrill } from "../snapshot/drills.ts"; | ||
| 36 | 36 | import { lastMirror, mirrorNeed } from "../snapshot/mirror.ts"; |
| 37 | 37 | import { lastSnapshotOutcome, leftOutNeeds, snapshotNeed } from "../snapshot/outcome.ts"; |
| 38 | 38 | import { drillNeed, lastVerdict } from "../snapshot/verdict.ts"; |
| 39 | import { standingProbes } from "../release/probes.ts"; | |
| 39 | 40 | import { leftoverProbes, proofNeed, proofNotice } from "../release/prove.ts"; |
| 40 | 41 | import { running as runningVersion } from "./version.ts"; |
| 41 | 42 | import { rollbackNeed } from "../release/launch.ts"; |
| @@ -659,7 +660,8 @@ export function vitals(input: VitalsInput): Vitals { | ||
| 659 | 660 | |
| 660 | 661 | // A probe forge the proof could not remove is hidden work on the host: a card each, its |
| 661 | 662 | // Remove page one tap away. |
| 662 | for (const name of leftoverProbes(input.dataDir)) | |
| 663 | // One that outlives its walk by half an hour is the same card, whatever the proof recorded. | |
| 664 | for (const name of new Set([...leftoverProbes(input.dataDir), ...standingProbes(input.dataDir, now)])) | |
| 663 | 665 | if (/^probe-[0-9a-f]{8}$/.test(name)) need("todo", `probe:${name}`, `The release proof's probe forge ${name} could not be removed and is still running.`, undefined, `/forges/${name}/remove`); |
| 664 | 666 | |
| 665 | 667 | // A roll the image's launcher undid is a card until a later version reads ready. Its sentence |
src/main.ts +10
| @@ -103,6 +103,8 @@ import { running } from "./kernel/version.ts"; | ||
| 103 | 103 | import { record as recordDegraded } from "./kernel/degraded_history.ts"; |
| 104 | 104 | import { vitals } from "./kernel/vitals.ts"; |
| 105 | 105 | import { markReady, readFootprint, keepFootprint } from "./system/footprint.ts"; |
| 106 | import { removeForge } from "./spawn/manage.ts"; | |
| 107 | import { listChildren } from "./actions/spawn.ts"; | |
| 106 | 108 | import { proveRunning } from "./release/prove.ts"; |
| 107 | 109 | import { walkJourney } from "./release/journey.ts"; |
| 108 | 110 | import { proberKey } from "./release/prober.ts"; |
| @@ -869,6 +871,14 @@ proveRunning({ | ||
| 869 | 871 | journey: walkJourney, |
| 870 | 872 | footprint: async () => keepFootprint(await readFootprint(app.config.dataDir)), |
| 871 | 873 | proberKey: proberKey(app.hookSecret), |
| 874 | // The host removes its own probe forge in process: no admin token to configure. | |
| 875 | hands: { | |
| 876 | remove: async (name) => { | |
| 877 | const done = await removeForge(app, name); | |
| 878 | return done.ok || done.says.startsWith("no forge named"); | |
| 879 | }, | |
| 880 | list: async () => (await listChildren(app)).map((c) => ({ name: c.name, createdAt: c.createdAt })), | |
| 881 | }, | |
| 872 | 882 | // The first app's production host: it must never answer as the forge (#6726). |
| 873 | 883 | appHost: (() => { |
| 874 | 884 | const first = listApps(app.db)[0]; |
src/release/journey.ts +39 −3
| @@ -36,6 +36,11 @@ export interface JourneyOptions { | ||
| 36 | 36 | readonly now?: () => number; |
| 37 | 37 | /** A site admin's token on the host: removes the throwaway forge afterwards. */ |
| 38 | 38 | readonly adminToken?: string; |
| 39 | /** | |
| 40 | * The host's own hands, when the walk runs inside it: removes a forge and lists the forges it | |
| 41 | * made, with no token and no request. Used before `adminToken`, which a deployment may not have. | |
| 42 | */ | |
| 43 | readonly hands?: HostHands; | |
| 39 | 44 | /** |
| 40 | 45 | * This boot's prober key (`release/prober.ts`): sent to the host only, so the forge's own walk |
| 41 | 46 | * is not a stranger to its rate limits. |
| @@ -47,6 +52,14 @@ export interface JourneyOptions { | ||
| 47 | 52 | readonly sleep?: (ms: number) => Promise<void>; |
| 48 | 53 | } |
| 49 | 54 | |
| 55 | /** What the host does for its own probe, in process (`main.ts` hands in its own `removeForge`). */ | |
| 56 | export interface HostHands { | |
| 57 | /** True when the forge is gone (or never was). */ | |
| 58 | readonly remove: (name: string) => Promise<boolean>; | |
| 59 | /** The forges this host made, with when each was begun. */ | |
| 60 | readonly list: () => Promise<readonly { readonly name: string; readonly createdAt: string | null }[]>; | |
| 61 | } | |
| 62 | ||
| 50 | 63 | export interface JourneyResult { |
| 51 | 64 | readonly ok: boolean; |
| 52 | 65 | /** The screens a person was shown, in order, the forge last. */ |
| @@ -266,16 +279,16 @@ export async function walkJourney(options: JourneyOptions): Promise<JourneyResul | ||
| 266 | 279 | // Afterwards, passed or failed: stop the crew's run, then remove the forge and its account. |
| 267 | 280 | if (forge !== null) { |
| 268 | 281 | if (child !== undefined && cookie !== "") await cancelRuns(doFetch, child, cookie); |
| 269 | removed = await removeForge(doFetch, hostUrl, forge, options.adminToken, sleep); | |
| 282 | removed = await removeForge(doFetch, hostUrl, forge, options.adminToken, sleep, REMOVE_BACKOFF_MS, options.hands); | |
| 270 | 283 | // A forge left running is hidden work on the host: the failure names it (never when there |
| 271 | 284 | // was no token to remove it with). |
| 272 | if (!removed && options.adminToken !== undefined && options.adminToken !== "") | |
| 285 | if (!removed && ((options.adminToken !== undefined && options.adminToken !== "") || options.hands !== undefined)) | |
| 273 | 286 | failure = `${failure === undefined ? "" : `${failure}; `}the probe forge ${forge} could not be removed`; |
| 274 | 287 | } |
| 275 | 288 | } |
| 276 | 289 | // What an interrupted run left: swept after this walk's own cleanup, never its own forge. |
| 277 | 290 | // Bounded (`SWEEP_BUDGET_MS`, `SWEEP_MAX`) and never part of the verdict. |
| 278 | const sweep = await sweepProbes(doFetch, hostUrl, options.adminToken, Date.now(), forge, sleep); | |
| 291 | const sweep = await sweepProbes(doFetch, hostUrl, options.adminToken, Date.now(), forge, sleep, options.hands); | |
| 279 | 292 | const result = { |
| 280 | 293 | ok: failure === undefined, |
| 281 | 294 | screens, |
| @@ -306,8 +319,23 @@ export async function sweepProbes( | ||
| 306 | 319 | at: number, |
| 307 | 320 | except: string | null = null, |
| 308 | 321 | sleep: (ms: number) => Promise<void> = (ms) => Bun.sleep(ms), |
| 322 | hands?: HostHands, | |
| 309 | 323 | ): Promise<{ gone: string[]; error?: string }> { |
| 310 | 324 | const gone: string[] = []; |
| 325 | if (hands !== undefined) { | |
| 326 | try { | |
| 327 | for (const { name, createdAt } of await hands.list()) { | |
| 328 | if (!PROBE_NAME.test(name) || name === except) continue; | |
| 329 | const begun = createdAt === null ? Number.NaN : Date.parse(createdAt); | |
| 330 | if (!Number.isFinite(begun) || at - begun < STALE_PROBE_MS) continue; | |
| 331 | if (gone.length >= SWEEP_MAX) break; | |
| 332 | if (await hands.remove(name).catch(() => false)) gone.push(name); | |
| 333 | } | |
| 334 | return { gone }; | |
| 335 | } catch (e) { | |
| 336 | return { gone, error: e instanceof Error ? e.message : "the sweep stopped unexpectedly" }; | |
| 337 | } | |
| 338 | } | |
| 311 | 339 | if (token === undefined || token === "") return { gone }; |
| 312 | 340 | const deadline = AbortSignal.timeout(SWEEP_BUDGET_MS); |
| 313 | 341 | try { |
| @@ -358,7 +386,15 @@ async function removeForge( | ||
| 358 | 386 | token: string | undefined, |
| 359 | 387 | sleep: (ms: number) => Promise<void>, |
| 360 | 388 | backoff: readonly number[] = REMOVE_BACKOFF_MS, |
| 389 | hands?: HostHands, | |
| 361 | 390 | ): Promise<boolean> { |
| 391 | if (hands !== undefined) { | |
| 392 | for (const ms of [0, ...backoff]) { | |
| 393 | if (ms > 0) await sleep(ms); | |
| 394 | if (await hands.remove(name).catch(() => false)) return true; | |
| 395 | } | |
| 396 | return false; | |
| 397 | } | |
| 362 | 398 | if (token === undefined || token === "") return false; |
| 363 | 399 | if (await removeOnce(doFetch, host, name, token)) return true; |
| 364 | 400 | // Each retry waits first (`backoff`); the sweep passes none, so a stale forge is tried once. |
src/release/probes.ts added +31
| @@ -0,0 +1,31 @@ | ||
| 1 | /** | |
| 2 | * Probe forges that outlived their walk: the release proof's throwaway forges are named | |
| 3 | * `probe-` and eight hex digits, and one still standing `PROBE_STANDS_MS` after it was begun | |
| 4 | * (the walk's own budget is far shorter) is hidden work on the host. Read from the forge's | |
| 5 | * ledgers under the data directory, so the needs-you stack finds it without the network. | |
| 6 | */ | |
| 7 | import { readdirSync, readFileSync } from "node:fs"; | |
| 8 | import { join } from "node:path"; | |
| 9 | ||
| 10 | /** How long a probe forge may stand before it is a card with a Remove button. */ | |
| 11 | export const PROBE_STANDS_MS = 30 * 60_000; | |
| 12 | ||
| 13 | /** Names of `probe-` forges begun at least `PROBE_STANDS_MS` before `now`; never throws. */ | |
| 14 | export function standingProbes(dataDir: string, now: number): string[] { | |
| 15 | let files: string[]; | |
| 16 | try { | |
| 17 | files = readdirSync(join(dataDir, "spawn")); | |
| 18 | } catch { | |
| 19 | return []; | |
| 20 | } | |
| 21 | const out: string[] = []; | |
| 22 | for (const f of files.sort()) { | |
| 23 | const name = f.slice(0, -".json".length); | |
| 24 | if (!f.endsWith(".json") || !/^probe-[0-9a-f]{8}$/.test(name)) continue; | |
| 25 | try { | |
| 26 | const begun = Date.parse(String((JSON.parse(readFileSync(join(dataDir, "spawn", f), "utf8")) as { createdAt?: unknown }).createdAt)); | |
| 27 | if (Number.isFinite(begun) && now - begun >= PROBE_STANDS_MS) out.push(name); | |
| 28 | } catch {} | |
| 29 | } | |
| 30 | return out; | |
| 31 | } |
src/release/prove.ts +8 −3
| @@ -22,7 +22,7 @@ | ||
| 22 | 22 | |
| 23 | 23 | import { mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs"; |
| 24 | 24 | import { join } from "node:path"; |
| 25 | import type { walkJourney, JourneyResult } from "./journey.ts"; | |
| 25 | import type { walkJourney, JourneyResult, HostHands } from "./journey.ts"; | |
| 26 | 26 | import { smoke, type Failure, type Heavy } from "./smoke.ts"; |
| 27 | 27 | import { UNSTAMPED } from "../kernel/version.ts"; |
| 28 | 28 | import { ownProbeHeaders } from "../kernel/probe.ts"; |
| @@ -88,6 +88,8 @@ export interface Proof { | ||
| 88 | 88 | readonly tries?: number; |
| 89 | 89 | /** Probe forges the proof could not remove: the needs-you stack lists each with Remove. */ |
| 90 | 90 | readonly leftover?: readonly string[]; |
| 91 | /** Whether the walk's probe forge is gone: false when one is left (`leftover` names it). */ | |
| 92 | readonly removed?: boolean; | |
| 91 | 93 | } |
| 92 | 94 | |
| 93 | 95 | /** |
| @@ -320,6 +322,8 @@ export interface ProveOptions { | ||
| 320 | 322 | * limits know it. |
| 321 | 323 | */ |
| 322 | 324 | readonly proberKey?: string; |
| 325 | /** The host's own hands to remove its probe forge, handed to the journey. */ | |
| 326 | readonly hands?: HostHands; | |
| 323 | 327 | } |
| 324 | 328 | |
| 325 | 329 | /** Is a proof of `version` due: never tried, or failed `retryAfter` its failures or more ago? */ |
| @@ -356,6 +360,7 @@ export async function proveRelease(o: ProveOptions): Promise<Proof | undefined> | ||
| 356 | 360 | ...(walked === undefined ? {} : { journey: { readyMs: walked.readyMs, firstActivityMs: walked.firstActivityMs, screens: walked.screens } }), |
| 357 | 361 | ...(tries === undefined ? {} : { tries }), |
| 358 | 362 | ...(leftover.length === 0 ? {} : { leftover }), |
| 363 | ...(walked === undefined ? {} : { removed: leftover.length === 0 }), | |
| 359 | 364 | ...(failure === undefined |
| 360 | 365 | ? {} |
| 361 | 366 | : { failure, since: failedBefore ? (failedBefore.since ?? failedBefore.at) : at, failures: (failedBefore?.failures ?? (failedBefore ? 1 : 0)) + 1, ...(slow ? { slow } : {}), ...(gaveUp ? { gaveUp } : {}) }), |
| @@ -406,7 +411,7 @@ export async function proveRelease(o: ProveOptions): Promise<Proof | undefined> | ||
| 406 | 411 | const settled = await settle(o.url, doFetch, now, sleep, o.giveUpMs === undefined ? SETTLE_MS : Math.min(SETTLE_MS, o.giveUpMs)); |
| 407 | 412 | tries++; |
| 408 | 413 | walked = settled |
| 409 | ? await o.journey({ base: o.url, fetch: doFetch, ...(o.token ? { adminToken: o.token } : {}), ...(o.proberKey ? { proberKey: o.proberKey } : {}) }) | |
| 414 | ? await o.journey({ base: o.url, fetch: doFetch, ...(o.token ? { adminToken: o.token } : {}), ...(o.proberKey ? { proberKey: o.proberKey } : {}), ...(o.hands ? { hands: o.hands } : {}) }) | |
| 410 | 415 | : { ok: false, screens: [], readyMs: null, firstActivityMs: null, failure: `the forge had not settled in ${SETTLE_MS / 1000} s after its start`, forge: null, removed: true }; |
| 411 | 416 | if (walked.forge !== null && !walked.removed) leftover.push(walked.forge); |
| 412 | 417 | // A passed walk, a refusal by the sign-up limit, or a forge left behind ends the tries: |
| @@ -528,5 +533,5 @@ export function proveRunning( | ||
| 528 | 533 | schedule: Schedule = unrefTimer, |
| 529 | 534 | prove: (o: ProveOptions) => Promise<Proof | undefined> = proveRelease, |
| 530 | 535 | ): () => void { |
| 531 | return startProving(o, (p) => log.info("release proof", { version: p.version, ok: String(p.ok), ...(p.tries === undefined ? {} : { tries: String(p.tries) }), ...(p.failure ? { failure: p.failure } : {}) }), everyMs, schedule, prove, HANG_MS, log); | |
| 536 | return startProving(o, (p) => log.info("release proof", { version: p.version, ok: String(p.ok), ...(p.tries === undefined ? {} : { tries: String(p.tries) }), ...(p.removed === undefined ? {} : { removed: p.removed ? "true" : `false (${(p.leftover ?? []).join(", ")} still running; the host could not remove it)` }), ...(p.failure ? { failure: p.failure } : {}) }), everyMs, schedule, prove, HANG_MS, log); | |
| 532 | 537 | } |
test/release-journey.test.ts +31
| @@ -11,6 +11,7 @@ import { mkdtemp, rm } from "node:fs/promises"; | ||
| 11 | 11 | import { tmpdir } from "node:os"; |
| 12 | 12 | import { join } from "node:path"; |
| 13 | 13 | import { childDirOf, childNamed } from "../src/actions/spawn.ts"; |
| 14 | import { removeForge } from "../src/spawn/manage.ts"; | |
| 14 | 15 | import { createApp, type App } from "../src/app.ts"; |
| 15 | 16 | import { startCrew, type CrewHandle } from "../src/crew/dispatch.ts"; |
| 16 | 17 | import { createToken } from "../src/core/tokens.ts"; |
| @@ -301,3 +302,33 @@ test("a removal that fails three times is still retried, so a slow host does not | ||
| 301 | 302 | expect(result.failure === undefined || !result.failure.includes("could not be removed")).toBe(true); |
| 302 | 303 | await fetch(`${parentServers.url}/forges/${result.forge}/remove`, { method: "POST", headers: { origin: parentServers.url, authorization: `Bearer ${adminToken}` } }); |
| 303 | 304 | }, 60_000); |
| 305 | ||
| 306 | test("with the host's own hands and no admin token, the walk removes its forge and sweeps stale ones", async () => { | |
| 307 | broken = undefined; | |
| 308 | const removedBy: string[] = []; | |
| 309 | const hands = { | |
| 310 | remove: async (name: string) => (removedBy.push(name), true), | |
| 311 | list: async () => [ | |
| 312 | { name: "probe-aaaaaaaa", createdAt: new Date(Date.now() - 2 * 3_600_000).toISOString() }, | |
| 313 | { name: "probe-bbbbbbbb", createdAt: new Date().toISOString() }, | |
| 314 | { name: "notes", createdAt: new Date(0).toISOString() }, | |
| 315 | ], | |
| 316 | }; | |
| 317 | const result = await walkJourney({ base: parentServers.url, fetch: routed([]), hands, sleep: async () => {}, pollMs: 100 }); | |
| 318 | expect(result.ok).toBe(true); | |
| 319 | expect(result.removed).toBe(true); | |
| 320 | expect(removedBy).toContain(result.forge!); | |
| 321 | expect(result.swept).toEqual(["probe-aaaaaaaa"]); | |
| 322 | expect(removedBy).not.toContain("probe-bbbbbbbb"); | |
| 323 | expect(removedBy).not.toContain("notes"); | |
| 324 | }, 60_000); | |
| 325 | ||
| 326 | test("hands that cannot remove the forge name it in the failure", async () => { | |
| 327 | broken = undefined; | |
| 328 | const hands = { remove: async () => false, list: async () => [] }; | |
| 329 | const result = await walkJourney({ base: parentServers.url, fetch: routed([]), hands, sleep: async () => {}, pollMs: 100 }); | |
| 330 | expect(result.removed).toBe(false); | |
| 331 | expect(result.ok).toBe(false); | |
| 332 | expect(result.failure).toContain(`the probe forge ${result.forge} could not be removed`); | |
| 333 | await removeForge(parent, result.forge!); | |
| 334 | }, 60_000); |
test/release-prove.test.ts +13
| @@ -153,6 +153,19 @@ describe("proving a release", () => { | ||
| 153 | 153 | expect(leftoverProbes(dir)).toEqual(["probe-abcd1234"]); |
| 154 | 154 | }); |
| 155 | 155 | |
| 156 | ||
| 157 | test("the log line says removed, and names the forge it could not remove", async () => { | |
| 158 | const lines: Record<string, string>[] = []; | |
| 159 | const p = await run("4.9.0", site("4.9.0").fake, { journey: walk({ ok: false, failure: "x", forge: "probe-abcd1234", removed: false }) }); | |
| 160 | expect(p?.removed).toBe(false); | |
| 161 | const ok = await run("4.9.1", site("4.9.1").fake, { journey: walk({}) }); | |
| 162 | expect(ok?.removed).toBe(true); | |
| 163 | proveRunning({ dataDir: dir, version: "4.9.1", url: "https://f.test" }, { info: (_m, f) => void lines.push(f as Record<string, string>), warn() {} }, 1, () => () => {}, async () => p); | |
| 164 | await Bun.sleep(10); // real-timer: lets the in-process server settle | |
| 165 | expect(lines[0]?.["removed"]).toContain("false"); | |
| 166 | expect(lines[0]?.["removed"]).toContain("probe-abcd1234"); | |
| 167 | }); | |
| 168 | ||
| 156 | 169 | test("a passing walk keeps its timings, and they reach the card", async () => { |
| 157 | 170 | const p = await run("4.0.1", site("4.0.1").fake, { journey: walk({}) }); |
| 158 | 171 | expect(p?.ok).toBe(true); |
test/vitals-release.test.ts +11
| @@ -90,3 +90,14 @@ test("a probe forge the proof could not remove is a card with its Remove page; n | ||
| 90 | 90 | keep({ version: "9.9.9", at: "2026-10-18T10:10:00.000Z", ok: true, tries: 2 }); |
| 91 | 91 | expect(vitals({ db: app.db, signals: app.signals, dataDir }).degraded.some((d) => d.cause.startsWith("probe:"))).toBe(false); |
| 92 | 92 | }); |
| 93 | ||
| 94 | test("a probe forge standing over 30 minutes is a card with Remove, whatever the proof says; a young one is not", () => { | |
| 95 | const spawn = join(dataDir, "spawn"); | |
| 96 | mkdirSync(spawn, { recursive: true }); | |
| 97 | const now = Date.now(); | |
| 98 | writeFileSync(join(spawn, "probe-11112222.json"), JSON.stringify({ createdAt: new Date(now - 31 * 60_000).toISOString() })); | |
| 99 | writeFileSync(join(spawn, "probe-33334444.json"), JSON.stringify({ createdAt: new Date(now - 5 * 60_000).toISOString() })); | |
| 100 | const causes = vitals({ db: app.db, signals: app.signals, dataDir, now }).degraded.filter((d) => d.cause.startsWith("probe:")); | |
| 101 | expect(causes.map((d) => d.cause)).toEqual(["probe:probe-11112222"]); | |
| 102 | expect(causes[0]).toMatchObject({ href: "/forges/probe-11112222/remove" }); | |
| 103 | }); |
new above
offline