Skip to content

Commit 2324d29

Browse files
committed
fix(plugins)!: business-unit recipients and approvers reach every member past 10,000 rows, and a failed member read refuses instead of answering nobody
The sys_business_unit_member reads in plugin-sharing (BusinessUnitGraphService expandUnitMembers / expandUsers, the primary-business-unit boot backfill) and plugin-approvals (expandBusinessUnitUsers) read to completion through the shared keyset walk and refuse a failed or truncated read; absence still answers no members. An expression approver's failed resolveAs expansion now logs the same "could not be expanded" warning the static approver types log, with the error. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JQwxbWdszDuXCYxfoR2ynB
1 parent 4d8095b commit 2324d29

9 files changed

Lines changed: 733 additions & 78 deletions
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
'@objectstack/plugin-sharing': patch
3+
'@objectstack/plugin-approvals': patch
4+
---
5+
6+
fix(plugins)!: business-unit recipients and approvers reach every member past 10,000 rows, a failed business-unit member read is refused loudly instead of answered with nobody, and a failed `resolveAs` expansion says so
7+
8+
Clause-②: no (narrowing)
9+
Metadata-protocol: none
10+
11+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped and no metadata changes: the business-unit expansions and the primary-business-unit backfill read lists they already read, to completion, and refuse a read that already failed. No author has anything to rewrite. -->
12+
13+
**BREAKING** only where a `sys_business_unit_member` read fails: the business-unit expansions used to answer nobody (an empty list) then, and now refuse.
14+
15+
This extends the family the team, position and role fixes closed to the last membership object, `sys_business_unit_member`. Its reads still read once with a 10,000-row bound and turned any read error into nobody.
16+
17+
- **Every member, nobody else.** In plugin-sharing, `BusinessUnitGraphService.expandUnitMembers` (every `business_unit` sharing recipient) and `BusinessUnitGraphService.expandUsers` (every `unit_and_subordinates` recipient) now read in pages of 10,000 ordered by id until the members are exhausted. In plugin-approvals, the `department` / `business_unit` / `bu` approver and an `expression` approver with `resolveAs: 'department'` do the same. Past 10,000 members, the members past the 10,000th row used to get no grant and no approval slot. They now do.
18+
- **The primary-business-unit backfill projects every primary membership.** The boot backfill of `sys_user.primary_business_unit_id` used to scan the `is_primary` rows once at the same bound, so users past the 10,000th row were never projected and nothing said so. It now pages to completion. A scan that fails, or a page the driver returned without honouring the id cursor, writes nothing and logs why (a failed scan logged before too, now with the consequence).
19+
- **Smaller units are unchanged.** A unit or subtree with fewer than 10,000 members issues one read, as before, and answers the same set.
20+
- **Loud, never short or empty.** A member read that fails, or a page the driver returned without honouring the id cursor, now throws.
21+
- Sharing, whole-rule passes: the expansion rejects, so that rule's reconcile or revoke pass fails, its callers log their existing per-rule warning, and the grants it already holds stay. Before, a failed read answered `[]`, so the retired-recipient revoke a business-unit graph write triggers took the rule's grants away from every member.
22+
- Approvals: the approver slot falls back to its literal (`department:ID`) and logs `could not be expanded — a directory or read-filter lookup failed` with its `error`. Before, a failed read logged "expanded to nobody", indistinguishable from an unstaffed unit.
23+
- Ownership queues: a `business_unit` or `unit_and_subordinates` queue specification whose member read fails still contributes nobody, the posture the queue declares for a failed member-table read, and now logs it once.
24+
- **A failed `resolveAs` expansion says so.** An `expression` approver whose `resolveAs` value could not be expanded (a `department`, `position` or `team` read failed) kept its `KIND:VALUE` literal slot with no log line. It now logs the same `could not be expanded` warning the static approver types log, with the `error` and the `expression` source.
25+
- **A missing object is still no members.** A stack that never registers, or never creates, `sys_business_unit_member` keeps answering no members through it, and the backfill has nothing to project. That is judged by `isObjectAbsentError(error, 'sys_business_unit_member')`; any other error stays loud.
26+
27+
**The remedy.** None is needed. A refusal means the membership table could not be read: fix that read, and the next expansion succeeds. A failed read is never cached.

