Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
0af78c0
feat(spec,metadata-protocol): Seed.fallback marks an object's fallbac…
claude Nov 17, 2026
7ddb914
test(spec,metadata-protocol): pin Seed.fallback schema rule and loade…
claude Nov 17, 2026
b5a66a3
test(runtime): pin Seed.fallback on the boot, replay, install, reseed…
claude Nov 17, 2026
18a0662
chore(spec): record Seed.fallback live in the liveness ledger
claude Nov 17, 2026
610df04
docs(spec): regenerate seed references for Seed.fallback
claude Nov 17, 2026
5edf145
docs(data-modeling): document the Seed.fallback locale set
claude Nov 17, 2026
7f6197c
docs(skills): name Seed.locale and Seed.fallback in the seeds field t…
claude Nov 17, 2026
2fb04ec
chore(changeset): Seed.fallback
claude Nov 17, 2026
d6c698e
fix(skills,runtime): pay the seeds token ratchet by deleting restated…
claude Nov 18, 2026
6e739df
Merge remote-tracking branch 'origin/main' into claude/issue-34940-se…
claude Nov 18, 2026
e020dc2
revert(skills): restore seeds.md to origin/main; the field rows move …
claude Nov 18, 2026
f64d23e
fix(seed): refuse only the object's duplicate fallback sets, counting…
claude Nov 18, 2026
09232b7
Merge origin/main into claude/issue-34940-seed-locale-fallback
claude Nov 18, 2026
e2c865b
fix(metadata-protocol): refuse only the fallback choice for an object…
claude Nov 18, 2026
6e660b0
test(runtime): pin a replay after an upgrade that changed the marked …
claude Nov 18, 2026
00b85b6
docs(spec): regenerate the seed references for the fallback describe …
claude Nov 18, 2026
cc0a04b
Merge branch 'main' into claude/issue-34940-seed-locale-fallback
objectstack-fleet[bot] Nov 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .changeset/34940-seed-locale-fallback.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
'@objectstack/spec': minor
'@objectstack/metadata-protocol': minor
---

feat(spec, metadata-protocol): `Seed.fallback` marks the set an organization gets when its locale matches no set of the object

Clause-②: yes (widening) — one new optional key, `fallback: true`, on a seed dataset (`SeedSchema`); a seed without it parses and loads exactly as before
Metadata-protocol: added

An app that splits a seed by language with `locale` (a `zh-CN` and an `en` set of the standard price book) used to leave an organization on any other locale (`ja-JP`, `es-ES`) with neither set. Mark one set `fallback: true` and it also loads for every resolved locale that no locale-scoped set of the same object lists:

```ts
defineSeed(PriceBook, { locale: ['zh-CN'], records: [{ name: '标准价格表' }] });
defineSeed(PriceBook, { locale: ['en', 'en-US'], fallback: true, records: [{ name: 'Standard' }] });
```

