Skip to content

realm-server: backfill realm.json card from .realm.json (CS-11150)#4848

Open
backspace wants to merge 2 commits into
mainfrom
realm-json-card-backfill-cs-11150
Open

realm-server: backfill realm.json card from .realm.json (CS-11150)#4848
backspace wants to merge 2 commits into
mainfrom
realm-json-card-backfill-cs-11150

Conversation

@backspace
Copy link
Copy Markdown
Contributor

Summary

  • Adds realm-server/lib/realm-config-card-backfill.ts: a one-time, boot-time migration that materializes a RealmConfig card at /realm.json for every realm directory that doesn't have one yet, populating it from the legacy .realm.json sidecar. After writing the card it trims the migrated keys (name, backgroundURL, iconURL, hostRoutingRules, includePrerenderedDefaultRealmIndex) out of the sidecar.
  • Mirrors the structure of realm-metadata-backfill.ts from CS-10053: same advisory-lock pattern (distinct lock id 7331013), same source / published / bootstrap walk, same idempotent-rerun semantics. Skips realms that already have a realm.json card — the card is the source of truth.
  • 11 qunit tests covering happy path, card-already-exists skip, no-migratable-keys skip, missing sidecar, hostRoutingRules array passthrough, bootstrap, published-realm-via-realm_registry, idempotent rerun, malformed JSON, non-object JSON.

Why

CS-10051 introduced the RealmConfig card and switched parseRealmInfo to prefer it over .realm.json, with the sidecar left as a fallback. No migration was written to create the card for realms that already existed on disk. EFS survey on staging shows 661/701 realm directories (94%) still rely entirely on the legacy sidecar:

.realm.json realm.json card Count
populated absent 661
populated present 17
absent present 21
absent absent 2

Removing the sidecar today (CS-11131) would strip name/icon/background from those 661 realms. This PR unblocks that.

After this PR ships and is verified-complete in every environment, the module becomes dead code and is removed alongside the sidecar in CS-11131. CS-11131's description has been updated with that cleanup checklist.

Out of scope

  • CS-11131 (remove .realm.json entirely) is gated on this PR + CS-10055 + CS-11151.
  • CS-11151 covers boxel-home, boxel-catalog, boxel-skills sister repos that still ship their own populated .realm.json and need realm.json cards added upstream.

Test plan

  • New tests pass: MATRIX_REGISTRATION_SHARED_SECRET=test-secret TEST_FILES=realm-config-card-backfill-test pnpm --filter @cardstack/realm-server test (11/11 ✓)
  • Verify on staging: after deploy, EFS survey shows zero populated .realm.json + absent realm.json rows. (aws-access skill + boxel-claude-fs-readonly task)
  • Verify on prod: same.
  • Investigate the 2 staging edge-case rows with stale showAsCatalog/publishable in .realm.json after this runs (the metadata-backfill trim should have already converged; if not, separate bug).

🤖 Generated with Claude Code

…(CS-11150)

The CS-10051 RealmConfig card was added without a migration for existing
realm directories — staging shows 661/701 realms still relying entirely
on the legacy .realm.json sidecar. This backfill walks each realm
directory on boot, writes /realm.json as a RealmConfig card when the
card is absent, and trims the migrated fields (name, backgroundURL,
iconURL, hostRoutingRules, includePrerenderedDefaultRealmIndex) out of
the sidecar. Pre-existing cards are left alone — the card is the source
of truth and the backfill never overwrites it.

Mirrors realm-metadata-backfill.ts (CS-10053): same advisory-lock
pattern (distinct lock id 7331013), same source/published/bootstrap
walk, same idempotent-rerun semantics. Unblocks CS-11131 once verified
in every environment.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4b71e3cb69

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +245 to +246
if (!url) {
continue;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid skipping published realms when registry rows are absent

In a multi-instance startup wave, one process can skip runRegistryBackfillWithAdvisoryLock (lock held elsewhere) and still win the config-backfill lock, so this published-realm pass may run before realm_registry has the disk_id -> url rows; in that case if (!url) continue drops those realms and they remain unmigrated for that rollout because the process that did finish registry can then skip config-backfill due lock contention. This leaves some published realms without realm.json, which defeats the migration guarantees needed before .realm.json removal.

Useful? React with 👍 / 👎.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 15, 2026

Host Test Results

    1 files  ±0      1 suites  ±0   1h 27m 21s ⏱️ - 2m 41s
2 659 tests ±0  2 644 ✅ ±0  15 💤 ±0  0 ❌ ±0 
2 678 runs  ±0  2 663 ✅ ±0  15 💤 ±0  0 ❌ ±0 

Results for commit ccf3214. ± Comparison against earlier commit 4b71e3c.

Realm Server Test Results

    1 files  ±0      1 suites  ±0   9m 5s ⏱️ + 1m 0s
1 388 tests ±0  1 388 ✅ ±0  0 💤 ±0  0 ❌ ±0 
1 469 runs  ±0  1 469 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit ccf3214. ± Comparison against earlier commit 4b71e3c.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant