Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 657a8282227916d581c5cb45a0ddacdc807ae98e
parent 07b88ae910e4f646ea2c710b6f1c7cce9408734f
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 18 Nov 2026 21:58:51 -0500

x: review 2 S5 -- an X channel's jobs that ask x.com nothing pass off X's queue; the ones that ask it are X's and are queued on X's queue

One predicate decides which network jobs ask x.com (lib/xJobRule.ts
xJobAsksX), read by the network guard from the job's kind, queue, channel and
spec:
- X's queue, or X's old clip queue: X's, whatever the kind.
- An import of one URL (import-one) asks that URL's host: an x.com URL is
  X's in any channel, an archive.org one into an X channel is not.
- An X channel's job is X's unless its work asks no platform:
  transcribe-one (the transcription worker -- it was refused on its own
  queue, and so was every whisper-video's hand-off to it), windows cut from
  the saved copy (`clips:saved-video`), import-media of a local file, and
  import-archive-org. These pass off X's queue; a job that is not X's is
  never taken for X's by its channel. transcribe-one does not count against
  X's job cap even on X's queue.
Moved onto X's queue (they ask x.com, so they were refused everywhere else):
X clip windows (clipWindowQueueKey: X's is platform:twitter -- a batch of X
windows with no single channel no longer passes the guard on clips:twitter),
import-media of an x.com URL, import-one of an x.com URL into any channel,
and an X channel's check-kept-deleted. Left refused off X's queue, named:
record-live of an X channel (a live recording would hold X's queue for
hours) and redownload-incomplete-bucket (the transcription queue).

Co-Authored-By: Claude <noreply@anthropic.com>

Diffstat:
Mcommon/controller/importMedia.ts | 5++++-
Mcommon/jobs/networkGuard.ts | 31++++++++++++++++++++-----------
Mcommon/jobs/pacingGuard.test.ts | 41+++++++++++++++++++++++++++++++++++++++++
Mcommon/lib/queueKeys.ts | 5+++++
Mcommon/lib/xJobRule.test.ts | 38+++++++++++++++++++++++++++++++++++++-
Mcommon/lib/xJobRule.ts | 40++++++++++++++++++++++++++++++++++++++++
Meditor/app/channels/[slug]/pipelineActions.ts | 3++-
Meditor/app/channels/[slug]/whisperActions.ts | 8+++++++-
8 files changed, 156 insertions(+), 15 deletions(-)

diff --git a/common/controller/importMedia.ts b/common/controller/importMedia.ts @@ -64,6 +64,8 @@ import { } from "./landMedia"; import { refreshVideoMetadata, type RefreshRunner } from "./refreshVideoMetadata"; +import { X_QUEUE_KEY } from "../lib/xJobRule"; + export const IMPORT_MEDIA_JOB_KIND = "import-media"; export const IMPORT_MEDIA_RESULT_MARKER = "@@import-media "; @@ -329,7 +331,8 @@ export async function runImportMediaJob(opts: ImportMediaJobOpts): Promise<Strea } return runManagedFunction({ kind: IMPORT_MEDIA_JOB_KIND, - queueKey: importMediaQueueKey(req.slug), + // An x.com URL asks X: X's queue (lib/xJobRule.ts), like every X job. + queueKey: target.kind === "url" && target.platform === "twitter" ? X_QUEUE_KEY : importMediaQueueKey(req.slug), paths, channelSlug: req.slug, videoId: target.id, diff --git a/common/jobs/networkGuard.ts b/common/jobs/networkGuard.ts @@ -47,7 +47,7 @@ import { } from "../social/xSessionBroker"; import { resolveXCookieSource, xMaxCookieAgeMinutes, type XCookieSource } from "../social/xCookieSource"; import { jobKindLabel, kindIsNetwork } from "./jobKinds"; -import { xJobCounts, xQueueRefusal, type XJobPlan } from "../lib/xJobRule"; +import { xJobAsksX, xJobCounts, xQueueRefusal, type XJobPlan } from "../lib/xJobRule"; import { isXTrendingChannel } from "../lib/xTrending/config"; import { recordXJobStart, xJobCapStatus } from "./xJobCap"; import { writeJobMeta } from "./jobMeta"; @@ -104,19 +104,26 @@ export async function networkJobPlatform(opts: NetworkJobOpts): Promise<string | } } -// Whether a job asks X: its queue is X's, OR its channel is on X. Both are -// asked (lane x-followups, R2): a job moved to another platform's queue used -// to be taken for that platform's and met none of X's rules. -export async function jobAsksX(opts: NetworkJobOpts): Promise<boolean> { - if (queueGapPlatform(opts.queueKey) === "twitter") return true; - if (!opts.channelSlug) return false; +async function channelPlatformOf(opts: NetworkJobOpts): Promise<string | null> { + if (!opts.channelSlug) return null; try { - return (await channelPlatform(opts.paths, opts.channelSlug)) === "twitter"; + return await channelPlatform(opts.paths, opts.channelSlug); } catch { - return false; + return null; } } +// Whether a job asks X: its queue is X's, OR it is an X channel's job whose +// work asks X (lane x-followups, R2: a job moved to another platform's queue +// used to be taken for that platform's and met none of X's rules), OR it +// imports an x.com URL. An X channel's job that asks no platform at all — +// its transcription, windows cut from disk, a local file's import — is not +// X's (review 2 S5). One predicate: lib/xJobRule.ts xJobAsksX. +export async function jobAsksX(opts: NetworkJobOpts): Promise<boolean> { + const params = opts.spec?.params as Record<string, unknown> | undefined; + return xJobAsksX({ kind: opts.kind, queueKey: opts.queueKey, channelPlatform: await channelPlatformOf(opts), ...(params ? { params } : {}) }); +} + // ── 2 + 3. X ─────────────────────────────────────────────────────────────── // "16 days", "3 h", "45 min". @@ -454,8 +461,10 @@ export async function guardNetworkJob( if (!kindIsNetwork(opts.kind)) return { ok: true, notes: [] }; const empty = emptyQueueRefusal(opts.kind, opts.queueKey); if (empty) return { ok: false, error: empty }; - // A job that asks X meets X's guard whatever queue it is on. - const platform = (await jobAsksX(opts)) ? "twitter" : await networkJobPlatform(opts); + // A job that asks X meets X's guard whatever queue it is on. One that does + // not is never taken for X's by its channel: its queue's platform decides. + const fromChannel = await networkJobPlatform(opts); + const platform = (await jobAsksX(opts)) ? "twitter" : fromChannel === "twitter" ? queueGapPlatform(opts.queueKey) : fromChannel; const guard = platform && Object.hasOwn(PLATFORM_GUARDS, platform) ? PLATFORM_GUARDS[platform] : undefined; return guard ? guard(opts) : { ok: true, notes: [] }; } diff --git a/common/jobs/pacingGuard.test.ts b/common/jobs/pacingGuard.test.ts @@ -595,3 +595,44 @@ test("R-b: a job that meets the cap AT ITS START ends deferred — done, not fai assert.equal((await readJobMeta(paths, blocker.jobId))?.xStarts?.length, 1); await reset(); }); + +test("S5: an X channel's jobs that ask x.com nothing pass off X's queue; those that ask it are X's — refused elsewhere, on X's queue by default", async () => { + await reset(); + // A stale jar and a full cap: nothing that is X's would start. + await writeJar(5 * 60 * 60_000); + for (let i = 0; i < 12; i++) await recordXJobStart(paths, fakeNow); + const slug = SLUGS[0]; + const g = (kind: string, queueKey: string, params?: Record<string, unknown>, channelSlug: string | undefined = slug) => + guardNetworkJob({ kind, queueKey, paths, ...(channelSlug ? { channelSlug } : {}), ...(params ? { spec: { kind, slug, params } as never } : {}) }); + // They ask no platform: they pass, whatever X's jar and cap say. + for (const [kind, queueKey, params] of [ + ["transcribe-one", `transcribe-one:${slug}:1`], + ["fetch-windows", "clips:saved-video"], + ["fetch-window", "clips:saved-video"], + ["import-media", `import-media:${slug}`], + ["import-archive-org", "platform:archiveorg"], + ["import-one", "platform:archiveorg", { url: "https://archive.org/details/example" }], + ] as const) { + const r = await g(kind, queueKey, params); + assert.equal(r.ok, true, `${kind} on ${queueKey}: ${r.ok ? "" : r.error}`); + } + // They ask x.com: X's, so refused off X's queue (and by the jar on it). + for (const [kind, queueKey, params, channelSlug] of [ + ["fetch-window", "clips:twitter", undefined, slug], + ["fetch-windows", "clips:twitter", undefined, undefined], + ["record-live", `record-live:${slug}:1`, undefined, slug], + ["check-kept-deleted", `channel:${slug}`, undefined, slug], + ["redownload-incomplete-bucket", "transcription", undefined, slug], + ["import-one", "platform:youtube", { url: "https://x.com/example/status/1" }, "not-an-x-channel"], + ] as const) { + const r = await g(kind, queueKey, params, channelSlug); + assert.equal(r.ok, false, `${kind} on ${queueKey}`); + assert.match(r.ok ? "" : r.error, /X jobs run on X's queue only/, `${kind} on ${queueKey}`); + } + // Where they are queued by default for an X channel: X's queue. + const { clipWindowQueueKey } = await import("../lib/queueKeys"); + const { platformQueueKey } = await import("../lib/platform"); + assert.equal(clipWindowQueueKey(platformQueueKey("twitter")), "platform:twitter"); + assert.equal(clipWindowQueueKey(platformQueueKey("youtube")), "clips:youtube"); + await reset(); +}); diff --git a/common/lib/queueKeys.ts b/common/lib/queueKeys.ts @@ -141,7 +141,12 @@ export function downloadQueueKey(config: ChannelConfig): string { // Takes the platform queue a window would otherwise have run on // (`downloadQueueKey`, `queueKeyForUrl`), so an unrecognized host keeps its // per-domain key: `platform:vimeo.com` → `clips:vimeo.com`. +// +// EXCEPT X's (lane x-followups, review 2 S5): an X window asks x.com with X's +// cookies, and X jobs run on X's queue only (lib/xJobRule.ts) — spaced by +// X's gap and counted under X's job cap like every other X job. export function clipWindowQueueKey(platformQueue: string): string { + if (platformQueue === "platform:twitter") return platformQueue; return `clips:${platformQueue.replace(/^platform:/, "")}`; } diff --git a/common/lib/xJobRule.test.ts b/common/lib/xJobRule.test.ts @@ -7,7 +7,7 @@ import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import path from "node:path"; import { runInJobContext } from "./jobContext"; -import { X_JOB_CAP, X_QUEUE_KEY, xJobCapSentence, xJobCapVerdict, xJobContextRefusal, xJobCounts, xQueueRefusal } from "./xJobRule"; +import { X_JOB_CAP, X_QUEUE_KEY, xJobCapSentence, xJobCapVerdict, xJobAsksX, xJobContextRefusal, xJobCounts, xQueueRefusal } from "./xJobRule"; const T0 = Date.parse("2026-11-18T12:00:00.000Z"); const MIN = 60_000; @@ -118,3 +118,39 @@ test("ruling R-a: what counts is decided from the job's own plan — only a libr assert.equal(xJobCounts({ kind, params: mediaOnly, channel: library }), true, kind); } }); + +test("S5: which network jobs ask x.com — by X's queue, X's clip queue, an import's URL, or an X channel's job that is not local", () => { + const x = (kind: string, queueKey: string, params?: Record<string, unknown>) => xJobAsksX({ kind, queueKey, channelPlatform: "twitter", ...(params ? { params } : {}) }); + // X's queue, whatever the kind and channel. + assert.equal(xJobAsksX({ kind: "transcribe-one", queueKey: "platform:twitter" }), true); + assert.equal(xJobAsksX({ kind: "fetch-windows", queueKey: "clips:twitter" }), true, "X's clip windows, a batch with no channel"); + // An X channel's jobs that ask x.com, on any other queue: X's (and refused there). + for (const [kind, queueKey] of [ + ["fetch-posts", "manual"], + ["fetch-window", "clips:twitter"], + ["fetch-windows", "clips:twitter"], + ["record-live", "record-live:x-chan:1"], + ["check-kept-deleted", "channel:x-chan"], + ["redownload-incomplete-bucket", "transcription"], + ["import-media", "platform:youtube"], + ["sync", "platform:youtube"], + ] as const) { + assert.equal(x(kind, queueKey), true, `${kind} on ${queueKey}`); + } + // An X channel's jobs that ask x.com nothing: never X's. + assert.equal(x("transcribe-one", "transcribe-one:x-chan:1"), false, "the transcription worker: local"); + assert.equal(x("fetch-windows", "clips:saved-video"), false, "windows cut from the saved copy on disk"); + assert.equal(x("fetch-window", "clips:saved-video"), false); + assert.equal(x("import-media", "import-media:x-chan"), false, "a local file (a URL on X is queued on X's queue)"); + assert.equal(x("import-archive-org", "platform:archiveorg"), false, "archive.org"); + assert.equal(x("import-one", "platform:archiveorg", { url: "https://archive.org/details/example" }), false, "the URL's host"); + // An import asks its URL's host, whatever the channel and queue. + assert.equal(xJobAsksX({ kind: "import-one", queueKey: "platform:youtube", channelPlatform: "youtube", params: { url: "https://x.com/example/status/1" } }), true); + assert.equal(xJobAsksX({ kind: "import-one", queueKey: "platform:youtube", channelPlatform: "youtube", params: { url: "https://twitter.com/example/status/1" } }), true); + assert.equal(x("import-one", "platform:twitter", { url: "https://x.com/example/status/1" }), true); + // Not an X channel, not X's queue: not X's. + assert.equal(xJobAsksX({ kind: "fetch-posts", queueKey: "platform:bluesky", channelPlatform: "bluesky" }), false); + assert.equal(xJobAsksX({ kind: "fetch-window", queueKey: "clips:youtube", channelPlatform: "youtube" }), false); + // The transcription worker asks x.com nothing even on X's queue: it does not count. + assert.equal(xJobCounts({ kind: "transcribe-one" }), false); +}); diff --git a/common/lib/xJobRule.ts b/common/lib/xJobRule.ts @@ -33,6 +33,7 @@ // (lib/jobContext.ts). The count's file is jobs/xJobCap.ts. import { currentJobContext } from "./jobContext"; +import { detectPlatform } from "./platform"; export const X_QUEUE_KEY = "platform:twitter"; @@ -170,6 +171,8 @@ export type XJobPlan = { // It still runs on X's queue, spaced from the others by X's gap, under X's // cooldown and the watch's jar rule: only the count is not asked. export function xJobCounts(plan: XJobPlan): boolean { + // The transcription worker reads a file on disk (review 2 S5). + if (plan.kind === "transcribe-one") return false; if (plan.kind !== "capture-posts" || plan.channel?.library !== true) return true; const p = plan.params; if (!p || typeof p !== "object") return true; @@ -180,3 +183,40 @@ export function xJobCounts(plan: XJobPlan): boolean { if (p.keptMedia === true) return true; return p.media === false; } + +// ── 4. which jobs ask x.com (review 2 S5) ───────────────────────────────── + +// X's clip windows run on X's own queue (lib/queueKeys.ts clipWindowQueueKey); +// the clip queue X once had is X's all the same. +export const X_CLIPS_QUEUE_KEY = "clips:twitter"; + +// The network job as queued: its kind, its queue, its channel's platform and +// its spec's params. +export type XAskPlan = { + kind: string; + queueKey: string; + channelPlatform?: string | null; + params?: Readonly<Record<string, unknown>>; +}; + +// DOES THIS NETWORK JOB ASK x.com? It does on X's queue (or X's old clip +// queue), whatever its kind; an import of one URL asks that URL's host; and a +// job for an X channel asks X — unless its work is one that asks no platform +// at all, which then passes whatever queue it is on: +// transcribe-one the transcription worker, over a file on disk; +// fetch-window(s) on `clips:saved-video`: windows cut from the saved +// copy on disk; +// import-media on its own queue (`import-media:<slug>`): a local +// file (an import of an x.com URL is queued on X's); +// import-archive-org archive.org. +// Everything else an X channel queues asks X, and is refused off X's queue. +export function xJobAsksX(plan: XAskPlan): boolean { + if (plan.queueKey === X_QUEUE_KEY || plan.queueKey === X_CLIPS_QUEUE_KEY) return true; + if (plan.kind === "import-one" && typeof plan.params?.url === "string") return detectPlatform(plan.params.url) === "twitter"; + if (plan.channelPlatform !== "twitter") return false; + if (plan.kind === "transcribe-one") return false; + if ((plan.kind === "fetch-window" || plan.kind === "fetch-windows") && plan.queueKey === "clips:saved-video") return false; + if (plan.kind === "import-media" && plan.queueKey.startsWith("import-media:")) return false; + if (plan.kind === "import-archive-org") return false; + return true; +} diff --git a/editor/app/channels/[slug]/pipelineActions.ts b/editor/app/channels/[slug]/pipelineActions.ts @@ -685,7 +685,8 @@ export async function importVideoAction( // queue control starts at the CHANNEL's queue, which is therefore read as // "no choice made"; any other queue the operator picks still wins. const channelQueue = downloadQueueKey(channelConfig); - const ownQueue = archiveOrg || pacedPlatform ? platformQueueKey(urlPlatform) : null; + // An x.com URL is X's: X's queue (review 2 S5; lib/xJobRule.ts). + const ownQueue = archiveOrg || pacedPlatform || urlPlatform === "twitter" ? platformQueueKey(urlPlatform) : null; const override = ownQueue && queueKey !== undefined && queueKey.trim() === channelQueue ? undefined diff --git a/editor/app/channels/[slug]/whisperActions.ts b/editor/app/channels/[slug]/whisperActions.ts @@ -9,8 +9,10 @@ import { import { TRANSCRIPTION_QUEUE, channelQueueKey, + downloadQueueKey, resolveQueueKey, } from "yt-dlp-transcript-common/lib/queueKeys"; +import { readChannelConfig } from "yt-dlp-transcript-common/controller/channels"; import { countNotYetTranscribed, readChannelStat, @@ -389,9 +391,13 @@ export async function checkKeptDeletedAction( queueKey?: string, ): Promise<StreamActionResult> { const paths = getPaths(); + // An X channel's check asks x.com (an availability probe per video): X's + // queue, X's gap and X's job cap (review 2 S5; lib/xJobRule.ts). + const config = await readChannelConfig(paths, slug).catch(() => null); + const own = config && downloadQueueKey(config) === "platform:twitter" ? "platform:twitter" : channelQueueKey(slug); return runManagedFunction({ kind: "check-kept-deleted", - queueKey: resolveQueueKey(channelQueueKey(slug), queueKey), + queueKey: resolveQueueKey(own, queueKey), paths, channelSlug: slug, spec: { kind: "check-kept-deleted", slug, params: { queueKey } },