Public: anyone can read this; the crew can change it.

The restore drill's result keeps how long the hosted forge took to restore, in whole seconds #14189

Merged opened this

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

Merged

torque/forge:torque/14184-the-restore-drill-s-result-keeps-how-lon → main 2 commits fork

  • Merged. torque/14184-the-restore-drill-s-result-keeps-how-lon was merged into main as 6f8a447.

Review

Sign in to review this change.
5 files changed +54 −7
src/snapshot/drill.ts +2 −2
@@ -359,12 +359,12 @@ export async function runDrill(deps: DrillDeps): Promise<DrillResult> {
359359 step = "forge";
360360 const from = tick();
361361 const proof = await within(
362 (deps.prove ?? proveHosted)(store, newest.name, pick, join(scratch, "forge"), { passphrase: deps.passphrase, of: held.length, leftMs: left }),
362 (deps.prove ?? proveHosted)(store, newest.name, pick, join(scratch, "forge"), { passphrase: deps.passphrase, of: held.length, leftMs: left, ticks: tick }),
363363 left(),
364364 budget,
365365 );
366366 // Its restore and checks together, so the card can say it in seconds (#13919).
367 hosted = { ...proof, ms: Math.round(tick() - from) };
367 hosted = { ...proof, ms: proof.ms ?? Math.round(tick() - from) };
368368 } else hostedSkipped = true;
369369 } catch (error) {
370370 reason =
src/snapshot/drill_hosted.ts +10 −4
@@ -29,8 +29,8 @@ export interface HostedProof {
2929 /** The bytes its restore wrote. */
3030 readonly bytes: number;
3131 /**
32 * Its restore and checks, wall time in ms, as the drill timed them (#13919); absent from a proof
33 * before the drill times it, and on drills kept before that.
32 * Its restore and checks, in whole ms of the monotonic clock: proveHosted times itself (#14184),
33 * and the drill times a proof that did not (#13919). Absent on drills kept before that.
3434 */
3535 readonly ms?: number | undefined;
3636 }
@@ -59,9 +59,15 @@ export async function proveHosted(
5959 snapshot: string,
6060 forge: HostedEntry,
6161 dir: string,
62 options: { readonly passphrase?: string | undefined; readonly of: number; readonly leftMs?: (() => number) | undefined; readonly git?: typeof runGit | undefined },
62 options: { readonly passphrase?: string | undefined; readonly of: number; readonly leftMs?: (() => number) | undefined;
63 readonly git?: typeof runGit | undefined;
64 /** Test seam: the monotonic clock its time is read from (`performance.now`). */
65 readonly ticks?: (() => number) | undefined;
66 },
6367 ): Promise<HostedProof> {
6468 const git = options.git ?? runGit;
69 const tick = options.ticks ?? (() => performance.now());
70 const start = tick();
6571 const back = await restoreHosted(store, snapshot, forge.name, dir, { passphrase: options.passphrase, git });
6672 // Without its host's ledger of it, a host could not list it or wake it.
6773 let kept: { name?: unknown };
@@ -98,5 +104,5 @@ export async function proveHosted(
98104 repos++;
99105 }
100106 if (repos !== forge.repos) throw new Error(`hosted forge ${forge.name}: ${repos} repositories came back, its copy holds ${forge.repos}`);
101 return { name: forge.name, of: options.of, repos, bytes: forge.bytes };
107 return { name: forge.name, of: options.of, repos, bytes: forge.bytes, ms: Math.max(0, Math.round(tick() - start)) };
102108 }
src/snapshot/drills.ts +1
@@ -68,6 +68,7 @@ export function parseHosted(raw: string | null): { hosted?: HostedProof } {
6868 const whole = (v: unknown): v is number => typeof v === "number" && Number.isSafeInteger(v) && v >= 0;
6969 const { name, of, repos, bytes, ms } = h;
7070 if (typeof name !== "string" || name.length > 100 || !whole(of) || !whole(repos) || !whole(bytes)) return {};
71 // A drill kept before its time was measured (#14184) has none; one that does not read is none.
7172 return { hosted: { name, of, repos, bytes, ...(whole(ms) ? { ms } : {}) } };
7273 } catch {
7374 return {};
test/drill-hosted-ms.test.ts added +25
@@ -0,0 +1,25 @@
1 /**
2 * A kept drill's hosted proof reads its restore time back, and a drill kept
3 * before that time was measured still reads (#14184).
4 */
5 import { describe, expect, test } from "bun:test";
6 import { parseHosted } from "../src/snapshot/drills.ts";
7
8 const row = (hosted: unknown): string => JSON.stringify({ phases: [], budgetMs: 1000, hosted });
9
10 describe("parseHosted and the hosted forge's restore time", () => {
11 test("a stored drill with ms reads it back", () => {
12 expect(parseHosted(row({ name: "alpha", of: 3, repos: 2, bytes: 4096, ms: 12_401 }))).toEqual({ hosted: { name: "alpha", of: 3, repos: 2, bytes: 4096, ms: 12_401 } });
13 });
14
15 test("a stored drill without ms still parses, with no ms", () => {
16 const read = parseHosted(row({ name: "alpha", of: 3, repos: 2, bytes: 4096 }));
17 expect(read).toEqual({ hosted: { name: "alpha", of: 3, repos: 2, bytes: 4096 } });
18 expect("ms" in read.hosted!).toBe(false);
19 });
20
21 test("an ms that is not a whole non-negative number is left out, and the rest still reads", () => {
22 for (const ms of [-1, 1.5, "12", null, Number.MAX_VALUE])
23 expect(parseHosted(row({ name: "alpha", of: 1, repos: 1, bytes: 1, ms }))).toEqual({ hosted: { name: "alpha", of: 1, repos: 1, bytes: 1 } });
24 });
25 });
test/snapshot-hosted-chunks.test.ts +16 −1
@@ -30,7 +30,7 @@ import { repoDir } from "../src/git/repos.ts";
3030 import { judge, readLane, type LaneRead } from "../src/snapshot/bucket.ts";
3131 import { CHUNK_PREFIX, chunkKey } from "../src/snapshot/chunks.ts";
3232 import { runDrill } from "../src/snapshot/drill.ts";
33 import { drillPick } from "../src/snapshot/drill_hosted.ts";
33 import { drillPick, proveHosted } from "../src/snapshot/drill_hosted.ts";
3434 import { hostedDrillWords } from "../src/snapshot/drill_hosted_words.ts";
3535 import { restoreHosted } from "../src/snapshot/restore.ts";
3636 import { chunksNamed, pruneSnapshots, takeSnapshot, type Manifest } from "../src/snapshot/snapshot.ts";
@@ -274,6 +274,21 @@ describe("two nights of a host with hosted forges", () => {
274274 expect(judge({ lanes: [lane], checkedAt: new Date(now).toISOString() }, result, now).drill?.says).toBe("restore drill 2026-11-17 passed (1 h ago), with hosted forge alpha (1 of 1)");
275275 });
276276
277 test("the proof keeps how long its restore and proof took, read from its clock, in whole ms (#14184)", async () => {
278 // A fake monotonic clock: 1000 ms at the start, 13_400.6 ms at the end, whatever was read
279 // between.
280 const reads: number[] = [];
281 const ticks = (): number => {
282 const t = reads.length === 0 ? 1000 : 13_400.6;
283 reads.push(t);
284 return t;
285 };
286 const proof = await proveHosted(store, m2.name, m2.hosted![0]!, join(fresh("prove"), "forge"), { passphrase: PASS, of: 1, ticks });
287 // 13_400.6 − 1000 = 12_400.6 ms, rounded to 12_401.
288 expect(proof).toEqual({ name: "alpha", of: 1, repos: 1, bytes: m2.hosted![0]!.bytes, ms: 12_401 });
289 expect(reads.length).toBe(2);
290 });
291
277292 test("a hosted forge that does not come back whole fails the drill at its own step, by name", async () => {
278293 // One chunk only that forge's database needs is gone from a store of its own.
279294 const holed = copyOf(store);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs