Archilyzer · Source

archilyzer

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

commit 9f36696bc2d2cf2f007aff0dbee525c472ead096
parent 63a60efdf254b4903d20d138b4f2e3523fc832f8
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Sat, 21 Nov 2026 14:32:46 -0500

sync: what a listing returned is evidence for the pre-clean check

Sync's listings now land in listing-evidence.json, so a candidate the
channel's own Sync listed inside verifyBeforeCleanMaxAgeHours is cleaned
with no request:

- the full sweep's whole listing (complete only when the shrink guard
  accepts it) and the entries a rate-limited one printed before the 429;
- each page of the paged walk (never complete: a prefix by design), and a
  page's entries before a 429;
- Store playlist's listing, as the full sweep's.

Best-effort: a failed evidence write is logged and never fails a sync.
Tests: manualDownloads.test.ts asserts the paged and full records.

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

Diffstat:
Mcommon/controller/listingEvidence.ts | 8+++++++-
Mcommon/ytdlp/manualDownloads.test.ts | 14++++++++++++++
Mcommon/ytdlp/runYtdlp.ts | 62+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
3 files changed, 80 insertions(+), 4 deletions(-)

diff --git a/common/controller/listingEvidence.ts b/common/controller/listingEvidence.ts @@ -39,6 +39,8 @@ export type ListingSource = | "clean-check" // Sync's periodic full sweep (one whole-channel listing). | "sync-full" + // The channel's Store playlist (one whole-channel listing). + | "store-playlist" // A page of Sync's newest-first walk (a prefix of the listing by design). | "sync-paged"; @@ -92,7 +94,11 @@ function isAttempt(v: unknown): v is ListingAttempt { !!a && typeof a.at === "string" && Number.isFinite(Date.parse(a.at)) && - (a.source === "quick-check" || a.source === "clean-check" || a.source === "sync-full" || a.source === "sync-paged") && + (a.source === "quick-check" || + a.source === "clean-check" || + a.source === "sync-full" || + a.source === "store-playlist" || + a.source === "sync-paged") && typeof a.complete === "boolean" && typeof a.start === "number" && a.start >= 1 && diff --git a/common/ytdlp/manualDownloads.test.ts b/common/ytdlp/manualDownloads.test.ts @@ -109,6 +109,14 @@ test("a manual channel's sync records the newest page and downloads nothing", as const roster = readFileSync(path.join(ROOT, "channels", "manual", "roster.json"), "utf8"); assert.match(roster, /aaaaaaaaaaa/); assert.match(roster, /bbbbbbbbbbb/); + // And it is evidence for the pre-clean check (lane verify-resume): what + // the page returned, dated, never a complete listing. + const ev = JSON.parse(readFileSync(path.join(ROOT, "channels", "manual", "listing-evidence.json"), "utf8")); + assert.ok(ev.seen.aaaaaaaaaaa && ev.seen.bbbbbbbbbbb); + assert.deepEqual( + ev.attempts.map((a: { source: string; complete: boolean; count: number }) => [a.source, a.complete, a.count]), + [["sync-paged", false, 2]], + ); // And the sync is a sync: its stamp is written. const cfg = JSON.parse(readFileSync(path.join(ROOT, "channels", "manual", "config.json"), "utf8")); assert.ok(cfg.lastSyncedAt); @@ -124,6 +132,12 @@ test("a manual channel's full sweep refreshes the playlist and downloads nothing const playlist = readFileSync(path.join(ROOT, "channels", "manual", "playlist"), "utf8"); assert.match(playlist, /aaaaaaaaaaa/); assert.match(playlist, /bbbbbbbbbbb/); + // The accepted whole listing is evidence, and complete. + const ev = JSON.parse(readFileSync(path.join(ROOT, "channels", "manual", "listing-evidence.json"), "utf8")); + const full = ev.attempts.filter((a: { source: string }) => a.source === "sync-full"); + assert.equal(full.length, 1); + assert.equal(full[0].complete, true); + assert.equal(full[0].count, 2); }); test("a single video still downloads on a manual channel", async () => { diff --git a/common/ytdlp/runYtdlp.ts b/common/ytdlp/runYtdlp.ts @@ -79,6 +79,7 @@ import { type Roster, } from "../controller/rosterStore"; import { acceptListing, type ListingDecision } from "../controller/acceptListing"; +import { recordListing, type RecordedListing } from "../controller/listingEvidence"; import { deriveChannelSets } from "../controller/channelSets"; import { resolveShardItems } from "../controller/shard"; import { @@ -620,6 +621,54 @@ async function enumeratePlaylistUrls( return urls; } +// EVIDENCE FOR THE PRE-CLEAN CHECK (lane verify-resume): what a listing of +// this channel RETURNED — a whole listing, a page of the paged walk, or the +// entries a rate-limited one printed before it stopped — dated to when it +// started (controller/listingEvidence.ts). Best-effort: a failed write loses +// evidence (the check then asks the source), and must not fail a sync. +async function noteListingEvidence( + opts: RunYtdlpOpts, + listing: Omit<RecordedListing, "platform">, +): Promise<void> { + if (listing.urls.length === 0 && !listing.complete) return; + try { + await recordListing(opts.paths, opts.channelSlug, { + ...listing, + platform: cooldownPlatformKey(opts.channelConfig), + }); + } catch (err) { + opts.onLog( + `Warning: could not record the listing evidence (${err instanceof Error ? err.message : String(err)}).\n`, + ); + } +} + +// enumeratePlaylistUrls, with what it returned noted as evidence — the +// entries printed before a 429 too (then rethrown, unchanged). +async function enumerateNoting( + opts: RunYtdlpOpts, + root: string, + source: RecordedListing["source"], + range?: { start: number; end?: number }, +): Promise<{ urls: string[]; at: string }> { + const at = new Date().toISOString(); + try { + return { urls: await enumeratePlaylistUrls(opts, root, range), at }; + } catch (err) { + if (err instanceof EnumerationIncompleteError) { + await noteListingEvidence(opts, { + at, + source, + urls: err.urls, + complete: false, + start: range?.start ?? 1, + pagesReached: err.pagesReached, + }); + } + throw err; + } +} + // Thin exported wrapper over the module-private enumeratePlaylistUrls for // callers (e.g. the quick availability check) that only need a one-shot fresh // flat-playlist fetch and shouldn't have to fabricate a full RunYtdlpOpts. @@ -785,8 +834,11 @@ async function acceptEnumeration( async function storePlaylist(opts: RunYtdlpOpts): Promise<void> { const root = channelRoot(opts); await mkdir(root, { recursive: true }); - const urls = await enumeratePlaylistUrls(opts, root); + const { urls, at } = await enumerateNoting(opts, root, "store-playlist"); const { decision } = await acceptEnumeration(opts, root, urls); + // Complete only when accepted: a shrink the guard holds is not trusted to + // say what is missing (its entries were still returned). + await noteListingEvidence(opts, { at, source: "store-playlist", urls, complete: decision.accept }); if (!decision.accept) { opts.onLog(`Store playlist: ${decision.reason}.\n`); return; @@ -2085,8 +2137,9 @@ async function syncPaged(opts: RunYtdlpOpts): Promise<void> { ) { const start = page * SYNC_PAGE_SIZE + 1; const end = start + SYNC_PAGE_SIZE - 1; - const pageUrls = await enumeratePlaylistUrls(opts, root, { start, end }); + const { urls: pageUrls, at: pageAt } = await enumerateNoting(opts, root, "sync-paged", { start, end }); if (pageUrls.length === 0) break; + await noteListingEvidence(opts, { at: pageAt, source: "sync-paged", urls: pageUrls, complete: false, start }); // ADD-ONLY: a page is a real (if partial) sighting of the listing, so the // ids on it belong in the roster — but a paged walk sees only the newest @@ -2185,8 +2238,9 @@ async function syncFullSweep(opts: RunYtdlpOpts): Promise<void> { // the roster (additive, so this is safe unconditionally) and decide // whether the listing itself may be acted on. let urls: string[]; + let listedAt: string; try { - urls = await enumeratePlaylistUrls(opts, root); + ({ urls, at: listedAt } = await enumerateNoting(opts, root, "sync-full")); } catch (err) { if (!(err instanceof EnumerationIncompleteError)) throw err; // A 429 part-way through the listing: what was printed is a prefix, not a @@ -2220,6 +2274,8 @@ async function syncFullSweep(opts: RunYtdlpOpts): Promise<void> { urls, ); opts.onLog(`Full sweep: ${decision.reason}.\n`); + // Complete only when accepted (see storePlaylist). + await noteListingEvidence(opts, { at: listedAt, source: "sync-full", urls, complete: decision.accept }); // A rejected listing must not truncate the stored playlist, must not flag // videos missing, and must not stamp lastFullSweepAt — so the next sync