From 728f3de40764cea023762be6725c48d63fdff3ef Mon Sep 17 00:00:00 2001 From: yetone Date: Fri, 13 Nov 2026 11:52:00 +0800 Subject: [PATCH] site: a release the feed named for one run still gets its attestations on R2 (ArcticLampyrid on X) 52830b077 asked for a release's bundles only while the feeds named it, and only after its files were copied inside the run's budget. Tags came minutes apart today: v0.1.3978 was the newest for the 03:40 run alone, which copied its 15 files, and by 03:45 v0.1.3979 had replaced it, so v0.1.3978's files are on R2 with no attestations.jsonl beside them. After pruning, the cron now also fills in the bundles of every tag it keeps (the four newest the feeds don't name), from the files and hashes R2 holds of it. A tag that never had files on R2 (v0.1.3977, newest for under a minute) is served by GitHub, bundles included, as before. Seen live: wrangler tail of the 03:45 run copied v0.1.3979/attestations.jsonl, and usemagpie.ai/files/v0.1.3979/attestations.jsonl answers 200. Run (mote): node --test site/files.test.mjs 10/10; site/*.test.mjs 118/119, the red is worker.test's "llms-full.txt is current", stale since 889758605 on origin/main, regenerated in the next commit. New test: a kept release the feeds no longer name gets its bundles. Broken by hand: the kept-tags loop emptied turns it red. --- site/files.js | 21 ++++++++++++++++++--- site/files.test.mjs | 24 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/site/files.js b/site/files.js index ac643d6be..ac4dab978 100644 --- a/site/files.js +++ b/site/files.js @@ -148,7 +148,20 @@ export async function mirror(env, rels, open, now = Date.now, attest = null) { else done.failed.push(`${tag}/${BUNDLES}`); } } - await prune(env, tags); + const kept = await prune(env, tags); + // a release the feeds named for one run only (the next tag came minutes + // later) can leave that run with its files copied and its budget spent; + // its bundles are filled in from the files R2 holds of it, while kept + for (const tag of kept) { + if (!attest || byVersion(tag, "v" + ATTESTED) < 0 || now() > until) continue; + const have = await held(env, tag); + if (!have || BUNDLES in have) continue; + const assets = {}; + for (const [name, sha256] of Object.entries(have)) if (sha256) assets[name] = { sha256 }; + if (!Object.keys(assets).length) continue; + if (await keepBundles(env, tag, { assets }, attest)) done.copied.push(`${tag}/${BUNDLES}`); + else done.failed.push(`${tag}/${BUNDLES}`); + } return done; } @@ -216,7 +229,8 @@ async function copy(env, tag, name, a, open) { } } -// prune deletes every tag but keep and the KEEP newest besides. +// prune deletes every tag but keep and the KEEP newest besides, and +// returns those KEEP newest. async function prune(env, keep) { let tags = [], cursor; try { @@ -227,7 +241,7 @@ async function prune(env, keep) { } while (cursor); } catch (e) { console.log("r2 prune: list", String(e)); - return; + return []; } const rest = tags.filter((t) => !keep.includes(t)).sort((a, b) => byVersion(b, a)); for (const tag of rest.slice(KEEP)) { @@ -240,6 +254,7 @@ async function prune(env, keep) { console.log("r2 prune: delete", tag, String(e)); } } + return rest.slice(0, KEEP); } function byVersion(a, b) { diff --git a/site/files.test.mjs b/site/files.test.mjs index b9b70509a..c153bc27d 100644 --- a/site/files.test.mjs +++ b/site/files.test.mjs @@ -179,6 +179,30 @@ test("mirror: a release's attestation bundles land in R2 as attestations.jsonl, assert.deepEqual(asked, []); }); +test("mirror: a kept release the feeds no longer name still gets its bundles, for the files R2 holds of it (v0.1.3978)", async () => { + const env = { RELEASES: bucket() }; + // v0.1.3978 was the newest for one run, which copied its files and spent + // its budget; by the next run v0.1.3979 had taken its place in the feed + await hold(env.RELEASES, "v0.1.3978", "a", "A"); + await hold(env.RELEASES, "v0.1.3978", "b", "B"); + await hold(env.RELEASES, "v0.1.3890", "a", "old"); + const rel = { version: "0.1.3979", assets: { c: { sha256: sha("C") } } }; + const asked = []; + const attest = async (h) => (asked.push(h), [{ for: h }]); + const done = await mirror(env, [rel], async () => new Response("C"), Date.now, attest); + assert.deepEqual(done.copied.sort(), ["v0.1.3978/attestations.jsonl", "v0.1.3979/attestations.jsonl", "v0.1.3979/c"]); + const res = await ask(env, "/files/v0.1.3978/attestations.jsonl"); + assert.equal(res.status, 200); + const lines = (await res.text()).trimEnd().split("\n").map((l) => JSON.parse(l)); + assert.deepEqual(lines.map((l) => l.for).sort(), [sha("A"), sha("B")].sort()); + // a kept release from before the attestations is not asked + assert.equal(asked.includes(sha("old")), false); + // written once: the next run asks nothing more + asked.length = 0; + await mirror(env, [rel], async () => new Response("C"), Date.now, attest); + assert.deepEqual(asked, []); +}); + test("mirror: a release from before the attestations is not asked for any", async () => { const env = { RELEASES: bucket() }; const rel = { version: "0.1.3890", assets: { a: { sha256: sha("A") } } };