Set the gate's checkouts to the old mtime only for a trimmed warm version

This commit is contained in:
aiongg committed 2026-11-23 16:37:39 +00:00
1 parent 49cba1776e
commit 697c24cbc1
4 files changed
+16 -10

No files matched your search

+2 -2
View File
@@ -1198,7 +1198,7 @@ For each offline step pod of such a task the runner reads the node's `warm-statu
1. Resolves `current` once and reads everything from the version dir it names, so a swap by warm-sync during the copy cannot mix versions. Verifies the version's `latest.json` with the public key from the ConfigMap `warm-verify-key` (key `public.pem`, mounted at `/keys/verify`) and the manifest's sha256 against it, and checks that the commit is the one the runner chose and that paths, image, CI env (the gate env, cache version and craft-fonts and craft-i18n commits) and (for `pvc`) Cargo.lock match. Anything else is a cold start, logged.
2. Copies the target and CARGO_HOME with 8 `cp -a` processes at once (the top four directory levels are split into batches of entries; modes, mtimes, symlinks and hard links are kept; CARGO_HOME goes into a dir beside it) whose entries then move in with renames, keeping what an earlier step already fetched, and logs `warm copy N GB in X s`. A failed copy leaves neither behind and starts cold. A volume target that already holds a finished copy or a build (a later offline pod of the same task, a rerun) is kept, and a task whose first offline pod started cold stays cold.
3. Sets every checkout file's mtime to 2001-01-01 and the files that changed since the warm commit to now, so cargo rebuilds only what changed. It also sets every file of the gate's extra checkouts (`/craft-fonts`, `/craft-i18n`, under the volume's `ext/`) to 2001-01-01, because their path-dependency inputs (such as the font manifest) would otherwise make cargo rebuild every crate that reads them; the warm-copy container does this while the volume is still writable (the steps mount them read-only), and only after the version's env hash, which covers both commits, matched. A cold start leaves all mtimes alone. For a file of the warm commit that the checkout no longer has, the nearest `Cargo.toml` above it and its nearest remaining dir count as changed. The source pod makes that list from a tree-only fetch of the warm commit from GitHub. This needs a version whose manifest is `trimmed`: the producer's publish left out every unit its build did not read, so each unit kept was checked at the warm commit. Without that, or without the list (the fetch failed, more than 5,000 files changed, or the node took a newer version meanwhile), every file counts as changed: correct, but every workspace crate rebuilds.
3. Sets every checkout file's mtime to 2001-01-01 and the files that changed since the warm commit to now, so cargo rebuilds only what changed. It also sets every file of the gate's extra checkouts (`/craft-fonts`, `/craft-i18n`, under the volume's `ext/`) to 2001-01-01, because their path-dependency inputs (such as the font manifest) would otherwise make cargo rebuild every crate that reads them; the warm-copy container does this while the volume is still writable (the steps mount them read-only), and only for a `trimmed` version (its env hash, which covers both commits, matched). An untrimmed version may hold units the producer restored from a build against other checkouts, so there the ext mtimes stay as copied. A cold start leaves all mtimes alone. For a file of the warm commit that the checkout no longer has, the nearest `Cargo.toml` above it and its nearest remaining dir count as changed. The source pod makes that list from a tree-only fetch of the warm commit from GitHub. This needs a version whose manifest is `trimmed`: the producer's publish left out every unit its build did not read, so each unit kept was checked at the warm commit. Without that, or without the list (the fetch failed, more than 5,000 files changed, or the node took a newer version meanwhile), every file counts as changed: correct, but every workspace crate rebuilds.
**Fetching dependencies.** The workspace pod has no network, so a session that adds a crate or a newer version of one calls `fetch_dependencies` after editing `Cargo.toml` (src/build/workspace-fetch.ts). The job starts a fetch pod (`<workspace pod>-fetch-<call>`, label `craft.build/network=mirror`) on the workspace's volume, at its paths and env without `CARGO_NET_OFFLINE` (with `HOME=/tmp` and no global or system git config), with a build pod's mirror parts: the mirror's CA, `mirror-wait` (30 s) and hostAliases that send crates.io and GitHub to the crate mirror. It runs `cargo fetch` (not `--locked`, `CARGO_NET_RETRY=10`, 10 min limit) in `/work/src` or the `path` given, which updates `Cargo.lock` and `CARGO_HOME` on the volume. The result is the `Cargo.lock` diff against the base commit (`git diff -- ':(glob)**/Cargo.lock'` in the workspace pod, cut at 30 KiB), or the end of cargo's output. A fetch holds all of the session's exec slots, so it waits for the foreground commands running and the session's other calls wait for it (background commands keep running); the launcher's checkpoint waits for it too. A failed read of the pod is retried until the call's deadline. Without the environment's `crateMirror` setting the tool refuses, and a mirror that does not accept connections fails the call: there is no fallback to the public network. The implement prompt mentions the tool only where the environment has a mirror; elsewhere a session that needs a dependency reports blocked. The job deletes the pod when the fetch ends; the launcher's pass deletes a fetch pod whose workspace is no longer ready on the pod it was made for (parked, ended, resumed elsewhere) or that is older than any fetch can take (about 16 min). A runner restart hands the call back to the session, which waits for the same pod.
@@ -1219,7 +1219,7 @@ How the target starts:
1. A fresh volume is sized from the key's last published size: 2.6 times it plus 8 GiB, at least the environment's `--workspace-storage` (photocraft's 27 GB target grows to 50-70 GB in a session). The runner picks a node whose fresh warm status lists the key with the workspace's toolchain image and CI env hash, and the base commit's Cargo.lock; the newest version wins, then the node with the fewest workspaces, then the lower disk usage; nodes whose disk is over 85% full are skipped. A workspace's target is always on its volume, whatever the repository's warm target (`tmpfs` and `pvc` alike): the warm target only decides whether the workspace starts warm (`none` starts cold), and the Cargo.lock check applies to every warm start. Otherwise the target starts cold, and the reason is logged.
2. A warm pod mounts that node's claim `craft-warm-<node>` read-only, which pins it there, and runs `warm-copy` before the workspace container, with the Cargo.lock sha256 from the runner (the checkout arrives later). Any node holding the version may run the workspace, the AutoCraft service's nodes included: the pod's isolation (restricted Pod Security, no service-account token, no network, no credentials) is what keeps it apart. A pod the scheduler cannot place on its warm node for 3 minutes is made again cold, without the claim.
3. Seeding unpacks the source, the gate's checkouts and then sets the checkout's mtimes against the warm commit: every file to 2001-01-01 and the files changed since the warm commit (from the runner's clone, with the build pods' deleted-file rule) to now, when the version is `trimmed`; otherwise every file to now. The same step sets every file of the gate's checkouts under `/work/ext` to 2001-01-01, in both modes. A checkpoint applied on a rebuild then gives its files newer mtimes.
3. Seeding unpacks the source, the gate's checkouts and then sets the checkout's mtimes against the warm commit: every file to 2001-01-01 and the files changed since the warm commit (from the runner's clone, with the build pods' deleted-file rule) to now, when the version is `trimmed`; otherwise every file to now. The same step sets every file of the gate's checkouts under `/work/ext` to 2001-01-01 in `list` mode (a trimmed version); in `all` mode they stay as copied. A checkpoint applied on a rebuild then gives its files newer mtimes.
4. The result is the row's `warm` note (`warm copy N GB in X s from <key>@<commit> on <node>`, or `started cold: <why>`), shown on the item page's history and by `workspace show`; `warm_commit` names the version.
A parked workspace resumed on its kept volume keeps its target and copies nothing. A resume onto a new volume starts over from step 1.
+2 -2
View File
@@ -138,9 +138,9 @@ export const WARM_CHANGED_DIRS = "/work/.ws/warm-changed.dirs";
*/
export const WARM_MTIMES_SH = `set -e
files() { find . -path ./.git -prune -o -path ./target -prune -o \\( -type f -o -type l \\) -print0; }
# The gate's checkouts (read-only mounts in the gate's steps) match the warm version's env: old like the checkout's unchanged files.
if [ -d /work/ext ]; then find /work/ext \\( -type f -o -type l \\) -print0 | xargs -0 -r touch -h -d @${OLD_MTIME_SEC} --; fi
if [ "$1" = list ]; then
# Trimmed version: the gate's checkouts (read-only mounts in the gate's steps) match its env, so they are old like the unchanged files.
if [ -d /work/ext ]; then find /work/ext \\( -type f -o -type l \\) -print0 | xargs -0 -r touch -h -d @${OLD_MTIME_SEC} --; fi
files | xargs -0 -r touch -h -d @${OLD_MTIME_SEC} --
if [ -s ${WARM_CHANGED_FILES} ]; then xargs -0 -r touch -c -h -- <${WARM_CHANGED_FILES}; fi
if [ -s ${WARM_CHANGED_DIRS} ]; then xargs -0 -r touch -c -- <${WARM_CHANGED_DIRS}; fi
+2 -2
View File
@@ -397,8 +397,8 @@ export async function warmCopyPhase(work: string, env: NodeJS.ProcessEnv, log: L
const secs = (performance.now() - t0) / 1000;
const trimmed = header.trimmed === true;
const mtimes = env.AUTOCRAFT_WARM_MTIMES === "later" ? "the checkout's mtimes are set once it arrives" : setMtimes(work, commit, trimmed);
// The warm version's env hash covers the craft-fonts and craft-i18n commits, so the checkouts here are the ones it was built with.
const ext = env.AUTOCRAFT_WARM_MTIMES === "later" ? 0 : setExtMtimes(work);
// A version that is not `trimmed` may hold units built against other checkouts (the producer's restore does not check the env hash), so only a trimmed one gets old ext mtimes; its env hash covers the craft-fonts and craft-i18n commits, so the checkouts here are the ones it was built with.
const ext = env.AUTOCRAFT_WARM_MTIMES === "later" || !trimmed ? 0 : setExtMtimes(work);
write({ state: "done", commit, trimmed, bytes: header.bytes, secs: Math.round(secs * 10) / 10 });
log(`warm copy ${(header.bytes / 1e9).toFixed(1)} GB in ${secs.toFixed(1)} s: ${at} into ${volume ? "the volume" : "memory"}; ${mtimes}${ext ? `; ${ext} files of the gate's checkouts set to 2001-01-01` : ""}`);
return 0;
+10 -4
View File
@@ -6,14 +6,14 @@ import { execFileSync } from "node:child_process";
import { chmodSync, linkSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, statSync, symlinkSync, utimesSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { test } from "node:test";
import { test, type TestContext } from "node:test";
import { CHANGED_FILE } from "../src/build/warm-mount.ts";
import { encodeManifest, makeHeader, signLatest } from "../src/warm/manifest.ts";
import { OLD_MTIME_SEC, copyTree, setExtMtimes, setMtimes, warmCopyPhase } from "../src/worker/warm-copy.ts";
const A = "a".repeat(40), B = "b".repeat(40);
test("a swap of current during the copy does not mix versions", async (t) => {
const swapTest = (trimmed: boolean) => async (t: TestContext) => {
const root = mkdtempSync(join(tmpdir(), "warm-copy-"));
t.after(() => rmSync(root, { recursive: true, force: true }));
const { privateKey, publicKey } = generateKeyPairSync("ed25519");
@@ -22,13 +22,15 @@ test("a swap of current during the copy does not mix versions", async (t) => {
const target = join(root, "target"), cargoHome = join(root, "cache", "cargo"), checkout = "/ci/app";
mkdirSync(join(work, "src"), { recursive: true });
writeFileSync(join(work, "src", "lib.rs"), "x");
mkdirSync(join(work, "ext", "craft-fonts"), { recursive: true });
writeFileSync(join(work, "ext", "craft-fonts", "manifest.txt"), "m");
const gen = (commit: string) => {
const dir = join(source, `gen-${commit.slice(0, 12)}`);
for (const r of ["target", "cargo"]) {
mkdirSync(join(dir, r), { recursive: true });
writeFileSync(join(dir, r, "which"), commit);
}
const header = makeHeader({ key: "app-0123", repo: "o/app", commit, stored: 1, image: "img", rustc: null, envHash: "h", checkout, targetDir: target, cargoHome, trimmed: true }, []);
const header = makeHeader({ key: "app-0123", repo: "o/app", commit, stored: 1, image: "img", rustc: null, envHash: "h", checkout, targetDir: target, cargoHome, trimmed }, []);
const buf = encodeManifest({ header, entries: [] });
writeFileSync(join(dir, "manifest.zst"), buf);
const latest = signLatest("app-0123", { commit, sha256: createHash("sha256").update(buf).digest("hex"), size: buf.length, stored: 1, bytes: 0 }, privateKey);
@@ -51,7 +53,11 @@ test("a swap of current during the copy does not mix versions", async (t) => {
assert.ok(logs.some((l) => l.startsWith("warm copy ")), logs.join("\n"));
assert.equal(readFileSync(join(target, "which"), "utf8"), A);
assert.equal(readFileSync(join(cargoHome, "which"), "utf8"), A);
});
const ext = statSync(join(work, "ext", "craft-fonts", "manifest.txt")).mtimeMs / 1000;
assert.equal(ext <= OLD_MTIME_SEC, trimmed, "ext checkouts are old only for a trimmed version");
};
test("a swap of current during the copy does not mix versions", swapTest(true));
test("an untrimmed warm copy leaves the gate's checkouts' mtimes alone", swapTest(false));
test("an untrimmed version counts every source as changed", (t) => {
const work = mkdtempSync(join(tmpdir(), "warm-mtimes-"));