commit 53d75f1455f4474774ff69e0ef2d827062174975
parent 5c0dfc61191d69d55281efa456d7b44cb4bb1d01
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Tue, 17 Nov 2026 22:57:45 -0500
x-trending review 2 (N5, N6, N7 wiring): X's cooldown holds captures; the profile guard goes by platform
N5: an X post capture checks the twitter platform cooldown at its start and fails
with the sentence naming the time (shot or no shot: its media comes from X too).
N6: both sides of the profile guard decide by the job's platform, read from its
channel's config, never by its queue key, so a queueKey override cannot escape it;
a capture that takes no shot (and is neither avatars-only nor context-only) opens
no browser, so it neither blocks a Connect or Refresh nor is refused by one.
N7: the action tells the plan whether a read of the library is queued or running.
OPERATING.md and the changelog say what a 429 holds, that nothing clears it early,
and that read.json names what stopped a read. Tests seen red first.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
8 files changed, 151 insertions(+), 44 deletions(-)
diff --git a/OPERATING.md b/OPERATING.md
@@ -674,7 +674,8 @@ pnpm ops get trending trending --topic kettle-festival --limit 50
finds) and writes no post. `{"reparse": "<readId>"}` parses a saved capture again, offline, as a
`reparse-x-trending` job: X is asked nothing, so it needs no fresh jar. `read.json` is written when a read
starts and again when it ends, so any capture can be parsed again; one left with its answers and no record
- takes `"url"` beside `"reparse"` to say which page it was.
+ takes `"url"` beside `"reparse"` to say which page it was. A read that is still queued or running is not
+ reparsed: ask once it has finished.
- **How a read ends**, in the job's last line (`@@read-x-trending {…, "sentence"}`):
- `Read …: N posts on the page, M new, in topic "…"`.
- `Read saved, nothing recognised: …`: the answers held no post the parser knows. Not a failure, no X alert; the
@@ -682,10 +683,13 @@ pnpm ops get trending trending --topic kettle-festival --limit 50
- `X asked to log in instead of showing the trending page …`: fails, no post written, and X's cookie alert goes
up (no X job starts until it is cleared).
- `X answered 429 (rate limit) …`: fails, the posts read before it kept, no alert. X is then left alone for 15
- minutes: no trending read is queued or started before the time the sentence names (the `twitter` platform
- cooldown, the one import-post respects). A clean read clears it.
+ minutes, whatever else went wrong with the read: no trending read is queued or started before the time the
+ sentence names. It is the `twitter` platform cooldown, so for those 15 minutes it also holds an X post capture
+ (which fails at its start with the same sentence), import-post on X, and the download lane's X units. It ends
+ by itself; a clean read does not clear it, and never touches a hold the download lane set for its own reason.
- `X answered 403 (forbidden) …`: fails at once, the posts read before it kept. No login alert, unless the page
- also showed the login wall.
+ also showed the login wall. The sentence names the operation that was refused, and `read.json`'s `stoppedBy`
+ its name and status (for a 429 and a 401 too).
- `The page was read and saved (…), but its posts could not be written: …`: fails; reparse the read.
- `X no longer has this trending page …`, `The trending page could not be loaded: …` and `The trending page
stopped answering: …`: fail, capture kept.
@@ -693,7 +697,9 @@ pnpm ops get trending trending --topic kettle-festival --limit 50
queue, X's Connect and Refresh cookies are refused with a sentence naming the job ("Cancel it on /jobs or wait
for it to finish"); a job that is only queued blocks nothing. While a Connect or Refresh is running, a trending
read is refused (when asked and again when it starts) and an X post capture fails at its start with the same
- sentence. Refresh the cookies first, then read.
+ sentence. Which job is X's is decided by its channel's platform, not by the queue it was put on; a capture that
+ takes no screenshot (`"shots": false`, and neither the avatars nor the context alone) opens no browser, so it
+ neither blocks a press nor is blocked by one. Refresh the cookies first, then read.
## Transcribe
diff --git a/common/controller/readXTrending.ts b/common/controller/readXTrending.ts
@@ -46,6 +46,7 @@ import {
NOT_A_TRENDING_URL,
NOT_AN_X_TRENDING_LIBRARY,
parseXTrendingUrl,
+ xRateLimitHoldSentence,
xTrendingLimits,
type XTrendingLimits,
type XTrendingRef,
@@ -103,10 +104,7 @@ export async function xTrendingHeld(paths: Paths, now: number = Date.now()): Pro
if (held) return held;
const ms = await platformCooldownRemainingMs(X_PLATFORM, paths).catch(() => 0);
if (ms <= 0) return null;
- return (
- `X answered a rate limit (429) a short while ago: no trending read starts before ${hhmm(now + ms)} UTC ` +
- `(${Math.ceil(ms / 60_000)} min from now). Ask again then; nothing retries by itself.`
- );
+ return xRateLimitHoldSentence("trending read", ms, now);
}
export const NO_X_PROFILE_FOR_TRENDING =
diff --git a/common/lib/xTrending/config.ts b/common/lib/xTrending/config.ts
@@ -34,6 +34,17 @@ export const X_TRENDING_QUEUE = "platform:twitter";
// refused while one of them is running (editor/app/lib/cookieRefreshGuard.ts).
export const X_PROFILE_BROWSER_JOB_KINDS: readonly string[] = [READ_X_TRENDING_KIND, "capture-posts"];
+// X is cooling down after a rate limit: why `what` ("trending read", "X
+// capture") does not start, and until when. One sentence for every job that
+// reads the cooldown.
+export function xRateLimitHoldSentence(what: string, remainingMs: number, now: number): string {
+ const until = new Date(now + remainingMs).toISOString().slice(11, 16);
+ return (
+ `X answered a rate limit (429) a short while ago: no ${what} starts before ${until} UTC ` +
+ `(${Math.ceil(remainingMs / 60_000)} min from now). Ask again then; nothing retries by itself.`
+ );
+}
+
export const X_TRENDING_DEFAULT_SCROLLS = 8;
export const X_TRENDING_MAX_SCROLLS = 20;
export const X_TRENDING_DEFAULT_POSTS = 60;
diff --git a/editor/CHANGELOG.md b/editor/CHANGELOG.md
@@ -24,8 +24,9 @@
`channels/<slug>/trending/posts/`, not where a posts channel keeps its posts, so every other reader finds a
library empty; an article or report that cites a library is refused, and a draft's X link never resolves to one.
- A read cannot hang: the load has 75 s, each scroll 20 s, the whole read 6 minutes, and the browser is closed or
- killed. A 429 leaves X alone for 15 minutes (the sentence says until when); a 403 stops the read at once with
- its own sentence and no login alert.
+ killed. A 429 leaves X alone for 15 minutes (the sentence says until when), which also holds X post captures,
+ import-post on X and the download lane's X units; a 403 stops the read at once with its own sentence and no
+ login alert. `read.json` names the operation and status that stopped a read.
- The raw captures are never committed: `trending/reads/.gitignore` ignores everything under it.
- **X's Connect and Refresh cookies say when a job is using the profile.** While a trending-page read or a post
capture is running on X's queue, a press is refused with a sentence that names the job and says to cancel it on
diff --git a/editor/app/channels/[slug]/socialActions.ts b/editor/app/channels/[slug]/socialActions.ts
@@ -42,7 +42,8 @@ import {
retryOnBlockProblem,
type RetryOnBlock,
} from "yt-dlp-transcript-common/lib/forumWalk";
-import { xProfileStartRefusal } from "../../lib/cookieRefreshGuard";
+import { channelPlatformOf, xCaptureStartRefusal } from "../../lib/cookieRefreshGuard";
+import { platformCooldownRemainingMs } from "yt-dlp-transcript-common/jobs/downloadBackoff";
import { saveSettings } from "../../settings/saveSettings";
import { isUtcDay } from "yt-dlp-transcript-common/social/olderBackfill";
import {
@@ -410,11 +411,16 @@ export async function capturePostsAction(
},
},
fn: async (onLog, signal, _progress, ctx) => {
- // One browser on the X profile at a time (lib/cookieRefreshGuard.ts): an
- // X capture that starts while X's Connect or Refresh holds the profile
- // fails with a sentence instead of with Chromium's profile-lock error.
- const profileHeld = xProfileStartRefusal(key, "capture these posts");
- if (profileHeld) throw new Error(profileHeld);
+ // AN X CAPTURE'S START (lib/cookieRefreshGuard.ts xCaptureStartRefusal),
+ // decided by the channel's PLATFORM, never by the queue this job was
+ // put on: X cooling down after a rate limit (a trending read's 429)
+ // holds it; and while X's Connect or Refresh holds the profile, a
+ // capture that would open its browser fails with a sentence instead of
+ // with Chromium's profile-lock error.
+ const platform = pages ? null : channelPlatformOf(slug);
+ const cooling = platform === "twitter" ? await platformCooldownRemainingMs("twitter", paths).catch(() => 0) : 0;
+ const held = xCaptureStartRefusal({ platform, shots, avatarsOnly, contextOnly }, cooling);
+ if (held) throw new Error(held);
const result = await capturePosts({
paths,
slug,
diff --git a/editor/app/channels/[slug]/xTrendingActions.ts b/editor/app/channels/[slug]/xTrendingActions.ts
@@ -18,6 +18,7 @@
// with `@@read-x-trending {…}`.
import { getPaths } from "yt-dlp-transcript-common/lib/paths";
+import { getRegistry } from "yt-dlp-transcript-common/jobs/registry";
import { runManagedFunction, type StreamActionResult } from "yt-dlp-transcript-common/jobs/streamCommand";
import {
planReadXTrending,
@@ -35,7 +36,13 @@ import { xPressInFlight } from "../../lib/cookieRefreshGuard";
export async function readXTrendingAction(ask: ReadXTrendingAsk): Promise<StreamActionResult> {
const paths = getPaths();
- const planned = await planReadXTrending(paths, ask);
+ // A read of this library queued or running: a reparse of a record still
+ // marked "started" is then refused (the read has not ended).
+ const readInFlight = async () =>
+ getRegistry()
+ .list()
+ .some((j) => j.kind === READ_X_TRENDING_KIND && j.channelSlug === ask.slug && (j.status === "queued" || j.status === "running"));
+ const planned = await planReadXTrending(paths, ask, { readInFlight });
if (!planned.ok) return { ok: false, error: planned.error };
const plan = planned.plan;
const done = (onLog: (line: string) => void, result: { ok: boolean; error?: string }) => {
diff --git a/editor/app/lib/cookieRefreshGuard.test.ts b/editor/app/lib/cookieRefreshGuard.test.ts
@@ -145,10 +145,12 @@ test("X's Connect and Refresh are refused while a job holds the profile's browse
const { xProfileJobRunning } = await import("./cookieRefreshGuard");
const at = Date.parse("2026-11-17T10:02:11Z");
const reading = () => [{ id: "J1", kind: "read-x-trending", queueKey: "platform:twitter", status: "running", queuedAt: 0, startedAt: at }];
- const capturing = () => [{ id: "J2", kind: "capture-posts", queueKey: "platform:twitter", status: "running", queuedAt: 0, startedAt: at }];
+ const capturing = () => [{ id: "J2", kind: "capture-posts", queueKey: "platform:twitter", channelSlug: "acct-x", status: "running", queuedAt: 0, startedAt: at }];
+ // The job's PLATFORM decides (review 2 N6), looked up by its channel.
+ const platformOf = (slug: string | undefined) => (slug === "acct-x" ? "twitter" : slug === "acct-bsky" ? "bluesky" : null);
let ran = 0;
const press = (service: string, action: "connect" | "refresh" | "recheck", jobs: () => never[]) =>
- withCookieAction(service, action, async () => { ran++; return { ok: true as const }; }, () => ({ ok: true, message: "done" }), { paths, jobs });
+ withCookieAction(service, action, async () => { ran++; return { ok: true as const }; }, () => ({ ok: true, message: "done" }), { paths, jobs, platformOf });
const refused = await press("x", "connect", reading as never);
assert.deepEqual(refused, {
ok: false,
@@ -166,11 +168,25 @@ test("X's Connect and Refresh are refused while a job holds the profile's browse
// fetch on X's, a recheck of X and another service's press are not held.
const idle = [
{ id: "J3", kind: "read-x-trending", queueKey: "platform:twitter", status: "queued", queuedAt: 0 },
- { id: "J4", kind: "capture-posts", queueKey: "platform:bluesky", status: "running", queuedAt: 0 },
- { id: "J5", kind: "fetch-posts", queueKey: "platform:twitter", status: "running", queuedAt: 0 },
+ { id: "J4", kind: "capture-posts", queueKey: "platform:bluesky", channelSlug: "acct-bsky", status: "running", queuedAt: 0 },
+ { id: "J5", kind: "fetch-posts", queueKey: "platform:twitter", channelSlug: "acct-x", status: "running", queuedAt: 0 },
{ id: "J6", kind: "read-x-trending", queueKey: "platform:twitter", status: "done", queuedAt: 0 },
+ // A Bluesky capture moved onto X's queue opens no X profile.
+ { id: "J7", kind: "capture-posts", queueKey: "platform:twitter", channelSlug: "acct-bsky", status: "running", queuedAt: 0 },
+ // An X capture that takes no shot opens no browser.
+ { id: "J8", kind: "capture-posts", queueKey: "platform:twitter", channelSlug: "acct-x", status: "running", queuedAt: 0, spec: { params: { shots: false } } },
];
- assert.equal(xProfileJobRunning(idle), null);
+ assert.equal(xProfileJobRunning(idle, platformOf), null);
+ // A queue override does not hide a job that holds the profile (N6).
+ for (const hidden of [
+ { id: "J9", kind: "capture-posts", queueKey: "my-own-queue", channelSlug: "acct-x", status: "running", queuedAt: 0, startedAt: at },
+ { id: "J10", kind: "read-x-trending", queueKey: "elsewhere", status: "running", queuedAt: 0, startedAt: at },
+ { id: "J11", kind: "capture-posts", queueKey: "my-own-queue", channelSlug: "acct-x", status: "running", queuedAt: 0, startedAt: at, spec: { params: { shots: false, avatarsOnly: true } } },
+ ]) {
+ assert.equal(xProfileJobRunning([hidden], platformOf)?.jobId, hidden.id);
+ const r = await press("x", "connect", (() => [hidden]) as never);
+ assert.equal((r as { busy?: boolean }).busy, true, hidden.id);
+ }
assert.deepEqual(await press("x", "refresh", (() => idle) as never), { ok: true });
assert.deepEqual(await press("x", "recheck", reading as never), { ok: true });
assert.deepEqual(await press("rumble", "refresh", reading as never), { ok: true });
@@ -187,25 +203,34 @@ test("a trending read is refused while X's Connect or Refresh is in flight, and
xPressInFlight() ?? "",
/^X's connect is running \(since \d\d:\d\d:\d\d UTC\) and holds the connected profile: read the trending page once it has finished\.$/,
);
- // The same at a job's start, for both kinds that open the profile — on X's
- // queue only: a capture on another platform's queue opens no X profile.
- const { xProfileStartRefusal } = await import("./cookieRefreshGuard");
+ // The same at an X capture's start (N6: by the job's platform, whatever
+ // its queue; a capture that takes no shot opens no browser).
+ const { xCaptureStartRefusal } = await import("./cookieRefreshGuard");
+ const now = Date.parse("2026-11-17T10:00:00Z");
assert.match(
- xProfileStartRefusal("platform:twitter", "capture these posts") ?? "",
+ xCaptureStartRefusal({ platform: "twitter" }, 0, now) ?? "",
/^X's connect is running \(since \d\d:\d\d:\d\d UTC\) and holds the connected profile: capture these posts once it has finished\.$/,
);
- assert.match(xProfileStartRefusal("platform:twitter", "read the trending page") ?? "", /read the trending page once it has finished/);
- assert.equal(xProfileStartRefusal("platform:bluesky", "capture these posts"), null);
- assert.equal(xProfileStartRefusal("platform:xenforo", "capture these posts"), null);
+ assert.match(xCaptureStartRefusal({ platform: "twitter", shots: false, contextOnly: true }, 0, now) ?? "", /^X's connect is running/);
+ assert.equal(xCaptureStartRefusal({ platform: "twitter", shots: false }, 0, now), null);
+ assert.equal(xCaptureStartRefusal({ platform: "bluesky" }, 0, now), null);
+ assert.equal(xCaptureStartRefusal({ platform: "xenforo" }, 15 * 60_000, now), null);
release();
await connecting;
assert.equal(xPressInFlight(), null);
- assert.equal(xProfileStartRefusal("platform:twitter", "capture these posts"), null);
+ assert.equal(xCaptureStartRefusal({ platform: "twitter" }, 0, now), null);
+ // N5: X cooling down after a rate limit holds an X capture too, shot or no
+ // shot (its media comes from X), and the sentence names the time.
+ assert.equal(
+ xCaptureStartRefusal({ platform: "twitter", shots: false }, 12 * 60_000, now),
+ "X answered a rate limit (429) a short while ago: no X capture starts before 10:12 UTC (12 min from now). Ask again then; nothing retries by itself.",
+ );
+ assert.match(xCaptureStartRefusal({ platform: "twitter" }, 1, now) ?? "", /no X capture starts before 10:00 UTC \(1 min from now\)/);
// A Refresh holds it as a Connect does.
let done!: () => void;
const hold = new Promise<void>((r) => (done = r));
const refreshing = withCookieAction("x", "refresh", async () => { await hold; return { ok: true as const }; }, () => ({ ok: true, message: "Cookies refreshed." }), { paths, jobs: noJobs });
- assert.match(xProfileStartRefusal("platform:twitter", "capture these posts") ?? "", /^X's refresh is running/);
+ assert.match(xCaptureStartRefusal({ platform: "twitter" }, 0, now) ?? "", /^X's refresh is running/);
done();
await refreshing;
// A recheck of X opens no profile: a read is not held by it.
diff --git a/editor/app/lib/cookieRefreshGuard.ts b/editor/app/lib/cookieRefreshGuard.ts
@@ -32,7 +32,13 @@ import { noteServiceCookieAction } from "yt-dlp-transcript-common/lib/serviceCoo
import { serviceLabel, type ServiceCookieActionKind } from "yt-dlp-transcript-common/lib/serviceCookies";
import type { CookieRunning } from "yt-dlp-transcript-common/lib/cookieStatus";
import { RECHECK_JOB_KIND } from "yt-dlp-transcript-common/controller/serviceCookieTimer";
-import { X_PROFILE_BROWSER_JOB_KINDS, X_TRENDING_QUEUE } from "yt-dlp-transcript-common/lib/xTrending/config";
+import path from "node:path";
+import {
+ READ_X_TRENDING_KIND,
+ xRateLimitHoldSentence,
+} from "yt-dlp-transcript-common/lib/xTrending/config";
+import { readJsonFileSync } from "yt-dlp-transcript-common/lib/jsonFile-server";
+import { detectPlatform } from "yt-dlp-transcript-common/lib/platform";
import { jobKindLabel } from "yt-dlp-transcript-common/jobs/jobKinds";
const QUEUE_PREFIX = "service-cookies:";
@@ -43,7 +49,37 @@ function inflight(): Map<string, CookieRunning> {
return (g[KEY] ??= new Map());
}
-type JobLike = { id: string; kind: string; queueKey: string; status: string; queuedAt?: number; startedAt?: number };
+type JobLike = {
+ id: string;
+ kind: string;
+ queueKey: string;
+ status: string;
+ queuedAt?: number;
+ startedAt?: number;
+ channelSlug?: string;
+ spec?: { params?: Record<string, unknown> };
+};
+
+// The platform a job's channel is on, by its config.json (its `platform`,
+// else its URL's) — or null. What decides whether a capture is X's: the JOB'S
+// PLATFORM, never its queue key, which a caller may override (review 2 N6).
+export type PlatformOf = (channelSlug: string | undefined) => string | null;
+
+export const channelPlatformOf: PlatformOf = (slug) => {
+ if (!slug || !/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(slug)) return null;
+ const raw = readJsonFileSync(path.join(getPaths().channelsDir, slug, "config.json"));
+ if (!raw.ok || !raw.value || typeof raw.value !== "object") return null;
+ const c = raw.value as { platform?: unknown; url?: unknown };
+ if (typeof c.platform === "string" && c.platform) return c.platform;
+ return typeof c.url === "string" ? detectPlatform(c.url) : null;
+};
+
+// Whether a capture opens the X profile's browser: a shot (the default), the
+// avatars alone or the context alone. One that takes no shot only downloads
+// media with the exported jar.
+export function captureOpensBrowser(params: { shots?: unknown; avatarsOnly?: unknown; contextOnly?: unknown } | undefined): boolean {
+ return params?.shots !== false || params?.avatarsOnly === true || params?.contextOnly === true;
+}
// What is running per service now: the presses in flight here, and any
// recheck job queued or running on a service's queue.
@@ -65,14 +101,19 @@ export function runningCookieActions(
return out;
}
-// A job that holds the connected X profile's browser now: one of the kinds
-// that open it, RUNNING on X's queue (a queued one holds nothing yet).
+// A job that holds the connected X profile's browser now: RUNNING (a queued
+// one holds nothing yet), and either a trending read, or a post capture of an
+// X channel that opens a browser — whatever queue it was put on.
export function xProfileJobRunning(
jobs: readonly JobLike[] = getRegistry().list(),
+ platformOf: PlatformOf = channelPlatformOf,
): { kind: string; since: string; jobId: string } | null {
for (const j of jobs) {
- if (j.status !== "running" || j.queueKey !== X_TRENDING_QUEUE) continue;
- if (!X_PROFILE_BROWSER_JOB_KINDS.includes(j.kind)) continue;
+ if (j.status !== "running") continue;
+ const holds =
+ j.kind === READ_X_TRENDING_KIND ||
+ (j.kind === "capture-posts" && captureOpensBrowser(j.spec?.params) && platformOf(j.channelSlug) === "twitter");
+ if (!holds) continue;
return { kind: j.kind, since: new Date(j.startedAt ?? j.queuedAt ?? Date.now()).toISOString(), jobId: j.id };
}
return null;
@@ -96,10 +137,22 @@ export function xPressInFlight(what = "read the trending page"): string | null {
);
}
-// The same, asked by a job as it STARTS: only a job on X's queue opens the X
-// profile (a capture of Bluesky or forum posts does not).
-export function xProfileStartRefusal(queueKey: string, what: string): string | null {
- return queueKey === X_TRENDING_QUEUE ? xPressInFlight(what) : null;
+// WHY AN X POST CAPTURE DOES NOT START NOW, or null — asked at the job's
+// start (channels/[slug]/socialActions.ts), by the channel's PLATFORM:
+// - X is cooling down after a rate limit (review 2 N5; `cooldownMs` is
+// platformCooldownRemainingMs("twitter")): any X capture, shot or not —
+// its media comes from X too;
+// - X's Connect or Refresh holds the profile, and this capture would open
+// its browser.
+// A capture of another platform's posts is never held by either.
+export function xCaptureStartRefusal(
+ job: { platform: string | null | undefined; shots?: unknown; avatarsOnly?: unknown; contextOnly?: unknown },
+ cooldownMs: number,
+ now: number = Date.now(),
+): string | null {
+ if (job.platform !== "twitter") return null;
+ if (cooldownMs > 0) return xRateLimitHoldSentence("X capture", cooldownMs, now);
+ return captureOpensBrowser(job) ? xPressInFlight("capture these posts") : null;
}
export function busySentence(service: string, r: CookieRunning): string {
@@ -133,12 +186,12 @@ export async function withCookieAction<T>(
action: ServiceCookieActionKind,
fn: () => Promise<T>,
describe: (r: T) => CookieActionOutcome,
- opts: { paths?: Paths; jobs?: () => readonly JobLike[] } = {},
+ opts: { paths?: Paths; jobs?: () => readonly JobLike[]; platformOf?: PlatformOf } = {},
): Promise<T | { ok: false; error: string; busy: true }> {
const running = runningCookieActions(opts.jobs ? opts.jobs() : undefined)[service];
if (running) return { ok: false, error: busySentence(service, running), busy: true };
if (service === "x" && (action === "connect" || action === "refresh")) {
- const job = xProfileJobRunning(opts.jobs ? opts.jobs() : undefined);
+ const job = xProfileJobRunning(opts.jobs ? opts.jobs() : undefined, opts.platformOf);
if (job) return { ok: false, error: xProfileJobSentence(action, job), busy: true };
}
const map = inflight();