Skip to content

fix: prefer uncached Hyperdrive after content writes - #2280

Merged
ascorbic merged 8 commits into
mainfrom
fix/prefer-uncached-hyperdrive-after-write
Aug 10, 2026
Merged

ascorbic merged 8 commits into
mainfrom
fix/prefer-uncached-hyperdrive-after-write

Conversation

@scottbuscemi

@scottbuscemi scottbuscemi commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Prevents anonymous public requests from reseeding Workers/Object Cache with stale Hyperdrive query-cache results immediately after content publishes. Content invalidation records a shared last-write timestamp, and Hyperdrive public reads temporarily use the uncached primary binding for a configurable window (60 seconds by default).

Cross-isolate coordination uses the configured distributed Object Cache backend. preferUncachedAfterWriteMs should match the cached Hyperdrive configuration's max_age.

Closes #2302

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm lint passes
  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • User-visible strings in the admin UI are wrapped for translation (if applicable). Do not include messages.po changes except in translation PRs — a workflow extracts catalogs on merge to main.
  • I have added a changeset (if this PR changes a published package)
  • New features link to an approved Discussion: https://github.com/emdash-cms/emdash/discussions/...

The i18n and Discussion checklist items are not applicable: this changes no admin UI strings and fixes an existing bug.

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Grok 4.5 / OpenCode; GPT-5 Codex

Screenshots / test output

Non-visual change. Verified after rebasing onto current main with:

  • pnpm build
  • pnpm typecheck
  • pnpm lint
  • pnpm format
  • Core Object Cache and middleware tests: 51 passed
  • Cloudflare Hyperdrive routing/config tests: 25 passed

Try this PR

Open a fresh playground →

A full working EmDash site, deployed from this branch. Each visit gets its own session-scoped sandbox: no login needed and no shared state. Try the admin, edit content, hit the public site.

Tracks fix/prefer-uncached-hyperdrive-after-write. Updated automatically when the playground redeploys.

@changeset-bot

changeset-bot Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2474ebc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 17 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/sandbox-workerd Patch
@emdash-cms/plugin-mcp-smoke Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/do-demo-site Patch
@emdash-cms/do-solo-demo-site Patch
@emdash-cms/admin Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
create-emdash Patch
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

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

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-cache 2474ebc Aug 10 2026, 02:07 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-playground 2474ebc Aug 10 2026, 02:05 PM

@github-actions github-actions Bot added the review/needs-review No maintainer or bot review yet label Jul 29, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@2280

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@2280

@emdash-cms/auth-atproto

npm i https://pkg.pr.new/@emdash-cms/auth-atproto@2280

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@2280

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@2280

@emdash-cms/contentful-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/contentful-to-portable-text@2280

emdash

npm i https://pkg.pr.new/emdash@2280

create-emdash

npm i https://pkg.pr.new/create-emdash@2280

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@2280

@emdash-cms/plugin-cli

npm i https://pkg.pr.new/@emdash-cms/plugin-cli@2280

@emdash-cms/plugin-types

npm i https://pkg.pr.new/@emdash-cms/plugin-types@2280

@emdash-cms/registry-client

npm i https://pkg.pr.new/@emdash-cms/registry-client@2280

@emdash-cms/registry-lexicons

npm i https://pkg.pr.new/@emdash-cms/registry-lexicons@2280

@emdash-cms/registry-verification

npm i https://pkg.pr.new/@emdash-cms/registry-verification@2280

@emdash-cms/sandbox-workerd

npm i https://pkg.pr.new/@emdash-cms/sandbox-workerd@2280

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@2280

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@2280

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@2280

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@2280

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@2280

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@2280

@emdash-cms/plugin-field-kit

npm i https://pkg.pr.new/@emdash-cms/plugin-field-kit@2280

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@2280

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@2280

commit: 2474ebc

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-do 2474ebc Aug 10 2026, 02:06 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
docs 4f895dc Aug 10 2026, 01:11 PM

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR addresses a real problem: with Hyperdrive's cachedBinding, anonymous public reads right after a content publish can reseed edge/object caches from Hyperdrive's still-stale query cache. The approach—tracking the last content-namespace invalidation in the object-cache backend and routing to the primary uncached binding for a configurable window—fits EmDash's existing epoch/invalidation architecture and the split-binding design.

