commit 3dc083b0a3a8bf8c74823ded5a1beb59e08b8c2e
parent b3e5722a01ab28abe52146593760a0bd0ec08b5f
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Tue, 24 Nov 2026 19:02:30 -0500
space-suggestions REVIEW-1 note 15: Refresh while a scan is queued or running queues nothing
The page's Refresh and POST /api/ops/space-scan answer with the scan already
there; help and COMMANDS.md say so.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
5 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/COMMANDS.md b/COMMANDS.md
@@ -162,7 +162,7 @@ Drives a running editor over HTTP (`/api/ops/*`, the same actions its pages run)
| `review-compacted-original` | review-compacted-original records a person's review of one compacted copy (watch it first: get compaction-review's "watch"): {"slug", "id", "note"?}. It names the copy it is for ("watched", its sha256) and counts for that copy only; it changes nothing on disk. It is what lets drop-saved-alternate ("confirmOriginal": true) drop the original of a video not freshly checked on its platform. "formerOriginal": "<file>" reviews the active copy that replaced a former original instead. | |
| `compaction-markers` | compaction-markers lists the "being compacted" markers (.compacting.json), each live or stale and why: {}. {"clear": {"slug", "id"}} removes a stale one; a live one is refused (cancel its job). Stale ones are also swept at editor boot and at the start of every compaction run. | |
| `kept-failed-encodes` | kept-failed-encodes lists the encodes kept after a failed check (in each video's .compact-scratch, never active: chunks and the joined copy, their size, what failed): {}. {"clear": {"slug", "id"}} removes one (refused while its compaction runs). compact-saved-videos "reverify": true re-checks one without encoding. | |
-| `space-scan` | space-scan measures every disk the archive writes to: {"compaction"?} -> {jobId}. The corpus disk, each storage location, the saved-video store's, the site builds' and umtool's reports' disks, by device: allocated bytes, each inode once, a file with other hard links never counted as freed, a tier link on its target's disk, a drive not mounted or not answering unknown (never empty). Then what would free space on each through the writers that exist — compress-text (captions, live chats), the cleanup sweeps, relocate, evict-clips, delete-file (abandoned partials), compact-saved-videos, drop-saved-alternate (compacted originals, alternates), kept-failed-encodes, live-recording-verify — with what is held (do-not-clean, a pin's copies, a live recording, a move in flight) and why. It only reads: nothing is removed, moved or fetched. Written to transcripts/.space-suggestions.json; get space-suggestions reads it. "compaction": false skips the selector's pass (one ffprobe per saved container not seen unchanged before) and keeps the last scan's rows. | `pnpm ops space-scan --json '{"compaction":false}' --wait` |
+| `space-scan` | space-scan measures every disk the archive writes to: {"compaction"?} -> {jobId}. The corpus disk, each storage location, the saved-video store's, the site builds' and umtool's reports' disks, by device: allocated bytes, each inode once, a file with other hard links never counted as freed, a tier link on its target's disk, a drive not mounted or not answering unknown (never empty). Then what would free space on each through the writers that exist — compress-text (captions, live chats), the cleanup sweeps, relocate, evict-clips, delete-file (abandoned partials), compact-saved-videos, drop-saved-alternate (compacted originals, alternates), kept-failed-encodes, live-recording-verify — with what is held (do-not-clean, a pin's copies, a live recording, a move in flight) and why. It only reads: nothing is removed, moved or fetched. Written to transcripts/.space-suggestions.json; get space-suggestions reads it. "compaction": false skips the selector's pass (one ffprobe per saved container not seen unchanged before) and keeps the last scan's rows. While a scan is queued or running, nothing more is queued: the answer is that job ({jobId, alreadyQueued: true}). | `pnpm ops space-scan --json '{"compaction":false}' --wait` |
| `compress-text` | compress-text stores big text files compressed (zstd, level 9): the raw live-chat replays (transcript.live\_chat.json -> .zst, kind live-chat, the default) and the caption tracks (every transcript.<lang>.vtt -> .zst, on the corpus disk: "kinds": \["captions"\], only when named). Read back by every reader as the same file, with the same times (the index sees no change): {"slugs"?: \[...\], "kinds"?: \["live-chat", "captions"\], "dryRun"?, "limit"?, "verify"?, "restore"?}. A caption's dry run also counts the en / en-orig pairs of equal size (compressed each as it is, never deduped). One file at a time: written beside the original, fsynced, read back and hashed against it, and only then the original removed; a crash at any step leaves a whole copy, and the next run finishes it (it visits every dir a stopped run left). Left alone and counted: a file written (mtime or ctime) in the last 10 minutes, one with a .part beside it, a video recording or with a job running, a drive that does not answer, a channel whose media is moving. Both forms present with different content are refused, both kept and listed once (recorded per channel; not visited again until a form changes): nothing removes a stored copy because a different one arrived. A file a writer replaces during the run is kept and read; the earlier content's stored copy is kept beside it. The dry run lists earlier chat captures a re-fetch kept (chat-capture-kept.\*.json.zst), which nothing removes automatically. "dryRun": true answers per channel and kind the files, their bytes, the stored ones, the estimate after (about 5 % for a chat, 20 % for a caption: estimates) and the free space, and writes nothing; "verify": true decodes every stored file in full and writes nothing; "limit" counts files compressed and takes exactly one channel in "slugs". One job per channel with work, on the machine-wide compress-text queue (one file at a time), waiting while render mode holds the machine and slower while a live recording runs. Started by a person only: a restart closes a queued one and resumes no interrupted one (it removes originals) -- a re-run continues. "restore": true is the rollback: every stored file of the kinds put back into its plain form, verified the same way in reverse (decoded beside, fsynced, read back against a fresh decode, the same times, then the .zst removed); with "dryRun" it answers the stored files, their plain bytes and the free space. Run it BEFORE reverting or running an older checkout, which cannot read a stored chat or caption (OPERATING.md). | |
| `build-cues` | build-cues writes each video's transcript.cues.json from its raw transcript (the caption-track rule for VTTs), as the digest card's Normalize button does: {"slug"}, "ids": \[...\] for those videos only (every one held), "force": true to rewrite a fresh one. A job on the channel's queue. The file every reader without an index build wants. | `pnpm ops build-cues --json '{"slug":"demo-yt","ids":["<videoId>"]}' --wait` |
| `feed-metadata` | feed-metadata completes a podcast channel's records from its RSS feed: one fetch of the channel's url, then title, date, description and duration into each record that lacks them: {"slug"}. "dryRun": true counts matched, unmatched and already complete, and writes nothing. | `pnpm ops feed-metadata --json '{"slug":"demo-podcast","dryRun":true}' --wait` |
diff --git a/editor/app/api/ops/space-scan/route.test.ts b/editor/app/api/ops/space-scan/route.test.ts
@@ -53,3 +53,22 @@ test("a scan runs as a job and writes .space-suggestions.json", async () => {
assert.ok(result?.suggestions.some((s) => s.kind === "compress-captions" && s.slug === "demo"));
assert.equal(result?.compactionAt, null);
});
+
+test("a scan already queued or running is the answer: no second one is queued", async () => {
+ const { newJobId } = await import("yt-dlp-transcript-common/jobs/registry");
+ const record = { id: newJobId(), kind: "space-scan", queueKey: "space-scan-held", status: "queued" as const, queuedAt: Date.now(), logPath: "/dev/null" };
+ getRegistry().register(record);
+ getRegistry().enqueue(record, { start: () => {}, onCancel: () => {} });
+ const before = await corpus.listJobIds();
+ const r = await callPost(POST, {});
+ assert.equal(r.status, 200, JSON.stringify(r.body));
+ assert.equal(r.body.jobId, record.id);
+ assert.equal(r.body.alreadyQueued, true);
+ assert.deepEqual(await corpus.listJobIds(), before);
+ const { startSpaceScanAction } = await import("../../../cleanup/space/actions");
+ const ui = await startSpaceScanAction();
+ assert.equal(ui.ok, false);
+ assert.ok(!ui.ok && ui.info);
+ assert.match(!ui.ok ? ui.error : "", new RegExp(record.id));
+ getRegistry().cancel?.(record.id);
+});
diff --git a/editor/app/api/ops/space-scan/route.ts b/editor/app/api/ops/space-scan/route.ts
@@ -1,5 +1,7 @@
import { SPACE_SCAN_BODY_KEYS } from "yt-dlp-transcript-common/controller/spaceScan";
import { enqueueSpaceScanJob } from "../../../cleanup/space/lib/spaceJob";
+import { NextResponse } from "next/server";
+import { spaceScanJob } from "../../../cleanup/space/lib/loadSpace";
import { jobResponse, ops, optBool } from "../_lib";
export const dynamic = "force-dynamic";
@@ -16,10 +18,14 @@ export const dynamic = "force-dynamic";
// `transcripts/.space-suggestions.json` (`get space-suggestions` reads it).
// It only reads: nothing is removed, moved or fetched. `"compaction": false`
// skips the compaction selector's pass (one ffprobe per saved container not
-// seen unchanged before) and carries the last scan's compaction rows.
+// seen unchanged before) and carries the last scan's compaction rows. While a
+// scan is queued or running nothing more is queued: the answer is that job,
+// `{ok: true, jobId, alreadyQueued: true}`.
export async function POST(request: Request) {
return ops(request, SPACE_SCAN_BODY_KEYS, async (body) => {
const compaction = optBool(body, "compaction");
+ const there = spaceScanJob();
+ if (there) return NextResponse.json({ ok: true, jobId: there.jobId, alreadyQueued: true, status: there.status });
return jobResponse(await enqueueSpaceScanJob(compaction === false ? { compaction: false } : {}));
});
}
diff --git a/editor/app/cleanup/space/lib/spaceJob.ts b/editor/app/cleanup/space/lib/spaceJob.ts
@@ -3,11 +3,19 @@ import { getSettings } from "yt-dlp-transcript-common/lib/settings";
import type { StreamActionResult } from "yt-dlp-transcript-common/jobs/streamCommand";
import { enqueueSpaceScan } from "yt-dlp-transcript-common/controller/spaceScan";
import { safeRevalidate } from "../../../lib/safeRevalidate";
+import { spaceScanJob } from "./loadSpace";
// ONE ENQUEUE OF THE SPACE SCAN, for /cleanup/space's Refresh and the
// `/api/ops/space-scan` adapter. Not in `actions.ts` ("use server": every
// export there is an endpoint), like storage/lib/evictClipsJob.ts.
-export function enqueueSpaceScanJob(opts: { compaction?: boolean } = {}): Promise<StreamActionResult> {
+//
+// ONE AT A TIME, AND NEVER TWICE (review 1, 15): while a scan is queued or
+// running, a second Refresh queues nothing and answers with the one there is.
+export async function enqueueSpaceScanJob(opts: { compaction?: boolean } = {}): Promise<StreamActionResult> {
+ const there = spaceScanJob();
+ if (there) {
+ return { ok: false, info: true, error: `A space scan is already ${there.status} (job ${there.jobId}): its result replaces this page's when it ends.` };
+ }
return enqueueSpaceScan({
paths: getPaths(),
// The settings as they are when the job STARTS (it may have queued).
diff --git a/scripts/archilyzer-ops.mjs b/scripts/archilyzer-ops.mjs
@@ -3519,6 +3519,8 @@ export function usage() {
" transcripts/.space-suggestions.json; get space-suggestions reads it.",
' "compaction": false skips the selector\'s pass (one ffprobe per saved',
" container not seen unchanged before) and keeps the last scan's rows.",
+ " While a scan is queued or running, nothing more is queued: the answer is",
+ " that job ({jobId, alreadyQueued: true}).",
"",
'copies-scan pairs a source group\'s channels video by video: {"group",',
' "dryRun"?} -> {jobId}. The group is settings.sourceGroups\' (an ordered',