commit e5079bb9f1edeaf803df8322e6b98c7cb700a6d3
parent 5c7438ec9dff9a32aa042bc3a58ebbe6d0becdc4
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Tue, 24 Nov 2026 12:42:55 -0500
record-live: REVIEW-8 2: no false "damaged" after a resume stopped inside an append, and the mark clears
After a resume that wrote, each stream file is checked by what its
fragments prove. With its state it is the equation: fragments 1..index, a
torn tail the repair allows, sizes and the last fragment's bytes, all
cheap. Finished, with no state, it is compared byte for byte. The mark
clears when a later check holds, and a resume that wrote nothing is not
checked, so the whole-stream re-read after every resume is gone. Test red
on 5c7438ec9.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
2 files changed, 48 insertions(+), 8 deletions(-)
diff --git a/common/controller/recordLive.test.ts b/common/controller/recordLive.test.ts
@@ -5129,3 +5129,31 @@ test("REVIEW-8 1: one state read failing for a NON-network reason does not aband
assert.ok(!log.some((l) => /nothing on disk can be reused with proof/.test(l)));
assert.ok(calls.some(isInsurance), "the insurance beside the part found far behind");
});
+
+test("REVIEW-8 2: a resume stopped inside an append (a torn tail the repair allows) is NOT 'damaged'; once the stream ends whole the row needs nobody", { timeout: 60_000 }, async () => {
+ const id = "exmplr8dmg1";
+ let live = true;
+ const { run, log } = await incidentRun(
+ id,
+ resumableYtdlp(async ({ n, write, tear }) => {
+ if (n === 1) {
+ await write(3000);
+ return "die";
+ }
+ if (n === 2) {
+ await write(3600);
+ await tear("video", 0.5);
+ return "die";
+ }
+ await write(7200);
+ live = false;
+ return "end";
+ }),
+ { deps: { ...FAST_WATCH, stallMs: 60_000, join: null, merge: fakeMerge }, refresh: { stillLive: () => live } },
+ );
+ assert.equal((await run).status, "landed");
+ const row = (await rowOf(id))[0]!;
+ assert.ok(row.parts.every((p) => !p.resumeDamaged), `no false damage: ${JSON.stringify(row.parts.map((p) => p.resumeDamaged))}`);
+ assert.ok(!log.some((l) => /after the resume, .* the file is kept as it is/.test(l)));
+ assert.equal(row.needsAttention, false);
+});
diff --git a/common/controller/recordLive.ts b/common/controller/recordLive.ts
@@ -1825,6 +1825,7 @@ async function recordLiveRunInner(
});
}, watchMs);
}
+ const streamBefore = opts.resume ? await streamBytesOf(stem) : 0;
// NOTE 5 (REVIEW-5) — ONE RECORDER PER STEM: a lock file held while the
// recorder runs. yt-dlp would let a second writer append to the same file.
const lock = opts.resume?.lock ?? (await takeStemLock(slugStore, stem));
@@ -1913,18 +1914,29 @@ async function recordLiveRunInner(
}
}
if (fragAbort && part.fragmentErrors) await save();
- // REVIEW-7 2: after EVERY resume, each stream file must still be its kept
- // fragments; said (and the part loud) when it is not.
- if (opts.resume && separate && !part.fragmentsDropped) {
+ // REVIEW-7 2 / REVIEW-8 2: after a resume that wrote, each stream file
+ // must still be what its fragments prove — with its state, the equation
+ // (fragments 1..index, a torn tail the repair allows, sizes and the last
+ // fragment's bytes: cheap); finished (no state), byte for byte. Said, and
+ // the part loud, when it is not; the mark clears when a later check holds.
+ if (opts.resume && separate && !part.fragmentsDropped && (await streamBytesOf(stem)) > streamBefore) {
+ let damaged: string | null = null;
const g = await filesOf(stem);
for (const f of g?.streams ?? []) {
- const eq = await streamEqualsFragments(slugStore, f).catch((e: Error) => ({ ok: false as const, why: e.message }));
- if (eq && !eq.ok) {
- part.resumeDamaged = eq.why;
- say(`[${tag}] after the resume, ${eq.why}: the file is kept as it is and never removed; the row needs a person.`);
- break;
+ const idx = await readYtdlIndex(path.join(slugStore, f));
+ if (typeof idx === "number") {
+ const r = await reconcileStream(slugStore, f, false).catch((e: Error) => ({ ok: false as const, why: e.message }));
+ if (!r.ok) damaged = r.why;
+ } else if (idx === "absent") {
+ const eq = await streamEqualsFragments(slugStore, f).catch((e: Error) => ({ ok: false as const, why: e.message }));
+ if (eq && !eq.ok) damaged = eq.why;
}
+ if (damaged) break;
}
+ if (damaged) {
+ part.resumeDamaged = damaged;
+ say(`[${tag}] after the resume, ${damaged}: the file is kept as it is and never removed; the row needs a person.`);
+ } else delete part.resumeDamaged;
}
await save();
return { ...o, part, stem, stalled, ...(fragAbort ? { fragAbort } : {}), ...(urlRefreshHere ? { urlRefresh: true } : {}) };