It is honoured wherever a load filters by locale: the boot seed and the dev hot reload (the app's `i18n.defaultLocale`), and the per-organization replay, marketplace install, sample-data reseed and restart heal (the locale `resolveSeedLocaleForLoad` resolves). The loader logs each fallback set it loaded, at info.

- The marker needs `locale`: `fallback: true` on a dataset with no `locale` is refused when the seed is parsed, because an unscoped dataset already loads for every locale. The published JSON Schema carries the rule as `dependentRequired`.
- A dataset with no `locale` does not count as a match: it loads beside whichever set is chosen.
- `env` is applied first; a set it scoped out neither matches nor falls back.
- At most one fallback set per object in a load: with two different marked sets of one object, only the fallback choice is refused. No marked set fills in for a locale no set lists, and the load reports one error per object (`field: 'fallback'`), logged at warn; every marked set still loads for the locales it lists, as an unmarked set would, and every other object still seeds. Identical copies of one set (a package's datasets merged twice) count once; an upgrade that changed a package's marked set leaves two sets on the replay list until the process restarts.
- A load with no locale (package apply, draft publish, an install no rung resolved a locale for) loads every dataset, the fallback set included, and warns as before.
61 changes: 60 additions & 1 deletion content/docs/data-modeling/seed-data.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,62 @@ dataset wrote: both sets stay resident and queryable, because the switch is
additive and not a migration. Clearing the market you left behind is the
operator's job — to switch locales cleanly, start from a fresh database.

### A Fallback Set — `fallback: true`

A locale that no dataset of an object names gets **none** of that object's
locale-scoped rows. Where the seed is functional rather than decorative — the
standard price book that quotes fall back to — an organization on `ja-JP` would
end up with no price book at all when you ship only a `zh-CN` and an `en` set.
Mark one set `fallback: true` and it also loads for every locale no other set
of the object names:

```typescript
defineSeed(PriceBook, {
locale: ['zh-CN'],
records: [{ name: '标准价格表' }],
});

defineSeed(PriceBook, {
locale: ['en', 'en-US'],
fallback: true, // also loads for ja-JP, es-ES, … — any locale no PriceBook set names
records: [{ name: 'Standard' }],
});
```

| Resolved locale | `PriceBook` rows loaded |
|:---|:---|
| `zh-CN` | the `zh-CN` set |
| `en`, `en-US` | the `en` set (its own locales) |
| `ja-JP`, `es-ES`, … | the `en` set, as the fallback |
| none (package apply, draft publish, an unresolved install) | both sets, with the usual warning |

The rules:

- **The fallback set lists its own locales.** `fallback: true` on a dataset with
no `locale` is refused when the seed is parsed: an unscoped dataset already
loads for every locale, so it cannot also be the set that loads only when no
other set matches. Write the locales the set is in and keep the marker.
- **A set with no `locale` does not count as a match.** It is locale-neutral: it
loads beside whichever set is chosen, and the fallback still fills in.
- **Matching is per object**, case-insensitive and otherwise exact, as above. A
`ja-JP` set of some *other* object does not stop the price book's fallback.
- **`env` is applied first.** A set `env` scoped out of the load neither matches
nor falls back.
- **At most one fallback set per object in a load.** Two different sets of one
object both marked `fallback: true` leave no single choice, so only the
fallback choice is refused: no marked set fills in for a locale no set lists,
and the load's error (also logged at warn) names the object. Every marked set
still loads for the locales it lists, exactly as an unmarked set would, and
every other object still seeds. Identical copies of one set — the same
package's datasets merged twice — count once. Two versions of one package
whose marked set changed are two sets: an upgrade keeps the earlier
version's datasets on the per-organization replay list until the process
restarts, so until then an organization on an unlisted locale gets no
fallback for that object.

The loader logs, at info, each fallback set it loaded and the locale it filled
in for. Datasets without the marker load exactly as before.

<Callout type="info">
**Where the loading locale comes from.** On the normal boot path your stack
supplies it: the runtime reads your app's `i18n.defaultLocale` and passes it to
Expand Down Expand Up @@ -801,7 +857,9 @@ When the same records need different display strings per language, author both
datasets and scope each with `locale`. Selecting between them in application
code instead bakes the choice into your build output, so shipping another
market means another build. Neither approach removes what the market you left
behind already wrote — see [Locale Scoping](#locale-scoping).
behind already wrote — see [Locale Scoping](#locale-scoping). Mark one set
`fallback: true` so a market you did not author still gets functional rows —
see [A Fallback Set](#a-fallback-set--fallback-true).

### Leave `mode` unset for data the customer owns

Expand Down Expand Up @@ -842,6 +900,7 @@ function defineSeed<
columns?: { [field: string]: { applyOn?: 'create' | 'always' } }; // per-column write policy; default: 'always'
env?: Array<'prod' | 'dev' | 'test'>; // default: ['prod','dev','test']
locale?: string[]; // BCP-47 tags; omitted = every locale
fallback?: true; // also load for a locale no other set of the object names (needs locale)
dependsOn?: string[]; // objects this dataset loads after (see "Load Order")
records: Array<SeedRecord<TObj['fields']>>; // declared fields + injectable system columns
}
Expand Down
6 changes: 4 additions & 2 deletions content/docs/references/api/package-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ Package manifest installed through POST /api/v1/packages (AUTHORING stage; scope
| **mode** | `Enum<'insert' \| 'update' \| 'upsert' \| 'replace' \| 'ignore'>` | optional (default: `"ignore"`) | What a load does with a record whose `externalId` matches an existing row. `ignore` (default) is create-only: a missing row is inserted and an existing row is left as it is, so a replay (every boot, a package install or upgrade, a publish) never writes a seeded value back over a later edit. `upsert` also writes every declared column back onto the matched row on each replay; declare it for reference data the package keeps current. `update` writes matched rows only, `insert` inserts every record with no match, so each replay inserts them again, and `replace` does the same and deletes nothing: it is for a table the caller cleared. On the loads that seed an organization (the boot seed, a seed-replayer replay, the dev hot reload, a package install or upgrade), an `ignore` or `upsert` row that landed once and was later deleted is not inserted again; a publish, or a load that names no organization and finds no sole one, keeps no such record, and seed-replayer called with `{ reseed: true }` or the sample-data reseed inserts every missing row. |
| **columns** | `Record<string, { applyOn?: Enum<'create' \| 'always'> }>` | optional | Per-column write policy, keyed by field name: `{ status: { applyOn: 'create' } }` writes `status` only when the seed creates the row. Omitted, every column is written on create and update. |
| **env** | `Enum<'prod' \| 'dev' \| 'test'>[]` | optional (default: `["prod","dev","test"]`) | Applicable environments |
| **locale** | `string[]` | optional | Applicable locales (BCP-47 tags); omitted applies to every locale. The boot seed filters on the app's i18n.defaultLocale; the marketplace install, sample-data reseed, restart heal and per-organization replay filter on the locale resolved for the load (the localization.locale setting when set, then the locale of the installing, reseeding or founding user, then the app's i18n.defaultLocale where the load names one); package apply and draft publish do not filter by locale — they load every dataset and warn |
| **locale** | `string[]` | optional | Applicable locales (BCP-47 tags); omitted applies to every locale. The boot seed filters on the app's i18n.defaultLocale; the marketplace install, sample-data reseed, restart heal and per-organization replay filter on the locale resolved for the load (the localization.locale setting when set, then the locale of the installing, reseeding or founding user, then the app's i18n.defaultLocale where the load names one); package apply and draft publish do not filter by locale — they load every dataset and warn. A locale no dataset of the object names gets none of its locale-scoped rows, unless one is marked `fallback: true` |
| **fallback** | `true` | optional | Marks this locale-scoped dataset as its object's fallback: it also loads for a resolved locale that no other locale-scoped dataset of the same object lists. Requires `locale`: a dataset with no locale already loads everywhere, and the pair is refused. At most one dataset per object in a load may be marked; with two different marked datasets of one object, none is used as the fallback and the load reports the object, while each still loads for the locales it lists, as an unmarked dataset would (identical copies count once). A load with no locale loads it like every other dataset. Omitted, the dataset loads only for the locales it lists. |
| **dependsOn** | `string[]` | optional | Objects (by name) this dataset loads after, for an order no lookup field gives — e.g. a beforeInsert hook that reads another seeded object. Each name adds an edge to the load's dependency graph. The load is refused, writing nothing, when a name is the dataset's own object, is not seeded by another dataset of the same load, or closes a cycle with the other edges. Omitted, the order comes from lookup fields alone. |
| **records** | `Record<string, any>[]` | ✅ | Data records |
| **files** | `Record<string, { contentType: string; size: integer; sha256: string; data: string }>` | optional | Bytes of the package files the records name with `seedFile(path)`, keyed by path. Written by `os build`, which reads each path relative to the package root; the loader stores each one as a file the written record owns. |
Expand Down Expand Up @@ -355,7 +356,8 @@ Package manifest installed through POST /api/v1/packages (AUTHORING stage; scope
| **mode** | `Enum<'insert' \| 'update' \| 'upsert' \| 'replace' \| 'ignore'>` | optional (default: `"ignore"`) | What a load does with a record whose `externalId` matches an existing row. `ignore` (default) is create-only: a missing row is inserted and an existing row is left as it is, so a replay (every boot, a package install or upgrade, a publish) never writes a seeded value back over a later edit. `upsert` also writes every declared column back onto the matched row on each replay; declare it for reference data the package keeps current. `update` writes matched rows only, `insert` inserts every record with no match, so each replay inserts them again, and `replace` does the same and deletes nothing: it is for a table the caller cleared. On the loads that seed an organization (the boot seed, a seed-replayer replay, the dev hot reload, a package install or upgrade), an `ignore` or `upsert` row that landed once and was later deleted is not inserted again; a publish, or a load that names no organization and finds no sole one, keeps no such record, and seed-replayer called with `{ reseed: true }` or the sample-data reseed inserts every missing row. |
| **columns** | `Record<string, { applyOn?: Enum<'create' \| 'always'> }>` | optional | Per-column write policy, keyed by field name: `{ status: { applyOn: 'create' } }` writes `status` only when the seed creates the row. Omitted, every column is written on create and update. |
| **env** | `Enum<'prod' \| 'dev' \| 'test'>[]` | optional (default: `["prod","dev","test"]`) | Applicable environments |
| **locale** | `string[]` | optional | Applicable locales (BCP-47 tags); omitted applies to every locale. The boot seed filters on the app's i18n.defaultLocale; the marketplace install, sample-data reseed, restart heal and per-organization replay filter on the locale resolved for the load (the localization.locale setting when set, then the locale of the installing, reseeding or founding user, then the app's i18n.defaultLocale where the load names one); package apply and draft publish do not filter by locale — they load every dataset and warn |
| **locale** | `string[]` | optional | Applicable locales (BCP-47 tags); omitted applies to every locale. The boot seed filters on the app's i18n.defaultLocale; the marketplace install, sample-data reseed, restart heal and per-organization replay filter on the locale resolved for the load (the localization.locale setting when set, then the locale of the installing, reseeding or founding user, then the app's i18n.defaultLocale where the load names one); package apply and draft publish do not filter by locale — they load every dataset and warn. A locale no dataset of the object names gets none of its locale-scoped rows, unless one is marked `fallback: true` |
| **fallback** | `true` | optional | Marks this locale-scoped dataset as its object's fallback: it also loads for a resolved locale that no other locale-scoped dataset of the same object lists. Requires `locale`: a dataset with no locale already loads everywhere, and the pair is refused. At most one dataset per object in a load may be marked; with two different marked datasets of one object, none is used as the fallback and the load reports the object, while each still loads for the locales it lists, as an unmarked dataset would (identical copies count once). A load with no locale loads it like every other dataset. Omitted, the dataset loads only for the locales it lists. |
| **dependsOn** | `string[]` | optional | Objects (by name) this dataset loads after, for an order no lookup field gives — e.g. a beforeInsert hook that reads another seeded object. Each name adds an edge to the load's dependency graph. The load is refused, writing nothing, when a name is the dataset's own object, is not seeded by another dataset of the same load, or closes a cycle with the other edges. Omitted, the order comes from lookup fields alone. |
| **records** | `Record<string, any>[]` | ✅ | Data records |
| **files** | `Record<string, { contentType: string; size: integer; sha256: string; data: string }>` | optional | Bytes of the package files the records name with `seedFile(path)`, keyed by path. Written by `os build`, which reads each path relative to the package root; the loader stores each one as a file the written record owns. |
Expand Down
3 changes: 2 additions & 1 deletion content/docs/references/data/seed-loader.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ Seed loader request with datasets and configuration
| **mode** | `Enum<'insert' \| 'update' \| 'upsert' \| 'replace' \| 'ignore'>` | optional (default: `"ignore"`) | What a load does with a record whose `externalId` matches an existing row. `ignore` (default) is create-only: a missing row is inserted and an existing row is left as it is, so a replay (every boot, a package install or upgrade, a publish) never writes a seeded value back over a later edit. `upsert` also writes every declared column back onto the matched row on each replay; declare it for reference data the package keeps current. `update` writes matched rows only, `insert` inserts every record with no match, so each replay inserts them again, and `replace` does the same and deletes nothing: it is for a table the caller cleared. On the loads that seed an organization (the boot seed, a seed-replayer replay, the dev hot reload, a package install or upgrade), an `ignore` or `upsert` row that landed once and was later deleted is not inserted again; a publish, or a load that names no organization and finds no sole one, keeps no such record, and seed-replayer called with `{ reseed: true }` or the sample-data reseed inserts every missing row. |
| **columns** | `Record<string, { applyOn?: Enum<'create' \| 'always'> }>` | optional | Per-column write policy, keyed by field name: `{ status: { applyOn: 'create' } }` writes `status` only when the seed creates the row. Omitted, every column is written on create and update. |
| **env** | `Enum<'prod' \| 'dev' \| 'test'>[]` | optional (default: `["prod","dev","test"]`) | Applicable environments |
| **locale** | `string[]` | optional | Applicable locales (BCP-47 tags); omitted applies to every locale. The boot seed filters on the app's i18n.defaultLocale; the marketplace install, sample-data reseed, restart heal and per-organization replay filter on the locale resolved for the load (the localization.locale setting when set, then the locale of the installing, reseeding or founding user, then the app's i18n.defaultLocale where the load names one); package apply and draft publish do not filter by locale — they load every dataset and warn |
| **locale** | `string[]` | optional | Applicable locales (BCP-47 tags); omitted applies to every locale. The boot seed filters on the app's i18n.defaultLocale; the marketplace install, sample-data reseed, restart heal and per-organization replay filter on the locale resolved for the load (the localization.locale setting when set, then the locale of the installing, reseeding or founding user, then the app's i18n.defaultLocale where the load names one); package apply and draft publish do not filter by locale — they load every dataset and warn. A locale no dataset of the object names gets none of its locale-scoped rows, unless one is marked `fallback: true` |
| **fallback** | `true` | optional | Marks this locale-scoped dataset as its object's fallback: it also loads for a resolved locale that no other locale-scoped dataset of the same object lists. Requires `locale`: a dataset with no locale already loads everywhere, and the pair is refused. At most one dataset per object in a load may be marked; with two different marked datasets of one object, none is used as the fallback and the load reports the object, while each still loads for the locales it lists, as an unmarked dataset would (identical copies count once). A load with no locale loads it like every other dataset. Omitted, the dataset loads only for the locales it lists. |
| **dependsOn** | `string[]` | optional | Objects (by name) this dataset loads after, for an order no lookup field gives — e.g. a beforeInsert hook that reads another seeded object. Each name adds an edge to the load's dependency graph. The load is refused, writing nothing, when a name is the dataset's own object, is not seeded by another dataset of the same load, or closes a cycle with the other edges. Omitted, the order comes from lookup fields alone. |
| **records** | `Record<string, any>[]` | ✅ | Data records |
| **files** | `Record<string, { contentType: string; size: integer; sha256: string; data: string }>` | optional | Bytes of the package files the records name with `seedFile(path)`, keyed by path. Written by `os build`, which reads each path relative to the package root; the loader stores each one as a file the written record owns. |
Expand Down
Loading
Loading