From 910f941936629d7586ec6e7bdd6d882478be63b8 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 21:45:19 +0000 Subject: [PATCH 1/4] fix(rest): the dataset door judges a holder whose own address is contended instead of answering 503 (ADR-0150 D4) A row two or more holders of a dataset name could own (a package-less row, or an App pair's undeclared row in the registry's bare slot) makes each holder's own exact read refuse `ambiguous-in-closure`, naming itself among the holders. The admission arm read that as "cannot be judged" and the door answered 503 for every caller. Such a holder is now judged on its own item as the list scoped to it serves it, never picked, and named in the 409 when the caller is admitted to it. Also: one exported package-scoped refusal recogniser for the door and the rule; the undetermined 503 carries its cause for the operator's log. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_016WV4cz4f7zEQZ2C9GTG382 --- .../src/analytics-dataset-admission-order.ts | 156 ++++++++++++++---- packages/rest/src/analytics-routes.ts | 49 ++++-- 2 files changed, 158 insertions(+), 47 deletions(-) diff --git a/packages/rest/src/analytics-dataset-admission-order.ts b/packages/rest/src/analytics-dataset-admission-order.ts index 05e9c422e0c..db4bfe6a692 100644 --- a/packages/rest/src/analytics-dataset-admission-order.ts +++ b/packages/rest/src/analytics-dataset-admission-order.ts @@ -22,8 +22,23 @@ import { stripReadDecorations } from '@objectstack/spec/kernel'; * answers, and otherwise the `409` names only the admitted holders; * - a holder whose admission could not be judged may be one the caller can * query: whenever it could change the answer, nothing runs (`503`). That - * includes a holder whose own exact-qualifier read refuses: its refusal is - * kept inside this arm and never answered. + * includes a holder whose own exact-qualifier read refuses in any other + * shape than the one below: its refusal is kept inside this arm and never + * answered. The `503` carries, on `cause` (the operator's log, never the + * body), which holders could not be judged and why. + * + * [#32948, ADR-0150 D4] A holder whose own address is CONTENDED is judged, not + * left undetermined. A row two or more holders of the name could own (a + * package-less row, or an App pair's row that no module's address declares, + * epic ruling on #31699 F2) is no one holder's customization, so each such + * holder's own exact read refuses `ambiguous-in-closure` naming the holders, + * itself among them ({@link isOwnAddressContention}). Nothing can run at that + * address, so such a holder is never picked; the caller's admission to it is + * judged on the holder's own item as the list scoped to it serves it (that + * list withholds the row), as `query_dataset` judges every holder over the + * list. Admitted, it is named in the `409`; not admitted, it is not named. + * Before, every such holder was undetermined, and the door answered `503` for + * every caller where D4 asks for the refusal naming the holders. * * ⛔ Only the refusal arm (seat ruling 6817809380, Q1 = A). A name the read * RESOLVES keeps its answer: a caller not admitted to the one holder (or to the @@ -51,8 +66,12 @@ export type DatasetRefusalAdmission = | { readonly kind: 'read'; readonly read: { readonly item: unknown } } /** The refusal over the admitted holders only. */ | { readonly kind: 'refused'; readonly error: PackageScopedNameRefusedError } - /** Whether a holder is admitted could not be judged, and it could move the answer. */ - | { readonly kind: 'undetermined' }; + /** + * Whether a holder is admitted could not be judged, and it could move the + * answer. `cause` names each holder that could not be judged and why: the + * operator's text, logged with the `503`, ⛔ never put in its body. + */ + | { readonly kind: 'undetermined'; readonly cause: string }; /** The analytics service's admission face, read structurally (this package carries no analytics code). */ interface DatasetAdmissionService { @@ -70,17 +89,47 @@ function admissionServiceOf(svc: unknown): DatasetAdmissionService | undefined { } /** - * A package-scoped refusal by class OR by shape (`code` `RESOURCE_CONFLICT` with - * a `refusal` whose `status` is `'refused'`), whatever its reason: the door's - * `isPackageScopedRefusal` predicate, so a refusal from another copy of - * `@objectstack/core` is caught here too. + * [#32072] A package-scoped resolver's refusal, by class or by shape: `code` + * `RESOURCE_CONFLICT` with a `refusal` whose `status` is `'refused'`, whatever + * its reason. The same predicate the `/meta` dispatcher reads + * (`isPackageScopedRefusal` in `@objectstack/runtime`'s `domains/meta.ts`), so + * one refusal is a `409` at both doors whichever copy of the class threw it. + * [#32826] The ONE copy in this package: the door's by-name read and this + * arm's per-holder reads both ask it. */ -function isRefusal(e: unknown): boolean { +export function isPackageScopedRefusal(e: unknown): e is { code: 'RESOURCE_CONFLICT'; refusal: PackageScopedRefusal } { if (e instanceof PackageScopedNameRefusedError) return true; const thrown = e as { code?: unknown; refusal?: { status?: unknown } } | null | undefined; return thrown?.code === 'RESOURCE_CONFLICT' && thrown.refusal?.status === 'refused'; } +/** + * [#32948] Is `e` the refusal of `packageId`'s own exact address over a row + * two or more holders could own: `ambiguous-in-closure`, read AS that package + * (`callerPackageId`), naming only packages, that package among them? The + * exact read throws exactly this for a package-less row, and for an App pair's + * undeclared row, of a name two or more packages hold + * (`exactQualifierItem` in `@objectstack/metadata-protocol`). Any other refusal + * of a holder's own read stays undetermined. + */ +function isOwnAddressContention(e: unknown, packageId: string): boolean { + if (!isPackageScopedRefusal(e)) return false; + const { reason, callerPackageId, candidates } = e.refusal; + return reason === 'ambiguous-in-closure' + && callerPackageId === packageId + && candidates.length >= 2 + && candidates.every((c) => c.kind === 'package') + && candidates.some((c) => c.kind === 'package' && c.packageId === packageId); +} + +/** + * The ambiguity reasons: the core vocabulary's whole ambiguity class, so an + * ambiguity is never read as a non-ambiguity. [#32826] `ambiguous-in-namespace` + * cannot reach this door today: only a read that names a namespace + * (`/meta/:type/:ns/:name`) is refused with it, and the dataset doors name a + * package or none. It is listed so that a refusal carrying it would be judged + * as the ambiguity it is, never as `outside-closure` is. + */ const AMBIGUITY: ReadonlySet = new Set([ 'ambiguous-in-environment', 'ambiguous-in-closure', @@ -89,18 +138,22 @@ const AMBIGUITY: ReadonlySet = new Set([ /** * Judge `refusal`'s holders for the caller in `context`. `readHolder` is the - * door's exact-qualifier read of one holder. A refusal it throws, of any - * reason and by class or by shape, leaves that holder undetermined; any other - * throw is a failed read, which the door answers as it answers any (`503`), so - * it is left to throw. + * door's exact-qualifier read of one holder. A refusal it throws, by class or + * by shape, leaves that holder undetermined, unless it is that holder's own + * address contended ({@link isOwnAddressContention}): that holder is then + * judged on `listHolder`'s answer, the holder's own item as the list scoped to + * it serves it, and is never picked. Any other throw is a failed read, which + * the door answers as it answers any (`503`), so it is left to throw. */ export async function admitRefusedDatasetHolders(args: { readonly refusal: PackageScopedRefusal; readonly svc: unknown; readonly context: unknown; readonly readHolder: (packageId: string) => Promise<{ item?: unknown } | null | undefined>; + /** The holder's own item of the name in the list scoped to it, `undefined` when it lists none. */ + readonly listHolder?: (packageId: string) => Promise; }): Promise { - const { refusal, context, readHolder } = args; + const { refusal, context, readHolder, listHolder } = args; const service = admissionServiceOf(args.svc); if (!service) return { kind: 'rethrow' }; const packageIds: string[] = []; @@ -112,20 +165,51 @@ export async function admitRefusedDatasetHolders(args: { } const { DatasetSchema } = await import('@objectstack/spec/ui'); - const admitted: Array<{ packageId: string; read: { item: unknown } }> = []; - let unresolved = false; + // `read` absent: a contended holder, admitted on its own listed item, which + // is named but never run. + const admitted: Array<{ packageId: string; read?: { item: unknown } }> = []; + // [#32826] Each holder that could not be judged, and why: the `503`'s cause. + const unjudged: string[] = []; + /** Judge one holder on `item`; `read` is what runs when it is picked. */ + const judge = async (packageId: string, item: unknown, runnable: boolean): Promise => { + const parsed = (DatasetSchema as { safeParse(v: unknown): { success: boolean; data?: unknown } }) + .safeParse(stripReadDecorations(item)); + if (!parsed.success) return; + const admission = await service.admitDatasetCatalogEntry(parsed.data, context); + if (admission.admitted) admitted.push({ packageId, ...(runnable ? { read: { item } } : {}) }); + else if (admission.unresolved) unjudged.push(`package "${packageId}": its admission could not be resolved`); + }; for (const packageId of packageIds) { let read: { item?: unknown } | null | undefined; try { read = await readHolder(packageId); } catch (readError) { - // The holder's own read refused its address: which item would run + // [#32948] The holder's own address is contended by a row no one + // holder owns (ADR-0150 D4): nothing runs there, and the holder is + // judged on its own listed item. The read's refusal never leaves + // this arm. + if (isOwnAddressContention(readError, packageId) && listHolder) { + let listed: unknown; + try { + listed = await listHolder(packageId); + } catch (listError) { + if (!isPackageScopedRefusal(listError)) throw listError; + listed = undefined; + } + if (listed !== undefined && listed !== null) { + await judge(packageId, listed, false); + continue; + } + unjudged.push(`package "${packageId}": its own address is contended and the list scoped to it serves no item of the name`); + continue; + } + // Any other refusal of the holder's own read: which item would run // there is not known, so neither is the caller's admission to it. // Undetermined, and the read's own refusal (its candidates // included) never leaves this arm. Any other throw is a failed // read, answered `503` by the door. - if (isRefusal(readError)) { - unresolved = true; + if (isPackageScopedRefusal(readError)) { + unjudged.push(`package "${packageId}": its own exact read refused (${readError.refusal.reason})`); continue; } throw readError; @@ -133,25 +217,24 @@ export async function admitRefusedDatasetHolders(args: { const item = read?.item; // The holder's own address serving nothing is no fact about the caller. if (item === undefined || item === null) { - unresolved = true; + unjudged.push(`package "${packageId}": its own exact read serves nothing`); continue; } - const parsed = (DatasetSchema as { safeParse(v: unknown): { success: boolean; data?: unknown } }) - .safeParse(stripReadDecorations(item)); - if (!parsed.success) continue; - const admission = await service.admitDatasetCatalogEntry(parsed.data, context); - if (admission.admitted) admitted.push({ packageId, read: { item } }); - else if (admission.unresolved) unresolved = true; + await judge(packageId, item, true); } const ambiguity = AMBIGUITY.has(refusal.reason); + const picked = ambiguity && admitted.length === 1 ? admitted[0].read : undefined; // An unjudged holder could be admitted: it moves "none" to "one" (or to a - // refusal), and for an ambiguity "one" to a refusal. - if (unresolved && (admitted.length === 0 || (ambiguity && admitted.length === 1))) { - return { kind: 'undetermined' }; + // refusal), and for an ambiguity a picked "one" to a refusal. + if (unjudged.length > 0 && (admitted.length === 0 || picked !== undefined)) { + return { + kind: 'undetermined', + cause: `The dataset "${refusal.name}" (${refusal.reason}) has holders whose admission could not be judged: ${unjudged.join('; ')}.`, + }; } if (admitted.length === 0) return { kind: 'not-found' }; - if (ambiguity && admitted.length === 1) return { kind: 'read', read: admitted[0].read }; + if (picked !== undefined) return { kind: 'read', read: picked }; const narrowed = { status: 'refused' as const, reason: refusal.reason, @@ -162,9 +245,18 @@ export async function admitRefusedDatasetHolders(args: { (c) => c.kind === 'package' && admitted.some((a) => a.packageId === c.packageId), ), }; + // [#32948] An ambiguity narrowed to one holder is that holder's contended + // address (a runnable one would have been picked above): the vocabulary's + // ambiguity sentence counts holders and tells the caller to address one, + // which is no remedy here, so the sentence says what stands in the way. + const [only] = narrowed.candidates; + const message = ambiguity && narrowed.candidates.length === 1 && only?.kind === 'package' + ? `The dataset "${refusal.name}" is held by package "${only.packageId}", and a row of the name that no one ` + + 'package owns stands beside its item, so nothing can be read at its address until that row is saved ' + + 'under one package (ADR-0150 D4).' + : packageScopedRefusalMessage(narrowed); return { kind: 'refused', - error: new PackageScopedNameRefusedError({ ...narrowed, message: packageScopedRefusalMessage(narrowed) }), + error: new PackageScopedNameRefusedError({ ...narrowed, message }), }; } - diff --git a/packages/rest/src/analytics-routes.ts b/packages/rest/src/analytics-routes.ts index 662e822c455..9a0b0ff2f09 100644 --- a/packages/rest/src/analytics-routes.ts +++ b/packages/rest/src/analytics-routes.ts @@ -82,7 +82,7 @@ import { logError } from './log.js'; import { refuseRepeatedQueryParams } from './query-multiplicity.js'; import { mayReadPendingDrafts, metaItemPackageBinding, type RestServer } from './rest-server.js'; import { metaCallerPackageQuery, metaItemCallerPackageRefusalMessage } from './meta-item-read-gate.js'; -import { admitRefusedDatasetHolders } from './analytics-dataset-admission-order.js'; +import { admitRefusedDatasetHolders, isPackageScopedRefusal } from './analytics-dataset-admission-order.js'; /** * The `RestServer` members {@link registerAnalyticsEndpoints} reads — every @@ -236,19 +236,6 @@ export function registerAnalyticsEndpoints(this: AnalyticsRouteHost, basePath: s }); } -/** - * [#32072] A package-scoped resolver's refusal, by class or by shape: `code` - * `RESOURCE_CONFLICT` with a `refusal` whose `status` is `'refused'`. The same - * predicate the `/meta` dispatcher reads (`isPackageScopedRefusal` in - * `@objectstack/runtime`'s `domains/meta.ts`), so one refusal is a 409 at both - * doors whichever copy of the class threw it. - */ -function isPackageScopedRefusal(e: unknown): e is { code: 'RESOURCE_CONFLICT'; refusal: PackageScopedNameRefusedError['refusal'] } { - if (e instanceof PackageScopedNameRefusedError) return true; - const thrown = e as { code?: unknown; refusal?: { status?: unknown } } | null | undefined; - return thrown?.code === 'RESOURCE_CONFLICT' && thrown.refusal?.status === 'refused'; -} - // ───────────────────────────────────────────────────────────────────────────── // [#32200] One body's judgment, shared by the single door and the batch door // ───────────────────────────────────────────────────────────────────────────── @@ -688,6 +675,35 @@ async function answerDatasetQuery( svc, context, readHolder: (holder) => readOne({ ...baseRequest, packageId: holder }), + // [#32948] A holder whose own address is contended (ADR-0150 + // D4) is judged on its own item as the list scoped to it + // serves it: that list withholds the row no one holder owns. + // A list that FAILED is a failed read, answered `503` as + // `readOne` answers one; a protocol with no list read leaves + // the holder undetermined. + listHolder: async (holder) => { + if (typeof p?.getMetaItems !== 'function') return undefined; + let listed: any; + try { + listed = await p.getMetaItems({ + type: 'dataset', packageId: holder, names: [body.datasetName], + ...(previewDrafts ? { previewDrafts } : {}), + }); + } catch (listError) { + if (isPackageScopedRefusal(listError)) throw listError; + throw Object.assign( + new Error( + `The dataset "${body.datasetName}" could not be resolved: the dataset read failed. ` + + 'This is a server-side fault, not a missing dataset.', + ), + { code: 'SERVICE_UNAVAILABLE', status: 503, refusal: true, cause: listError }, + ); + } + const items: unknown[] = Array.isArray(listed) ? listed : Array.isArray(listed?.items) ? listed.items : []; + // Only the holder's own item: one the list serves under + // another package is not this holder's. + return items.find((it: any) => it?.name === body.datasetName && it?._packageId === holder); + }, }); if (judged.kind === 'rethrow') throw refused; if (judged.kind === 'refused') throw judged.error; @@ -698,7 +714,10 @@ async function answerDatasetQuery( `Read access to the dataset "${body.datasetName}" could not be determined, so the query was not run. ` + 'This is a server-side fault, not a permission denial.', ), - { code: 'SERVICE_UNAVAILABLE', status: 503, refusal: true }, + // [#32826] Which holders could not be judged, and why: + // on `cause`, so the door's `logError` prints it for the + // operator; the body keeps the sentence above only. + { code: 'SERVICE_UNAVAILABLE', status: 503, refusal: true, cause: new Error(judged.cause) }, ); } read = judged.read; From 85a5bac5b5e124710c9634c32694f35e412c0e88 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 21:48:03 +0000 Subject: [PATCH 2/4] test(rest): pin the contended-holder judgement and the 503's logged cause; docs and changeset Real-arrangement pins over the registry and protocol: an App pair row no module owns, both orders, bare read, a module's ?package= and ?callerPackage=, single door and batch; CONTROLs for a package-less row (declined, unchanged) and for one holder (unchanged). The analytics page says what the door answers for such rows and that the 503 logs its cause. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_016WV4cz4f7zEQZ2C9GTG382 --- .../32948-dataset-door-contended-holder.md | 19 +++ content/docs/data-modeling/analytics.mdx | 16 ++- packages/rest/src/analytics-routes.test.ts | 121 +++++++++++++++++- 3 files changed, 153 insertions(+), 3 deletions(-) create mode 100644 .changeset/32948-dataset-door-contended-holder.md diff --git a/.changeset/32948-dataset-door-contended-holder.md b/.changeset/32948-dataset-door-contended-holder.md new file mode 100644 index 00000000000..916b733eb08 --- /dev/null +++ b/.changeset/32948-dataset-door-contended-holder.md @@ -0,0 +1,19 @@ +--- +"@objectstack/rest": patch +--- + +`POST /analytics/dataset/query` (and each query of `POST /analytics/dataset/query/batch`), under the analytics service's plugin-wired admission: a holder whose own address is contended by a stored row two or more holders of the name could own (ADR-0150 D4) is now judged on its own dataset instead of being left undetermined. Such a row makes each of those holders' own exact read refuse the name, naming them; the door now reads each such holder's own dataset as the list scoped to it serves it (that list withholds the row), asks admission about it, names it in the `409` when the caller may query it, and never runs it. + +Clause-②: yes (widening) +Metadata-protocol: none + +Moved answers, when the name is refused (bare name, `?callerPackage=`, or `?package=` naming a contended holder) and its holders' own addresses are contended: + +- admitted to two or more holders: `503 SERVICE_UNAVAILABLE` → `409 RESOURCE_CONFLICT` naming those holders; +- admitted to exactly one contended holder: `503` → `409` naming that holder only, nothing run; +- admitted to none: `503` → `404 NOT_FOUND`, byte-equal to the answer for a name nothing holds; +- admitted to exactly one holder whose address is not contended, every other holder contended and not admitted: `503` → `200`, that holder's dataset runs (the rule for one admitted holder of an ambiguity, now reached). + +The stored row this arises from today is an App's customization-pair row that names none of the App's modules. A row bound to no package is declined at each holder's address for a dataset, so it moves no answer, before or after. + +Also: the `503` the door still answers where a holder cannot be judged carries, on its logged cause, which holders could not be judged and why; its body is unchanged and names no holder. Unchanged: every refusal of a holder's own read in any other shape stays undetermined; a name the read resolves keeps its answer. No fix needed from callers. diff --git a/content/docs/data-modeling/analytics.mdx b/content/docs/data-modeling/analytics.mdx index 8962b2eb99a..cd60c3d75df 100644 --- a/content/docs/data-modeling/analytics.mdx +++ b/content/docs/data-modeling/analytics.mdx @@ -303,11 +303,23 @@ With none left, the answer is the `404` a missing name gets. Where two or more holders were in contention and exactly one is left, that one runs. Otherwise the `409` names only the holders left. If whether the caller may query a holder cannot be judged, and it could change the answer, the route answers `503` and -runs nothing. A service built by hand, whose admission passes every caller, is -not asked, so its refusal names every holder. A name that resolves to one +runs nothing; the server log says which holders could not be judged and why. +Where some holders cannot be judged and the answer is a `409` anyway, that +`409` names only the holders that could be judged. A service built by hand, +whose admission passes every caller, is not asked, so its refusal names every +holder. A name that resolves to one dataset is unchanged: a caller who may not query it is refused by the query itself (`403`). +A stored row of the name that two or more holders could own is no one holder's +customization (ADR-0150 D4). A row bound to no package is declined at each +holder's address for a dataset, so it changes no answer: the name is judged as +if the row were not there. An App's customization-pair row that names none of +the App's modules makes each module's own address refuse the name until the row +is saved under one package. Such a module never runs, and it is judged on its +own dataset: the `409` names it when the caller may query it, and a caller who +may query none of the holders gets the `404`. + To run several queries in one request, as a dashboard render does, send them to `POST {basePath}/analytics/dataset/query/batch` as `{ queries: [...] }`, each entry a body the single route takes (at most 50). Each query is judged diff --git a/packages/rest/src/analytics-routes.test.ts b/packages/rest/src/analytics-routes.test.ts index ba1386802a6..b9af72c942a 100644 --- a/packages/rest/src/analytics-routes.test.ts +++ b/packages/rest/src/analytics-routes.test.ts @@ -874,6 +874,92 @@ describe('#32501 — the dataset doors at an exact pair address read the package boot(order, true); await judgedOverAdmission({ callerPackage: `${P}.custom` }, '?callerPackage= the App pair, installed'); }); + + // ── [#32948, ADR-0150 D4] a row no one module owns, beside the App's two modules ── + // A row of the name that either module could own is no one holder's + // customization, so each module's own exact read refuses it naming both + // (`ambiguous-in-closure`, read as that module). The admission arm read that + // refusal as "cannot be judged", so every refusal of the name answered 503 + // for every caller. Now a module whose own address is contended is judged on + // its own item as the list scoped to it serves it: named in the 409 when the + // caller is admitted to it, never run, and not named otherwise. + // + // Staged with the registry's own `registerItem`: the App pair's row that no + // module's address declares, hydrated into the bare slot (the registry binds + // it to no package). A package-less row (`_provenance: 'org'`, or stamped + // `sys_metadata`) is declined at each module's address for a dataset (epic + // ruling 6817768147), so it contends nothing; the CONTROL below holds that. + // + // BASE (`main` ba35dfd78): 503 SERVICE_UNAVAILABLE for every caller, in both + // orders, on the bare read and at a module's own `?package=`, single door and + // batch alike; nothing named, nothing run. + const contendingRow = () => registry.registerItem('dataset', { + name: 'sales', label: 'pair sales', object: 'pair_item', _packageId: `${P}.custom`, _provenance: 'org', + dimensions: [{ name: 'region', field: 'region', type: 'string' }], + measures: [{ name: 'revenue', aggregate: 'sum', field: 'amount' }], + }, 'name' as never); + const judgedOverContention = async (query: Record, what: string) => { + refusedNamingModules(await both(query, admitting(['one_item', 'two_item'])), `${what}, admitted to both`); + for (const [admitted, shown, hidden] of [['one_item', M1, M2], ['two_item', M2, M1]] as const) { + const answer = await both(query, admitting([admitted])); + const where = `${what}, admitted to ${admitted} only`; + // Never run: the module's own address is contended, so nothing is picked. + expect([answer.single.status, answer.single.code, answer.single.ran], where).toEqual([409, 'RESOURCE_CONFLICT', []]); + expect([answer.batch.status, answer.batch.entry, answer.batch.code, answer.batch.ran], where).toEqual([200, 409, 'RESOURCE_CONFLICT', []]); + expect(answer.single.message, where).toContain(`package "${shown}"`); + expect(answer.batch.message, where).toContain(`package "${shown}"`); + expect(answer.single.text, where).not.toContain(hidden); + expect(answer.batch.text, where).not.toContain(hidden); + } + const none = await both(query, admitting([])); + const missing = await both(query, admitting([]), 'nowhere'); + expect([none.single.status, none.single.code, none.single.ran], `${what}, admitted to neither`).toEqual([404, 'NOT_FOUND', []]); + expect(none.single.text, `${what}, admitted to neither`).toBe(missing.single.text.replace(/nowhere/g, 'sales')); + expect([none.batch.status, none.batch.entry, none.batch.ran], `${what}, admitted to neither`).toEqual([200, 404, []]); + expect(none.batch.text, `${what}, admitted to neither`).toBe(missing.batch.text.replace(/nowhere/g, 'sales')); + }; + + it.each([['one first', [M1, M2]], ['two first', [M2, M1]]] as const)('[#32948] plugin-wired admission (%s): an App pair row no module owns contends both modules\' addresses, and the name refuses 409 naming the modules the caller is admitted to (BASE: 503 for every caller)', async (_order, order) => { + boot(order, true); + contendingRow(); + await judgedOverContention({}, 'the bare read'); + await judgedOverContention({ package: M1 }, '?package= a module'); + await judgedOverContention({ callerPackage: M2 }, '?callerPackage= a module'); + }); + + it.each([['alpha first', [A, M1, M2]], ['alpha last', [M2, M1, A]]] as const)('[#32948] plugin-wired admission (%s): beside the two contended modules, another package\'s holder the caller alone may query runs, and with a module admitted too the 409 names both (BASE: 503)', async (_order, order) => { + boot(order, true); + contendingRow(); + ran(await both({}, admitting(['alpha_item'])), 'alpha sales', 'admitted to alpha only'); + const two = await both({}, admitting(['alpha_item', 'one_item'])); + expect([two.single.status, two.single.code, two.single.ran]).toEqual([409, 'RESOURCE_CONFLICT', []]); + expect([two.batch.status, two.batch.entry, two.batch.ran]).toEqual([200, 409, []]); + for (const text of [two.single.message, two.batch.message]) { + expect(text).toContain(`package "${A}"`); + expect(text).toContain(`package "${M1}"`); + expect(text).not.toContain(M2); + } + }); + + it.each([['one first', [M1, M2]], ['two first', [M2, M1]]] as const)('[#32948] CONTROL (%s): a package-less row beside the two modules is declined at each module\'s address, so the App pair is judged over the modules as with no row, before and after', async (_order, order) => { + boot(order); + registry.registerItem('dataset', { + name: 'sales', label: 'row sales', object: 'row_item', _provenance: 'org', + dimensions: [{ name: 'region', field: 'region', type: 'string' }], + measures: [{ name: 'revenue', aggregate: 'sum', field: 'amount' }], + }, 'name' as never); + await judgedOverAdmission({ package: `${P}.custom` }, '?package= the App pair, a package-less row beside'); + }); + + it('[#32948] CONTROL — one module holds the name: the App pair row is that module\'s customization, served at its address and on the bare read; admission is not asked, before and after', async () => { + boot([M1], true); + contendingRow(); + for (const query of [{}, { package: M1 }]) { + const svc = admitting(['one_item', 'pair_item']); + ran(await both(query, svc), 'pair sales', JSON.stringify(query)); + expect(svc.admitDatasetCatalogEntry, JSON.stringify(query)).not.toHaveBeenCalled(); + } + }); }); // ── [#32292, ADR-0150 D3 after ADR-0149 D2] the refusal arm judges admission first ── @@ -938,7 +1024,11 @@ describe('[#32292] POST /analytics/dataset/query — a refused name is judged ov * package-less row of the name beside the holders no longer rigs this for a * dataset: a sealed type declines that row at every exact address (epic * ruling 6817768147), which serves the holder's own. So the refusal that row - * gave is thrown here, in the shape that read threw it. + * gave is thrown here, read as no address's own (`callerPackageId: null`). + * [#32948] The shape a real exact read throws over a row two holders could + * own (read AS the holder, naming it) is judged, not left undetermined: the + * `#32501` describe pins that over a real registry arrangement. This double + * pins every OTHER refusal of a holder's own read, which stays undetermined. */ const exactReadsRefuse = (...holders: string[]) => { const target = protocol; @@ -1082,6 +1172,35 @@ describe('[#32292] POST /analytics/dataset/query — a refused name is judged ov } }); + // [#32826] The operator reads why: the 503's cause, printed by the door's + // `logError`, names each holder that could not be judged and why; the body + // keeps its one sentence and names no holder. BASE (`main` ba35dfd78): the + // logged error carried no cause. + it('[#32826] the undetermined 503 logs which holders could not be judged and why, and its body names none', async () => { + ship('sales', A); + ship('sales', B); + exactReadsRefuse(B); + vi.stubEnv('OS_REST_LOG', 'error'); + const logged = vi.spyOn(console, 'error').mockImplementation(() => undefined); + try { + const svc = service({ unresolved: ['alpha_item'] }); + const answer = await send(svc); + expect([answer.status, answer.code], answer.text).toEqual([503, 'SERVICE_UNAVAILABLE']); + expect(answer.text).not.toContain(A); + expect(answer.text).not.toContain(B); + const error = logged.mock.calls.map((call) => call.find((arg) => arg instanceof Error)).find(Boolean) as Error | undefined; + expect((error as { code?: unknown } | undefined)?.code).toBe('SERVICE_UNAVAILABLE'); + const cause = String((error?.cause as Error | undefined)?.message ?? ''); + // Each unjudged holder by name, and the refusal's reason where a read refused. + expect(cause).toContain(`package "${A}"`); + expect(cause).toContain(`package "${B}"`); + expect(cause).toContain('ambiguous-in-closure'); + } finally { + logged.mockRestore(); + vi.unstubAllEnvs(); + } + }); + it('a name the read resolves keeps its answer: admission is not asked, and the one holder runs into queryDataset\'s own gates', async () => { ship('sales', A); const svc = service(); From cfc3b3dd39e1ac9e18a814cea88accc5cd9a644d Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 22:40:36 +0000 Subject: [PATCH 3/4] fix(rest): one-holder dataset 409 names no other holder; pin module-address widening The door's own sentence for an ambiguity narrowed to one admitted holder no longer counts holders or speaks of another package; pins assert the hidden holder is neither named nor implied (body keys, text, counts). The widening is pinned at ?package= and ?callerPackage= a module, both registration orders: the uncontended holder is not a candidate there and is never reached across to. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_016WV4cz4f7zEQZ2C9GTG382 --- .../src/analytics-dataset-admission-order.ts | 9 ++-- packages/rest/src/analytics-routes.test.ts | 47 +++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/packages/rest/src/analytics-dataset-admission-order.ts b/packages/rest/src/analytics-dataset-admission-order.ts index db4bfe6a692..70c9ba8049c 100644 --- a/packages/rest/src/analytics-dataset-admission-order.ts +++ b/packages/rest/src/analytics-dataset-admission-order.ts @@ -249,11 +249,14 @@ export async function admitRefusedDatasetHolders(args: { // address (a runnable one would have been picked above): the vocabulary's // ambiguity sentence counts holders and tells the caller to address one, // which is no remedy here, so the sentence says what stands in the way. + // ⛔ It speaks of that one package and the row only: a holder the caller + // may not query is hidden, so nothing here says or counts that another + // holder exists (no plural, no "other", no "no one package"). const [only] = narrowed.candidates; const message = ambiguity && narrowed.candidates.length === 1 && only?.kind === 'package' - ? `The dataset "${refusal.name}" is held by package "${only.packageId}", and a row of the name that no one ` - + 'package owns stands beside its item, so nothing can be read at its address until that row is saved ' - + 'under one package (ADR-0150 D4).' + ? `The dataset "${refusal.name}" cannot be read at package "${only.packageId}": a stored row of the name ` + + 'stands beside that package\'s item and is not saved under it, so nothing is run until the row is ' + + 'saved under a package (ADR-0150 D4).' : packageScopedRefusalMessage(narrowed); return { kind: 'refused', diff --git a/packages/rest/src/analytics-routes.test.ts b/packages/rest/src/analytics-routes.test.ts index b9af72c942a..e036e090871 100644 --- a/packages/rest/src/analytics-routes.test.ts +++ b/packages/rest/src/analytics-routes.test.ts @@ -898,6 +898,23 @@ describe('#32501 — the dataset doors at an exact pair address read the package dimensions: [{ name: 'region', field: 'region', type: 'string' }], measures: [{ name: 'revenue', aggregate: 'sum', field: 'amount' }], }, 'name' as never); + /** + * A 409 narrowed to the one module the caller may query neither names nor + * implies the hidden one: the refusal carries its code and its sentence and + * nothing else (no candidates, no reason, no details), and the sentence + * counts no holders and speaks of no other, both, each or "no one" package. + */ + const hiddenHolderNotImplied = (answer: Awaited>, where: string) => { + const single = JSON.parse(answer.single.text); + const entry = JSON.parse(answer.batch.text); + expect(Object.keys(single).sort(), where).toEqual(['code', 'message']); + expect(Object.keys(entry).sort(), where).toEqual(['error', 'status']); + expect(Object.keys(entry.error).sort(), where).toEqual(['code', 'message']); + for (const message of [answer.single.message, answer.batch.message]) { + expect(message, where).not.toMatch(/\b\d+\s+(packages?|holders?)\b/i); + expect(message, where).not.toMatch(/\b(packages|holders|other|another|both|each|either|no one|ambiguous|picks?)\b/i); + } + }; const judgedOverContention = async (query: Record, what: string) => { refusedNamingModules(await both(query, admitting(['one_item', 'two_item'])), `${what}, admitted to both`); for (const [admitted, shown, hidden] of [['one_item', M1, M2], ['two_item', M2, M1]] as const) { @@ -910,6 +927,7 @@ describe('#32501 — the dataset doors at an exact pair address read the package expect(answer.batch.message, where).toContain(`package "${shown}"`); expect(answer.single.text, where).not.toContain(hidden); expect(answer.batch.text, where).not.toContain(hidden); + hiddenHolderNotImplied(answer, where); } const none = await both(query, admitting([])); const missing = await both(query, admitting([]), 'nowhere'); @@ -941,6 +959,35 @@ describe('#32501 — the dataset doors at an exact pair address read the package } }); + // At a module's own address the uncontended holder is not a candidate: the + // read refuses that module's name over the two modules only, so the widening + // never reaches across to it. Running alpha there would be a pick at a + // module's exact address; the caller admitted to alpha alone is answered what + // a missing name answers, and one admitted beside a module is refused naming + // that module alone. BASE (`main` ba35dfd78): 503 in every cell. + it.each([['alpha first', [A, M1, M2]], ['alpha last', [M2, M1, A]]] as const)('[#32948] plugin-wired admission (%s): at a module\'s address the uncontended holder is not reached across to — alpha alone answers the missing name, alpha with a module refuses naming that module alone (BASE: 503)', async (_order, order) => { + boot(order, true); + contendingRow(); + for (const [query, what] of [[{ package: M1 }, '?package= a module'], [{ callerPackage: M2 }, '?callerPackage= a module']] as const) { + const alone = await both(query, admitting(['alpha_item'])); + const missing = await both(query, admitting(['alpha_item']), 'nowhere'); + expect([alone.single.status, alone.single.code, alone.single.ran], `${what}, alpha only`).toEqual([404, 'NOT_FOUND', []]); + expect(alone.single.text, `${what}, alpha only`).toBe(missing.single.text.replace(/nowhere/g, 'sales')); + expect([alone.batch.status, alone.batch.entry, alone.batch.ran], `${what}, alpha only`).toEqual([200, 404, []]); + expect(alone.batch.text, `${what}, alpha only`).toBe(missing.batch.text.replace(/nowhere/g, 'sales')); + const beside = await both(query, admitting(['alpha_item', 'one_item'])); + const where = `${what}, alpha and one`; + expect([beside.single.status, beside.single.code, beside.single.ran], where).toEqual([409, 'RESOURCE_CONFLICT', []]); + expect([beside.batch.status, beside.batch.entry, beside.batch.code, beside.batch.ran], where).toEqual([200, 409, 'RESOURCE_CONFLICT', []]); + for (const answer of [beside.single, beside.batch]) { + expect(answer.message, where).toContain(`package "${M1}"`); + expect(answer.text, where).not.toContain(A); + expect(answer.text, where).not.toContain(M2); + } + hiddenHolderNotImplied(beside, where); + } + }); + it.each([['one first', [M1, M2]], ['two first', [M2, M1]]] as const)('[#32948] CONTROL (%s): a package-less row beside the two modules is declined at each module\'s address, so the App pair is judged over the modules as with no row, before and after', async (_order, order) => { boot(order); registry.registerItem('dataset', { From b89bfcd08d3ae799053b7ff46f1aeca750baf94d Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 22:48:08 +0000 Subject: [PATCH 4/4] docs(rest): the one-module dataset 409 neither names nor counts a hidden holder Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_016WV4cz4f7zEQZ2C9GTG382 --- .changeset/32948-dataset-door-contended-holder.md | 4 ++-- content/docs/data-modeling/analytics.mdx | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.changeset/32948-dataset-door-contended-holder.md b/.changeset/32948-dataset-door-contended-holder.md index 916b733eb08..cae09248beb 100644 --- a/.changeset/32948-dataset-door-contended-holder.md +++ b/.changeset/32948-dataset-door-contended-holder.md @@ -10,9 +10,9 @@ Metadata-protocol: none Moved answers, when the name is refused (bare name, `?callerPackage=`, or `?package=` naming a contended holder) and its holders' own addresses are contended: - admitted to two or more holders: `503 SERVICE_UNAVAILABLE` → `409 RESOURCE_CONFLICT` naming those holders; -- admitted to exactly one contended holder: `503` → `409` naming that holder only, nothing run; +- admitted to exactly one contended holder: `503` → `409` naming that holder only, nothing run; its sentence speaks of that holder and the row alone and neither names nor counts any holder the caller may not query; - admitted to none: `503` → `404 NOT_FOUND`, byte-equal to the answer for a name nothing holds; -- admitted to exactly one holder whose address is not contended, every other holder contended and not admitted: `503` → `200`, that holder's dataset runs (the rule for one admitted holder of an ambiguity, now reached). +- admitted to exactly one holder whose address is not contended, every other holder contended and not admitted: `503` → `200`, that holder's dataset runs (the rule for one admitted holder of an ambiguity, now reached). At `?package=` or `?callerPackage=` naming a contended module that holder is not among the refused holders, so it never runs there: admitted to it alone is the `404`, admitted beside a module is the `409` naming that module only. The stored row this arises from today is an App's customization-pair row that names none of the App's modules. A row bound to no package is declined at each holder's address for a dataset, so it moves no answer, before or after. diff --git a/content/docs/data-modeling/analytics.mdx b/content/docs/data-modeling/analytics.mdx index cd60c3d75df..3876dfd94cc 100644 --- a/content/docs/data-modeling/analytics.mdx +++ b/content/docs/data-modeling/analytics.mdx @@ -318,7 +318,9 @@ if the row were not there. An App's customization-pair row that names none of the App's modules makes each module's own address refuse the name until the row is saved under one package. Such a module never runs, and it is judged on its own dataset: the `409` names it when the caller may query it, and a caller who -may query none of the holders gets the `404`. +may query none of the holders gets the `404`. A `409` that names one module +speaks of that module and the row only: it neither names nor counts a holder +the caller may not query. To run several queries in one request, as a dashboard render does, send them to `POST {basePath}/analytics/dataset/query/batch` as `{ queries: [...] }`,