Repository navigation
Commit 329f2f7
feat(plugin-auth): remove a pending person and retry every environment-user host call from a durable outbox (#34162)
repo:cloud#5 · hotlong · session_01Q4EjjPP1zuWBNq3nBXVei9
Fixes #33228
Clause-②: yes (widening) — added: `POST
/api/v1/auth/admin/remove-sso-user` (platform administrators,
cloud-managed environments only); an optional `userRemoved` member on
`EnvironmentUserHost` and the `'removed'` value of
`EnvironmentUserEventKind`; the `'deactivated'` value of the host
outcome's `reason`. Nothing that was accepted is refused.
Metadata-protocol: none
## 维护者速读
- **改了什么:** 云托管环境新增「删除待登录人员」接口 `POST
/admin/remove-sso-user`:邮箱输错、从未登录的人可以直接删掉,同时通知云端取消其邀请;已停用的待登录人员被重新添加时不再给他发邀请。
- **为什么改:** 此前输错邮箱的待登录人员只能停用、删不掉。按裁决 A,本 PR
只保留删除接口和宿主接缝;邀请的可靠投递、重试和每人邀请状态由云端宿主自己负责,框架不再另建发件箱,避免两层各自重试、两张状态表互相矛盾。
- **风险与回滚:** 只在 `OS_CLOUD_MANAGED=1`
时生效,只能删「待登录」的人;新接口和宿主可选成员都是加法,没有新表、没有迁移。云端暂时连不上时删除会被拒绝(503,人员保留,稍后重试即可),不会出现「本地删了、云端邀请还在」的情况。回滚即
revert 本 PR。唯一的行为变化是停用中的待登录人员被重新添加时不再通知云端(答复里写明 `deactivated`)。
- **先看:** `packages/plugins/plugin-auth/src/pending-sso-users.ts` 的
`runRemoveSsoUser` / `takeBackPerson`(删除行时带「待登录」条件)/
`removalNotDone`(删除失败后的内联重新邀请),以及同文件 `addOnePendingPerson` 里停用判断那几行;其次
`environment-user-host.ts` 的 `hostMember` 回退。
- **两分钟验证:** `pnpm --filter @objectstack/plugin-auth exec vitest run
--maxWorkers=2 src/pending-sso-users.test.ts`,预期 74 个测试全部通过。
- **需要你做的:** 无,席位落地(本 PR 767 行,低于 3000 行人合门槛,不触治理面)。
## What changes
Reshaped to ruling A on the card: the remove door and the host seam
stay, and the framework keeps no outbox. Delivering a host call durably,
and keeping each person's invitation status, is the host's job.
**Remove door.** `POST /api/v1/auth/admin/remove-sso-user` with `{
"userId": "…" }`, gated for platform administrators exactly as
`add-sso-user` is.
- Off a cloud-managed environment it answers `409` and removes no one.
- A person who is not pending answers `409` (deactivate them instead).
This also holds at the removal itself. The person is re-checked inside
the unit of work, and the `sys_user` delete carries `source:
'idp_pending'` in its `where` (a predicate delete, which honours
`deleteBehavior` like the by-id one). A delete that removes no row
throws inside the unit of work, so the child deletes roll back. A person
whose first sign-in lands while the host is asked is kept with `409`,
and the answer says the host was already told.
- **One window stays open (objectstack#34373, an engine defect, no
workaround here).** `sys_user` has cascading lookups. For such an object
the engine reads the matching ids, walks the cascade, and then deletes
`{ id: { $in } }` with no `source` predicate and no row lock. A first
sign-in that commits between that read and that delete is still deleted
and answered `200`. The docblocks, ledger note, docs and changeset all
say so.
- An unknown id answers `404`. A body with any key other than `userId`
answers `400`.
- The host is asked first, outside any transaction. Then the person's
positions, permission sets, membership and row are removed in one unit
of work, as the system.
- The host is told through `userRemoved`. A host without that member is
told through `userDeactivated` with `source: 'idp_pending'`, which by
ruling already means "cancel the invitation".
- A typed host refusal (403/409) answers with the host's own sentence,
and no one is removed.
- A host that cannot be reached refuses the removal, as it refuses a
deactivation. The answer is `503 SERVICE_UNAVAILABLE` ("could not be
reached … so they were not removed. Nothing was changed; try again.");
the person is kept and no invitation is re-sent. The door calls the host
once and keeps no record to ask again from, so removing the person would
leave an invitation nothing could cancel.
- With no host wired, the person is removed and the answer says `host: {
notified: false, reason: 'no_host' }`.
- A person other records still point at (`deleteBehavior: 'restrict'`)
answers the engine's refusal, and no one is removed. When the host had
already taken the cancellation and the person is still pending and not
deactivated, the door sends the invitation again inline, once, through
`userAdded`. The answer says whether that worked ("it was sent again",
or "sending it again did not succeed, so they stay pending with no
invitation: add them again"). Nothing is retried later.
**A deactivated person is never sent an invitation** (review#1 S1, the
in-door half). Re-adding a pending person who is deactivated no longer
calls `userAdded`. The answer is `200 alreadyPending` with `host: {
notified: false, reason: 'deactivated' }`. Reactivating them
(`admin/unban-user`) is what tells the host again. A `banned` column
read back as `true`, `1`, `'1'` or `'true'` counts as deactivated.
**Host contract.** `EnvironmentUserHost` gains an optional
`userRemoved(event)`, and `EnvironmentUserEventKind` gains `'removed'`.
The seam's header now says each door calls the host once, and that a
host which must not lose a call queues and retries it on its side.
**Also.**
- Auth route ledger row for the new door, plus the ledger-hygiene pin.
- Both dogfood admin sweeps classify it
(`admin-platform-admin-standing`, `admin-route-nonadmin-refusal`).
- `content/docs/permissions/authentication.mdx` documents the door, the
deactivated re-add, and what is the host's job (durable delivery,
per-person status, treating a repeat as harmless, cancelling by
`userId`, never by email address).
**Dropped from the earlier head `3c25103f`** (ruling A):
- `sys_environment_user_outbox` (object, platform-objects export,
`platform-object-names.ts` row, cli ownership inventory row, tenancy
census rows and census-page figures, the 21 generated translation
files);
- `environment-user-outbox.ts` (worker, lease, backoff, boot, accepted
trigger) and its tests;
- every outbox write in add, import, ban, unban and remove;
- `deliveryId` on `EnvironmentUserEvent`;
- the `invitation: { id, status }` answer fields;
- the `opts.retried` argument of `notifyEnvironmentUserHost`;
- the cli, spec and platform-objects changesets.
Outside the files listed below, the tree is byte-identical to `main`.
`admin-ban-endpoints.ts` and `manifest.ts` are back to main too.
## Tests
`pending-sso-users.test.ts` (+16 tests, 74 in the file):
- **Remove door:**
- removes the row, grants and membership, and tells `userRemoved` first;
- the `userDeactivated` fallback for a host without `userRemoved`;
- a not-pending person gets `409`, no host is called, and no one is
removed;
- a typed host refusal leaves the person in place;
- an unreachable host refuses the removal with `503`: the person is
kept, the host is asked once, and nothing is re-sent;
- `no_host`;
- the `restrict` refusal re-invites inline through `userAdded`;
- a re-invite the host does not take is answered truthfully;
- `404`, `400` (missing id, unknown key) and `403` (non-admin);
- the not-managed `409`.
- **S1 and pending at the write:**
- re-adding a deactivated pending person calls no `userAdded` and
answers `deactivated`;
- CONTROL: re-adding an active pending person invites again;
- a refused removal of a deactivated pending person sends no new
invitation;
- a `banned` column read back as `'1'` or `'true'` is deactivated on a
re-add;
- a person who signs in while the host is asked is kept with `409`;
- a person whose first sign-in lands inside the unit of work, after the
pending read and before the row's delete, is kept with `409`, and their
positions, permission sets and membership survive. The memory engine has
no transaction, so the test gives it a snapshot `transaction`, which the
plugin's `runAtomically` seam calls. The test asserts that the removal
entered that seam once and that the child rows were restored when
`NoLongerPending` was thrown. This proves the door's rollback path
against the seam; on the real engine the window above still applies.
Also: auth route ledger conformance, and the two dogfood admin sweeps.
## Acceptance notes
- **Durable retry and per-person invitation status live in the host.**
On a hosted environment that is cloud's `sys_env_member_request` (cloud
PR #4594), which already handles invite / cancel / remove. A host that
cannot be reached refuses the removal (`503`, nothing removed); the
framework does not retry. Whether Setup → Users reads status through a
host seam member or through cloud's table is decided on #33187, not
here.
- **Behaviour change on an existing door:** a re-add of a deactivated
pending person used to call `userAdded`. It now calls nothing and
answers `host.reason: 'deactivated'`. The request is not refused, and
the answer gains a value (declared in the `Clause-②:` line).
- **The pending check has a narrow open window on the real engine**
(objectstack#34373). The engine's predicate delete on an object with
cascading lookups re-deletes by id after the cascade walk, with no row
lock, so a first sign-in that commits in that window is still removed.
This is an engine defect, filed there, with no workaround in this PR.
- **A person who signs in while the host is asked to cancel** is kept,
but the host took the cancellation and no compensating call follows.
Already routed to #34183, unchanged here.
- **No explicit admin audit row for a removal.** The admin audit
writer's union only takes create and update. The removal runs attributed
to the administrator, so the engine's delete records who did it.
review#1 escalated this as a follow-up card for the seat.
- **No UI here.** No `sys_user` remove action. The Setup → Users column
and button stay with #33186 / #33187.
- **No new error code.** Refusals reuse `RESOURCE_CONFLICT`,
`RESOURCE_NOT_FOUND`, `INVALID_REQUEST` and the host's own codes.
## Verification
At head `2e868fa7e24` (origin/main `8436f67a2` merged at `1f1f43cbb`),
heavy runs under the shared verify lock.
- PR size against main: 11 files, +733 / −34 = **767 changed lines**,
nothing generated. This is under the 3000-line human-merge threshold,
and no governed surface is touched.
<details><summary>Gates</summary>
- Full derived run at `1f9b39d2606` (the previous head): `dispatch-gates
--commands --repo objectstack-ai/objectstack` derived 108 families. Each
ran with stdin from /dev/null and its exit code was captured before any
pipe. 106 exited 0. `check:skill-examples` exited 3 (`client-react` not
built), then 0 after a client-react build. `check:dual-build-cjs-loads`
exited 3 (needs a repo-wide build) and was NOT MEASURED locally; `Lint &
Repo Gates` ran it in CI and succeeded. `--ran` with `:: exit` codes:
"108 derived famil(ies) accounted for — 107 run, 1 NOT-MEASURED (1
DERIVED from a recorded exit 3)".
- This round at `2e868fa7e24` changed only prose (a docblock, the ledger
note, the docs paragraph and the changeset) and one test. Re-run
locally: the gate subset that reads those files, 14 of 14 exit 0. They
are `check:doc-authoring`, `check:auth-mount-ledger`,
`check-affected-docs`, `check-drift-comment`, `check-empty-changeset`,
`check-changeset-no-major`, `check:nul-bytes`, `check:issue-citations`
(both forms), `check:docs-transcript-drift`, `check:doc-anchors`,
`check:cross-package-test-inputs`, `check:engine-double-contract` and
`check:closed-ceremony-text`. The full family set is declared to CI for
this head.
- PR check-runs on `2e868fa7e24` at write time: 33 success, 15 skipped,
4 in progress, none failed. `Lint & Repo Gates`, `TypeScript Type
Check`, `Build Core`, `Check Changeset` and `Governed Surface Queue
Guard` are success; `Test Core` was in progress.
- Not run locally, left to CI: `pnpm lint`, `test:repo`, and the dogfood
battery (the title has no `!` and `Clause-②:` has no narrowing arm).
</details>
<details><summary>Tests</summary>
- `pnpm --filter @objectstack/plugin-auth test`: Test Files 279 passed
(279), Tests 5667 passed | 10 skipped (5677).
- `pnpm --filter @objectstack/plugin-auth typecheck`: exit 0.
- `pnpm --filter @objectstack/plugin-auth exec vitest run --maxWorkers=2
src/pending-sso-users.test.ts`: 74 passed.
</details>
<details><summary>Ablations</summary>
Each mutation went through `scripts/ablation-replace.mjs` in wrap mode
(the anchor hit once and the mutation landed, verified against the
blob). Each went red and was restored with blob == HEAD (the last two at
`d2608bc280f4`) and an empty `git diff HEAD`. The suite imports source,
so no `dist/` leg applies.
- Row delete without the pending marker (`where: { id, source }` reduced
to `where: { id }`): 1 failed (the in-unit sign-in case). Run at both
`1f9b39d26` and `2e868fa7e`.
- `takeBackPerson` run without its unit of work (`await (unit ?
unit.runAtomically(work) : work())` reduced to `await work()`), at
`2e868fa7e`: 1 failed, the in-unit case ("the removal ran inside the
transactional seam: expected +0 to be 1").
- The unreachable-host refusal disabled: 1 failed ("a host that cannot
be reached refuses the removal: 503").
- `isDeactivated` without the string forms: 1 failed ("a banned column
read back as a string"). The first attempt was a no-op:
`ablation-replace` refused it because the replacement (a bare semicolon)
was not distinct, and nothing ran. It was redone with a distinct
replacement.
- The in-unit pending pre-read reduced to an existence check: 1 failed
("a person who signs in while the host is asked", whose membership
assertion catches the child deletes the memory engine cannot roll back).
- The `userDeactivated` fallback disabled in `hostMember`: 1 failed.
- The S1 guard (`if (existing.deactivated)` made false): 2 failed (the
re-add case and the string-forms case).
- The inline re-invite disabled: 2 failed (the restrict re-invite case
and the truthful-failure case).
- The re-invite's deactivated check dropped: 1 failed ("a refused
removal of a deactivated pending person sends no new invitation").
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01Q4EjjPP1zuWBNq3nBXVei9)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 183a89e commit 329f2f7
11 files changed
Lines changed: 733 additions & 34 deletions
File tree
- .changeset
- content/docs/permissions
- packages
- plugins/plugin-auth/src
- qa/dogfood/test
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1316 | 1316 | | |
1317 | 1317 | | |
1318 | 1318 | | |
1319 | | - | |
| 1319 | + | |
| 1320 | + | |
1320 | 1321 | | |
1321 | 1322 | | |
1322 | 1323 | | |
| |||
1336 | 1337 | | |
1337 | 1338 | | |
1338 | 1339 | | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
1339 | 1377 | | |
1340 | 1378 | | |
1341 | 1379 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
389 | 389 | | |
390 | 390 | | |
391 | 391 | | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
398 | 399 | | |
399 | 400 | | |
400 | 401 | | |
| |||
5255 | 5256 | | |
5256 | 5257 | | |
5257 | 5258 | | |
| 5259 | + | |
| 5260 | + | |
| 5261 | + | |
| 5262 | + | |
| 5263 | + | |
| 5264 | + | |
| 5265 | + | |
| 5266 | + | |
| 5267 | + | |
| 5268 | + | |
| 5269 | + | |
| 5270 | + | |
| 5271 | + | |
| 5272 | + | |
| 5273 | + | |
| 5274 | + | |
| 5275 | + | |
| 5276 | + | |
| 5277 | + | |
5258 | 5278 | | |
5259 | 5279 | | |
5260 | 5280 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
294 | 294 | | |
295 | 295 | | |
296 | 296 | | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
297 | 301 | | |
298 | 302 | | |
299 | 303 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
260 | 260 | | |
261 | 261 | | |
262 | 262 | | |
263 | | - | |
| 263 | + | |
264 | 264 | | |
| 265 | + | |
265 | 266 | | |
266 | 267 | | |
267 | 268 | | |
| |||
0 commit comments