Repository navigation
fix(metadata-protocol): a seed key reference empty on the first load holds one row across loads - #34854
Conversation
… is found again by a derived id Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzgNCAXyGfBQFZBwixH
…s one row across loads Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzgNCAXyGfBQFZBwixH
…st boot holds one row over a sqlite file Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzgNCAXyGfBQFZBwixH
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzgNCAXyGfBQFZBwixH
…ed-composite-deferred-key
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzgNCAXyGfBQFZBwixH
📓 Docs Drift Check3 anchor(s) derived from 1 changed package(s); no hand-written page names any of them, so this run has nothing to list — not a clean bill of health. This check sees only pages that NAME a derived anchor: one that documents this change in prose, or enumerates it in an authoring dialect, names none and stays invisible to it on every run. What this run could not see
Coarse fallback — 10 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin aa4e5f5eb3bec86e950121078c090eda0c04eb35 && git checkout aa4e5f5eb3bec86e950121078c090eda0c04eb35
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 7752cac7b002c6beb7b32dcc4ad2db450884151a 58dc0dfd82d3ad31538410285214129b6aaef9c0 && git checkout -B drift-repro 7752cac7b002c6beb7b32dcc4ad2db450884151a && git merge --no-ff 58dc0dfd82d3ad31538410285214129b6aaef9c0
node scripts/docs-audit/affected-docs.mjs --json 7752cac7b002c6beb7b32dcc4ad2db450884151a |
|
repo:objectstack#3 · os-support-ai · session_01WGufzgQsdnyS4QdR8stjDa L1 review (L1-d) · 2026-11-17T14:25ZL1: ACCEPT Read at that head: the file list (5 paths), the full diff, the PR body, card #34800 with triage 6946065909, claim 6947910076 (its Route line), surface amendment 6950188764, os-dev report 6950154378, and the 53 check-runs. Checklist
Must-fixNone. Should-fixNone. Notes
Landing: not governed, all checks green. Area o3-G lands it. A later push owes a delta read. |
|
repo:objectstack#3 · os-support-ai · session_01WGufzgNCAXyGfBQFZBwixH Landing · 2026-11-17T14:26Z
Ready + auto-merge into the queue. Area o3-G (repo:objectstack#3) watches it to MERGED and closes out #34800. |
…ed keys Seat S2: since #34854 a composite-key row whose reference the first load leaves empty is found again by its authored key and filled later, so the advice to key only on fields every load can fill is false. Dropped from the migration entry replacement and SEED_MODE_RETIRED_FIX; seed-data.mdx step 2 now says what the loader does. N12: the changeset states the rule count 70 to 69. Text only. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzfr1xZSFZzCR8HnqXX
Requested by Yibo Wang · project thread
Fixes #34800
Clause-②: no
Metadata-protocol: none
repo:objectstack#3 · os-support-ai · session_01WGufzgNCAXyGfBQFZBwixH
维护者速读
externalId里含一个首次加载时只能留空的引用(如尚未注册的人员)时,这行以「按作者写下的键派生的 id」落库;之后每次加载按这个 id 找回同一行,引用一旦可解析就补写到这一行上。packages/metadata-protocol/src/seed-loader.ts里rowLandedWithEmptyKeyReference(按 id 认领的守卫条件)、派生 id 赋值块与ignore模式的 pass-2 补写块;seedDeferredKeyRowId。pnpm --filter @objectstack/metadata-protocol exec vitest run --maxWorkers=2 src/seed-loader-deferred-key-reference.test.ts,预期 9 个用例全绿(三次加载始终 1 行、人员出现后引用补到首行、两条仅引用不同的记录保持 2 行、客户手建的空引用行不被占用)。What changes
packages/metadata-protocol/src/seed-loader.ts:seedDeferredKeyRowId(object, row organization, authoredKey), whereauthoredKeyisseedLandedKeyover the record before its references resolve — the person's natural key, never the id it resolves to. Only forupsert/ignore, only when the record names noidof its own, and never an id a row of this organization or another record of the load already holds.rowLandedWithEmptyKeyReferencelooks the row up by that id (or by the record's ownid), from the same pre-load read, now also indexed by id (loadExistingRecords' optionalbyId). It takes the row only when its other key columns equal the record's and each reference column it holds is empty or the very value the record resolved, and only for one record of the load. An exact natural-key match always wins. The write decision, the create-only check, seed files and the seed loader: a declared seed row a person deleted comes back under a new id at the next seed replay — record landed keys per organization and skip the ones now absent #31021 withdrawal question all read the found row through one view (existingRowsFor).upsertupdates the row as it does any matched row;ignorewrites nothing over a row it found, so the one column is back-filled by pass 2 (the held person reference path writes the same way onto the row the seed landed on).Route (the claim's): the replay finds the row as first landed. Why an id and not the #31021 ledger: the ledger stores keys, never which row a key landed on, so it can say "this key landed here" but cannot find the row; and it exists only where a composition registers
sys_seed_landed_keyand the load has an organization. The id is carried by the row itself, so both paths are covered by one mechanism, and a row a person created (random id) can never be taken. Authoring-time refusal of such a key was not taken (it narrows the accept set; the claim excludes it).Tests
packages/metadata-protocol/src/seed-loader-deferred-key-reference.test.ts(9 cases, a fresh loader per load as a restart does):ignoreandupsert× {person never appears: 3 loads → 1 row; person appears between loads: 1 row, reference on the row first landed}; the landed-key record kept (landedKeys: 'honour'): 1 row, skipped not withdrawn; two records differing only in the reference stay two rows, each filled with its own person; a customer row with the reference empty is never taken. CONTROLs: a composite key whose reference resolves on the first load, and a composite key over plain fields, match as before with engine-minted ids.packages/runtime/src/seed-deferred-key-reference-real-driver.integration.test.ts(2 cases): realSeedLoaderService+ realObjectQL+ realSqlDriveron one better-sqlite3 file, three boots (new engine/driver/loader each): per-organization replay with the landed-key record, person never appears →[1, 1, 1]; no landed-key record,upsert, person appears before boot 2 →[1, 1, 1]and the reference lands.scripts/engine-double-contract.pinned.json: the three pinned doubles of the new test file, written bynode scripts/check-engine-double-contract.mjs --writeas the gate prescribes (add-only, "0 lost").Acceptance notes
SeedDatasetFiles.openstill receives the natural-key map only; a row found by id is passed toprepareRowthroughexistingRowsFor, which is the call that reads it.resolveHeldPersonReferences) is not edited: the deferral's internal id is the found row's id, so a held reference is written onto that row.Verification
Measured on
origin/mainc513d62 before code, with the same harness as the runtime test (scratch file, deleted): every composition duplicated.Reproduction on main (three boots over one sqlite file)
Same harness on this branch: every line
rows=1 -> 1 -> 1, reference filled where the person signed up.Ablation (unit file; it imports ./seed-loader.js from src, so no dist leg)
Fix committed first; mutation via
scripts/ablation-replace.mjs, restore bygit checkout HEAD --, proven by blob == HEAD andgit diff HEADempty.const row = existingRowsById.get(rowId);→const row = undefined as any;, blob 195e71f0 → 50685164): 7 failed / 2 passed — every duplicate and fill case red; the two CONTROLs green.constand threw TypeError in every case; that run was discarded as a non-mutation and redone.Local readings at head 58dc0df (CI runs the full farm)
pnpm --filter @objectstack/metadata-protocol typecheck+ fullvitest run(after merging origin/main dfbc316 and rebuilding the closure): VERDICT command-exit 0 · Test Files 349 passed / 9 skipped (358) · Tests 23100 passed / 45 skipped.pnpm --filter @objectstack/runtime typecheck(tsc + check:test-typecheck OK) and the new runtime file: Test Files 1 passed · Tests 2 passed.dispatch-gates.mjs --commands, 75 for this diff):--ranverdict "75 derived famil(ies) accounted for — 73 run, 2 NOT-MEASURED". NOT MEASURED:check:dual-build-cjs-loads(PREREQUISITE NOT MET: reads every package's dist; only the touched closures are built here) andcheck-plugin-teardown-shape.mjs --self-test(shallow clone cannot reach its pinned fixture commit; checker-health only).check:engine-double-contractwas red until the ledger rows above, exit 0 after.overlap-check.mjs: VERDICT clean — merges cleanly with origin/main and with fix(spec,metadata-protocol)!: retire the seed modes insert and replace, which inserted every record again on each replay #34791 (shares seed-loader.ts) and feat(i18n): a dependent package's fieldPatches text is translated from that package's own translations #34784 (shares the ledger).test:repoprojects and the rest of the farm: declared to CI.Generated by Claude Code
🤖 Generated with Claude Code
https://claude.ai/code/session_01WGufzgNCAXyGfBQFZBwixH