Skip to content

Commit 32fe321

Browse files
docs(adr): ADR-0093 D3 amendment note, bulk import joins the administrator's current organization (#35035)
Fixes #34809 Clause-②: no Metadata-protocol: none > **Governed / Tier H.** The diff touches `docs/adr/**` only, a Tier H row of `GOVERNED_SURFACES`. The note sits under the record's `Decisions` heading, the status line gains an entry, and the behaviour it describes is the admin user import (auth). So the low-risk add-only arm does not apply: it lands by the maintainer's hand or an authorized approval, and this area never readies, queues or arms it. ## 维护者速读 - 改了什么:ADR-0093 的 D3 修订(2026-10-24)末段下面,加一条带日期(2026-11-17)的修订说明;状态行末尾加一条 Amended。原裁决句一字未动。说明记录的是:有墙(多组织)模式下,批量导入的每一行用户都加入管理员当前所在的组织。 - 为什么改:你在 #34535 裁了 B(裁决记录 6942842013),PR #34750(合并提交 `36af6b05a7`)已经落地。ADR 那一句还写着批量导入在多组织下不绑定任何组织,和代码相左。 - 风险与回滚:纯文档,没有代码,不发布任何东西;回滚即 revert 本 PR。另有一处要知道:在开的 PR #34909 也在同一条状态行末尾追加了一句,两边在这一行上有文本冲突;后落地的一方合 main 时把两句都留下即可。 - 先看:`docs/adr/0093-tenancy-mode-and-membership-lifecycle.md` 第 276–307 行的修订说明。风险点是 upsert 那一条:它写明「已属于其他组织的已有用户,被 CSV 匹配到时也会加入管理员当前组织」。再看第 3 行状态行末尾新增的一句。 - 两分钟验证:`node scripts/check-adr-symbol-anchors.mjs && node scripts/check-adr-links.mjs && node scripts/adr-index.mjs --check`,预期三条都以 0 退出,最后一条印 `adr-index: OK`。 - 需要你做的:按 Tier H 审读并批准本 PR。 ## What changes One file, `docs/adr/0093-tenancy-mode-and-membership-lifecycle.md`, +34 / −1: - **An add-only dated note under the D3 amendment (2026-10-24)**, in the record's own `Amendment note (date, ruling)` blockquote form (the form of its 2026-11-11 note under D8). It says the amendment's closing sentence no longer holds for bulk import, and records what PR #34750 landed for `POST /api/v1/auth/admin/import-users`. It cites maintainer ruling 6942842013 (option B) and merge commit `36af6b05a7`. - **The ruled 2026-10-24 sentence is not rewritten.** The note states that the sentence stands as ruled for the reconciler and for the other creation paths it names (self sign-up, SSO JIT, host hooks). - **The status line gains one `Amended` entry** dated 2026-11-17, as the two later amendments of this record did (2026-11-08 and 2026-11-11). This is the one modified line of the diff: the entry is appended to the single status line. - `docs/adr/README.md` is unchanged. `node scripts/adr-index.mjs --check` answers that it is current (the index shows only the head of a status line). ## Tests None: the diff is one ADR. Nothing published moves, so no changeset (`skip-changeset`). ## Acceptance notes **The landed facts, FROM → TO, each read at `origin/main` `4443014630`.** "Walled posture" is `tenancy.isolationActive === true`, the predicate `packages/plugins/plugin-auth/src/admin-user-endpoints.ts#multiOrgCreationJoinsCurrentOrganization` reads. | Fact in the note | Before `36af6b05a7` | At `main` | Where it is read | Pin | |:--|:--|:--|:--|:--| | Settled before any row is written, on a dry run too | no settlement | `settleCurrentOrganizationJoin` runs before `runImport`, with no `dryRun` branch before it | `packages/plugins/plugin-auth/src/admin-import-users.ts#runAdminImportUsers` | the two `no current organization` cases (`dryRun` false and true) | | No current organization | `200`, rows created in no organization | `400 NO_ACTIVE_ORGANIZATION`, Create User's sentence, nothing created | `packages/plugins/plugin-auth/src/admin-user-endpoints.ts#settleCurrentOrganizationJoin` | same cases, asserted equal to the settlement's own answer; dogfood I2 | | No unit of work wired, or no `addMember` on better-auth's API | `200`, rows created | `501 NOT_IMPLEMENTED`, nothing created | same function (`!seam` or `addMember` not a function) | `a host with no unit of work, or no organization plugin` | | Created row: account and join are one unit of work | account only, no membership | `createUser` and `joinCurrentOrganization` inside `join.seam.runAtomically` | `inRowUnit` in `runAdminImportUsers`; `packages/plugins/plugin-auth/src/admin-user-endpoints.ts#joinCurrentOrganization` | `every created row joins`; dogfood I1 | | A refused join | n/a | row `failed` with the vendor's code, account rolled back, no temporary password, no invitation, other rows land | `inRowUnit` rethrows `CreationRefused` as the row's error; the password and the invitation target are recorded after the unit returns | `a row whose join is refused`, `a refused row under the temporary policy`; dogfood I1 | | Upsert-matched existing user | profile updated, no membership | joined in the same unit as its profile update; a refused join fails the row and leaves the profile; an existing member is not added twice | `updateData` in `runAdminImportUsers` calls `inRowUnit('existing', …)` | the two `upsert:` cases | | A dry run that is not refused | joins nothing | joins nothing | `runImport` with `dryRun` writes no row | `a dry run with a current organization joins nothing` | | Single mode, a degraded wall included | no join | no join; no session read, no transaction | `multiOrgCreationJoinsCurrentOrganization` answers false | `CONTROL single-org (or a degraded wall)` | The unit pins are the multi-org describe of `packages/plugins/plugin-auth/src/admin-import-users-manager-pass.test.ts`; the dogfood pins are I1 and I2 of `packages/qa/dogfood/test/create-user-organization-join.dogfood.test.ts`. **Where the note differs from the card's drafted paragraph, and why:** - The draft edited the ruled sentence (it took `bulk import` out of the list). The claim's form is add-only, so the sentence is untouched and the note says where it no longer holds. - `no organization plugin` is written as the code tests it: no `addMember` on better-auth's API. `no unit of work` is the host wiring no seam for the creation. - `multi mode` is written `under a walled posture`, the amendment's own words for the predicate, because a degraded wall is multi-requested and does not join. - Added from the merged PR's table and the code: a refused row gets no temporary password and no invitation and the other rows go on; a dry run that is not refused joins nothing; an existing member is not added twice. - Added, and worth the approver's eye: the upsert bullet says the matched user joins `whichever other organizations that user already belongs to`. This is read from the code, not from a pin: the membership probe in `joinCurrentOrganization` asks only about the current organization, and the import matches users across the deployment. The contract review of PR #34750 (6946273468) raised the same consequence for the approver. - Added: the unit of work is named as the engine transaction with the limit ADR-0119 D1 declares (a default driver without `beginTransaction` runs the callback with no rollback). The seam's own comment in `auth-plugin.ts` states that limit, and the same contract review lists it as inherited from Create User. - `501` on a dry run is true by the code path (the settlement precedes `runImport` whatever `dryRun` says); the pin covers `400` on a dry run and `501` on a real run. **Nothing moved in review after PR #34750's table was written.** The PR has no review comment and no submitted review; its last two commits type a test harness and repair one docs anchor. `git log 36af6b0..4443014` over the four files above, `auth-plugin.ts` and `reconcile-membership.ts` answers 0 commits, and `git merge-base --is-ancestor 36af6b0 4443014` answers exit 0. **Notes for the seat, not acted on here:** - Ruling record 6942842013 says the sentence `is rewritten by the implementing PR`. The claim chose the add-only note instead. This PR follows the claim; the difference from the ruling's letter is the approver's to accept. - The ruled sentence says SSO JIT and host hooks bind nothing in multi mode, while D3's table and D7 say those flows own membership there. The note repeats the sentence as ruled and does not reword it. Observation only; no card. - **Overlap.** `node scripts/pm/overlap-check.mjs --branch=HEAD` answers exit 1: this branch merges cleanly with `origin/main` (`6d2db1d7ef`) and conflicts with open PR #34909 in this file. The conflict is the status line alone (each side appends one `Amended` entry to the same line); the D1 and D7 hunks of that PR and the D3 hunk here merge cleanly. Whichever lands second merges `main` and keeps both entries. The claim recorded no open PR on this file; that reading was wrong at claim time. ## Verification Head `1a6abb30dd`, one commit on `origin/main` `4443014630`. <details><summary>Derived gates on 1a6abb3: 21 derived, 21 run, 0 NOT-MEASURED, 0 UNRUN</summary> `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` derived 21 commands from the one changed path. Each ran with stdin closed and its exit recorded before any pipe; all 21 answered exit 0. `node scripts/pm/dispatch-gates.mjs --ran` on that record: `21 derived famil(ies) accounted for — 21 run, 0 NOT-MEASURED`. - `pnpm check:adr-symbol-anchors`: `3756 anchors across 158 records resolve`. The note carries 5 of them (3 symbol, 2 file-level), read with the gate's own `extractAnchors`. - `node scripts/check-adr-links.mjs`: `1151 relative link destination(s) under docs/adr/ resolve`. - `pnpm check:adr-index`: `OK — docs/adr/README.md is current, every record parsed`. - `pnpm check:adr-anchors`, `pnpm check:doc-authoring`, `pnpm check:nul-bytes`, `pnpm check:pm-governed-merges`, `pnpm check:pm-prior-rulings`: exit 0. - `pnpm --filter @objectstack/lint run check:doc-formula-expressions` first answered exit 3 (prerequisite: `@objectstack/formula` and `@objectstack/lint` not built in this worktree). After `turbo run build` of those two under the verify lock (`VERDICT command-exit 0`), it answered exit 0. - Not run locally, left to CI: the repo-wide lint, the type-check lanes and the test shards. No package is touched. </details> <details><summary>Governed reading</summary> `node scripts/pm/dispatch-gates.mjs --tier`: model tier MANDATORY for `docs/adr/**`; changed lines 35 (+34 / −1), under the 3000 threshold. The `check-governed-merges.mjs --pr` reading is posted in the report on #34809 once this PR has a number. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufzgwLiKcfujYUug7sPs)_ <!-- signed: repo:objectstack#3 · os-support-ai · session_01WGufzgwLiKcfujYUug7sPs --> Co-authored-by: Claude <noreply@anthropic.com>
1 parent c21945d commit 32fe321