I read the full changed files, traced the routing tests, and checked the marker logic against the object-cache revalidation pattern. The code is generally clean and well-tested, and the changeset/docs are appropriate.

The one blocking concern is a performance regression in getLastContentWriteAt: it refuses to cache a "no writes yet" marker (0), so sites with an object-cache configured will perform an extra backend round-trip on every logged-out request until a content write occurs. That violates the "never add queries to the logged-out hot path" guidance and should be fixed. I also flagged one newly-added config-pin test as low-value.

Once the zero-marker caching is fixed, this looks good to merge.

Comment thread packages/core/src/object-cache/index.ts Resolved
@github-actions github-actions Bot added review/awaiting-author Reviewed; waiting on the author to respond review/needs-rereview New commits since the last review overlap and removed review/needs-review No maintainer or bot review yet review/awaiting-author Reviewed; waiting on the author to respond labels Jul 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Overlapping PRs

This PR modifies files that are also changed by other open PRs:

This may cause merge conflicts or duplicated work. A maintainer will coordinate.

@khoinguyenpham04 khoinguyenpham04 added the bot:review Trigger an emdashbot code review on this PR label Jul 30, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is a sensible, targeted fix for a real Hyperdrive cachedBinding footgun. By tracking the last content-namespace object-cache invalidation and briefly routing anonymous public GETs to the uncached binding, it prevents stale query-cache results from reseeding edge/object caches right after a publish. The approach fits EmDash's existing epoch/invalidation architecture and keeps the window configurable.

The previous review's blocking concern—the getLastContentWriteAt marker not caching a confirmed "no writes yet" value—has been addressed. The new caches a confirmed zero marker within the revalidate window test verifies that sites without content writes no longer pay a backend round-trip on every logged-out request, which satisfies the logged-out hot-path concern.

I read the full changed files, traced the routing logic and the marker lifecycle, and checked the new tests against the behavior. The fix is clean. There are two non-blocking items left: a config-pin test that should be deleted or rewritten, and an unnecessary public export of an internal helper. Once those are addressed, this is good to merge.

