Skip to content

Bust Astro build cache when the markdown pipeline changes#1904

Merged
benbalter merged 2 commits into
mainfrom
fix-astro-cache-staleness
Jul 10, 2026
Merged

Bust Astro build cache when the markdown pipeline changes#1904
benbalter merged 2 commits into
mainfrom
fix-astro-cache-staleness

Conversation

@benbalter

Copy link
Copy Markdown
Owner

Root cause

The failing E2E test — link-validation.spec.ts:92 › sample blog posts should not have broken internal links — has failed on every main push since the /q/<id> quote pages were retired. It flags two dead links in the cathedral-bazaar-management post: /q/match-management-to-the-moment/ and /q/cathedral-bazaar-operating-systems/.

The source is correct — those posts use inline :quote[…]{#id} directives that render #quote- anchors, and a cold build produces zero /q/ links. This is CI cache staleness, not content:

  • Both workflows cache node_modules/.astro (Astro's content layer) with restore-keys: astro-cache-<os>-.
  • Astro caches rendered markdown keyed on each file's content digest and reuses it for unchanged files regardless of the remark/rehype plugin code.
  • When the quote plugin switched from /q/ links to #quote- anchors, the cathedral post's .md never changed — so CI restored the pre-change cache and kept shipping its stale /q/ HTML. astro preview (what E2E runs against) doesn't honor the /q/* → /posts/ 301 in _redirects, so it 404s.

Reproduced the reuse mechanism locally (building with a different plugin than what's cached leaves unchanged content un-re-rendered) and confirmed via the .astro data-store cache.

Fix

Fold a pipeline fingerprint (src/lib/**, astro.config.mjs, src/content.config.ts, package-lock.json) into both the cache key and the restore-keys prefix, in astro-e2e.yml and build-and-deploy.yml. A rendering-pipeline change now busts the cache; content-only edits still reuse it.

The deploy workflow had the identical bug, so prod was serving the degraded /q/ → /posts/ 301 on every quote share link until an unrelated edit touched those posts — this fixes that path too.

Verification

  • Cold build (rm -rf node_modules/.astro && npm run build): 0 /q/ links, 27 quote posts rendering #quote- anchors.
  • All 5 link-validation tests green against a stable preview server, including the originally-failing one.
  • Both workflow YAMLs parse clean.

The new key format can't prefix-match any existing cache, so the first run on each workflow cold-builds automatically; no manual cache purge needed.

🤖 Generated with Claude Code

benbalter and others added 2 commits July 10, 2026 19:34
The E2E "sample blog posts should not have broken internal links" test has
failed on every main push since the /q/<id> quote pages were retired: the
cathedral-bazaar-management post rendered links to /q/match-management-to-the-moment/
and /q/cathedral-bazaar-operating-systems/, both now 404 under `astro preview`
(which doesn't honor the /q/* -> /posts/ 301 in _redirects).

Root cause is CI cache staleness, not the content. Astro's content layer caches
rendered markdown keyed on each file's content digest and reuses it for unchanged
files regardless of the remark/rehype plugin code. The cache step's
`restore-keys: astro-cache-<os>-` restored a cache built before the quote plugin
switched from /q/<id> links to #quote-<id> anchors; since the post's .md never
changed, its stale /q/ HTML was reused and shipped. A cold build produces zero
/q/ links (verified), confirming the source is correct.

Fold a pipeline fingerprint (src/lib/**, astro.config.mjs, src/content.config.ts,
package-lock.json) into both the cache key and the restore-keys prefix so a
rendering change can no longer restore a cache built by the old pipeline, while
content-only edits still reuse it. Applied to both the E2E and deploy workflows —
the deploy path had the same bug, so prod was serving the degraded /q/ -> /posts/
301 on every quote share link until the next unrelated edit to those posts.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@benbalter
benbalter merged commit d34bb82 into main Jul 10, 2026
12 checks passed
@benbalter
benbalter deleted the fix-astro-cache-staleness branch July 10, 2026 23:51
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.

1 participant