1 file changed

Lines changed: 34 additions & 1 deletion

File tree

‎docs/adr/0093-tenancy-mode-and-membership-lifecycle.md‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ADR-0093: Tenancy mode as a first-class capability, and a single owner for the user→membership lifecycle
22

3-
**Status**: Accepted (2026-07-13) — implemented: `tenancy` kernel service (`plugin-auth/src/tenancy-service.ts`), membership reconciler (`reconcile-membership.ts`), locked by `dogfood/test/membership-reconciler.dogfood.test.ts` · **Amended** (2026-11-08, [ADR-0151](./0151-ai-service-account-a-headless-agent-is-a-registered-principal-of-its-own.md) D1, proposed, adopted by its merge) — D7's machine / service-account row: the first-class marker it waited on is `sys_user.principal_kind`. The membership reconciler never binds an account of kind `agent`, whose one membership its registration creates. · **Amended** (2026-11-11, maintainer ruling 6796108313) — D8.1 reversed: under every tenancy posture, a person's data access requires a current membership in the organization, judged on each request; see the amendment note under D8.
3+
**Status**: Accepted (2026-07-13) — implemented: `tenancy` kernel service (`plugin-auth/src/tenancy-service.ts`), membership reconciler (`reconcile-membership.ts`), locked by `dogfood/test/membership-reconciler.dogfood.test.ts` · **Amended** (2026-11-08, [ADR-0151](./0151-ai-service-account-a-headless-agent-is-a-registered-principal-of-its-own.md) D1, proposed, adopted by its merge) — D7's machine / service-account row: the first-class marker it waited on is `sys_user.principal_kind`. The membership reconciler never binds an account of kind `agent`, whose one membership its registration creates. · **Amended** (2026-11-11, maintainer ruling 6796108313) — D8.1 reversed: under every tenancy posture, a person's data access requires a current membership in the organization, judged on each request; see the amendment note under D8. · **Amended** (2026-11-17, maintainer ruling 6942842013) — D3 amendment: under a walled posture, bulk import (`POST /api/v1/auth/admin/import-users`) joins each row to the administrator's current organization; see the amendment note under the D3 amendment.
44
- **Date:** 2026-07-13
55
- **Deciders:** ObjectStack Protocol Architects
66
- **Implementation:** #2882 (Phase 0 — tactical create-user bind, merged) → this PR (Phases 1–3 — `tenancy` service, fail-fast boot guard, membership reconciler, consumer migration, backfill, docs). One revision from the original plan, ratified in D2: the endpoint-level create-user bind **delegates to the shared reconciler** (one implementation, two call sites) instead of being deleted. Runtime verification confirmed the hook fires for `admin.createUser`, but better-auth *defers* `user.create.after` post-commit (#1881), so the endpoint keeps its delegated call to report `organizationId` / `membershipCreated` deterministically in its response. Cloud-host semantics (personal-org hook precedence, multi-org non-binding, D5 blast radius) verified against `objectstack-ai/cloud` — see D2/D3/D5.
@@ -273,6 +273,39 @@ This is not the reconciler guessing a tenant: the reconciler, and every other
273273
creation path (self sign-up, bulk import, SSO JIT, host hooks), still binds
274274
nothing in multi mode.
275275

