Skip to content

Commit bf7e329

Browse files
committed
Merge origin/main
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ADHkmRb3wUaRcujR7QEm2o
2 parents 96212d1 + 2b752aa commit bf7e329

24 files changed

Lines changed: 2115 additions & 57 deletions
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@objectstack/service-analytics': patch
3+
'@objectstack/spec': patch
4+
---
5+
6+
feat(service-analytics): `list_datasets` and `query_dataset` — the dataset AI tools, one definition and one executor (ADR-0149 D2–D4)
7+
8+
Clause-②: yes (widening) — new exports `createDatasetTools`, `getDatasetToolDefinitions`, `DATASET_TOOL_DEFAULT_MAX_ROWS`, `matchDatasetTerms` and their types, and three new `AnalyticsService` methods (`datasetTools`, `hasPluginWiredAdmission`, `admitDatasetCatalogEntry`) plus `reportDatasetCatalogDefect`.
9+
Metadata-protocol: none
10+
11+
An AI can now answer a business question from a governed dataset instead of guessing a field on an object.
12+
13+
- **Two tools, defined once.** `getDatasetToolDefinitions()` returns the two `AIToolDefinition`s — names, the descriptions that teach the model the selection rule, and the JSON Schemas projected from `@objectstack/spec`'s tool schemas. `AnalyticsService.datasetTools({ loadDatasets, maxQueryLimit?, diagnoseDelegation? })` (or `createDatasetTools`) binds the executor; the MCP bridges and the product AI's registry both call it.
14+
- **`list_datasets`** lists the saved datasets the caller may query, with each member's label, business description and synonyms at the caller's locale. It asks the same gates a query of the dataset asks: a dataset whose object the caller may not read, or that is not API-exposed, is absent; a member over a field the caller may not read is left out and `membersWithheld: true` says so; a member over an `internal` field is left out for every caller and reported once to the server log. With `terms`, each dataset's `matches` names which word equals which member's name, label (any locale) or synonym, after the dataset schema's own normalization.
15+
- **`query_dataset`** runs a `DatasetSelection` against one saved dataset through `queryDataset` with the caller's context — no gate added, none skipped. A missing dataset and one the caller may not query both answer `NOT_FOUND`. Rows are capped (50 by default) with `truncated`; the answer carries no SQL and adds a `provenance` block (dataset, measures with their descriptions, dimensions, the caller's `runtimeFilter`) composed from what ran — the model's input cannot set it.
16+
- **Plugin-wired only.** Both tools refuse with `SERVICE_UNAVAILABLE` / 503 on an `AnalyticsService` built without the admission hooks `AnalyticsServicePlugin` wires, where the exposure gate would warn and pass and the read admission would return silently.
17+
- **Member descriptions reach the Cube.** `compileDataset` writes a dataset member's `description` onto the Cube member, so `GET /api/v1/analytics/meta` publishes it for a registered dataset cube.
18+
- The spec liveness ledger moves the four dataset member rows (`synonyms` and `description` on dimensions and measures) from `planned` to `live`.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
'@objectstack/cli': patch
3+
---
4+
5+
fix(cli)!: `os serve` asks the multi-node gate about a topology declared by `OS_EXPECT_MULTI_NODE=true`, not only by `OS_CLUSTER_REPLICAS`
6+
7+
Clause-②: no (narrowing)
8+
Metadata-protocol: none
9+
Skills-docs: `skills/**` names neither spelling of the multi-node declaration. `content/docs/kernel/cluster.mdx` already teaches both spellings as the declaration; its sentence that a gate denial "downgrades … rather than failing" is corrected in this diff: with a declared topology the split-brain guard refuses the boot.
10+
11+
<!-- adr-0087: not-required (no-migration-prescription) No schema key, export, type or stored shape changes. The narrowing is a boot refusal keyed to environment variables an operator sets, so there is nothing for a metadata migration to rewrite and no tombstone. -->
12+
13+
**BREAKING** for a deployment that runs `os serve` with a remote cluster driver (`OS_CLUSTER_DRIVER` other than `memory`), declares multi-node only as `OS_EXPECT_MULTI_NODE=true`, and registers no multi-node gate.
14+
15+
A multi-node topology has two spellings, `OS_CLUSTER_REPLICAS` greater than 1 and `OS_EXPECT_MULTI_NODE=true`. With no gate registered, the gate refuses a declared multi-node topology, because multi-node is a licensed capability. `os serve` used to ask the gate with `OS_CLUSTER_REPLICAS` alone, so a topology declared only as `OS_EXPECT_MULTI_NODE=true` reached the gate as undeclared and booted the remote driver multi-node with no gate. The same deployment spelled `OS_CLUSTER_REPLICAS=2` was already refused.
16+
17+
After the upgrade both spellings answer the same way. `os serve` reads the declaration through `declaresMultiNode` from `@objectstack/service-cluster`. A declaration with no count is asked as 2 nodes, the smallest multi-node count. With no gate registered it prints `[cluster] multi-node not authorized (…)`, drops the remote driver, and the split-brain guard refuses the in-process fallback, so the boot stops.
18+
19+
FROM a multi-replica deployment that sets `OS_EXPECT_MULTI_NODE=true` over a remote driver with no gate TO either:
20+
21+
- register a multi-node gate (install the distribution that carries it), which authorizes the topology, or
22+
- drop `OS_EXPECT_MULTI_NODE` (and keep `OS_CLUSTER_REPLICAS` unset or 1) to run single-node.
23+
24+
A single-node boot, a boot declared as `OS_CLUSTER_REPLICAS`, and a boot whose registered gate admits the topology are unchanged.
25+
26+
When a gate that caps the node count admits fewer nodes than that 2, the licensed-cap advisory no longer prints a replica count the operator did not write. It names `OS_EXPECT_MULTI_NODE=true`, says what the licence admits, says the cap is advisory and every replica still joins, and asks the operator to run at most that many replicas (or set `OS_CLUSTER_REPLICAS`) or raise the limit. The advisory for a count declared as `OS_CLUSTER_REPLICAS` is unchanged.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
'@objectstack/skills': patch
3+
---
4+
5+
docs(skills): objectstack-data `security.md` teaches that a package's sharing rule resolves its queue recipient from its own package
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
`skills/objectstack-data/rules/security.md` now states the rule the sharing plugin enforces since ADR-0150 E4: a declared sharing rule's `sharedWith: { type: 'queue', value }` reads the name as its own package's queue, else the one holder in the package's declared `dependencies` closure plus `sys`, else (no package or environment item declares the name) an organization's `sys_queue` row. Three refusal codes are taught, each with an example: `outside-closure` (the only holder is a package the rule's package does not depend on, or an environment-authored item), `ambiguous-in-closure` (two dependencies hold the name) and `ambiguous-in-environment` (the holder the rule reaches, its own package or one dependency, and a non-dependency both hold it). A refused rule grants no one new and is warned as `RESOURCE_CONFLICT`; it loads, so nothing earlier tells the author. `evals/hooks-security-seeds-datasources.json` gains case 18, which requires the queue recipient plus a manifest `dependencies` entry on the queue's package and refuses redeclaring the queue in the rule's package.
11+
12+
The file sits at its token ceiling, so the new bullet (446 bytes) is paid for by these cuts in the same file (459 bytes; the file goes from 15069 to 15056 bytes):
13+
14+
- `(PermissionSetSchema.rowLevelSecurity)` after "permission set / profile" (41 B); the same sentence names `rowLevelSecurity` on a permission set.
15+
- "(the tenant wall still applies)" in the RLS default-deny sentence (32 B); the Layer 0 bullet says the wall is AND-composed ahead of all business RLS.
16+
- The sentence that a legacy SQL-style `=` / `IN (...)` predicate still compiles through a deprecated bridge (98 B). This is not a restatement: the file now teaches canonical CEL only.
17+
- The four "(for `IN`)" notes in the `current_user.*` table (42 B); the predicate list above it spells `field in current_user.ARRAY`.
18+
- The membership-key section intro, shortened to "Declare the set on the roster object, not one policy per record." (80 B); the section heading and the "Choose by" bullet's "a named record → a membership key" carry the rest.
19+
- "(`isDefault` sets)" after the `everyone` baseline in the Positions section (19 B); the `isDefault: true` bullet defines that baseline.
20+
- The admin-only recipe's `tenancy` comment "not a tenant object → Layer 0 contributes nothing" (55 B); the blockquote below it explains the key.
21+
- The blockquote's "it is the half that holds however permissive the grants" (59 B); the `requiredPermissions` paragraph calls it an AND-gate, strictest-wins over field grants.
22+
- "(`@objectstack/plugin-security`)" after `sys_user_permission_set` (33 B); a package pointer an author never writes.
23+
24+
The `(definePermissionSet)` example comment and the field-lock recipe docs link stay.

‎content/docs/kernel/cluster.mdx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,9 +685,12 @@ const cluster = defineCluster({ driver: 'memory' })
685685
Under `os serve` the driver is selected from the environment instead:
686686
`OS_CLUSTER_DRIVER` (anything other than `memory` triggers a dynamic import of
687687
`@objectstack/service-cluster-<driver>`) and `OS_REDIS_URL` for the connection
688-
string. A distribution may register a multi-node gate; when it denies,
689-
`os serve` logs a warning and downgrades to the single-node in-memory cluster
690-
rather than failing.
688+
string. A distribution may register a multi-node gate; with no gate
689+
registered, a declared multi-node topology is denied. When the gate denies,
690+
`os serve` logs a warning and drops the remote driver for the in-memory one.
691+
That is a single-node downgrade only when no multi-node topology is declared:
692+
with one declared (`OS_CLUSTER_REPLICAS` > 1 or `OS_EXPECT_MULTI_NODE=true`),
693+
the split-brain guard below refuses the boot.
691694

692695
A gate may instead admit **fewer** nodes than the deployment declares — a
693696
licensed node-cap overflow. That is a different verdict from a denial and is

‎packages/cli/src/commands/serve-multi-node-cap-advisory.pin.test.ts‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,35 @@ describe('os serve ↔ multi-node gate', () => {
155155
// desired count, identical in every replica, not a live membership count —
156156
// which is right for an advisory message about the operator's own
157157
// configuration, and is NOT sufficient for enforcement.
158-
expect(MASKED_SERVE_SOURCE).toMatch(/checkMultiNodeAllowed\(\s*Number\(process\.env\.OS_CLUSTER_REPLICAS\)\s*\)/);
158+
//
159+
// The count is asked through the one reading of the declaration
160+
// (`declaresMultiNode`, both spellings): a topology declared only as
161+
// `OS_EXPECT_MULTI_NODE=true` carries no count, and asked with the bare
162+
// `NaN` the gate read it as "not declared". ⛔ No second parse of that
163+
// spelling here — the shared predicate is the only reader.
164+
expect(MASKED_SERVE_SOURCE).toMatch(
165+
/const __countUnknown =\s*declaresMultiNode\(process\.env\)\s*&&\s*!declaresMultiNode\(\{\s*OS_CLUSTER_REPLICAS:\s*process\.env\.OS_CLUSTER_REPLICAS\s*\}\);/,
166+
);
167+
expect(MASKED_SERVE_SOURCE).toMatch(
168+
/const __requestedNodes = __countUnknown \? 2 : Number\(process\.env\.OS_CLUSTER_REPLICAS\);/,
169+
);
170+
expect(MASKED_SERVE_SOURCE).toMatch(/checkMultiNodeAllowed\(\s*__requestedNodes\s*\)/);
171+
expect(MASKED_SERVE_SOURCE).not.toMatch(/process\.env\.OS_EXPECT_MULTI_NODE/);
172+
});
173+
174+
it('tells the cap advisory whether the count the gate saw is one the operator wrote', () => {
175+
// Both cases share one call: counted (`OS_CLUSTER_REPLICAS`, or nothing
176+
// declared) keeps the counted wording byte for byte; uncounted
177+
// (`OS_EXPECT_MULTI_NODE=true` alone, asked as 2) must never print that 2 as
178+
// a declared count. The flag comes from the call site's own reading, so the
179+
// formatter re-reads nothing — and the parameter is required, so no call can
180+
// fall back to the counted wording by leaving it out.
181+
expect(MASKED_SERVE_SOURCE).toMatch(
182+
/formatMultiNodeCapAdvisory\(\s*__gate\s*,\s*\{\s*countDeclared:\s*!__countUnknown\s*\}\s*\)/,
183+
);
184+
expect(MASKED_SERVE_SOURCE).toMatch(
185+
/export function formatMultiNodeCapAdvisory\(\s*verdict: MultiNodeGateVerdict,\s*declaration: \{ countDeclared: boolean \},\s*\)/,
186+
);
159187
});
160188

161189
it('types the dynamic import with the mirrored verdict, not an inline literal', () => {

‎packages/cli/src/commands/serve-multi-node-cap-advisory.test.ts‎

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@
2121
import { describe, it, expect } from 'vitest';
2222
import { formatMultiNodeCapAdvisory, type MultiNodeGateVerdict } from './serve.js';
2323

24+
// Pay the first load of what `serve.ts` reaches through dynamic `import()`s at
25+
// MODULE LOAD, outside any clocked case (`pnpm check:test-source-alias`).
26+
import '@objectstack/metadata-protocol';
27+
import '@objectstack/metadata';
28+
import '@objectstack/objectql';
29+
import '@objectstack/plugin-hono-server';
30+
import '@objectstack/rest';
31+
import '@objectstack/service-settings';
32+
import '@objectstack/service-datasource';
33+
import '@objectstack/driver-turso';
34+
import '@objectstack/driver-sql';
35+
import '@objectstack/platform-objects/plugin';
36+
import '@objectstack/plugin-security';
37+
2438
/**
2539
* The four verdicts the producer can hand this consumer, spelled the way
2640
* `checkMultiNodeAllowed` builds them (`multi-node-gate.ts`). The pin test
@@ -37,17 +51,25 @@ const VERDICTS = {
3751
denied: { allowed: false, reason: 'no clustering entitlement', admitted: 0, refused: 5, capped: false },
3852
} satisfies Record<string, MultiNodeGateVerdict>;
3953

54+
/** The operator wrote `OS_CLUSTER_REPLICAS`: the count the gate saw is theirs. */
55+
const COUNTED = { countDeclared: true };
56+
/** `OS_EXPECT_MULTI_NODE=true` with no count: `serve` asked the gate about 2 nodes. */
57+
const UNCOUNTED = { countDeclared: false };
58+
59+
/** An uncounted declaration under a cap of 1: the gate was asked about 2. */
60+
const UNCOUNTED_OVER_CAP = { allowed: true, admitted: 1, refused: 1, capped: true } satisfies MultiNodeGateVerdict;
61+
4062
describe('formatMultiNodeCapAdvisory', () => {
4163
it('says nothing when no cap is configured', () => {
42-
expect(formatMultiNodeCapAdvisory(VERDICTS.uncapped)).toBeNull();
64+
expect(formatMultiNodeCapAdvisory(VERDICTS.uncapped, COUNTED)).toBeNull();
4365
});
4466

4567
it('says nothing when a cap is configured and the declared topology fits', () => {
46-
expect(formatMultiNodeCapAdvisory(VERDICTS.withinCap)).toBeNull();
68+
expect(formatMultiNodeCapAdvisory(VERDICTS.withinCap, COUNTED)).toBeNull();
4769
});
4870

4971
it('warns on a licensed overflow, naming both numbers', () => {
50-
expect(formatMultiNodeCapAdvisory(VERDICTS.overflow)).toBe(
72+
expect(formatMultiNodeCapAdvisory(VERDICTS.overflow, COUNTED)).toBe(
5173
'[cluster] licensed node cap exceeded: the licence admits 3 node(s), '
5274
+ 'but OS_CLUSTER_REPLICAS declares 5 — 2 beyond the cap.\n'
5375
+ '[cluster] This cap is ADVISORY and is not enforced yet: nothing is refused, '
@@ -57,7 +79,7 @@ describe('formatMultiNodeCapAdvisory', () => {
5779
});
5880

5981
it('⚠️ never claims replicas were refused — nothing is refused today', () => {
60-
const text = formatMultiNodeCapAdvisory(VERDICTS.overflow) ?? '';
82+
const text = formatMultiNodeCapAdvisory(VERDICTS.overflow, COUNTED) ?? '';
6183

6284
// The false sentences, in the shapes they would plausibly be written.
6385
expect(text).not.toMatch(/\d+\s+(replicas?\s+)?(were\s+|was\s+|are\s+)?refused/i);
@@ -72,7 +94,7 @@ describe('formatMultiNodeCapAdvisory', () => {
7294
});
7395

7496
it('names the declared count, the admitted count and the remedy', () => {
75-
const text = formatMultiNodeCapAdvisory(VERDICTS.overflow) ?? '';
97+
const text = formatMultiNodeCapAdvisory(VERDICTS.overflow, COUNTED) ?? '';
7698
expect(text).toContain('admits 3');
7799
expect(text).toContain('declares 5');
78100
expect(text).toContain('2 beyond the cap');
@@ -85,7 +107,7 @@ describe('formatMultiNodeCapAdvisory', () => {
85107
// unlicensed case cannot be conflated with the licensed-overflow one. The
86108
// call site already prints its own downgrade warning; a second message here
87109
// would report one event twice, and would call a full denial a partial cap.
88-
expect(formatMultiNodeCapAdvisory(VERDICTS.denied)).toBeNull();
110+
expect(formatMultiNodeCapAdvisory(VERDICTS.denied, COUNTED)).toBeNull();
89111
});
90112

91113
it('surfaces the gate reason when the cap carries one', () => {
@@ -95,12 +117,12 @@ describe('formatMultiNodeCapAdvisory', () => {
95117
admitted: 3,
96118
refused: 2,
97119
capped: true,
98-
});
120+
}, COUNTED);
99121
expect(text).toContain('(plan: team (3 nodes))');
100122
});
101123

102124
it('scales with the numbers rather than hard-coding the 3/5 case', () => {
103-
const text = formatMultiNodeCapAdvisory({ allowed: true, admitted: 10, refused: 7, capped: true }) ?? '';
125+
const text = formatMultiNodeCapAdvisory({ allowed: true, admitted: 10, refused: 7, capped: true }, COUNTED) ?? '';
104126
expect(text).toContain('admits 10');
105127
expect(text).toContain('declares 17');
106128
expect(text).toContain('7 beyond the cap');
@@ -111,7 +133,44 @@ describe('formatMultiNodeCapAdvisory', () => {
111133
// a numeric `admitted`), so this pins the choice rather than a behaviour:
112134
// faced with a stale or foreign build, silence beats a warning with an
113135
// invented count in it.
114-
expect(formatMultiNodeCapAdvisory({ allowed: true, refused: 2, capped: true })).toBeNull();
115-
expect(formatMultiNodeCapAdvisory({ allowed: true, admitted: 3, refused: 0, capped: true })).toBeNull();
136+
expect(formatMultiNodeCapAdvisory({ allowed: true, refused: 2, capped: true }, COUNTED)).toBeNull();
137+
expect(formatMultiNodeCapAdvisory({ allowed: true, admitted: 3, refused: 0, capped: true }, COUNTED)).toBeNull();
138+
});
139+
140+
it('names OS_EXPECT_MULTI_NODE and prints no count when the operator gave none', () => {
141+
expect(formatMultiNodeCapAdvisory(UNCOUNTED_OVER_CAP, UNCOUNTED)).toBe(
142+
'[cluster] licensed node cap exceeded: the licence admits 1 node(s), '
143+
+ 'but OS_EXPECT_MULTI_NODE=true declares a multi-node topology without a replica count.\n'
144+
+ '[cluster] This cap is ADVISORY and is not enforced yet: nothing is refused, '
145+
+ 'and every replica will still join the cluster.\n'
146+
+ '[cluster] Run at most 1 replica(s) (or set OS_CLUSTER_REPLICAS to the count you run), '
147+
+ 'or raise the licensed node limit.',
148+
);
149+
});
150+
151+
it('⚠️ never prints the 2 serve asked about as a declared count, nor an excess', () => {
152+
const text = formatMultiNodeCapAdvisory(UNCOUNTED_OVER_CAP, UNCOUNTED) ?? '';
153+
expect(text).not.toBe('');
154+
expect(text).not.toMatch(/declares\s+\d/);
155+
expect(text).not.toMatch(/beyond the cap/);
156+
expect(text).not.toMatch(/all\s+\d+\s+replicas/);
157+
expect(text).not.toMatch(/Reduce OS_CLUSTER_REPLICAS/);
158+
expect(text).toMatch(/still join/);
159+
});
160+
161+
it('the same verdict with a counted declaration keeps the counted wording', () => {
162+
expect(formatMultiNodeCapAdvisory(UNCOUNTED_OVER_CAP, COUNTED)).toBe(
163+
'[cluster] licensed node cap exceeded: the licence admits 1 node(s), '
164+
+ 'but OS_CLUSTER_REPLICAS declares 2 — 1 beyond the cap.\n'
165+
+ '[cluster] This cap is ADVISORY and is not enforced yet: nothing is refused, '
166+
+ 'and all 2 replicas will still join the cluster.\n'
167+
+ '[cluster] Reduce OS_CLUSTER_REPLICAS to 1, or raise the licensed node limit.',
168+
);
169+
});
170+
171+
it('an uncounted declaration stays silent wherever the counted one does', () => {
172+
expect(formatMultiNodeCapAdvisory(VERDICTS.uncapped, UNCOUNTED)).toBeNull();
173+
expect(formatMultiNodeCapAdvisory(VERDICTS.denied, UNCOUNTED)).toBeNull();
174+
expect(formatMultiNodeCapAdvisory({ allowed: true, admitted: 2, refused: 0, capped: false }, UNCOUNTED)).toBeNull();
116175
});
117176
});

0 commit comments

Comments
 (0)