close
Skip to content

fix: address #631 review feedback#636

Merged
ascorbic merged 1 commit intomainfrom
fix/pr-631-followup
Apr 17, 2026
Merged

fix: address #631 review feedback#636
ascorbic merged 1 commit intomainfrom
fix/pr-631-followup

Conversation

@ascorbic
Copy link
Copy Markdown
Collaborator

Follow-up to #631. Addresses two real issues raised in the Copilot review:

  • ensureSearchHealthy() was calling FTSManager with this.db, which on GET search requests is a D1 Sessions Kysely bound to first-unconstrained routing. The verify step reads, but a mismatched row count triggers a rebuild write, which can land on a replica instead of the primary. Switched to this._db (singleton) so repair writes always route to the primary via the adapter's own first-primary promotion.
  • The playground branch in request-context.ts middleware was creating an ALS context without dbIsIsolated, which meant module-scoped caches (manifest, taxonomy defs, byline/term probes) would be reused across playground sessions with independent schemas. Added the flag.

Also tidied the ensureSearchHealthy docstring; the original mentioned "admin routes" as callers but only the search/suggest endpoints actually call it.

The two other review comments are left unaddressed intentionally:

  • "Async recursion in getRuntime risks stack overflow" — await suspends the stack, so recursion through async calls doesn't accumulate frames the way sync recursion does. The loop form would be functionally identical; not worth changing.
  • "Changeset numbers don't match PR body" — already reconciled before merge; the changeset now describes the improvement qualitatively and the PR body carries the measurement table.

Type of change

  • Bug fix
  • Feature
  • 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 (2395)
  • pnpm format has been run
  • I have added/updated tests for my changes (N/A — one behavioral fix affects only a rarely-hit repair path on D1 Sessions; covering it reliably would require mocking the D1 adapter internals)
  • I have added a changeset

AI-generated code disclosure

  • This PR includes AI-generated code

- ensureSearchHealthy() uses the singleton DB so index rebuilds land
  on the primary instead of whichever replica the request session
  happened to route to.
- Playground request context now carries dbIsIsolated so per-session
  DO schemas don't accidentally share module-scope cache entries.
Copilot AI review requested due to automatic review settings April 17, 2026 18:54
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 17, 2026

🦋 Changeset detected

Latest commit: 8341151

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

This PR includes changesets to release 10 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/perf-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/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

@github-actions
Copy link
Copy Markdown
Contributor

PR template validation failed

Please fix the following issues by editing your PR description:

  • Fill out the "What does this PR do?" section with a description of your change.

See CONTRIBUTING.md for the full contribution policy.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Apr 17, 2026

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 8341151 Apr 17 2026, 06:56 PM

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 17, 2026

Open in StackBlitz

@emdash-cms/admin

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

@emdash-cms/auth

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

@emdash-cms/blocks

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

@emdash-cms/cloudflare

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

emdash

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

create-emdash

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

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

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

@emdash-cms/x402

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

@emdash-cms/plugin-ai-moderation

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

@emdash-cms/plugin-atproto

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

@emdash-cms/plugin-audit-log

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

@emdash-cms/plugin-color

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

@emdash-cms/plugin-embeds

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

@emdash-cms/plugin-forms

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

@emdash-cms/plugin-webhook-notifier

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

commit: 8341151

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Follow-up correctness fix to the cold-start/runtime work from #631, ensuring search index repair operations and schema-derived caches behave safely under D1 Sessions and isolated playground databases.

Changes:

  • Run ensureSearchHealthy() against the runtime singleton DB (this._db) so any repair/rebuild writes cannot route to a replica via request-scoped D1 Sessions DB.
  • Mark playground DO-backed DB overrides as isolated (dbIsIsolated: true) so module-scoped schema-derived caches are bypassed per session.
  • Add a changeset documenting the two fixes.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/core/src/emdash-runtime.ts Switches ensureSearchHealthy() to use the singleton DB and updates docstring to match actual callers + D1 Sessions routing constraints.
packages/core/src/astro/middleware/request-context.ts Ensures playground ALS context sets dbIsIsolated: true to prevent cross-session cache reuse with divergent schemas.
.changeset/pr-631-followup.md Adds release note describing the two correctness fixes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ascorbic ascorbic merged commit 6d41fe1 into main Apr 17, 2026
33 of 34 checks passed
@ascorbic ascorbic deleted the fix/pr-631-followup branch April 17, 2026 20:43
@emdashbot emdashbot bot mentioned this pull request Apr 17, 2026
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.

2 participants