Skip to content

feat: resolve site backends through shared KV - #349

Merged
kptdobe merged 5 commits into
mainfrom
feat/shared-site-backend-registry
Nov 25, 2026
Merged

kptdobe merged 5 commits into
mainfrom
feat/shared-site-backend-registry

Conversation

@kptdobe

@kptdobe kptdobe commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Replace HLX6_MIGRATED_SITES with the shared DA_SITE_BACKENDS KV registry (org/site -> da or hlx6), normalizing cached values.
  • Probe Helix Admin only on misses; successful results persist, while 404-derived results expire after 300 seconds. HLX_ADMIN configures the probe base URL.
  • Fail closed on KV read/probe errors. Log KV write failures and return the known backend result. Keep request-scoped I/O independent across requests.
  • Preserve admin-only dual-write overrides and async dispatch/copy/move destination guards.
  • Require read or readable-descendant permission before listing probes. Gate HLX6 org discovery on existing registry entries, filter candidates before resolution, and preserve partial successes.
  • Cache positive and negative org-discovery gates for 300 seconds at org:<org>. Warm gates require one KV read and no listing/bulk-read scan; misses scan and refresh the derived cache.
  • Update environment typings for DA_SITE_BACKENDS and HLX_ADMIN, removing the obsolete migrated-sites variable.
  • Bind the shared production/staging namespaces and document rollout, manual cutover, remaining probe-traffic risk, and forward-or-410 contributor requirements.

Rollout and limits

  • Preload all sites still served by DA, including dual-write sites, as da, and migrated sites as hlx6. Audit conflicting inventory instead of overwriting authoritative entries.
  • For every new DA-served site after rollout, explicitly seed a non-expiring da entry and wait for KV propagation before its first request, including document creation. Site creation does not seed the registry automatically.
  • The upgrade header reflects source-bus configuration, including overlays; it does not prove completed migration. Explicit registry entries take precedence.
  • Deploy da-admin before feat: use shared KV for content site routing da-content#35.
  • For cutover, pause traffic, drain in-flight requests/probes, update KV, end dual write in da-admin, and verify propagation before resuming traffic. KV is eventually consistent (60 seconds or more).
  • A wholly uncached HLX6-only org needs a direct site request or a seeded entry before org discovery starts. Cached discovery gates can add five minutes of listing lag; after backend changes propagate, optionally delete the derived org:<org> entry to refresh sooner. Direct site routing is unaffected.
  • The 404 TTL bounds retention, not traffic; public content and open-org requests can still generate cold probes. Duplicate concurrent probes or gate refreshes remain possible.

Validation

  • Full admin suite: 718 passing, including conditional-request tests.
  • Targeted registry and bridge suite: 184 passing.
  • ESLint and production Wrangler dry-run build passed; no manual deployment.
  • Pushed-head integration and deployment checks: https://github.com/adobe/da-admin/actions/runs/45390558278

Companion

adobe/da-content#35. Deploy da-admin first.

Replace migrated-site lists with cached ping detection. Keep dual-write
overrides in admin and fail closed on registry or probe errors.

Seed migrated sites as hlx6 and active dual-write sites as da before
rollout. KV cutovers require propagation and request draining.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@codecov

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@kptdobe
kptdobe requested a review from bosschaert November 24, 2026 10:44
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bosschaert

Copy link
Copy Markdown
Contributor

Review

Swapping the hand-maintained env list for a shared registry is a good direction, and the cutover steps in the README are clear. Lint passes and the unit tests pass (702). The main risks are in the cold-lookup probe.

