commit 790d1a7f059c5cc6626502861010a971abfac5e7
parent 15dd29e11907f698198e20205590c16bbd8b4a96
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 11 Nov 2026 00:27:38 -0500
lanes: the Speakers lane does speakers only, in a chosen order -- autoQueue.<lane>.operations narrows an operation lane to named operations (["diarization"]: no naming pass), and order "space" puts corpus-disk channels first, then the most audio bytes per audio-hour of work
- operations: on the POLICY, read by operationsForLane -- the one place the
runner, the per-channel "Run speaker work", the counts and the deck ask. Not
a leaf's match.operation, which the spec named: while a channel-priority
document exists (this machine has one: 39 tiered channels and a site focus)
the lane's tree is compiled from tiers and the stored leaves are not used, so
a leaf narrowing would silently do nothing. Absent/empty = every enabled
operation, as before; the sanitizer writes the key only when it narrows, and
saveAutoQueueAction carries it like `held` (it lists fields explicitly, and
would have dropped it on every save).
- order "space" (lib/spaceOrder.ts, pure): external = the channel config names
a mediaDir (or the retired dataDir); within a disk class, held audio bytes
(audioFilesToRemove, stat through tier links) over the memoized duration,
descending; unknown rate last; ties stable. Supplied by the runner for the
backfill lane only and offered on its console ("Most space freed first");
elsewhere it is listed, as `cheapest` is. The channel-priority tiers still
win: the comparator orders videos within a leaf, never across tiers. A
per-channel run keeps listed order (one channel, one disk).
- Attribution code is untouched; the rollout sets the narrowing and
attribution.textOnlyEnabled in settings, not in code defaults.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat:
13 files changed, 193 insertions(+), 7 deletions(-)
diff --git a/SETTINGS.md b/SETTINGS.md
@@ -407,6 +407,7 @@ Configuration for the automatic priority-queue runners (auto-transcribe / auto-d
| `order` | transcription `"listed"`<br>download `"listed"`<br>digest `"cheapest"`<br>backfill `"listed"` | Ordering within each rule (see AutoQueueOrder). Optional exactly like replaceAutoSubs: settings files written before this field existed lack it, and the sanitizer defaults them to "listed" (today's behaviour). |
| `snoozeUntil` | `null` | Epoch ms until which this runner idles WITHOUT stopping: next() returns null so the loop stays up, re-reads settings each iteration, and resumes by itself when the moment passes. null/absent/past = not snoozed. Survives a restart because it lives in settings.json, not in runner memory. |
| `held` | transcription `false`<br>download `false`<br>digest `false`<br>backfill `true` | THE LANE'S PAUSE GATE. Shut means the lane holds: every dispatch path asks lib/pauseGates.ts, whose limit()/guard returns 0 so runPool idle-waits. A hold, never a stop — see that file's header.<br><br>OPTIONAL IN THE TYPE, FILLED BY THE SANITIZER. Until slice 1.4 four separate settings fields carried this — `transcriptionsPaused`, `downloadsPaused`, `digest.digestsPaused` and (inverted) `backfill.enabled` — so `undefined` meant "ask the legacy field" and `sanitizePolicy` deliberately refused to default it: a default would have read a paused corpus as running. S0-pause deleted those four, on the precondition that the live settings.json already carried every `held` key, and the default came in with them (`defaultHeldFor` — free everywhere except backfill, whose field was inverted and shipped held).<br><br>It stays optional because a reader may be handed a PARTIAL settings object (laneGuards.test.ts casts one), and `isGateHeld` answers `false` for a lane that carries no key at all rather than throwing. |
+| `operations` | absent | Narrow an OPERATION lane to these operation ids (e.g. ["diarization"] on the backfill lane: speakers only, no naming pass). Absent or empty = every enabled operation on the lane's queue, as before.<br><br>On the POLICY rather than a leaf's `match.operation` because a channel-priority document compiles the lane's tree from its tiers and the stored leaves are not used while one exists; a lane-wide narrowing survives that and narrows the per-channel run, the counts and the runner alike (lib/operations.ts operationsForLane). |
| `root` | object — see below | The lane's rule tree: a group whose children are groups and leaves (see the node table). A missing root is the lane's default — empty for the runner lanes, one catch-all leaf for digest and backfill. While a channel-priority document exists, the four roots are compiled from it and not hand-edited. |
#### `autoQueue.<lane>.root (tree nodes)`
diff --git a/common/controller/autoRunner.ts b/common/controller/autoRunner.ts
@@ -1,4 +1,7 @@
import path from "node:path";
+import { readdir, stat } from "node:fs/promises";
+import { audioFilesToRemove } from "../lib/mediaFiles";
+import { audioBytesPerHour, spaceComparator } from "../lib/spaceOrder";
import type { Paths } from "../lib/paths";
import type { ChannelConfig } from "../lib/channelConfig";
import { mapConcurrent } from "../lib/concurrency";
@@ -862,6 +865,11 @@ async function recencyOrdering(
if (order === "cheapest" && kind !== "digest") {
return { compare: null, keys: new Map() };
}
+ // `space` is the Speakers lane's: its candidates all hold audio and have a
+ // transcript, so each can be weighed. Elsewhere it is listed, as above.
+ if (order === "space" && kind !== "backfill") {
+ return { compare: null, keys: new Map() };
+ }
// Candidates AND their owning channel, derived in one pass from the same
// projection buildPendingByLeaf claims from — first-writer-wins, exactly as
// buildChannelWork builds its own owner map, so the two cannot disagree.
@@ -890,6 +898,21 @@ async function recencyOrdering(
// would be pure cost.
interpolate: kind === "download",
});
+ if (order === "space") {
+ // Corpus disk = the channel names no `mediaDir` (and no retired
+ // whole-dir `dataDir`); the rest live on another drive.
+ const external = new Set(
+ meta.filter((m) => !!m.config?.mediaDir || !!m.config?.dataDir).map((m) => m.slug),
+ );
+ const rates = await loadAudioRates(paths, owner, candidateIds);
+ return {
+ compare: spaceComparator({
+ external: (id) => external.has(owner.get(id) ?? ""),
+ bytesPerHour: (id) => rates.get(id) ?? null,
+ }),
+ keys,
+ };
+ }
if (order !== "cheapest") {
return { compare: makeRecencyComparator(keys, order), keys };
}
@@ -944,6 +967,34 @@ async function loadDurations(
const DURATION_READ_CONCURRENCY = 64;
+// Bytes of held audio per audio-hour, per candidate, for the `space` order. The
+// audio is what clean audio would remove (audioFilesToRemove), sized through
+// tier links; the duration is the memoized one `cheapest` uses. Read per tick
+// like the durations, at the same concurrency: a readdir and a stat or two per
+// candidate, and the Speakers lane's candidates are the videos still holding
+// audio (thousands, not the corpus).
+async function loadAudioRates(
+ paths: Paths,
+ owner: ReadonlyMap<string, string>,
+ candidateIds: ReadonlySet<string>,
+): Promise<Map<string, number | null>> {
+ const ids = [...candidateIds];
+ const rates = await mapConcurrent(ids, DURATION_READ_CONCURRENCY, async (id) => {
+ const slug = owner.get(id);
+ if (!slug) return null;
+ const dir = path.join(paths.channelsDir, slug, "data", id);
+ const entries = await readdir(dir).catch(() => [] as string[]);
+ let bytes = 0;
+ for (const name of audioFilesToRemove(entries)) {
+ bytes += await stat(path.join(dir, name)).then((st) => st.size, () => 0);
+ }
+ return audioBytesPerHour(bytes, await videoDurationSeconds(paths, slug, id));
+ });
+ const out = new Map<string, number | null>();
+ ids.forEach((id, i) => out.set(id, rates[i]));
+ return out;
+}
+
// How many drill-down ids the status payload carries per rule. Enough to see
// whether an ordering change did what you asked; small enough that a 9,000-video
// catch-all doesn't ship 9,000 strings on a 3-second poll.
diff --git a/common/controller/operationBatch.ts b/common/controller/operationBatch.ts
@@ -2000,6 +2000,9 @@ export async function runOperationBatch(
function laneOrderFor(run: OperationRun): AutoQueueOrder {
const order = run.settings.autoQueue[run.digest ? "digest" : "backfill"].order;
if (order === "cheapest") return run.digest ? "newest" : "listed";
+ // "space" orders ACROSS channels (corpus disk first); one channel's run has
+ // one disk, so it keeps the listed order.
+ if (order === "space") return "listed";
return order ?? "listed";
}
diff --git a/common/controller/recencyIndex.ts b/common/controller/recencyIndex.ts
@@ -569,7 +569,7 @@ export function makeRecencyComparator(
keys: ReadonlyMap<string, RecencyKey>,
order: AutoQueueOrder,
): ((a: string, b: string) => number) | null {
- if (order === "listed" || order === "cheapest") return null;
+ if (order === "listed" || order === "cheapest" || order === "space") return null;
// Keys are YYYYMMDD strings, so lexicographic order IS chronological order.
// "newest" therefore sorts DESCENDING: a smaller (older) key must come later,
// which is a positive comparator result.
diff --git a/common/jobs/autoQueuePolicy.test.ts b/common/jobs/autoQueuePolicy.test.ts
@@ -1440,3 +1440,14 @@ test("bucketIdsFrom knows undownloadedIds is a TOP-LEVEL field", () => {
assert.deepEqual([...bucketIdsFrom({}, "partialDownloads")], []);
assert.deepEqual([...bucketIdsFrom({}, "undownloadedIds")], []);
});
+
+test("sanitize: order \"space\" is kept; a lane's `operations` narrowing is kept, deduped and trimmed, and absent when empty", () => {
+ const s = sanitizeAutoQueue({
+ backfill: { enabled: true, order: "space", operations: [" diarization ", "diarization", 3, ""] },
+ digest: { enabled: true, operations: [] },
+ });
+ assert.equal(s.backfill.order, "space");
+ assert.deepEqual(s.backfill.operations, ["diarization"]);
+ assert.equal("operations" in s.digest, false);
+ assert.equal("operations" in s.transcription, false);
+});
diff --git a/common/lib/autoQueueSchema.ts b/common/lib/autoQueueSchema.ts
@@ -48,6 +48,7 @@ export const AUTO_QUEUE_ORDERS: ReadonlyArray<AutoQueueOrder> = [
"newest",
"oldest",
"cheapest",
+ "space",
];
@@ -58,7 +59,10 @@ export const AUTO_QUEUE_ORDERS: ReadonlyArray<AutoQueueOrder> = [
// slice 1.3 folded digest.recencyOrder and backfill.order into them — and copies
// of this line would eventually disagree about what an absent field means.
export function sanitizeAutoQueueOrder(value: unknown): AutoQueueOrder {
- return value === "newest" || value === "oldest" || value === "cheapest"
+ return value === "newest" ||
+ value === "oldest" ||
+ value === "cheapest" ||
+ value === "space"
? value
: "listed";
}
@@ -267,6 +271,9 @@ function sanitizePolicy(value: unknown, lane: AutoQueueKind): AutoQueuePolicy {
// reading those fields gave a file that named no gate — free everywhere
// except backfill, whose field was inverted and defaulted to held.
held: typeof r.held === "boolean" ? r.held : defaultHeldFor(lane),
+ // Written only when it narrows: an absent key is every policy on disk
+ // today, and a default that wrote `[]` would change their bytes for nothing.
+ ...sanitizeLaneOperations(r.operations),
root:
r.root === undefined
? defaultRootFor(lane)
@@ -274,6 +281,19 @@ function sanitizePolicy(value: unknown, lane: AutoQueueKind): AutoQueuePolicy {
};
}
+function sanitizeLaneOperations(value: unknown): { operations?: string[] } {
+ if (!Array.isArray(value)) return {};
+ const ids = [
+ ...new Set(
+ value
+ .filter((v): v is string => typeof v === "string")
+ .map((v) => v.trim())
+ .filter(Boolean),
+ ),
+ ];
+ return ids.length > 0 ? { operations: ids } : {};
+}
+
export function sanitizeAutoQueue(value: unknown): AutoQueueSettings {
if (!value || typeof value !== "object") return defaultAutoQueue();
const r = value as Record<string, unknown>;
diff --git a/common/lib/autoQueueTypes.ts b/common/lib/autoQueueTypes.ts
@@ -33,7 +33,12 @@ export type AutoQueueMatchType = "channel" | "platform" | "all";
// SUPPLIED BY THE RUNNER (the engine never reads a duration off disk). A lane
// whose runner supplies no comparator for it falls back to today's order —
// which is what makes it safe to name here before anything computes it.
-export type AutoQueueOrder = "listed" | "newest" | "oldest" | "cheapest";
+//
+// "space" is the Speakers lane's free-the-disk order: channels whose media is
+// on the corpus disk (no `mediaDir`) first, then the videos holding the most
+// audio bytes per audio-hour of work — the space each hour of CPU frees.
+// Supplied by the runner for the backfill lane only; elsewhere it is "listed".
+export type AutoQueueOrder = "listed" | "newest" | "oldest" | "cheapest" | "space";
// Each field is documented in AUTO_QUEUE_MATCH_FIELD_DOCS below (rendered into SETTINGS.md).
export type AutoQueueMatch = {
@@ -128,6 +133,7 @@ export type AutoQueuePolicy = {
order?: AutoQueueOrder;
snoozeUntil?: number | null;
held?: boolean;
+ operations?: string[];
root: AutoQueueGroup;
};
@@ -176,6 +182,15 @@ export const AUTO_QUEUE_POLICY_FIELD_DOCS: FieldDocs<AutoQueuePolicy> = {
"It stays optional because a reader may be handed a PARTIAL settings " +
"object (laneGuards.test.ts casts one), and `isGateHeld` answers " +
"`false` for a lane that carries no key at all rather than throwing.",
+ operations:
+ "Narrow an OPERATION lane to these operation ids (e.g. [\"diarization\"] " +
+ "on the backfill lane: speakers only, no naming pass). Absent or empty = " +
+ "every enabled operation on the lane's queue, as before.\n\n" +
+ "On the POLICY rather than a leaf's `match.operation` because a channel-" +
+ "priority document compiles the lane's tree from its tiers and the stored " +
+ "leaves are not used while one exists; a lane-wide narrowing survives that " +
+ "and narrows the per-channel run, the counts and the runner alike " +
+ "(lib/operations.ts operationsForLane).",
root:
"The lane's rule tree: a group whose children are groups and leaves (see the node table). A missing root is the lane's default — empty for the runner lanes, one catch-all leaf for digest and backfill. While a channel-priority document exists, the four roots are compiled from it and not hand-edited.",
};
diff --git a/common/lib/operations.test.ts b/common/lib/operations.test.ts
@@ -1745,3 +1745,19 @@ test("operationsForLane: digest stays on the digest lane on BOTH its queues", ()
// And the backfill lane never picks it up on either engine.
assert.deepEqual(operationsForLane("backfill", remote).map((o) => o.id), []);
});
+
+test("operationsForLane: autoQueue.backfill.operations narrows the lane — speakers only — and absent is everything", () => {
+ const s = settingsWithBackfillLane();
+ const all = operationsForLane("backfill", s).map((k) => k.id);
+ assert.ok(all.length > 1 && all.includes("diarization"));
+ const narrowed = {
+ ...s,
+ autoQueue: {
+ ...s.autoQueue,
+ backfill: { ...s.autoQueue.backfill, operations: ["diarization"] },
+ },
+ };
+ assert.deepEqual(operationsForLane("backfill", narrowed).map((k) => k.id), ["diarization"]);
+ const empty = { ...s, autoQueue: { ...s.autoQueue, backfill: { ...s.autoQueue.backfill, operations: [] } } };
+ assert.deepEqual(operationsForLane("backfill", empty).map((k) => k.id), all);
+});
diff --git a/common/lib/operations.ts b/common/lib/operations.ts
@@ -1755,9 +1755,15 @@ export function operationsForLane(
? [BACKFILL_QUEUE]
: [];
if (keys.length === 0) return [];
+ // The lane-wide narrowing (autoQueue.<lane>.operations): the one place every
+ // dispatch path, count and per-channel run asks, so "speakers only" is one
+ // setting rather than a leaf the channel-priority compiler would discard.
+ const only = settings.autoQueue?.[lane]?.operations;
return orderByDependencies(
- allOperations(settings).filter((op) =>
- keys.includes((op.laneFor?.(settings) ?? op.lane).queueKey),
+ allOperations(settings).filter(
+ (op) =>
+ keys.includes((op.laneFor?.(settings) ?? op.lane).queueKey) &&
+ (!only || only.length === 0 || only.includes(op.id)),
),
);
}
diff --git a/common/lib/spaceOrder.test.ts b/common/lib/spaceOrder.test.ts
@@ -0,0 +1,17 @@
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import { audioBytesPerHour, spaceComparator } from "./spaceOrder";
+
+test("space order: corpus-disk channels first, then the most bytes freed per audio-hour; unknown last; ties stable", () => {
+ const external = new Set(["x1", "x2"]);
+ const rate: Record<string, number | null> = { a: 10, b: 50, c: null, d: 50, x1: 900, x2: null };
+ const cmp = spaceComparator({ external: (id) => external.has(id), bytesPerHour: (id) => rate[id] ?? null });
+ assert.deepEqual(["c", "x1", "a", "b", "x2", "d"].sort(cmp), ["b", "d", "a", "c", "x1", "x2"]);
+});
+
+test("audioBytesPerHour: bytes over hours; nothing to say without both", () => {
+ assert.equal(audioBytesPerHour(3_600_000, 1800), 7_200_000);
+ assert.equal(audioBytesPerHour(0, 1800), null);
+ assert.equal(audioBytesPerHour(100, null), null);
+ assert.equal(audioBytesPerHour(100, 0), null);
+});
diff --git a/common/lib/spaceOrder.ts b/common/lib/spaceOrder.ts
@@ -0,0 +1,38 @@
+// The Speakers lane's "space" order (AutoQueueOrder): which video to capture
+// next so the disk frees fastest.
+//
+// Two keys, in this order:
+// 1. a channel whose media is on the CORPUS disk (no `mediaDir`) before one
+// whose media lives on another drive — the operator's ruling: internal
+// disk first, because that is the disk that fills;
+// 2. bytes of held audio per audio-hour, descending — the space one hour of
+// diarization CPU frees (the CPU cost is ~proportional to duration, the
+// space to the file's size).
+// A video whose rate is unknown (no duration on disk) sorts after every known
+// one within its disk class. Equal keys compare 0, so the sort is stable and
+// keeps the listed order between them.
+//
+// Pure: the runner (controller/autoRunner.ts recencyOrdering) supplies the two
+// lookups; nothing here touches the disk.
+
+export function audioBytesPerHour(bytes: number, seconds: number | null): number | null {
+ if (!(bytes > 0) || seconds === null || !(seconds > 0)) return null;
+ return bytes / (seconds / 3600);
+}
+
+export function spaceComparator(look: {
+ external: (id: string) => boolean;
+ bytesPerHour: (id: string) => number | null;
+}): (a: string, b: string) => number {
+ return (a, b) => {
+ const ea = look.external(a) ? 1 : 0;
+ const eb = look.external(b) ? 1 : 0;
+ if (ea !== eb) return ea - eb;
+ const ra = look.bytesPerHour(a);
+ const rb = look.bytesPerHour(b);
+ if (ra === rb) return 0;
+ if (ra === null) return 1;
+ if (rb === null) return -1;
+ return rb - ra;
+ };
+}
diff --git a/editor/app/operations/actions.ts b/editor/app/operations/actions.ts
@@ -105,6 +105,11 @@ export async function saveAutoQueueAction(
order: input.order,
snoozeUntil: current.autoQueue[kind].snoozeUntil ?? null,
held: current.autoQueue[kind].held,
+ // The lane-wide operation narrowing is set in settings (ops settings),
+ // not by this form: carried like `held`, never dropped by a save.
+ ...(current.autoQueue[kind].operations
+ ? { operations: current.autoQueue[kind].operations }
+ : {}),
root: compiled ? current.autoQueue[kind].root : input.root,
},
},
diff --git a/editor/app/operations/components/dispatch.ts b/editor/app/operations/components/dispatch.ts
@@ -76,6 +76,9 @@ export const ORDER_LABEL: Record<AutoQueueOrder, string> = {
// The digest lane's shortest-first. Named by DURATION, not by date, which is
// why it is not a third arm of the recency axis.
cheapest: "Shortest first",
+ // The Speakers lane's: corpus-disk channels first, then the most audio freed
+ // per hour of work.
+ space: "Most space freed first",
};
// THE ORDERS A DATE-KEYED LANE OFFERS — the three this control has always
@@ -104,7 +107,7 @@ export const LANE_ORDERS: Record<
transcription: RECENCY_ORDERS,
download: RECENCY_ORDERS,
digest: [...RECENCY_ORDERS, "cheapest"],
- backfill: RECENCY_ORDERS,
+ backfill: [...RECENCY_ORDERS, "space"],
};
// The runner console's heading, per lane. PINNED: the e2e suite scopes whole
@@ -123,7 +126,7 @@ export function orderTradeoff(
): string | null {
// Neither of these reorders by upload date, so neither costs a retry or a
// partial download its head start.
- if (order === "listed" || order === "cheapest") return null;
+ if (order === "listed" || order === "cheapest" || order === "space") return null;
// The trade-off named below is a DOWNLOAD/TRANSCRIPTION one — a retry or a
// partial losing its head start. The operation lanes have no retry bucket and
// no partial state to lose, so there is nothing to warn about.