‎content/docs/automation/approvals.mdx‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -456,11 +456,13 @@ What an entry that resolves to nobody leaves on the slate depends on its kind:
456456
[Acting on requests in the console](#acting-on-requests-in-the-console)).
457457
Beside entries that do resolve, a literal is a slot like any other, so a
458458
`behavior` that needs every slot (`unanimous`) waits on it too. A `team`,
459-
`position` or `org_membership_level` entry whose holder read failed
460-
(`sys_team_member`, `sys_user_position` or `sys_member`) keeps its literal
461-
the same way. It logs `could not be expanded — a directory or read-filter
462-
lookup failed` with the `error`, instead of `expanded to nobody`, and never
463-
routes to the holders that happened to read.
459+
`position`, `department` or `org_membership_level` entry whose holder read
460+
failed (`sys_team_member`, `sys_user_position`, `sys_business_unit_member`
461+
or `sys_member`) keeps its literal the same way. It logs `could not be
462+
expanded — a directory or read-filter lookup failed` with the `error`,
463+
instead of `expanded to nobody`, and never routes to the holders that
464+
happened to read. An `expression` value whose `resolveAs` read failed keeps
465+
its literal and logs the same line, with the `expression` source.
464466
- **A slate left empty, or holding only literals,** goes to the node's
465467
`onEmptyApprovers` policy, whose four values are listed under
466468
[Approving across organizations](#cross-org-approvers). Under the default,

‎packages/plugins/plugin-approvals/src/approval-service.ts‎

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ const MEMBER_SCREEN_READ_LIMIT = 50000;
11211121
/**
11221122
* [#29362, #29503] Rows per page of the directory holder reads
11231123
* ({@link ApprovalService.readHoldersToCompletion}: the membership tier, the
1124-
* position assignments, the team members) — the bound each read always
1124+
* position assignments, the team members, the business-unit members) — the bound each read always
11251125
* carried, so a group held by fewer people issues the one read it always did,
11261126
* and one held by more is read in further pages rather than cut.
11271127
*/
@@ -2695,12 +2695,7 @@ export class ApprovalService implements IApprovalService {
26952695
// this is, and carry the error, so an operator does not go staffing a
26962696
// position whose holders simply could not be read. The try above also
26972697
// wraps the cross-org read filter (`bounded`), so the line names both.
2698-
this.logger?.warn?.(
2699-
`[approvals] approver '${type}:${a.value}' could not be expanded — a directory or read-filter lookup failed, so the `
2700-
+ `slot falls back to its literal rather than route to part of its people. Fix the read (see error); `
2701-
+ `a slate left naming no one is decided by the node's onEmptyApprovers.`,
2702-
{ type, value: a.value, organizationId: organizationId ?? null, error: directoryFailure },
2703-
);
2698+
this.warnExpansionFailed(type, a.value, organizationId, directoryFailure);
27042699
} else {
27052700
this.logger?.warn?.(
27062701
`[approvals] approver '${type}:${a.value}' expanded to nobody — the slot names no one, so no one is `
@@ -2717,6 +2712,32 @@ export class ApprovalService implements IApprovalService {
27172712
return [`${type}:${a.value}`];
27182713
}
27192714

2715+
/**
2716+
* [#29362, #29606] The one warning an approver slot logs when its expansion
2717+
* FAILED — a directory or read-filter lookup threw — rather than came back
2718+
* empty: the slot falls back to its literal, and the line carries the error.
2719+
* Shared by the static graph types ({@link resolveApproverSpec}) and an
2720+
* `expression` approver's `resolveAs` values ({@link resolveExpressionApprovers},
2721+
* which passes its source as `expression`), so the two cannot drift.
2722+
*/
2723+
private warnExpansionFailed(
2724+
type: string,
2725+
value: unknown,
2726+
organizationId: string | null | undefined,
2727+
error: string,
2728+
expression?: string,
2729+
): void {
2730+
this.logger?.warn?.(
2731+
`[approvals] approver '${type}:${value}' could not be expanded — a directory or read-filter lookup failed, so the `
2732+
+ `slot falls back to its literal rather than route to part of its people. Fix the read (see error); `
2733+
+ `a slate left naming no one is decided by the node's onEmptyApprovers.`,
2734+
{
2735+
type, value, organizationId: organizationId ?? null, error,
2736+
...(expression === undefined ? {} : { expression }),
2737+
},
2738+
);
2739+
}
2740+
27202741
/**
27212742
* Resolve an `expression` approver (#3447 P2): evaluate its CEL source at
27222743
* node entry against the three explicit roots — `current` (live record),
@@ -2859,6 +2880,11 @@ export class ApprovalService implements IApprovalService {
28592880
}
28602881
} catch (err: any) {
28612882
if (String(err?.message ?? '').startsWith('VALIDATION_FAILED')) throw err;
2883+
// [#29606] The literal slot below is the same fallback the static graph
2884+
// types take, and it says why exactly as they do: a failed read is not
2885+
// an unstaffed value, so an operator is pointed at the read rather than
2886+
// at staffing it.
2887+
this.warnExpansionFailed(resolveAs, key, organizationId, err instanceof Error ? err.message : String(err), source);
28622888
users = [];
28632889
}
28642890
if (crossOrg && users.length) {
@@ -3210,20 +3236,22 @@ export class ApprovalService implements IApprovalService {
32103236
if (kid && !seen.has(kid)) { seen.add(kid); queue.push(kid); }
32113237
}
32123238
}
3213-
let rows: any[] = [];
3214-
try {
3215-
rows = await this.engine.find('sys_business_unit_member', {
3216-
// #14946: tenant-screened — {@link businessUnitMemberScope} is STRICT
3217-
// on purpose and is not {@link businessUnitOrgScope}. The units above
3218-
// proved their tenancy; these rows have not, and the
3219-
// shared seeded unit id is exactly where other tenants' rows sit.
3220-
where: this.businessUnitMemberScope({ business_unit_id: { $in: Array.from(seen) } }, organizationId),
3221-
fields: ['user_id'],
3222-
limit: 10000,
3223-
context: SYSTEM_CTX,
3224-
} as any);
3225-
} catch { rows = []; }
3226-
return Array.from(new Set((rows ?? []).map((r: any) => String(r.user_id ?? '')).filter(Boolean)));
3239+
// [#29606] Every member of the subtree, read to completion — or a refusal
3240+
// that {@link resolveApproverSpec}'s directory catch reports as a failed
3241+
// read, never "expanded to nobody". It read once at a 10,000-row bound and
3242+
// answered `[]` on any failure: past the bound the slate silently lost the
3243+
// rest, and a failed read logged as an unstaffed unit. A stack with no
3244+
// `sys_business_unit_member` has no members.
3245+
return this.readHoldersToCompletion(
3246+
'sys_business_unit_member',
3247+
// #14946: tenant-screened — {@link businessUnitMemberScope} is STRICT
3248+
// on purpose and is not {@link businessUnitOrgScope}. The units above
3249+
// proved their tenancy; these rows have not, and the
3250+
// shared seeded unit id is exactly where other tenants' rows sit.
3251+
this.businessUnitMemberScope({ business_unit_id: { $in: Array.from(seen) } }, organizationId),
3252+
`the members of business unit '${businessUnitId}' and its descendant units`
3253+
+ `${organizationId ? ` in organization '${organizationId}'` : ''}`,
3254+
);
32273255
}
32283256

32293257
/**
@@ -3445,8 +3473,8 @@ export class ApprovalService implements IApprovalService {
34453473
/**
34463474
* [#29362, #29503] The `user_id`s of every `object` row matching `where`,
34473475
* read to COMPLETION — or a refusal, never a shortened or an invented empty
3448-
* slate. The one read behind the membership tier, the position assignments
3449-
* and the team members.
3476+
* slate. The one read behind the membership tier, the position assignments,
3477+
* the team members and the business-unit members (#29606).
34503478
*
34513479
* Pages of {@link HOLDER_PAGE_ROWS} through the platform's one keyset walk
34523480
* (`keysetWalk`, `@objectstack/types`), ordered by `id`, so a group held past

0 commit comments

Comments
 (0)