Repository navigation
Commit e542b7b
feat(service-analytics): a word that names the field a filtered measure candidate sums is answered from that field (ADR-0149 D3 note of 2026-12-01) (#38869)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} -->
_Requested by **Yibo Wang** · [project
thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBG4YD4RMAt72Ga5PdYYZDAQ)_
Fixes #38551
Clause-②: no
Metadata-protocol: none
PR #38848 (ADR note) merged; origin/main is merged in at cabeb27 and
the ADR-0149 blob at HEAD equals main's (0d752a3).
Claim for this branch: #38551 comment 7305144268 (PR 2 of claim
7301418387).
## 维护者速读
- 用户在问数时说的词正好是某个带筛选条件的指标所汇总的字段(例如「工时」对「计费工时」),AI
不再反问,而是直接按该字段回答并注明非指标口径,顺带提一句那个更窄的指标;两个 MCP 入口(HTTP 与 stdio)行为一致。
- 属于「AI 通过数据集语义层回答业务问题」的 ADR-0149 修订落地,替云端去掉它自己那份重复的下一步逻辑,解决正式基线里不必要的反问。
-
若判断出错,最坏是某个词本该反问却被按字段回答(或反之);不带筛选的指标、跨关联路径的字段、一个词同时指向两个字段,这三种情况都保持原来的反问;改动可整体撤回,不涉及数据或元数据格式。
- ADR 修订那个 PR(#38848,定义本改动所依据的规则)已合并,且三个子问题按默认答案落定;本 PR 已合入最新
main,按合并后的规则文本实现。
## What changes
Implements the ADR-0149 D3 amendment note of 2026-12-01 (PR #38848,
ruling record 7301332152: "A measure candidate whose aggregated field is
named by the term is not offered as a candidate to ask back about. The
field answers the term under rule 4's labelled fallback, and the measure
is mentioned as a narrower declared metric."), with the zone's two later
narrowings: only a measure that carries a `filter` is taken out (L2 S2
on #38848), and the reading is per candidate (L1 N4 on #38848).
- **Executor**
(`packages/services/service-analytics/src/dataset-term-matcher.ts`,
`readDatasetTerms`). For a term with no hit, the whole near set is built
uncapped; a measure candidate that carries a `filter` and whose
aggregated BASE field the term names (the term equals, or is inside, the
field's label in any label handed in, or its name; both sides normalized
as rule 1 normalizes) is taken out, and the field is reported
(`namedFields`). Then the per-term cap applies to what is left.
`findDatasetTermCandidates` keeps its signature and returns the
candidates of the same reading.
- **Sentence** (`dataset-next-step.ts`). No new decision value and no
new key. A term left with nothing is `no_measure`, its note naming the
field (object and field name) and mentioning the measure as a narrower
declared metric, then the labelled fallback tail. A term left with only
dimensions stays `candidates_only`: the field sentence, the dimensions
offered as a possible grouping, and no outright question on its account;
beside a grouping word the conditional sentence of the note of
2026-11-24 is still written (L2 S1). A term left with another measure
candidate is asked about what is left, and one more sentence says the
field answers only when that question settles nothing. Written in all
four locales.
- **Labels, route A** (`DatasetToolsDeps.readFieldLabel`, optional).
Both hosts wire it from the object `describe_object` serves, as this
caller is served it: the authored label, and the same object through the
`/meta` object translation for the answer's locale (the bundle label).
HTTP: `packages/runtime/src/domains/mcp.ts`, `datasetFieldLabelRead`
(`readServedObject` → `servedToCaller` → `inCallerLocale`, each object
read once per request), passed to `datasetToolMembers`. stdio:
`packages/mcp/src/stdio-data-bridge.ts` (`servedView.getObject` →
`inServedLocale` for the i18n default locale). The executor reads a
label only for a base field that a measure near a sent term aggregates,
once per field per answer; a host that omits the member, or a read that
throws, tests the field's name only, and the `list_datasets` description
says so.
- **Texts.** `LIST_DATASETS_DESCRIPTION` and `DATASET_SELECTION_RULE`
carry one sentence in the same words (pinned equal); the spec's
`candidates` and `nextStep.note` descriptions and the
`DatasetTermCandidateSchema` doc say it (descriptions only, no shape
change; `content/docs/references/ai/dataset-tools.mdx` regenerated by
`check:generated --fix`); `content/docs/data-modeling/analytics.mdx`
gains one bullet.
**Defaults named for the seat** (not decided by the ADR, set by the
zone): a measure over a relationship path (`account.amount`), `*` or no
field is never taken out and keeps today's ask (base fields only; no
label is read for it). Not covered by the note and kept as today: a term
naming different fields through different candidates (nothing is taken
out; the field set is counted over every named measure, filtered or
not), and a measure with no `filter` over the named field (it stays a
candidate and is asked about).
## Tests
- New
`packages/services/service-analytics/src/__tests__/dataset-term-names-field-38551.test.ts`,
every case reading `decision`, `note` and `candidates`: the card's 工时
case (bundle label over an English-authored field), the host-omission
control, a throwing read, 销售 near 销售额 over 金额 still `candidates_only`
with the ask note, the unfiltered measure kept, "Billable hours" taken
out beside "Total hours" kept (per candidate), dimension-only candidates
byte-identical with and without the label read, dimensions left, another
measure left, two fields not covered, take-out before the cap, a
relationship-path measure, a left-out field word beside a `one_measure`
word, the grouping-word case (L2 S1), the description (15 cases).
- `packages/runtime/src/mcp-dataset-tools-bridge.test.ts` and
`packages/mcp/src/stdio-data-bridge.dataset-locale.test.ts`: each host's
read answers `{ authored: 'Hours', translated: '工时' }` from the object
`describe_object` serves; over the REAL executor 工时 is `no_measure` with
no candidate; the control (no zh-CN field label / an `en` default) keeps
`candidates_only` with the ask.
- `packages/mcp/src/initialize-selection-rule-34686.test.ts`: both doors
carry the field sentence in the same words.
- The two 金额 pins in `dataset-tools.test.ts` keep their reading
unchanged (fixture measures are unfiltered and `amount` is on two
objects).
<details><summary>Readings at 61388b8 (revision 1; round-1 readings
below where unchanged)</summary>
- At 61388b8, after the merge of origin/main 2af3d78:
service-analytics full test 229 files, 5935 passed / 345 skipped;
typecheck exit 0; `dataset-term-names-field-38551.test.ts` 15 passed;
mcp tools-list-weight + initialize-selection-rule +
stdio-data-bridge.dataset-locale + mcp-dataset-tools 4 files, 61 passed;
runtime mcp-dataset-tools-bridge 16 passed; spec `check:generated` green
after `--fix`; 117 of 120 derived gates run and exit 0 (3 left to CI on
a missing prerequisite).
- S1 ablation (`!numberNamed` re-inserted on each `noNumberTail`
condition): 1 of 15 red in each branch; restored to the HEAD blob.
- `vitest run src/__tests__/dataset-term-names-field-38551.test.ts
src/__tests__/dataset-tools.test.ts` (service-analytics, at d33cb9b):
2 files passed, 110 passed / 10 skipped.
- `pnpm --filter @objectstack/service-analytics test` (at 68254f1;
only description text and one test case changed since): 229 files
passed, 5933 passed / 345 skipped. `typecheck`: exit 0.
- `vitest run src/tools-list-weight-34689.test.ts
src/initialize-selection-rule-34686.test.ts` (mcp, at d33cb9b): 2
files, 18 passed. Full `@objectstack/mcp` suite at 68254f1: 88 files
passed, 1 failed (`tools-list-weight-34689`, 39002 over the 39000
ceiling) — fixed at d33cb9b by a shorter host clause, re-run green.
`pnpm --filter @objectstack/mcp typecheck`: exit 0.
- `vitest run src/stdio-data-bridge.dataset-locale.test.ts` (mcp): 16
passed. `vitest run src/mcp-dataset-tools-bridge.test.ts` (runtime): 16
passed. `pnpm --filter @objectstack/runtime typecheck`: exit 0 (after
building `@objectstack/driver-turso`, a devDependency the worktree had
not built).
- `pnpm --filter @objectstack/spec check:generated`: "All 14 generated
artifacts are up to date" after `--fix` regenerated
`content/docs/references/ai/dataset-tools.mdx`.
- Ablation 1 (the take-out set emptied, `scripts/ablation-replace.mjs`,
restored to the HEAD blob with `git diff HEAD` empty): 7 of 13 cases
red. Ablation 2 (the `filter` condition removed, every named measure
taken out): 1 red, the unfiltered-measure case. Both restored.
- `tools/list` weight (open door, 18 tools): before 38569 bytes,
`list_datasets` description 2567; after 38940 bytes, description 2938
(+371); ceiling 39000 unchanged.
</details>
## Acceptance notes
- H1 (route A): HTTP reads the authored label off
`servedToCaller(readServedObject(object))` and the bundle label off the
same object through `inCallerLocale` (`translateMetaList` over `object`,
`metaTranslationSources`, the locale `loadDatasets` translates for).
stdio reads them off `servedView.getObject(object)` and `inServedLocale`
(the i18n service's default locale).
- H2: the take-out runs before the cap; pinned by "the take-out runs
over the uncapped near set".
- Skill text this makes stale is left to a `domain:skills` card (no
`skills/**` edit here): `skills/objectstack-ask/SKILL.md` step 1's
candidates bullet and step 2's table rows,
`skills/objectstack-ask/evals/metric-selection-fallback.json`, and the
regenerated `packages/mcp/src/ask-skill.generated.ts`.
## Verification
Read first, by risk:
`packages/services/service-analytics/src/dataset-term-matcher.ts`
(`readDatasetTerms`, the take-out set and the cap loop);
`packages/services/service-analytics/src/dataset-next-step.ts`
(`readTerm`, the `candidates_only` branch, `leftOutSentences`);
`packages/runtime/src/domains/mcp.ts` (`datasetFieldLabelRead`).
Two-minute check: `pnpm --filter @objectstack/service-analytics exec
vitest run src/__tests__/dataset-term-names-field-38551.test.ts` —
expect 15 passed.
Signed: repo:objectstack@os-support-ai · os-support-ai ·
session_01WGufzeatqKfTRUzTJVa9jQ
---
_Generated by [Claude
Code](https://claude.ai/code/session_01WGufzeatqKfTRUzTJVa9jQ)_
<!-- signed: repo:objectstack@os-support-ai · os-support-ai ·
session_01WGufzeatqKfTRUzTJVa9jQ -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 475277b commit e542b7b
14 files changed
Lines changed: 1090 additions & 43 deletions
File tree
- .changeset
- content/docs
- data-modeling
- references/ai
- packages
- mcp/src
- runtime/src
- domains
- services/service-analytics/src
- __tests__
- spec/src/ai
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
200 | 210 | | |
201 | 211 | | |
202 | 212 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| |||
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
259 | | - | |
| 259 | + | |
260 | 260 | | |
261 | 261 | | |
262 | 262 | | |
| |||
286 | 286 | | |
287 | 287 | | |
288 | 288 | | |
289 | | - | |
| 289 | + | |
290 | 290 | | |
291 | 291 | | |
292 | 292 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
254 | 254 | | |
255 | 255 | | |
256 | 256 | | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
257 | 277 | | |
258 | 278 | | |
259 | 279 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1893 | 1893 | | |
1894 | 1894 | | |
1895 | 1895 | | |
1896 | | - | |
| 1896 | + | |
| 1897 | + | |
| 1898 | + | |
| 1899 | + | |
1897 | 1900 | | |
1898 | 1901 | | |
1899 | 1902 | | |
| |||
1912 | 1915 | | |
1913 | 1916 | | |
1914 | 1917 | | |
1915 | | - | |
| 1918 | + | |
| 1919 | + | |
| 1920 | + | |
| 1921 | + | |
1916 | 1922 | | |
1917 | 1923 | | |
1918 | 1924 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
0 commit comments