Skip to content

Commit 9e71ef8

Browse files
docs(adr-0149): D3 rule 1 note — a member label matches as resolved along the caller's locale chain (#34928)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBLW6dHPW6sSheA32XPKZzPV)_ repo:objectstack#3 · os-support-ai · session_01WGufzg1NmbJpZhtiWQkTir Closes #34870 Clause-②: no Metadata-protocol: none Landing: **Tier H** (`docs/adr/**`). This PR stays draft; no seat readies, queues or arms auto-merge on it. ## 维护者速读 - 改了什么:ADR-0149 D3 第 1 条下加一段只增不改的修订说明,写明「标签在每个语言下都是匹配目标」的准确含义:内联多语言标签的每个语言都算,翻译包里的标签只算为调用方语言解析出的那一个值(沿解析器的语言链:先按平台语言阶梯找请求语言,含变体扩展,再找部署声明的回退语言;请求语言即编写语言时跳过回退);别的语言的词只有写成同义词才命中。`dataset-term-matcher.ts` 的文档注释改成同样的话。没有任何代码行为变化。 - 为什么改:#34720 的裁决「A+C 本语言标签+同义词」(记录 6946563869)已定,但 ADR 原文和匹配器注释仍写「every locale」,读起来像翻译包的所有语言都能命中,与裁决和 HTTP 入口的实际行为不符。 - 风险与回滚:只改文档与注释,零运行时风险。回滚即 revert 本 PR。 - 先看:① ADR-0149 D3 第 1 条下的修订说明,看是否如实转述裁决;② 其中「按传输层的调用方语言」一条:stdio 入口现在也走翻译(用 i18n 服务的默认语言),不是派发词所说的「不翻译」,见 Acceptance notes;③ `dataset-term-matcher.ts` 顶部注释。 - 两分钟验证:`pnpm check:adr-symbol-anchors`,预期最后一行 `✅ check-adr-symbol-anchors: ... anchors across 158 records resolve`(修订说明里新增的符号锚都能解析)。 - 需要你做的:席位 L2 复核后,亲手合并本 PR(Tier H:`docs/adr/**`)。 ## What changes - **`docs/adr/0149-ai-answers-business-questions-through-the-dataset-semantic-layer.md`** (10 lines added, 0 removed): an add-only amendment note, nested under D3 rule 1 so the numbered list stays intact. It follows the record's existing amendment-note form (the #34761 note after rule 5) and its measurement discipline (symbol anchors only; the line positions are below, not in the record). It states: - an inline label map: every locale is a target, unless the bundle answers for that member; - a bundle label: one value, resolved for the caller's locale along the resolver's locale chain (option A; fix round 1 spells the chain out), resolved before matching; where the bundle answers, its value replaces the authored label (string or inline map), so the authored label is then no target, the consequence the ruling records; - a word in another language is an authored synonym (option C); `candidates` offer, never hit; - the caller's locale per transport: HTTP reads `Accept-Language`, falling back to the i18n default; stdio has no request and translates for the i18n service's default locale; with no resolvable i18n service the catalogue is untranslated on either; - the matcher is unchanged. - **`packages/services/service-analytics/src/dataset-term-matcher.ts`** (doc comments only, +13 / -3): the module comment and the `MatchableMember.label` comment say the same words. No statement, type or export changes. ## Why The decision text said a member's label matches "in every locale". The ruling on #34720, verbatim 「A+C 本语言标签+同义词」 (ruling record 6946563869), and the HTTP door hold it narrower. The note did not ride #34761's ADR note (PR #34828). ## Code readings behind each claim (base `ab441988`) <details><summary>File and line positions, measured at the base commit</summary> - HTTP door: `packages/runtime/src/domains/mcp.ts:1542` (`loadDatasets` inside `datasetToolMembers`) runs `translateMetaList` with `requestLocale` at `:1555` = `metaRequestLocale({ headers: context.request?.headers }, i18n)`. Headers only, so the locale is `Accept-Language`, else the i18n service's default. - `packages/rest/src/meta-item-read-gate.ts:3208` `metaRequestLocale`: `Accept-Language`, then `?locale=`, then `i18n.getDefaultLocale()`. `:3538` `translateMetaList` returns the items untranslated when no locale resolves; `:3286` `metaTranslateOptions` adds the i18n fallback locale as the lookup chain. - `packages/spec/src/system/i18n-resolver.ts:1907` maps `dataset` to `translateDataset` (`:2626`); `translateDatasetMembers` (`:2545`, label lookup `:2562`) writes the bundle string over `member.label` when the bundle answers, an inline map included (the doc block's "An inline locale map is never changed" sentence: the catalog applies to it). `localeChain` (`:649`) is the caller's locale plus the fallback chain. - Executor: `packages/services/service-analytics/src/dataset-tools.ts:365` loads through the transport's `loadDatasets`; `:439` hands the loaded (translated) members to `matchDatasetTerms`. The matcher (`dataset-term-matcher.ts`, `labelTargets`) reads a string or each value of an inline map and never reads a bundle. - stdio: `packages/mcp/src/stdio-data-bridge.ts:1431`-`1458` runs the same `translateMetaList`, with `requestLocale` at `:1453` = `metaRequestLocale(undefined, i18n)`, the i18n service's default locale. This landed with #34833 (commit `6320abba`), the change made for card #34787. </details> ## Tests No behaviour change, so no new test and no ablation. At head `233683d6`: <details><summary>Typecheck and tests, service-analytics</summary> - `pnpm --filter '@objectstack/service-analytics^...' build && pnpm --filter @objectstack/service-analytics run typecheck` (under the verify lock): `VERDICT command-exit 0`, `tsc --noEmit` clean. - `pnpm --filter @objectstack/service-analytics test` (under the verify lock): `Test Files 218 passed (218)`, `Tests 5548 passed | 335 skipped (5883)`, `VERDICT command-exit 0`. </details> ## Acceptance notes - **The dispatch's stdio premise did not hold at the base.** The dispatch said the stdio transport's `loadDatasets` applies no translation step. At `ab441988` it does: #34833 (`6320abba`) made it run the HTTP door's `translateMetaList` for the i18n service's default locale. The note states what the code does: on stdio the bundle label in the workspace default locale is a target, and an inline map's every locale is a target. - **Bundle replaces, it does not add.** The ruling's words are "every locale of an inline label map, plus the bundle label in the caller's locale". In the code, a member that has both an inline map and a bundle entry for the caller's locale is served the bundle string alone. The note says so instead of implying both are targets for one member. This is the ruling's own recorded consequence (an English source label stops matching under a translated locale), stated one step more generally. - **Overlap.** Open draft PR #34904 (#34763) touches `dataset-term-matcher.ts` too. `overlap-check` merges it cleanly with this branch. - **Changeset: none, with the `skip-changeset` label.** The diff is an ADR (not published) plus doc comments in a published package. That is the fast lane's comment-only case, so nothing ships. An empty changeset was ruled out on purpose: `check-empty-changeset` refuses a new one. ## Verification At head `233683d6`, change set derived by `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` (2 paths vs merge base `ab4419881`): 54 local commands run, 52 exit 0, 2 NOT MEASURED (prerequisites, not red). `--ran` reconciliation: `54 derived famil(ies) accounted for — 54 run, 0 UNRUN`. <details><summary>Selected verdict lines</summary> - `pnpm check:adr-symbol-anchors` exit 0: `✅ check-adr-symbol-anchors: 3740 anchors across 158 records resolve` - `node scripts/check-adr-links.mjs` exit 0: `✅ check-adr-links: 1150 relative link destination(s) under docs/adr/ resolve` - `pnpm check:adr-index` exit 0: `adr-index --report: OK — docs/adr/README.md is current` - `pnpm check:adr-anchors` exit 0 - `pnpm check:nul-bytes` exit 0: `check-nul-bytes: OK (scanned 25983 text file(s) ... no raw ASCII control bytes)` - `node scripts/check-issue-citations.mjs` exit 0: `✅ check-issue-citations: no issue citations added against ab44198 (1 file(s) read)`; `pnpm check:issue-citations` (self-test) exit 0 - `pnpm check:doc-authoring` exit 0 - `node scripts/pm/overlap-check.mjs --branch=HEAD` exit 0: `VERDICT clean exit 0` (origin/main `13e0305c33` and #34904) - NOT MEASURED: `node scripts/check-plugin-teardown-shape.mjs --self-test` exit 3, reason: its fixture is pinned to commit `621a4876`, which this shallow checkout cannot reach (checker health only, cannot judge this diff). `pnpm check:dual-build-cjs-loads` exit 3, reason: `PREREQUISITE NOT MET`, no full `pnpm build` in this worktree. CI runs both. </details> The repo-wide runs (`pnpm lint`, the full `check:*` farm, `Test Core`) are CI's. ## Fix round 1 Head `4b963c98` answers the seat's L2 record (comment 6954921504, S1, with N1 to N3 folded in) and the L1-c ACCEPT's note N1 (comment 6954336709), which made the same point as S1. Prose only: no statement, type or export changes. The body's What changes bullet and the 维护者速读 line above were edited to match. - **S1, the bundle label's locale chain.** The note had said a bundle label matches in "the caller's locale only" and that "the bundle's values in other locales are not" targets. The resolver says otherwise. `lookupDatasetMemberAttr` walks `localeChain`: first the requested locale, read through `pickData` / `resolveBundleLocale` (exact, case, platform table language, base language, variant expansion), then the deployment's declared fallback locale. `metaTranslateOptions` supplies that fallback from `getFallbackLocale()`, and `localeChain` skips it when the caller's locale is the authored one (`getSourceLocale()`, else `getDefaultLocale()`). The note's bundle point now states that chain, says one value is served per member and only that value is a target, and replaces the clause with "no other bundle value is". It gives two worked cases. A `zh-TW` caller against a bundle whose only Chinese locale is `zh-CN` is served the `zh-CN` label: `resolveLocaleAmong` step 5, variant expansion. A `fr` caller in a deployment authored in another language, with declared fallback `en`, is served the `en` label when the bundle has no French one. The bold lead now reads "the one translation-bundle label resolved for the caller's locale". New anchors: `i18n-resolver.ts#lookupDatasetMemberAttr`, `i18n-resolver.ts#resolveBundleLocale`, `meta-item-read-gate.ts#metaTranslateOptions`. The matcher's module comment mirrors the chain in one clause, and its `MatchableMember.label` comment says "resolved for", not "resolved to". - **N1, the HTTP pair-translation corner.** When no i18n service resolves, stdio has no locale (`metaRequestLocale(undefined, undefined)` is `undefined`), so `translateMetaList` returns the items untranslated. HTTP is different: `Accept-Language` still yields a locale, and `pairTranslationBundleOf` reads a declared override's pair bundle from the protocol. `translateDataset` then applies it through `labelCatalogs`. The note now names that one exception (anchor `meta-item-read-gate.ts#pairTranslationBundleOf`). - **N2, other doors.** The note adds one sentence. Any other door to the same executor, cloud's service-ai `ToolRegistry` (D2) among them, supplies the executor's `loadDatasets` itself and owes the same translation step. The contract it points to is `dataset-tools.ts#DatasetToolsDeps`, whose `loadDatasets` doc already says "localized at the metadata boundary for the caller's locale". No repository beyond those the ADR already names is cited. - **N3, the PR in the note header.** The header now says "PR #34928" instead of "this PR". That is ADR-0011's note form, minus the commit, which does not exist before merge. <details><summary>Fix round 1 verification, head 4b963c9</summary> - Named gates, each exit code captured before any pipe: `pnpm check:adr-symbol-anchors` exit 0, `✅ check-adr-symbol-anchors: 3745 anchors across 158 records resolve` (3740 at round 0, plus the five new anchors). `pnpm check:adr-links` exit 0, `1150 relative link destination(s) under docs/adr/ resolve`. `pnpm check:adr-index` exit 0, `docs/adr/README.md is current`. `pnpm check:adr-anchors` exit 0. `pnpm check:doc-authoring` exit 0. `pnpm check:nul-bytes` exit 0, `no raw ASCII control bytes`. `pnpm check:issue-citations` (self-test) exit 0. `node scripts/check-issue-citations.mjs` exit 0, `no issue citations added against ab44198 (1 file(s) read)`. - `pnpm --filter '@objectstack/service-analytics^...' build`, then `pnpm --filter @objectstack/service-analytics typecheck`, both under the verify lock: `VERDICT command-exit 0` each, `tsc --noEmit` clean. - Derived families: `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` gave 54 commands, all run. 52 exited 0. 2 are NOT MEASURED for the same reasons as round 0, both prerequisites and not reds. `check-plugin-teardown-shape --self-test` exited 3: the fixture commit `621a4876` cannot be reached from this shallow checkout. `check:dual-build-cjs-loads` exited 3 with `PREREQUISITE NOT MET`: there is no full build here. `--ran` gives `54 derived famil(ies) accounted for — 54 run, 0 UNRUN`. The derivation warned STALE TREE: this branch is 11 commits behind `origin/main`, and `dispatch-gates.mjs` and its data file changed in that range. CI derives on its own tree. - `node scripts/pm/overlap-check.mjs` exit 0: `VERDICT clean exit 0`, against origin/main `46991d0e` and #34904. - No test or ablation: the matcher's code lines are unchanged. </details> ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (Not touched.) - [x] 2. Every name I added uses the casing for its kind. (No names added.) - [x] 3. No formatter ran; `pnpm lint` passes. (Left to CI.) - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. (Publishes nothing: `skip-changeset`.) - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. (Not touched.) - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English (the 维护者速读 block is Chinese by the dev agent's rule). - [x] The *Before Submitting* list in CONTRIBUTING.md is done, with the repo-wide runs left to CI as stated above. --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufzg1NmbJpZhtiWQkTir)_ <!-- signed: repo:objectstack#3 · os-support-ai · session_01WGufzg1NmbJpZhtiWQkTir --> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
1 parent e556e3a commit 9e71ef8

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

‎docs/adr/0149-ai-answers-business-questions-through-the-dataset-semantic-layer.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,16 @@ Both `DatasetMeasureSchema` and `DatasetDimensionSchema` gain two optional keys.
149149
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).
150150

