Skip to content

Commit 12fb7d3

Browse files
committed
feat(spec): IOwnershipQueueService lets a caller ask for a refusal on a failed member read (onFailedRead)
ADR-0142 D2 (as amended) says each queue consumer declares at call time whether a failed member read answers nobody or refuses. expandMembers gains an optional onFailedRead beside purpose, isMember gains an optional trailing options argument with the same key, both typed OwnershipQueueFailedReadAnswer (nobody | refuse, default nobody). Contract only; the producer and the D6/D7 callers land with #29604. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzfHeHezsXgrF5MEs4N
1 parent 959c26b commit 12fb7d3

5 files changed

Lines changed: 158 additions & 3 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/spec': patch
3+
---
4+
5+
feat(spec): `IOwnershipQueueService` lets a caller ask for a refusal on a failed member read (`onFailedRead`), the call-time signal ADR-0142 D2 asks each consumer to send
6+
7+
Clause-②: yes (widening: an optional `onFailedRead` on `expandMembers`' options and an optional options argument on `isMember`; precedent PR #30015)
8+
Metadata-protocol: none
9+
10+
- **New type `OwnershipQueueFailedReadAnswer`** (`'nobody' | 'refuse'`, `@objectstack/spec/contracts`): what a membership read answers when a read behind the queue fails (`sys_queue`, `sys_queue_member`, `sys_team_member`, `sys_user_position`, `sys_member` through the position transition limb, the business-unit membership and tree).
11+
- **`expandMembers(name, organizationId, { purpose?, onFailedRead? })`** and **`isMember(userId, name, organizationId, { onFailedRead? })`**. `'nobody'` is the default and the answer every caller had before: a failed read is logged at `warn` and contributes nobody. Under `'refuse'` a failed read rejects with a failure that names the read, never `[]`, a partial set or `false`; an empty queue is still `[]`. The docblock names who takes which: the access path (D3), the claim admission (D4) and the assignment pool (D5) take `'nobody'`; the approver slate (D6) and the sharing-recipient grant recompute (D7) take `'refuse'`. The key is independent of `purpose`.
12+
- **Contract only.** Every existing call and implementation compiles unchanged and behaves as today; the producer in `@objectstack/plugin-sharing` and the D6/D7 callers that pass `'refuse'` land with #29604.

‎packages/spec/api-surface/contracts.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@
241241
"OWNERSHIP_QUEUE_SERVICE (const)",
242242
"ObjectDraft (interface)",
243243
"OwnershipFloorAlternate (interface)",
244+
"OwnershipQueueFailedReadAnswer (type)",
244245
"PRINCIPAL_SESSION_MAX_TTL_SECONDS (const)",
245246
"PendingActionRow (interface)",
246247
"PendingActionStatus (type)",

‎packages/spec/export-origins/contracts.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@
241241
"OWNERSHIP_QUEUE_SERVICE": "src/contracts/ownership-queue-service.ts#OWNERSHIP_QUEUE_SERVICE (const)",
242242
"ObjectDraft": "src/contracts/external-datasource-service.ts#ObjectDraft (interface)",
243243
"OwnershipFloorAlternate": "src/contracts/security-service.ts#OwnershipFloorAlternate (interface)",
244+
"OwnershipQueueFailedReadAnswer": "src/contracts/ownership-queue-service.ts#OwnershipQueueFailedReadAnswer (type)",
244245
"PRINCIPAL_SESSION_MAX_TTL_SECONDS": "src/contracts/auth-service.ts#PRINCIPAL_SESSION_MAX_TTL_SECONDS (const)",
245246
"PendingActionRow": "src/contracts/ai-service.ts#PendingActionRow (interface)",
246247
"PendingActionStatus": "src/contracts/ai-service.ts#PendingActionStatus (type)",
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [#30251] `onFailedRead` on {@link IOwnershipQueueService}: the call-time
5+
* signal ADR-0142 D2 (as amended) asks each consumer to send, so a recompute
6+
* consumer reached only through this contract (the D6 approver slate in
7+
* `@objectstack/plugin-approvals`) can ask for a refusal on a failed read.
8+
*
9+
* Pinned at the type level, under `check:test-typecheck` (this file compiles
10+
* under `tsconfig.test.json`):
11+
*
12+
* 1. **A widening, not a narrowing.** A call with no options, and the
13+
* three-argument `isMember` call, compile exactly as before; so does an
14+
* implementation written before the key existed.
15+
* 2. **Both members read one value type.** `expandMembers`' and `isMember`'s
16+
* `onFailedRead` are both {@link OwnershipQueueFailedReadAnswer}, which is
17+
* exactly `'nobody' | 'refuse'`; an unknown value does not compile.
18+
* 3. **Independent of `purpose`.** The two keys sit side by side; neither
19+
* value set leaks into the other.
20+
*
21+
* ⛔ Not pinned: what any implementation DOES under `'refuse'` — that is the
22+
* producer half (#29604, `@objectstack/plugin-sharing`).
23+
*/
24+
25+
import { describe, it, expect } from 'vitest';
26+
27+
import type {
28+
IOwnershipQueueService,
29+
OwnershipQueueFailedReadAnswer,
30+
QueueExpansionPurpose,
31+
} from './ownership-queue-service';
32+
33+
/** Type-level identity: true iff A and B are the same type. */
34+
type Eq<A, B> = (<T>() => T extends A ? 1 : 2) extends (<T>() => T extends B ? 1 : 2) ? true : false;
35+
/** Compile error when the argument is not `true`. */
36+
type Assert<T extends true> = T;
37+
38+
type ExpandOptions = NonNullable<Parameters<IOwnershipQueueService['expandMembers']>[2]>;
39+
type IsMemberOptions = NonNullable<Parameters<IOwnershipQueueService['isMember']>[3]>;
40+
41+
export type _AnswerIsExactlyTwoValues = Assert<Eq<OwnershipQueueFailedReadAnswer, 'nobody' | 'refuse'>>;
42+
export type _ExpandReadsTheAnswerType = Assert<Eq<ExpandOptions['onFailedRead'], OwnershipQueueFailedReadAnswer | undefined>>;
43+
export type _IsMemberReadsTheAnswerType = Assert<Eq<IsMemberOptions['onFailedRead'], OwnershipQueueFailedReadAnswer | undefined>>;
44+
export type _PurposeUnchanged = Assert<Eq<ExpandOptions['purpose'], QueueExpansionPurpose | undefined>>;
45+
export type _ExpandOptionKeys = Assert<Eq<keyof ExpandOptions, 'purpose' | 'onFailedRead'>>;
46+
export type _IsMemberOptionKeys = Assert<Eq<keyof IsMemberOptions, 'onFailedRead'>>;
47+
/** The axes stay apart: no failed-read answer is a purpose, and no purpose is a failed-read answer. */
48+
export type _AxesDisjoint = Assert<Eq<Extract<OwnershipQueueFailedReadAnswer, QueueExpansionPurpose>, never>>;
49+
50+
/** An implementation written before the key existed still satisfies the contract (method bivariance on an optional trailing argument). */
51+
const legacy: IOwnershipQueueService = {
52+
resolveQueue: async () => null,
53+
expandMembers: async (_name: string, _org: string | null, _options?: { purpose?: QueueExpansionPurpose }) => [],
54+
isMember: async (_user: string, _name: string, _org: string | null) => false,
55+
queuesOf: async () => [],
56+
};
57+
58+
/** Every call shape the card's acceptance names; the unknown values must NOT compile. */
59+
async function callShapes(svc: IOwnershipQueueService): Promise<unknown[]> {
60+
return [
61+
await svc.expandMembers('q', 'org_a'),
62+
await svc.expandMembers('q', null, {}),
63+
await svc.expandMembers('q', 'org_a', { purpose: 'addressing' }),
64+
await svc.expandMembers('q', 'org_a', { onFailedRead: 'refuse' }),
65+
await svc.expandMembers('q', 'org_a', { purpose: 'addressing', onFailedRead: 'refuse' }),
66+
await svc.expandMembers('q', 'org_a', { onFailedRead: 'nobody' }),
67+
await svc.isMember('u', 'q', 'org_a'),
68+
await svc.isMember('u', 'q', 'org_a', { onFailedRead: 'refuse' }),
69+
// @ts-expect-error — not a failed-read answer
70+
await svc.expandMembers('q', 'org_a', { onFailedRead: 'throw' }),
71+
// @ts-expect-error — not a failed-read answer
72+
await svc.isMember('u', 'q', 'org_a', { onFailedRead: 'empty' }),
73+
// @ts-expect-error — `purpose` is the other axis, and `isMember` does not take it
74+
await svc.isMember('u', 'q', 'org_a', { purpose: 'addressing' }),
75+
// @ts-expect-error — a purpose value is not a failed-read answer
76+
await svc.expandMembers('q', 'org_a', { onFailedRead: 'addressing' }),
77+
];
78+
}
79+
80+
describe('IOwnershipQueueService onFailedRead (#30251)', () => {
81+
it('every call shape compiles against an implementation written before the key, and answers as it did', async () => {
82+
expect(await callShapes(legacy)).toEqual([[], [], [], [], [], [], false, false, [], false, false, []]);
83+
});
84+
});

‎packages/spec/src/contracts/ownership-queue-service.ts‎

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
* answers `[]`. Each consumer says what it does with that (ADR-0142 D5, D6,
3636
* D7) — and every queue-dependent ADMISSION fails closed when the service is
3737
* not registered at all.
38+
*
39+
* A read that FAILS is not absence. What the expander answers then is the
40+
* caller's to say, per call — see {@link OwnershipQueueFailedReadAnswer}.
3841
*/
3942

4043
import type { QueueMemberType } from '../security/queue.zod.js';
@@ -45,6 +48,40 @@ export const OWNERSHIP_QUEUE_SERVICE = 'ownership-queue';
4548
/** Which reader an expansion is for — see {@link IOwnershipQueueService.expandMembers}. */
4649
export type QueueExpansionPurpose = 'access' | 'addressing';
4750

51+
/**
52+
* What a membership read answers when a read behind the queue FAILS — the
53+
* `onFailedRead` option of {@link IOwnershipQueueService.expandMembers} and
54+
* {@link IOwnershipQueueService.isMember} (ADR-0142, D2 "Membership", the
55+
* amended paragraph "An empty expansion is a fact; a failed read is a fault").
56+
*
57+
* The tables behind a queue are its own row (`sys_queue`, through which an
58+
* authored queue resolves), its member rows (`sys_queue_member`), and the
59+
* member tables a specification reads: `sys_team_member`, `sys_user_position`,
60+
* `sys_member` (through the position transition limb), and the business-unit
61+
* membership and tree. A table the composition does not carry is absence, not
62+
* failure.
63+
*
64+
* - `'nobody'` — the default and the answer every caller had before the key
65+
* existed. A failed read is logged at `warn`, and what sat behind it
66+
* contributes nobody. The admission consumers take it, because for them
67+
* nobody denies: the sitting-record access path (D3), the claim admission
68+
* (D4) and the assignment pool (D5).
69+
* - `'refuse'` — a failed read rejects the call with a failure that names the
70+
* read, never `[]`, a partial set or `false`. The recompute consumers take
71+
* it, because they turn the member set into routed work or materialised
72+
* grants and "nobody" there revokes: the approver slate (D6) and the
73+
* sharing-recipient grant recompute (D7).
74+
*
75+
* Under either answer an EMPTY queue — every read succeeded and reached
76+
* nobody — is still `[]`, and a name that resolves nowhere is still `[]` /
77+
* `false`: those are facts, not faults.
78+
*
79+
* ⛔ An axis independent of {@link QueueExpansionPurpose}: which holders an
80+
* answer keeps and whether a failed read refuses are two questions, and one
81+
* value never answers both.
82+
*/
83+
export type OwnershipQueueFailedReadAnswer = 'nobody' | 'refuse';
84+
4885
/** One member specification: a recipient kind and the value that kind takes in a sharing rule. */
4986
export interface QueueMemberSpec {
5087
type: QueueMemberType;
@@ -92,15 +129,35 @@ export interface IOwnershipQueueService {
92129
* off — the sitting-record path, the claim, the assignment pool and the
93130
* sharing recipient all confer access. `'addressing'` keeps them — the
94131
* approver slate routes work, and dropping holders there is fail-open.
132+
*
133+
* `onFailedRead` says what the call is owed when a read behind the queue
134+
* fails: `'nobody'`, the default, or `'refuse'`, under which the call
135+
* rejects with a failure naming the read. An empty queue is still `[]`.
136+
* See {@link OwnershipQueueFailedReadAnswer} for the tables and for which
137+
* ADR-0142 consumer takes which answer; it is independent of `purpose`.
95138
*/
96139
expandMembers(
97140
name: string,
98141
organizationId: string | null,
99-
options?: { purpose?: QueueExpansionPurpose },
142+
options?: { purpose?: QueueExpansionPurpose; onFailedRead?: OwnershipQueueFailedReadAnswer },
100143
): Promise<string[]>;
101144

102-
/** Is `userId` a member of the queue named `name` in `organizationId`? `false` when the name resolves nowhere. */
103-
isMember(userId: string, name: string, organizationId: string | null): Promise<boolean>;
145+
/**
146+
* Is `userId` a member of the queue named `name` in `organizationId`?
147+
* `false` when the name resolves nowhere.
148+
*
149+
* `onFailedRead` is {@link expandMembers}' key with the same meaning:
150+
* under `'nobody'`, the default, a failed read counts as not reaching
151+
* `userId`; under `'refuse'`, `false` is answered only when every read
152+
* behind it succeeded, and a failed read rejects with a failure naming it.
153+
* The options argument is optional, so a three-argument call is today's.
154+
*/
155+
isMember(
156+
userId: string,
157+
name: string,
158+
organizationId: string | null,
159+
options?: { onFailedRead?: OwnershipQueueFailedReadAnswer },
160+
): Promise<boolean>;
104161

105162
/**
106163
* The machine names of every queue `userId` is a member of in

0 commit comments

Comments
 (0)