Skip to content

Commit f796089

Browse files
os-steveclaudeobjectstack-fleet[bot]
authored
fix(spec,metadata-protocol)!: retire the seed modes insert and replace, which inserted every record again on each replay (#34791)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBFyg5B2muWbKZjA9phXVWse)_ Fixes #34613 Clause-②: no (narrowing) Metadata-protocol: narrowed Skills-docs: follow-up #34798 ## 维护者速读 - 改了什么:seed 的 `mode` 去掉 `insert` 和 `replace`,只剩 `update` / `upsert` / `ignore`(默认 `ignore` 不变)。写这两个值的数据集在 `defineSeed` / `defineStack` / `os validate` / 保存与发布门被拒,报错直接写出改法;已经存下来的旧数据集在启动、组织重放、热重载、安装时单独拒收,其余数据集照常加载。场景跑分器的种子改用默认 `ignore`;它把被某一轮删掉的种子行放回去时改走该数据包的 sample-data reseed(安装门会按落地记录扣下被删的种子行),放不回的行点名报出,不再记成已放回。 - 为什么改:按裁定 6942780880(选 B)。seed 每次启动、安装、发布都会重放,这两种模式不匹配已有行,所以每次重放都再插一遍:实测三次启动 1→2→3 行,人员引用只在最新那行补上。 - 风险与回滚:收窄,不是 Tier H:check-governed-merges 判定不在受治理面(0/86 路径,+1473 / −532 共 2005 行);裁决 6942780880 第 4 步是 seat-2 的执行文字,不是维护者原话,维护者对本卡的原话是「接受未知,评审完就合」(6949639011)。源头侧存量为零(本仓、hotcrm、cloud main 9cce314 都没有;托管 AI 构建器只写 `upsert`,读数见 #34479 评论 6943182271);托管环境里已存的包体读不到,是未知面,见 Acceptance notes。回滚即还原本 PR。 - 先看:`packages/spec/src/data/seed.zod.ts` 的 `SeedMode`(`enumWithRetiredValues` 带处方);`packages/metadata-protocol/src/seed-loader.ts` 新增的 `loadStored` 和 `loadDataset` 开头的模式拒收;`packages/metadata/src/artifact-retired-seed-modes.ts`(已编译制品里的旧数据集先摘出再严格解析、解析后放回,整机照常启动)。 - 两分钟验证:`pnpm --filter @objectstack/metadata-protocol exec vitest run src/seed-loader-retired-mode-34613.test.ts`,预期 8 例全绿;制品启动:`pnpm --filter @objectstack/runtime exec vitest run src/standalone-stack-artifact-retired-seed-mode-34613.test.ts`,预期 3 例全绿。 - 需要你做的:无。维护者已接受托管存量未知(6949639011「接受未知,评审完就合」);区域在 L1、席位契约评审和终 head 的 dogfood 电池通过后落地。 ## What changes Per the maintainer's ruling on this card (comment 6942780880, option **B**): retire the seed modes `insert` and `replace`. - **`SeedMode` (`@objectstack/spec/data`)** narrows from `insert | update | upsert | replace | ignore` to `update | upsert | ignore`, default `ignore` unchanged. The two values are kept as retired enum values (`enumWithRetiredValues`, ADR-0049), so `mode: 'insert'` / `mode: 'replace'` fail parse with a prescription that names the fix: keep the default `mode: 'ignore'` (or `'upsert'`) and set `externalId` to the field that names a row, to a list of fields when no single field does, or to `'id'` when the records carry their own ids. `defineSeed`, `defineStack`, `os validate` / `os build` and the metadata save and publish doors all refuse through that one parse. - **Stored datasets are refused alone, loudly.** A package built before this change, or a seed already stored, can still carry a retired mode. `SeedLoaderService.loadStored` (`@objectstack/metadata-protocol`) is the funnel the replaying loads now go through: the single-tenant boot seed, the per-organization replay, the dev hot reload (`packages/runtime/src/app-plugin.ts`) and the marketplace local install (`packages/cloud-connection/src/marketplace-install-local-plugin.ts`). A retired-mode dataset writes nothing; the load result carries one error for it with the schema's prescription and `success: false`; every other dataset loads. A dataset that is malformed for any other reason still fails the whole parse, as before. The publish doors keep their whole-request refusal (422), unchanged. - **Compiled artifacts still boot.** The artifact door (`MetadataPlugin._parseAndRegisterArtifact`, `@objectstack/metadata`) strict-parses the whole definition, so a stale `objectstack.json` carrying one retired-mode dataset would otherwise abort the boot. The door now takes such a dataset out of every seed collection the artifact can hold (top-level `data`, `manifest.data`, each assembled package body's `data` and `manifest.data`) before the parse, hands it back to the same collection afterwards, and logs one warning naming it and the fix; the seed load then refuses it alone. Seeds are never registered as metadata items, so nothing else reads the handed-back dataset. A never-valid mode is still the door's parse refusal. (L2 review M1.) - **The loader refuses the mode itself.** `loadDataset` refuses a mode outside the live `SeedMode` set before any write, so `load()` and `validate()` handed an unparsed request answer what a real load does: nothing written, every record errored, the prescription as the error, logged at `error`. The `insert` / `replace` arms are removed from `writeRecord` and `decideWriteAction`. A request with no mode at all keeps its old path. (L2 review S1.) - **`RETIRED_SEED_MODE_VALUES`** (`@objectstack/spec/data`, new export): the retired values, membership only, read by the artifact door and the loader so neither restates the list. - **Hints repointed.** The save door's and the loader's hint for a key no record carries used to say "or use mode 'insert' for rows with no natural key", steering into the one mode that duplicates. It now names a list of fields or `'id'`. - **Scenario runner restore (contract review 6969536704, M3).** The runner's seed datasets carry no `mode` (default `ignore`). The install door keeps the organization's record of landed seed rows (`sys_seed_landed_key`, no package in the key) and installs under `honour`, which withholds a recorded row that is gone (`skipped`, no error), so a restore sent as a second data-only package put nothing back, booked the row as reinserted, and after three rounds left the later operations of template mode's iterate-run half `notMeasured`. `loadSeedRows` (`packages/qa/scenarios/src/runner/orchestrate.ts`) now reads the door's `skipped`: the restore goes on through that package's sample-data reseed (`POST /api/v1/marketplace/install-local/:manifestId/reseed-sample-data`, the deliberate re-seed; `AppHarness.reseedManaged`, optional), and whenever the door skipped a row the objects are read back and each row still not there is refused by name with the reason, never counted as written or reinserted. A dataset refused whole (`field: 'mode'`) refuses each of its rows (N23). The install door's behaviour is unchanged (`honour` stays). The test double's door keeps the landed-row record and answers a retired mode with one dataset entry, as the real door does (N22). - **Lint.** The advisory rule `seed-insert-mode-duplicates-on-replay` (`validateSeedReplaySafety`) is removed; the schema refusal does its job for both modes. Author-time rule count 71 → 70 at the merged head (main is at 71 after #34822 and a later rule; this PR retires one; the four docs transcripts follow). - **`os diff`** on a dataset declaring either mode says the mode is retired, that a replay refuses the dataset, and what to declare. - **Conversion route (same PR, per the seat's 08:47Z order).** `content/docs/data-modeling/seed-data.mdx` › *Moving off `insert` and `replace`* gives the three conversions (a field, a composite list, `'id'`), a before/after, the rebuild/reinstall step. Step 2 says a reference the first load leaves empty still belongs in a composite key: since main's #34854 each later load finds that row by the key as authored, and the load that can resolve the reference fills it in. ADR-0087 D3 entry `seed-mode-insert-replace-retired` (no D2 conversion: which field names a row is the author's to declare). - Changeset `.changeset/34613-seed-mode-insert-replace-retired.md`; reference docs regenerated. ## Verification - `packages/metadata-protocol/src/seed-loader-retired-mode-34613.test.ts` (new, 8): through `loadStored`, insert / replace each refused alone while two other datasets land; an all-refused load answers failed with nothing written; `load()` handed an unparsed retired dataset refuses it (nothing written, every record errored, one `error` log) while the other dataset lands; `validate()` answers the same refusal; controls: no retired dataset → `load()`'s answer unchanged; a never-valid mode (`merge`) still fails the whole parse. - `packages/runtime/src/standalone-stack-artifact-retired-seed-mode-34613.test.ts` (new, 3): a real `createStandaloneStack` boot over a compiled artifact carrying an `insert` (and a `replace`) dataset completes, the dataset's object registers, the keyed dataset lands, the stale one writes nothing; control: a `merge` mode still fails the door's parse. - `packages/metadata/src/artifact-retired-seed-modes.test.ts` (new, 3): every seed collection path, the input not mutated, the hand-back to the same collection, and the control that a never-valid mode is left to the parse. - `packages/spec/src/data/seed.test.ts`: the two values refused with the prescription at path `['mode']`; the live modes parse. - `protocol.seed-external-id-refusal` tests: insert / replace now refused at the save door with the prescription, nothing stored. - `packages/cloud-connection/src/marketplace-install-local-landed-keys.test.ts` (new top-level describe, 2): through the real door and `SeedLoaderService`, a data-only package keyed on `id` seeds `ct1`, `ct2`; `ct2` is deleted; a second package carrying `ct2` answers `inserted: 0, skipped: 1, errors: 0, errorList: []` and the row stays gone; that package's reseed answers `inserted: 1` and the row is back; control: an unrecorded row lands from a second package. This confirms M3 at the door. - `packages/qa/scenarios/test/runner/orchestrate.test.ts`: the double's control (an install withholds a recorded row that is gone, the reseed brings it back, a held row is skipped, an unrecorded row lands, an unknown package's reseed is 404); a restore puts back a withheld row through exactly one reseed of the restore package; a harness with no reseed door refuses the row by name (`sys_seed_landed_key`, `no reseed door`) and books nothing as reinserted. Before the runner fix, with the honest double, 7 of 150 tests were red, among them the crm card's `runCard` (template iterate-run operations `notMeasured: 3`) and every restore pin (`demotravel_expense_claim: 1 missing (c001)`, `democrm_account: 1 missing (ac1)`); after it 153 of 153 pass. Ablation at `1f74fbc7` through `scripts/ablation-replace.mjs` (`{ reseedWithheld: true }` removed from the restore's call, anchor 1 → 0, blob `902855e2` → `446674cf`): 8 red, restored to the HEAD blob with `git diff HEAD` empty. - Real boot, three boots over one SQLite file with `OrganizationsPlugin` (scratch probe through `@objectstack/verify` `bootStack`, not committed), a task dataset plus a keyed tag dataset, a person signing up before boot 3: | task dataset | boot 1 | boot 2 | boot 3 | |---|---|---|---| | `mode: 'insert'` | refused, 0 rows (tag: 1) | refused, 0 (tag: 1) | refused, 0 (tag: 1) | | `mode: 'replace'` | refused, 0 (tag: 1) | refused, 0 (tag: 1) | refused, 0 (tag: 1) | | converted: `externalId: 'name'` | 1 row | same id | same id, now names the person | | `externalId: ['name', 'assignee']` (person not yet signed up) | 1 | 2 | 3 | Each refusal logs `✗ Seed dataset for 'seedowner_task' was not loaded: <prescription>`. The last row was measured at `ef48f915`, before main's #34854 (card #34800) fixed it: such a row is now found again by its authored key on every later load and filled once the person resolves. The docs caveat and the "list only fields every load can fill" advice built on that row were removed at `f596517c` (seat S2, finding 6957342048). - `defineStack` with `mode: 'insert'` → `✗ data.0.mode: seed.mode: 'insert' was removed …`. - Suites green: spec, metadata (2635), metadata-protocol (23064), lint (9112), objectql (`engine-seed-required-deferral`), runtime, cloud-connection (1308), plugin-security (`predicate-related-read-tenant-scope`), dogfood (`grant-table-write-contract`; the full battery on `f596517c` failed exactly 1 of 4140 tests, the #28952 control in `seed-external-id-refusal.dogfood.test.ts` that saved an `insert` seed and expected 200, a forced edit fixed at `4932db39` to expect the 422 mode refusal that never reaches the key judgment, amendment 6959256004; the full battery on `4932db39` then passed, 479 files and 4072 tests, 3 and 68 skipped, VERDICT 0, recorded on #34613; `ebf3a6ae` merges origin/main `fb5c42d1` cleanly over it, with the regen chain clean and the net diff unchanged; after the second merge-queue removal, `da7dd9ec` hand-merges origin/main `1282a464` and resolves the four `os validate` transcripts to 70 author-time rules (measured), `b398503c` regenerates protocol.mdx, api-surface and export-origins over the merge (restoring main's generated rows from #34719, #34976 and #34799 that the hand merge had dropped; this PR's own rows were never lost), `b5e8fd0f` corrects the changeset count line to 71 to 70; the full battery on `b5e8fd0f` passed, 479 files and 4072 tests, 3 and 68 skipped, VERDICT 0, comment 6967579608; `863908f4` drops the scenario runner's retired `mode: 'insert'` (seat delta-4 M2, amendment 6967843392), and the full battery on `863908f4` passed, 479 files and 4072 tests, 3 and 68 skipped, VERDICT 0, os-dev-report 6969229130; `3f014443` merges origin/main `526282e1` through os-regen-merge.sh with no conflicts, and `d56fedc2` regenerates protocol.mdx to restore main's view.timesheet rows that the driver dropped; the net diff is unchanged (84 files, identical changed lines), and the full battery on `d56fedc2` passed: 479 files and 4072 tests, 3 and 68 skipped, VERDICT 0, os-dev-report 6969269115; `2215056c`, `1f74fbc7`, `0dd0e0af` and `fdaf6213` answer contract review 6969536704 M3 (the restore's reseed route and its pins) and move the release wording to 18.7.0, and the full battery on `fdaf6213` passed, 479 files and 4072 tests, 3 and 68 skipped, VERDICT 0; `5af3e083` merges origin/main `958ee035` (the 18.6.0 version cut) through os-regen-merge.sh with no conflicts and nothing to regenerate (`check:generated`: all 14 artifacts up to date), the net diff is 86 files, +1473 / -532, and `git diff origin/main...HEAD | grep -n '18\.6\.0'` is empty; the full battery on `5af3e083` passed: 479 files and 4072 tests, 3 and 68 skipped, VERDICT 0), cli (the 220 test files that name seeds, authoring rules or `os diff`: 3058 passed, 9 skipped). - Gates: `check:generated` (references regenerated; `check:test-typecheck` OK), `gen:migration-registry` current, `check-docs-transcript-drift` (70 at the merged head), `check:adr-0087-registration`, `check:changeset-fixed`, `check-changeset-no-major`, `check-empty-changeset`, `tsc --noEmit` for metadata-protocol / runtime / cloud-connection / lint / cli, eslint on touched files (0 errors), `check:test-source-alias`, `check:where-matcher`, `check:engine-double-contract`, `check:skill-identifier-liveness` (the `seed-modes` binding reads `SEED_MODE_VALUES`, the array `SeedMode` wraps, since the gate cannot read an `enumWithRetiredValues` call). ## Acceptance notes - **FROM, measured on `origin/main` e533651** (premise reading): `insert` keyed by name 1 → 2 → 3 rows over three boots, only the newest row naming the person; keyless `insert` and `replace` the same; with a `unique` field the replay insert was refused and the one row stayed empty; `ignore` control one row, same id. TO: both values refused; a converted dataset holds one row. - **Stock reading and its source.** Source-side stock is zero from `863908f4` on, which drops the scenario runner's `mode: 'insert'` (`loadSeedRows`, brought in by main's #34985; seat delta-4 M2, amendment 6967843392): no non-test `mode: 'insert'` / `'replace'` in this repo, hotcrm, or cloud `main` 9cce314, and the hosted AI builder writes only `upsert` (cloud seat reading, #34479 comment 6943182271). **Unknown surface:** stored seed metadata and installed package bodies in hosted environments could not be read (no production credentials). A stored dataset there carrying either mode is refused alone at its next replay with the fix in the message, and the rest of its package loads; a compiled artifact carrying one still boots (pinned above). The maintainer accepted the unknown (6949639011, 「接受未知,评审完就合」), so landing does not wait on a count. - Rows earlier replays duplicated are data and are left as they are. - L2 nits not changed here: N1 (the boot banner's Seeds row counts no rejection when a refused dataset loads beside others; the refusal is still logged), N2 (the prescriptions and the docs name 18.7.0: the 18.6.0 cut, Version PR #33849, merged at 2026-11-18T05:13Z without this PR; this PR's `@objectstack/spec` changeset is `minor` over 18.6.0, `@objectstack/spec` is in the changeset `fixed` group, and no pending changeset on `main` or here bumps a package of that group `major`, so the first release carrying the refusal is 18.7.0), N4 (an admitted dataset whose `dependsOn` names the refused dataset's object is refused by the dependency check with its own message), N5 (`loadStored` is not on `ISeedLoaderService`; adding it is a contract change of its own), N6 (the refusal rides the existing error shape with `recordIndex: 0`). - **Follow-ups filed.** #34798 (blocked by this card): `skills/objectstack-data/references/seeds.md` and `skills/objectstack-platform/SKILL.md` still teach the retired modes. #34800 (a composite `externalId` over a reference the first load leaves empty) was fixed on main by #34854 while this PR was open; this branch carries that fix through the main merge. #34963: the local artifact checksum is computed before withheld datasets are restored (seat N10). #34975 (p2, area takes it right after this merge): the platform-checklist items `platform-core.seed-mode-matrix` and `access-security.agent-ceiling-set-assignment-refusal` still exercise the retired modes (the daily checklist watchdog is expected to go red on `main` until it lands), FOLLOW-UPS K6, and three stale comments (seat N14, N16, N18). --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufzfr1xZSFZzCR8HnqXX)_ <!-- signed: repo:objectstack#1 · os-warren · session_01JQwxbaX2qDxUq9sF93EqqL --> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
1 parent 6cc1b3e commit f796089

86 files changed

Lines changed: 1473 additions & 532 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@objectstack/scenarios': patch
3+
---
4+
5+
fix(scenarios): the runner's card seed and restore load under the default seed mode, not the retired `insert`
6+
7+
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.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
'@objectstack/spec': minor
3+
'@objectstack/metadata-protocol': minor
4+
'@objectstack/runtime': patch
5+
'@objectstack/cloud-connection': patch
6+
'@objectstack/lint': minor
7+
'@objectstack/cli': patch
8+
'@objectstack/metadata': patch
9+
---
10+
11+
fix(spec,metadata-protocol)!: retire the seed modes `insert` and `replace`, which inserted every record again on each replay
12+
13+
Clause-②: no (narrowing)
14+
Metadata-protocol: narrowed
15+
Skills-docs: follow-up #34798
16+
17+
<!-- adr-0087: registered seed-mode-insert-replace-retired -->
18+
19+
**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.
20+
21+
What moves (each line FROM → TO):
22+
23+
- `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.
24+
- 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.
25+
- 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.
26+
- `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.
27+
- 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).
28+
- 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.
29+
30+
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.
31+
32+
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.
33+
34+
Unchanged: `ignore`, `upsert` and `update` datasets load byte-identically.