Comment on lines +46 to +58
it("passes through preferUncachedAfterWriteMs", () => {
const result = hyperdrive({
binding: "HYPERDRIVE",
cachedBinding: "HYPERDRIVE_CACHED",
preferUncachedAfterWriteMs: 120_000,
});
expect(result.config).toEqual({
binding: "HYPERDRIVE",
max: undefined,
cachedBinding: "HYPERDRIVE_CACHED",
preferUncachedAfterWriteMs: 120_000,
});
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[suggestion] This test passes preferUncachedAfterWriteMs: 120_000 into hyperdrive() and asserts the same value appears in the returned descriptor config. It restates the source code rather than testing behavior, so it can only fail when someone intentionally changes the option plumbing. Per AGENTS.md, config-pin tests inflate coverage without catching regressions and should be deleted or rewritten against observable behavior. A meaningful behavior test already exists in hyperdrive-routing.test.ts for custom windows, so this descriptor test is redundant.

Suggested change
it("passes through preferUncachedAfterWriteMs", () => {
const result = hyperdrive({
binding: "HYPERDRIVE",
cachedBinding: "HYPERDRIVE_CACHED",
preferUncachedAfterWriteMs: 120_000,
});
expect(result.config).toEqual({
binding: "HYPERDRIVE",
max: undefined,
cachedBinding: "HYPERDRIVE_CACHED",
preferUncachedAfterWriteMs: 120_000,
});
});
it("defaults preferUncachedAfterWriteMs to 60s when cachedBinding is set", () => {
const result = hyperdrive({
binding: "HYPERDRIVE",
cachedBinding: "HYPERDRIVE_CACHED",
});
expect(result.config).not.toHaveProperty("preferUncachedAfterWriteMs");
});

Or simply remove this block, since the routing tests cover the custom value behavior.

Comment thread packages/core/src/index.ts Outdated
// Object cache (distributed read-through query cache)
export {
cachedQuery,
getLastContentWriteAt,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[suggestion] getLastContentWriteAt is only used inside core middleware (which passes the resolved stamp to adapters via lastContentWriteAt in RequestScopedDbOpts) and in tests; it is not consumed from the public emdash package. Exporting it from the barrel makes it part of the supported API surface without a clear external consumer.

Suggested change
getLastContentWriteAt,
export {
cachedQuery,
invalidateObjectCache,
invalidateCollectionCache,
invalidateTaxonomyObjectCache,
invalidateBylineObjectCache,
invalidateMenuObjectCache,
invalidateSchemaObjectCache,
invalidateCommentObjectCache,
isObjectCacheActive,
isObjectCacheConfigured,
contentNamespace,
contentNamespaces,
CacheNamespace,
} from "./object-cache/index.js";

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Jul 30, 2026
@github-actions github-actions Bot added review/awaiting-author Reviewed; waiting on the author to respond and removed review/needs-rereview New commits since the last review labels Jul 30, 2026
Comment thread packages/core/src/astro/middleware.ts Outdated
// Even on the anonymous fast path we ask the adapter for a per-request
// scoped db. For D1 with read replication this routes anonymous reads
// to the nearest replica; for other adapters it's a no-op.
const lastContentWriteAt = await getLastContentWriteAt();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This runs on every logged-out request for every adapter, but only Hyperdrive with cachedBinding ever consumes the value. On the recommended D1 + KV setup that's a blocking backend read ahead of render once per revalidate window (1s default, 2s timeout worst case) per isolate, when most sites don't need it.

Gate the fetch on the adapter actually wanting it e.g. a flag on DatabaseDescriptor so middleware doesn't need to know adapter config shapes, and skip it entirely when unset. Same applies to the call in the general request path below.

Comment thread packages/core/src/astro/middleware.ts Outdated
): Promise<T> {
const runtime = await getRuntime(config);

const lastContentWriteAt = await getLastContentWriteAt();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one can just be dropped: runOutsideRequest passes isWrite: true, and selectBindingName never consults lastContentWriteAt on the write path. It's a wasted backend read on every cron tick.

Comment thread packages/core/src/index.ts Outdated
// Object cache (distributed read-through query cache)
export {
cachedQuery,
getLastContentWriteAt,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with the open thread here but there's more: middleware imports this via a relative path, so the export has no consumers - it's permanent public API surface added without needing to. Remove it from the barrel.

});
});

