Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
30d2dbe
wip(spec): retire SeedMode insert and replace (#34613)
claude Nov 17, 2026
5267073
wip: loader refuses a stored retired-mode dataset alone; lint rule re…
claude Nov 17, 2026
d7bf0cd
wip: docs conversion steps, changeset, remaining loader mocks (#34613)
claude Nov 17, 2026
28c1361
wip: regenerate references, transcript count 68, composite-key caveat…
claude Nov 17, 2026
c67cb4c
Merge commit '6dd57163295fa6e72dca5c469dbbb23e44d20bfc' into claude/p…
claude Nov 17, 2026
336672e
test: pay seed-test module loads at collection; the retired-mode test…
claude Nov 17, 2026
07b6f2f
fix(metadata,metadata-protocol): a compiled artifact with a retired s…
claude Nov 17, 2026
032f8e2
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude Nov 17, 2026
ef48f91
docs(references): regenerate from the merged tree (#34613)
claude Nov 17, 2026
080cbe7
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude Nov 17, 2026
c675317
docs(references): regenerate protocol reference after main merge
claude Nov 17, 2026
09901d0
docs(changeset): name follow-up #34798 and RETIRED_SEED_MODE_VALUES
claude Nov 17, 2026
f596517
docs(spec): drop the stale "fields every load can fill" advice for se…
claude Nov 17, 2026
4932db3
test(dogfood): the insert-seed control now expects the mode retiremen…
claude Nov 17, 2026
ebf3a6a
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude Nov 17, 2026
790dd2b
Merge branch 'main' into claude/project-thread-ylqtt2
objectstack-fleet[bot] Nov 17, 2026
da7dd9e
Merge origin/main into claude/project-thread-ylqtt2
claude Nov 18, 2026
b398503
chore(spec): regenerate protocol reference, api-surface and export-or…
claude Nov 18, 2026
b5e8fd0
chore(changeset): the rule-count line drops by one, 71 to 70 at this …
claude Nov 18, 2026
863908f
fix(scenarios): runner seed and restore name no retired seed mode
claude Nov 18, 2026
3f01444
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude Nov 18, 2026
d56fedc
chore(docs): regenerate protocol.mdx over the main merge
claude Nov 18, 2026
2215056
test(cloud-connection): pin the landed-key record across data-only pa…
claude Nov 18, 2026
1f74fbc
fix(scenarios): a restore puts back a withheld seeded row through the…
claude Nov 18, 2026
0dd0e0a
docs(spec): name 18.7.0 as the release that retires seed.mode insert/…
claude Nov 18, 2026
fdaf621
test: pin 18.7.0 in the retired seed-mode prescriptions; type the no-…
claude Nov 18, 2026
5af3e08
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude 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
7 changes: 7 additions & 0 deletions .changeset/34613-scenario-seed-no-retired-mode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@objectstack/scenarios': patch
---

fix(scenarios): the runner's card seed and restore load under the default seed mode, not the retired `insert`

The scenario runner wrote every card seed (and every restore of a removed seeded row) as a data-only package whose datasets declared `mode: 'insert'`. That mode is retired (#34613), and the managed install door refuses a dataset declaring it, every row of it, so no card seed loaded. The datasets now name no `mode`: the default, `ignore`, creates each row whose `id` the object does not hold and leaves one it holds as it is, which is what a fresh seed needs. A restore needs more: the install door keeps the organization's record of landed seed rows (`sys_seed_landed_key`) and withholds a recorded row that is gone, as a person's removal, so an install does not put back a seeded row a turn deleted. The restore therefore goes on through that package's sample-data reseed (`POST /api/v1/marketplace/install-local/:manifestId/reseed-sample-data`), the platform's deliberate re-seed, which inserts every missing row; and whenever the door skipped a row, the runner reads the objects back and refuses each row still not there by name, with the reason, instead of counting it as written or reinserted. The test double's seed door now judges `mode` with `SeedMode` and keeps the landed-row record, as the real door does, and pins hold that the seed and restore packages carry no retired mode and that a restore brings back a recorded row.
34 changes: 34 additions & 0 deletions .changeset/34613-seed-mode-insert-replace-retired.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
'@objectstack/spec': minor
'@objectstack/metadata-protocol': minor
'@objectstack/runtime': patch
'@objectstack/cloud-connection': patch
'@objectstack/lint': minor
'@objectstack/cli': patch
'@objectstack/metadata': patch
---

fix(spec,metadata-protocol)!: retire the seed modes `insert` and `replace`, which inserted every record again on each replay

Clause-②: no (narrowing)
Metadata-protocol: narrowed
Skills-docs: follow-up #34798

<!-- adr-0087: registered seed-mode-insert-replace-retired -->

**BREAKING** for a seed dataset authored with `mode: 'insert'` or `mode: 'replace'`. A seed is replayed on every single-tenant boot, every package install or upgrade and every publish, and neither mode matched an existing row, so every replay inserted each record again: an un-walled install went from 1 to 2 to 3 rows over three boots, a person reference the first load had to leave empty stayed empty on the first row while only the newest copy named the person, and with a unique field the replay insert was refused and the one row stayed empty. `replace` expected the caller to clear the table first, and no load path ever clears one.

What moves (each line FROM → TO):

- `SeedSchema.mode` / `SeedMode` (`@objectstack/spec/data`; `defineSeed`, `defineStack({ data })`, a `seed` metadata item, a package body's seed): FROM `insert` / `update` / `upsert` / `replace` / `ignore` TO `update` / `upsert` / `ignore` (default `ignore`, unchanged). `mode: 'insert'` or `mode: 'replace'` fails parse with a prescription naming the fix; the save and publish doors refuse it with the same message. The retired pair is exported as `RETIRED_SEED_MODE_VALUES` (`@objectstack/spec/data`): it is derived from the parse refusal's own table, and the loader and the artifact door read it.
- a stored dataset that still declares one, replayed by the boot seed, the per-organization replay, the dev hot reload or a package install, upgrade or sample-data reseed (`SeedLoaderService.loadStored`, `@objectstack/metadata-protocol`): FROM inserted again on every load TO refused alone — it writes nothing, the load result carries one error with the prescription and `success: false`, and every other dataset loads. `SeedLoaderService.load()` and `validate()` refuse the dataset the same way when handed one unparsed, so a dry run reports what a real load does.
- a compiled artifact (`objectstack.json`) carrying such a dataset, booted by `os serve` / `os start` / `os dev` (the artifact door, `MetadataPlugin`, `@objectstack/metadata`): the door parses the artifact without that dataset and hands it back to the seed load, which refuses it alone; the door logs a warning naming the dataset and the fix. Everything else in the artifact registers and boots.
- `os diff` (`@objectstack/cli`) on a dataset declaring either mode: FROM "a replay inserts these again" TO a note that the mode is retired, that a replay refuses the dataset, and what to declare.
- the advisory lint rule `seed-insert-mode-duplicates-on-replay` (`validateSeedReplaySafety`, `@objectstack/lint`): FROM a warning on `mode: 'insert'` TO removed; the schema refusal does its job for both modes. The author-time rule count `os validate` / `os build` print drops by one (71 to 70 at this release).
- the save door's and the loader's hint for a key no record carries: FROM "or use mode 'insert' for rows with no natural key" TO a list of fields when no single field names a row, or `'id'` when the records carry their own ids.

The fix: declare which field identifies a row and drop the mode (or declare `upsert` for reference data the package keeps current). Set `externalId` to the field that names a row, to a list of fields when no single field does (a junction table's `['team', 'project']`), or to `'id'` when the records carry their own ids. Rebuild the package, and reinstall it where it was installed with `os package install`, so the stored body carries the new declaration.

No conversion is made, at load, at save or by a migration (ADR-0087 D3, entry `seed-mode-insert-replace-retired`): a keyed mode needs the field that identifies a row, and only the author knows it. Rows earlier replays duplicated are data and are left as they are.

Unchanged: `ignore`, `upsert` and `update` datasets load byte-identically.
86 changes: 57 additions & 29 deletions content/docs/data-modeling/seed-data.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ customer has since edited.
|:-----|:---------|:---------|
| `ignore` | **Default.** Create-only: insert a record whose row is missing (a boot or organization replay skips one a person [deleted](#a-deleted-seed-row-stays-deleted)), leave an existing row exactly as it is | Business and starter data the customer owns once it is loaded |
| `upsert` | Create if new (a boot or organization replay skips one a person [deleted](#a-deleted-seed-row-stays-deleted)), and on **every** replay write each declared column back onto the matched row | Reference data the package must keep current |
| `insert` | Insert **every** record unconditionally — no existing-row check, so it **duplicates the table on each replay boot** ([#3434](https://github.com/objectstack-ai/objectstack/issues/3434)). Rarely what you want | Append-only rows loaded exactly once (never re-run) |
| `update` | Update only, skip if not found | Migration patches on existing rows |
| `replace` | Insert without checking for an existing match — the seed loader does **not** delete anything itself; the target table must already be empty (or cleared by the caller) | Cache / lookup tables rebuilt from an already-truncated table |

Every mode matches on `externalId`, so a replay finds the row an earlier load wrote.
The unkeyed modes `insert` and `replace` are retired: see
[Moving off `insert` and `replace`](#moving-off-insert-and-replace).

### `ignore` — The Default (Create-Only)

Expand Down Expand Up @@ -126,32 +128,57 @@ customer or a job owns, mark those columns create-only — see
`mode: 'upsert'` on the datasets that must stay current.
</Callout>

### `replace` — Insert Into an Already-Cleared Table
### Moving off `insert` and `replace`

`insert` and `replace` matched no existing row, so every replay inserted each
record again: a 3-row fixture became 6, then 9
([#3434](https://github.com/objectstack-ai/objectstack/issues/3434)), and a person
reference the first load had to leave empty stayed empty on the first row while
only a later copy named the person. `replace` expected the caller to clear the
table first, and no load ever clears one. Both were removed in
`@objectstack/spec` 18.7.0 ([#34613](https://github.com/objectstack-ai/objectstack/issues/34613)):

- **Authoring refuses them.** `defineSeed`, `defineStack`, `os validate`, `os build`
and the metadata save and publish doors reject `mode: 'insert'` or
`mode: 'replace'` with a message that names the fix.
- **A stored dataset is refused alone.** A package or a compiled artifact
(`objectstack.json`) built before the change, or a seed already stored, can
still carry one. The environment still boots: the boot seed, the organization
replay, the dev hot reload and a package install or upgrade refuse that one
dataset. It writes nothing, the load reports it as an error with the same
message, and every other dataset and definition loads.
- **Rows already duplicated stay.** Earlier replays wrote them as data; nothing
deletes them. Remove the extra copies yourself if they matter.

To convert a dataset, declare which field identifies a row, then drop the mode
(or declare `upsert` for reference data the package keeps current):

1. **A field names the row** (a code, a slug, an email): set `externalId` to it.
2. **No single field does** (a join table, a line item under a parent): set
`externalId` to the list of fields that together identify a row, for example
`['team', 'project']`. Reference fields are matched by their resolved ids. A
reference the first load has to leave empty (a person who has not signed up
yet) still belongs in the key: each later load finds that row again by the
key as authored, and the load that can resolve the person fills it in. See
[Composite natural key](#composite-externalid--join--junction-tables).
3. **The records carry their own ids**: set `externalId: 'id'`.

```typescript
// ⚠️ The seed loader does NOT delete existing records for you — `replace`
// always inserts. Truncate/clear the table yourself before this seed runs,
// or every load will attempt to insert duplicate rows.
// Only use for cache or lookup tables with no user-generated data.
defineSeed(ExchangeRateCache, {
externalId: 'key',
// Before — refused since @objectstack/spec 18.7.0
defineSeed(ExchangeRate, {
mode: 'replace',
env: ['dev'],
records: [
{ key: 'USD_EUR', rate: 0.92 },
{ key: 'USD_GBP', rate: 0.79 },
],
records: [{ key: 'USD_EUR', rate: 0.92 }],
});
```

### `insert` — Not Idempotent (Avoid for Replayed Seeds)
// After — one row per key, written once
defineSeed(ExchangeRate, {
externalId: 'key',
records: [{ key: 'USD_EUR', rate: 0.92 }],
});
```

Seeds are **replayed** — they re-load on every dev-server boot and every package
re-publish, not applied once. `insert` writes every record with **no existing-row
check**, so a replayed `insert` dataset duplicates its table on each restart
(a 3-row fixture becomes 6, then 9 — [#3434](https://github.com/objectstack-ai/objectstack/issues/3434)).
It is almost never the right mode: leave `mode` unset (create-only), or declare
`upsert` for reference data, with a stable `externalId` instead. `os validate` warns on any `mode: 'insert'` seed.
Rebuild the package (and reinstall it where it was installed with
`os package install`) so the stored body carries the new declaration.

### A Deleted Seed Row Stays Deleted

Expand Down Expand Up @@ -243,8 +270,8 @@ defineSeed(Instalment, {
out of the write: the row keeps the values the jobs gave it, while `amount`
(`applyOn: 'always'`, the default) is refreshed. A row whose only differences
are create-only columns is not written at all.
- An `update` dataset never writes a create-only column. `insert`, `ignore` and
`replace` never update a matched row, so the policy changes nothing there.
- An `update` dataset never writes a create-only column. `ignore` never updates
a matched row, so the policy changes nothing there.
- A create-only **reference** on a matched row is not resolved at all, so a
replay neither re-points it nor reports it.
- A column of the `externalId` is what the row was matched by, so it stays in
Expand Down Expand Up @@ -541,8 +568,9 @@ const membershipsSeed = defineSeed(ProjectMembership, {
});
```

Without a composite key such a table can only fall back to `mode: 'insert'`, which
duplicates on every replay boot ([#3434](https://github.com/objectstack-ai/objectstack/issues/3434)).
Without a composite key such a table has nothing to match a replay on. The
unkeyed `mode: 'insert'` it once fell back to duplicated on every replay boot
([#3434](https://github.com/objectstack-ai/objectstack/issues/3434)) and is retired.

---

Expand Down Expand Up @@ -807,8 +835,8 @@ behind already wrote — see [Locale Scoping](#locale-scoping).

The default, `ignore`, is idempotent and never overwrites an edit. Declare a mode only
when the use case requires it — `upsert` for reference data the package keeps current
(with `applyOn: 'create'` on the columns the customer or a job owns), or `replace`
for ephemeral cache tables.
(with `applyOn: 'create'` on the columns the customer or a job owns), or `update`
for a migration patch on rows that already exist.

### Declare a dependency no field expresses

Expand Down Expand Up @@ -838,7 +866,7 @@ function defineSeed<
objectDef: TObj,
config: {
externalId?: string | string[]; // single field, or a composite list (join tables); default: 'name'
mode?: 'insert' | 'update' | 'upsert' | 'replace' | 'ignore'; // default: 'ignore'
mode?: 'update' | 'upsert' | 'ignore'; // default: 'ignore'
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
Expand Down
2 changes: 1 addition & 1 deletion content/docs/deployment/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ os compile --json # JSON output for CI pipelines
→ Normalizing stack definition...
→ Lowering inline handlers...
→ Validating protocol compliance...
→ Running author-time rules (71)...
→ Running author-time rules (70)...
→ Checking that every required capability has a provider installable in this edition...
→ Collecting package docs (ADR-0046)... 0 collected
→ Writing artifact...
Expand Down
2 changes: 1 addition & 1 deletion content/docs/deployment/validating-metadata.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ A clean run walks the registry and reports timing:
Config: /path/to/support-desk/objectstack.config.ts
Load time: 21ms
→ Validating against ObjectStack Protocol...
→ Running author-time rules (71)...
→ Running author-time rules (70)...
→ Checking that every required capability has a provider installable in this edition...
→ Checking package docs (ADR-0046)...

Expand Down
2 changes: 1 addition & 1 deletion content/docs/getting-started/build-with-claude-code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ visible: 'status != "resolved"'
◆ Validate
────────────────────────────────────────
→ Validating against ObjectStack Protocol...
→ Running author-time rules (71)...
→ Running author-time rules (70)...

✗ Author-time rules failed (1 issue)
• stack · action 'resolve_ticket' visible: bare reference `status` — a
Expand Down
Loading
Loading