commit f49b9e3105791d69ba3169d0f3559c0b4cf958fa
parent 2738c12670bb0ba3d3bbee21b416f83640c63dd6
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Sat, 21 Nov 2026 17:44:12 -0500
verify before clean: the newest complete listing is kept apart (review 2)
F1 (blocking). The newest complete whole-channel listing is kept as
`lastComplete` in listing-evidence.json, outside the 20 capped attempts:
start, end, URL, count and the sorted id sets it named (about 120 KB for
an 8,000-video channel). Any actor's complete listing from entry 1 sets it
(Sync's full sweep, Store playlist, the Quick check; never a paged walk);
a URL change clears it. So its omissions age out only by the window, not
by how many listings came after.
F2. A full listing that ended normally is complete EVIDENCE even when the
shrink guard holds it back from Sync; the guard's own behaviour (playlist,
missing sets) is unchanged.
Nits. An omission is dated from the listing's END: a sighting made while
it was running does not beat it. A cut-short listing whose upload dates are
not in order covers nothing beyond what it returned. OPERATING.md and
CHANGELOG say so, and that another actor's cut-short listing does not
overrule.
Tests, RED first: verifyNewerEvidence.test.ts "R2-1: the newest complete
listing is kept apart…25 later paged pages…", "R2-3: …from its END…",
"R2-3: …not in order covers nothing…"; manualDownloads.test.ts "a normally
ended full listing the shrink guard holds back…".
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
9 files changed, 279 insertions(+), 52 deletions(-)
diff --git a/OPERATING.md b/OPERATING.md
@@ -1172,11 +1172,23 @@ pnpm ops channel-config --json '{"slug":"example","cleanAudioWithoutChecking":tr
listed.
- **Newer beats older**: a sighting or probe does not count if a newer complete listing in the window does not name
the video. Such a video is asked about by itself, with no second listing. The same applies when the clean's own
- listing does not name it. For a listing cut short, that holds only over the stretch the listing covered, judged by
- upload time; outside that stretch the older evidence still counts, by the window. While any video overruled this
- way stays unconfirmed, the saved-video retention prune does not run. A listing counts as complete only when it
- ended normally: a cancel, a restart part-way or an early stop (exit 101) leaves a partial one. A listing time in
- the future (a wrong clock) is dropped.
+ listing does not name it.
+ - **Which listing**: the newest complete one, by any actor: Sync's full sweep, Store playlist or the Quick check.
+ It is kept as `lastComplete` in `listing-evidence.json`, with the ids it named, so any number of later listings
+ cannot push it out; only the window ages it.
+ - **Dated from its end**: a sighting made while that listing was still running counts as older than it.
+ - **The shrink guard**: a full sweep the guard holds back still counts as a complete listing here. The guard
+ still keeps Sync from applying it. Its omissions only send videos to be asked about, never pin or clean them.
+ - **A listing cut short** overrules older evidence only over the stretch it covered, judged by upload time.
+ Outside that stretch, the older evidence still counts, by the window. If the listing's entries are not in
+ upload order (several tabs, a re-ordered playlist), it covers nothing beyond what it returned.
+ - **The clean's own listings only**: a Quick check or full sweep cut short by another actor does not overrule
+ older sightings, even over the stretch it covered. That cost is part of the window.
+ - **Complete means it ended normally**: a cancel, a restart part-way or an early stop (exit 101) leaves a partial
+ listing.
+ - **The prune**: while any video overruled this way stays unconfirmed, the saved-video retention prune does not
+ run.
+ - **A wrong clock**: a listing time in the future is dropped.
- **A listing**: the videos it returns are verified. If the source rate-limits it part-way, the videos among the
entries it did return are still cleaned, and the job says "verified N from a partial listing of M entries; K
unverified remain". A video the partial listing did not reach is not judged and keeps its audio.
diff --git a/common/controller/listingEvidence.test.ts b/common/controller/listingEvidence.test.ts
@@ -73,6 +73,7 @@ test("only ids listed inside the window are fresh; 0 h uses nothing; a date in t
version: 2,
url: RU,
absent: {},
+ lastComplete: null,
seen: { fresh: iso(T0 - 23 * H), stale: iso(T0 - 25 * H), future: iso(T0 + 2 * H) },
embedSeen: {},
attempts: [],
@@ -92,6 +93,7 @@ test("the resume start: a continuation only where the extractor pages by offset,
version: 2,
url: RU,
absent: {},
+ lastComplete: null,
seen: {},
embedSeen: {},
attempts: [{ at, source: "quick-check", complete: false, start: 1, count: 408, platform, url: RU }],
@@ -115,21 +117,17 @@ test("the resume start: a continuation only where the extractor pages by offset,
assert.equal(listingResumeStart(paged, "odysee", T0, 24).start, 1);
});
-test("a complete whole listing inside the window is found; a paged walk or a continuation is not one", () => {
- const r: ListingEvidence = {
- version: 2,
- url: RU,
- absent: {},
- seen: {},
- embedSeen: {},
- attempts: [
- { at: iso(T0 - 2 * H), source: "sync-full", complete: true, start: 1, count: 8000, platform: "rumble", url: RU },
- { at: iso(T0 - H), source: "sync-paged", complete: true, start: 1, count: 30, platform: "rumble", url: RU },
- { at: iso(T0 - H), source: "clean-check", complete: true, start: 309, count: 30, platform: "rumble", url: RU },
- ],
- };
- assert.equal(freshCompleteListing(r, T0, 24)?.source, "sync-full");
- assert.equal(freshCompleteListing(r, T0, 1), null);
+test("the newest complete whole listing is kept as lastComplete; a paged walk or a continuation never is one", () => {
+ let r = empty();
+ r = foldListing(r, { at: iso(T0 - 2 * H), endedAt: iso(T0 - 2 * H + 600_000), source: "sync-full", urls: ["https://rumble.com/v1aaaa-t.html", "https://rumble.com/embed/v8embd1/"], complete: true, platform: "rumble", url: RU }, T0);
+ r = foldListing(r, { at: iso(T0 - H), source: "sync-paged", urls: ["https://rumble.com/v1bbbb-t.html"], complete: true, platform: "rumble", url: RU }, T0);
+ r = foldListing(r, { at: iso(T0 - H), source: "clean-check", urls: ["https://rumble.com/v1cccc-t.html"], complete: true, start: 309, platform: "rumble", url: RU }, T0);
+ const c = freshCompleteListing(r, T0, 24);
+ assert.equal(c?.source, "sync-full");
+ assert.equal(c?.endedAt, iso(T0 - 2 * H + 600_000));
+ assert.deepEqual(c?.ids, ["v1aaaa"]);
+ assert.deepEqual(c?.embedIds, ["v8embd1"]);
+ assert.equal(freshCompleteListing(r, T0, 1), null, "outside the window");
});
// ---------------------------------------------------------------------------
diff --git a/common/controller/listingEvidence.ts b/common/controller/listingEvidence.ts
@@ -82,6 +82,28 @@ export type ListingEvidence = {
absent: Record<string, string>;
// Newest last.
attempts: ListingAttempt[];
+ // THE NEWEST COMPLETE WHOLE-CHANNEL LISTING, kept apart from the capped
+ // `attempts` (review 2, F1), so the omission it records can age out only by
+ // the trust window, never by how many listings came after. Written by any
+ // actor whose listing ended normally from entry 1 (Sync's full sweep, Store
+ // playlist, the Quick check; a paged walk never is one). Its id sets answer
+ // "did it name video X"; on a channel of 8,000 videos they are about 8,000
+ // ids of ~11 characters, ~120 KB of the file.
+ lastComplete: CompleteListing | null;
+};
+
+export type CompleteListing = {
+ // When it started and when it ended (ISO). An omission is dated from the
+ // END (review 2, F4): the listing may have passed a video's place at any
+ // moment before it ended, so a sighting during the listing does not beat it.
+ at: string;
+ endedAt: string;
+ source: ListingSource;
+ url: string;
+ count: number;
+ // Canonical page ids and Rumble embed ids it returned, sorted.
+ ids: string[];
+ embedIds: string[];
};
export function listingEvidencePath(paths: Pick<Paths, "channelsDir">, slug: string): string {
@@ -89,7 +111,24 @@ export function listingEvidencePath(paths: Pick<Paths, "channelsDir">, slug: str
}
export function emptyEvidence(url: string | null = null): ListingEvidence {
- return { version: 2, url, seen: {}, embedSeen: {}, absent: {}, attempts: [] };
+ return { version: 2, url, seen: {}, embedSeen: {}, absent: {}, attempts: [], lastComplete: null };
+}
+
+function isCompleteListing(v: unknown): v is CompleteListing {
+ const c = v as Partial<CompleteListing> | null;
+ return (
+ !!c &&
+ typeof c.at === "string" &&
+ Number.isFinite(Date.parse(c.at)) &&
+ typeof c.endedAt === "string" &&
+ Number.isFinite(Date.parse(c.endedAt)) &&
+ typeof c.url === "string" &&
+ typeof c.count === "number" &&
+ Array.isArray(c.ids) &&
+ c.ids.every((x) => typeof x === "string") &&
+ Array.isArray(c.embedIds) &&
+ c.embedIds.every((x) => typeof x === "string")
+ );
}
function stringMap(v: unknown): Record<string, string> {
@@ -135,6 +174,9 @@ export function normalizeListingEvidence(value: unknown): ListingEvidence {
embedSeen: stringMap(r.embedSeen),
absent: stringMap(r.absent),
attempts: Array.isArray(r.attempts) ? r.attempts.filter(isAttempt).slice(-LISTING_ATTEMPTS_KEPT) : [],
+ lastComplete: isCompleteListing(r.lastComplete)
+ ? { ...r.lastComplete, ids: [...r.lastComplete.ids].sort(), embedIds: [...r.lastComplete.embedIds].sort() }
+ : null,
};
}
@@ -162,6 +204,8 @@ export type RecordedListing = {
platform: string;
// The channel URL that was listed.
url: string;
+ // When the listing ended (ISO); its start (`at`) when not given.
+ endedAt?: string;
};
// A time later than the clock (plus a minute) is a clock that was wrong when
@@ -190,8 +234,9 @@ export function foldListing(record: ListingEvidence, listing: RecordedListing, n
prune(embedSeen, nowMs);
prune(absent, nowMs);
const attempts = base.attempts.filter((a) => !inFuture(a.at, nowMs));
+ let lastComplete = base.lastComplete && !inFuture(base.lastComplete.endedAt, nowMs) ? base.lastComplete : null;
if (inFuture(listing.at, nowMs)) {
- return { version: 2, url: listing.url, seen, embedSeen, absent, attempts };
+ return { version: 2, url: listing.url, seen, embedSeen, absent, attempts, lastComplete };
}
const idx = indexListing(listing.urls);
const stamp = (map: Record<string, string>, id: string) => {
@@ -210,7 +255,32 @@ export function foldListing(record: ListingEvidence, listing: RecordedListing, n
platform: listing.platform,
url: listing.url,
};
- return { version: 2, url: listing.url, seen, embedSeen, absent, attempts: [...attempts, attempt].slice(-LISTING_ATTEMPTS_KEPT) };
+ const endedAt = listing.endedAt && !inFuture(listing.endedAt, nowMs) ? listing.endedAt : listing.at;
+ if (
+ listing.complete &&
+ attempt.start === 1 &&
+ listing.source !== "sync-paged" &&
+ (!lastComplete || Date.parse(lastComplete.endedAt) <= Date.parse(endedAt))
+ ) {
+ lastComplete = {
+ at: listing.at,
+ endedAt,
+ source: listing.source,
+ url: listing.url,
+ count: idx.entries,
+ ids: [...idx.ids].sort(),
+ embedIds: [...idx.embedIds].sort(),
+ };
+ }
+ return {
+ version: 2,
+ url: listing.url,
+ seen,
+ embedSeen,
+ absent,
+ attempts: [...attempts, attempt].slice(-LISTING_ATTEMPTS_KEPT),
+ lastComplete,
+ };
}
// Record what a listing returned. Callers treat a failure as best-effort: a
@@ -265,22 +335,46 @@ export function isFresh(at: string, nowMs: number, maxAgeHours: number): boolean
return Number.isFinite(t) && t <= nowMs + FUTURE_SLACK_MS && nowMs - t <= maxAgeHours * HOUR;
}
-// NEWER EVIDENCE BEATS OLDER (review 1, F1). When a video was last
-// contradicted by the source, in ms (-Infinity: never): the newest COMPLETE
-// whole-channel listing inside the window — it stamps every id it returned
-// with its own start, so a video it named carries a stamp at least that new,
-// and one it did not name carries an older one or none — or the video's
-// absent mark (a listing of the pre-clean check that covered its place and did
-// not name it). A sighting or a probe older than this does not vouch for it.
-export function contradictedSince(record: ListingEvidence, dirId: string, nowMs: number, maxAgeHours: number): number {
+// NEWER EVIDENCE BEATS OLDER (review 1, F1; review 2, F1 and F4). When a
+// video was last contradicted by the source, in ms (-Infinity: never): the
+// END of the newest complete whole-channel listing inside the window when
+// that listing does not name the video (`lastComplete`, kept apart from the
+// capped attempts), or the video's absent mark (a listing of the pre-clean
+// check that covered its place and did not name it). A sighting or a probe
+// older than this does not vouch for it — one made while that listing was
+// still running included: the listing may have passed the video's place after
+// it. A video the complete listing named is never contradicted by it.
+export function contradictedSince(
+ record: ListingEvidence,
+ c: { dir: string; embed?: string },
+ nowMs: number,
+ maxAgeHours: number,
+): number {
let t = Number.NEGATIVE_INFINITY;
const complete = freshCompleteListing(record, nowMs, maxAgeHours);
- if (complete) t = Date.parse(complete.at);
- const mark = record.absent[dirId];
+ if (complete && !completeNames(complete, c)) t = Date.parse(complete.endedAt);
+ const mark = record.absent[c.dir];
if (mark && !inFuture(mark, nowMs)) t = Math.max(t, Date.parse(mark));
return t;
}
+// PURE: did the complete listing name this candidate (its directory id among
+// page ids, its embed id among embed ids)?
+export function completeNames(complete: CompleteListing, c: { dir: string; embed?: string }): boolean {
+ const has = (list: string[], id: string) => {
+ let lo = 0;
+ let hi = list.length - 1;
+ while (lo <= hi) {
+ const mid = (lo + hi) >> 1;
+ if (list[mid] === id) return true;
+ if (list[mid] < id) lo = mid + 1;
+ else hi = mid - 1;
+ }
+ return false;
+ };
+ return has(complete.ids, c.dir) || (c.embed !== undefined && has(complete.embedIds, c.embed));
+}
+
// PURE: the newest fresh stamp of a candidate (its directory id against page
// ids, its embed id against embed ids), in ms, or null.
export function freshStampOf(
@@ -310,18 +404,16 @@ export function freshListingIndex(record: ListingEvidence, nowMs: number, maxAge
// PURE: is there a COMPLETE whole-channel listing inside the window? Then a
// candidate it does not name is a suspect (unlisted or gone) to confirm by
-// itself — no second listing is needed to learn that.
+// itself — no second listing is needed to learn that. The record's
+// `lastComplete`, whatever has been listed since; fresh by its start.
export function freshCompleteListing(
record: ListingEvidence,
nowMs: number,
maxAgeHours: number,
-): ListingAttempt | null {
+): CompleteListing | null {
if (maxAgeHours <= 0) return null;
- for (let i = record.attempts.length - 1; i >= 0; i--) {
- const a = record.attempts[i];
- if (a.complete && a.start === 1 && a.source !== "sync-paged" && isFresh(a.at, nowMs, maxAgeHours)) return a;
- }
- return null;
+ const c = record.lastComplete;
+ return c && isFresh(c.at, nowMs, maxAgeHours) && !inFuture(c.endedAt, nowMs) ? c : null;
}
// WHERE A CUT-SHORT LISTING CONTINUES, per platform — read from yt-dlp's
diff --git a/common/controller/quickAvailabilityCheck.ts b/common/controller/quickAvailabilityCheck.ts
@@ -72,7 +72,16 @@ export async function runQuickAvailabilityCheck({
const platform = detectPlatform(config.url) ?? "unknown";
const url = config.url;
const record = (urls: readonly string[], complete: boolean, pagesReached?: number | null) =>
- recordListing(paths, channelSlug, { at: now, source: "quick-check", urls, complete, platform, pagesReached, url }).catch(
+ recordListing(paths, channelSlug, {
+ at: now,
+ endedAt: new Date().toISOString(),
+ source: "quick-check",
+ urls,
+ complete,
+ platform,
+ pagesReached,
+ url,
+ }).catch(
(err) => log(`Warning: could not record the listing evidence (${(err as Error).message}).`),
);
let freshUrls: string[];
diff --git a/common/controller/verifyBeforeClean.ts b/common/controller/verifyBeforeClean.ts
@@ -168,15 +168,39 @@ async function videoTimeOf(videoDir: string): Promise<number | null> {
// candidate whose time cannot be read is counted as covered — the safe side:
// it is asked about, not cleaned on an older sighting. A listing that returned
// nothing and did not finish covered nothing.
+//
+// NOT IN UPLOAD ORDER, NOTHING ASSUMED (review 2, F3). The stretch is only
+// meaningful for a newest-first listing. One that walks several tabs, or a
+// re-ordered playlist, prints dates out of order: then a cut-short listing
+// covers nothing beyond the entries it returned (they still count as seen),
+// so no omission is read into it. Checked over up to ORDER_SAMPLE dated
+// entries spread across the run, with ORDER_SLACK_MS of slack.
const COVERAGE_PROBE_ENTRIES = 20;
+const ORDER_SAMPLE = 60;
+const ORDER_SLACK_MS = 3_600_000;
async function coverageOf(
run: { urls: readonly string[]; complete: boolean; start: number },
dataDir: string,
+ log: (m: string) => void,
): Promise<(id: string) => Promise<boolean>> {
if (run.complete && run.start === 1) return async () => true;
if (run.urls.length === 0) return async () => run.complete;
const dirs = new Set(await readdir(dataDir).catch(() => [] as string[]));
const onDisk = run.urls.map((u) => extractVideoId(u)).filter((id): id is string => !!id && dirs.has(id));
+ const step = Math.max(1, Math.floor(onDisk.length / ORDER_SAMPLE));
+ let prev: number | null = null;
+ for (let i = 0; i < onDisk.length; i += step) {
+ const t = await videoTimeOf(path.join(dataDir, onDisk[i]));
+ if (t === null) continue;
+ if (prev !== null && t > prev + ORDER_SLACK_MS) {
+ log(
+ "Verify before clean: this listing's entries are not in upload order (several tabs, or a re-ordered playlist) — " +
+ "nothing is read into what it did not return.",
+ );
+ return async () => false;
+ }
+ prev = t;
+ }
const edge = async (ids: string[], pick: (a: number, b: number) => number): Promise<number | null> => {
let best: number | null = null;
let dated = 0;
@@ -355,8 +379,9 @@ export async function verifyBeforeClean({
let probedStored = 0;
if (maxAge > 0) {
for (const id of remaining) {
- const since = contradictedSince(evidence, id, nowMs, maxAge);
- const stamp = freshStampOf(evidence, await candidateIdsOf(paths.channelsDir, channelSlug, id, platform), nowMs, maxAge);
+ const cand = await candidateIdsOf(paths.channelsDir, channelSlug, id, platform);
+ const since = contradictedSince(evidence, cand, nowMs, maxAge);
+ const stamp = freshStampOf(evidence, cand, nowMs, maxAge);
if (stamp !== null && stamp >= since) {
vouched.add(id);
listedStored++;
@@ -457,7 +482,8 @@ export async function verifyBeforeClean({
noteShift(listing.urls, resume, evidence, log);
// Complete only at the lister's own normal end (review 1, F2).
const done = listing.ended === "normal";
- await recordListing(paths, channelSlug, { at, source: "clean-check", urls: listing.urls, complete: done, start: resume.start, platform, url: config.url }, nowMs).catch(
+ const endedAt = new Date().toISOString();
+ await recordListing(paths, channelSlug, { at, endedAt, source: "clean-check", urls: listing.urls, complete: done, start: resume.start, platform, url: config.url }).catch(
(err) => log(`Warning: could not record the listing evidence (${(err as Error).message}).`),
);
run = { urls: listing.urls, complete: done, start: resume.start };
@@ -480,7 +506,7 @@ export async function verifyBeforeClean({
const returned = maybeMissing
? new Set(remaining.filter((id) => !maybeMissing!.has(id)))
: await listedCandidates(match, remaining, indexListing(run.urls));
- const covered = await coverageOf(run, dataDir);
+ const covered = await coverageOf(run, dataDir, log);
const absentNow: string[] = [];
for (const id of remaining) {
if (returned.has(id) || !(await covered(id))) continue;
diff --git a/common/controller/verifyNewerEvidence.test.ts b/common/controller/verifyNewerEvidence.test.ts
@@ -362,3 +362,58 @@ test("F3: evidence taken from another channel URL is not used, and the new URL's
// Keep the import used: the partial-listing error is what the fake's 429 becomes.
void EnumerationIncompleteError;
+
+// ---------------------------------------------------------------------------
+// Review 2
+
+test("R2-1: the newest complete listing is kept apart from the capped attempts — 25 later paged pages do not age its omission out", async () => {
+ const c = await channel(RU, [{ id: "v1gone" }, { id: "v1here" }]);
+ const now = Date.now();
+ await recordListing(c.paths, "ch", { at: iso(now - 10 * H), source: "sync-full", urls: [watch("v1gone"), watch("v1here")], complete: true, platform: "rumble", url: RU });
+ await recordListing(c.paths, "ch", { at: iso(now - 8 * H), source: "quick-check", urls: [watch("v1here")], complete: true, platform: "rumble", url: RU });
+ for (let i = 0; i < 25; i++) {
+ await recordListing(c.paths, "ch", { at: iso(now - 7 * H + i * 60_000), source: "sync-paged", urls: [watch("v1here")], complete: false, platform: "rumble", url: RU });
+ }
+ const { asked, probes } = probesAnswering(c.paths, () => "deleted");
+ await clean(c.paths, probes);
+ assert.deepEqual(asked, ["v1gone"], "still contradicted: probed");
+ assert.equal(await c.pinned("v1gone"), true);
+ assert.equal(await c.hasAudio("v1gone"), true);
+ const ev = await readListingEvidence(c.paths, "ch");
+ assert.equal(ev.attempts.length, 20);
+ assert.equal(ev.lastComplete?.source, "quick-check");
+ assert.deepEqual(ev.lastComplete?.ids, ["v1here"]);
+});
+
+test("R2-3: a complete listing contradicts from its END — a sighting while it was still running does not vouch", async () => {
+ const c = await channel(RU, [{ id: "v1gone" }, { id: "v1here" }]);
+ const now = Date.now();
+ // The listing ran from 40 to 20 minutes ago; a paged page saw v1gone 30
+ // minutes ago, while it ran; the listing did not name it.
+ await recordListing(c.paths, "ch", { at: iso(now - 30 * 60_000), source: "sync-paged", urls: [watch("v1gone")], complete: false, platform: "rumble", url: RU });
+ await recordListing(c.paths, "ch", { at: iso(now - 40 * 60_000), endedAt: iso(now - 20 * 60_000), source: "store-playlist", urls: [watch("v1here")], complete: true, platform: "rumble", url: RU });
+ const { asked, probes } = probesAnswering(c.paths, () => "deleted");
+ await clean(c.paths, probes);
+ assert.deepEqual(asked, ["v1gone"]);
+ assert.equal(await c.hasAudio("v1gone"), true);
+ // A sighting AFTER the end does vouch (here: v1here, named by it, is cleaned).
+ assert.equal(await c.hasAudio("v1here"), false);
+});
+
+test("R2-3: a partial listing whose upload dates are not in order covers nothing beyond what it returned", async () => {
+ const c = await channel(RU, [
+ { id: "v1aaaa", uploadedDaysAgo: 1 },
+ { id: "v1bbbb", uploadedDaysAgo: 40 },
+ { id: "v1cccc", uploadedDaysAgo: 2 },
+ { id: "v1seen", uploadedDaysAgo: 10 },
+ ]);
+ await recordListing(c.paths, "ch", { at: iso(Date.now() - 5 * H), source: "sync-paged", urls: [watch("v1seen")], complete: false, platform: "rumble", url: RU });
+ // Returned out of date order (1, 40, 2 days), then a 429.
+ await c.setListing([watch("v1aaaa"), watch("v1bbbb"), watch("v1cccc"), watch("v1more")]);
+ await c.setLimit(3);
+ const lines: string[] = [];
+ await clean(c.paths, probesAnswering(c.paths, () => undefined).probes, lines);
+ assert.equal(await c.hasAudio("v1aaaa"), false, "returned: cleaned");
+ assert.equal(await c.hasAudio("v1seen"), false, "nothing is assumed about an omission: its sighting still counts");
+ assert.ok(lines.some((l) => l.includes("not in upload order")), lines.join("\n"));
+});
diff --git a/common/ytdlp/manualDownloads.test.ts b/common/ytdlp/manualDownloads.test.ts
@@ -48,13 +48,19 @@ process.env.YTDLP_BIN = BIN;
const MANUAL = { handling: "transcribe", url: "https://www.youtube.com/@manual/videos", downloadMode: "manual" } as const;
const AUTO = { handling: "transcribe", url: "https://www.youtube.com/@auto/videos" } as const;
-for (const [slug, config] of [["manual", MANUAL], ["auto", AUTO]] as const) {
+// A channel whose stored playlist lists a hundred videos, of which the fake's
+// listing (two) is far less than the shrink guard lets Sync accept.
+const SHRINK = { handling: "transcribe", url: "https://www.youtube.com/@shrink/videos", downloadMode: "manual" } as const;
+for (const [slug, config] of [["manual", MANUAL], ["auto", AUTO], ["shrink", SHRINK]] as const) {
mkdirSync(path.join(ROOT, "channels", slug, "data"), { recursive: true });
writeFileSync(path.join(ROOT, "channels", slug, "config.json"), JSON.stringify(config));
// An empty saved playlist: an automatic download-missing has nothing to fetch.
writeFileSync(path.join(ROOT, "channels", slug, "playlist"), "");
}
+const SHRINK_PLAYLIST = Array.from({ length: 100 }, (_, i) => `https://www.youtube.com/watch?v=shrink${String(i).padStart(5, "0")}`);
+writeFileSync(path.join(ROOT, "channels", "shrink", "playlist"), SHRINK_PLAYLIST.join("\n") + "\n");
+
const { runYtdlp } = await import("./runYtdlp");
const { getPaths } = await import("../lib/paths");
@@ -150,3 +156,24 @@ test("a single video still downloads on a manual channel", async () => {
"the one video was asked for",
);
});
+
+test("a normally ended full listing the shrink guard holds back: Sync does not apply it, but it is complete evidence", async () => {
+ await runYtdlp({
+ channelSlug: "shrink",
+ mode: "sync",
+ channelConfig: SHRINK as never,
+ paths: getPaths(),
+ onLog: () => {},
+ signal: new AbortController().signal,
+ forceFullSweep: true,
+ });
+ // The guard's own behaviour is unchanged: the stored playlist is not cut.
+ const playlist = readFileSync(path.join(ROOT, "channels", "shrink", "playlist"), "utf8").split("\n").filter(Boolean);
+ assert.deepEqual(playlist, SHRINK_PLAYLIST);
+ // But the listing really did end normally and omit 98 videos: it is the
+ // complete listing every older sighting must answer to.
+ const ev = JSON.parse(readFileSync(path.join(ROOT, "channels", "shrink", "listing-evidence.json"), "utf8"));
+ const full = ev.attempts.filter((a: { source: string }) => a.source === "sync-full");
+ assert.equal(full.at(-1).complete, true);
+ assert.deepEqual(ev.lastComplete.ids, ["aaaaaaaaaaa", "bbbbbbbbbbb"]);
+});
diff --git a/common/ytdlp/runYtdlp.ts b/common/ytdlp/runYtdlp.ts
@@ -649,6 +649,7 @@ async function noteListingEvidence(
if (!opts.channelConfig.url) return;
try {
await recordListing(opts.paths, opts.channelSlug, {
+ endedAt: new Date().toISOString(),
...listing,
url: opts.channelConfig.url,
platform: cooldownPlatformKey(opts.channelConfig),
@@ -862,10 +863,14 @@ async function storePlaylist(opts: RunYtdlpOpts): Promise<void> {
await mkdir(root, { recursive: true });
const { urls, at, ended } = await enumerateNoting(opts, root, "store-playlist");
const { decision } = await acceptEnumeration(opts, root, urls);
- // Complete only when the lister ended normally and the listing was
- // accepted: a shrink the guard holds is not trusted to say what is missing
- // (its entries were still returned), and a cancelled one is a prefix.
- await noteListingEvidence(opts, { at, source: "store-playlist", urls, complete: decision.accept && ended === "normal" });
+ // Complete when the lister ended normally (a cancelled one is a prefix),
+ // WHETHER OR NOT THE SHRINK GUARD ACCEPTS IT (review 2, F2): the guard
+ // keeps a sudden shrink from rewriting the playlist and the missing sets,
+ // which it still does; as evidence, a listing that really omitted the
+ // videos must contradict older sightings of them — that omission is the
+ // mass-removal case — and an omission here only sends a video to be asked
+ // about by itself, never pins or cleans it.
+ await noteListingEvidence(opts, { at, source: "store-playlist", urls, complete: ended === "normal" });
if (!decision.accept) {
opts.onLog(`Store playlist: ${decision.reason}.\n`);
return;
@@ -2302,8 +2307,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 && listingEnd === "normal" });
+ // Complete when it ended normally, accepted or not (see storePlaylist).
+ await noteListingEvidence(opts, { at: listedAt, source: "sync-full", urls, complete: listingEnd === "normal" });
// A rejected listing must not truncate the stored playlist, must not flag
// videos missing, and must not stamp lastFullSweepAt — so the next sync
diff --git a/editor/CHANGELOG.md b/editor/CHANGELOG.md
@@ -24,6 +24,9 @@
- Newer beats older: a newer complete listing that does not name the video overrules an older sighting or probe,
and so does the clean's own listing. The video is then asked about by itself. A listing counts as complete only
when it ended normally: a cancelled one is a prefix.
+ - The newest complete listing is kept apart from the 20 recent listings, so later Sync pages cannot push its
+ omissions out. It is dated from its end. A full sweep the shrink guard holds back still counts as one (Sync
+ still does not apply it).
- On Odysee and BitChute the next listing continues two pages before where the last one stopped. Elsewhere yt-dlp
cannot skip pages, so a retry keeps the earlier verdicts and asks only for the rest.
- When few candidates remain against a large channel, each one is asked about by itself (paced, every answer kept)