Archilyzer · Source

archilyzer

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

commit c6c578de55b43b2fda1e756324d609cf8659af01
parent bdd7d9395d35a9fdbf8c2259772576b90f332bbe
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 18 Nov 2026 15:48:15 -0500

review 1: the guide, the ops help, the changelog and the plan of slices say what changed; the fake and the spec act it out

plans/instagram.md is the lane's rulings and slices. The fake gallery-dl has an
account whose lookup answers 429 and then goes on, as the real binary does.

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

Diffstat:
MCOMMANDS.md | 2+-
MENVIRONMENT.md | 2+-
MOPERATING.md | 49++++++++++++++++++++++++++++++++++---------------
Meditor/CHANGELOG.md | 17+++++++++++------
Meditor/e2e/fixtures/bin/fake-gallery-dl-instagram.mjs | 10+++++++++-
Meditor/e2e/instagram.spec.ts | 37+++++++++++++++++++++++++++++++++----
Aplans/instagram.md | 93+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mscripts/archilyzer-ops.mjs | 6++++--
8 files changed, 186 insertions(+), 30 deletions(-)

diff --git a/COMMANDS.md b/COMMANDS.md @@ -167,7 +167,7 @@ Drives a running editor over HTTP (`/api/ops/*`, the same actions its pages run) | `download-missing` | download-missing downloads every listed video the channel does not hold: {"slug"}. "ignoreArchive": true drops the download archive so listed videos it names are fetched again (recovery from a stale archive); "abortOnError": false carries on past a failure (default: stop at the first that is not one video's own). Paced on the platform's queue. "storedUrl": "fallback" \| "only" reads each video from the media URL its record stores when the page is rate-limited (or always), one file per 20 min; with one, a held platform's run goes ahead as "only". | | | `retry-bucket` | retry-bucket runs one bucket of a channel's report as one job, past any lane hold: {"slug", "bucket"}. "ids": \[...\] runs only those videos, and every one must be in the bucket (a stray id is refused, named); a job run with ids is not replayable, as a checkbox selection in the UI is not. "corruptFullSource" downloads again: the kept file is set aside, and comes back if the download fails; malformed again, the longer decode stays. A record that stores an Odysee media URL is read from that URL (as "only") until 2 such downloads are on record, then from the page. "storedUrl": "fallback" \| "only" reads each from the media URL its record stores, as on download-missing (a held platform's retry runs as "only"). "corruptHeldAudio" (held audio the audio audit found damaged) is refetched the same way, with the audio check on; the new file is audited again. | `pnpm ops retry-bucket --json '{"slug":"demo-odysee","bucket":"corruptHeldAudio"}' --wait` | | `transcribe-bucket` | transcribe-bucket transcribes a channel's "downloaded, not transcribed" bucket on the transcription queue, as the channel page's Transcribe button does: {"slug"}. "ids": \[...\] narrows it the same way as on retry-bucket. | | -| `fetch-posts` | fetch-posts fetches a social channel's new posts: {"slug"} is SYNC NEW — from the top of the timeline down to the newest archived post (a sync that stopped part-way continues down to the watermark it began with). It never reads or clears an unfinished backfill's resume point. "backfill": true is RESUME BACKFILL instead (the same as resume-backfill). "full": true re-walks the whole timeline; "older": true walks back from the oldest archived post through search (X; needs a login), saving its place for the next run, down to "floor": "YYYY-MM-DD" when given; "from": "YYYY-MM-DD" starts the walk afresh there, replacing its saved place (and a "complete") — for a gap above one surviving old post. "limit": N caps the posts one run reads; "pages": N caps the pages (a forum thread: its latest N pages). A forum thread keeps two positions: a run catches up from the last page, then continues the history where it stopped; "full": true is its full re-walk (every page, edits updated). "retryOnBlock": {"minutes": 30, "max": 12} (or true: the forum default in settings) waits out a challenge or refusal page and runs again, max tries in all. "full", "older" and "backfill" are one at a time. An older walk over an account that shows no posts (nothing archived, and the last timeline fetch read none) is refused unless "force": true. AN INSTAGRAM CHANNEL: a sync reads ONE page (up to 30 posts), a first fetch, "full" or "backfill" walks up to 300 posts and the next run resumes; the new posts' pictures and videos are fetched in the same job (40 files / 200 MB a job, 100 MB a file; the rest is recorded as owed). Refused before a job exists when the channel has no cookiesFromBrowser of its own, and with "retryOnBlock" or "older". A login, challenge or checkpoint page raises Instagram's alert and refuses every Instagram job until recheck-service; the first 429 holds Instagram for an hour (clear-platform-hold {"platform": "instagram"} ends that by hand). A drained fetch stops at its next resume point and the next run of the same walk resumes there. | `pnpm ops fetch-posts --json '{"slug":"example-x"}' --wait` | +| `fetch-posts` | fetch-posts fetches a social channel's new posts: {"slug"} is SYNC NEW — from the top of the timeline down to the newest archived post (a sync that stopped part-way continues down to the watermark it began with). It never reads or clears an unfinished backfill's resume point. "backfill": true is RESUME BACKFILL instead (the same as resume-backfill). "full": true re-walks the whole timeline; "older": true walks back from the oldest archived post through search (X; needs a login), saving its place for the next run, down to "floor": "YYYY-MM-DD" when given; "from": "YYYY-MM-DD" starts the walk afresh there, replacing its saved place (and a "complete") — for a gap above one surviving old post. "limit": N caps the posts one run reads; "pages": N caps the pages (a forum thread: its latest N pages). A forum thread keeps two positions: a run catches up from the last page, then continues the history where it stopped; "full": true is its full re-walk (every page, edits updated). "retryOnBlock": {"minutes": 30, "max": 12} (or true: the forum default in settings) waits out a challenge or refusal page and runs again, max tries in all. "full", "older" and "backfill" are one at a time. An older walk over an account that shows no posts (nothing archived, and the last timeline fetch read none) is refused unless "force": true. AN INSTAGRAM CHANNEL: a sync reads ONE page (up to 30 posts), a first fetch, "full" or "backfill" walks up to 120 posts and the next run resumes; the new posts' pictures and videos are fetched in the same job (a sync 40 files / 200 MB, a walk 120 / 600 MB, 100 MB a file; a walk leaves the posts whose media would not fit for its next run; what is still not fetched is recorded as owed, and none after a refusal). Refused before a job exists when the channel has no cookiesFromBrowser of its own, and with "retryOnBlock" or "older". A login, challenge or checkpoint page raises Instagram's alert and refuses every Instagram job until recheck-service; the first 429 holds Instagram for an hour (clear-platform-hold {"platform": "instagram"} ends that by hand). A drained fetch stops at its next resume point and the next run of the same walk resumes there. | `pnpm ops fetch-posts --json '{"slug":"example-x"}' --wait` | | `resume-backfill` | resume-backfill continues a social channel's unfinished full-history timeline walk (X, Bluesky) from its saved resume point, with no watermark: {"slug"} ("limit"? caps the posts this run reads). The walk is left part-way by a first fetch, a full re-walk or a backfill that stopped; the channel page then says "backfill unfinished — N archived" and shows Resume backfill. Nothing resumes it but this (or fetch-posts "backfill": true): a plain fetch-posts, Sync and the scheduler sync new posts and keep its place. Refused when none is part-way, on a forum thread (every fetch catches up, then continues its history) and on an X search channel. | `pnpm ops resume-backfill --json '{"slug":"example-x"}' --wait` | | `capture-posts` | capture-posts captures archived posts of a social channel (X, forum, Bluesky): a screenshot of each through the connected X profile (a forum thread: its host's forum profile; Bluesky: a headless browser with no login on bsky.app, the shot cropped to the post), and its attached media through gallery-dl (a forum thread: the same profile; Bluesky: its images from the CDN), into the channel's posts-media/&lt;id&gt;/: {"slug", "ids": \[...\]}. Every id must be in the channel's posts archive. An Instagram channel is refused: no screenshot is taken of an Instagram post, and its media come with the post, in the fetch-posts job. "shots": false or "media": false skips that half; posts already captured are skipped unless "force": true. A post that links to an X Article also gets the article (article.json, .md, .png and its images) unless "articles": false; both halves off with "articles": true reads only the articles. "thread": true (X; default the channel's postCaptureThread) also shoots each reply with the post it answers above it, as shot-thread.png beside shot.png (a post shot before gets only that); the replied-to author's avatar, name and handle are blurred unless verified or the reply's own. "threadRedact": false turns the blur off, true blurs any author; {"&lt;id&gt;": false} sets it per post. X also keeps each author's avatar, read off the page the shot loads (with "thread", the replied-to and quoted authors' too), in posts-media/\_avatars/&lt;handle&gt;.&lt;ext&gt; + avatars.json; an author already stored is not fetched again unless "force". "avatars": false turns that off. "avatarsOnly": true (X) loads ONE post page per distinct archived author for the avatars alone -- no shot, media, article or thread shot, no capture record, no availability: one author's avatar is {"slug", "ids": \["&lt;one of their post ids&gt;"\], "avatarsOnly": true}. X also reads each post's CONTEXT off the same page -- the post it quotes and the post it answers (its author, check, date, words, media links) -- into its capture.json's "context"; "context": false turns that off. "contextOnly": true (X) loads ONE page per post for that alone (and the avatars it shows): the context written into capture.json, nothing shot, no media, article, thread shot or availability; a post whose context is already read is skipped unless "force". Not with "avatarsOnly". Paced like a post fetch, on its queue. An X trending library is captured by this same job, under channels/&lt;slug&gt;/trending/posts-media/&lt;id&gt;/. Its media comes from X's media CDN by the addresses in the library's saved captures: no login, one file after another 1-2 s apart, under X's cooldown, each file kept once (trending/media-store/, a hardlink per post). A file over the library's maxVideoMb (100 MB) and whatever is past the job's budget (40 files / 200 MB) is owed: asked for again by the next capture of that post. A 429 from the CDN stops the job and leaves X alone for 15 minutes; a 403 or 404 marks the file; three refusals in a row (a 403, or no answer) and the job asks the CDN no more; nothing retries. "keptMedia": true is for posts marked keep (refused for any other id): no per-file cap, and a post the CDN cannot serve whole is downloaded the logged-in way, if it is still kept when that download would start. A library's capture runs on X's queue only: "queueKey" is refused for it. | | | `publish` | publish runs publish stages on the editor's publish queue, one at a time, under one run id: {"verb": …}. "index" updates the index; "build" builds "siteId"/"siteIds" (forced; the index first when stale; "runner": "docker" builds every site in containers; "allowMissingMedia": true lets a report citation with no prepared media through compose, local builds only); "deploy" ships their built bundles (production, "preview": "&lt;branch&gt;", or "to": "local"; "force" redeploys a bundle already shipped there); "hub" / "homepage" build them, {"deploy": true} deploys after; "now" is Publish now (the stale index, then each policy target); "stale" builds every stale site. The answer lists every job ({target, kind, jobId}) and --wait follows them all. A site never built is refused: "no build of &lt;id&gt; in &lt;dir&gt; — archilyzer publish build &lt;id&gt;". `get publish` is the status. | | diff --git a/ENVIRONMENT.md b/ENVIRONMENT.md @@ -231,7 +231,7 @@ Read only by a test harness, a fake binary or a test-mode branch. Never set one | Variable | Default | What it does | Read by | |---|---|---|---| -| `E2E_TEST_ROUTES` | off | `1` opens the editor's `/api/test/*` routes and marks a test server at boot. Set by `editor/playwright.config.ts` on its test server, and by nothing else. | editor/app/api/test/_guard.ts, editor/instrumentation.ts | +| `E2E_TEST_ROUTES` | off | `1` opens the editor's `/api/test/*` routes and marks a test server at boot. Under it Instagram's media CDN is played back, never asked (`fakeInstagramMediaDeps`). Set by `editor/playwright.config.ts` on its test server, and by nothing else. | editor/app/api/test/_guard.ts, editor/instrumentation.ts, common/social/instagramMedia.ts, common/social/fakeXProfileBrowser.ts | | `E2E_MODE` | `start` | `start`: the editor and umtool suites run against `next start` from a build `scripts/e2e-stamp.mjs` vouches for, rebuilt through the heavy slot when the tree moved. `dev`: against `next dev`, for iterating on one spec. The export and homepage suites always run `next dev` (static exports) and say so when asked for `start`. | editor/playwright.config.ts, umtool/playwright.config.ts, scripts/e2e-stamp.mjs | | `E2E_NEXT_DIST_DIR` | `.next` | The editor's build directory for the e2e suite's start mode (`.next/e2e`), so a test build never replaces the `.next` a running editor serves from. Set by `scripts/e2e-stamp.mjs` for its build and by `editor/playwright.config.ts` for its test server — and for the editor suite's export dev server (`.next/e2e-editor`), which then runs beside the export suite's own (Next allows one `next dev` per dist dir). | editor/next.config.ts, export/next.config.ts | | `E2E_MODEL_LOG_SHOTS` | unset (no screenshots) | A directory: the model log's e2e (demo epic D3) saves its 1366×768 screenshots of the panel there — the run page live and done, a call opened, the Iterations tab, a media draft, the settings table, the editor's job page — for a lane's report. Unset, none is taken. | umtool/e2e/model-log.spec.ts, editor/e2e/report-draft.spec.ts | diff --git a/OPERATING.md b/OPERATING.md @@ -599,7 +599,7 @@ pnpm ops capture-posts --json '{"slug":"example-x","ids":["<postId>"]}' --wait pnpm ops create-channel --json '{"fields":{"name":"Example (Instagram)","handling":"transcribe","url":"https://www.instagram.com/example.account/","cookiesFromBrowser":"firefox:instagram-archive"}}' pnpm ops channel-config --json '{"slug":"example-instagram","patch":{"cookiesFromBrowser":"file:/data/instagram-archive-cookies.txt"}}' pnpm ops fetch-posts --json '{"slug":"example-instagram"}' --wait # the first: a walk; after it: sync new, one page -pnpm ops resume-backfill --json '{"slug":"example-instagram"}' --wait # the walk's next 300 posts +pnpm ops resume-backfill --json '{"slug":"example-instagram"}' --wait # the walk's next 120 posts pnpm ops recheck-service --json '{"service":"instagram"}' # the operator's word, no request pnpm ops clear-platform-hold --json '{"platform":"instagram"}' # end the hour's hold by hand pnpm ops settings --json '{"patch":{"social":{"instagram":{"visibility":"public"}}}}' @@ -617,27 +617,46 @@ pnpm ops settings --json '{"patch":{"social":{"instagram":{"visibility":"p if it follows them. Nothing logs in or refreshes a session by itself. - **What a run costs, and it says so.** gallery-dl sleeps 6–12 s before every request. A sync is ONE feed page (up to 30 posts), plus up to two requests for the account's id the first time. A walk (the first fetch, - `"full"`, `resume-backfill`) reads up to 300 posts and stops; the next run resumes from its cursor, re-reading - that one page. A run is stopped at 4 requests (a sync) or 13 (a walk). Its log ends `This run cost Instagram N - request(s) and its CDN F file(s).` + `"full"`, `resume-backfill`, a sync that continues) reads up to 120 posts and stops; the next run resumes from + its cursor, re-reading that one page. A run is stopped at 4 requests (a sync) or 7 (a walk). Its log ends + `This run cost Instagram N request(s) and its CDN F file(s).` The log never prints the cookie source. +- **A sync that finds a whole page of new posts continues**: the next Sync new walks on from the top, skips what + it archived, and stops only at the newest post the archive held when the sync began. Nothing between is dropped. - **Media come with the post, in the same job.** Their addresses are signed and expire, so the new posts' - pictures and videos are fetched at once: one GET per file with no cookies, 2–5 s apart, at most 40 files or - 200 MB a job and 100 MB a file, into `channels/<slug>/posts-media/<post id>/` beside a `capture.json`. What a - job did not fetch is recorded as owed (`mediaOwed`); three CDN refusals in a row end the media half. Nothing - collects owed media yet. `posts-media/` is not in the media tier: it stays on the corpus disk. + pictures and videos are fetched at once: one GET per file with no cookies and no referer, a plain `Mozilla/5.0` + User-Agent, 2–5 s apart, only from hosts under `.cdninstagram.com` or `.fbcdn.net`, into + `channels/<slug>/posts-media/<post id>/` beside a `capture.json`. A sync may fetch 40 files or 200 MB, a walk + 120 files or 600 MB, a file at most 100 MB; the media half has 20 minutes and a file 5. + **A walk is sized to its media**: it lists as many posts as its budget has files, and the posts whose media + would not fit are left for the next run, which lists them again. So a post a run archives has its media asked + for in that run. What was still not fetched (a file over the cap, a CDN refusal, a drain) is recorded as owed + (`mediaOwed`) and the log says how many posts; nothing collects owed media yet. Three CDN refusals in a row + end the media half. `posts-media/` is not in the media tier: it stays on the corpus disk. - **A post's id is its numeric media pk**, not the shortcode in its URL. The two convert both ways with no request (`common/lib/instagram/ids.ts`); the post keeps its shortcode in `instagram.shortcode`. - **Pacing.** Instagram jobs run one at a time, ten minutes apart (`pacing.jobGapSeconds.instagram`, 600). A - channel is synced every 12 hours at the most often, 4 hours with a `syncIntervalMinutes` of its own. -- **Nothing is retried.** The first 429 (or 401/403) ends the run, keeps what it read, and holds every Instagram - job for 60 minutes. A login, challenge or checkpoint page — and the "Page Not Found" a dead session gets — - raises Instagram's alert on the dashboard: every Instagram job is refused until a person passes the check in - that browser and presses **Recheck** (`recheck-service`), which sends Instagram no request and is taken on the - operator's word. The recheck timer never asks Instagram. `retryOnBlock` is refused. + channel is synced every 12 hours at the most often, 4 hours with a `syncIntervalMinutes` of its own. The + scheduler does not queue a channel with no cookie source, nor any Instagram channel while Instagram is held; + /operations/sync says why. A restart never re-queues an interrupted Instagram fetch: its place is saved and + the next scheduled or pressed sync continues. +- **Only the editor's jobs ask Instagram.** `pnpm archilyzer posts fetch <slug>` refuses an Instagram channel and + names `pnpm ops fetch-posts`; a channel whose `postFetcher` is another platform's is refused. yt-dlp is never + started on an instagram.com URL (`import-video` says so; a single reel's import comes later). +- **Nothing is retried.** The first 429 ends the run, keeps what it read, and holds every Instagram job for 60 + minutes. So does one 401 or 403; a second in a row with no clean read between raises the alert instead. A + login, challenge or checkpoint page — and the "Page Not Found" a dead session gets — raises Instagram's alert + on the dashboard at once: every Instagram job is refused until a person passes the check in that browser and + presses **Recheck** (`recheck-service`), which sends Instagram no request and is taken on the operator's + word. The recheck timer never asks Instagram. A refusal during the account lookup ends the run too (gallery-dl + would carry on to the feed). **After a refusal no media is asked for either**: the posts the run read are + archived with their media owed. `retryOnBlock` is refused. - **An account is "gone" only when its own page answers 404.** A private account the login does not follow, and a gone account, end the job with a sentence and raise no alert. - **Private by default.** An Instagram channel's posts are built only into private sites unless - `social.instagram.visibility` is `"public"` (`common/lib/postsVisibility.ts`). + `social.instagram.visibility` is `"public"` (`common/lib/postsVisibility.ts`). A Wayback pages channel scoped to + instagram.com follows the same setting, and a capture of an instagram.com page is refused by any other pages + channel while Instagram is private. A flip from public back to private is tombstoned on the hub and refuses a + stale homepage build, as X's is. ### X search diff --git a/editor/CHANGELOG.md b/editor/CHANGELOG.md @@ -8,12 +8,17 @@ **Cookies from browser** in the Source section and the channel never borrows the global browser; with none set, a fetch is refused before a job exists. Use an account made for the archive: Instagram may checkpoint or ban an account that reads this way. - - **Gentle by rule.** One Instagram job at a time, ten minutes apart. A sync reads one page; a walk reads up to - 300 posts and resumes. Nothing is retried: the first 429 holds Instagram for an hour, and a login, challenge - or checkpoint page raises Instagram's alert, which refuses every Instagram job until **Recheck**. A run says - what it cost in requests and files. A channel is synced every 12 hours at the most often. - - **Media come with the post**, in the same job, because their addresses expire: up to 40 files or 200 MB a - job, 100 MB a file, into `posts-media/<post id>/`. The rest is recorded as owed. + - **Gentle by rule.** One Instagram job at a time, ten minutes apart, and only as the editor's job (the CLI's + `posts fetch` refuses and names `pnpm ops fetch-posts`). A sync reads one page; a walk reads up to 120 posts + and resumes. Nothing is retried: the first 429 (or one 401/403) holds Instagram for an hour; a login, + challenge or checkpoint page, or a second 401/403 in a row, raises Instagram's alert, which refuses every + Instagram job until **Recheck**. A run says what it cost in requests and files. A channel is synced every 12 + hours at the most often; the scheduler skips one it could not fetch and says why. yt-dlp is never started + on an instagram.com URL. + - **Media come with the post**, in the same job, because their addresses expire: only from Instagram's CDN + hosts, a sync up to 40 files or 200 MB, a walk 120 files or 600 MB, 100 MB a file, into + `posts-media/<post id>/`. A walk leaves the posts whose media would not fit for its next run; what is still + not fetched is recorded as owed, and nothing is asked of the CDN after a refusal. - **Private by default**: built only into private sites unless `social.instagram.visibility` is `"public"`. - Stories, highlights, screenshots and transcription are not built yet. OPERATING.md, "Instagram accounts". - **A trending library's topics can be organised, and a topic published.** diff --git a/editor/e2e/fixtures/bin/fake-gallery-dl-instagram.mjs b/editor/e2e/fixtures/bin/fake-gallery-dl-instagram.mjs @@ -14,6 +14,9 @@ // ig_loginwall a redirect to the login page // ig_challenge a redirect to the challenge page // ig_ratelimited one page, then 429 on the next +// ig_lookup429 the account search answers 429 — and, as the real binary +// does (it swallows the lookup's exceptions), the run GOES ON +// to the profile page and the feed unless it is stopped // ig_private a private account the login does not follow // ig_gone the search and the profile page both answer 404 // anything else an account of 75 posts: two pinned on top (one of them @@ -129,7 +132,12 @@ export async function runInstagram(args) { req(`/${handle}`, 404); fail("NotFoundError", "Requested user could not be found"); } - req(`/web/search/topsearch/?query=${handle}`); + if (handle === "ig_lookup429") { + req(`/web/search/topsearch/?query=${handle}`, 429); + // What gallery-dl does next, a moment later: the profile page, then the feed. + await new Promise((r) => setTimeout(r, 1500)); + req(`/${handle}`, 200); + } else req(`/web/search/topsearch/?query=${handle}`); if (handle === "ig_loginwall") { req(feed, 302); fail("AbortExtraction", "HTTP redirect to login page (https://www.instagram.com/accounts/login/)"); diff --git a/editor/e2e/instagram.spec.ts b/editor/e2e/instagram.spec.ts @@ -126,11 +126,14 @@ test("no cookie source, nothing is asked; with one, a walk archives posts and th expect(first).toHaveLength(59); expect(first).toContain(pk(3)); // the old pinned post, far below the walk's reach const log = await jobLog(walk.body.jobId!); - expect(log).toContain(`Instagram login: this channel's cookie source (${COOKIES})`); + // The cookie source is never printed. + expect(log).toContain("Instagram login: the channel's own cookie source, read by gallery-dl."); + expect(log).not.toContain("instagram-archive-cookies"); expect(log).toContain("Walking up to 60 posts from the top."); expect(log).toContain("Cost: 3 request(s) to Instagram (1 for the account's id, 2 feed page(s))."); - expect(log).toContain("This job's media budget (40 files / 200 MB) is used: the rest is owed to a later capture."); - expect(log).toContain("This run cost Instagram 3 request(s) and its CDN 40 file(s)."); + // A walk's posts get their media in the same run: 71 files, inside its budget of 120. + expect(log).toMatch(/Media: 71 file\(s\) fetched from its CDN \(0 MB\); 59 of 59 post\(s\) whole\./); + expect(log).toContain("This run cost Instagram 3 request(s) and its CDN 71 file(s)."); expect(log).toContain("more history remains"); const state = await readJson<{ backfill?: { cursor?: string } }>(channelRel(slug, "posts-state.json")); expect(state.backfill?.cursor).toBe("page-2"); @@ -245,6 +248,7 @@ test("the first 429 ends the run and holds Instagram for an hour; a private acco await makeChannel(request, "ig-private", "ig_private"); await makeChannel(request, "ig-gone", "ig_gone"); await makeChannel(request, "ig-limited", "ig_ratelimited"); + await makeChannel(request, "ig-lookup", "ig_lookup429"); await makeChannel(request, "ig-ok", "ig_fake"); const priv = await ops(request, "fetch-posts", { slug: "ig-private" }); @@ -260,7 +264,15 @@ test("the first 429 ends the run and holds Instagram for an hour; a private acco expect(limited.body.ok).toBe(true); expect(await waitJob(request, limited.body.jobId!)).toBe("failed"); const log = await jobLog(limited.body.jobId!); - expect(log).toMatch(/Instagram refused the read \(HttpError: '429 Too Many Requests'.*a rate limit/); + expect(log).toMatch(/Instagram refused the read \(GET \/api\/v1\/feed\/user\/\d+\/ answered 429\): a rate limit/); + // After a refusal nothing more is asked of Instagram, its CDN included: the posts are archived, their media owed. + expect(log).toMatch(/Media: none asked for\. Instagram refused the listing, so its CDN is not asked either; \d+ post\(s\) are archived with their media owed/); + expect(log).toMatch(/This run cost Instagram 3 request\(s\) and its CDN 0 file\(s\)\./); + const limitedIds = await archivedIds("ig-limited"); + const owed = await readJson<{ mediaState: string; mediaOwed?: string; media: unknown[] }>( + channelRel("ig-limited", `posts-media/${limitedIds[0]}/capture.json`), + ); + expect(owed).toMatchObject({ mediaState: "error", mediaOwed: "next", media: [] }); expect(log).toMatch(/no Instagram job starts before \d\d:\d\d UTC \(60 min\)\. Nothing retries by itself\./); // What the first page held is archived, with the resume point for the page that was refused. expect((await archivedIds("ig-limited")).length).toBeGreaterThan(20); @@ -277,4 +289,21 @@ test("the first 429 ends the run and holds Instagram for an hour; a private acco const after = await ops(request, "fetch-posts", { slug: "ig-ok", limit: 60 }); expect(after.body.ok).toBe(true); expect(await waitJob(request, after.body.jobId!)).toBe("done"); + + // A 429 DURING THE ACCOUNT LOOKUP: gallery-dl swallows it and would go on to the feed. The run is stopped at that + // line — one request — and Instagram is held, as for any 429. + const lookup = await ops(request, "fetch-posts", { slug: "ig-lookup" }); + expect(lookup.body.ok).toBe(true); + expect(await waitJob(request, lookup.body.jobId!)).toBe("failed"); + const lookupLog = await jobLog(lookup.body.jobId!); + expect(lookupLog).toContain("Cost: 1 request(s) to Instagram (1 for the account's id, 0 feed page(s))."); + expect(lookupLog).toMatch(/Instagram refused the read \(GET \/web\/search\/topsearch\/ answered 429\): a rate limit/); + expect(await archivedIds("ig-lookup")).toHaveLength(0); + expect((await ops(request, "fetch-posts", { slug: "ig-ok" })).body.error).toMatch(/^Instagram answered a rate limit a short while ago/); + expect((await ops(request, "clear-platform-hold", { platform: "instagram" })).body.ok).toBe(true); + + // yt-dlp is never started on an instagram.com URL: import-video says so before a job exists. + const reel = await ops(request, "import-video", { slug: "ig-ok", url: "https://www.instagram.com/reel/CabcDEF1234/" }); + expect(reel.status).toBe(400); + expect(reel.body.error).toMatch(/Instagram is read as a posts channel; a single reel import comes with a later slice/); }); diff --git a/plans/instagram.md b/plans/instagram.md @@ -0,0 +1,93 @@ +# Instagram accounts as posts channels + +Lane `lane/instagram`, begun 18 Nov 2026. Guide: OPERATING.md, "Instagram accounts". + +## The ask + +An Instagram account becomes a posts channel, as an X account is: posts with their text, images, videos and +reels, carousels, dates and links; and stories, which vanish in 24 h. Research reads and cites them like any +post; video with speech should be transcribable. + +## Rulings + +These are rulings, not reasons. A later ruling overturns an earlier one only when it says so. + +**Safety** + +- All Instagram traffic goes through the editor's Instagram queue (`platform:instagram`): one job at a time, + ten minutes apart, only as the editor's own job. Never a burst, never a retry. +- A login is required: logged out, the feed answers "Page Not Found" (one read, 18 Nov 2026). The cookie source + is the channel's own `cookiesFromBrowser`, never the global browser. The operator will use an account made + for the archive. Nothing logs in or refreshes a session unattended. +- The first 429 ends the run and holds Instagram for 60 minutes. One 401/403 does the same; a second in a row + with no clean read between raises the alert. A login, challenge or checkpoint page raises Instagram's alert, + which refuses every Instagram job until a person's Recheck (no request). The recheck timer never asks. +- After a refusal in the listing no media is asked for: everything Instagram stops, its CDN too. +- A request line is read as it arrives: a refusal during the account lookup ends the run (gallery-dl swallows + it). Posts with no request line read are a failure. +- A logged-out 404 on the search or the feed is the login, never "account gone". An account is gone only when + its own page answered 404. +- yt-dlp is never started on an instagram.com URL (slice 1). A single reel's import is a later slice's. +- Development and tests use invented fixtures and the fake gallery-dl. No test opens a socket. + +**The store** + +- A post's id is its numeric media pk; the shortcode is kept in `Post.instagram` and converts both ways. +- A carousel is one post with several media; a reel is one video. A collaboration's author is the owner; the + channel's account is among `coauthors`. +- Media are fetched in the fetch job (their addresses expire): only from `.cdninstagram.com` / `.fbcdn.net`, no + cookies, no referer, `Mozilla/5.0`. A sync: 40 files / 200 MB. A walk: 120 files / 600 MB, and it lists no + more posts than that, leaving the posts whose media would not fit for the next run. A file: 100 MB. +- `posts-media/` is not in the media tier. +- Instagram posts are private unless `social.instagram.visibility` is `"public"`, by X's rule shape. A Wayback + pages channel scoped to instagram.com follows it. Stories are never public. + +## Slice 1, as built (fetcher, store, channel, ops) + +- Platform `instagram`: `common/lib/instagram/` (ids, the yt-dlp refusal), `Post.instagram`, the job gap, + the visibility rule, the per-platform guard table (`common/jobs/networkGuard.ts PLATFORM_GUARDS`, + `instagramGuard.ts`), the service alert. +- Fetcher `instagram-gallery-dl` (`common/social/instagramGalleryDlFetcher.ts`, `instagramSignals.ts`, + `instagramNormalize.ts`), media (`instagramMedia.ts`), the controller's part (`controller/fetchPosts.ts`). +- gallery-dl runs with `--dump-json` and NOT `output.jsonl`: with it on, the exception that ended a run is + printed nowhere and the run exits 0. A stopped run is stopped with SIGINT, which prints what it has. +- Sync new: one page. A walk: 120 posts, then the cursor. A sync whose page is all new continues from the + top down to its watermark, skipping what it archived. +- The scheduler: every 12 h at the most often (4 h with an interval of its own); no slot for a channel with no + cookie source or while Instagram is held; a restart never re-queues an Instagram job. +- The channel form asks for the cookie source in the Source section. `capture-posts`, `retryOnBlock`, the + older walk and the deleted-posts sweep refuse an Instagram channel by name. +- Tests: `common/lib/instagram/*.test.ts`, `common/social/instagram*.test.ts`, + `common/jobs/instagram*.test.ts`, `editor/e2e/instagram.spec.ts` with + `editor/e2e/fixtures/bin/fake-gallery-dl-instagram.mjs`. + +**Review 1 (18 Nov), as fixed.** M1 a continuing sync dropped the gap (it stopped at its own posts); M2 a +refusal during the lookup did not end the run; M3 the CLI's `posts fetch` ran past the guard, and a fetcher +of another platform could. S1–S13: digits inside captions, no media after a refusal, the media half's +deadline, host allowlist, User-Agent, write errors, a walk sized to its media, the second 401/403, private +before the error row, the scheduler's skips, yt-dlp refused, Wayback captures and tombstones, the cookie +source out of the log. + +## Slice 2 (not built): stories, the cookie row, owed media + +- `fetch-stories` on the same queue, a per-channel switch with its own interval (off by default), and a timer + armed below the idle gate. Stories need the login; a story deleted before the next read is missed. +- A row on /cookies and a jar of its own with an age rule; nothing refreshes it unattended. +- **The owed-media collector**: `capture-posts` for Instagram (media only, one request per post for fresh + addresses). Slice 1 records `mediaOwed` and collects nothing. +- An ops read of what an Instagram job would be told now (the alert, the hold), as `get x-session` is for X. + +## Slice 3 (not built): viewer, export, transcription + +- PostBody: a kind badge, a carousel, a story's expiry. Published captures for a public Instagram channel. +- `import-post` for one Instagram URL; a single reel's import (through the fetcher, never yt-dlp). +- Highlights, by hand. +- Transcription of a post's video: nothing transcribes `posts-media/` today, for any platform. +- The deleted-posts sweep. + +## Open + +- A logged-in probe (the fetcher's own argv, 3 posts) has not been run: the row shape, the page size, the + cursor line and the CDN hosts are from gallery-dl 1.32.9's source. +- A `--cookies-from-browser` spec that yields no session is not detected before the run: it costs three + requests logged out, then raises the alert. diff --git a/scripts/archilyzer-ops.mjs b/scripts/archilyzer-ops.mjs @@ -1949,9 +1949,11 @@ export function usage() { ' older walk over an account that shows no posts (nothing archived, and', ' the last timeline fetch read none) is refused unless "force": true.', " AN INSTAGRAM CHANNEL: a sync reads ONE page (up to 30 posts), a first", - ' fetch, "full" or "backfill" walks up to 300 posts and the next run', + ' fetch, "full" or "backfill" walks up to 120 posts and the next run', " resumes; the new posts' pictures and videos are fetched in the same job", - " (40 files / 200 MB a job, 100 MB a file; the rest is recorded as owed).", + " (a sync 40 files / 200 MB, a walk 120 / 600 MB, 100 MB a file; a walk", + " leaves the posts whose media would not fit for its next run; what is", + " still not fetched is recorded as owed, and none after a refusal).", " Refused before a job exists when the channel has no cookiesFromBrowser", ' of its own, and with "retryOnBlock" or "older". A login, challenge or', " checkpoint page raises Instagram's alert and refuses every Instagram job",