151151
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).
152+
153+
> **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`.**
154+
> 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.
155+
>
156+
> - **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).
157+
> - **A bundle label: one value, resolved for the caller's locale (option A).** A label the translation bundle carries (`datasets.<name>.dimensions.<d>.label`, `.measures.<m>.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.
158+
> - **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.
159+
> - **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.
160+
> - **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.
161+
152162
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.
153163
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.)
154164
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.

‎packages/services/service-analytics/src/dataset-term-matcher.ts‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,19 @@ import { normalizeDatasetTerm } from '@objectstack/spec/ui';
1717
* dataset schema's own vocabulary validation uses (NFKC, case-fold, trim,
1818
* collapse whitespace, `_` and `-` folded to a space) — and EQUALITY is a hit.
1919
* A substring, a stem or a near neighbour is not a hit. The match targets are
20-
* the member's `name`, its `label` in every locale of an inline map, and each
21-
* of its `synonyms`.
20+
* the member's `name`, its `label` in every locale of an inline map, plus the
21+
* one translation-bundle label resolved for the caller's locale, and each of
22+
* its `synonyms`; a word in another language hits only as an authored synonym
23+
* (ADR-0149 D3 rule 1's amendment note, ruled 「A+C 本语言标签+同义词」).
24+
*
25+
* This function never reads the bundle: the transport localizes the catalogue
26+
* before it runs (the HTTP door for the request's locale, stdio for the i18n
27+
* service's default), and where the bundle answers for a member that value is
28+
* the `label` handed in, in place of the authored string or inline map. The
29+
* value is resolved along the resolver's locale chain (the requested locale by
30+
* the platform locale ladder, variant expansion included, then the
31+
* deployment's declared fallback locale, skipped when the caller's locale is
32+
* the authored one); no other bundle value is a target.
2233
*
2334
* Rules 2–5 (one hit wins, several hits ask, no hit falls back to the object
2435
* query labelled 「非指标口径」, a dimension hit alone is no answer) are the
@@ -33,7 +44,10 @@ import { normalizeDatasetTerm } from '@objectstack/spec/ui';
3344
/** A member's match targets, as the dataset declares them. */
3445
export interface MatchableMember {
3546
readonly name: string;
36-
/** A string, or an inline locale map (every locale is a target). */
47+
/**
48+
* A string, or an inline locale map (every locale is a target); a bundle
49+
* label arrives already resolved for the caller's locale, as a string.
50+
*/
3751
readonly label?: unknown;
3852
readonly synonyms?: readonly unknown[];
3953
}

0 commit comments

Comments
 (0)