Skip to content

ADR-0004: Feed fetches run in a plain loop, not as durable tasks

  • Status: accepted
  • Date: 2026-11-12
  • Decided by: Stefan Imhoff

Context

SI-522 planned the scheduler’s fetches as pi-durable tasks: the tick only enqueues due sources, and a crash mid-batch resumes cleanly. pi-durable isn’t in the code yet. ADR-0001 and ADR-0002 plan it, durable.db doesn’t exist, and SI-533 (the AI pipeline) is the first feature that needs it.

A feed fetch is cheap and can safely run twice. Items are stored by (source, guid) and URL, so a second fetch adds nothing. The ETag and Last-Modified are stored only after the items, so an interrupted fetch costs a full fetch next time and loses nothing (SI-521). A source that was due when the process stopped is still due when it starts again: next_fetch_at is only set after a fetch.

Decision

The scheduler is a plain loop in the app process (scheduler.ts). Every minute, it starts the sources whose next_fetch_at has passed and that someone follows without pausing. The fetcher’s pool limits how many run at once. The loop computes each source’s next fetch after every fetch, from its posting history (SI-522). Fetches aren’t durable tasks. A crash or deploy drops the fetches in flight, and the next tick starts them again.

The scheduler starts with the web server and nowhere else. CLI scripts and tests open the runtime without it, so a script never fetches alongside the server.

Rejected alternatives

  • A durable task per fetch, as planned in SI-522. That would mean bringing in pi-durable, durable.db and its upgrade risk (SI-512) for work that is already safe to repeat. A checkpoint would save at most one HTTP request per interrupted fetch. It’s worth it for the AI pipeline (SI-533), where every step costs money and takes seconds.
  • A system cron that calls an endpoint. Rejected in ADR-0001 for the same reasons: the scheduler needs each source’s next-check time, which sits in the database next to it.

Consequences

  • SI-522 ships without pi-durable. SI-533 brings it in, for the item pipeline.
  • After a restart, everything due in the meantime is fetched in the first few ticks (200 sources per tick, within the pool’s limits). For the 1,021 sources at the time, a full catch-up takes about 3 minutes.
  • If fetching ever does something that can’t safely be repeated (paid APIs, writes elsewhere), that part belongs in a durable task, not in this loop.