commit af3b84c24f11e996a77b81b8150842cc984d2082
parent 1a9d99df916eb481426bc14a6ac6d6c64cd65114
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Sat, 21 Nov 2026 14:25:39 -0500
x-sittings: docs, the scheduler's room by kind, and a route test for the account mark
- OPERATING.md: X's drawn gap, sittings and their kinds, the account mark,
the 429 stop for every X job, the cap at 6.
- editor CHANGELOG bullet.
- The scheduler queues no X sync into a browse sitting (xSittingHeld judges
a timelines job), with a test.
- POST /api/ops/x-session route test (mark suspended / ok, refusals).
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
5 files changed, 152 insertions(+), 16 deletions(-)
diff --git a/OPERATING.md b/OPERATING.md
@@ -517,11 +517,40 @@ pnpm ops capture-posts --json '{"slug":"example-x","ids":["<postId>"]}' --wait
did not continue from its place: it stops at once with a sentence and keeps the place. If a place is lost,
`fetch-posts {"older": true}` walks down from the oldest archived post.
- **Pacing is enforced, not advised** (plans/pacing-guard.md). Every job that asks a platform waits its
- platform queue's gap after the previous one there ended — `pacing.jobGapSeconds`: Instagram 600 s, X 300 s,
- forums and Bluesky 60 s, everything else 20 s (set on /settings) — and its /jobs row and log say so (`waiting 4m12s: X
- jobs are spaced 5 min apart (pacing.jobGapSeconds.twitter)`). Thirteen fetches queued in one loop run five
- minutes apart and stop at the first challenge. A queue override of `""` (immediate) is refused for any
- such job.
+ platform queue's gap after the previous one there ended — `pacing.jobGapSeconds`: Instagram 600 s, forums
+ and Bluesky 60 s, everything else 20 s (set on /settings) — and its /jobs row and log say so. **X's gap is
+ drawn per job**, uniform in `social.x.gapMinMinutes`-`gapMaxMinutes` (5-12 min; never below 5, and an explicit
+ `pacing.jobGapSeconds.twitter` above 5 min raises the minimum): `waiting 8m41s (a 9m02s gap drawn from 5-12
+ min): X jobs are spaced 5-12 min apart, drawn per job`. A queue override of `""` (immediate) is refused for
+ any such job.
+- **X in small, uneven sittings** (21 Nov 2026, after the account's suspension: one sitting of a trending read
+ and 12 timeline fetches, each 5-6 minutes after the last). A **sitting** begins at a cookie refresh (Refresh
+ cookies or Connect X account on /cookies) and admits at most `social.x.sittingJobs` X job starts — 4 by
+ default, bounded 1-6 in the code — counted as X's job cap counts them (each channel of an X run is one; a
+ library's media-only capture is not). A sitting is **one kind**, fixed by its first job: **timelines**
+ (account post fetches in any mode, an X run's channels, Sync, captures of an account's posts, availability
+ checks, an import of one X post, X video windows) or **browse** (trending reads, an X search channel's walk, a
+ trending library's captures). A job past the sitting, or of the other kind, is refused when it is queued
+ (`This X sitting is used up: 4 of 4 X jobs started since the cookies were refreshed at 14:02 UTC …`), or ends
+ `done`, deferred, when its queue reaches it; nothing retries it. **A new Refresh starts the next sitting** —
+ and only a refresh does: the jar's refresh time is the broker's own stamp (`.x-session/refreshed.json`), not
+ the jar file's time, which gallery-dl used to rewrite after every run (gallery-dl now runs with
+ `cookies-update` off). The sitting is kept in `.x-session/sitting.json` (a restart keeps it; deleted, it is
+ counted again from the job records and X's job count; unreadable, no X job starts). `pnpm ops get x-session`
+ shows `sitting {began, kind, used, left, limit}`, and /cookies shows it on X's row with the jobs left. An X run
+ stops at the sitting's end like at a stale jar, and Resume after a Refresh takes the rest; the scheduler
+ queues no more X syncs than the sitting has left; a trending watch waits for the next Refresh.
+- **The X account's state, marked by hand.** `pnpm ops x-session --json '{"accountState":"suspended","note":"…"}'`
+ (or **Mark suspended** on /cookies) records that the account X answers as is suspended (read-only). While it
+ is: `check-post-availability` on X and `capture-posts` with screenshots (the jobs that record a post as deleted
+ or unavailable) are refused, the capture and the check also drop any "deleted"/"unavailable" verdict if the
+ mark is made while they run, and every other X job's log says the account is marked suspended.
+ `{"accountState":"ok"}` (Mark ok) lifts it. Nothing detects a suspension by itself: neither the fetchers nor
+ gallery-dl see an explicit signal of OUR account's suspension in X's answers.
+- **A 429 from X stops every X job for 15 minutes.** A trending read, its media, a capture and a gallery-dl
+ fetch that met X's rate limit record X's cooldown, and the guard refuses every X job of any kind until it ends
+ (`X answered a rate limit (429) a short while ago: no X job starts before …`); `get x-session` shows
+ `cooldown {until}`.
- **Only the editor's jobs ask X.** `pnpm archilyzer posts fetch --slug <x-channel>` is refused, in every mode
(plain, `--backfill`, `--full`, `--older`, an X search channel) and for every X fetcher, and names `pnpm ops
fetch-posts`: run directly it had no queue, no gap, no fresh-jar rule, no X alert and no cooldown. It still
@@ -543,7 +572,7 @@ pnpm ops capture-posts --json '{"slug":"example-x","ids":["<postId>"]}' --wait
by the time it runs fails ("the saved copy no longer covers this window; ask again and it runs on X's queue")
and asks X nothing. `fetch-copies` refuses a copy whose address is X's. A `t.co` short link is X's. `record-live` of an X channel is refused (a recording would hold X's queue
for hours), and so is `redownload-incomplete-bucket` on one (the transcription queue).
-- **X's job cap: 12 in any 60 minutes, 150 in any 24 hours, on this machine.** ONE count over every kind of X
+- **X's job cap: 6 in any 60 minutes, 150 in any 24 hours, on this machine.** ONE count over every kind of X
job together (each channel of an X run is one), whatever the login source, cookie spec or channel. A job past
it is refused when it is queued, with the time the next may start; nothing queues behind it. **A job that meets
it when its queue starts it ends `done`, deferred** (`[deferred] …` in its log, `deferred` on the job): it did
@@ -562,10 +591,9 @@ pnpm ops capture-posts --json '{"slug":"example-x","ids":["<postId>"]}' --wait
say since when in `.jobs/x-records-kept.json`; until that is a day old, a lost count is refused, at most for a
day (a date in that file after now is no proof: said again at now). A start stamped in the future (a clock set
back) counts until the clock has passed it by the window. The scheduler queues no more X syncs than the cap has
- starts left (less the X jobs already waiting); the others wait for a later tick. X's own gap (5 minutes) already means 12 jobs an hour, so
- the hourly cap bites only if that gap is lowered; the daily cap bites sooner: an X run over more than 150
- channels, more than 150 X channels on a daily sync, or two topics watched at 30 minutes (a tick is a read and
- usually a capture: about 96 jobs a day per topic) each reach it.
+ starts left (less the X jobs already waiting); the others wait for a later tick. At 6 an hour the hourly cap
+ bites at X's floor gap (5 minutes) and implies the daily one (6 × 24 = 144 < 150), which stays as a second,
+ independent bound. In practice the sitting (4 per refresh) is reached first.
- **X only on a fresh jar.** With the connected profile as the login source, a job aimed at X is refused —
at enqueue and again when its queue reaches it — unless the cookies were refreshed within
`social.x.maxCookieAgeMinutes` (60; 0 = off): `X cookies were last refreshed 16 days ago (limit 60 min):
@@ -772,8 +800,8 @@ pnpm ops watch-trending --json '{"slug":"trending","topic":"kettle-festival","o
store, the transcript archives read `data/`, and the source mirror publishes this code repo, not the corpus.
Nothing in Archilyzer commits or pushes the corpus repo; a backup you run yourself over `transcripts/` is yours
to point away from `trending/reads/`.
-- **One page is one job on X's queue** (`read-x-trending`): the fresh-jar rule, the X alert and X's 5-minute job
- gap apply as to every X job. The page is opened in the connected X profile's browser (headless; `"headed": true`
+- **One page is one job on X's queue** (`read-x-trending`): the fresh-jar rule, the X alert, X's drawn 5-12 minute job
+ gap and X's sitting (a read is a browse job) apply as to every X job. The page is opened in the connected X profile's browser (headless; `"headed": true`
opens a window on the editor's desktop), and what the page itself fetches is kept: every GraphQL JSON answer, raw,
in `channels/<slug>/trending/reads/<readId>/responses.jsonl`, a screenshot (`page.png`) and the read's record
(`read.json`: operation names and sizes only). No request is built and no header is stored. That directory is
diff --git a/common/jobs/networkGuard.ts b/common/jobs/networkGuard.ts
@@ -488,9 +488,10 @@ async function xSittingHeld(paths: Paths): Promise<{ left: number; sentence?: st
const status = await readXSessionStatus(paths);
const limit = xSittingJobs(settingsNow()?.social?.x);
const look = await xSittingLook(paths, { refreshedAt: status.cookiesUpdatedAt ?? null, kind: "timelines", limit });
- if (!look.status.readable) return { left: 0, sentence: look.verdict.ok ? undefined : look.verdict.sentence };
- if (look.status.left > 0) return { left: look.status.left };
- return { left: 0, ...(look.verdict.ok ? {} : { sentence: look.verdict.sentence }) };
+ // The scheduler queues syncs (timelines jobs): a browse sitting, or one
+ // used up or unreadable, has no room for them.
+ if (look.verdict.ok) return { left: look.status.left };
+ return { left: 0, sentence: look.verdict.sentence };
} catch {
return null;
}
diff --git a/common/jobs/xSittings.test.ts b/common/jobs/xSittings.test.ts
@@ -58,7 +58,7 @@ const { runManagedFunction } = await import("./streamCommand");
const { setQueueGapClock, clearQueueGaps, noteQueueJobEnd, queueGapWait, queueGapLine, setXGapRandom, xQueueGapRange } = await import("./queueGap");
const { xJobStartsFile } = await import("./xJobCap");
const { xSittingFile } = await import("./xSitting");
-const { xSessionReport, guardNetworkJob } = await import("./networkGuard");
+const { xSessionReport, guardNetworkJob, xCapRoom, xCapHeldReason } = await import("./networkGuard");
const { recordPlatformCooldown } = await import("./downloadBackoff");
const { writeAutoQueueState, readAutoQueueState } = await import("./autoQueueState");
const { writeXAccountState, xAccountStateFile, keepVerdictsTrustedWhileSuspended } = await import("../social/xAccountState");
@@ -380,3 +380,21 @@ test("A 429 STOPS EVERY X JOB FOR 15 MINUTES: fetch, capture, availability check
await writeAutoQueueState(paths, st);
assert.equal((await xJob("fetch-posts", ACCOUNTS[0])).status, "done");
});
+
+test("the scheduler queues no more X syncs than the sitting has left, and none into a browse sitting", async () => {
+ await reset();
+ await writeJar(60_000, { refresh: true });
+ assert.equal(await xCapRoom(paths, fakeNow), 4);
+ assert.equal(await xCapHeldReason(paths, fakeNow), null);
+ assert.equal((await xJob("fetch-posts", ACCOUNTS[0])).status, "done");
+ assert.equal(await xCapRoom(paths, fakeNow), 3);
+ // A browse sitting has no room for a timeline sync.
+ await writeJar(0, { refresh: true });
+ assert.equal((await xJob("read-x-trending", "demo-library")).status, "done");
+ assert.equal(await xCapRoom(paths, fakeNow), 0);
+ assert.match((await xCapHeldReason(paths, fakeNow)) ?? "", /^This X sitting is a browse sitting/);
+ // Used up: the sentence says so.
+ await writeFile(xSittingFile(paths), JSON.stringify({ version: 1, began: JSON.parse(await readFile(xSittingFile(paths), "utf8")).began, kind: "timelines", starts: [1, 2, 3, 4].map((i) => ({ at: fakeNow - i, jobKind: "fetch-posts", kind: "timelines" })) }));
+ assert.equal(await xCapRoom(paths, fakeNow), 0);
+ assert.match((await xCapHeldReason(paths, fakeNow)) ?? "", /^This X sitting is used up: 4 of 4/);
+});
diff --git a/editor/CHANGELOG.md b/editor/CHANGELOG.md
@@ -1,6 +1,32 @@
# Changelog
## [Unreleased]
+- **X is asked in small, uneven sittings.** The archive's X account was suspended after one sitting of a trending
+ read and 12 timeline fetches back to back, each 5-6 minutes after the last.
+ - A cookie refresh (Refresh cookies or Connect X account on /cookies) now admits at most **4 X job starts**
+ (`social.x.sittingJobs`, 1-6; it cannot be set higher). The 5th is refused when it is queued, or ends
+ **deferred** when its turn comes: "This X sitting is used up: 4 of 4 X jobs started since the cookies were
+ refreshed at 14:02 UTC … A new Refresh cookies on /cookies starts the next sitting." Nothing retries it.
+ - A sitting is **one kind**, set by its first job: timelines (account fetches, captures, availability checks,
+ an import) or browse (trending reads, X searches, a library's captures). A job of the other kind waits for
+ the next Refresh, saying why.
+ - **The gap before an X job is drawn anew each time**, 5-12 minutes by default (set in the X account session;
+ never below 5). The job's log says what was drawn: "waiting 8m41s (a 9m02s gap drawn from 5-12 min)".
+ - **At most 6 X jobs start in any hour** (was 12). The daily 150 is unchanged.
+ - A refresh is now the only thing that resets the cookies' age. gallery-dl rewrote the cookie file after every
+ fetch, so the file's time said "refreshed" after each one, and a chain of fetches could stay inside the
+ 60-minute limit. gallery-dl no longer writes the file, and the refresh time is recorded on its own.
+ - **A 429 from X stops every kind of X job for 15 minutes**: fetches, syncs, X runs, captures and checks too,
+ where before only trending reads and captures waited. A fetch that X rate-limited now records the 15 minutes
+ as well.
+ - **Mark suspended** on /cookies (or `pnpm ops x-session --json '{"accountState":"suspended"}'`) records that
+ the X account is suspended. While it is marked, deleted-post checks and captures with screenshots are refused,
+ because a suspended account may not see posts that still exist. Every other X job's log says so. **Mark ok**
+ lifts it.
+ - /cookies shows the sitting on X's row ("Sitting: 2 of 4 used, 2 left · timelines · began 14:02 UTC"), the
+ 15-minute wait after a 429 and the account's state. `pnpm ops get x-session` reports `sitting`, `account`,
+ `cooldown` and `refusedBy`.
+ - Needs a restart of the editor.
- **umtool: name a channel once for a whole cut.**
- A cut made from two recordings of one channel showed two names for it, the older record's uploader name and
the current one. Before, the only fix was to hand-edit `channelTitle` on every clip.
diff --git a/editor/app/api/ops/x-session/route.test.ts b/editor/app/api/ops/x-session/route.test.ts
@@ -0,0 +1,63 @@
+import test from "node:test";
+import assert from "node:assert/strict";
+import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
+import os from "node:os";
+import path from "node:path";
+
+// Run with:
+// pnpm -C editor exec tsx --test "app/api/ops/x-session/route.test.ts"
+//
+// Lane x-sittings: the operator marks the X account suspended (or ok) through
+// POST /api/ops/x-session, and GET reports it with X's sitting. Temp dirs
+// only; nothing reaches X.
+
+const ROOT = await mkdtemp(path.join(os.tmpdir(), "x-session-route-"));
+process.env.WORKER_TOKEN = "test-token";
+process.env.TRANSCRIPTS_DIR = ROOT;
+process.env.SETTINGS_FILE = path.join(ROOT, "settings.json");
+await writeFile(process.env.SETTINGS_FILE, JSON.stringify({ social: { x: { cookieSource: "profile" } } }));
+
+const { POST, GET } = await import("./route");
+test.after(() => rm(ROOT, { recursive: true, force: true }));
+
+const AUTH = { authorization: "Bearer test-token" };
+
+async function post(body: Record<string, unknown>) {
+ const res = await POST(
+ new Request("http://localhost/api/ops/x-session", {
+ method: "POST",
+ headers: { ...AUTH, "content-type": "application/json" },
+ body: JSON.stringify(body),
+ }),
+ );
+ return { status: res.status, body: (await res.json()) as { ok: boolean; error?: string; account?: { state: string; note?: string } } };
+}
+
+async function get() {
+ const res = await GET(new Request("http://localhost/api/ops/x-session", { headers: AUTH }));
+ return (await res.json()) as { account: { state: string; alert?: string }; sitting: { used: number; limit: number; left: number } };
+}
+
+test("POST marks the account suspended with a note, GET shows it as the account's alert, and ok lifts it", async () => {
+ assert.equal((await get()).account.state, "ok");
+ const marked = await post({ accountState: "suspended", note: "read-only since the 21st" });
+ assert.equal(marked.status, 200, marked.body.error);
+ assert.deepEqual([marked.body.account?.state, marked.body.account?.note], ["suspended", "read-only since the 21st"]);
+ const file = JSON.parse(await readFile(path.join(ROOT, ".x-session", "account.json"), "utf8"));
+ assert.equal(file.state, "suspended");
+ const after = await get();
+ assert.equal(after.account.state, "suspended");
+ assert.match(after.account.alert ?? "", /^The X account is marked suspended .*read-only since the 21st/);
+ // The sitting is reported beside it: the default four, none used.
+ assert.deepEqual([after.sitting.used, after.sitting.limit, after.sitting.left], [0, 4, 4]);
+ assert.equal((await post({ accountState: "ok" })).status, 200);
+ assert.equal((await get()).account.state, "ok");
+});
+
+test("POST refuses a state it does not know, a stray key and a note that is not a string", async () => {
+ for (const body of [{ accountState: "banned" }, {}, { accountState: "ok", when: "now" }, { accountState: "ok", note: 3 }]) {
+ const r = await post(body);
+ assert.equal(r.status, 400, JSON.stringify(body));
+ assert.equal(r.body.ok, false);
+ }
+});