‎content/docs/data-modeling/seed-data.mdx‎

Lines changed: 57 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,11 @@ customer has since edited.
7373
|:-----|:---------|:---------|
7474
| `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 |
7575
| `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 |
76-
| `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) |
7776
| `update` | Update only, skip if not found | Migration patches on existing rows |
78-
| `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 |
77+
78+
Every mode matches on `externalId`, so a replay finds the row an earlier load wrote.
79+
The unkeyed modes `insert` and `replace` are retired: see
80+
[Moving off `insert` and `replace`](#moving-off-insert-and-replace).
7981

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

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

129-
### `replace` — Insert Into an Already-Cleared Table
131+
### Moving off `insert` and `replace`
132+
133+
`insert` and `replace` matched no existing row, so every replay inserted each
134+
record again: a 3-row fixture became 6, then 9
135+
([#3434](https://github.com/objectstack-ai/objectstack/issues/3434)), and a person
136+
reference the first load had to leave empty stayed empty on the first row while
137+
only a later copy named the person. `replace` expected the caller to clear the
138+
table first, and no load ever clears one. Both were removed in
139+
`@objectstack/spec` 18.7.0 ([#34613](https://github.com/objectstack-ai/objectstack/issues/34613)):
140+
141+
- **Authoring refuses them.** `defineSeed`, `defineStack`, `os validate`, `os build`
142+
and the metadata save and publish doors reject `mode: 'insert'` or
143+
`mode: 'replace'` with a message that names the fix.
144+
- **A stored dataset is refused alone.** A package or a compiled artifact
145+
(`objectstack.json`) built before the change, or a seed already stored, can
146+
still carry one. The environment still boots: the boot seed, the organization
147+
replay, the dev hot reload and a package install or upgrade refuse that one
148+
dataset. It writes nothing, the load reports it as an error with the same
149+
message, and every other dataset and definition loads.
150+
- **Rows already duplicated stay.** Earlier replays wrote them as data; nothing
151+
deletes them. Remove the extra copies yourself if they matter.
152+
153+
To convert a dataset, declare which field identifies a row, then drop the mode
154+
(or declare `upsert` for reference data the package keeps current):
155+
156+
1. **A field names the row** (a code, a slug, an email): set `externalId` to it.
157+
2. **No single field does** (a join table, a line item under a parent): set
158+
`externalId` to the list of fields that together identify a row, for example
159+
`['team', 'project']`. Reference fields are matched by their resolved ids. A
160+
reference the first load has to leave empty (a person who has not signed up
161+
yet) still belongs in the key: each later load finds that row again by the
162+
key as authored, and the load that can resolve the person fills it in. See
163+
[Composite natural key](#composite-externalid--join--junction-tables).
164+
3. **The records carry their own ids**: set `externalId: 'id'`.
130165

131166
```typescript
132-
// ⚠️ The seed loader does NOT delete existing records for you — `replace`
133-
// always inserts. Truncate/clear the table yourself before this seed runs,
134-
// or every load will attempt to insert duplicate rows.
135-
// Only use for cache or lookup tables with no user-generated data.
136-
defineSeed(ExchangeRateCache, {
137-
externalId: 'key',
167+
// Before — refused since @objectstack/spec 18.7.0
168+
defineSeed(ExchangeRate, {
138169
mode: 'replace',
139-
env: ['dev'],
140-
records: [
141-
{ key: 'USD_EUR', rate: 0.92 },
142-
{ key: 'USD_GBP', rate: 0.79 },
143-
],
170+
records: [{ key: 'USD_EUR', rate: 0.92 }],
144171
});
145-
```
146172

147-
### `insert` — Not Idempotent (Avoid for Replayed Seeds)
173+
// After — one row per key, written once
174+
defineSeed(ExchangeRate, {
175+
externalId: 'key',
176+
records: [{ key: 'USD_EUR', rate: 0.92 }],
177+
});
178+
```
148179

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

156183
### A Deleted Seed Row Stays Deleted
157184

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

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

603631
---
604632

@@ -865,8 +893,8 @@ see [A Fallback Set](#a-fallback-set--fallback-true).
865893

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

871899
### Declare a dependency no field expresses
872900

@@ -896,7 +924,7 @@ function defineSeed<
896924
objectDef: TObj,
897925
config: {
898926
externalId?: string | string[]; // single field, or a composite list (join tables); default: 'name'
899-
mode?: 'insert' | 'update' | 'upsert' | 'replace' | 'ignore'; // default: 'ignore'
927+
mode?: 'update' | 'upsert' | 'ignore'; // default: 'ignore'
900928
columns?: { [field: string]: { applyOn?: 'create' | 'always' } }; // per-column write policy; default: 'always'
901929
env?: Array<'prod' | 'dev' | 'test'>; // default: ['prod','dev','test']
902930
locale?: string[]; // BCP-47 tags; omitted = every locale

‎content/docs/deployment/cli.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ os compile --json # JSON output for CI pipelines
887887
→ Normalizing stack definition...
888888
→ Lowering inline handlers...
889889
→ Validating protocol compliance...
890-
→ Running author-time rules (71)...
890+
→ Running author-time rules (70)...
891891
→ Checking that every required capability has a provider installable in this edition...
892892
→ Collecting package docs (ADR-0046)... 0 collected
893893
→ Writing artifact...

‎content/docs/deployment/validating-metadata.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ A clean run walks the registry and reports timing:
866866
Config: /path/to/support-desk/objectstack.config.ts
867867
Load time: 21ms
868868
→ Validating against ObjectStack Protocol...
869-
→ Running author-time rules (71)...
869+
→ Running author-time rules (70)...
870870
→ Checking that every required capability has a provider installable in this edition...
871871
→ Checking package docs (ADR-0046)...
872872

‎content/docs/getting-started/build-with-claude-code.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ visible: 'status != "resolved"'
311311
◆ Validate
312312
────────────────────────────────────────
313313
→ Validating against ObjectStack Protocol...
314-
→ Running author-time rules (71)...
314+
→ Running author-time rules (70)...
315315
316316
✗ Author-time rules failed (1 issue)
317317
• stack · action 'resolve_ticket' visible: bare reference `status` — a

0 commit comments

Comments
 (0)