Repository navigation
Commit e26e7be
fix(organizations): the walled Default Organization's seed resolves its bound owner (#34457)
Fixes #34425
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:隔离(walled)部署首次启动时,系统自动创建的默认组织(Default
Organization)的示例数据(seed)回放,从"组织行写入时"推迟到"平台所有者成为该组织成员之后",示例数据里指向所有者的人员字段(指派人、审核人等)现在能正确填上。
-
为什么改:原来回放早于所有者的成员行写入,默认组织里一个成员都没有,示例数据中所有指向所有者的人员字段都存成空值;只有负责人(owner_id)靠后续的归属交接被补上,其它人员字段一直为空。
- 风险与回滚:只改了 `@objectstack/organizations` 一个中间件的触发时机,复用 #34038
已上线的"等待第一个成员再回放"机制;非隔离部署、用户新建组织、导入与迁移等路径不变,每个组织仍只回放一次;启动流程没能绑定所有者时,仍会在启动调用结束时照旧回放。回滚即还原这一个
PR。
-
先看:`packages/plugins/organizations/src/organizations-plugin.ts`(Middleware
B 的默认组织等待分支与 runEnsure
的兜底回放)、`default-organization-seed-owner.wall.test.ts`(真实隔离启动的复现测试)。
- 两分钟验证:`pnpm --filter @objectstack/organizations exec vitest run
src/default-organization-seed-owner.wall.test.ts`,预期 3 个用例全绿;在 main
上第二个用例是红的(所有者的指派人、审核人字段为空)。
- 需要你做的:无,席位落地。
## What changes
**Landing point:
`packages/plugins/organizations/src/organizations-plugin.ts` only.** On
a walled posture the default-organization bootstrap is wired by this
package alone (`AuthPlugin` skips its own bootstrap under a wall), and
the replay trigger is this package's Middleware B. `plugin-auth`'s
`ensure-default-organization.ts` is unchanged: it still writes the
organization, then the owner's member row, then runs the seed-ownership
handoff. Both `ensure-default-organization.ts` files named in the
claim's file surface are untouched.
The order on main, measured on a walled `bootStack`: the bootstrap
inserts the `default` organization as SYSTEM with no person behind it,
Middleware B replays the seed inside that insert, every person reference
in the seed is refused as "not a member of organization ORG", and only
then does the owner's `sys_member` row land. The seed-ownership handoff
re-owns NULL `owner_id` rows afterwards, so `owner_id` reads right and
every other person column (a `Field.user()` column, a
`Field.lookup('sys_user')` column) stays NULL.
The change reuses the mechanism #34038 added for the organization-create
path (the `awaitingFirstMember` wait, released by the organization's
first `sys_member` insert, one replay per organization). It adds a
second way in, and no second mechanism:
- While this plugin's default-organization bootstrap is running (a
counter, because the owner bind re-enters the bootstrap from inside the
deciding call), a SYSTEM `sys_organization` insert with slug `default`
and no `userId` no longer replays on the insert. It waits for the
organization's first member row and replays inside it, after the row is
stored. The replay names that member (the bound owner) as the locale
user, as the founder is named on the create path.
- When the bootstrap binds nobody (the owner bind was decided earlier
and only the organization was recreated, or the member write failed),
the last bootstrap call to finish replays the still-waiting organization
at once, with no person. That is the order it had before, delayed only
to the end of the bootstrap call.
- Every other organization insert is unchanged: an attributed create
waits as before, and any other SYSTEM or `userId` insert replays on the
insert.
**No signal is borrowed from attribution.** Stamping `attributedUserId`
on the bootstrap's organization insert would also have made Middleware B
wait, but `attributedUserId` is the audit attribution channel
(`sys_audit_log.user_id`), and nobody acted to create the Default
Organization. The bootstrap-scoped wait keeps the audit row as it is.
## Tests
- New
`packages/plugins/organizations/src/default-organization-seed-owner.wall.test.ts`:
`bootStack` (`@objectstack/verify`) with the real `AuthPlugin`,
`SecurityPlugin`, `AppPlugin` replayer and this package's
`OrganizationsPlugin`. The app's seed names the harness's dev admin (the
declared platform owner on a walled boot) in a `user` field, a `lookup`
to `sys_user` and `owner_id`.
- premise: the wall is up, and the Default Organization's only member is
the owner, role `owner`;
- the Default Organization was seeded once, and all three references
store the owner's user id;
- control, un-walled boot of the same app: the wall is down, the row is
seeded once, and it reads exactly as on main.
- `organizations-plugin.test.ts`, new top-level describe on an engine
double whose inserts run the plugin's middlewares, driven by the owner's
verified `sys_user` insert (the walled bootstrap trigger):
- the `default` organization replays once, inside the owner's member
write, naming the owner, and the member row is stored when the replay
reads membership;
- control: with the member write refused, the organization still replays
once, with no person.
<details><summary>Red on main, green on the fix, ablation</summary>
Red: the new wall test on `78cfdf31` / `b7675220` (test only, main's
plugin):
```text
ERROR [SeedLoader] Deferred reference UNRESOLVED after pass 2 — seedowner_task.assignee is NULL at the end of pass 2 on record 'Owner task'. ... because the sys_user row that answers to it is not a member of organization org_mwjons01f49gucr4, the organization this load seeds ...
× the replay seeded the Default Organization once, and every person reference naming the owner resolves to the owner 7ms
- "assignee": "jHY1Q8qdwMEN0mVDt0FKd5WCPBrkgp7J",
+ "assignee": null,
- "reviewer": "jHY1Q8qdwMEN0mVDt0FKd5WCPBrkgp7J",
+ "reviewer": null,
Test Files 1 failed (1)
Tests 1 failed | 2 passed (3)
os-verify-lock: VERDICT command-exit 1
```
Green, with the fix (now `46d2a91f`), the new wall test beside the
#34038 wall test:
```text
Test Files 2 passed (2)
Tests 6 passed (6)
os-verify-lock: VERDICT command-exit 0
```
Ablation, after committing the fix: `organizations-plugin.ts` restored
from the base commit `6a7403ba` (anchor `defaultOrgBootstrapsInFlight`
counted 0 on disk, file hash equal to the base blob `56168912`), the
wall test and the unit file run, the file restored from `HEAD` (anchor
count 5, hash equal to the HEAD blob `2b1eac94`, `git diff HEAD` empty).
The tests import the plugin from source, so no build was involved.
```text
× replays the default organization once, inside the owner's member write, naming the owner 9ms
× the replay seeded the Default Organization once, and every person reference naming the owner resolves to the owner 6ms
Test Files 2 failed (2)
Tests 2 failed | 25 passed (27)
```
Package suite and typecheck on `46d2a91f`:
```text
pnpm --filter @objectstack/organizations test Test Files 20 passed (20) · Tests 262 passed (262)
pnpm --filter @objectstack/organizations typecheck tsc --noEmit clean · check:test-typecheck: OK
os-verify-lock: VERDICT command-exit 0
```
</details>
## Acceptance notes
- **The card's un-walled baseline does not resolve these references
either, for another reason.** Measured on the un-walled control boot:
the boot seed loads before the dev admin's `sys_user` row exists, so
`assignee` and `reviewer` land NULL with "no such sys_user row exists",
and only the first-admin handoff writes `owner_id`. The card reads
"exactly as on an un-walled boot"; on this fixture the un-walled boot is
not a resolving baseline. The walled replay runs after the owner exists
and is the person being bound, so after this change it resolves them.
The un-walled reading is the same class of gap reached through another
entry point (only `owner_id` is repaired), and this PR does not fix it:
it is carried by #34458. The control pins the un-walled reading as it
stands on main, so a change to the un-walled path shows up there;
#34458's Done-when flips that control (`control: the same seed on an
un-walled boot reads as it did before the fix`) to the admin id.
- **Residual, not changed here:** if the bootstrap call throws after
inserting the organization and before its member write, the waiting
entry stays until a later member write releases it (the next bootstrap
trigger binds the owner) or the abandoned-create warning drops it.
`ensureDefaultOrganization` catches its own write failures, so no such
throw is known.
- No public contract moves: no spec, export, hook signature, error code
or route changes.
## Verification
Local gate subset, derived with `node scripts/pm/dispatch-gates.mjs
--commands --repo objectstack-ai/objectstack` against `46d2a91f` (68
families): 67 ran with exit 0. One was not measured locally and is left
to CI:
- `pnpm check:dual-build-cjs-loads`: exit 3, PREREQUISITE NOT MET
(packages outside this card's build closure have no `dist/` in this
worktree).
`--ran` reconciliation on `46d2a91f`: `68 derived, 67 run, 1
NOT-MEASURED, 0 UNRUN`. `origin/main` has not moved since the branch
point (`6a7403ba`).
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes (left to CI).
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: not touched.
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English.
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
Opened for seat `repo:objectstack#1` · os-project-manager ·
session_01FEkQ5kgF3mo9f7LXuv5hac, area o1-C.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01FEkQ5kgF3mo9f7LXuv5hac)_
<!-- signed: repo:objectstack#1 · os-project-manager ·
session_01FEkQ5kgF3mo9f7LXuv5hac -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 152cd1f commit e26e7be
4 files changed
Lines changed: 395 additions & 11 deletions
File tree
- .changeset
- packages/plugins/organizations/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 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 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
471 | 472 | | |
472 | 473 | | |
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 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
0 commit comments