Should fix

  1. Any signed-in user can create permanent registry entries (index.js#L64, hlx6.js#L132). /list/{org}/{anything} skips the authorized check, and orgs without ACLs authorize everyone anyway. So any made-up org/site name triggers a call to admin.hlx.page and a permanent KV write. That means unbounded KV growth, KV write costs and probe traffic. Suggest probing only after the DA permission check passes.
  2. 404s are stored as da forever (hlx6.js#L132). If anyone touches a site before it exists on AEM, it stays da after it's later created on HLX6, and da-content keeps serving it from R2. Suggest storing 404s with an expirationTtl, or not storing them at all.
  3. Rollout risk (hlx6.js#L117). Only migrated and dual-write sites get pre-loaded into the registry, so every other DA site is probed on its first request. A failed probe fails the request, so a 429, 5xx or timeout from admin.hlx.page during rollout becomes a 500 for ordinary DA users. Suggest pre-loading all existing DA sites as da before deploying.
  4. Every org listing now calls HLX6 (index.js#L82, routes/hlx6.js#L253). With the org check removed, every org listing in every org calls api.aem.live and then does a lookup per HLX6 site. That's up to about 3s + 3s of extra latency. A single failed lookup also drops all HLX6 sites from the listing because of Promise.all; Promise.allSettled would keep the rest.

Minor

  1. Shared in-flight lookups (hlx6.js#L100). Concurrent lookups share one promise across requests (siteLookups). In Workers, if the request that started the probe is cancelled, the other requests waiting on it can fail with a "code had hung" error (see Workers best practices). Since KV already serves repeat lookups, dropping this sharing is safer.
  2. Probe result lost on KV failure (hlx6.js#L132). If the KV put fails after a successful probe, the request returns 500 even though the answer is known. Returning the result and logging the error would be better.
  3. Exact value match (hlx6.js#L120). Registry values must be exactly da or hlx6. A manual typo like HLX6 or a trailing newline makes every request to that site return 500. Consider trimming and lowercasing.
  4. Hardcoded probe host (hlx6.js#L123). The admin.hlx.page URL is hardcoded, so stage and CI probe production. AEM_API, by contrast, is configurable.

Question: does x-api-upgrade-available mean the content has already moved to HLX6, or only that the site can upgrade? If it's the latter, a site whose content is still in DA would be stored as hlx6 permanently and its content would become unreachable through da-admin.

Expire negative probes and keep known routing results on cache write failures.
Authorize listing probes and gate org discovery on cached HLX6 sites.
Avoid sharing request-scoped I/O between Worker requests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@kptdobe

kptdobe commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@bosschaert Thanks — addressed in cf6aa44, with the shared resolver fixes also pushed to adobe/da-content#35.

  1. Site listings now require read or readable-descendant permission before backend detection. Org discovery filters individual candidates by DA ACLs before resolving/probing them, while preserving descendant-only browsing.
  2. Ping 404 classifications now use expirationTtl: 300 (the agreed five-minute policy). Successful non-404 classifications and manual entries remain persistent.
  3. Rollout instructions now require preloading all sites still served by DA as da, including dual-write sites, not just migrated entries. Existing authoritative entries must not be blindly overwritten. This is a deployment prerequisite; this update did not seed production data or deploy production.
  4. Org discovery is now gated by an already-cached, non-dual-writing HLX6 site. The gate uses paginated KV listing plus bulk reads of at most 100 keys and never pings. Candidate resolution uses Promise.allSettled, logging failed lookups while retaining healthy sites. The agreed tradeoff: a wholly uncached HLX6-only org needs a direct site request or a seeded entry before discovery starts.
  5. Removed cross-request promise sharing in both workers; each cold request owns its I/O.
  6. KV write failures are logged and the known probe result is returned. KV read/probe failures still fail closed.
  7. Cached values are trimmed and lowercased; genuinely invalid values still fail explicitly.
  8. Added HLX_ADMIN to configure the probe base URL; local integration tests point it at their mock server rather than production.

Header semantics: the upgrade header reflects source-bus configuration, including an AEM API source or overlay; it does not prove completed migration. The originally requested heuristic remains, but this limitation and the need to preload still-DA sites are now explicit. Manual registry values take precedence.

Residual limit: the TTL bounds retention, not traffic. Open-org access and unauthenticated da-content requests can still generate arbitrary-name probes/KV writes. No rate limiter or org-existence policy was introduced, so this should not be read as eliminating that cost/abuse risk.

Validation: 712 admin tests pass; lint and the production dry-run build pass. All pushed-head PR checks are green, including the Build workflow. The companion has 111 passing tests with 100% coverage in all four categories and green CI. PR descriptions and operational docs have been updated.

@bosschaert

Copy link
Copy Markdown
Contributor

Follow-up review (cf6aa44)

Thanks @kptdobe. I checked the update against your replies, and all 8 points are addressed in the code. Lint passes and the unit tests pass (712). I agree the two residual risks are now stated explicitly: arbitrary-name probes in orgs without ACLs and from da-content, and the upgrade header being a heuristic that relies on pre-loading every site still on DA.

Remaining concerns

  1. Org listings now scan KV (hlx6.js#L180, #L189). hasHlx6Sites lists all of an org's registry keys and bulk-reads their values on every org listing. KV list calls aren't edge-cached and are billed like writes. Once every DA site is pre-loaded as da, DA-only orgs (most of them) take the full scan every time. A single per-org marker key, or storing the backend in key metadata so the list call alone is enough, would avoid this.
  2. New DA sites can be auto-flipped to hlx6 (hlx6.js#L136). A DA site created after the pre-load whose AEM config has an API source or overlay will be stored as hlx6 permanently by the probe. Its content would then be unreachable through da-admin. That's worth an ops note, or having site creation write da to the registry.
  3. Stale typings (nit) (index.d.ts#L30). src/index.d.ts still documents HLX6_MIGRATED_SITES, which is no longer read, and lacks DA_SITE_BACKENDS and HLX_ADMIN.

Cache both gate results for five minutes to avoid per-listing KV scans.
Keep direct site routing authoritative and document cache invalidation.
Require registry pre-seeding for new DA sites and refresh env typings.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@kptdobe

kptdobe commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@bosschaert Thanks for the follow-up. Addressed the three remaining concerns in c18c909:

  1. Org-listing KV scans: added the agreed five-minute derived gate cache at org:<org>, for both positive and negative results. Cache hits perform one KV get, with no list or bulk-read scan. Only misses/expiry scan the registry and cache the result with expirationTtl: 300. Cache-write failures are logged without losing the computed result. Regressions verify both cache values, exact TTL, no rescans or TTL renewal on hits, invalidation, and failed cache writes.
  2. DA sites created after rollout: added an explicit provisioning section requiring a non-expiring org/site = da entry before every new DA-served site receives its first request, including first-document creation. Operators must wait for propagation and must not rely on a temporary 404 entry. Site creation still does not seed the registry automatically; this is the documented ops prerequisite to avoid an API-source/overlay header selecting HLX6 prematurely. Matching guidance was pushed to feat: use shared KV for content site routing da-content#35 in b9ddbd3657156a53c19ef06706c5c2c2ba7c9c68.
  3. Typings: updated Env to remove HLX6_MIGRATED_SITES, declare the DA_SITE_BACKENDS KV binding, and add optional HLX_ADMIN.

Cache tradeoff: scans still happen on cold/expired org gates, and concurrent misses can duplicate them. New HLX6 sites or dual-write changes can take five minutes plus KV propagation to affect org discovery. Direct site routing remains authoritative and does not consult the org cache. The cutover docs explain optionally deleting the derived org:<org> entry after site updates propagate to refresh discovery sooner.

Validation: 718 full-suite tests and 184 focused registry/bridge tests pass; lint and the production dry-run build pass. The pushed-head Build workflow is green, including unit tests, local integration, branch deployment, and post-deployment integration. The companion documentation-head CI is also green. PR descriptions are updated; no manual production deployment or production registry seeding was performed.

@kptdobe
kptdobe merged commit a685e2e into main Nov 25, 2026
6 checks passed
@kptdobe
kptdobe deleted the feat/shared-site-backend-registry branch November 25, 2026 07:58
adobe-bot pushed a commit that referenced this pull request Nov 25, 2026
# [1.18.0](v1.17.0...v1.18.0) (2026-11-25)

### Features

* resolve site backends through shared KV ([#349](#349)) ([a685e2e](a685e2e))
@adobe-bot

Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 1.18.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants