Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 835a05793a10a41a2a8d8aa3c64ee3e556dff30f
parent e3b0a3f8ced78d9ad1ac5d24ea2eab0f6f75b0bb
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 18 Nov 2026 23:54:32 -0500

x-cap: review 4 A -- a lost count is rebuilt only on the kept-records marker; an old finished record proves nothing, and a marker dated after now is no proof

A record of a job cancelled while queued has no log and is never pruned, and
retention goes by id and queue time, not start time: an old finished record on
disk does not show the day's records are all there. Without the marker over a
day old the rebuild refuses and writes nothing; the refusal ends within a day.
A marker whose "since" is after now is said again at now.

Co-Authored-By: Claude <noreply@anthropic.com>

Diffstat:
Mcommon/jobs/xJobCap.test.ts | 27++++++++++++++++++---------
Mcommon/jobs/xJobCap.ts | 19+++++++++----------
2 files changed, 27 insertions(+), 19 deletions(-)

diff --git a/common/jobs/xJobCap.test.ts b/common/jobs/xJobCap.test.ts @@ -230,18 +230,16 @@ test("review 3 M3: a rebuild that cannot show its records cover the last day ref const later = await xJobCapStatus(paths, T0 + MIN + 24 * HOUR); assert.deepEqual([later.ok, later.lastDay], [true, 0]); - // SHOWN BY A RECORD: a finished job that ended over a day ago is still on - // disk, so no retention ever deleted a newer one. - const shown = corpus("m3-shown-by-old"); + // A FINISHED JOB THAT ENDED OVER A DAY AGO IS NO PROOF (review 4 A): a + // record of a job cancelled while queued has no log and is never pruned, and + // retention goes by id and queue time, not start time. + const shown = corpus("m3-old-finished-no-proof"); xs(shown); meta(shown, { kind: "sync", queueKey: "platform:youtube", status: "done", startedAt: T0 - 26 * HOUR, endedAt: T0 - 25 * HOUR }, T0 - 26 * HOUR); + meta(shown, { kind: "fetch-posts", queueKey: "platform:twitter", status: "cancelled", endedAt: T0 - 30 * HOUR }, T0 - 30 * HOUR); const s = await xJobCapStatus(shown, T0 + MIN); - assert.deepEqual([s.ok, s.lastDay], [true, 5]); - // …but an old job still running (or queued) is no such proof: it was kept because it ran. - const running = corpus("m3-old-running"); - xs(running); - meta(running, { kind: "sync", queueKey: "platform:youtube", status: "running", startedAt: T0 - 26 * HOUR }, T0 - 26 * HOUR); - assert.equal((await xJobCapStatus(running, T0 + MIN)).ok, false); + assert.equal(s.ok, false); + assert.throws(() => readFileSync(xJobStartsFile(shown)), "nothing is written on a guess"); // SHOWN BY THE PRUNER: it has kept X's records for over a day. const pruner = corpus("m3-shown-by-pruner"); xs(pruner); @@ -254,4 +252,15 @@ test("review 3 M3: a rebuild that cannot show its records cover the last day ref const r = await xJobCapStatus(recent, T0 + MIN); assert.equal(r.ok, false); assert.match(r.sentence ?? "", /at the latest until 2026-11-19 10:00 UTC/); + // A MARKER IN THE FUTURE IS NO PROOF (review 4 A): refused, as with none, + // and the refusal ends within a day. + const ahead = corpus("m3-pruner-future"); + xs(ahead); + keptSince(ahead, T0 + 365 * 24 * HOUR); + const f = await xJobCapStatus(ahead, T0 + MIN); + assert.equal(f.ok, false); + assert.match(f.sentence ?? "", /at the latest until 2026-11-19 12:01 UTC/); + assert.throws(() => readFileSync(xJobStartsFile(ahead)), "nothing is written on a guess"); + const aheadLater = await xJobCapStatus(ahead, T0 + MIN + 24 * HOUR); + assert.deepEqual([aheadLater.ok, aheadLater.lastDay], [true, 0]); }); diff --git a/common/jobs/xJobCap.ts b/common/jobs/xJobCap.ts @@ -80,9 +80,10 @@ async function readStartsFile(paths: CapPaths): Promise<{ state: "absent" } | { // has kept them: `<jobsDir>/x-records-kept.json`, {version: 1, since: <ms>}, // written once, by the first prune (or rebuild) of code that keeps them. A // rebuild trusts the records of the last day only when that is over a day -// old — or when a finished job that ended over a day ago is still on disk -// (retention deletes the oldest finished first, so nothing newer was -// deleted). +// old. The marker is the ONLY proof (review 4 A): an old finished record on +// disk shows nothing (a job cancelled while queued has no log and is never +// pruned; retention goes by id and queue time, not start time). A "since" +// after now is no proof either: it is said again, at now. export const X_RECORDS_KEPT_FILE = "x-records-kept.json"; export async function readXRecordsKeptSince(paths: Pick<Paths, "jobsDir">): Promise<number | undefined> { @@ -91,10 +92,12 @@ export async function readXRecordsKeptSince(paths: Pick<Paths, "jobsDir">): Prom return finite(since) ? since : undefined; } -// Said once: a "since" already on disk is never moved later. +// Said once: a "since" already on disk is never moved later. One after `now` +// (a clock that jumped) proves nothing and is said again at `now`, so the +// refusal it causes ends within a day (review 4 A). export async function noteXRecordsKept(paths: Pick<Paths, "jobsDir">, now: number): Promise<number> { const had = await readXRecordsKeptSince(paths); - if (had !== undefined) return had; + if (had !== undefined && had <= now) return had; await writeJsonAtomic(path.join(paths.jobsDir, X_RECORDS_KEPT_FILE), { version: 1, since: now }, { mkdir: true }); return now; } @@ -142,7 +145,6 @@ export async function rebuildXJobStarts(paths: Pick<Paths, "jobsDir">, now: numb } const starts: number[] = []; let records = 0; - let oldFinished = false; for (const name of names) { if (!name.endsWith(".meta.json")) continue; const id = name.slice(0, -".meta.json".length); @@ -160,9 +162,6 @@ export async function rebuildXJobStarts(paths: Pick<Paths, "jobsDir">, now: numb if (born === 0 || born > since) return { ok: false, why: `the job record ${name} cannot be read`, ...(until ? { until } : {}) }; continue; } - // A finished job that ended over a day ago, still on disk: retention - // deletes the oldest finished jobs first, so no newer one was deleted. - if ((m.status === "done" || m.status === "failed" || m.status === "cancelled") && finite(m.endedAt) && m.endedAt <= since) oldFinished = true; if (m.queueKey !== X_QUEUE_KEY) continue; if (Array.isArray(m.xStarts)) { records++; @@ -188,7 +187,7 @@ export async function rebuildXJobStarts(paths: Pick<Paths, "jobsDir">, now: numb // nothing is counted on a guess. if (lastXEnd !== undefined || starts.length > 0) { const kept = await noteXRecordsKept(paths, now); - if (!(kept <= since || oldFinished)) { + if (!(kept <= since)) { const ends = [kept + X_JOB_CAP.dayMs, ...(until !== undefined ? [until] : [])]; return { ok: false,