Skip to content

fix(plugin-auth)!: import-users joins each row to the administrator's current organization in multi-org mode - #34750

Merged
os-zhuang merged 6 commits into
mainfrom
claude/project-thread-55tnyt
Nov 17, 2026
Merged

os-zhuang merged 6 commits into
mainfrom
claude/project-thread-55tnyt

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Steve · project thread

Fixes #34535

Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: none — no published skill teaches the admin import-users route (git grep -n import-users -- skills/ answers 0 lines on this head); the route is documented in content/docs/permissions/authentication.mdx, updated here

维护者速读

  • 改了什么:多组织模式下,CSV/JSON 批量导入用户时,每一行的用户都在建号的同一个事务里加入管理员当前所在的组织(和单个新建同一个判断、同一个加入函数);名额满等原因加入被拒的那一行不建号、不给临时密码、不发邀请,在该行报错,其余行照常;没有当前组织时整单 400 NO_ACTIVE_ORGANIZATION,和单个新建同码同句。upsert 匹配到的已有用户也按同一规矩加入。
  • 为什么改:你在 plugin-auth: admin import-users does not join created users to the importing admin's current organization in multi-org mode #34535 裁 B「入当前组织,被拒行不建号」。以前多组织下导入的用户不属于任何组织,positions 列每行都被成员资格校验拒掉,托管版用一份 CSV 建带岗位的员工走不通。
  • 风险与回滚:属收窄(BREAKING)。四处答复变了:无当前组织整单 400(含 dryRun);服务器跑不了加入时整单 501;被拒行不再建号;upsert 匹配到的已有用户加入被拒时连资料更新一起回滚。单组织模式不变(有 CONTROL 钉)。回滚=revert 本 PR。
  • 先看:packages/plugins/plugin-auth/src/admin-import-users.ts(inRowUnit 与 createData/updateData 两处)、admin-user-endpoints.ts(抽出的 settleCurrentOrganizationJoin,create-user 码句不变)、packages/qa/dogfood/test/create-user-organization-join.dogfood.test.ts(真引擎 I1/I2)。
  • 两分钟验证:pnpm --filter @objectstack/dogfood exec vitest run test/create-user-organization-join.dogfood.test.ts,预期 5/5 绿:I1 前两行进当前组织、第三行因名额上限失败且库里没有这个用户;I2 无当前组织 400。
  • 需要你做的:无,席位落地。

What changes

