commit b1c52521f92ebd1230a0af86866c13daca7f8a06
parent 8a6742adc2d2ff8aeaeda178bca13b3e01302aca
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 18 Nov 2026 15:39:09 -0500
review 1 S10: the scheduler does not queue an Instagram channel its fetch would refuse, and the schedule view says why
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
7 files changed, 133 insertions(+), 2 deletions(-)
diff --git a/common/jobs/instagramGuard.ts b/common/jobs/instagramGuard.ts
@@ -80,3 +80,11 @@ export async function instagramJobGuard(opts: {
if (ms > 0) return { ok: false, message: instagramCooldownSentence(ms, now), alert: false };
return { ok: true };
}
+
+// Why no Instagram job starts now, as a sentence, or null — for the scheduler,
+// which skips every Instagram channel with it rather than queue a fetch the
+// guard would refuse.
+export async function instagramHeldReason(paths: Paths, now: number = Date.now()): Promise<string | null> {
+ const g = await instagramJobGuard({ paths, now });
+ return g.ok ? null : g.message;
+}
diff --git a/common/jobs/instagramSchedule.test.ts b/common/jobs/instagramSchedule.test.ts
@@ -0,0 +1,58 @@
+// The scheduler does not queue an Instagram channel its fetch would refuse
+// (review 1, S10): no cookie source of its own, or Instagram held by its
+// alert or its cooldown. Such a channel takes no sync slot, and the schedule
+// view says why.
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import type { ChannelConfig } from "../lib/channelConfig";
+import { defaultSyncScheduler } from "../lib/settings";
+import { defaultChannelPriority } from "../lib/channelPriority";
+import { emptySchedulerState } from "./syncSchedulerState";
+import { buildScheduleView, INSTAGRAM_SYNC_NO_COOKIES, instagramSyncHold, selectDueChannels } from "./syncScheduler";
+
+const NOW = Date.parse("2026-03-10T12:00:00Z");
+const scheduler = { ...defaultSyncScheduler(), enabled: true, defaultIntervalMinutes: 60, quietHoursStart: null, quietHoursEnd: null };
+const ig = (cookies?: string): ChannelConfig =>
+ ({ handling: "transcribe", sourceKind: "social", platform: "instagram", url: "https://www.instagram.com/example.account/", ...(cookies ? { cookiesFromBrowser: cookies } : {}) }) as ChannelConfig;
+const x: ChannelConfig = { handling: "transcribe", sourceKind: "social", platform: "twitter", url: "https://x.com/example" } as ChannelConfig;
+const channels = [
+ { slug: "ig-bare", config: ig() },
+ { slug: "ig-ready", config: ig("firefox:ig-profile") },
+ { slug: "x-chan", config: x },
+];
+const base = { channels, scheduler, state: emptySchedulerState(), activeSlugs: new Set<string>(), now: NOW, priority: defaultChannelPriority() };
+const HELD = "Instagram answered a rate limit a short while ago: no Instagram job starts before 13:00 UTC (60 min from now). Ask again then; nothing retries by itself.";
+
+test("an Instagram channel with no cookie source is never due; one with a source is, like any never-synced channel", () => {
+ const r = selectDueChannels(base);
+ assert.deepEqual([...r.due].sort(), ["ig-ready", "x-chan"]);
+ // Configuration, not a hold: no line in the run log each tick.
+ assert.deepEqual(r.skipped, []);
+});
+
+test("while Instagram is held every Instagram channel is skipped with the sentence, and takes no slot; X is not Instagram's business", () => {
+ const r = selectDueChannels({ ...base, instagramHeld: HELD });
+ assert.deepEqual(r.due, ["x-chan"]);
+ assert.deepEqual(r.skipped, [{ slug: "ig-ready", reason: HELD }]);
+});
+
+test("the schedule view agrees: not eligible, with the reason", () => {
+ const view = buildScheduleView({ ...base, instagramHeld: HELD });
+ const of = (slug: string) => view.find((v) => v.slug === slug)!;
+ assert.deepEqual([of("ig-bare").autoSyncEligible, of("ig-bare").heldReason], [false, INSTAGRAM_SYNC_NO_COOKIES]);
+ assert.deepEqual([of("ig-ready").autoSyncEligible, of("ig-ready").heldReason], [false, HELD]);
+ assert.deepEqual([of("x-chan").autoSyncEligible, of("x-chan").heldReason], [true, undefined]);
+ const free = buildScheduleView(base);
+ assert.equal(free.find((v) => v.slug === "ig-ready")!.autoSyncEligible, true);
+ assert.equal(free.find((v) => v.slug === "ig-ready")!.heldReason, undefined);
+});
+
+test("the one predicate", () => {
+ assert.equal(instagramSyncHold(x, HELD), null);
+ assert.equal(instagramSyncHold(ig(), null), INSTAGRAM_SYNC_NO_COOKIES);
+ assert.equal(instagramSyncHold(ig(" "), null), INSTAGRAM_SYNC_NO_COOKIES);
+ assert.equal(instagramSyncHold(ig("file:/x"), null), null);
+ assert.equal(instagramSyncHold(ig("file:/x"), HELD), HELD);
+ // A video channel that names the platform is not an Instagram posts channel.
+ assert.equal(instagramSyncHold({ platform: "instagram" } as ChannelConfig, HELD), null);
+});
diff --git a/common/jobs/syncScheduler.ts b/common/jobs/syncScheduler.ts
@@ -47,8 +47,34 @@ export type SelectDueInput = {
// sync, so it is the same on every tick until the next sync. Absent = 0, the
// exact interval (this module reads no settings; the tick passes it).
jitter?: number;
+ // WHY NO INSTAGRAM JOB STARTS NOW, when none does: Instagram's alert is up,
+ // or it is cooling down after a rate limit (jobs/instagramGuard.ts — I/O,
+ // so the tick asks and hands the sentence in). Every Instagram channel is
+ // then skipped with it, and takes no sync slot.
+ instagramHeld?: string | null;
};
+// WHY AN INSTAGRAM CHANNEL IS NOT SYNCED NOW, or null (review 1, S10). A
+// channel with no cookie source of its own would be refused by its fetch
+// before anything is asked; one while Instagram is held, by the guard. Either
+// way the scheduler does not queue it — a refusal each tick is a failed job
+// and a sync slot spent on nothing.
+export const INSTAGRAM_SYNC_NO_COOKIES =
+ "Instagram: no cookie source of its own (set Cookies from browser on the channel's Edit form)";
+
+export function isInstagramPostsConfig(config: Pick<ChannelConfig, "sourceKind" | "platform">): boolean {
+ return config.sourceKind === "social" && config.platform === "instagram";
+}
+
+export function instagramSyncHold(
+ config: Pick<ChannelConfig, "sourceKind" | "platform" | "cookiesFromBrowser">,
+ held: string | null | undefined,
+): string | null {
+ if (!isInstagramPostsConfig(config)) return null;
+ if (!config.cookiesFromBrowser?.trim()) return INSTAGRAM_SYNC_NO_COOKIES;
+ return held ? held : null;
+}
+
// The most a channel's sync is pushed back by the jitter, whatever its
// interval: a share of a 24 h interval would otherwise be hours.
export const SYNC_JITTER_CAP_MS = 30 * 60_000;
@@ -78,7 +104,7 @@ export function resolveIntervalMinutes(
config: ChannelConfig,
scheduler: SyncSchedulerSettings,
): number {
- const instagram = config.sourceKind === "social" && config.platform === "instagram";
+ const instagram = isInstagramPostsConfig(config);
if (config.syncIntervalMinutes === undefined) {
const inherited = scheduler.defaultIntervalMinutes;
return instagram && inherited > 0 ? Math.max(inherited, INSTAGRAM_DEFAULT_SYNC_MINUTES) : inherited;
@@ -167,6 +193,16 @@ export function selectDueChannels(input: SelectDueInput): SelectDueResult {
const interval = resolveIntervalMinutes(config, scheduler);
if (interval <= 0) continue; // per-channel disabled
+ // An Instagram channel that would be refused anyway is not queued: with
+ // no cookie source it is configuration (silent, like a paused channel —
+ // the schedule view says why); while Instagram is held it is a hold worth
+ // a line.
+ const igHold = instagramSyncHold(config, input.instagramHeld);
+ if (igHold) {
+ if (igHold !== INSTAGRAM_SYNC_NO_COOKIES) skipped.push({ slug, reason: igHold });
+ continue;
+ }
+
if (activeSlugs.has(slug)) {
skipped.push({ slug, reason: "already running" });
continue;
@@ -229,6 +265,10 @@ export type ChannelScheduleView = {
// on, so the sync console can never show a channel as eligible that the
// scheduler will not schedule.
autoSyncEligible: boolean;
+ // Why the scheduler does not sync this channel now though its settings
+ // would have it synced (an Instagram channel with no cookie source, or while
+ // Instagram is held). `autoSyncEligible` is false with it.
+ heldReason?: string;
intervalMinutes: number; // resolved; 0 = disabled
inheritsInterval: boolean; // using the global default vs a per-channel value
// The raw per-channel value as stored in config (undefined = inherit global,
@@ -266,9 +306,12 @@ export function buildScheduleView(input: {
// The scheduler's jitter (SelectDueInput.jitter), so the next-due time shown
// is the one selectDueChannels will act on.
jitter?: number;
+ // SelectDueInput.instagramHeld: the same sentence, for the same skip.
+ instagramHeld?: string | null;
}): ChannelScheduleView[] {
const { channels, scheduler, state, now, priority } = input;
return channels.map(({ slug, config }) => {
+ const igHold = instagramSyncHold(config, input.instagramHeld);
const interval = resolveIntervalMinutes(config, scheduler);
const sweepInterval = resolveFullSweepIntervalMinutes(config, scheduler);
const cs = state.channels[slug];
@@ -298,7 +341,9 @@ export function buildScheduleView(input: {
!!config.url &&
!isRemoteOnlyChannel(config) &&
!isChannelPaused(priority, slug, "sync") &&
- interval > 0,
+ interval > 0 &&
+ !igHold,
+ ...(igHold ? { heldReason: igHold } : {}),
intervalMinutes: interval,
inheritsInterval: config.syncIntervalMinutes === undefined,
configuredIntervalMinutes: config.syncIntervalMinutes,
diff --git a/common/views/schedulerStatus.ts b/common/views/schedulerStatus.ts
@@ -43,6 +43,9 @@ export type SchedulerStatusInputs = {
// Resolved by the shell: it reads the env override and imports the heartbeat
// module, which owns a RUNNER. A view never names a runner.
heartbeatSeconds: number;
+ // Why no Instagram job starts now, when none does (the shell asks the
+ // guard: jobs/instagramGuard.ts).
+ instagramHeld?: string | null;
};
export function buildSchedulerStatusPayload(
@@ -56,6 +59,7 @@ export function buildSchedulerStatusPayload(
now,
priority: settings.channelPriority,
jitter: settings.pacing?.jitter ?? 0,
+ ...(inputs.instagramHeld ? { instagramHeld: inputs.instagramHeld } : {}),
});
return {
now,
diff --git a/editor/app/operations/components/sync/SyncConsole.tsx b/editor/app/operations/components/sync/SyncConsole.tsx
@@ -282,6 +282,14 @@ export function SyncConsole({
type ChannelRow = SchedulerStatusPayload["channels"][number];
function statusBadge(c: ChannelRow) {
+ // Not scheduled though its settings would have it synced: say why.
+ if (c.heldReason) {
+ return (
+ <span className="text-warning" title={c.heldReason}>
+ held: {c.heldReason}
+ </span>
+ );
+ }
if (c.intervalMinutes === 0 || !c.autoSyncEligible) {
return <span className="text-muted-foreground">—</span>;
}
diff --git a/editor/app/scheduler/runTick.ts b/editor/app/scheduler/runTick.ts
@@ -4,6 +4,7 @@
// instrumentation.ts, both /api/scheduler/* routes, the operations rail's sync
// row and two forms import from it.
import { getPaths } from "yt-dlp-transcript-common/lib/paths";
+import { instagramHeldReason } from "yt-dlp-transcript-common/jobs/instagramGuard";
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";
@@ -13,6 +14,7 @@ import {
isInQuietHours,
nextEligibleAfterFailure,
selectDueChannels,
+ isInstagramPostsConfig,
type ChannelEntry,
} from "yt-dlp-transcript-common/jobs/syncScheduler";
import {
@@ -137,6 +139,8 @@ export async function runSchedulerTick(): Promise<SchedulerTickResult> {
priority,
// Each channel due up to pacing.jitter of its interval later (≤ 30 min).
jitter: pacingJitter(),
+ // Instagram's alert or cooldown: its channels take no slot while it is up.
+ instagramHeld: channels.some((c) => isInstagramPostsConfig(c.config)) ? await instagramHeldReason(paths) : null,
focusSlugs: resolveFocusSlugs(
priority,
siteChannels,
diff --git a/editor/app/scheduler/status.ts b/editor/app/scheduler/status.ts
@@ -6,6 +6,8 @@ import {
type SchedulerStatusPayload,
} from "yt-dlp-transcript-common/views/schedulerStatus";
import { readSchedulerState } from "yt-dlp-transcript-common/jobs/syncSchedulerState";
+import { instagramHeldReason } from "yt-dlp-transcript-common/jobs/instagramGuard";
+import { isInstagramPostsConfig } from "yt-dlp-transcript-common/jobs/syncScheduler";
import { resolveHeartbeatSeconds } from "./heartbeat";
// THE SHELL. The payload is `common/views/schedulerStatus.ts`; this reads the
@@ -26,5 +28,7 @@ export async function buildSchedulerStatusPayload(): Promise<SchedulerStatusPayl
state,
channels,
heartbeatSeconds: resolveHeartbeatSeconds(),
+ // Asked only when there is an Instagram channel to say it about.
+ instagramHeld: channels.some((c) => isInstagramPostsConfig(c.config)) ? await instagramHeldReason(paths) : null,
});
}