commit 80a61994a65374a255cc16b8265976bf3d98294d
parent 3240571994585fd098839df6051545114192ded2
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Tue, 20 Oct 2026 18:30:40 -0400
plans: release 37 lane G — the record (forum-resume.md), as shipped
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
1 file changed, 131 insertions(+), 0 deletions(-)
diff --git a/plans/release-37/forum-resume.md b/plans/release-37/forum-resume.md
@@ -0,0 +1,131 @@
+# Release 37 lane G — `r37/forum-resume`: a forum walk that resumes, never re-crawls (as shipped)
+
+The operator, 2026-10-20: "change the walk to track the last page and be able to resume rather than always
+re-crawling, even if things could change. We can have two buttons like a channel's sync and full fetch." The bug seen
+live: a run capped with `pages: 3` caught up the 3 newest pages and stored its catch-up position as THE cursor,
+replacing the history cursor (2340 → 2593), and the next run re-read ~250 held pages in history mode. One cursor
+served two walks. Rulings followed: no model anywhere; every operation has a button (Fetch posts, Full re-walk, Retry
+after a block); polite (the walk's pace is unchanged, a retry waits minutes, never sooner); synthetic fixtures only
+(no real forum, no network — a saved-pages directory and a fake thread); commits end with the one Co-Authored-By
+trailer.
+
+## What
+
+1. **Two positions** — `posts-state.json` `forum` (`ForumWalkState`, `common/lib/forumWalk.ts`, pure):
+ `{newestPage, newestPostId, catchUpPage?, historyPage?, oldestPageReached, complete?}`. `newestPostId` is the
+ MARK: a catch-up ends at the first page holding an archived post with id ≤ it. A capped or interrupted catch-up
+ writes only `catchUpPage` (its next page); the history walk writes only `historyPage`. A forum fetch writes no
+ `cursor`; an old one is read once as the history position and dropped.
+2. **Derive, don't trust** — `deriveForumWalk(stored, legacyCursor, heldPages)`, run at the start of every fetch and
+ by the channel page: the held band is the contiguous run of archived `forum.page`s down from the highest;
+ `historyPage = min(stored, band.low + 1)`; page 1 held ⇒ complete; complete with the band above page 1 ⇒ reopened.
+ Each change is a log line. (`+1`, not the brief's `− 2`: see "Decisions".)
+3. **The walk** (`walkXenforoThread`, `common/social/xenforoFetcher.ts`) — three modes from the last page:
+ catch-up (to the mark, then a jump to `historyPage`, never re-reading the band between; meeting the pages an
+ earlier capped catch-up read, a jump to its `catchUpPage`), history (to page 1; archived posts mean nothing), full
+ (every page; archived posts handed back for their edits). A page whose posts are all archived never counts
+ against `pages`/`limit` (except in a full re-walk) and logs "Page N: all held, skipping on." Every checkpoint
+ carries the positions it leaves. A first run (nothing archived) is one history walk from the last page. The
+ start line says both positions ("caught up to page 2600; history resumes at page 2338"). The watermark (`since`)
+ is gone from the forum walk: after a capped catch-up it would stop the next one above the band still owed.
+4. **Two buttons** — the forum channel page's **Fetch posts** (catch up + continue history; "Latest N pages" caps
+ it) and **Full re-walk** (`full: true`; it replaces "Re-fetch full history" on a forum channel; an inline confirm
+ names the page count and the time at the channel's pace, `meanPagePauseSeconds` = 1.25 × the base pause). A full
+ re-walk upserts with `ignorePosition` (a renumbered `#N` is not an edit) and logs the archived posts no page
+ showed (`notSeen`), never marking them. A status line: "pages read 2338–2600 of 2600 · history to page 1
+ remaining: 2337 pages (~9.7 h)", plus "catch-up unfinished at page N" while one is owed.
+5. **Retry on a block** — `fetch-posts {retryOnBlock: {minutes, max}}`: a challenge or refusal (403/429) stops the
+ walk with `PostFetchResult.block`; the controller waits `minutes` (log: "Waiting 30 min after a challenge page,
+ try 2/12."), re-reads the state and runs again, `max` tries in all; never a captcha or a login; minutes 5–1440,
+ max 1–48; a cancel ends the wait, a drain ends it as a drained success. The default for the forum Fetch posts
+ button is `settings.social.xenforo.retryOnBlock` (off unless set), set on the channel page (Forum session →
+ **Retry after a block**: minutes, tries, Save, Turn off). Ops: `"retryOnBlock": {…}` or `true` (the setting);
+ CLI: `--retry-minutes N --retry-tries M` or `--retry-on-block`. The scheduler's unattended fetch never retries.
+6. **An empty page is read again, once** (the orchestrator's live finding, 2026-10-20: "The browser check cleared
+ in 12 s. → Page 2193/2606: 0 post(s) parsed … → [error] Page 2193 of the thread parsed to no posts"): right after
+ a browser check clears, the page standing is often not the thread page yet. A page that parses to no posts is
+ loaded once more (paced like any load; logged "Page N: no posts on the first read after the browser check
+ cleared; loading it again."); only a second empty read stops the walk, as before.
+7. **Test seam** — `E2E_FORUM_FIXTURE_DIR` (test audience, ENVIRONMENT.md): the forum fetcher reads
+ `<dir>/<threadId>/page-<N>.html` (and `page-<N>.<status>.html` in its place while it exists) with no pause
+ (`common/social/forumFixtureLoader.ts`); the e2e server sets it per slot (`e2e/servers.ts`) to `test-transcripts/.forum-fixture`.
+ `common/social/__fixtures__/fakeForumThread.ts`: a synthetic thread that grows, loses posts and writes its pages.
+
+## Files
+
+`common/lib/forumWalk.ts` (+ test), `common/social/xenforoFetcher.ts` (+ test), `common/social/forumFixtureLoader.ts`,
+`common/social/__fixtures__/fakeForumThread.ts`, `common/controller/fetchPosts.ts` (`fetchTimeline`, the retry loop,
+`sleepOrStop`), `common/controller/fetchForumPosts.test.ts`, `common/social/fetchers.ts` (additive:
+`PostFetchInput.forumWalk`, the checkpoint's `forumWalk`, `PostFetchResult.{forumWalk, block, notSeen}`),
+`common/lib/posts-server.ts` (`PostFetchState.forum`; `upsertPosts`/`supersedesPost` `ignorePosition`),
+`common/social/xCookieSource.ts` + `common/lib/settingsSchema.ts` + `settingsDocs.ts` (`social.xenforo`),
+`common/lib/envVars.ts`, `common/bin/fetch-posts.ts`, `common/bin/archilyzer.ts`, `scripts/archilyzer-ops.mjs`,
+`editor/app/channels/[slug]/{socialActions.ts, page.tsx, components/SocialChannelPanel.tsx}`,
+`editor/app/api/ops/fetch-posts/route.ts`, `editor/app/jobs/jobReplayRegistry.ts`,
+`editor/e2e/servers.ts` + `editor/playwright.config.ts`,
+`editor/e2e/forum-resume.spec.ts`; docs OPERATING.md, COMMANDS.md, SETTINGS.md, settings.json.example,
+ENVIRONMENT.md, FACTS ("Release 37 lane G"), CHANGELOG.
+
+## Interfaces
+
+- `ForumWalkState`, `deriveForumWalk`, `heldBand`, `forumWalkStartLine`, `describeForumWalk`,
+ `meanPagePauseSeconds`, `roughDuration`, `FORUM_HISTORY_OVERLAP`, `FORUM_DEFAULT_PAGE_PAUSE_SECONDS`,
+ `FORUM_MIN_PAGE_PAUSE_SECONDS`, `RetryOnBlock`, `retryOnBlockProblem`, `parseRetryOnBlock`,
+ `describeRetryOnBlock`, `RETRY_MIN_MINUTES`/`RETRY_MAX_MINUTES`/`RETRY_MAX_TRIES` (lib/forumWalk.ts).
+- `fetchPosts({…, retryOnBlock?, sleep?})` → `FetchPostsResult.{updated?, block?}`; `sleepOrStop`,
+ `RETRY_AND_OLDER_REFUSAL` (controller/fetchPosts.ts).
+- `fetchPostsAction(…, from?, retryOnBlock?: RetryOnBlock | "settings")`, `setForumRetryOnBlockAction(retry | null)`.
+- `fixtureForumLoader`, `forumFixtureDir`; `FakeForumThread`, `FAKE_THREAD_ID`.
+
+## Gates
+
+All through the session lock (`r31-locked.sh` / `r31-locked6.sh`), from the worktree root.
+
+| Gate | Base (main b8458892) | Branch (after merging main 1f440480) |
+|---|---|---|
+| `pnpm -r exec tsc --noEmit` | clean | clean (at 75482416, 8f63b988, 6cec4dd0) |
+| common `pnpm --filter yt-dlp-transcript-common test` | 4764 tests | 4821 tests, 4819 pass, 0 fail, 2 skipped (at 8f63b988; main's lanes B+E add their own) |
+| lane G unit files (xenforoFetcher, forumWalk, fetchForumPosts, envVars, settingsSchema, settingsDocs) | — | 80/80 |
+| editor `pnpm --filter editor test` | 356 | 357/357 |
+| mcp `pnpm --filter yt-dlp-transcript-mcp test` | — | 379/379 |
+| `pnpm run test:scripts` | 1316 (1312 pass, 4 skipped) | 1317 (1313 pass, 0 fail, 4 skipped) |
+| `docs env / cli / files --check`, `settings example --check` | — | all 0 (ENVIRONMENT.md, COMMANDS.md, SETTINGS.md regenerated; settings.json.example unchanged) |
+| e2e `forum-resume.spec.ts` + `social-channel.spec.ts` (start mode, build 43 s) | — | 7 passed, 0 failed, 1.8 min (run 3; run 1 failed on a getByLabel substring match, run 2 on Turn off not removing the key — both fixed) |
+
+New tests: `lib/forumWalk.test.ts` (5), `controller/fetchForumPosts.test.ts` (6, through the real fetcher over saved
+pages), `social/xenforoFetcher.test.ts` +7 (capped catch-up keeps history, drift reaches page 1 with no gap, all-held
+pages uncounted, a lost position heals, the mark stops the catch-up, empty page reloaded once / after a check, full
+re-walk hands archived posts back and counts `notSeen`), `e2e/forum-resume.spec.ts` (the two buttons, the confirm,
+the status line, Retry after a block).
+
+## Decisions
+
+- **The derived history start is `band.low + 1`, not `lowest − 2`.** Drift only moves posts to LOWER page numbers
+ (a deletion shifts every later post back), so the unread posts below a page read earlier are still on pages ≤ the
+ page below it. Starting at `lowest − 2` skips page `lowest − 1` outright when nothing was deleted — a gap. Starting
+ `OVERLAP − 1` pages above the band's foot re-reads one or two held pages (all held, uncounted) and can never step
+ over an unread page. `min(stored, …)` keeps an honest stored position.
+- **The band is contiguous from the top** (no holes tolerated): an article thread's starter (stored with page 1)
+ or a range imported from saved pages far below would otherwise pull the history start down past pages never
+ read. A drift hole only makes the derived start higher — more uncounted re-reading, never a gap.
+- **A mark and a catch-up position**, beyond the brief's list: without `catchUpPage`, a capped catch-up leaves the
+ band between its foot and the old top owed, and the next catch-up (stopping at any archived post) would skip it;
+ with the mark alone, every capped run re-reads the partial top band. Both are additive keys.
+- **All-held pages are uncounted in the catch-up too** (one rule): a 1-page run whose last page holds nothing new
+ reads its one counted page from the history.
+- **Full re-walk is not resumable as such**: interrupted, its positions say what it covered (mark at its top,
+ `historyPage = min(stored, next)`), and Fetch posts continues from there.
+- **Deletions are counted, not marked**: a page the parser misread would otherwise mark live posts deleted.
+- **`max` is tries in all** (so "try 2/12" is the first retry); minutes ≥ 5.
+- **Retry only from the button and explicit callers**: the scheduler's fetch never waits hours on a lane.
+- **The e2e reads a saved-pages directory through an env seam** rather than a browser at an `.example` host.
+
+## Live migration (kf-oney-thread)
+
+State at 2026-10-20 (orchestrator's notes): `{"cursor":"2280","lastError":null}`, then — after the live run stopped
+on the empty page after a browser check (item 6) — `{"cursor":"2193"}`, posts holding `forum.page` contiguously
+down to ~2194, the thread's last page ~2606. The first fetch after the restart: `deriveForumWalk` reads `cursor
+2193` as the history position ("Read the old single resume point (page 2193) as the history position."), checks it
+against the band (foot ~2194 → at most 2195): it stays 2193 (or heals down to `foot + 1` were the cursor above). No mark yet, so the catch-up runs from ~2602 down to the first page holding any archived post (as before),
+sets the mark to the newest post read, then jumps to page 2280 and continues the history. The state written has
+`forum` and no `cursor`. Nothing on disk needs changing by hand.