Skip to content

Feed fetcher

Fetches a source, parses RSS 2.0, RSS 1.0 (RDF), Atom or JSON Feed, normalizes the entries and stores the new ones for every subscriber (SI-521). The other source types (GitHub releases, JSON APIs, web pages) plug into the same steps with a fetch of their own: source-types.md. Code: packages/core/src/feeds/. It runs in the app process (ADR-0001). Deciding when to fetch a source is the scheduler’s job (SI-522). Until it exists, fetches run from the CLI.

Steps

  1. Download (http.ts). Sends the stored ETag / Last-Modified, so an unchanged feed costs a 304. Follows up to 5 redirects. When every hop is a 301 or 308, the source’s URL is updated, unless another source already has the new URL. The old URL goes into config.previousUrls, so following it again (an old OPML file, a bookmark) finds the moved source. Limits: 20 s per fetch, 15 MB per feed. The charset comes from a BOM, then the XML declaration, then the Content-Type header.
  2. Parse (parse.ts) with feedsmith, which tolerates bare &, HTML entities, uppercase tags and missing namespaces. An HTML page is reported as not_feed, and truncated XML as parse.
  3. Normalize (normalize.ts), per entry:
    • URL: absolute, without utm_*, fbclid, gclid and similar tracking parameters, without the fragment.
    • guid: the feed’s id, else the URL, else a hash of title, date and text, so it’s the same on every fetch.
    • Title: plain text. If there’s none, it’s made from the text, then from the URL.
    • Content: cleaned HTML. No scripts, styles, classes, event handlers, forms or tracking pixels. Only YouTube and Vimeo iframes. Links and images point at the original site, lazy-loaded images get their real src, and srcset is dropped.
    • Excerpt: up to 300 characters of plain text from the summary, else from the content.
    • Date: published, else updated. Handles RFC 822 with named zones (CEST, PST), German month and day names, and ISO 8601 without a zone (read as UTC). Dates before 1995 are placeholders. If there’s no usable date, the item gets the fetch time, a second earlier per position, so the feed’s order is kept. Dates in the future are set to the fetch time.
    • Author, image, media: author from the item, else the feed. The image comes from media:thumbnail / media:content, an image enclosure, itunes:image or JSON Feed image. Audio and video enclosures, with their duration, go into media. Open Graph images and a thumbnail cache are SI-527.
  4. Store (refresh.ts). At most the newest 200 entries per fetch, so a podcast with 1,000 episodes doesn’t flood the stream. Entries already stored under the same guid are skipped. Entries whose URL the source already has under another guid are skipped too: some feeds rewrite their guids. A URL that several entries of one fetch share (changelogs, podcasts linking their homepage) doesn’t identify an entry, so those are compared by guid only. New items go to every subscriber (addItems). The ETag is stored only after the items, so a failed insert means a full fetch next time.

Finding feeds

Adding a source by a site’s address finds the feeds the page links to, or tries the usual paths: sources.md (SI-524).

Politeness

HostPool limits fetches to 12 in parallel overall and 2 per host, with at least 250 ms between two requests to the same host. 531 of the 1,021 feeds are on youtube.com. www. and the bare domain count as one host. After a 429 or 503, the host is paused for its Retry-After (at most 10 minutes), or for 60 s if it gives none. The user agent is Mozilla/5.0 (compatible; Hotaru/1.0; feed reader).

Errors and source health

A failed fetch never throws. It increments consecutive_failures and sets last_error (for example HTTP 404 Not Found), and a successful fetch resets both. After every fetch, the scheduler sets the status (ok, hibernating, failing or dead) and the next fetch time (scheduler.md). Error kinds: timeout, dns, network, tls, blocked, http, too_large, not_feed, parse.

Private addresses are blocked

Any user can add any URL, so a feed URL must not reach this machine or its network. Requests to loopback, private (10/8, 172.16/12, 192.168/16, fc00::/7), link-local (including 169.254.169.254, the cloud metadata service), CGNAT and multicast addresses fail with blocked. IPv6 addresses that carry an IPv4 address (IPv4-mapped and -compatible, NAT64 64:ff9b::/96, 6to4 2002::/16) are checked by that IPv4 address. Teredo, local-use NAT64 and the discard range are blocked outright. The check runs on the resolved address of every connection, redirects included, so a DNS name that points inside can’t get around it. Tests use unrestrictedDispatcher() to reach their local server.

CLI

Terminal window
# Fetch and parse every feed of an OPML file (or URLs), write nothing, print an error report
pnpm feeds check "fixtures/private/Inoreader Feeds 20261112.xml" --json report.json
# Refresh the sources in the app database: all with subscribers, or the given ones
pnpm feeds fetch [--source <id>]…
# On the server (Coolify → Terminal)
node /app/packages/core/scripts/feeds.ts fetch

Run on 2026-11-12 against the Inoreader export (1,021 feeds): 990 OK, 31 failed in 152 s, 27,377 items, and nothing crashed. The failures: 8 × HTTP 404, 6 × 403, 4 timeouts, 3 not a feed, 3 network errors, 3 × 429, 2 TLS errors, 1 × 503, 1 unreadable feed. Two feeds had moved permanently, and 11 parse but list no items. The list is input for the cleanup before the cutover (SI-532). An earlier run that day had 56 timeouts. Rerun alone, 49 of them worked in 5 s, and a profiled full sweep had 4: a network hiccup, not the fetcher. The event loop never stalled for more than 250 ms. Parsing all feeds takes about 7 s of CPU in total, and the slowest single feed takes about 240 ms.

Tests

The fixtures in packages/core/src/feeds/fixtures/ are synthetic. They reproduce the quirks found in the real subscriptions (fixtures/private/ is git-ignored): WordPress with lazy images and tracking pixels, YouTube, Atom with HTML titles and xhtml content, JSON Feed, RDF, podcasts, ISO-8859-1, a changelog with one URL for every entry, missing titles, guids, links and dates, truncated XML, and an HTML page. The HTTP and refresh tests run against a local server.

Left for later

  • Changed entries (a corrected title, updated content) aren’t updated. Only new guids are stored.
  • Open Graph images, first image in the content, thumbnail cache: SI-527.
  • Full article text when the feed has only a teaser: SI-535.