commit 217234fae69f8128152e09efd5a8714dc86976ac
parent 538420dddcc1ea73a26699ed362d71fd4d8ae736
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Thu, 19 Nov 2026 00:07:10 -0500
scheduler: review 4 D -- an X job running with no start recorded yet takes the cap's room, as a queued one does
xJobsWaiting counts every job queued on X's queue and every one running
there that has not recorded a start (waiting out X's gap before its guard).
The tick uses it for limitXSyncs.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
3 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/common/jobs/syncScheduler.test.ts b/common/jobs/syncScheduler.test.ts
@@ -350,3 +350,22 @@ test("review 3 N9: no more X syncs are queued than the cap has starts left; the
assert.deepEqual(limitXSyncs(due, isX, { room: 12, waiting: 2 }).queue, due);
assert.deepEqual(limitXSyncs(due, isX, { room: 12, waiting: 2 }).held, []);
});
+
+// Review 4 D: a running X job whose start is not counted yet (waiting out
+// X's gap before its guard) takes the cap's room as surely as a queued one.
+test("review 4 D: X jobs waiting are the queued ones and the running ones that have not recorded a start", async () => {
+ const { xJobsWaiting } = await import("./syncScheduler");
+ const X = "platform:twitter";
+ assert.equal(
+ xJobsWaiting([
+ { status: "queued", queueKey: X },
+ { status: "running", queueKey: X },
+ { status: "running", queueKey: X, xStarts: [] },
+ { status: "running", queueKey: X, xStarts: [1] },
+ { status: "done", queueKey: X },
+ { status: "queued", queueKey: "platform:youtube" },
+ { status: "running", queueKey: "platform:youtube" },
+ ]),
+ 3,
+ );
+});
diff --git a/common/jobs/syncScheduler.ts b/common/jobs/syncScheduler.ts
@@ -1,6 +1,7 @@
import { isInstagramPostsChannelConfig } from "../lib/instagram/channel";
import { isRemoteOnlyChannel, type ChannelConfig } from "../lib/channelConfig";
import { detectPlatform } from "../lib/platform";
+import { X_QUEUE_KEY } from "../lib/xJobRule";
import type { SyncSchedulerSettings } from "../lib/settings";
import {
type ChannelPriority,
@@ -74,9 +75,20 @@ export function xSyncHold(
// left in the hour, queueing every due X channel would start one and defer
// the rest at their start — a job each for nothing. `room`: the starts the
// cap has left now (jobs/networkGuard.ts xCapRoom, a look: nothing counted);
-// `waiting`: X jobs already queued on X's queue, which take that room first.
+// `waiting`: X jobs already waiting on X's queue (xJobsWaiting), which take that room first.
// The X channels past it are held for a later tick; every other channel is
// queued as it was.
+// THE X JOBS THAT WILL TAKE THE CAP'S ROOM BEFORE A SYNC QUEUED NOW (review 4
+// D): every one queued on X's queue, and every one running there that has not
+// recorded a start yet (waiting out X's gap before its guard counts it). A
+// running job that counts nothing is taken for one that will — more rather
+// than fewer: a sync held a tick, never one deferred at its start.
+export function xJobsWaiting(records: ReadonlyArray<{ status: string; queueKey: string; xStarts?: readonly number[] }>): number {
+ return records.filter(
+ (r) => r.queueKey === X_QUEUE_KEY && (r.status === "queued" || (r.status === "running" && !(r.xStarts?.length))),
+ ).length;
+}
+
export function limitXSyncs(
toQueue: readonly string[],
isX: (slug: string) => boolean,
diff --git a/editor/app/scheduler/runTick.ts b/editor/app/scheduler/runTick.ts
@@ -6,7 +6,6 @@
import { getPaths } from "yt-dlp-transcript-common/lib/paths";
import { instagramHeldReason } from "yt-dlp-transcript-common/jobs/instagramGuard";
import { xCapHeldReason, xCapRoom } from "yt-dlp-transcript-common/jobs/networkGuard";
-import { X_QUEUE_KEY } from "yt-dlp-transcript-common/lib/xJobRule";
import { listChannelConfigs } from "yt-dlp-transcript-common/controller/channels";
import { getSettings } from "yt-dlp-transcript-common/lib/settings";
import { getRegistry } from "yt-dlp-transcript-common/jobs/registry";
@@ -18,6 +17,7 @@ import {
selectDueChannels,
isInstagramPostsConfig,
limitXSyncs,
+ xJobsWaiting,
xSyncHold,
type ChannelEntry,
} from "yt-dlp-transcript-common/jobs/syncScheduler";
@@ -168,9 +168,8 @@ export async function runSchedulerTick(): Promise<SchedulerTickResult> {
return config ? xSyncHold(config, "x") !== null : false;
};
if (toQueue.some(isXSync)) {
- const waiting = getRegistry()
- .list()
- .filter((r) => r.status === "queued" && r.queueKey === X_QUEUE_KEY).length;
+ // Queued on X's queue, or running there with no start counted yet (review 4 D).
+ const waiting = xJobsWaiting(getRegistry().list());
const limited = limitXSyncs(toQueue, isXSync, { room: await xCapRoom(paths), waiting });
toQueue = limited.queue;
skipped.push(...limited.held);