it("passes through preferUncachedAfterWriteMs", () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the open thread about this being a config-pin test I half agree, but note the routing tests construct config objects directly and never go through the hyperdrive() builder, so this is currently the only test that would catch a typo in the conditional spread. Rather than delete it, replace it with one test through the real chain: createRequestScopedDb(hyperdrive({...}).config, { ..., lastContentWriteAt: recent }) asserting the primary pool. That tests behaviour and keeps the builder link covered.

* content-namespace invalidation → primary, so a post-publish rebuild does
* not reseed edge/object caches from Hyperdrive's still-stale query cache.
*
* Pure (no I/O) so the routing rule can be unit-tested directly.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this doc line is no longer true: the new window check calls Date.now() inside. Taking now in opts would make it pure and make the window tests deterministic instead of wall-clock-relative.

@ascorbic

ascorbic commented Aug 8, 2026

Copy link
Copy Markdown
Member

This is a good additioon, and pretty close to ready. Just a few tidiness and perf changes

After a content publish, anonymous public reads briefly use the primary
Hyperdrive binding so edge/object caches are not reseeded from stale
query-cache results (default 60s when cachedBinding is set).
Avoid an object-cache backend round-trip on every logged-out request when
no content write has occurred yet. Also drop a low-value config-pin test.
@ascorbic ascorbic added the bot:review Trigger an emdashbot code review on this PR label Aug 10, 2026
@github-actions github-actions Bot added review/needs-rereview New commits since the last review and removed review/awaiting-author Reviewed; waiting on the author to respond labels Aug 10, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review of #2280

The previously raised blocking concern is resolved: getLastContentWriteAt now caches a confirmed zero marker, so sites without recent content writes do not pay the object-cache backend round-trip on every logged-out request. The internal-test-helper export is also gone.

The approach remains sound: track the last content-namespace invalidation through the existing object-cache backend and briefly route anonymous public GETs to the primary Hyperdrive binding after a publish so stale Hyperdrive query-cache results cannot reseed edge/object caches. The implementation correctly gates the marker read behind canUseCachedBinding && needsLastContentWriteAt, keeping the logged-out hot path narrow.

I read the full changed source files, traced createRequestScopedDb / selectBindingName call sites, and checked that every content-invalidation path uses a content:* namespace that will stamp the marker. I found one new contract issue: a request-free code path still calls createRequestScopedDb with the pre-PR option shape, missing the now-required canUseCachedBinding field. That is a type error against the updated RequestScopedDbOpts contract and should be fixed before merge.

No other blocking issues.


Findings

  • [needs fixing] packages/core/src/astro/middleware.ts:350-357

    runOutsideRequest (used by withEmDashRuntime and cron/event workloads) calls createRequestScopedDb without the required canUseCachedBinding field that virtual:emdash/dialect now expects on RequestScopedDbOpts.

    This is a request-free write workload, so the right value is false; Hyperdrive will still fall back to the primary binding because isWrite: true, but the call violates the updated contract and will break type-checking.

    	const scoped = createRequestScopedDb({
    		config: config.database?.config,
    		isAuthenticated: false,
    		// Event handlers publish, clean up, or run jobs — a write workload —
    		// so a connection-backed adapter routes them to the primary.
    		isWrite: true,
    		canUseCachedBinding: false,
    		cookies: NOOP_COOKIE_JAR,
    		url: CRON_EVENT_URL,
    	});
    

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Aug 10, 2026
@github-actions github-actions Bot added review/awaiting-author Reviewed; waiting on the author to respond and removed review/needs-rereview New commits since the last review labels Aug 10, 2026
@ascorbic ascorbic added the bot:review Trigger an emdashbot code review on this PR label Aug 10, 2026
@github-actions github-actions Bot added review/needs-rereview New commits since the last review cla: signed and removed review/awaiting-author Reviewed; waiting on the author to respond labels Aug 10, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review of #2280

The approach remains sound: use the existing object-cache backend to share the last content-namespace invalidation timestamp, and briefly route anonymous public Hyperdrive reads to the primary uncached binding after a publish so stale Hyperdrive query-cache results cannot reseed edge/object caches. This is the minimal change that fits EmDash's architecture — it reuses invalidateObjectCache's already-deferred epoch writes rather than inventing a new coordination channel.

The previously raised blocking contract issue is resolved: runOutsideRequest now passes canUseCachedBinding: false to createRequestScopedDb, satisfying the updated RequestScopedDbOpts contract.

I read the full changed source files, re-traced createRequestScopedDb / selectBindingName call sites, and checked that every content-invalidation path goes through invalidateCollectionCache, which stamps a content:* namespace via invalidateObjectCache. I also verified that getLastContentWriteAt caches a confirmed-zero marker, so sites without recent content writes avoid repeated object-cache backend reads on every logged-out request.

I found one new contract issue: selectBindingName is exported from the public @emdash-cms/cloudflare/db/hyperdrive runtime entry and this PR made now a required field. Existing callers that passed the previous { isAuthenticated, isWrite, url } shape now get a TypeScript error, and at runtime opts.now - lastWrite becomes NaN, causing the prefer-uncached window to be silently ignored. Since the changeset is a patch and does not call out a break, this should be made backward-compatible by defaulting now.

Overall the implementation is clean, well-tested, and the changeset/docs are in place; fix the API contract and this is good to merge.

Comment on lines +301 to +311
now: number;
},
): string {
if (
config.cachedBinding &&
!opts.isAuthenticated &&
!opts.isWrite &&
!isEmDashInternalPath(opts.url)
(opts.canUseCachedBinding ??
(!opts.isAuthenticated && !opts.isWrite && !isEmDashInternalPath(opts.url)))
) {
const duration = preferUncachedDurationMs(config);
const lastWrite = opts.lastContentWriteAt ?? 0;
if (duration > 0 && lastWrite > 0 && opts.now - lastWrite < duration) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[needs fixing] selectBindingName is exported from the public ./db/hyperdrive runtime entry, so this is a breaking change in a patch release. Previously valid callers that passed only { isAuthenticated, isWrite, url } now fail type-checking, and at runtime opts.now is undefined, so opts.now - lastWrite evaluates to NaN and the post-write prefer-uncached window is silently skipped (the NaN < duration comparison is always false).

Make now optional with a Date.now() default, matching how createRequestScopedDb already handles the field:

Suggested change
now: number;
},
): string {
if (
config.cachedBinding &&
!opts.isAuthenticated &&
!opts.isWrite &&
!isEmDashInternalPath(opts.url)
(opts.canUseCachedBinding ??
(!opts.isAuthenticated && !opts.isWrite && !isEmDashInternalPath(opts.url)))
) {
const duration = preferUncachedDurationMs(config);
const lastWrite = opts.lastContentWriteAt ?? 0;
if (duration > 0 && lastWrite > 0 && opts.now - lastWrite < duration) {
export function selectBindingName(
config: HyperdriveConfig,
opts: {
isAuthenticated: boolean;
isWrite: boolean;
canUseCachedBinding?: boolean;
url: URL;
lastContentWriteAt?: number;
now?: number;
},
): string {
if (
config.cachedBinding &&
(opts.canUseCachedBinding ??
(!opts.isAuthenticated && !opts.isWrite && !isEmDashInternalPath(opts.url)))
) {
const duration = preferUncachedDurationMs(config);
const lastWrite = opts.lastContentWriteAt ?? 0;
const now = opts.now ?? Date.now();
if (duration > 0 && lastWrite > 0 && now - lastWrite < duration) {
return config.binding;
}
return config.cachedBinding;
}
return config.binding;
}

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Aug 10, 2026
@github-actions github-actions Bot added review/awaiting-author Reviewed; waiting on the author to respond and removed review/needs-rereview New commits since the last review labels Aug 10, 2026
@ascorbic ascorbic added the bot:review Trigger an emdashbot code review on this PR label Aug 10, 2026
@github-actions github-actions Bot added review/needs-rereview New commits since the last review and removed review/awaiting-author Reviewed; waiting on the author to respond labels Aug 10, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks ready to merge.

Approach — The PR solves the right problem in the minimal way that fits EmDash. After a content publish it briefly routes anonymous public Hyperdrive reads to the uncached primary binding, using the existing distributed Object Cache backend to share the last content-write timestamp across Worker isolates. It reuses invalidateObjectCache’s already-deferred writes rather than inventing a new coordination channel, and it keeps the change scoped to the Hyperdrive adapter via the new needsLastContentWriteAt descriptor flag.

Re-review status — The only blocking issue from my previous review is resolved: selectBindingName now defaults now with opts.now ?? Date.now(), so the exported runtime API stays backward-compatible and earlier callers cannot hit a NaN window.

What I checked

  • Read the full diff and the changed source files (hyperdrive.ts, index.ts, middleware.ts, adapters.ts, object-cache/index.ts, virtual-modules.d.ts) plus the updated tests.
  • Verified the new getLastContentWriteAt marker uses the same monotonic-merge, timeout, and in-flight-promise reclaim patterns as the existing epoch reader.
  • Traced createRequestScopedDb call sites and confirmed runOutsideRequest passes canUseCachedBinding: false for event/queue workloads.
  • Confirmed invalidateCollectionCache is invoked from every content-mutation path I found.
  • Checked that needsLastContentWriteAt is only set by the Hyperdrive adapter and only when a cachedBinding is configured with a non-zero prefer-uncached window, so D1/SQLite logged-out routes are unaffected.

Headline conclusion — The fix is correct, well-tested, and the changeset/docs are in place. The new object-cache read on the Hyperdrive anonymous public path is an intentional coordination cost (justified by the bug), and the code already caches the confirmed-zero case within the object-cache revalidate window to avoid repeated backend reads on sites with no recent content writes.

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Aug 10, 2026
@github-actions github-actions Bot added review/approved Approved; no new commits since and removed review/needs-rereview New commits since the last review labels Aug 10, 2026

@ascorbic ascorbic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous review requests are addressed; exact-head bot review and CI are green.

@ascorbic
ascorbic merged commit f586100 into main Aug 10, 2026
51 checks passed
@ascorbic
ascorbic deleted the fix/prefer-uncached-hyperdrive-after-write branch August 10, 2026 14:33
@emdashbot emdashbot Bot mentioned this pull request Aug 10, 2026
@ascorbic ascorbic mentioned this pull request Aug 10, 2026
11 of 18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Cache] Purge is inconsistent for specific types of updates

3 participants