commit ccd01947e83e401a6183bed7d66ba4580b64ff13
parent dc22616c792a585eb03ede7168a9e022721fa28b
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 18 Nov 2026 18:13:25 -0500
posts: an X fetch runs only as the editor's job -- `archilyzer posts fetch` on an X channel is refused
`pnpm archilyzer posts fetch --slug <x-channel>` called fetchPosts directly: no queue, no gap between
X jobs, no fresh-jar rule, no X alert, no cooldown after a rate limit. fetchPosts now refuses a fetcher
of the twitter platform when it is not inside a job of the editor's (currentJobContext), before the
search, older and timeline branches, with a sentence naming `pnpm ops fetch-posts`. Every X fetcher is
covered (gallery-dl, the Playwright fallback, Nitter), every mode, and an X search channel.
Bluesky, a forum thread and a web page keep the direct path: their pacing is the fetcher's own, and
`posts fetch --pages N` on a forum thread is a documented way to read with no editor (README). No
document named the CLI for X.
The tests that call fetchPosts on an X channel directly, to look at what it does with a fake gallery-dl,
stand where a job does (common/testing/jobs/asEditorJob.ts).
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
10 files changed, 169 insertions(+), 6 deletions(-)
diff --git a/COMMANDS.md b/COMMANDS.md
@@ -70,7 +70,7 @@ Run from the repo root (in the container: `docker compose exec editor pnpm archi
| `archilyzer seed` | | the home seeder of last resort: seed the playable torrents of settings.seeder.sites, each only while no other seeder has it (standby otherwise, with hysteresis), TCP + WebRTC, no DHT; runs until interrupted — behind the VPN (docker compose profile `seeder`, docker-compose.seeder.yml) |
| `archilyzer tracker` | `[--host 127.0.0.1] [--port 8000]` | the self-hosted tracker (HTTP + WebSocket, no UDP) for the seeder's torrents only — any other infohash is refused; runs until interrupted |
| `archilyzer duplicates` | `[--threshold N] [--all-durations] [--blocking title\|duration\|both] [--near F] [--tolerance N] …` | on-demand duplicate detection (after index + stats) *(passthrough)* |
-| `archilyzer posts fetch` | `--slug <channel> [--backfill \| --full \| --older [--floor YYYY-MM-DD] [--from YYYY-MM-DD] [--force]] [--limit N] [--pages N] [--retry-on-block \| --retry-minutes N --retry-tries M]` | fetch a social channel's posts into its posts corpus (plain: sync new — from the top down to the newest archived post, never the backfill; --backfill: resume the timeline's unfinished full-history walk from its saved point; --older: walk back below the oldest archived post; --pages: a forum thread's latest N pages — a run catches up, then continues the history where it stopped; --full: a forum thread's full re-walk; --retry-\*: wait out a challenge or refusal page and run again) *(passthrough)* |
+| `archilyzer posts fetch` | `--slug <channel> [--backfill \| --full \| --older [--floor YYYY-MM-DD] [--from YYYY-MM-DD] [--force]] [--limit N] [--pages N] [--retry-on-block \| --retry-minutes N --retry-tries M]` | fetch a social channel's posts into its posts corpus (plain: sync new — from the top down to the newest archived post, never the backfill; --backfill: resume the timeline's unfinished full-history walk from its saved point; --older: walk back below the oldest archived post; --pages: a forum thread's latest N pages — a run catches up, then continues the history where it stopped; --full: a forum thread's full re-walk; --retry-\*: wait out a challenge or refusal page and run again). An X or Instagram channel is refused here and names `pnpm ops fetch-posts`: those are asked only by the editor's jobs, on their queue, gap and cookie rules; Bluesky, a forum thread and a web page are fetched) *(passthrough)* |
| `archilyzer posts import-html` | `<slug> <file-or-dir>… [--dry-run]` | import forum thread pages saved from a browser ("Save page as", .html) into a forum-thread channel: new posts appended, edited ones updated, nothing fetched |
| `archilyzer posts check` | `--slug <channel> [--mode stale\|unchecked\|all] [--limit N]` | which archived posts were deleted at the source (a Wayback pages channel: each record's ORIGINAL URL, asked at its own site) *(passthrough)* |
| `archilyzer evidence pack` | `<channel>[,<channel>…] [--handle <h>] [--since YYYY-MM-DD] [--until YYYY-MM-DD] [--out <dir>] [--media\|--no-media] [--stamp\|--no-stamp] [--dry-run] [--json]` | package posts channels' archived posts as timestamped evidence, read only: posts.jsonl (one record a post, deduped across the channels, every archived field under raw, the capture record, the availability check, the archived record of a post it answers or quotes), posts.csv, media/<postId>/ (the post's captured files, copied byte for byte, each hash checked against its capture.json), pack.json, README.md (how to verify), SHA256SUMS over every file, and SHA256SUMS.ots (OpenTimestamps: `ots stamp`, one request to each of its calendars). --handle keeps one author's posts; --since/--until the post's UTC day. Default --out ~/reports/evidence/<handle\|channel>-<YYYY-MM-DD>/; refused inside the corpus or a channel's media, over a non-empty dir, or for a channel whose text is unreadable; built in a sibling staging dir and renamed into place. Exit 1 when the package is written but the stamp failed (`evidence stamp` it later) |
diff --git a/OPERATING.md b/OPERATING.md
@@ -515,6 +515,10 @@ pnpm ops capture-posts --json '{"slug":"example-x","ids":["<postId>"]}' --wait
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.
+- **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
+ fetches a Bluesky account, a forum thread (`--pages N`) and a web page, whose pacing is the fetcher's own.
- **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):
@@ -741,6 +745,17 @@ pnpm ops watch-trending --json '{"slug":"trending","topic":"kettle-festival","o
- **Topics.** `"topic"` is a topic's id or name, or a new one's name: several pages can be read into one topic.
Without it the posts go to the topic that page was read into before, else to a new one named for the page. A post
already in a topic stays there.
+- **X's own title and summary.** A trending page carries X's title and summary of the trend. A topic you did not
+ name is called by the page's title (its id stays `t-<number>`); one still called `Trending <number>` takes the
+ title at the next read or `reparse` of a capture that has it, and the job's sentence says so. A topic made with
+ a name, or renamed since by you or an agent, is never renamed by a read; nor is one whose page's title another
+ topic already answers to. Whatever the topic is called, the page's entry in it keeps X's title, summary and when
+ X last updated them: the channel page, `get trending` (`sources[].title` / `summary` / `lastUpdatedAt`),
+ `x_trending_topics`, and umtool's library page and `umtool library topics` show them as X's.
+- **A read sees one tab.** A trending page has tabs (`Top`, `Latest`), each its own list of posts. A read sees
+ the tab the page opens on and says which: in its sentence, in `read.json` (`tabs`: a label and a count), per
+ post (`posts[].reads[].tab`) and per page (`sources[].lastReadTab`, with the page's `tabs`). The other tab is
+ not read. "Gone from the page" compares a read with earlier reads of the same tab only.
- **`"probe": true`** saves the capture and a summary (the operations' names and sizes, how many posts the parser
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
@@ -749,7 +764,7 @@ pnpm ops watch-trending --json '{"slug":"trending","topic":"kettle-festival","o
reparsed: ask once it has finished. The job asks again when it starts, and parses nothing if the read is
running by then.
- **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 …: N posts on the page, M new, in topic "…" (<id>), shown by the page's "Top" tab.`
- `Read saved, nothing recognised: …`: the answers held no post the parser knows. Not a failure, no X alert; the
capture is kept for the parser.
- `X asked to log in instead of showing the trending page …`: fails, no post written, and X's cookie alert goes
diff --git a/common/bin/archilyzer.ts b/common/bin/archilyzer.ts
@@ -912,7 +912,7 @@ export const COMMANDS: Command[] = [
script(["duplicates"], "duplicate-shorts.ts",
"[--threshold N] [--all-durations] [--blocking title|duration|both] [--near F] [--tolerance N] … on-demand duplicate detection (after index + stats)", 8192),
script(["posts", "fetch"], "fetch-posts.ts",
- "--slug <channel> [--backfill | --full | --older [--floor YYYY-MM-DD] [--from YYYY-MM-DD] [--force]] [--limit N] [--pages N] [--retry-on-block | --retry-minutes N --retry-tries M] fetch a social channel's posts into its posts corpus (plain: sync new — from the top down to the newest archived post, never the backfill; --backfill: resume the timeline's unfinished full-history walk from its saved point; --older: walk back below the oldest archived post; --pages: a forum thread's latest N pages — a run catches up, then continues the history where it stopped; --full: a forum thread's full re-walk; --retry-*: wait out a challenge or refusal page and run again)"),
+ "--slug <channel> [--backfill | --full | --older [--floor YYYY-MM-DD] [--from YYYY-MM-DD] [--force]] [--limit N] [--pages N] [--retry-on-block | --retry-minutes N --retry-tries M] fetch a social channel's posts into its posts corpus (plain: sync new — from the top down to the newest archived post, never the backfill; --backfill: resume the timeline's unfinished full-history walk from its saved point; --older: walk back below the oldest archived post; --pages: a forum thread's latest N pages — a run catches up, then continues the history where it stopped; --full: a forum thread's full re-walk; --retry-*: wait out a challenge or refusal page and run again). An X or Instagram channel is refused here and names `pnpm ops fetch-posts`: those are asked only by the editor's jobs, on their queue, gap and cookie rules; Bluesky, a forum thread and a web page are fetched)"),
{
path: ["posts", "import-html"],
usage:
diff --git a/common/bin/fetch-posts.ts b/common/bin/fetch-posts.ts
@@ -5,6 +5,12 @@
// --slug <channel-slug> [--backfill | --full | --older [--floor YYYY-MM-DD] [--from YYYY-MM-DD] [--force]] [--limit N] [--pages N]
// [--retry-on-block | --retry-minutes N --retry-tries M]
//
+// NOT FOR X OR INSTAGRAM: fetchPosts refuses a channel of either outside the
+// editor's job (controller/fetchPosts.ts X_ONLY_AS_A_JOB, INSTAGRAM_ONLY_AS_A_JOB)
+// and names `pnpm ops fetch-posts`. Run from here a fetch has no queue, no gap
+// between jobs, no fresh-jar rule, no alert and no cooldown. Bluesky, a forum
+// thread and a web page are fetched from here as before.
+//
// --pages caps how many pages one run reads, for a source read page by page (a
// forum thread: its latest N pages, newest first; the next run continues where
// this one stopped).
diff --git a/common/controller/fetchForumPosts.test.ts b/common/controller/fetchForumPosts.test.ts
@@ -193,3 +193,16 @@ test("the real wait ends on a cancel or a drain", async () => {
assert.equal(await q, "drained");
assert.equal(await sleepOrStop(1), "slept");
});
+
+// Lane x-followups: X is asked only by the editor's jobs; a forum thread keeps the direct path
+// (`pnpm archilyzer posts fetch --slug <thread> --pages N`, README): its pacing is the fetcher's own.
+test("a forum thread is fetched by a direct call, outside any job: the CLI's path stays", async () => {
+ const { currentJobContext } = await import("../lib/jobContext");
+ assert.equal(currentJobContext(), undefined);
+ const { slug } = await channel();
+ const thread = new FakeForumThread(3);
+ await thread.writeTo(FIXTURES);
+ const r = await fetchPosts({ paths: getPaths(), slug, settings: {}, pages: 1 });
+ assert.equal(r.ok, true, r.error);
+ assert.ok(r.written > 0);
+});
diff --git a/common/controller/fetchOlderPosts.test.ts b/common/controller/fetchOlderPosts.test.ts
@@ -94,12 +94,15 @@ async function makeChannel(slug: string): Promise<string> {
}
const {
- fetchPosts,
+ fetchPosts: fetchPostsDirect,
FULL_AND_OLDER_REFUSAL,
EMPTY_ACCOUNT_OLDER_REFUSAL,
emptyAccountOlderProblem,
olderPostsProblem,
} = await import("./fetchPosts");
+// An X fetch runs only as the editor's job (X_ONLY_AS_A_JOB): these calls stand where one does.
+const { insideEditorJob } = await import("../testing/jobs/asEditorJob");
+const fetchPosts = insideEditorJob(fetchPostsDirect);
const {
readPostFetchState,
readSeenPostIds,
diff --git a/common/controller/fetchPosts.test.ts b/common/controller/fetchPosts.test.ts
@@ -116,7 +116,10 @@ await writeFile(
}),
);
-const { fetchPosts } = await import("./fetchPosts");
+// An X fetch runs only as the editor's job (X_ONLY_AS_A_JOB): these calls stand where one does.
+const { fetchPosts: fetchPostsDirect, X_ONLY_AS_A_JOB } = await import("./fetchPosts");
+const { insideEditorJob } = await import("../testing/jobs/asEditorJob");
+const fetchPosts = insideEditorJob(fetchPostsDirect);
const { readPostFetchState, readSeenPostIds } = await import("../lib/posts-server");
async function lastArgv(): Promise<string[]> {
@@ -441,3 +444,58 @@ test("a drain before the fetch starts reads nothing and spawns nothing", async (
assert.equal((await readFile(ARGS_LOG, "utf8")).trim().split("\n").length, before);
assert.equal(await readPostFetchState(root), null);
});
+
+// ── lane x-followups: X is asked only by the editor's jobs ─────────────────
+
+test("an X fetch outside the editor's job is refused, whatever the mode or the fetcher, and spawns nothing", async () => {
+ const paths = (await import("../lib/paths")).getPaths();
+ const { asEditorJob } = await import("../testing/jobs/asEditorJob");
+ const spawned = async () => (await readFile(ARGS_LOG, "utf8")).trim().split("\n").length;
+ const before = await spawned();
+ const stateBefore = await readFile(path.join(channelRoot, "posts-state.json"), "utf8");
+ // The sentence names the door.
+ assert.equal(
+ X_ONLY_AS_A_JOB(SLUG),
+ `${SLUG} is an X channel, and X is asked only by the editor's own jobs (on X's queue, spaced apart, on a fresh cookie jar, ` +
+ `stopped by the X alert and held after a rate limit): nothing was asked. Queue it instead: pnpm ops fetch-posts --json '{"slug":"${SLUG}"}' --wait`,
+ );
+ for (const mode of [{}, { backfill: true }, { full: true }, { older: true }, { limit: 5 }]) {
+ const r = await fetchPostsDirect({ paths, slug: SLUG, settings: {}, ...mode });
+ assert.deepEqual(r, { ok: false, written: 0, skipped: 0, complete: false, error: X_ONLY_AS_A_JOB(SLUG) }, JSON.stringify(mode));
+ }
+ // Every fetcher of the twitter platform: the rule does not hang on `postFetcher`.
+ for (const postFetcher of ["x-playwright", "x-nitter"]) {
+ const slug = `fake-${postFetcher}`;
+ const root = path.join(ROOT, "transcripts", "channels", slug);
+ await mkdir(root, { recursive: true });
+ await writeFile(
+ path.join(root, "config.json"),
+ JSON.stringify({ handling: "transcribe", sourceKind: "social", postFetcher, socialHandle: "faketester", platform: "twitter", name: "Fake (X)", url: "https://x.com/faketester" }),
+ );
+ assert.equal((await fetchPostsDirect({ paths, slug, settings: {} })).error, X_ONLY_AS_A_JOB(slug));
+ }
+ assert.equal(await spawned(), before, "gallery-dl was not started");
+ assert.equal(await readFile(path.join(channelRoot, "posts-state.json"), "utf8"), stateBefore, "the fetch state was not touched");
+ // Inside a job the same call runs (here: a refusal of its own, further in — no backfill is part-way).
+ const inside = await asEditorJob(() => fetchPostsDirect({ paths, slug: SLUG, settings: {}, backfill: true }));
+ assert.notEqual(inside.error, X_ONLY_AS_A_JOB(SLUG));
+});
+
+test("`archilyzer posts fetch` on an X channel exits 1 with the sentence naming pnpm ops fetch-posts, and starts no gallery-dl", async () => {
+ const { execFile } = await import("node:child_process");
+ const { createRequire } = await import("node:module");
+ const tsx = createRequire(import.meta.url).resolve("tsx/cli");
+ const before = (await readFile(ARGS_LOG, "utf8")).trim().split("\n").length;
+ const ran = await new Promise<{ code: number | null; stdout: string; stderr: string }>((resolve) => {
+ const child = execFile(
+ process.execPath,
+ [tsx, path.join(import.meta.dirname, "..", "bin", "fetch-posts.ts"), "--slug", SLUG],
+ { env: { ...process.env, NODE_OPTIONS: "" }, timeout: 60_000 },
+ (_err, stdout, stderr) => resolve({ code: child.exitCode, stdout, stderr }),
+ );
+ });
+ assert.equal(ran.code, 1, ran.stderr);
+ assert.equal(ran.stderr.trim(), `Failed: ${X_ONLY_AS_A_JOB(SLUG)}`);
+ assert.equal(ran.stdout.trim(), "");
+ assert.equal((await readFile(ARGS_LOG, "utf8")).trim().split("\n").length, before);
+});
diff --git a/common/controller/fetchPosts.ts b/common/controller/fetchPosts.ts
@@ -191,6 +191,24 @@ export const INSTAGRAM_ONLY_AS_A_JOB = (slug: string) =>
`${slug} is an Instagram channel, and Instagram is asked only by the editor's own jobs (one at a time, ten minutes ` +
`apart, held after a refusal): nothing was asked. Queue it instead: pnpm ops fetch-posts --json '{"slug":"${slug}"}' --wait`;
+// AN X FETCH RUNS ONLY AS THE EDITOR'S JOB TOO (lane x-followups; found by the
+// Instagram review). X's guards all live in the job funnel: X's queue (one X
+// job at a time), the gap between X jobs, the fresh-jar rule, the X alert, the
+// cooldown after a rate limit. A direct call — `pnpm archilyzer posts fetch
+// <x-channel>`, a script — met none of them: it asked X at once, on whatever
+// jar was there, beside whatever X job the editor was running. Every fetcher
+// of the twitter platform is covered (the account's timeline, the older walk,
+// an X search channel; gallery-dl, the Playwright fallback, Nitter), since the
+// channel's `postFetcher` is the operator's to change and the rule must not
+// depend on it. Bluesky, a forum thread and a web page keep the direct path:
+// their pacing is the fetcher's own (a forum's page pause, its browser
+// profile), and `posts fetch --pages N` on a forum thread is a documented way
+// to read without an editor (README).
+export const X_ONLY_AS_A_JOB = (slug: string) =>
+ `${slug} is an X channel, and X is asked only by the editor's own jobs (on X's queue, spaced apart, on a fresh ` +
+ `cookie jar, stopped by the X alert and held after a rate limit): nothing was asked. ` +
+ `Queue it instead: pnpm ops fetch-posts --json '{"slug":"${slug}"}' --wait`;
+
// A channel's fetcher is of the channel's platform (review 1, M3): a config
// naming X's fetcher on an Instagram channel (or the other way round) would
// run one platform's requests on another's queue, past its guard.
@@ -387,6 +405,12 @@ export async function fetchPosts(
const mismatch = fetcherPlatformMismatch(slug, config, fetcher);
if (mismatch) return { ok: false, written: 0, skipped: 0, complete: false, error: mismatch };
+ // X: only inside a job of the editor's (X_ONLY_AS_A_JOB says why). Asked
+ // before the search, older and timeline branches, so no mode slips past.
+ if (fetcher.platform === "twitter" && !currentJobContext()) {
+ return { ok: false, written: 0, skipped: 0, complete: false, error: X_ONLY_AS_A_JOB(slug) };
+ }
+
// AN X SEARCH CHANNEL (release 38): its query across accounts, walked in
// search windows — no handle, no timeline, no older walk (fetchXSearch.ts).
if (isXSearchChannel(config) && config.xSearch) {
diff --git a/common/controller/fetchXSearch.test.ts b/common/controller/fetchXSearch.test.ts
@@ -95,7 +95,10 @@ async function makeSearchChannel(slug: string, xSearch: Record<string, unknown>)
return channelRoot;
}
-const { fetchPosts } = await import("./fetchPosts");
+// An X fetch runs only as the editor's job (X_ONLY_AS_A_JOB): these calls stand where one does.
+const { fetchPosts: fetchPostsDirect, X_ONLY_AS_A_JOB } = await import("./fetchPosts");
+const { insideEditorJob } = await import("../testing/jobs/asEditorJob");
+const fetchPosts = insideEditorJob(fetchPostsDirect);
const { X_SEARCH_OLDER_REFUSAL } = await import("./fetchXSearch");
const { readPostFetchState, readSeenPostIds, readAllPosts, writePosts, writePostFetchState } = await import(
"../lib/posts-server"
@@ -296,3 +299,16 @@ test("a post another X channel holds is kept in the search channel too, once —
assert.match(full.log.join("\n"), /read 2 post\(s\), 0 new, 2 already archived/);
assert.match(full.log.join("\n"), /Starting the search walk afresh, as asked/);
});
+
+// Lane x-followups: X is asked only by the editor's jobs — an X search channel too.
+test("an X search fetch outside the editor's job is refused and spawns nothing", async () => {
+ const slug = "outside-search";
+ await makeSearchChannel(slug, { query: "zephyr", since: "2025-01-01", until: "2025-03-01" });
+ const before = (await argvLines()).length;
+ for (const mode of [{}, { full: true }, { older: true }, { backfill: true }]) {
+ const r = await fetchPostsDirect({ paths: getPaths(), slug, settings: LOGIN, olderWindowPauseMs: 0, ...mode });
+ assert.equal(r.ok, false);
+ assert.equal(r.error, X_ONLY_AS_A_JOB(slug), JSON.stringify(mode));
+ }
+ assert.equal((await argvLines()).length, before);
+});
diff --git a/common/testing/jobs/asEditorJob.ts b/common/testing/jobs/asEditorJob.ts
@@ -0,0 +1,28 @@
+// A CALL MADE AS THE EDITOR'S JOB, for tests of code that runs only inside
+// one: an X posts fetch (controller/fetchPosts.ts X_ONLY_AS_A_JOB) asks
+// `currentJobContext()` and refuses a caller that is no job. The real funnel
+// (jobs/streamCommand.ts runManagedFunction) gives every job this context; a
+// test that calls the controller directly, to look at what it does with a
+// fake gallery-dl, has to say it stands where a job does.
+//
+// X's queue by default (`platform:twitter`). Nothing of the funnel's guards
+// runs here: no queue, no gap, no jar rule — a test of THOSE goes through
+// runManagedFunction (jobs/pacingGuard.test.ts).
+
+import { runInJobContext, type JobContext } from "../../lib/jobContext";
+
+export const X_QUEUE_KEY = "platform:twitter";
+
+export function editorJobContext(over: Partial<JobContext> = {}): JobContext {
+ return { jobId: "test-job", kind: "fetch-posts", queueKey: X_QUEUE_KEY, onLog: () => {}, staleServices: new Set(), ...over };
+}
+
+// Run `fn` as a job's body.
+export function asEditorJob<T>(fn: () => T, over: Partial<JobContext> = {}): T {
+ return runInJobContext(editorJobContext(over), fn);
+}
+
+// The same function, every call of it made as a job's body.
+export function insideEditorJob<A extends unknown[], R>(fn: (...args: A) => R, over: Partial<JobContext> = {}): (...args: A) => R {
+ return (...args: A) => asEditorJob(() => fn(...args), over);
+}