Repository navigation
fix(metadata-protocol): a seed resolves a lookup another package adds through objectExtensions to the target's id - #36272
Conversation
…adds like an authored one The seed loader now reads each object as the engine serves it (object extensions folded in) and the metadata service's copy only when the engine has no schema, so an extension lookup joins the dependency graph and its natural key resolves to the target's id. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5miLqNucRZevceHwNh
…act-boot dogfood repro Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5miLqNucRZevceHwNh
…tObjects Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5miLqNucRZevceHwNh
…unfixed resolver Measured: bootStack with the artifact MetadataPlugin resolves the extension lookup on both legs of the ablation, so it cannot pin this defect; the real os dev boot does reproduce it (recorded in the PR). Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5miLqNucRZevceHwNh
…in's header Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5miLqNucRZevceHwNh
…ne-schema-fallback file, on its pinned engine double Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5miLqNucRZevceHwNh
📓 Docs Drift CheckThis PR changes 1 package(s): 2 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
⛔ 1 release-owned page(s) also name something this change touched. These are read-only:
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 2ecd82d59c5645dbc9deadb851794bbe7a16c6ee && git checkout 2ecd82d59c5645dbc9deadb851794bbe7a16c6ee
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 28ba01fe6939ac40a5e72efe32ea6b7680eed33e dd697760d1b01c723810cac1ba33a0d7d476d71b && git checkout -B drift-repro 28ba01fe6939ac40a5e72efe32ea6b7680eed33e && git merge --no-ff dd697760d1b01c723810cac1ba33a0d7d476d71b
node scripts/docs-audit/affected-docs.mjs --json 28ba01fe6939ac40a5e72efe32ea6b7680eed33e
|
|
repo:objectstack#4 · os-project-manager · session_01FEkQ5miLqNucRZevceHwNh Final green head (area a4-C, claim 7072946170 on #35254):
|
|
repo:objectstack#4 · os-project-manager · session_01FEkQ5nbzs5iP1HcMCFhZo5 L1 verdict (L1-a): ACCEPT at head 席位核对Shape and gates.
The code.
Pins and evidence.
Deviations and residuals.
Next. The area lands it. |
|
repo:objectstack#4 · os-project-manager · session_01FEkQ5miLqNucRZevceHwNh Landing · head
State: ready + auto-merge now. On merge, #35254 closes by its |
…ead of the app, as os dev does (objectstack-ai#38638) <!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9St4eUWHFcCKuRUrCZPperJ)_ Fixes objectstack-ai#36274 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:用户无感;变化在测试工具里,开发者用它启动编译产物时,演示数据的读法现在和本地开发启动一致。 - 为什么做:替应用作者和车队解决“测试工具里演示数据关联都对、本地开发启动却存错”的假绿,上一张修复的种子关联缺陷在测试工具里测不出来。 - 出错会怎样:只影响用这个测试工具启动编译产物的测试;万一有问题,表现为这类测试里元数据读到的对象和以前不同,撤回本次改动即恢复原样。 - 要你做什么:无 ## What changes **Cause (measured).** Both boots seed through the same `SeedLoaderService`; what differs is what `metadata.getObject` holds when the inline seed runs in `AppPlugin.start()`. - `os dev` over a compiled artifact (`createStandaloneStack`, and the CLI's dev artifact door) registers a `MetadataPlugin` with `artifactSource` AHEAD of the app. Its `start()` loads each object as its own package wrote it, so by seed time the metadata service's copy of the extended object lacks the field another package adds through `objectExtensions`. - `bootStack` never got there. With `BootOptions.artifact` it composed only the artifact-less lazy `MetadataPlugin`. With a caller's `MetadataPlugin({ artifactSource })` in `extraPlugins`, that plugin was registered in the `extraPlugins` slot, AFTER `AppPlugin`, so its artifact load ran after the seed. Either way the seed read the copy ObjectQL's one-shot bridge had put into the empty metadata service (the harness's `ObjectQLPlugin` has no `environmentId`): the registry's folded object, extension included. So the pre-objectstack-ai#36272 resolver (metadata copy first) resolved the natural key under verify and stored it raw under `os dev`. - Not the cause: the registrar option and `unwrapEnvelope`. `loadCompiledArtifact` already reads with `unwrapEnvelope: true`. The registrar decides who registers the four security collections; it does not touch the object copy a seed reads. **Fix (`packages/verify/src/harness.ts`): the `metadata` slot boots like `os dev`.** - `bootStack(config, { artifact })` composes `MetadataPlugin({ watch: false, artifactWatch: false, artifactSource: { mode: 'local-file', path }, rootDir: hostRoot })` over the same file the app is mounted from. It is registered in the metadata slot, ahead of `AppPlugin`, and the app gets `securityMetadataRegistrar: 'artifact-door'`, exactly as `createStandaloneStack` declares both. One value (`composesArtifactDoor`) decides both. - A `MetadataPlugin` in `extraPlugins` is registered in the metadata slot, ahead of the app, and skipped in the `extraPlugins` loop. The harness still composes none of its own beside it. - A source boot (no `artifact`, no caller `MetadataPlugin`) is unchanged, and so is an app that declares a `MetadataPlugin` in its own `plugins`. - `loadCompiledArtifact` now also returns the `location` it resolved. The docblocks of `bootStack`, `BootOptions.artifact` and `BootOptions.extraPlugins` say where the door sits and why. `packages/verify/README.md` names the door and its slot. - `.changeset/36274-verify-artifact-metadata-door.md`: `@objectstack/verify` patch. ## Tests New pin: `packages/verify/src/harness.seed-extension-lookup.test.ts`. It boots a two-package artifact of the objectstack-ai#35254 shape: module `com.example.sxl.mod` adds `quote_ref` (lookup to `sxl_quote`) to the app's `sxl_order` through `objectExtensions`, and seeds `O-1` with `quote_ref: 'Acme Quote'`. There are two legs, `bootStack(config, { artifact })` and `bootStack(artifact, { extraPlugins: [MetadataPlugin({ artifactSource })] })`. Each leg asserts: - precondition: the metadata service's copy of `sxl_order` has no `quote_ref`, which is the copy `os dev` holds; - `quote_ref` stores the quote's id; - CONTROL: `account_ref`, the owner's own lookup, stores the account's id. <details> <summary>Measurement: what getObject held at seed time, per boot (pre-objectstack-ai#36272 resolver)</summary> The resolver body of `8925d5bc^` was put back in the worktree, never committed (blob 2713d6f4cb, the same blob objectstack-ai#36272's ablation used). `@objectstack/metadata-protocol` was rebuilt, and `ablation-dist-preflight.mjs @objectstack/metadata-protocol 'fromMetadata?.fields'` read the marker present in `dist/`. A scratch probe (not committed) wrapped `SeedLoaderService.prototype.resolveObjectDefinition` and recorded, for the extended object, whether the metadata copy and the engine schema carried the extension field. | boot | harness | metadata copy at seed time | engine schema | stored `quote_ref` | |:--|:--|:--|:--|:--| | `bootStack(config)` (source) | origin/main | has the field | has it | quote id | | `bootStack(config, { artifact })` | origin/main | has the field | has it | quote id | | `bootStack(artifact, { extraPlugins: [MetadataPlugin(artifactSource)] })` | origin/main | has the field (after boot: absent) | has it | quote id | | `createStandaloneStack({ artifactPath })` kernel (the `os dev` composition) | n/a | **absent** | has it | not read (see below) | | `bootStack(config, { artifact })` | this branch | **absent** | has it | **`"Acme Quote"`** | | `bootStack(artifact, { extraPlugins: [MetadataPlugin(artifactSource)] })` | this branch | **absent** | has it | **`"Acme Quote"`** | The standalone-stack leg composes only the stack's own plugins (no `AuthPlugin`), so its rows were refused for a missing organization. Its seed-time reading is the measurement there. That `os dev` stores the raw key on this resolver was measured on objectstack-ai#36272 (`os dev --fresh`, PR body table). </details> <details> <summary>Ablation of the pin (rebuild + on-disk mutation proof)</summary> The fix was committed first (d11ad49). The red leg used the same put-back resolver as above, with the dist marker present (preflight exit 0): - `vitest run src/harness.seed-extension-lookup.test.ts`: 2 failed, 4 passed. Both seed pins were red: `expected 'Acme Quote' to be 'Jxi4WdPdRfw5yZh3'` (artifact leg) and `expected 'Acme Quote' to be 'uI0EwppDilcGU-qA'` (caller-door leg). The two preconditions and the two CONTROLs stayed green. - Restore: `git checkout HEAD -- packages/metadata-protocol/src/seed-loader.ts`. The blob reads fdbca4a, the HEAD blob, and `git status --porcelain` showed only the untracked scratch probe, since deleted. After the rebuild, `--absent` read the marker absent from all 24 built files. - Green: 6 of 6 pin tests pass. </details> <details> <summary>Suite and gate readings</summary> - `pnpm --filter @objectstack/verify typecheck`: exit 0 (`check:test-typecheck: OK`). - `pnpm --filter @objectstack/verify exec vitest run --maxWorkers=2` (whole package): `Test Files 56 passed (56)`, `Tests 515 passed (515)`. - Flip sweep: every dogfood file that hands `bootStack` a `MetadataPlugin` or an `artifact` (16 files), run against the rebuilt `@objectstack/verify` dist: `Test Files 16 passed (16)`, `Tests 206 passed (206)`. No existing test flipped. - `dispatch-gates.mjs --commands` at ce65d57 derived 75 families, and every one ran locally, each exit captured before any pipe. 74 exited 0. `node scripts/check-plugin-teardown-shape.mjs --self-test` exited 3 (PREREQUISITE NOT MET: its fixture commit is out of this shallow clone's reach), so it is NOT MEASURED locally and CI runs it. `--ran` reconciliation: "75 derived, 74 run, 1 NOT-MEASURED, 0 UNRUN", exit 0. - The first pass at da23bd2 caught `check:test-source-alias` exiting 1 on the new pin, which loaded `@objectstack/service-automation` inside a case's clock. ce65d57 adds the module-top side-effect imports, and the gate exits 0. The whole list was re-run on that head (the reading above). The pin re-ran there too: `Tests 6 passed (6)`. `typecheck` exit 0. </details> ## Acceptance notes - **The dogfood-guidance sentence is not owed.** The Done-when offers it only for a harness that seeds through another path on purpose. The measurement shows the divergence was an accident of slot order, now fixed, so `.claude/skills/dogfood-verification/SKILL.md` is untouched. - **Not changed, same shape:** a `MetadataPlugin` declared in the app's own `plugins` is still registered in the app-plugins slot after `AppPlugin`, while `serve` registers it ahead of the wrap. No producer was measured; noted, not filed. - **Not changed:** a caller's `MetadataPlugin` with an `artifactSource` leaves the app's registrar at `'app-plugin'`. The harness cannot know that the caller's door reads the same file the app is mounted from, so both still register the four security collections, as before this change. - **Not changed:** the harness's `ObjectQLPlugin` still has no `environmentId`, so its one-shot bridge still copies registry objects the artifact does not carry into the metadata service. The door's load supersedes the bridge for every object the artifact carries. ## Verification Files to read first, by risk: 1. `packages/verify/src/harness.ts`, the metadata-slot hunk (`callerMetadataPlugins` / `composesArtifactDoor`) and the `extraPlugins` loop's skip. 2. `packages/verify/src/harness.seed-extension-lookup.test.ts`. 3. `.changeset/36274-verify-artifact-metadata-door.md`. Two-minute check: `pnpm --filter @objectstack/verify exec vitest run --maxWorkers=2 src/harness.seed-extension-lookup.test.ts` should print `Tests 6 passed (6)`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01ADHkmRar3Kkg6SpwVgaaVE <!-- signed: repo:objectstack#3 · os-steve · session_01ADHkmRar3Kkg6SpwVgaaVE --> --------- Co-authored-by: Claude <noreply@anthropic.com>
Fixes #35254
Clause-②: no
Metadata-protocol: none
维护者速读
What changes
SeedLoaderService.resolveObjectDefinition(packages/metadata-protocol/src/seed-loader.ts) is the one place the seed loader reads an object definition. Every per-field decision of a load goes through it: the reference graph, natural-key resolution, required-on-insert, the tenant column, the roll-up strip, the replay comparands and the undeclared-column warning.fields, and fell back to the engine's schema only when the metadata service had none. A boot that loads a compiled artifact (os dev,os serve, the cloud runtime) gives the metadata service each object as its own package wrote it. The fields another package adds throughobjectExtensions(ADR-0130 D5) live only in the ObjectQL registry's fold. So a lookup that an extension adds was never a reference. It had no graph edge, and its natural key was written verbatim into the foreign-key column.IDataEnginedoes not require one). The loader merges no extension itself: the registry's fold is the one source. The marketplace case the old fallback existed for (an object only the engine registry knows) is still served: it is now found on the first read.engineSchemaOf. The resolved definition now IS the engine's schema whenever the engine has one, so the union collapses tosummaryFieldNames(objectDefinition). Its pins are unchanged and green.resolveObjectDefinition,seedReferenceGraphFields,declaresNameColumn, and the seed: a seed row that supplies a summary (roll-up) field value is stored as written, and nothing recomputes it until a child write #35655 extension pin's header inseed-loader-summary-stale.test.ts..changeset/35254-seed-extension-lookup.md:@objectstack/metadata-protocolpatch.The in-process boot (
@objectstack/verifywithout an artifact) bridges the metadata service from the folded registry, so the metadata copy and the engine copy already agreed there. This change makes the artifact boot read what that boot already read.Tests
New pins in
packages/metadata-protocol/src/seed-loader-engine-schema-fallback.test.ts, as a top-leveldescribe('[#35254] …')on that file's engine double, which is already pinned. The metadata double serves the authoredext_orderwithoutquote_ref. The engine double'sgetSchemaserves the folded object withquote_ref → ext_quote. Every case has a CONTROL:account_ref, a lookup the owner authored on the same object.upsertandignore(the inserting modes;insertitself is a retiredSeedMode):quote_refstores the quote's id.insertOrderputsext_quote(andext_account) beforeext_order. Theext_ordernode'sdependsOnis[ext_account, ext_quote], and its references includequote_ref->ext_quotebesideaccount_ref->ext_account.update: the existing order row gets the quote's id and the account's id, and no second order is inserted.ext_quote.order_refback to the order): the cycle is detected, one side waits for pass 2, and both links resolve. The pass-2 writes and theinsertOrderare identical to the CONTROL, wherequote_refis authored.ext_order.quote_ref.falls back to the metadata service definition when the engine has no schema for the object(renamed fromprefers the metadata service definition …): the engine is asked first for every seeded object, and the metadata service is read for each.Premise on the real boot path: os dev on a two-package artifact
A fixture of the card's shape, not committed: app package
qx_appownsqx_accountandqx_order(with the authoredaccount_ref). Moduleqx_mod(built withartifactObjects) ownsqx_quote, addsquote_ref(→qx_quote) toqx_order, seedsO-1inupdatemode and insertsO-2inupsertmode, both withquote_refby the quote's name. Theos dev --freshboot came from this branch's CLI closure build, and the rows were read withGET /api/v1/data/qx_orderas the seeded dev admin.O-1.quote_ref(update)O-2.quote_ref(upsert)account_ref(CONTROL)"Acme Annual Renewal Quote""Acme Annual Renewal Quote"[SeedLoader] Dependency graph builtreadinsertOrder: [qx_account, qx_quote, qx_order]on both legs. That reading does not tell the legs apart on this fixture; the unit pins assert the edge itself.Ablation of the resolver order
The fix was committed first.
node scripts/ablation-replace.mjs --holdreplaced the three-line engine-first body withorigin/main's metadata-first body: anchor x1 → x0, replacement x0 → x1, blob fdbca4a77946 → 2713d6f4cbe4. Thenpnpm --filter @objectstack/metadata-protocol buildran, andablation-dist-preflight.mjs @objectstack/metadata-protocol 'fromMetadata?.fields'read the marker present indist/.Tests 7 failed | 15 passed (22). All five seed loader: a seed that sets a lookup another package adds through objectExtensions writes the raw natural key into the FK column (resolveObjectDefinition reads the object without its extensions) #35254 pins were red (for exampleexpected 'Q-ACME' to be 'gen-1'). So were the renamed fallback pin (expected [] to deeply equal [ 'crm_account', … ], metadata read first) and the seed: a seed row that supplies a summary (roll-up) field value is stored as written, and nothing recomputes it until a child write #35655 extension roll-up pin (expected [ 'name', 'total', 'ext_refunds' ] to not include 'ext_refunds', because the union is gone). The throwing-schema CONTROL stayed green.os devon that build: the raw names in the table above.git checkout HEAD -- ABS_PATHin a trap. Blob after restore fdbca4a77946 equals the HEAD blob,git diff HEADis empty, andgit status --porcelain -- packages/is empty. After a rebuild, the--absentdist reading passed. The tree reading reported only the uncommittedos devfixture (since deleted). Green again:Tests 22 passed (22), andos devstored the ids.The pins were later moved from a new file into
seed-loader-engine-schema-fallback.test.tsunchanged (see Acceptance notes).seed-loader.tsdid not change after the ablation.Suite and gate readings
pnpm --filter @objectstack/metadata-protocol testat e3d3340:Test Files 363 passed | 9 skipped (372),Tests 23325 passed | 45 skipped (23370).typecheck: VERDICT command-exit 0. At the head (dd69776, a test-file move only), the two edited test files readTests 22 passed (22)andtypecheckexits 0.dispatch-gates.mjs --commandsderived 67 families, and the list is identical at the head. All 67 ran locally, with each exit captured before any pipe:check:engine-double-contractexited 1 at e3d3340 (RETAINED: the new file's pinned double was not in the pinned ledger). The pins moved onto the file's already-pinned double, and the gate exits 0 at dd69776.check:dual-build-cjs-loadsexited 3 (PREREQUISITE NOT MET: no localdist/for packages outside this diff). NOT MEASURED locally; CI runs it.--ranreconciliation: "67 derived, 67 run, 0 NOT-MEASURED, 0 UNRUN", exit 0.overlap-checkat dd69776: VERDICT clean, exit 0.Acceptance notes
check:engine-double-contractrefused a new engine double. The gate asked for its pinned ledger to be regenerated (--write), and that ledger write was refused in this session. So the pins were folded intoseed-loader-engine-schema-fallback.test.ts, whose engine double is already pinned and is the same double the new file had copied.bootStackfrom@objectstack/verifywithMetadataPlugin({ artifactSource })over the same two-package artifact read the extension field absent frommetadata.getObject('qa_ext_order')and present ingetSchema. Yet it stored the quote's id on BOTH legs of the ablation, so it could not pin this defect, and it is not committed. Only the realos devboot showed the raw key. Why the harness's seed load sees a different definition was not established. This is reported as a finding, not fixed here. Carried by verify: a bootStack-booted seed resolves an extension lookup that os dev stores as the raw natural key, so the harness cannot pin #35254-class seed defects #36274.updateorupsertmode replaces the key with the id (the replay compare sees a difference). The changeset says so.packages/runtime/src/app-plugin.ts(no metadata service, or the loader threw) does not go through this resolver, as fix(metadata-protocol)!: a seed never stores a roll-up (summary) value; the children compute it, and the load says what it dropped #36118's notes already record.Verification
Two-minute check:
pnpm --filter @objectstack/metadata-protocol exec vitest run --maxWorkers=2 src/seed-loader-engine-schema-fallback.test.ts. ExpectTests 8 passed, including five[#35254]cases.Read first, by risk:
packages/metadata-protocol/src/seed-loader.ts, theresolveObjectDefinitionhunk: the order flip that every per-field read inherits.summaryFieldshunk inloadDataset: fix(metadata-protocol)!: a seed never stores a roll-up (summary) value; the children compute it, and the load says what it dropped #36118's union collapsed onto the single source.packages/metadata-protocol/src/seed-loader-engine-schema-fallback.test.ts: the probe assertion of the renamed fallback pin, and the new[#35254]block.Generated by Claude Code