From 233683d6ee98accf75b8a0dd6e0ae6324c861e68 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 16:11:44 +0000 Subject: [PATCH 1/2] =?UTF-8?q?docs(adr-0149):=20D3=20rule=201=20note=20?= =?UTF-8?q?=E2=80=94=20a=20bundle=20label=20matches=20in=20the=20caller's?= =?UTF-8?q?=20locale=20only?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ADR-0149 D3 rule 1 said a member's label matches "in every locale". The maintainer's ruling 「A+C 本语言标签+同义词」 (ruling record 6946563869) and both transports hold it narrower: every locale of an inline label map, plus the translation bundle's label in the caller's locale; a word in another language hits only as an authored synonym. An add-only amendment note under rule 1 records it, and the term matcher's doc comment says the same. No behaviour change. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01WGufzg1NmbJpZhtiWQkTir --- ...estions-through-the-dataset-semantic-layer.md | 10 ++++++++++ .../src/dataset-term-matcher.ts | 16 +++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/docs/adr/0149-ai-answers-business-questions-through-the-dataset-semantic-layer.md b/docs/adr/0149-ai-answers-business-questions-through-the-dataset-semantic-layer.md index 8ebae3485f6..a2c60efbc11 100644 --- a/docs/adr/0149-ai-answers-business-questions-through-the-dataset-semantic-layer.md +++ b/docs/adr/0149-ai-answers-business-questions-through-the-dataset-semantic-layer.md @@ -149,6 +149,16 @@ Both `DatasetMeasureSchema` and `DatasetDimensionSchema` gain two optional keys. The rule is stated once here and carried in three places: the tool descriptions (for MCP clients), cloud's planner (the product's enforcement), and the D5 evaluation (the measurement). 1. **Normalize** the question's candidate terms and every match target the same way: NFKC, case-fold, trim, collapse whitespace, fold `_` and `-` to a space. Match targets are a member's `name`, its `label` in every locale, and each `synonym`. Equality after normalization is a **hit**; a substring, a stem or an embedding neighbour is **not** a hit (it may be offered in rule 3's question, never acted on). + + > **Amendment note (2026-11-17, [#34870](https://github.com/objectstack-ai/objectstack/issues/34870) — this PR): "its `label` in every locale" means every locale of an inline label map, plus the translation bundle's label in the caller's locale only; a word in another language hits only as an authored `synonym`.** + > Ruled by the maintainer on [#34720](https://github.com/objectstack-ai/objectstack/issues/34720), option text verbatim 「A+C 本语言标签+同义词」 (ruling record [`6946563869`](https://github.com/objectstack-ai/objectstack/issues/34720#issuecomment-6946563869)). This note qualifies the label target and changes no other word of rule 1: the normalization, equality as the only hit, and the `name` and `synonym` targets stand as written. + > + > - **An inline label map: every locale is a target.** A member whose `label` is authored as an inline locale map is matched on each locale's value, whatever locale the caller speaks, unless the bundle answers for that member (next point). + > - **A bundle label: the caller's locale only (option A).** A label the translation bundle carries (`datasets..dimensions..label`, `.measures..label`) is resolved for the caller's locale before any matching, and only that resolved value is a target; the bundle's values in other locales are not. Where the bundle answers for a member, the resolved value is the label the member is served with: it takes the place of the authored label, a plain string or an inline map alike, so the authored label is then no target. The ruling records the consequence: under a translated locale, an English source label that is not the member's `name` misses. + > - **A word in another language is an authored synonym (option C).** Synonyms are never translated and match in every language at once ([D1](#d1--business-vocabulary-on-measures-and-dimensions-synonyms-and-description)'s i18n stance), so a word meant to hit across locales is written as a `synonym`. The `candidates` of the amendment note after rule 5 offer such a word for a question; they never make it a hit. + > - **The caller's locale, per transport.** The HTTP door's dataset catalogue (`packages/runtime/src/domains/mcp.ts#datasetToolMembers`) is localized by the `/meta` list translation (`packages/rest/src/meta-item-read-gate.ts#translateMetaList`, which applies `packages/spec/src/system/i18n-resolver.ts#translateDataset`) for the locale `packages/rest/src/meta-item-read-gate.ts#metaRequestLocale` reads from the request's `Accept-Language`, falling back to the i18n service's default locale. The stdio transport (`packages/mcp/src/stdio-data-bridge.ts#createStdioDataBridge`) carries no request: it runs the same translation for the i18n service's default locale, the workspace default its principal speaks. On either transport, a host whose i18n service cannot be resolved serves the catalogue untranslated, and the authored label alone is the target: a string, or every locale of an inline map. + > - **The matcher is unchanged.** `packages/services/service-analytics/src/dataset-term-matcher.ts#matchDatasetTerms` compares the label it is handed (a string, or each locale's value of an inline map); which bundle locale it sees is settled before it runs, by the transport's translation. Its doc comment says the same. + 2. **One hit → it wins.** The AI answers through `query_dataset` on that dataset and member, and renders the answer's source from the tool's `provenance` — 「指标:营收(数据集:销售分析)」 — never from its own recollection of what it asked. A measure's `description` is the sentence the AI uses to explain what the number includes. 3. **More than one hit** (two datasets, or two members, answer to the word) → the AI **asks**, listing each candidate's label, dataset label and description. It does not pick, and it does not silently prefer the first. (Snowflake's suggestions, Looker's clarifying question, Genie's follow-up.) 4. **No hit → fall back to the object query the AI runs today** (`query_records` / `aggregate_records`, or cloud's equivalents), and the answer's source says so in words — 「来源:对象 crm_opportunity 的 amount 字段合计(非指标口径)」 — so a reader can tell a governed number from an estimate. The posture of this rule is [M2](#m2--what-the-ai-does-when-no-dataset-covers-the-question), ruled A; the card's wording (「没有命中时,再退回按对象查询」) is that option. **Recommended practice, not a rule** (the analysis the ruling endorsed leaned toward it): when a listed dataset's `object` is the object the fallback query landed on, the answer adds one line naming that dataset and its measures — 「该对象已有数据集 X(指标:…),如需口径答案请换用这些术语」 — so the reader learns a governed path exists. It lives in cloud's planner prompt and in the tool description, is added after the object is chosen, needs no up-front object resolution, and changes nothing about the fallback itself. D5 reports how often the line fires. diff --git a/packages/services/service-analytics/src/dataset-term-matcher.ts b/packages/services/service-analytics/src/dataset-term-matcher.ts index f4e92f4503b..9c853c27b87 100644 --- a/packages/services/service-analytics/src/dataset-term-matcher.ts +++ b/packages/services/service-analytics/src/dataset-term-matcher.ts @@ -12,8 +12,15 @@ import { normalizeDatasetTerm } from '@objectstack/spec/ui'; * dataset schema's own vocabulary validation uses (NFKC, case-fold, trim, * collapse whitespace, `_` and `-` folded to a space) — and EQUALITY is a hit. * A substring, a stem or a near neighbour is not a hit. The match targets are - * the member's `name`, its `label` in every locale of an inline map, and each - * of its `synonyms`. + * the member's `name`, its `label` in every locale of an inline map, plus the + * translation bundle's label in the caller's locale only, and each of its + * `synonyms`; a word in another language hits only as an authored synonym + * (ADR-0149 D3 rule 1's amendment note, ruled 「A+C 本语言标签+同义词」). + * + * This function never reads the bundle: the transport localizes the catalogue + * before it runs (the HTTP door for the request's locale, stdio for the i18n + * service's default), and where the bundle answers for a member that value is + * the `label` handed in, in place of the authored string or inline map. * * Rules 2–5 (one hit wins, several hits ask, no hit falls back to the object * query labelled 「非指标口径」, a dimension hit alone is no answer) are the @@ -24,7 +31,10 @@ import { normalizeDatasetTerm } from '@objectstack/spec/ui'; /** A member's match targets, as the dataset declares them. */ export interface MatchableMember { readonly name: string; - /** A string, or an inline locale map (every locale is a target). */ + /** + * A string, or an inline locale map (every locale is a target); a bundle + * label arrives already resolved to the caller's locale, as a string. + */ readonly label?: unknown; readonly synonyms?: readonly unknown[]; } From 4b963c9824ac155296328f5a8723915650155995 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 17:25:05 +0000 Subject: [PATCH 2/2] docs(adr-0149): the rule 1 note states the bundle label's locale chain The D3 rule 1 amendment note said a bundle label is matched in "the caller's locale only" and that "the bundle's values in other locales are not" targets. The resolver says otherwise: lookupDatasetMemberAttr walks the requested locale through the platform locale ladder (variant expansion included), then the deployment's declared fallback locale (metaTranslateOptions), skipped when the caller's locale is the authored one. The note now states that chain, keeps "one value is served and only that value is a target", and names two worked cases. It also names the HTTP pair-translation corner when no i18n service resolves, says any other door to the executor owes the same translation step, and names the PR in its header. The matcher's module comment mirrors the chain in one clause. Prose only; no code changes. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01WGufzg1NmbJpZhtiWQkTir --- ...s-questions-through-the-dataset-semantic-layer.md | 6 +++--- .../service-analytics/src/dataset-term-matcher.ts | 12 ++++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/docs/adr/0149-ai-answers-business-questions-through-the-dataset-semantic-layer.md b/docs/adr/0149-ai-answers-business-questions-through-the-dataset-semantic-layer.md index a2c60efbc11..2f796b3ad54 100644 --- a/docs/adr/0149-ai-answers-business-questions-through-the-dataset-semantic-layer.md +++ b/docs/adr/0149-ai-answers-business-questions-through-the-dataset-semantic-layer.md @@ -150,13 +150,13 @@ The rule is stated once here and carried in three places: the tool descriptions 1. **Normalize** the question's candidate terms and every match target the same way: NFKC, case-fold, trim, collapse whitespace, fold `_` and `-` to a space. Match targets are a member's `name`, its `label` in every locale, and each `synonym`. Equality after normalization is a **hit**; a substring, a stem or an embedding neighbour is **not** a hit (it may be offered in rule 3's question, never acted on). - > **Amendment note (2026-11-17, [#34870](https://github.com/objectstack-ai/objectstack/issues/34870) — this PR): "its `label` in every locale" means every locale of an inline label map, plus the translation bundle's label in the caller's locale only; a word in another language hits only as an authored `synonym`.** + > **Amendment note (2026-11-17, [#34870](https://github.com/objectstack-ai/objectstack/issues/34870) — PR #34928): "its `label` in every locale" means every locale of an inline label map, plus the one translation-bundle label resolved for the caller's locale; a word in another language hits only as an authored `synonym`.** > Ruled by the maintainer on [#34720](https://github.com/objectstack-ai/objectstack/issues/34720), option text verbatim 「A+C 本语言标签+同义词」 (ruling record [`6946563869`](https://github.com/objectstack-ai/objectstack/issues/34720#issuecomment-6946563869)). This note qualifies the label target and changes no other word of rule 1: the normalization, equality as the only hit, and the `name` and `synonym` targets stand as written. > > - **An inline label map: every locale is a target.** A member whose `label` is authored as an inline locale map is matched on each locale's value, whatever locale the caller speaks, unless the bundle answers for that member (next point). - > - **A bundle label: the caller's locale only (option A).** A label the translation bundle carries (`datasets..dimensions..label`, `.measures..label`) is resolved for the caller's locale before any matching, and only that resolved value is a target; the bundle's values in other locales are not. Where the bundle answers for a member, the resolved value is the label the member is served with: it takes the place of the authored label, a plain string or an inline map alike, so the authored label is then no target. The ruling records the consequence: under a translated locale, an English source label that is not the member's `name` misses. + > - **A bundle label: one value, resolved for the caller's locale (option A).** A label the translation bundle carries (`datasets..dimensions..label`, `.measures..label`) is resolved for the caller's locale before any matching, along the resolver's locale chain (`packages/spec/src/system/i18n-resolver.ts#lookupDatasetMemberAttr`): first the requested locale, read through the platform locale ladder (`packages/spec/src/system/i18n-resolver.ts#resolveBundleLocale`: case, platform table language, base language, variant expansion), then the deployment's declared fallback locale (`packages/rest/src/meta-item-read-gate.ts#metaTranslateOptions`), which is skipped when the caller's locale is the one the labels are authored in. One value is served per member, and only that resolved value is a target; no other bundle value is. So a `zh-TW` caller against a bundle whose only Chinese locale is `zh-CN` is served, and matched on, the `zh-CN` label (variant expansion, no fallback declared), and a `fr` caller in a deployment authored in another language, whose declared fallback is `en`, is served, and matched on, the `en` label when the bundle has no French one. Where the bundle answers for a member, the resolved value is the label the member is served with: it takes the place of the authored label, a plain string or an inline map alike, so the authored label is then no target. The ruling records the consequence: under a translated locale, an English source label that is not the member's `name` misses. > - **A word in another language is an authored synonym (option C).** Synonyms are never translated and match in every language at once ([D1](#d1--business-vocabulary-on-measures-and-dimensions-synonyms-and-description)'s i18n stance), so a word meant to hit across locales is written as a `synonym`. The `candidates` of the amendment note after rule 5 offer such a word for a question; they never make it a hit. - > - **The caller's locale, per transport.** The HTTP door's dataset catalogue (`packages/runtime/src/domains/mcp.ts#datasetToolMembers`) is localized by the `/meta` list translation (`packages/rest/src/meta-item-read-gate.ts#translateMetaList`, which applies `packages/spec/src/system/i18n-resolver.ts#translateDataset`) for the locale `packages/rest/src/meta-item-read-gate.ts#metaRequestLocale` reads from the request's `Accept-Language`, falling back to the i18n service's default locale. The stdio transport (`packages/mcp/src/stdio-data-bridge.ts#createStdioDataBridge`) carries no request: it runs the same translation for the i18n service's default locale, the workspace default its principal speaks. On either transport, a host whose i18n service cannot be resolved serves the catalogue untranslated, and the authored label alone is the target: a string, or every locale of an inline map. + > - **The caller's locale, per transport.** The HTTP door's dataset catalogue (`packages/runtime/src/domains/mcp.ts#datasetToolMembers`) is localized by the `/meta` list translation (`packages/rest/src/meta-item-read-gate.ts#translateMetaList`, which applies `packages/spec/src/system/i18n-resolver.ts#translateDataset`) for the locale `packages/rest/src/meta-item-read-gate.ts#metaRequestLocale` reads from the request's `Accept-Language`, falling back to the i18n service's default locale. The stdio transport (`packages/mcp/src/stdio-data-bridge.ts#createStdioDataBridge`) carries no request: it runs the same translation for the i18n service's default locale, the workspace default its principal speaks. On either transport, a host whose i18n service cannot be resolved serves the catalogue untranslated, and the authored label alone is the target: a string, or every locale of an inline map. The one exception is on HTTP: an `Accept-Language` header still resolves a locale there, and a dataset that is a `.custom` pair's declared override can still take its pair's own translations (`packages/rest/src/meta-item-read-gate.ts#pairTranslationBundleOf`, read from the protocol, not from the i18n service). Any other door to the same executor, cloud's service-ai `ToolRegistry` ([D2](#d2--two-tools-one-definition-one-executor-two-transports)) among them, supplies the executor's `loadDatasets` itself (`packages/services/service-analytics/src/dataset-tools.ts#DatasetToolsDeps`) and owes the same translation step there. > - **The matcher is unchanged.** `packages/services/service-analytics/src/dataset-term-matcher.ts#matchDatasetTerms` compares the label it is handed (a string, or each locale's value of an inline map); which bundle locale it sees is settled before it runs, by the transport's translation. Its doc comment says the same. 2. **One hit → it wins.** The AI answers through `query_dataset` on that dataset and member, and renders the answer's source from the tool's `provenance` — 「指标:营收(数据集:销售分析)」 — never from its own recollection of what it asked. A measure's `description` is the sentence the AI uses to explain what the number includes. diff --git a/packages/services/service-analytics/src/dataset-term-matcher.ts b/packages/services/service-analytics/src/dataset-term-matcher.ts index 9c853c27b87..c5de6a835cf 100644 --- a/packages/services/service-analytics/src/dataset-term-matcher.ts +++ b/packages/services/service-analytics/src/dataset-term-matcher.ts @@ -13,14 +13,18 @@ import { normalizeDatasetTerm } from '@objectstack/spec/ui'; * collapse whitespace, `_` and `-` folded to a space) — and EQUALITY is a hit. * A substring, a stem or a near neighbour is not a hit. The match targets are * the member's `name`, its `label` in every locale of an inline map, plus the - * translation bundle's label in the caller's locale only, and each of its - * `synonyms`; a word in another language hits only as an authored synonym + * one translation-bundle label resolved for the caller's locale, and each of + * its `synonyms`; a word in another language hits only as an authored synonym * (ADR-0149 D3 rule 1's amendment note, ruled 「A+C 本语言标签+同义词」). * * This function never reads the bundle: the transport localizes the catalogue * before it runs (the HTTP door for the request's locale, stdio for the i18n * service's default), and where the bundle answers for a member that value is - * the `label` handed in, in place of the authored string or inline map. + * the `label` handed in, in place of the authored string or inline map. The + * value is resolved along the resolver's locale chain (the requested locale by + * the platform locale ladder, variant expansion included, then the + * deployment's declared fallback locale, skipped when the caller's locale is + * the authored one); no other bundle value is a target. * * Rules 2–5 (one hit wins, several hits ask, no hit falls back to the object * query labelled 「非指标口径」, a dimension hit alone is no answer) are the @@ -33,7 +37,7 @@ export interface MatchableMember { readonly name: string; /** * A string, or an inline locale map (every locale is a target); a bundle - * label arrives already resolved to the caller's locale, as a string. + * label arrives already resolved for the caller's locale, as a string. */ readonly label?: unknown; readonly synonyms?: readonly unknown[];