# Pacing guard — no unpaced network job, X only on a fresh jar, a challenge stops X Lane `lane/pacing-guard`, 2026-10-23. ## Why On the night of 2026-10-23 an agent queued `fetch-posts` for 13 X accounts in one loop. The registry runs one job per queue and starts the next the moment one ends, so they ran ~0.6 s apart on a cookie jar exported 16 days earlier. X answered with a Cloudflare challenge; gallery-dl printed `[twitter][warning] Cloudflare challenge`, exited 0, read nothing, and every job ended `done`. The operator had to pass a human verification on the account. Operator, verbatim: "Let's be more cautious- only start X downloads with a recent cookie refresh", "yeah never do that, be very careful not to do that thing on any sort of site", "This should be enforced in Archilyzer, not just an AI standing rule". The same night a podcast feed channel's (`platform:megaphone.fm`) download-missing probed ~1,150 episodes with yt-dlp back to back to learn their titles for the download filter. ## What is enforced All of it in code, in the one job funnel (`runManagedFunction`, `common/jobs/streamCommand.ts`), driven by a declarative flag on the kind. 1. **`network` on a job kind** (`common/jobs/jobKinds.ts`). 40 kinds that send requests to a platform declare `network: true` (fetch-posts, capture-posts, import-post, check-post-availability, sync, download-*, import-one, import-archive-org, metadata-scan, store-playlist, refresh-metadata, fetch-window(s), record-live, persist-*, fetch-chat, auto-download-unit, the availability checks, import-page, save-page-now, wayback-scan, browser-lookup, find-copy, fetch-copies, whisper-video, transcribe-one, check-kept-deleted, import-media, recheck-service-cookies …); the two offline kinds on a platform queue (import-forum-pages, reextract-pages) declare `false`. `jobKinds.test.ts` fails if a platform-queue kind declares neither. A caller may mark one job `network: false` (a fetch-chat whose replay is already on disk only normalizes it); never the other way. 2. **No unpaced network job** (`common/jobs/networkGuard.ts`). A queue override of `""` (immediate) is refused for a network kind, before any job exists. `QueueControl` no longer offers "(immediate)" on an action whose default is a `platform:` queue. 3. **The gap between jobs on a platform queue** (`common/jobs/queueGap.ts`, `common/lib/jobGap.ts`). A network job on `platform:

` does not begin until `pacing.jobGapSeconds[p]` (else the built-in for p, else `default`) after the previous network job there ENDED. Built in: default 20, twitter 300, xenforo 60, bluesky 60; only keys the operator sets are stored. While it waits, the job is `running` (its queue slot held) and its log and /jobs row say `waiting 4m12s: X jobs are spaced 5 min apart (pacing.jobGapSeconds.twitter)`. Only a job that got past its guards counts as an end, so a refused job does not make the next one wait. The last end per queue is in memory and in `.jobs/queue-gaps.json`, so a restart is not a free pass. Cancel aborts the wait; Drain ends the job `done` without asking anything. 4. **X only on a fresh jar.** Before a network job aimed at X (its queue is `platform:twitter`, or its channel's platform is twitter) is queued, and again when its queue starts it (and once more after its gap), with the `"profile"` login source: refused unless the exported jar's mtime is within `social.x.maxCookieAgeMinutes` (absent 60, 0 off) and it carries an auth_token. The sentence: `X cookies were last refreshed 16 days ago (limit 60 min): press Refresh cookies (or Connect X account) on /settings, then fetch again.` With the `"browser"` source the age cannot be read: the job logs that and proceeds. Nothing refreshes the jar automatically — `refreshXCookies` loads x.com/home, itself a request to X. 5. **A challenge stops X.** `GalleryDlStream` records the first stderr line with a challenge word (`cloudflare`, `challenge`, `just a moment`, `captcha`) or an AUTH_ERROR_PATTERNS match on a warning/error line, on ANY exit code. The timeline walk, the older/search windows and the media capture then fail (posts read so far kept; `needsCookies`, an `error`) and raise **X as a cookie-alert service** (`"x"`, label "X", family `x`; `lib/serviceCookies.ts`) — one signal is enough. **While the X alert is raised, every X job is refused before it starts** with `X answered with a challenge at HH:MM UTC () and its cookie alert is up, so no X job starts: …, then Recheck on the dashboard.`, and the refused job is recorded on the alert for **Re-run stopped jobs**. A clean gallery-dl run notes a clean request (clears a pending one, remembers the last good URL). **Recheck for X sends X no request**: clean when the login on disk (the profile jar, or the browser's x.com auth_token last-sent time) was renewed after the alert was raised. The dashboard banner, `pnpm ops get services`, `recheck-service`, `dismiss-service`, `rerun-service-jobs` and `archilyzer doctor` carry it like the other services. 6. **A probe is a request.** Release 9 B2 let a video the download filter declined after only its metadata prefetch skip `sleepBetweenDownloadsSeconds`; now only an outcome with no attempt at all skips it (`madeNoRequest`, `common/ytdlp/runYtdlp.ts`). To keep that cheap: a channel with a download filter, no known platform, and a playlist that is mostly direct media files (a feed's enclosures) reads its feed ONCE per download run and writes each unscanned episode's title into the metadata-scan store (`common/controller/feedTitlePrefilter.ts`); `settledByTitleFilterIds` then declines a filtered episode with no request. Settings: `pacing.jobGapSeconds` (on /settings beside the download sleep: every platform, X, forums, Bluesky; a value equal to the built-in is not stored) and `social.x.maxCookieAgeMinutes` (the X account section). SETTINGS.md regenerated. Test-only: `E2E_JOB_GAP_SECONDS` and `E2E_X_MAX_COOKIE_AGE_MINUTES` replace the BUILT-IN values (the e2e server sets both to 0); a value written into settings.json still applies. ## The lanes The auto-download lane's units (`auto-download-unit`) ride the platform queues and are network jobs, so they wait `max(the lane's own gap, the queue gap)`: the lane already waits `sleepBetweenDownloadsSeconds` (+ the adaptive pace) after a unit settles before it queues the next on that platform. With the operator's 30 s sleep the 20 s default adds nothing; with the shipped default sleep (10 s) a YouTube unit starts 20 s after the last instead of 10. Other effects: a scheduler tick's syncs on one platform start 20 s apart; imports on archive.org's queue (import-page, save-page-now, import-archive-org) 20 s apart; a channel's X fetches 5 min apart. The transcription, digest, backfill and clip-window lanes are not on `platform:` queues and are unchanged. ## Verified - `pnpm typecheck` clean. `pnpm --filter yt-dlp-transcript-common test`: 5005 pass, 0 fail, 2 skipped (the two autoRunner computeLeafPending failures seen on main did not reproduce here). `pnpm test:scripts`: 1446 pass, 0 fail. `pnpm --filter editor test`: 370 pass. Docs: `archilyzer settings example --check`, `docs cli --check`, `docs env --check`, `docs files --check` clean. - `common/jobs/pacingGuard.test.ts` reproduces the night through the real funnel, the real fetch controller and the real gallery-dl fetcher against a fake binary: 13 `fetch-posts` on `platform:twitter`; job 1 meets the Cloudflare warning (exit 0) → job 1 `failed`, the X alert raised, jobs 2–13 refused at their start without spawning gallery-dl (one gallery-dl run in all), all 13 on the alert, a fourteenth refused at enqueue; with no challenge the 13 start ≥ 300 s apart on a fake clock and the second's log carries the waiting line; a 16-day-old jar is refused at enqueue and a jar that went stale while a job was queued refuses it at start; `""` is refused for a network kind and allowed for an offline one. - Unit tests: `jobs/queueGap.test.ts`, `jobs/networkGuard.test.ts`, `jobs/jobKinds.test.ts` (every platform kind decided), `lib/serviceCookies.test.ts` (X), `controller/recheckServiceCookies.test.ts` (X asks nothing), `controller/feedTitlePrefilter.test.ts`, `ytdlp/managedDownloadsSleep.test.ts` (a probe sleeps), `controller/fetchPosts.test.ts` (an auth failure now fails the fetch). - e2e (written, NOT run in the lane — the orchestrator runs the suite): `cookie-alerts.spec` (a stale jar's sentence, `""` refused, the fake gallery-dl's `challenged_user` answers with the challenge → the job fails, the next fetch is refused, the X banner, Recheck stale then clean after the jar is refreshed, then a fetch runs), `pacing.spec` (two download-missing jobs on `platform:youtube` with a 6 s gap: the /jobs row and the log), `queues.spec` (no "(immediate)" on Sync; an empty custom queue is refused — replaces "empty queue runs immediately"). ## Not done - A Bluesky or forum jar-age rule (X only, as asked). The forum's own challenge alert already existed; it still only logs and does not refuse the next forum job (a forum fetch has `retryOnBlock`). - The X Article/screenshot half of capture-posts loads pages through the profile, not gallery-dl; a challenge page there is not yet recognised (its media download through gallery-dl is).