Repository navigation
Commit b95d915
fix(metadata-protocol)!: the seed membership probe is bounded by the organization's members, and an id-shaped person is judged by membership (#33611)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} -->
_Requested by **Elon** · [project
thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9D4Jsmd91BqTVB7dSii9uJMV)_
Fixes #33280
Clause-②: no (narrowing) — narrowed: on a load for one organization, a
person reference (`sys_user` lookup) whose value is UUID- or
ObjectId-shaped resolves only when it names a member of that
organization, where it was written verbatim. A member's id still
resolves to itself; a load with no organization, a dry run and every
other reference target keep an id-shaped value verbatim. Unchanged: the
name/email lookup resolves the same member it did.
Metadata-protocol: none
Skills-docs: none — the seed docs
(`content/docs/data-modeling/seed-data.mdx`) and `skills/**` already
teach a natural key, not an id, for a reference; the membership rule
they inherit from the prior seed-scoping change is unchanged in wording.
## 维护者速读
- 改了什么:种子加载器按组织解析人员引用时,先读该组织的 `sys_member`(按 `user_id` 键集分页),再对每页成员做一次
`sys_user` 读取(限定成员 id 与引用值);不再按 offset 翻遍全部署同名人员。UUID/ObjectId
形状的人员引用在按组织加载时也走成员资格判定。
- 为什么改:旧探针成本随部署规模增长(托管环境每个组织都有同名样例人员),offset
翻页在并发删除下可能跳过真正的成员而误报「不是成员」;UUID 形状的值完全绕过成员规则,可以把行挂到组织外的人身上。
- 风险与回滚:收窄仅一处——按组织加载时用 UUID 指向非成员的种子引用,现在留空并报错(与按名字引用一致);成员的 id
照常解析,无组织加载不变。回滚即还原本 PR。
- 先看:`packages/metadata-protocol/src/seed-loader.ts` 的
`probeOrganizationMember`(成员分页与「首页命中即最小 id」的论证),其次
`resolveReferenceItem` 里内部 id 短路的改动与 `judgesInternalIdByMembership`。
- 两分钟验证:`pnpm --filter @objectstack/runtime exec vitest run
src/seed-org-scoped-references.integration.test.ts`,预期 21 个用例全绿,其中
#33280 三个新用例。
- 需要你做的:无,席位落地。
## What changes
`probeOrganizationMember`
(`packages/metadata-protocol/src/seed-loader.ts`):
- Reads the load organization's `sys_member` rows ordered by `user_id`,
a page (500) at a time, by keyset (`user_id` greater than the last one
seen). No `offset` anywhere, so a concurrent delete cannot shift a page
and skip the member.
- Each member page is asked ONE `sys_user` read constrained to that
page's user ids AND the reference value, `orderBy id asc, limit 1`.
Pages ascend by `user_id`, so the first page that answers holds the
lowest-id member and the walk stops there: the "lowest id wins" rule of
the previous probe holds.
- On a miss, one `limit: 1` read of `sys_user` by the value says whether
anyone outside the organization answers to it; it only words the verdict
("not a member of organization ...").
- The `id` probe leg reads the one membership row directly
(`organization_id` + `user_id`), then confirms the person exists.
- Cost is now bounded by the organization: an organization under 500
members answers a resolved reference with one member read and one person
read, whatever the number of same-named people deployment-wide.
The internal-id skip (`resolveReferenceItem`): an id-shaped value
(`looksLikeInternalId`) is still kept verbatim, except on a load pinned
to an organization (not a dry run) for the target whose probe scope is
`members` (`sys_user`), where it now goes through the same lookup, so
its `id` leg applies the membership rule. Decision: check it. A non-UUID
id (`usr_...`) already reached the membership probe through the `id`
leg; the recognised shapes were the only door past the rule. A seed
naming a member by id keeps working (pinned).
One changeset: `@objectstack/metadata-protocol` patch, with the BREAKING
note and its fix.
## Tests
New top-level describe in
`packages/runtime/src/seed-org-scoped-references.integration.test.ts`
(real `SqlDriver` over better-sqlite3, real `AppPlugin` replayer):
- **Bound pin**: the same replay (North resolves the member, South is
refused) with 0 and with 120 same-named strangers that sort before the
member; the count of `sys_user`/`sys_member` reads is equal for both, on
the hit and on the miss. No read carries `offset`; every person read
naming the key is constrained to member ids or `limit: 1`; every member
read is walled by the load organization.
- **Id-shaped person**: a UUID of a North member resolves on North; a
UUID of a South-only member is refused on North with the "not a member
of organization" error, and vice versa.
- **CONTROL**: a load with no organization keeps an id-shaped person
value verbatim.
The prior pins stay green: 60 same-named people with the member last,
the `workspace_id`-walled object (both cases), the pass-2 back-fill that
cannot see its row.
<details><summary>Ablation (each leg: on-disk mutation by
scripts/ablation-replace.mjs, metadata-protocol rebuilt, marker proven
in dist/, restore proven blob == HEAD, rebuilt, marker proven
absent)</summary>
- Leg 1, the previous offset probe restored verbatim (page 50):
`ablation-dist-preflight` "marker present in 2 built files"; integration
file `Tests 1 failed | 20 passed (21)`, the bound pin red with `expected
6 to be 2` (North reads with 120 strangers vs none). Restore: `blob ==
HEAD (7ec7f8b) and git diff HEAD is empty`; rebuild then `--absent`
green. A first attempt at this leg did not run: the mutated build failed
its dts step (an unused constant), so no test ran; the replacement was
respelled and the leg re-run.
- Leg 2, the internal-id skip restored (the membership judgement forced
off): marker present in 2 built files; `Tests 1 failed | 20 passed
(21)`, the id-shaped person case red (`expected ... to deeply equal
...`: North's non-member UUID kept). Restore proven the same way;
`--absent` green.
</details>
## Verification
Read at head `3a152285a2` (seed-loader blob `7ec7f8be7dbc`, unchanged
since the ablations).
<details><summary>Local runs</summary>
- `pnpm --filter @objectstack/metadata-protocol test`: Test Files 340
passed, 9 skipped; Tests 22877 passed, 43 skipped. VERDICT command-exit
0.
- `pnpm --filter @objectstack/runtime typecheck` (tsc +
check:test-typecheck): VERDICT command-exit 0.
- `pnpm --filter @objectstack/runtime test` (full suite, a direct
dependent): Test Files 602 passed; Tests 10784 passed, 19 skipped.
VERDICT command-exit 0.
- `eslint --no-inline-config` on the two changed source files: exit 0,
no findings.
- Derived gate families (`dispatch-gates.mjs --commands`, 65 commands):
see the report comment on the card for the reconciled list.
`check:dual-build-cjs-loads` answered PREREQUISITE NOT MET (needs a
whole-workspace build): NOT MEASURED locally, CI runs it.
- Full dogfood battery (narrowing arm): running on this head at the time
of writing; its reading is in the report comment on the card.
</details>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_016WV4cw787kMeaX7oyz7DDC
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 8f915f2 commit b95d915
3 files changed
Lines changed: 211 additions & 39 deletions
File tree
- .changeset
- packages
- metadata-protocol/src
- runtime/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2781 | 2781 | | |
2782 | 2782 | | |
2783 | 2783 | | |
2784 | | - | |
| 2784 | + | |
| 2785 | + | |
| 2786 | + | |
| 2787 | + | |
| 2788 | + | |
| 2789 | + | |
| 2790 | + | |
| 2791 | + | |
| 2792 | + | |
2785 | 2793 | | |
2786 | 2794 | | |
2787 | 2795 | | |
| |||
2895 | 2903 | | |
2896 | 2904 | | |
2897 | 2905 | | |
2898 | | - | |
2899 | | - | |
2900 | | - | |
2901 | | - | |
2902 | | - | |
2903 | | - | |
2904 | | - | |
| 2906 | + | |
| 2907 | + | |
| 2908 | + | |
| 2909 | + | |
| 2910 | + | |
| 2911 | + | |
| 2912 | + | |
| 2913 | + | |
| 2914 | + | |
| 2915 | + | |
| 2916 | + | |
| 2917 | + | |
| 2918 | + | |
| 2919 | + | |
| 2920 | + | |
| 2921 | + | |
| 2922 | + | |
| 2923 | + | |
| 2924 | + | |
| 2925 | + | |
2905 | 2926 | | |
2906 | | - | |
2907 | | - | |
2908 | | - | |
2909 | | - | |
2910 | | - | |
2911 | | - | |
| 2927 | + | |
| 2928 | + | |
| 2929 | + | |
2912 | 2930 | | |
2913 | 2931 | | |
2914 | 2932 | | |
2915 | 2933 | | |
2916 | 2934 | | |
2917 | 2935 | | |
2918 | 2936 | | |
2919 | | - | |
2920 | | - | |
2921 | | - | |
2922 | | - | |
| 2937 | + | |
| 2938 | + | |
| 2939 | + | |
2923 | 2940 | | |
2924 | 2941 | | |
2925 | | - | |
2926 | | - | |
| 2942 | + | |
2927 | 2943 | | |
2928 | | - | |
2929 | | - | |
2930 | | - | |
2931 | | - | |
2932 | | - | |
2933 | | - | |
| 2944 | + | |
| 2945 | + | |
| 2946 | + | |
| 2947 | + | |
| 2948 | + | |
| 2949 | + | |
| 2950 | + | |
2934 | 2951 | | |
2935 | | - | |
| 2952 | + | |
| 2953 | + | |
2936 | 2954 | | |
2937 | | - | |
2938 | | - | |
| 2955 | + | |
| 2956 | + | |
| 2957 | + | |
| 2958 | + | |
| 2959 | + | |
| 2960 | + | |
| 2961 | + | |
| 2962 | + | |
| 2963 | + | |
2939 | 2964 | | |
2940 | | - | |
| 2965 | + | |
2941 | 2966 | | |
2942 | 2967 | | |
2943 | 2968 | | |
2944 | | - | |
2945 | | - | |
2946 | | - | |
2947 | | - | |
2948 | | - | |
| 2969 | + | |
| 2970 | + | |
| 2971 | + | |
2949 | 2972 | | |
| 2973 | + | |
| 2974 | + | |
| 2975 | + | |
| 2976 | + | |
| 2977 | + | |
| 2978 | + | |
| 2979 | + | |
| 2980 | + | |
| 2981 | + | |
| 2982 | + | |
| 2983 | + | |
| 2984 | + | |
| 2985 | + | |
| 2986 | + | |
| 2987 | + | |
| 2988 | + | |
| 2989 | + | |
| 2990 | + | |
| 2991 | + | |
2950 | 2992 | | |
2951 | 2993 | | |
2952 | 2994 | | |
| |||
3478 | 3520 | | |
3479 | 3521 | | |
3480 | 3522 | | |
3481 | | - | |
3482 | | - | |
3483 | | - | |
| 3523 | + | |
| 3524 | + | |
| 3525 | + | |
| 3526 | + | |
| 3527 | + | |
3484 | 3528 | | |
3485 | | - | |
| 3529 | + | |
3486 | 3530 | | |
3487 | 3531 | | |
3488 | 3532 | | |
| |||
4557 | 4601 | | |
4558 | 4602 | | |
4559 | 4603 | | |
| 4604 | + | |
| 4605 | + | |
| 4606 | + | |
| 4607 | + | |
| 4608 | + | |
| 4609 | + | |
| 4610 | + | |
| 4611 | + | |
| 4612 | + | |
| 4613 | + | |
| 4614 | + | |
| 4615 | + | |
| 4616 | + | |
| 4617 | + | |
| 4618 | + | |
4560 | 4619 | | |
4561 | 4620 | | |
4562 | 4621 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
438 | 438 | | |
439 | 439 | | |
440 | 440 | | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
441 | 537 | | |
442 | 538 | | |
443 | 539 | | |
| |||
0 commit comments