Bust Astro build cache when the markdown pipeline changes#1904
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause
The failing E2E test —
link-validation.spec.ts:92 › sample blog posts should not have broken internal links— has failed on everymainpush 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:node_modules/.astro(Astro's content layer) withrestore-keys: astro-cache-<os>-./q/links to#quote-anchors, the cathedral post's.mdnever 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
.astrodata-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, inastro-e2e.ymlandbuild-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
rm -rf node_modules/.astro && npm run build): 0/q/links, 27 quote posts rendering#quote-anchors.link-validationtests green against a stable preview server, including the originally-failing one.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