Skip to content

fix(crawler): ignore s-maxage and revalidate stale-while-revalidate entries with a conditional GET #2229 - #2232

Merged
nc9 merged 1 commit into
mainfrom
fix/crawler-private-client-freshness
Nov 22, 2026
Merged

nc9 merged 1 commit into
mainfrom
fix/crawler-private-client-freshness

Conversation

@nc9

@nc9 nc9 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Closes #2229

Cause. packages/crawler/src/incremental.ts calculateFreshness: cacheControlLifetimeSeconds let s-maxage (shared caches only) beat max-age, and a stale entry inside stale-while-revalidate returned revalidate, which core/crawler.ts handled by reusing the stored body with no request (no background revalidation ever ran). max-age=300, s-maxage=3600, stale-while-revalidate=86400 reused the stored page for up to 24 h.

Fix.

  • calculateFreshness uses max-age, then Expires; s-maxage is still parsed (the bad-caching rule audits it) but no longer sets the lifetime. The s-maxage fresh reason is removed (contract unions keep the literal for stored data).
  • The revalidate state is removed. Inside the SWR window it returns stale with reason stale-while-revalidate (kept for diagnostics), so the crawler sends If-None-Match / If-Modified-Since. 304 keeps the stored body, 200 replaces it. The cloud consumer shares calculateFreshness, so it gets the same decision. Removed the crawler revalidate branch.
  • immutable, no-cache, no-store, staleness cap and Vary unchanged.
  • Docs: docs/crawl.mdx, docs/configuration/output.mdx. Changelog: changelog.d/2229-private-client-freshness.fixed.md.

Tests (tests/private-client-freshness-2229.test.ts, new). Fail before on origin/main: 6 of 7 failed (unit s-maxage, s-maxage-alone, SWR, and the crawl-level +301 s changed and unchanged cases made 0 requests, plus the +200 s case's body check that I later fixed). Crawl-level: +301 s changed origin sends If-None-Match and stores the NEW body; unchanged gets 304 and keeps the old body; +200 s reuses with no request. Updated existing tests that asserted the old behaviour (incremental-freshness, cache-store; no-cache-fetch-2032 drops its SWR case, whose control assumed SWR reuse).

Gates. packages/crawler: typecheck, lint, format:check clean; bun scripts/test-suites.ts --run crawler: 1186 pass, 0 fail; --check OK; make validate in docs: 74 pass, 0 fail.

Agent skill: no change.

…ntries with a conditional GET #2229

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 marked this pull request as ready for review November 22, 2026 04:46
@nc9
nc9 merged commit a85ea12 into main Nov 22, 2026
10 checks passed
@nc9
nc9 deleted the fix/crawler-private-client-freshness branch November 22, 2026 05:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Re-audits reuse stored pages for up to 24 h: crawler honours s-maxage and treats stale-while-revalidate as reuse without a request

1 participant