276+
> **Amendment note (2026-11-17, maintainer ruling 6942842013 on #34535, option B — PR #34750,
277+
> `36af6b05a7`): bulk import joins each row to the administrator's current organization.** The
278+
> sentence above no longer holds for bulk import. Under a walled posture
279+
> `POST /api/v1/auth/admin/import-users` follows this amendment's rule row by row, through the one
280+
> settlement and the one join Create User runs:
281+
> `packages/plugins/plugin-auth/src/admin-user-endpoints.ts#settleCurrentOrganizationJoin`, `#joinCurrentOrganization`.
282+
> For the reconciler and the other creation paths that sentence names (self sign-up, SSO JIT, host
283+
> hooks) it stands as ruled: they still bind nothing in multi mode.
284+
>
285+
> - **Settled once, before any row is written, on a dry run too.** An administrator with no current
286+
> organization is refused whole (`400 NO_ACTIVE_ORGANIZATION`, Create User's code and sentence),
287+
> and so is an import on a host that wires no unit of work for the creation, or whose better-auth
288+
> offers no `addMember` (`501 NOT_IMPLEMENTED`). Nothing is created. A dry run that is not
289+
> refused joins nothing.
290+
> - **One unit of work per created row.** The row's account and its join, as `member` through
291+
> better-auth's `addMember`, run inside the seam's `runAtomically`
292+
> (`packages/plugins/plugin-auth/src/admin-import-users.ts#runAdminImportUsers`, its `inRowUnit`):
293+
> the engine transaction, with the limit
294+
> [ADR-0119](./0119-plugin-reachable-transactions-and-honest-atomic-batch.md) D1 declares for it.
295+
> A refused join (the organization's member cap, say) rolls that row's account back: the row
296+
> fails with the vendor's code, is handed no temporary password and is sent no invitation. The
297+
> other rows go on.
298+
> - **A row that matches an existing user (upsert) joins that user too** (the seat's reading in the
299+
> same ruling record), whichever other organizations that user already belongs to. The profile
300+
> update and the join are one unit of work, so a refused join fails the row and leaves the
301+
> profile as it was. A user already in the current organization is not added twice.
302+
> - **Single mode (a degraded wall included) is unchanged**: the import joins nothing, and the
303+
> reconciler binds the default org.
304+
>
305+
> Pinned by the multi-org cases of
306+
> `packages/plugins/plugin-auth/src/admin-import-users-manager-pass.test.ts` and, on the real
307+
> engine, by I1 and I2 of `packages/qa/dogfood/test/create-user-organization-join.dogfood.test.ts`.
308+
276309
### D4 — The `tenancy` kernel service
277310

278311
Registered under the service name **`tenancy`**:

0 commit comments

Comments
 (0)