Skip to content

fix(api): no-store on tree/readme empty-fallback branches - #54

Merged
neuromechanist merged 2 commits into
mainfrom
53-fixapi-dont-cache-failure-fallback-html-on-treereadme-partials
May 23, 2026
Merged

neuromechanist merged 2 commits into
mainfrom
53-fixapi-dont-cache-failure-fallback-html-on-treereadme-partials

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Closes #53.

Problem

/api/dataset/<id>/{tree,readme} set

Cache-Control: public, max-age=300, s-maxage=600, stale-while-revalidate=86400

on every 200, including the empty-fallback HTML emitted when getManifest
times out from a cold SSR isolate (or any other transient upstream
failure). That fallback gets pinned at the CF edge for s-maxage=600
fresh + stale-while-revalidate=86400 stale, blanking otherwise-healthy
dataset pages for hours.

Reproduced on on002778: 5/10 cold calls returned the 354-byte
"Manifest unavailable" partial before warming. After cache-bust, the
canonical URL returned the full 187 KB tree.

Fix

Branch the Cache-Control header by outcome:

  • Success (manifest fetched, summary fetched, or any of the 4 readme
    steps produced a source) → keep PUBLISHED_CACHE. Response is
    deterministic for the (id, version) pair, long edge cache is fine.
  • Failure-fallback (no manifest after a published landing; empty
    source after all four readme steps) → Cache-Control: no-store. The
    one unlucky request takes the hit; subsequent requests get a fresh
    origin call.

Unpublished and unknown-dataset branches keep their existing caches.

Why not just shorten s-maxage everywhere

Healthy responses are deterministic; long edge caches matter for cold
visitors on large datasets (nm000104's tree HTML is ~ 200 KB). Shortening
the success-path cache would amplify origin load with no upside. The
failure cases are the actual problem.

Test plan

  • bun run lint → clean
  • bun run typecheck → 0 errors
  • bun test → 350/350 pass
  • After deploy, re-curl ww2.nemar.org/api/dataset/on002778/tree?v=v1.0.0
    until a cold-start failure appears, then immediately re-curl and
    verify the second call hits the origin (not a cached empty).

Closes #53. Transient upstream failures were producing 200-OK empty-fallback HTML cached at the CF edge with s-maxage=600 + stale-while-revalidate=86400, blanking dataset pages for hours after a single cold-start manifest timeout.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 23, 2026 •

Copy link
Copy Markdown

Address minor wording finding in PR review: distinguish 'content steps came back null' from 'come back empty'. The discriminator at line 135 is source nullability, not content emptiness — non-null source from any of the four steps (manifest/github/description) means real content was found and gets PUBLISHED_CACHE.
@neuromechanist
neuromechanist merged commit cec3575 into main May 23, 2026
1 check passed
@neuromechanist
neuromechanist deleted the 53-fixapi-dont-cache-failure-fallback-html-on-treereadme-partials branch May 23, 2026 13:49
neuromechanist added a commit that referenced this pull request May 26, 2026
Comment-analyzer found the rationale block named the wrong cached
keys: poisoned entries are responses from /api/dataset/<id>/readme
and /api/dataset/<id>/tree (the partial endpoints), not the SSR
/dataset/<id> page. Also add "(fixes #53)" next to "PR #54" so a
future GitHub search lands on the original bug report.
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.

fix(api): don't cache failure-fallback HTML on tree/readme partials

1 participant