Repository navigation
fix(core): invalidate Node route caches after background publishing - #4889
Conversation
Bind the active Astro route-cache handle to long-lived Node runtimes for plugin hook/cron publication, and use it as the scheduled publishing fallback while preserving explicit platform callbacks. Added real-memory-provider regressions, failure-path coverage, updated route-cache docs, and an emdash patch changeset. Verified pnpm build, pnpm typecheck, pnpm lint:quick (zero diagnostics), pnpm format, docs build, and 159 targeted tests across seven files. Independent review found no blocking issues. EmDash-Bot-Case: 1198246700-issue-6426352206 EmDash-Bot-Candidate: cand-1-856b65e264
EmDash bot: ClosedPlan Ready for maintainer approval and merge: required checks pass on 6d728c7, the latest review is clean, and the branch merges cleanly. The reporter confirmed scheduled-cache invalidation on production Node with PostgreSQL 16; no further…
Status
Next action: None. Details
Required checks on the current head:
This status is generated from recorded evidence. It is not a review and contains no instructions. |
🦋 Changeset detectedLatest commit: 6d728c7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
The approach is sound. It fills the existing pluginContentCacheInvalidator slot on long-lived Node/Bun hosts from the request's context.cache, so invalidation hits the cache Astro actually serves. It does not construct a separate provider. Scheduled publishing uses that invalidator as the fallback onPublished, and an explicit callback still takes precedence. Both reviewers approved and found no blocking issues. Invalidation failures remain non-fatal, Cloudflare behaviour is unchanged, and no new per-request queries are added. One reviewer ran no code (static review only). The other noted that Astro's per-request handle was not confirmed to keep delegating to the shared provider after its request ends. Two non-blocking suggestions remain: trimming a justification-style comment in the middleware, and a middleware unit test that asserts less than its title claims.
Reviewed by anthropic/claude-opus-5-5 and openai/gpt-6.1-sol.
| // Reuse Astro's active provider: constructing another memory provider | ||
| // would invalidate a separate, empty cache. Only long-lived runtimes | ||
| // may retain this handle beyond the request. |
There was a problem hiding this comment.
[suggestion] Most of this comment explains an alternative the PR rejected ("constructing another memory provider would invalidate a separate, empty cache"). That justification is aimed at reviewers rather than future readers (see AGENTS.md comment discipline). The part worth keeping is the lifetime constraint:
| // Reuse Astro's active provider: constructing another memory provider | |
| // would invalidate a separate, empty cache. Only long-lived runtimes | |
| // may retain this handle beyond the request. | |
| // Only long-lived runtimes may retain the request's cache handle beyond the request. |
There was a problem hiding this comment.
Trimmed this to the lifetime constraint as suggested.
| const entries = new Map([["posts:post-1", "cached"]]); | ||
| const cache = { | ||
| enabled: true, | ||
| invalidate: vi.fn(async ({ tags }: { tags: string[] }) => { | ||
| for (const tag of tags) entries.delete(tag); | ||
| }), | ||
| }; | ||
| const context = createContext({ cache, path }); | ||
| if (path === "/") { | ||
| (globalThis as Record<symbol, unknown>)[SETUP_VERIFIED_KEY] = true; | ||
| } | ||
|
|
||
| expect((await onRequest(context as never, async () => new Response("ok"))).status).toBe(200); | ||
| expect(mockSetInvalidator).toHaveBeenCalledOnce(); | ||
|
|
||
| const invalidator = mockSetInvalidator.mock.calls[0]?.[0] as ( | ||
| tags: string[], | ||
| ) => Promise<void>; | ||
| await invalidator(["posts:post-1"]); | ||
| expect(cache.invalidate).toHaveBeenCalledWith({ tags: ["posts:post-1"] }); | ||
| expect(entries.has("posts:post-1")).toBe(false); |
There was a problem hiding this comment.
[suggestion] This test can't fail on a real regression. cache.invalidate is a mock that deletes from a local entries map, and the test then asserts that the mock deleted from that map. The only real assertion is that the bound closure forwards { tags } to cache.invalidate. The title ("keeps the request cache usable after the request ends") claims more than that, because a hand-written mock can't show that Astro's per-request handle keeps working after the request. I'd drop the entries map, rename the test to describe the forwarding it actually checks, and cover the after-request behaviour with an end-to-end test through a real Astro request context.
There was a problem hiding this comment.
Agreed—the map only tested the mock. Removed it and renamed the test to describe the forwarding it actually checks. The separate integration test continues to cover eviction through Astro's real memory provider.
I also checked Astro's AstroCache.invalidate: it delegates directly to the stored provider and does not access request state. I'm leaving a full production-server lifetime regression out of this follow-up: the current browser fixture runs astro dev, where route caching is disabled, so that needs a production-mode harness rather than another synthetic context.
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
docs | 6d728c7 | Nov 30 2026, 05:57 PM |
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/auth-atproto
@emdash-cms/blocks
@emdash-cms/cloudflare
@emdash-cms/contentful-to-portable-text
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/plugin-cli
@emdash-cms/plugin-test
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/registry-loader
@emdash-cms/registry-moderation
@emdash-cms/registry-verification
upgrade-emdash
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-ai-search
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-field-kit
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
Address review suggestions: shorten the middleware comment to its lifetime constraint, remove the mock-only eviction map assertion, and rename the middleware test to describe forwarding rather than real Astro request lifetime. Verified 13 focused tests, pnpm format, and pnpm lint:quick with zero diagnostics. Independent review found no blocking defects. Production-server lifecycle coverage is deferred and disclosed. EmDash-Bot-Case: 1198246700-issue-6426352206 EmDash-Bot-Candidate: cand-2-838ffd7999
There was a problem hiding this comment.
The approach is sound. On long-lived Node/Bun hosts, the middleware fills the existing pluginContentCacheInvalidator slot from the request's context.cache, so invalidation hits the cache Astro actually serves rather than a separate provider. Scheduled publishing uses that invalidator as the fallback onPublished, and an explicit callback still takes precedence. Both reviewers approved, and neither raised new findings. Both earlier suggestions are resolved: the middleware comment is trimmed to the lifetime constraint, and the unit test is renamed to describe the forwarding it actually checks. Invalidation failures stay non-fatal, Cloudflare behaviour is unchanged, and no new per-request queries are added. Reviewers ran no tests or builds. A full production-server after-request lifetime regression remains unverified. The author reasonably deferred it because the browser fixture runs astro dev, where route caching is disabled.
Reviewed by anthropic/claude-opus-5-5 and openai/gpt-6.1-sol.
Merge default branch 643443f and resolve the middleware conflict, preserving anonymous-render/rewrite reuse and active cache binding in both request initialization paths. Clarify docs to enumerate plugin methods that invalidate and explicitly exclude create/update. Verified workspace build and typecheck, formatting, quick lint (zero diagnostics), docs build, eight targeted test files, and a final 38-test cache/rewrite run. Follow-up review found all findings addressed and no new defects. EmDash-Bot-Case: 1198246700-issue-6426352206 EmDash-Bot-Candidate: cand-3-8437fda77f
There was a problem hiding this comment.
The approach is sound. On long-lived Node/Bun hosts, the middleware fills the existing pluginContentCacheInvalidator slot from the request's context.cache, so invalidation reaches the cache Astro actually serves instead of a separately built provider. Scheduled publishing uses that invalidator as the fallback onPublished, and an explicit callback still takes precedence. Both reviewers approved and raised no new findings. Both earlier suggestions are resolved: the middleware comment is trimmed to the lifetime constraint, and the unit test is renamed to describe the forwarding it checks. Invalidation failures stay non-fatal, Cloudflare behaviour is unchanged, and no new per-request queries are added. Neither reviewer ran tests or builds. A production-server regression test for reusing the cache handle after the request ends is still missing. The author reasonably deferred it because the browser fixture runs astro dev, where route caching is disabled.
Reviewed by anthropic/claude-opus-5-5 and openai/gpt-6.1-sol.
Merge default branch f585c35 and resolve middleware conflict while preserving installed-plugin refresh, anonymous rewrite scope reuse, and active cache binding. Expose normalized publicPath from the page-signal helper so the merged plugin refresh logic works. Tighten scheduler comment and clarify Cloudflare hook guarantees. Verified workspace build/typecheck, format, zero-diagnostic quick lint, docs build, and 193 targeted tests across eight files; final review found no blockers. EmDash-Bot-Case: 1198246700-issue-6426352206 EmDash-Bot-Candidate: cand-4-eb03418a04
There was a problem hiding this comment.
The approach is sound. On long-lived Node/Bun hosts, the middleware stores the request's context.cache handle in the existing pluginContentCacheInvalidator slot, so invalidation reaches the cache Astro actually serves. Scheduled publishing uses that invalidator as the fallback onPublished, and an explicit callback still takes precedence. Both reviewers approved and raised no findings. Cloudflare, astro dev and prerendered requests are unchanged, invalidation failures stay non-fatal, and no new per-request queries are added. Both earlier suggestions (the trimmed middleware comment and the renamed unit test) remain resolved. A production-server regression test for reusing the cache handle after the request ends is still missing. The author reasonably deferred it because the browser fixture runs astro dev, where route caching is disabled. Neither reviewer ran tests or builds.
Reviewed by anthropic/claude-opus-5-5 and openai/gpt-6.1-sol.
|
CI's two Cloudflare failures are editor assertions (block deep-link expansion and saved image display). Both passed together locally against the Cloudflare fixture on this head; Node E2E and the other CI lanes passed. I requested a rerun of shard 3. A maintainer needs to rerun Cloudflare E2E shard (2/8): GitHub refused the bot's request with HTTP 403. The aggregate Tests failure is only downstream of Cloudflare E2E, not a separate test failure. |
Merge default branch 01f717d and resolve route-caching documentation conflicts, retaining new media-cache caveats and corrected Node scheduled/plugin publication guidance. No background-publish code behavior changed. Verified workspace build/typecheck, format, quick lint (zero diagnostics), docs build, and eight targeted test files. Reporter confirmed production Node scheduled invalidation with PostgreSQL 16. Independent review found no blockers. EmDash-Bot-Case: 1198246700-issue-6426352206 EmDash-Bot-Candidate: cand-5-6d6af0becb
There was a problem hiding this comment.
The approach is sound: on long-lived Node/Bun hosts the middleware reuses Astro's active context.cache handle. The scheduled-publishing fallback keeps explicit onPublished precedence, and invalidation failures stay non-fatal. Neither reviewer found a runtime correctness issue, and both reviews were static with no tests or builds run. One finding needs fixing: the shared invalidator also enables Node media purges, and the route-caching docs still describe those as unsupported. Only openai/gpt-6.1-sol raised this; anthropic/claude-opus-5-5 reviewed the docs and found nothing to flag. The deferred production-server lifetime regression test is still missing, and both reviewers accepted that deferral.
Reviewed by anthropic/claude-opus-5-5 and openai/gpt-6.1-sol.
| ); | ||
| if (virtualCreateScheduler && cache?.enabled) { | ||
| // The timer scheduler needs the active provider's cache handle outside requests. | ||
| instance.setPluginContentCacheInvalidator((tags) => cache.invalidate({ tags })); |
There was a problem hiding this comment.
[needs fixing] Binding this shared invalidator also enables Node media purges, not just content-action purges: invalidatePluginMedia() falls back to this.pluginContentCacheInvalidator, and runSystemCleanupIfDue() passes it into runSystemCleanup(). However, the updated route-caching page still lists plugin hook/cron media deletes and hourly cleanup on Node under “Some deletes are not purged” (route-caching.mdx:95–97). Those statements become false for Node deployments with a compatible media cache provider once this binding has run. Update the media section to describe that coverage and its initialization/process-local limits, while retaining the separate warning that memoryCache() does not automatically cache media. (Raised by openai/gpt-6.1-sol only; anthropic/claude-opus-5-5 said the docs matched the behaviour.)
There was a problem hiding this comment.
Confirmed both consumers of the shared invalidator. Updated the media section and changeset to cover Node hook/cron image deletes and hourly cleanup after a route-cache-enabled request accesses the runtime. The docs explain the per-process binding and provider-dependent cross-instance behavior, remove the obsolete Node exclusions, and retain the warning that memoryCache() does not automatically cache media. Docs build, quick lint, and 66 focused cache/media tests pass.
Correct docs and changeset for the shared invalidator's existing Node media-purge effect: hook/cron media deletes and hourly cleanup purge removed images after a non-prerendered route-cache-enabled request accesses the runtime. Document initialization and provider-dependent cross-instance limits consistently for content/media, remove obsolete Node exclusions, and retain memoryCache's automatic-media-caching warning. No runtime code changed. Verified docs build, format, zero-diagnostic quick lint, and 66 focused tests; follow-up review found all findings addressed. EmDash-Bot-Case: 1198246700-issue-6426352206 EmDash-Bot-Candidate: cand-6-3b621b2d9f
There was a problem hiding this comment.
The approach is sound. On long-lived Node/Bun hosts, the middleware reuses Astro's active context.cache handle to purge outside requests, and scheduled publishing falls back to it only when no explicit onPublished is passed. Both reviewers approved and neither raised new findings. The earlier findings are resolved: the route-caching docs and changeset now cover Node hook/cron media deletes and hourly cleanup, the mock-only test is renamed to describe the forwarding it checks, and the middleware comment is trimmed to the lifetime constraint. A regression test for the handle's lifetime on a real production server is still deferred. The author explained that the browser fixture runs astro dev, where route caching is disabled, so it needs a production-mode harness, and both reviewers accepted that. Both reviews were static, with no tests or builds run.
Reviewed by anthropic/claude-opus-5-5 and openai/gpt-6.1-sol.
|
@emdash-autofix This branch has conflicts that must be resolved docs/src/content/docs/deployment/route-caching.mdx |
|
@swissky Resolved the route-caching docs conflict, preserving the latest Cloudflare cron-purge warning and cacheable-404 guidance alongside the Node fix. Build, typecheck, docs build, quick lint, and 11 focused test files pass. Publishing the updated merge now. |
Merge default branch 2084e51 and resolve maintainer-reported route-caching documentation conflicts. Preserve the latest Cloudflare cron-purge reliability warning, positive-maxAge/cacheable-404 guidance, and all Node content/media invalidation caveats. Clarify plugin create/update/delete remain non-purging. No runtime behavior changed during conflict resolution. Verified workspace build/typecheck, format, zero-diagnostic quick lint, docs build, 11 focused test files, and a final 13-test background-cache run. Follow-up review is clean. EmDash-Bot-Case: 1198246700-issue-6426352206 EmDash-Bot-Candidate: cand-7-bb7cf395b0
There was a problem hiding this comment.
The approach is sound. On long-lived Node/Bun runtimes, the middleware reuses Astro's active context.cache handle so request-less purges (scheduled publishing, plugin content actions, media deletes, hourly cleanup) reach the same cache. Scheduled publishing falls back to it only when no explicit onPublished is passed. Both reviewers approved with no new findings. The earlier findings are resolved: the media docs and changeset now cover Node hook/cron deletes and hourly cleanup, the mock-only test is renamed to describe the forwarding it checks, and the middleware comment is trimmed to the lifetime constraint. A regression test for the handle's lifetime on a real production server is still deferred, because the browser fixture runs astro dev, where route caching is disabled. Both reviewers accepted that. Both reviews were static, with no tests or builds run.
Reviewed by anthropic/claude-opus-5-5 and openai/gpt-6.1-sol.
|
Cloudflare E2E is green after the rerun. The remaining blocker is Test Shard (2/4). I reproduced that shard on this head with PostgreSQL 17.12: 236 files passed, 3,723 tests passed, 3 skipped. I need a maintainer to provide the failing Vitest summary or rerun that unit shard directly. The available CI log tool exposes only the tail, which is entirely PostgreSQL teardown output—even at its 1,000-line limit. GitHub first refused the rerun with HTTP 403; the tool now reports a later failed run without giving its check ID. I haven't changed code without knowing the failing assertion. |
Merge default branch ebc9fcd and resolve route-caching docs conflict, retaining Node scheduled/plugin publish invalidation and the new EmDashWorker requirement for effective Cloudflare cron purges. No runtime behavior changed during this merge. Verified workspace build/typecheck, format, zero-diagnostic quick lint, docs build, 11 focused core test files, and 18 Cloudflare scheduled-worker tests. Follow-up review found no blockers. EmDash-Bot-Case: 1198246700-issue-6426352206 EmDash-Bot-Candidate: cand-8-bf221e3288
There was a problem hiding this comment.
The approach is sound. On long-lived Node/Bun runtimes, the middleware keeps Astro's active context.cache handle, so request-less purges reach the same cache provider that served pages. These purges come from scheduled publishing, plugin content actions, media deletes and hourly cleanup. Scheduled publishing uses the handle only when no explicit onPublished is passed. Both reviewers approved with no new findings. The earlier findings stay resolved: the media docs and changeset cover Node hook/cron deletes and hourly cleanup, the mock-only test was renamed to describe the forwarding it checks, and the middleware comment was trimmed to the lifetime constraint. A production-server regression test for the handle's lifetime is still deferred, because the browser fixture runs astro dev, where route caching is disabled. Both reviewers accepted that deferral. Both reviews were static, with no tests or builds run.
Reviewed by anthropic/claude-opus-5-5 and openai/gpt-6.1-sol.
What does this PR do?
Reuses Astro's active cache handle on long-lived Node runtimes so plugin content actions from hooks and cron invalidate the same cache as plugin routes. Scheduled publishing falls back to that invalidator, including timer-driven sweeps,
publishScheduled(), andrunScheduledTasks(); explicit platformonPublishedcallbacks keep precedence.This addresses cached home/category listings and articles remaining stale after background publication. Constructing another memory provider would clear a separate cache, so the runtime retains the handle supplied by an actual request. Invalidation remains process-local; other Node instances still retain their own entries. No general-purpose purge API is added.
Updates route-caching documentation and adds an emdash patch changeset.
Scope: plugin enrichment is covered when the plugin publishes after updating. This does not change
ctx.content.updatecache behavior or hook invalidation on Cloudflare.Type of change
Your connection to this change
Project-operated autofix bot working on the reported bug through auto-intake, under the AI policy's bot exemption. Maintainer review and approval are required before merge.
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runAI assistance disclosure
AI-generated implementation, tests, and PR text using OpenAI GPT-5.5 and the delegated helper tool. Human maintainer approval is required before merge.
Screenshots / test output
Not applicable: no UI changes.
Verified:
pnpm buildpnpm typecheckpnpm lint:quick— zero diagnosticspnpm formatpnpm --dir docs buildThe regression reproduced a cached listing remaining a HIT after a scheduled publication before the fix. Tests use a real SQLite runtime and Astro's real memory provider, checking collection/entry invalidation while unrelated cached pages remain hits. Additional coverage checks disabled/absent caches, prerender and non-timer platforms, missing/failing invalidators, and explicit callback precedence. Full type-aware lint and the full test suite are left to CI.
AI assistance disclosure
Closes #4887
The EmDash bot took this issue on automatically when it was opened; no maintainer has assigned it yet.