Maintainer ruling 6942842013 on #34535 (option B, Ruled: B): in multi-org mode POST /api/v1/auth/admin/import-users follows create-user's ADR-0093 D3 amendment rule, row by row.

  • One settlement, shared. create-user's pre-creation settlement (multi-org predicate, the caller's current organization, the unit-of-work seam and better-auth's addMember) moves into settleCurrentOrganizationJoin in admin-user-endpoints.ts; create-user calls it with its codes and sentences byte-identical (its existing multi-org suite is unchanged and green), and import-users calls the same function. No copy.
  • Settled before any row is written, dry run included. No current organization ⇒ the whole import answers 400 NO_ACTIVE_ORGANIZATION; no unit of work or no organization plugin ⇒ 501 NOT_IMPLEMENTED. Nothing is created.
  • One unit of work per row (inRowUnit): a created row's createUser and joinCurrentOrganization run inside createGrant.runAtomically (the engine transaction; better-auth's adapter writes join it as an ambient transaction, ADR-0067 D2). A refused join throws out of the unit, the account rolls back, and the row fails with the vendor's code and create-user's sentence. The temporary password and the invitation target are recorded only after the unit committed, and invitations go out after runImport, so a refused row gets neither.
  • Matched existing users (upsert) join too, per the seat's reading in 6942842013: the profile update and the join are one unit, so a refused join fails the row and leaves the profile as it was. joinCurrentOrganization gains an optional account: 'created' | 'existing' argument so that refusal does not say "no user was created", and an existing member is reported membershipCreated: false; create-user passes nothing and is unchanged.
  • Wiring: the import route now passes getTenancy and getCallerActiveOrganizationId (create-user's session reader) in auth-plugin.ts.
  • Audit: the run-level user.import_run row records the joined organizationId in multi-org mode.
  • Docs: content/docs/permissions/authentication.mdx Bulk Import section states the rule.
  • Single-org mode (and a degraded wall) does not move: no join, the reconciler binds the default organization.

Tests

  • admin-import-users-manager-pass.test.ts — the file's shared table-backed harness gains a multi-org mode (a unit of work that really restores the tables on throw, a member cap refused with better-auth's code, and the grant-holder membership refusal on position assignment), and one new top-level describe with 10 cases: joins + positions validate; refused row rolled back with no invitation (invite) and no password (temporary); 400 whole, dry run too, asserted equal to create-user's settlement answer; 501 for no unit of work / no addMember; dry run joins nothing; upsert joins and skips an existing member; upsert refusal rolls the profile back; CONTROL single-org.
  • packages/qa/dogfood/test/create-user-organization-join.dogfood.test.ts — the existing real-route, real-walled-posture harness for create-user's join gains I1 (three rows under OS_ORG_MEMBERSHIP_LIMIT=3: two join the current organization, the third is refused and its account is gone from sys_user) and I2 (no current organization: 400, no user). This file is outside the claim's plugin-auth test paths; it is the existing harness for this exact join, so the pin went there (AGENTS.md: a new pin goes into the component's shared harness file).
  • No existing test was changed to accommodate the fix.

Acceptance notes

FROM → TO, measured (multi-org mode unless stated):

Request main answers This PR answers
Import, administrator has no current organization 200, every row created, in no organization (dogfood I2 on the pre-fix build: created: 1) 400 NO_ACTIVE_ORGANIZATION, create-user's sentence, nothing created
Same, dryRun: true 200 preview 400 NO_ACTIVE_ORGANIZATION
Import on a host with no unit of work or no organization plugin 200, rows created 501 NOT_IMPLEMENTED, create-user's sentence, nothing created
A row the organization refuses (member cap) created, in no organization (dogfood I1 on the pre-fix build: created: 3) row failed with the vendor's code, account rolled back, no temporary password, no invitation; other rows land
Upsert row matching an existing user profile updated, no membership profile updated and joined in one unit; a refused join fails the row and the profile is not updated
A created row that joins created, in no organization; its positions refused on every row created and a member of the current organization; its positions assign
Single-org mode, any of the above unchanged unchanged (CONTROL pin)
  • The three cells beyond the ruling's text (501 whole, dry run refused whole, upsert profile rolled back with a refused join) apply create-user's same rule; the area accepted them, and they are declared in the changeset's BREAKING list.
  • ADR-0087 disposition: not-required (no-migration-prescription) — no schema key, export or stored row changes; the moved answers are admin HTTP refusals.
  • ADR-0093 D3 amendment's closing sentence ("…every other creation path (self sign-up, bulk import, SSO JIT, host hooks), still binds nothing in multi mode") is now false for bulk import; the ADR bookkeeping is carded as ADR-0093 D3 amendment: bulk import binds the administrator's current organization in multi mode after #34535 #34809 (docs/adr/** is outside an implementing card's surface).
  • A refused row's rows[].code is the vendor's code as mapAuthApiError reads it (ORGANIZATION_MEMBERSHIP_LIMIT_REACHED in the unit pin); the import response gains no new field.

Verification

Final head 6bfc9758 (the only commit after 870ce227 is a one-line anchor fix in content/docs/permissions/authentication.mdx).

Local gate round on 6bfc975 — 108 / 108 exit 0

node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack derived 108 commands; each ran with stdin closed and its exit captured before any pipe; --ran reconciliation: 108 derived, 108 run, 0 NOT-MEASURED, 0 UNRUN. File: /mnt/project-files/objectstack-seat2/34535-gates-ran.txt.
First round on 870ce227: two non-zero, both fixed before this round — check-plugin-teardown-shape --self-test exit 3 (shallow clone: its pinned fixture commit fetched with --no-tags, then 48/48), and check:doc-anchors exit 1 (#create-a-user → #create-a-user-directly, the commit above).

Tests
  • pnpm --filter @objectstack/plugin-auth test on 870ce227 (after merging origin/main f6f5b50a and a full pnpm build): Test Files 282 passed (282), Tests 5916 passed | 10 skipped. pnpm --filter @objectstack/plugin-auth typecheck (incl. check:test-typecheck): exit 0 after typing the harness's unit-of-work mock as the seam declares it.
  • create-user-organization-join.dogfood.test.ts: 5/5 on the fix.
  • Full dogfood battery, pnpm --filter @objectstack/dogfood test under the verify lock on 870ce227: VERDICT command-exit 0 (42m07s), Test Files 478 passed | 3 skipped (481), Tests 4057 passed | 68 skipped (4125). The final head differs only in the docs line above, which no dogfood test reads.
Ablations (one per changed behaviour, restore proven by blob == HEAD)
  • No join at all (the settlement replaced by undefined, i.e. main's import): the new multi-org describe goes 8 failed | 2 passed — the two that stay green are the dry-run-joins-nothing case and the single-org CONTROL, which assert the absence of a join.
  • Join outside a unit of work (runAtomically replaced by a pass-through): 4 failed | 6 passed — the refused-row rollback (invite), the temporary-password case, the upsert rollback, and the commit bookkeeping of the happy path.
  • FROM reading on the real engine: the same "no join" mutation built into plugin-auth/dist (ablation-dist-preflight: marker present in 2 built files), dogfood file: I1 expected 3 to be 2 (all three rows created, cap never reached), I2 expected 200 to be 400 (one user created in no organization); J1/J2 and the posture guard stay green. Restore leg rebuilt, marker absent from all 20 built files, tree clean.

Generated by Claude Code

@github-actions github-actions Bot added size/l documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 17, 2026
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/plugin-auth, touching 22 documentable anchor(s).

25 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: node scripts/docs-audit/affected-docs.mjs --json f02f4f63707bd05ae2186ca63babd54bfe37abcc.

⛔ 9 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails.

What this run could not see
  • 1 anchor(s) matched too much of the corpus to be a work list: sys_user (literal, 55 pages)
  • 1 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 65 of 247 client-bound route-ledger rows — the other 182 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 182: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 123 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 21 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json f02f4f63707bd05ae2186ca63babd54bfe37abcc → packageMentionDocs.

Which tree this was computed on

This run read content/docs from a63443cd71bf014db25aadc4e8a871bdb89e7574 — the merge of head 6bfc975899a1ed10282cfe967eb01ed3ad7e8ea8 into base f02f4f63707bd05ae2186ca63babd54bfe37abcc, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin a63443cd71bf014db25aadc4e8a871bdb89e7574 && git checkout a63443cd71bf014db25aadc4e8a871bdb89e7574
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin f02f4f63707bd05ae2186ca63babd54bfe37abcc 6bfc975899a1ed10282cfe967eb01ed3ad7e8ea8 && git checkout -B drift-repro f02f4f63707bd05ae2186ca63babd54bfe37abcc && git merge --no-ff 6bfc975899a1ed10282cfe967eb01ed3ad7e8ea8

node scripts/docs-audit/affected-docs.mjs --json f02f4f63707bd05ae2186ca63babd54bfe37abcc

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs f02f4f63707bd05ae2186ca63babd54bfe37abcc → pass the list as
args.docs, on the commit named under Which tree this was computed on.

…Directly heading

Claude-Session: https://claude.ai/code/session_01ADHkmQ6fcQhYhhjvBoSuKn
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#2 · os-steve · session_01ADHkmRXuRn93HphKp7kXEz

Final head for review: 6bfc975899a1ed10282cfe967eb01ed3ad7e8ea8 (card #34535, branch claude/project-thread-55tnyt). CI on this head, latest run per check (after the body-only footer edit re-ran PR-body guards and Check Changeset): 53 green (36 success, 17 skipped), 0 failed; mergeable state clean. Derived gates 108/108 exit 0 (--ran: 0 NOT-MEASURED, 0 UNRUN). Full dogfood battery: VERDICT exit 0, 478 files / 4057 tests passed (read on 870ce227, which differs from this head only by a test type cast and a docs anchor). check-governed-merges.mjs --pr 34750: NOT governed, 0 of 7 paths. Clause-②: no (narrowing) (four moved answers, listed in the FROM → TO table and the changeset's BREAKING list; three of them are cells beyond the ruling's text that apply create-user's same rule, accepted by the area), Metadata-protocol: none, Skills-docs: none, ADR-0087 disposition not-required (no-migration-prescription). The ADR-0093 D3 closing sentence this makes false is with the seat for an ADR bookkeeping card (outside this card's surface). Card report 6945990787. Owed: L1 review and the contract-tier L2 review (a narrowing), both on this head; then the seat's governed step. The PR stays a draft and unarmed. A push after this comment restarts both.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

l2-review#4 · os-steve · session_01ADHkmP44onN8RMzsPMqjRq

Contract-review-claim: session_01ADHkmP44onN8RMzsPMqjRq · head 6bfc975 · 2026-11-17T11:00Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#2 · os-steve · session_01ADHkmTHGRTjPqZAcBuo9WH

席位核对

L1 first review · ACCEPT · head 6bfc975899a1ed10282cfe967eb01ed3ad7e8ea8 (final head 6946100255) · card #34535 · read 2026-11-17T11:00Z

Checklist (read on GitHub at this head, not from the report)

  • Shape:

    • Draft PR against main; mergeable_state is clean, and the title carries !.
    • The only closing-keyword hit is Fixes #34535.
    • The footer is in AGENTS.md's PR-body form.
    • The claim (6943200727, 08:46Z) is earlier than the 09:49Z wind-down, so this PR is in flight.
  • Declarations:

    • Body and changeset both declare Clause-②: no (narrowing) and Metadata-protocol: none.
    • The body adds Skills-docs: none. I verified it: git grep -i import-users -- skills returns 0 hits at this head.
    • The changeset is patch with **BREAKING**, four FROM → TO lines, and adr-0087: not-required (no-migration-prescription). That marker holds, because only admin HTTP answers move: no schema key, export or stored row.
    • patch for a narrowing has precedent among the pending changesets (for example 33203-managed-no-local-password.md on the same package).
  • Against ruling 6942842013 (B, plus the seat's reading on matched users):

    • Each row joins in the unit of work that creates or matches its user.
    • A refused join creates no account and sends no invitation, and the refusal is reported on the row.
    • Having no current organization refuses the whole import with 400 NO_ACTIVE_ORGANIZATION.
    • A matched existing user joins too.

    Three cells go past the option text: the whole-import 501, the whole-import 400 on a dry run, and rolling back the upsert profile when its join is refused. All three apply the option's own words 「和单个新建同一规矩」 (same rule as a single create). They are declared in the FROM → TO table and in the changeset.

  • File surface: 7 files, +552/−58.

    • The dogfood pin sits in packages/qa/dogfood/test/create-user-organization-join.dogfood.test.ts, outside the claim's plugin-auth test paths. It is the existing harness for this same join, and the body names it.
    • ui/ is untouched: the import response gains no field.
  • Mechanism, read in the source:

    • Shared settlement. settleCurrentOrganizationJoin is create-user's former inline block, moved without change; its codes and sentences are byte-identical. create-user now calls it, and the import calls the same function before runImport, so the dry run is settled too.
    • inRowUnit. It wraps both the createUser and the matched-user update, together with joinCurrentOrganization, in join.seam.runAtomically. A CreationRefused is rethrown as a row error carrying the vendor's code and status, and any other throw passes through unchanged.
    • Commit order. The temporary password and invitation bookkeeping run only after the unit returns. An upsert with an empty patch still joins.
    • account: 'existing'. On a refusal it drops the "no user was created" clause, and it reports an existing member as membershipCreated: false. create-user passes nothing, so its behaviour is unchanged.
    • Wiring. auth-plugin.ts reads the session the same way create-user does.
    • Audit. The run row carries organizationId only in multi-org mode.
  • Tests:

    • 10 unit cases on a harness whose unit of work really restores the tables on throw, with a better-auth-coded member cap; a single-org CONTROL is among them.
    • Dogfood I1 and I2 on the real engine. I1 asserts that the refused row's account is gone from sys_user.
    • Ablations: "no join" leaves 8 of the 10 cases failing; "join outside the unit" leaves 4 failing. The FROM reading was taken through dist. Restore was proven.
    • No existing test was changed.
  • Gates at this head:

    • Check-runs on 6bfc9758…: 61 runs, all completed, 42 success, 19 skipped, 0 failed.
    • git merge-tree --write-tree against today's origin/main is clean.
    • check-governed-merges.mjs --pr 34750, read here: 0 of 7 paths governed, 610 lines.
    • The full dogfood battery is pinned at 870ce227 (4057 passed). The final head differs from it by one docs anchor only.

Before landing (no head move)

Owed outside this PR

  • ADR-0093 D3 amendment, docs/adr/0093-tenancy-mode-and-membership-lifecycle.md around line 273. It still reads "…every other creation path (self sign-up, bulk import, SSO JIT, host hooks), still binds nothing in multi mode". That becomes false for bulk import when this PR lands.
    • The ruling names the implementing PR as the one that rewrites it. The claim routed the edit to the seat instead, because docs/adr/** is governed.
    • Either way, the seat owes that Tier H edit. It should land with this PR or immediately after it, so the record and the code do not disagree for long.

Owed after this

  • L2: owed, CONTRACT_REVIEW_TIER (a declared narrowing).
  • Landing tier: narrowing, handed to the seat for Tier H. Not governed.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

l2-review#4 · os-steve · session_01ADHkmP44onN8RMzsPMqjRq

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 6bfc975899a1ed10282cfe967eb01ed3ad7e8ea8
Local-runs: none
Scope: .changeset/34535-import-users-current-organization.md, packages/plugins/plugin-auth/src/admin-import-users.ts, packages/plugins/plugin-auth/src/admin-user-endpoints.ts, packages/plugins/plugin-auth/src/auth-plugin.ts, packages/plugins/plugin-auth/src/admin-import-users-manager-pass.test.ts, packages/qa/dogfood/test/create-user-organization-join.dogfood.test.ts + packages/core/src/utils/import-runner.ts, packages/plugins/plugin-auth/src/platform-admin-gate.ts, packages/plugins/plugin-auth/src/reconcile-membership.ts, docs/adr/0093-tenancy-mode-and-membership-lifecycle.md, scripts/check-changeset-no-major.mjs (read in the cited code, not reviewed). Prose face content/docs/permissions/authentication.mdx was read against the code only.

Security-touching: yes
The diff changes who becomes a member of which organization. No access finding: the route stays behind the platform-admin gate (gateAdmin, judgePlatformAdmin), the organization is read from the caller's own session and never from the request body, and the role written is always member.

① Derived judgments

  • import-users accept-set, multi-org only: four answers narrowed (no current organization 400 whole, dry run included; no unit of work or no addMember 501 whole; a refused row creates no account; an upsert-matched user whose join is refused keeps its old profile). Right, and each is declared in the changeset's BREAKING list and the PR's FROM and TO table. Read in runAdminImportUsers: the settlement runs after request validation and before runImport, so nothing is written on either whole-request refusal.
  • create-user answers unchanged. Right. The block removed from runAdminCreateUser and the body of settleCurrentOrganizationJoin are the same text: same predicate, same order (400 before 501), same two codes and the same two sentences. joinCurrentOrganization's new fifth parameter defaults to 'created', and on that arm the refusal sentence and membershipCreated: true are what main answers. create-user passes four arguments.
  • Single-org and a degraded wall unchanged. Right. multiOrgCreationJoinsCurrentOrganization answers false before the session is read, settleCurrentOrganizationJoin answers undefined, and inRowUnit then calls the write directly with no transaction opened. The CONTROL case pins that the session reader, addMember and runAtomically are never called.
  • Public surface: additive only. settleCurrentOrganizationJoin, CurrentOrganizationJoin, the optional account parameter, and two optional members on IdentityImportDeps (getTenancy, getCallerActiveOrganizationId). A host that calls runAdminImportUsers without the two new members keeps main's behaviour, as create-user's predicate already reads. Right.
  • Response shape: no new field. A refused row answers action: 'failed' with the vendor's code read by mapAuthApiError and carried through toFailedResult as the thrown code. New values in an existing field. Right.
  • Audit row: organizationId added to the user.import_run metadata in multi-org mode. Additive. Right.
  • Metadata-protocol: none, Skills-docs: none, ADR-0087 not-required (no-migration-prescription). Right: no file under packages/spec is in the diff, no skill names the route, and no stored row, key or export changes shape.
  • Upsert rows always reach the join. Right. In import-runner.ts a matched row always calls updateData, and the head no longer returns early on an empty patch, so a matched user joins even when no profile field changes. Blank-key rows are skipped before the write and join nothing, as before.

② Semver level

Clause-②: no (narrowing)

@objectstack/plugin-auth: patch with a ! subject and a BREAKING section. That is the level check-changeset-no-major.mjs asks for: a declared Metadata-protocol: none must grade every entry patch, and no major is introduced. The BREAKING section carries four FROM and TO pairs, one per narrowed answer, and a one-line fix for the caller (switch to the organization first; raise OS_ORG_MEMBERSHIP_LIMIT for a capped row). The changeset matches what the diff publishes; I found no narrowed answer in the code that the list omits.

③ Boundary flags

  • Three cells beyond the ruling's text (dev flag). Answered, none needs a new ruling before this lands:
    • Dry run refused 400 with no current organization. Inside the ruling's own words ("the whole import is refused"). A preview answering 200 for a file whose import answers 400 would misreport the import.
    • 501 whole when the join cannot run in the account's unit of work. The ruling requires the join "in the same unit of work that creates the account". A host that cannot do that can only deliver member-less accounts, which the ruling forbids. Same rule and sentence as create-user. In the shipped wiring createGrant is always passed, so this is reached only when better-auth's organization plugin is off under a walled posture.
    • Upsert profile update rolled back with a refused join. This rests on the seat's reading in 6942842013 (matched existing users join too), which that comment marks as inside the maintainer's veto window, not on the option text. Given that reading, one unit per row is the consistent choice: the alternative is a row reported failed that still wrote. Defensible. For the approver, one consequence the card does not spell out: the upsert match runs deployment-wide under the system context, so a profile-refresh upsert now also adds every matched user, including users of other organizations, to the administrator's current organization as member. There is no longer a profile-only upsert in multi-org mode. The actor is a platform administrator who can perform Add Member anyway, so this is a product consequence, not an access finding; it should be visible at Tier H approval.
  • Test file outside the claim's paths (dev flag). Accepted: the dogfood file is the existing real-engine harness for this join.
  • ADR-0093 D3's closing sentence becomes untrue for bulk import. Ruling 6942842013 says the sentence "is rewritten by the implementing PR"; the claim moved it to the seat because docs/adr/** is outside an implementing card's surface, and the PR body points to ADR-0093 D3 amendment: bulk import binds the administrator's current organization in multi mode after #34535 #34809 (not among this review's inputs, not read). Shipping the code first is acceptable: the changeset, the product docs and the module header all state the new rule, and the ADR edit has its own approval path. It is a deviation from the ruling's letter, so ADR-0093 D3 amendment: bulk import binds the administrator's current organization in multi mode after #34535 #34809 should land in the same release window. The ADR text itself is not graded here.
  • Atomicity, tried five ways.
    • Membership insert fails after the user insert: CreationRefused leaves runAtomically, the engine transaction rolls back, and the temporary password and the invitation target are recorded only after the unit returns. Pinned for invite and temporary, and on the real engine by I1.
    • Duplicate email in one file: on insert the second createUser throws inside its own unit and fails that row as on main; on upsert the second row matches the first, finds the membership, and adds nothing.
    • Existing user already in another organization: joined to the current one (see the upsert flag above).
    • Dry run with no current organization: 400, pinned.
    • Single-org: no transaction, no join, pinned.
    • Inherited limit, not introduced here: createGrantFor(...).runAtomically falls through to a plain call when the engine or the datasource has no transaction (the engine's declared limit, warned once per driver). On such a datasource a refused row would leave its account behind while the row says no user was created. create-user has the same limit today; the 501 cell checks that a seam is wired, not that it is transactional.
  • SQL push-down. No new id materialisation and no in-app join. The join is one sys_member existence probe (limit: 1) and one addMember per row, inside the per-row unit the ruling requires so that the other rows go on.
  • Check-runs on this head. Pending, so not verdicts: Check Changeset (run 44070143991) and PR-body guards (claim · duplicate · Part-of · single-writer path) (run 44070143814). Both have earlier completed runs on this same head that concluded success. Concluded success: Build Core, Test Core and its eight shards, TypeScript Type Check and the Type Check family, Lint and Repo Gates and the Lint family, Build Docs, Check Documentation Links, Flag docs affected by code changes, Spec property liveness, Governed Surface Queue Guard, Live E2E UI, and the Dogfood Regression Gate aggregate. No check concluded failure.
  • Dogfood evidence. The three Dogfood Regression Gate shard jobs and Dogfood Verify CLI concluded skipped on this head; only the aggregate concluded success. The real-engine evidence for I1 and I2 is therefore the dev's local battery (4057 passed on 870ce227), which this read-only review cannot confirm. Verified with git: 870ce227 to the head is one line in content/docs/permissions/authentication.mdx (the anchor), and the commit before it is the one-line type cast in the unit test harness. The seat should confirm the dogfood shards run before merge.
  • Tests as pins. Real pins of each cell: refused row (account gone, no invitation, no temporary password, other rows land), 400 for both import and dry run asserted equal to the settlement's own answer, 501 for both causes, upsert join and no double add, upsert rollback of the profile, and the single-org control. I1 and I2 pin the created-row rollback and the 400 on the real route.

④ Design judgment

No must-fix, no should-fix.

The narrowing makes an existing refusal real; it does not take a declared capability away at the consumer. On main a multi-org import produced accounts in no organization, which the D8 amendment of ADR-0093 leaves with no data access, and whose positions were refused on every row. Nothing published promised that outcome as a capability; the only text describing it is the D3 closing sentence, which the maintainer ruled rewritten. The new refusals are create-user's, reached through one shared settlement and one shared join, not a copy. I tried to break the design on ordering (validation before settlement, settlement before any write), on the retry wrapper around the row write (a retried unit starts from a rolled-back state), on the positions pass (a rolled-back row is not walked), and on the organization source (session only). None broke.

  • N1 (nit) — the prose face keeps main's sentence that upsert updates "only touch profile fields" a few bullets above the new bullet saying a matched user also joins the organization. Both are true of the user row, but a reader can take the first as "upsert changes nothing else". Fixable on the prose face, or left.
  • N2 (nit) — I1 asserts the refused row's sentence and the missing sys_user row, not the row's code and not the credential row. The unit pin covers the code; the transaction covers the credential row. Left as an accepted gap or a follow-up.
  • N3 (nit) — on the 400 and 501 whole-request refusals the sentence is create-user's singular ("no user was created", "the new user"). The ruling asks for the same code and sentence, so this is as ruled; noted only because an import reads it about a file.

Implemented-by: claude/project-thread-55tnyt
Reviewed-by: session_01ADHkmP44onN8RMzsPMqjRq

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#2 · os-steve · session_01ADHkmQ2SN4K183oqAvUajA

Seat record · 2026-11-17T11:17Z · Head-sha: 6bfc975

维护者速读

  • 改了什么:多组织模式下,CSV/JSON 批量导入用户时,每一行的用户在建号的同一个事务里加入管理员当前所在的组织(和单个新建同一判断、同一加入函数)。名额满等原因加入被拒的那一行不建号、不给临时密码、不发邀请,只在该行报错,其余行照常;没有当前组织时整单 400 NO_ACTIVE_ORGANIZATION。
  • 为什么改:执行你对 plugin-auth: admin import-users does not join created users to the importing admin's current organization in multi-org mode #34535 的裁决 B「入当前组织,被拒行不建号」(6942842013)。以前多组织下导入的用户不属于任何组织,positions 列每行都被拒,托管版用一份 CSV 建带岗位的员工走不通。
  • 风险与回滚:收窄(BREAKING),四处答复变了:无当前组织整单 400(含 dryRun);服务器跑不了加入时整单 501;被拒行不再建号;upsert 匹配到的已有用户加入被拒时连资料更新一起回滚。单组织模式不变。回滚即撤回本 PR。
  • 先看:packages/plugins/plugin-auth/src/admin-import-users.ts(inRowUnit)、admin-user-endpoints.ts(抽出的 settleCurrentOrganizationJoin)、packages/qa/dogfood/test/create-user-organization-join.dogfood.test.ts。
  • 两分钟验证:pnpm --filter @objectstack/dogfood exec vitest run test/create-user-organization-join.dogfood.test.ts,预期 5/5 绿。
  • 需要你做的:用 os-zhuang 审读并批准(收窄,按 Tier H 交人),并请确认两点:① 席位对裁决 B 的读法:多组织下 CSV 按邮箱 upsert 匹配到的、本属其他组织的已有用户,也会以 member 身份加入管理员当前组织;② 本 head 上 dogfood 三个分片被选择器跳过,5/5 与全量 4057 过是本地读数(870ce22,与本 head 只差一行文档锚点);合并队列跑全量,会补上这一读数。批准即视为你接受这两点。契约复审 PASS 6946273468,钉在 Head-sha 6bfc975899a1ed10282cfe967eb01ed3ad7e8ea8。批准在案后由席位翻 ready,经合并队列落地。

席位意见:同意合并。按裁决 B 实现,超出裁决原文的三格(501、dryRun 无组织、upsert 回滚)都套用「和单个新建同一规矩」并已申报。

席位核对

  1. 形态:7 个文件,+552/−58,Fixes #34535;Clause-②: no (narrowing),Metadata-protocol: none,标题带 !。非受管 0/7;收窄 ⇒ 按 Tier H 交人。
  2. 前提实测:main 上多组织导入的行不入任何组织,带 positions 的行被成员资格校验拒(卡上复现)。
  3. 门禁 check-runs:head 6bfc9758 上 65 条,44 绿、21 跳、0 红;区报门禁 108/108;dogfood 本地全量 4057 过(见上)。
  4. 接受的偏差:L1-b2 ACCEPT 6946152446;契约复审 PASS 6946273468;dogfood 测试文件入认领面(修订 6946192204)。
  5. 范围外去向:ADR-0093 D3 修订末句在本 PR 合并后失实,记账卡 ADR-0093 D3 amendment: bulk import binds the administrator's current organization in multi mode after #34535 #34809(建议同一发版窗口落)。Skills-docs: none(无技能教此路由,文档已在本 PR 更新)。
  6. 落地条款:os-zhuang 授权批准在案后,席位翻 ready,经合并队列落地;合并即关 plugin-auth: admin import-users does not join created users to the importing admin's current organization in multi-org mode #34535,ADR-0093 D3 amendment: bulk import binds the administrator's current organization in multi mode after #34535 #34809 解锁。

@github-actions

Copy link
Copy Markdown
Contributor

⛔ merge queue 构建失败 — 先分诊,再决定要不要重排

队列构建 44080198671 红了。队列跑的是全量套件(PR 侧 CI 只跑 affected 子集),
所以失败的测试可能在本 PR 没碰过的包里 —— 那不是重排能修的。每次盲目重排都会让排在后面的所有 PR 重建一轮。

分类:failure —— 按下面的日志分诊。

失败的 job(日志抽取,best effort):

  • Dogfood Regression Gate (2/3) — 失败步骤: Boot example apps and exercise real user flows

    @objectstack/dogfood:test:  FAIL   isolated  test/activity-text-predicate.dogfood.test.ts > [#21154] a query over activity text or the approval snapshot, by a reader withheld a field of its record > a
      ↳ 失败原因: (这条 FAIL 之后 12 行内没有可识别的原因行 —— 点进 job 看)
    @objectstack/dogfood:test:  FAIL   isolated  test/activity-text-predicate.dogfood.test.ts > [#21154] a query over activity text or the approval snapshot, by a reader withheld a field of its record > a
      ↳ 失败原因: (这条 FAIL 之后 12 行内没有可识别的原因行 —— 点进 job 看)
    @objectstack/dogfood:test:  FAIL   isolated  test/activity-text-predicate.dogfood.test.ts > [#21154] a query over activity text or the approval snapshot, by a reader withheld a field of its record > a
      ↳ 失败原因: @objectstack/dogfood:test: AssertionError: {"object":"sys_activity","records":[],"total":0,"hasMore":false}: expected 200 to be 403 // Object.is equality
    

↳ 失败原因 是判读的关键:超时(Test timed out in … / Hook timed out in …)多半是负载/时序,不是本 PR 的回归;
断言(AssertionError: …)才指向真实的行为改变。两者的 FAIL 行长得一模一样,只有这一行能区分。

⚠️ 断言这一侧有一类例外,判据是断言在测什么,不是它是不是 AssertionError。 断言的对象是产品行为(一个值、一个形状、一次拒收)⇒ 照上面读:真实的行为改变,去查,⛔ 不要重排掉;
断言的对象是这次实验自身的有效性前提(跑完的耗时、负载下的先后、任何只在时间预算内才成立的条件)⇒ 它跟超时是同一类,同样对负载敏感,重排一次是合法的判别手段。
识别是机械的:断言的消息或它比较的值本身点名了一段时长、一个时间戳、一个耗时计数。实测过的一对 —— AssertionError: SecurityPlugin.init() ran: expected false to be true 测的是产品行为(真回归);
AssertionError: this run took over a second, so second-precision stamps could have differed too: expected 1006 to be less than 1000 测的是实验前提:它守护的那条不变式当时是绿的,同一个 head 原样重排一次即成功。
穿着 AssertionError 外衣的时间测量,仍然是时间测量。(⛔ 这只改「怎么读一次红」,不改「哪些测试可以重排」——后者由别处管。)

跨 PR 相同签名(24h,按失败测试文件聚合):

历史信号:

  • 本 PR 过去 24h 无队列失败记录(首次)。
  • 过去 24h 队列共有 26 个失败构建(不含本次)。

分诊清单:

  1. 失败测试在本 PR 改动的包里 → 真回归,修 PR。
  2. 失败测试与本 PR 无关 → 看上面的「跨 PR 相同签名」;已有汇总 issue ⇒ flaky/环境问题实锤,去那张 issue 上谈,修好前重排只会再烧一轮全队列。
  3. 两者都不是 → 可能与同组 PR 语义冲突;等前面的 PR 落地或失败出队后再重排一次即可,不要连续重排。

Generated by Claude Code · merge-queue-triage workflow (#4859)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue size/l tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

plugin-auth: admin import-users does not join created users to the importing admin's current organization in multi-org mode

3 participants