Skip to content

Commit b2af63e

Browse files
committed
refactor(auth): reshape the pending-person remove door to ruling A, without the framework outbox
Ruling A on the card: the remove door and the optional `userRemoved` host member stay; durable retry and per-person invitation status are the host's job. Drops `sys_environment_user_outbox`, its worker, boot and accepted trigger, every outbox write in add/import/ban/unban/remove, `deliveryId`, the `invitation` answer fields, the translation bundles and the census/inventory/registry rows, so main is unchanged outside the door. A removal that fails after the host took the cancellation sends the invitation again once through `userAdded` and says whether it worked. A deactivated pending person who is re-added is not invited: the answer says `host: { notified: false, reason: 'deactivated' }`. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q4EjjPP1zuWBNq3nBXVei9
1 parent 1f1f43c commit b2af63e

44 files changed

Lines changed: 287 additions & 3227 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.changeset/33228-remove-pending-outbox.md‎

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
'@objectstack/plugin-auth': patch
3+
---
4+
5+
feat(auth): a cloud-managed environment can remove a pending person, cancelling their invitation at the host
6+
7+
Clause-②: yes (widening) — added: `POST /api/v1/auth/admin/remove-sso-user` (platform administrators, cloud-managed environments only); an optional `userRemoved` member on the environment-user host contract and the `'removed'` event kind; the `'deactivated'` value of the host outcome's `reason`. Nothing that was accepted is refused.
8+
Metadata-protocol: none
9+
10+
On a cloud-managed environment, a person added to sign in through the hosting organisation's identity provider stays pending until their first sign-in. Before this change a pending person with a typo in their email could only be deactivated.
11+
12+
**Removing a pending person.** `POST /api/v1/auth/admin/remove-sso-user` with `{ "userId": "…" }` asks the host first, outside any transaction, then removes the person with their positions, permission sets and membership in one unit of work:
13+
14+
- The host is told through `userRemoved`. A host without it is told through `userDeactivated` with `source: 'idp_pending'`, which already means "cancel the invitation". A host should implement `userRemoved`.
15+
- A host refusal (403/409) answers with the host's sentence, and no one is removed.
16+
- A host that cannot be reached does not block the removal; the answer says `host: { notified: false, reason: 'host_failed' }`. The door calls the host once: durable retry is the host's job.
17+
- With no host wired, the person is removed and the answer says `host: { notified: false, reason: 'no_host' }`.
18+
- A person who is not pending answers `409`: deactivate them instead. This holds at the removal itself, so a person who signs in while the host is asked is not removed.
19+
- A person that other records still point at (`deleteBehavior: 'restrict'`) answers the engine's refusal, and nothing is removed. If the host had already cancelled the invitation of a person who is still pending and not deactivated, the door sends it again through `userAdded`, once, and the answer says whether that worked.
20+
- An unknown id answers `404`; a body with any key but `userId` answers `400`. Off a cloud-managed environment the door answers `409` and removes no one.
21+
22+
**A deactivated person is never sent an invitation.** Adding a deactivated pending person again no longer calls `userAdded`; the answer says `host: { notified: false, reason: 'deactivated' }`. Reactivating them (`admin/unban-user`) is what tells the host again.
23+
24+
Nothing to migrate.

‎content/docs/permissions/authentication.mdx‎

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,10 +1333,9 @@ reactivation writes nothing, and a refused add takes that person back out
13331333
deactivation with `503` and writes nothing, since only the host can say
13341334
whether the person is an organization owner or admin. It never undoes or
13351335
blocks an add or a reactivation: the answer carries `host: { notified: false,
1336-
reason }`. Adding a person who is still pending again re-sends their
1337-
invitation and changes nothing else: positions, permission sets or a manager
1338-
sent with it are listed on the answer as `notApplied`; set them on the
1339-
person's record.
1336+
reason }`. Adding a person who is still pending again tells the host again
1337+
and changes nothing else: positions, permission sets or a manager sent with
1338+
it are listed on the answer as `notApplied`; set them on the person's record.
13401339

13411340
A pending person who never signs in, for example one added with a mistyped
13421341
address, can be removed: `POST /api/v1/auth/admin/remove-sso-user` takes
@@ -1345,36 +1344,30 @@ membership, and cancels their invitation at the host. The host is asked
13451344
first, through its `userRemoved` member; a host without that member is asked
13461345
through `userDeactivated` for the pending person instead, which means the same
13471346
thing, but a host should implement `userRemoved`. A host's refusal leaves the
1348-
person as they are. A person who is not pending (they have signed in, or were
1347+
person as they are. A host that cannot be reached does not block the removal:
1348+
the person is removed and the answer says `host: { notified: false, reason:
1349+
'host_failed' }`. A person who is not pending (they have signed in, or were
13491350
not added this way) is refused with `409`: deactivate them instead. That holds
13501351
at the removal itself, so a person who signs in while the host is asked is not
1351-
removed either, and the answer says the host was already told. A record
1352-
that still points at the person through a lookup that restricts deletes
1353-
refuses the removal with that lookup's own answer, and nothing is removed.
1354-
Like the add doors, it is platform-admin gated and answers `409` off a managed
1355-
environment.
1356-
1357-
On a cloud-managed environment these calls are recorded in
1358-
`sys_environment_user_outbox`, one row per call, readable by platform
1359-
administrators: every invitation sent (an add or re-add), every re-send (a
1360-
reactivation), and every cancellation (a removal, or the deactivation of a
1361-
person still pending). The deactivation of a person who has signed in is asked
1362-
of the host but not recorded. The door still makes the first call itself, so a refusal
1363-
reaches the administrator on that request, row by row. A call the host did not
1364-
take stays `pending` and is retried in the background with a growing wait (one
1365-
minute at first, up to twelve hours), and after twelve attempts it is
1366-
`failed`; a refusal that arrives on a retry is `failed` too, with the host's
1367-
code and sentence, and the person is left as they are. A failed reactivation
1368-
and a failed removal are retried the same way; a deactivation is never
1369-
retried, because a deactivation the host did not answer does not happen. The
1370-
newest row of a person is their invitation status: `sent`, `accepted` once
1371-
their first sign-in clears the pending state, `failed`, or, for a deactivation
1372-
or removal, the cancelled invitation. A call can reach the host more than
1373-
once, so each carries the row's id as `deliveryId` for the host to drop a
1374-
repeat. A host cancels an invitation by the event's `userId` or `deliveryId`, never by
1375-
its email address, which an administrator may have typed wrong and may type
1376-
again for someone else. The add, deactivate, reactivate and remove answers
1377-
name the row as `invitation: { id, status }`.
1352+
removed either, and the answer says the host was already told. A record that
1353+
still points at the person through a lookup that restricts deletes refuses the
1354+
removal with that lookup's own answer, and nothing is removed; when the host
1355+
had already cancelled the invitation of a person who is still pending and not
1356+
deactivated, the door sends the invitation again through `userAdded`, once,
1357+
and the answer says whether that worked. Like the add doors, it is
1358+
platform-admin gated and answers `409` off a managed environment.
1359+
1360+
A deactivated person is never sent an invitation: adding a deactivated pending
1361+
person again calls no host and answers `host: { notified: false, reason:
1362+
'deactivated' }`; reactivating them is what tells the host again.
1363+
1364+
Each door calls the host once and keeps no record of the call. Delivering it
1365+
durably, and keeping each person's invitation status, is the host's job: a
1366+
host may queue and retry a call it could not complete. A call can reach a host
1367+
more than once (adding a person who is still pending again tells the host
1368+
again), so a host should treat a repeat as harmless, and should cancel an
1369+
invitation by the event's `userId`, never by its email address, which an
1370+
administrator may have typed wrong and may type again for someone else.
13781371

13791372
`admin/ban-user` and `admin/unban-user` work without the admin plugin: on a
13801373
deployment without it the ban is written by the platform, and a banned user is

‎content/docs/permissions/tenant-audit-census.mdx‎

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ are reported as `undecidable` rather than assumed either way.
132132

133133
The same holds twice over for the context. An options argument spelled as a
134134
literal can be read; one spelled `options`, `{ ...opts }`, or handed through a
135-
forwarding shim cannot, and **59 of the 328 sites are spelled that way**. A
135+
forwarding shim cannot, and **59 of the 321 sites are spelled that way**. A
136136
context resolved from an inline literal or a local `const` can be tested for
137137
`isSystem`; one arriving from a helper call cannot.
138138

@@ -197,10 +197,10 @@ reproduce them. Where it disagrees, it disagrees on the page:
197197

198198
| carried figure | where it survives | this census |
199199
| :--- | :--- | ---: |
200-
| 175 write call sites | quoted in the merged changeset | **328** |
200+
| 175 write call sites | quoted in the merged changeset | **321** |
201201
| 24 carrying no tenant context | quoted in the merged changeset | **3** provable and tenancy-enabled; **32** more whose options argument is unreadable |
202-
| 127 of 175 statically decidable, 48 runtime-parameter-name sites | restated on the `isSystem`-scoping card | **233 of 328** decidable, **95** undecidable |
203-
| 135 (77%) silenced by the `isSystem` guard before the posture gate | the lost issue body — **no surviving corroboration** | **not reproduced**: 187 decidably elevated, 0 decidably not, 129 undecidable |
202+
| 127 of 175 statically decidable, 48 runtime-parameter-name sites | restated on the `isSystem`-scoping card | **226 of 321** decidable, **95** undecidable |
203+
| 135 (77%) silenced by the `isSystem` guard before the posture gate | the lost issue body — **no surviving corroboration** | **not reproduced**: 181 decidably elevated, 0 decidably not, 128 undecidable |
204204
| 141 and 132, two independent re-derivations | the card that filed this work | — |
205205

206206
**The differences are not reconciled, and deliberately so.** The old census's
@@ -211,17 +211,17 @@ at any commit.
211211

212212
Two structural facts do plausibly widen this reading against any hand or regex
213213
one, and both are counted in the generated tables below: the 66 sites reached
214-
through an erased (`any`) receiver, and the 93 that name their object through a
214+
through an erased (`any`) receiver, and the 86 that name their object through a
215215
`const` rather than inline. An instrument that read either the way a person does
216216
would report a smaller number and would not say so.
217217

218218
The fourth row is the one worth flagging to anyone citing it. **The 135 / 77%
219219
figure has no surviving corroboration anywhere in the tree.** This census reads
220-
187 of 328 (57%) as decidably elevated, with 129 more whose elevation is a
220+
181 of 321 (56%) as decidably elevated, with 128 more whose elevation is a
221221
run-time fact — so the claim is neither confirmed nor refuted, and the honest
222222
answer is that a static reading cannot settle it.
223223

224-
⇒ **Cite `3 / 328`, and say what it is**: the sites whose options argument was
224+
⇒ **Cite `3 / 321`, and say what it is**: the sites whose options argument was
225225
READ and holds no tenant context, against a decidably tenancy-enabled object.
226226
That is the control's provable yield surface. ⛔ Do not cite it as "the sites
227227
without tenant context" — **32 further sites** have an options argument this
@@ -233,29 +233,29 @@ cannot read, and they are neither in nor out.
233233

234234
| what | count |
235235
| :--- | ---: |
236-
| write call sites on the application surface | **328** |
237-
| …whose object name is statically decidable | 233 |
236+
| write call sites on the application surface | **321** |
237+
| …whose object name is statically decidable | 226 |
238238
| …whose object name is chosen at run time | 95 |
239-
| …against an object with tenancy ENABLED | 226 |
239+
| …against an object with tenancy ENABLED | 219 |
240240
| …against an object that declares tenancy off | 7 |
241-
| threading a tenant context | 257 |
241+
| threading a tenant context | 250 |
242242
| PROVABLY carrying none (options read, no context key) | **12** |
243243
| …of those, against a decidably tenancy-enabled object | **3** |
244244
| options argument UNREADABLE — may or may not carry one | 59 |
245245
| …of those, against a decidably tenancy-enabled object | 32 |
246-
| threading a decidably ELEVATED (`isSystem`) context | 187 |
246+
| threading a decidably ELEVATED (`isSystem`) context | 181 |
247247
| threading a context that is decidably NOT elevated | 0 |
248-
| threading a context whose elevation is a run-time fact | 129 |
248+
| threading a context whose elevation is a run-time fact | 128 |
249249

250250
| how the instrument reached the site | count |
251251
| :--- | ---: |
252-
| receiver carried a readable engine type | 262 |
252+
| receiver carried a readable engine type | 255 |
253253
| receiver erased, placed by the object NAME | 56 |
254254
| receiver erased, placed by an `object: string` PARAMETER | 5 |
255255
| receiver erased, placed by an `UNTYPED_RECEIVERS` row | 5 |
256256

257257
| object name spelled inline | 140 |
258-
| object name spelled through a `const` | 93 |
258+
| object name spelled through a `const` | 86 |
259259
| object name is an `object: string` parameter | 10 |
260260
| object name is some other run-time expression | 85 |
261261

@@ -307,13 +307,13 @@ holds still. They are required to be HERE and to say WHEN they were true;
307307
their values are not compared. The reasoning, and the measurement behind it,
308308
are in `scripts/check-tenant-audit-census.mjs`.
309309

310-
Measured on 2026-11-15 at `f51a0c4fc`.
310+
Measured on 2026-11-15 at `2ab05f460`.
311311

312312
| corpus scale (not enforced) | count |
313313
| :--- | ---: |
314-
| tracked non-test sources scanned | 1177 |
315-
| engine-shaped types recognised | 143 |
316-
| declared objects in the registry | 138 |
317-
| same-named calls subtracted as non-engine | 313 |
314+
| tracked non-test sources scanned | 1176 |
315+
| engine-shaped types recognised | 141 |
316+
| declared objects in the registry | 137 |
317+
| same-named calls subtracted as non-engine | 311 |
318318

319319
{/* END GENERATED: tenant-audit-census */}

‎docs/audits/2026-08-tenant-audit-write-call-sites.counts.md‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ silent, and `node scripts/tenant-audit-census.mjs --write` is the resolution.
3333

3434
| Measure | Value |
3535
|---|---:|
36-
| Write call sites | 328 |
37-
| Object name statically decidable | 233 |
36+
| Write call sites | 321 |
37+
| Object name statically decidable | 226 |
3838
| Object name chosen at run time | 95 |
39-
| Against a tenancy-enabled object | 226 |
39+
| Against a tenancy-enabled object | 219 |
4040
| Against an object declaring tenancy off | 7 |
41-
| Threading a tenant context | 257 |
41+
| Threading a tenant context | 250 |
4242
| Provably carrying none | 12 |
4343
| …and decidably tenancy-enabled | 3 |
4444
| Options argument unreadable | 59 |
4545
| …and decidably tenancy-enabled | 32 |
46-
| Threading a decidably elevated context | 187 |
46+
| Threading a decidably elevated context | 181 |
4747
| Threading a decidably non-elevated context | 0 |
48-
| Threading a context of undecidable elevation | 129 |
48+
| Threading a context of undecidable elevation | 128 |
4949

5050
## Subtractions the census could NOT defend — enforced
5151

@@ -90,14 +90,14 @@ holds still. They are required to be HERE and to say WHEN they were true;
9090
their values are not compared. The reasoning, and the measurement behind it,
9191
are in `scripts/check-tenant-audit-census.mjs`.
9292

93-
Measured on 2026-11-15 at `f51a0c4fc`.
93+
Measured on 2026-11-15 at `2ab05f460`.
9494

9595
| corpus scale (not enforced) | count |
9696
| :--- | ---: |
97-
| tracked non-test sources scanned | 1177 |
98-
| engine-shaped types recognised | 143 |
99-
| declared objects in the registry | 138 |
100-
| same-named calls subtracted as non-engine | 313 |
97+
| tracked non-test sources scanned | 1176 |
98+
| engine-shaped types recognised | 141 |
99+
| declared objects in the registry | 137 |
100+
| same-named calls subtracted as non-engine | 311 |
101101

102102
## Every site
103103

@@ -163,8 +163,6 @@ Measured on 2026-11-15 at `f51a0c4fc`.
163163
| `packages/plugins/plugin-auth/src/demo-staff.ts` | `insert` | `sys_user_position` | enabled | elevated | 1 |
164164
| `packages/plugins/plugin-auth/src/ensure-default-organization.ts` | `insert` | `object` | undecidable | elevated | 1 |
165165
| `packages/plugins/plugin-auth/src/ensure-default-organization.ts` | `update` | `sys_member` | enabled | elevated | 1 |
166-
| `packages/plugins/plugin-auth/src/environment-user-outbox.ts` | `insert` | `sys_environment_user_outbox` | enabled | context, elevation undecidable | 1 |
167-
| `packages/plugins/plugin-auth/src/environment-user-outbox.ts` | `update` | `sys_environment_user_outbox` | enabled | elevated | 6 |
168166
| `packages/plugins/plugin-auth/src/forced-reset-revocation.ts` | `update` | `SystemObjectName.API_KEY` | undecidable | elevated | 1 |
169167
| `packages/plugins/plugin-auth/src/forced-reset-revocation.ts` | `update` | `SystemObjectName.SESSION` | undecidable | elevated | 1 |
170168
| `packages/plugins/plugin-auth/src/idp-group-mapping-admin.ts` | `delete` | `IDP_GROUP_MAPPING_OBJECT` | undecidable | PROVABLY NONE | 1 |

0 commit comments

Comments
 (0)