Skip to content

Commit e25207d

Browse files
fix(service-analytics): list_datasets asks nothing when a word that falls back stands beside a grouping word (#36509)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9JpRoUZGqtwqMU5k7b4C58D)_ Part of #34996. The card stays open: the 5-rep round that keeps or drops this change set is the eval seat's, and the ask-back over a single measure candidate is ruled behaviour this PR leaves as it is (see Acceptance notes). Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:用 AI 问数的人问「各状态的销售订单各有多少」这类问题时,助手以前会停下来反问「你想看哪个数字」,现在直接按记录统计并注明这不是指标口径的数。 - 为什么做:属于「AI 问数」专题;最近一轮样板应用验收里,助手反问过多是丢分最多的一项。 - 出错会怎样:最坏情况是助手在本该先问清楚的时候直接给出一个按记录统计的数,答案里带着「非指标口径」的标注;撤回这一个改动即可恢复原样。 - 要你做什么:评测席跑完一轮五次重复的问数评测并确认有效之后,审批这份对外发布的技能文字。 ## What changes One over-asking path, measured and fixed at its root, plus one term-lifting line. A question that names its number ("How many sales orders are in each status?") was asked back "which number do you mean?" whenever its grouping word equalled, or was near, a dataset dimension and no dataset measure answered to the number word. One object answers that question through the labelled fallback; the served text said to fall back and to ask in the same breath, and a careful client asked. **The served sentences, and why each reads as "ask" when one object matches** | Where it is served | Sentence on `main` | Why it over-triggers | |:--|:--|:--| | `list_datasets` answer, `nextStep.note` (`dataset-next-step.ts`, the `groupingTail` copy, four locales) | "A grouping alone is no answer: ask the user which number they mean." | Written whenever a grouping word had no measure word matched beside it, also when another word in the same call falls back. The note then held "Answer with the object query tools ..." and this sentence together. The grouping is not alone there. | | `list_datasets` tool description (`dataset-tools.ts`) | "A dimension match alone picks a grouping, not a number: a measure must still match." | "a measure must still match" reads as a stop when the number word matched nothing, where the rule two sentences earlier says to fall back. | | Published skill, step 2 (`skills/objectstack-ask/SKILL.md`, served again by `GET /mcp/skill`) | "Only a dimension matches: That is a grouping, not a number. Without a measure match, ask which number is meant." | "Only a dimension matches" is literally true of a call whose number word matched nothing and whose grouping word matched, so this row and the fallback row both apply, and this one says ask. | | Published skill, step 1 | "A term is the noun phrase for the thing, kept whole (travel budget, not travel and budget)" | It does not say a counting head is part of the phrase. The eval reading on the card (4 of 4 runs): "number of claims", a declared synonym of one measure, was sent as "claims", which equals nothing and comes back near two measures, so the client rightly asked. | **The fix** - `composeDatasetNextStep` writes the "which number" sentence only when every word sent is a grouping (it equals a dimension, or has only dimensions among its candidates). With an unknown word beside it (no measure, no dimension, no candidate) the note carries that word's labelled fallback and no question. Two branches change: the `no_measure` note, and the `candidates_only` note whose reported words are all possible groupings. `decision`, `terms`, `matches` and `candidates` are untouched. Round 2 (head `4342cf009`, after L2 record 7081905010 S1) adds one copy key, `noNumberTail`, in four locales: beside such a fallback the note ends with "Only when the question has no word for a thing measured, ask the user which number they mean instead." The executor sees words, not which one names the number, so the client judges; the outright question stays for a call whose every word is a grouping, and is never written beside a fallback sentence. - The tool description now reads: "A dimension match picks a grouping, not a number: when the question has no word for a thing measured, ask which number is meant; beside a word for a thing measured that falls back, ask nothing and take the fallback." The `dataset-next-step.ts` jsdoc states the executor's presumption and where it is wrong. - Skill step 2: the row becomes "No word for a thing measured, only grouping or filter words", and the fallback row reads "Step 4, without asking: a grouping word's match, or another word's, is no reason to ask." The clause under the table that said the same of another word's matches is cut, since the row now holds it. - Skill step 1: the kept-whole example gains a counting head ("number of deals", not "deals"). - `packages/mcp/src/ask-skill.generated.ts` is regenerated by `scripts/gen-mcp-ask-skill.mjs`, never hand-edited. - Eval cases 21 to 24 in `skills/objectstack-ask/evals/metric-selection-fallback.json`: the fallback beside a grouping candidate (quoting the note as the executor now writes it), the fallback beside a dimension match, the whole counting phrase as the first call, and (case 24, round 2) a grouping plus a filter word with no word for a thing measured, where the reply is the which-number question alone. Round 2 rewords the forbidden tokens of cases 21 to 23 to the question as put to the user and the cut-down word as a term sent; a grader proof ran 13 of 13 checks as wanted. **What does not change, on purpose** - A word that equals several measures is still asked about; a word with a measure among its candidates is still asked about and never selected, a single candidate included (ADR-0149 D3 and its notes of 2026-11-17 and 2026-11-19). Their pins stay green and one new pin holds the candidate question beside an unknown word. - The MCP `initialize` rule (`DATASET_SELECTION_RULE`, `mcp-server-runtime.ts`) is not edited: read sentence by sentence, it asks only in those two ruled cases and says "No match and no candidates: fall back". It carries no dimension-alone sentence. - A grouping word alone ("by stage", "this quarter") still asks which number is meant (D3 rule 5). **Read first** (by risk) 1. `packages/services/service-analytics/src/dataset-next-step.ts`: the two conditions in `composeDatasetNextStep` (`candidates_only` and `no_measure`), and the header section "A grouping beside a word that falls back asks nothing". 2. `skills/objectstack-ask/SKILL.md`: step 2 rows five and six, and the cut clause in the paragraph under the table. 3. `packages/services/service-analytics/src/dataset-tools.ts`: one sentence of `LIST_DATASETS_DESCRIPTION`. **Skill size** (governed catalog; growth is paid by deletion in the same file) | Reading | Before | After | |:--|:--|:--| | `skills/objectstack-ask/SKILL.md` lines | 128 | 127 | | `skills/objectstack-ask/SKILL.md` tokens (the ratchet's count; ceiling 1877, not moved) | 1875 | 1875 (round 1: 1872) | | All 14 `SKILL.md` files, lines | 4950 | 4949 | | Ratcheted authored tokens, whole catalog | 197507 | 197504 | | `evals/metric-selection-fallback.json` (eval fixture, measured, not ratcheted): lines, tokens | 205, 7007 | 235, 8425 | | Bundle total tokens (whole shipped tree) | 290262 | 291677 | Added to the skill: the counting-head example (+32 bytes) and the two reworded rows (+75). Deleted: the clause "; when their word matched nothing and has no candidates, go to step 4 instead of asking about some other word's matches" (-119), whose content the fallback row now carries. Net -12 bytes at round 1 (7520 to 7508); round 2 adds " or filter words" to row five: 7518 bytes, 1875 tokens, headroom 2. ## Tests **Measured: what `list_datasets` serves for the gallery's failing questions.** The scenario cards pin their datasets, so the real matcher, candidate finder and note composer were run over `docs/qa/scenarios/order_to_cash.json` and `travel_expense.json` (a scratch script, one node process, locale `en`), at base `59392ed1d` and at head `6c5c5e2ae`. The terms are this author's lifting of each question by the skill's step 1, not a recording: the gallery recordings are not readable from this container. | Question (card item) | Terms sent | Note at base | Note at head | |:--|:--|:--|:--| | "How many sales orders are in each status?" (`orders_by_status`) | sales orders, status | `candidates_only`: offers Order status as a possible grouping, then "A grouping alone is no answer: ask the user which number they mean.", then the fallback for "sales orders" | the same note without the question | | the same, grouping word as the dimension is labelled | sales orders, order status | `no_measure`: "Answer with the object query tools ..." and "A grouping alone is no answer: ask the user which number they mean." | the fallback sentence only | | "How does the outstanding balance break down by aging bucket?" (`receivables_aging`) | outstanding balance, aging bucket | `no_measure`: fallback and the question, both | the fallback sentence only | | "number of claims ... by status" (`claims_by_status`, the eval reading) | claims, status | `candidates_only`: Claimed amount and Claim count offered, asked about (correct for that word) | unchanged | | the same, counting head kept | number of claims, status | `one_measure`: Claim count, computed, status offered as a grouping | unchanged | | "how much has been booked per product category" (`booked_by_category`) | booked, product category | `candidates_only`: one measure candidate (Booked amount), asked about | unchanged, by ruling | <details><summary>The three notes that changed, in full (base, then head)</summary> ```text terms ["sales orders","status"] base: "status" matches no member exactly; it may name a grouping: Order status (dataset: Order book). A possible grouping is not a question: do not ask the user about it, and it does not stop a matched measure; group the answer only as the question asks. A grouping alone is no answer: ask the user which number they mean. "sales orders" equals no measure and has no possible reading. For those words, use the object query tools (query_records, aggregate_records) and say in the answer that no governed metric was used for them. head: "status" matches no member exactly; it may name a grouping: Order status (dataset: Order book). A possible grouping is not a question: do not ask the user about it, and it does not stop a matched measure; group the answer only as the question asks. "sales orders" equals no measure and has no possible reading. For those words, use the object query tools (query_records, aggregate_records) and say in the answer that no governed metric was used for them. terms ["sales orders","order status"] base: "sales orders" equals no measure and has no possible reading. "order status" equals a grouping, not a number: Order status (dataset: Order book). Answer with the object query tools (query_records, aggregate_records) and say in the answer that no governed metric was used. A grouping alone is no answer: ask the user which number they mean. head: "sales orders" equals no measure and has no possible reading. "order status" equals a grouping, not a number: Order status (dataset: Order book). Answer with the object query tools (query_records, aggregate_records) and say in the answer that no governed metric was used. terms ["outstanding balance","aging bucket"] base: "outstanding balance" equals no measure and has no possible reading. "aging bucket" equals a grouping, not a number: Aging bucket (dataset: Billing). Answer with the object query tools (query_records, aggregate_records) and say in the answer that no governed metric was used. A grouping alone is no answer: ask the user which number they mean. head: "outstanding balance" equals no measure and has no possible reading. "aging bucket" equals a grouping, not a number: Aging bucket (dataset: Billing). Answer with the object query tools (query_records, aggregate_records) and say in the answer that no governed metric was used. ``` Of 22 term sets tried over the two cards, these 3 changed and 19 are byte-identical at base and head. </details> **Round 2, at head `4342cf009`** (under the verify lock unless said): service-analytics `dataset-tools.test.ts` 95 passed | 10 skipped; package suite 5730 passed | 345 skipped (224 files), typecheck exit 0; mcp typecheck exit 0; mcp suite 1466 passed with 1 failed on two runs, the failure being `mcp-file-tools.test.ts` "a worker past its wall-clock ceiling is terminated" (a 200 ms load-sensitive worker-pool test this diff does not reach; 54 of 54 alone, green on CI). Ablations through `scripts/ablation-replace.mjs`, restore proven by blob: the closing condition dropped from `no_measure` (2 red) and from `candidates_only` (1 red); the outright question written beside a fallback again in `candidates_only` (1 red) and `no_measure` (2 red), the vitest red legs round 1 left NOT MEASURED. A fifth (condition written with no grouping beside the unknown word) was read by a single-process probe (red in 4 locales, restored green); its vitest leg is NOT MEASURED, the lock not obtained. `gen-mcp-ask-skill.mjs --check` exit 0; skill-evals `--dry-run` 31 cases. The round 1 readings below are kept as measured at `6c5c5e2ae`. All at head `6c5c5e2ae`, each under the shared verify lock, exit read from the lock's VERDICT line. - `pnpm --filter @objectstack/service-analytics test`: `Test Files 224 passed (224)`, `Tests 5729 passed | 345 skipped (6074)`; `pnpm --filter @objectstack/service-analytics typecheck`: exit 0. VERDICT command-exit 0. - `pnpm --filter @objectstack/mcp test` (after rebuilding `@objectstack/service-analytics` and `@objectstack/mcp`, since the MCP pins read the description from the built package): `Test Files 83 passed (83)`, `Tests 1467 passed (1467)`; `pnpm --filter @objectstack/mcp typecheck`: exit 0. VERDICT command-exit 0. This run holds `skill-single-source-34686.test.ts` (the generated mirror equals the skill) and `initialize-selection-rule-34686.test.ts` (the sentence the two doors share is unchanged). - New and changed pins, in `packages/services/service-analytics/src/__tests__/dataset-tools.test.ts`: the mixed `no_measure` note falls back and asks nothing, in four locales, with the lone grouping word as the same-locale control; a grouping candidate beside an unknown word falls back and asks nothing, with a lone candidate and two groupings as controls that still ask; an unknown word beside a measure candidate keeps the question about that candidate. - Eval file: `pnpm --filter @objectstack/scenarios skill-evals --dry-run --skills objectstack-ask`: exit 0, "objectstack-ask: 30 case(s)", "23 behaviour case(s) × 2 arms + 7 trigger case(s)", "dry run: no login read, no model called, nothing written". By script: ids 1 to 23 distinct, each new case holds every `must_contain` token in its expected output and no `must_not_contain` token. <details><summary>Ablation: each changed branch, once (narrowed, declared)</summary> The fix was committed first. Each mutation went through `scripts/ablation-replace.mjs` (anchor hit once, blob changed, restore proven: blob equals HEAD `b241cbd65a5a`, `git diff HEAD` empty). - Mutation 1, the `candidates_only` branch back to `if (asked.length === 0)`: the note for a grouping candidate beside an unknown word asks "which number" again in all four locales; the `no_measure` case stays fixed. - Mutation 2, the `no_measure` branch back to writing both sentences: the mixed note asks again in all four locales; the `candidates_only` case stays fixed. - Restored: neither asks, and a lone grouping word still asks, in all four locales. **Narrowing, declared.** The red runs were read through a single-process probe of the composer (the pins' two fixtures and the same sentences, no test runner), not through vitest. The vitest red leg is NOT MEASURED: four attempts to take the verify lock for it each ended `VERDICT queue-timeout (exit 99)` over about 45 minutes while another worktree's full dogfood battery held the lock (pid 17598, alive, held over 70 minutes at the last reading). The green leg of the pins is the package run above. </details> ## Acceptance notes - **The round this PR is waiting for (eval seat).** With-skill arm, ask only, 5 repetitions, haiku medium, `--packages workspace` built from this branch (the note is composed in `@objectstack/service-analytics`, so npm 18.6.0 cannot show it), against the last kept round on `main`. Cards: `travel_expense` (the loop's card; `claims_by_status` is the counting-head item) and `order_to_cash` (`orders_by_status` and `receivables_aging` are the fallback-beside-a-grouping items). Keep when asked-back on ordinary questions falls on those items and the dataset ask-back cases (the several-match and measure-candidate cases) hold at their last kept score; drop otherwise. No model round ran here: NOT MEASURED, reason: paid rounds and the gallery belong to the eval seat. - **Not re-measured wording.** The fallback row's new sentence replaces a clause iteration 2 measured ("go to step 4 instead of asking about some other word's matches"). The meaning is kept and moved into the row; the wording itself is new and unmeasured until the round above. - **What this PR does not move, and why.** The 2026-11-21 gallery reading counts 12 failing ask items. This PR addresses the ones where the number word matched nothing and a grouping word matched or neared a dimension. Items where the number word comes back with one measure among its candidates ("booked" near Booked amount, measured below) are asked about by ruling: a measure candidate is offered for a question and never selected. Changing that is the maintainer's decision, raised in the report's open questions and not taken here. The gallery ran on npm 18.6.0, which also still asks about a word whose candidates are all dimensions; `main` stopped that before this PR. - **The reading of ADR-0149 D3 this rests on, for the contract review.** Rule 4 (no hit: labelled fallback) and rule 5 (a dimension hit without a measure hit is not an answer; the AI still needs a measure hit, or asks) both apply to a call with an unknown number word and a matched grouping word, and the record does not say which governs. `main` wrote both instructions into one note. This PR reads rule 4 as governing the unknown word and rule 5 as the rule for a question with no number word, on M2 ruled A ("answers everything it answers today, and the governed answers are marked"). A reviewer who reads rule 5 as governing the mixed case should stop this PR at review. - **Ratchet row.** The skill file is 1875 tokens at round 2, 2 under its ceiling, as on `main`. The ceiling is not moved. - **Closed in round 2 (L2 S1).** The executor cannot tell which word is the number word. The note beside a fallback now ends with the conditional sentence, row five names filter words, and case 24 covers "by stage for the west region". L2 delta record 7083451259 PASS at `4342cf009`; its nits N3 to N5 are accepted (N5 folds into the ADR-0149 amendment carried by #36086, with the rule-4 reading and the `noNumberTail` sentence). - **New wording, unmeasured by a model.** The conditional sentence puts "ask" back into the note, under a condition. No model round has read it; the eval round above, on this head, is what measures it. ## Verification Two minutes: `pnpm --filter @objectstack/service-analytics exec vitest run --maxWorkers=2 src/__tests__/dataset-tools.test.ts` prints `Test Files 1 passed (1)` and `Tests 95 passed | 10 skipped (105)`. Then `node scripts/gen-mcp-ask-skill.mjs --check` prints "is current with skills/objectstack-ask/SKILL.md", and `node scripts/check-skills-token-ratchet.mjs` prints "skills/objectstack-ask/SKILL.md is 1875 tokens (ceiling 1877; headroom 2)". <details><summary>Gates</summary> - `node scripts/pm/dispatch-gates.mjs --commands` at `6c5c5e2ae` (7 paths vs merge base `59392ed1d`): 83 commands, run serially, each exit code recorded before any pipe. `--ran`: "83 derived famil(ies) accounted for — 81 run, 2 NOT-MEASURED (2 DERIVED from a recorded exit 3)", 0 unrun; the 81 exited 0. - NOT MEASURED: `check:dual-build-cjs-loads` (exit 3, needs a whole-workspace build) and `check:type-check-debt` (exit 3, its re-measure could not take the verify lock). CI carries both. - Named by the dispatch: `node scripts/gen-mcp-ask-skill.mjs --check` exit 0 ("is current with skills/objectstack-ask/SKILL.md"); `node scripts/check-skills-token-ratchet.mjs` exit 0 ("skills/objectstack-ask/SKILL.md is 1872 tokens (ceiling 1877; headroom 5)"). - `node scripts/pm/overlap-check.mjs`: "VERDICT clean exit 0" (origin/main and the one open PR sharing the skill file merge cleanly). - `node scripts/pm/check-governed-merges.mjs --branch HEAD`: exit 3, GOVERNED, Tier H (`skills/**`, 2 paths). This PR stays draft; no reviewer is requested here. - `node scripts/pm/dispatch-gates.mjs --tier`: mandatory contract-review tier for `skills/**`; this change was authored at that tier. A contract-review-tier review is owed before the governed landing. - `test:repo` not run locally (CI owns it; the diff touches no test of that project). </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01ADHkmRY38EZf38Yy3zthbY <!-- signed: repo:objectstack#2 · os-steve · session_01ADHkmRY38EZf38Yy3zthbY --> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
1 parent 45ef94e commit e25207d

7 files changed

Lines changed: 245 additions & 30 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
'@objectstack/service-analytics': patch
3+
'@objectstack/mcp': patch
4+
'@objectstack/skills': patch
5+
---
6+
7+
fix(service-analytics): `list_datasets` no longer tells a client outright to ask "which number" when a word that falls back stands beside a grouping word
8+
9+
Clause-②: no
10+
Metadata-protocol: none
11+
12+
A question such as "How many sales orders are in each status?" names its number. When no dataset measure answers to "sales orders" and none is offered as a candidate, the labelled fallback to the object query tools computes it. Until now the `nextStep` note of such an answer said two things at once whenever the grouping word equalled a dimension, or was near one: answer with the object query tools, and "A grouping alone is no answer: ask the user which number they mean." A client told both asked, and computed nothing.
13+
14+
- **`list_datasets` `nextStep.note`** (`@objectstack/service-analytics`): the "which number is meant" sentence is written only when every word sent is a grouping (it equals a dimension, or has only dimensions among its candidates). With an unknown word beside it, the note carries that word's labelled fallback, then one closing sentence that leaves the question to the case only the client can see: "Only when the question has no word for a thing measured, ask the user which number they mean instead." (the unknown word may be a filter value, as in "break it down by stage for the west region"; the server sees words, not which of them names the number). `decision`, `terms`, `matches` and `candidates` are what they were. Unchanged: a word that equals several measures, and a word with a measure among its candidates (one candidate included), are still asked about and never selected.
15+
- **`list_datasets` description**: the sentence "A dimension match alone picks a grouping, not a number: a measure must still match." now reads "A dimension match picks a grouping, not a number: when the question has no word for a thing measured, ask which number is meant; beside a word for a thing measured that falls back, ask nothing and take the fallback."
16+
- **`objectstack-ask` skill, step 2** (`@objectstack/skills`, and the copy `GET /mcp/skill` serves from `@objectstack/mcp`): the row "Only a dimension matches" becomes "No word for a thing measured, only grouping or filter words", and the fallback row says the fallback is taken without asking, whatever a grouping word or another word matched. The sentence under the table that said the same about another word's matches is cut, since the row now holds it.
17+
- **`objectstack-ask` skill, step 1**: a term keeps its counting head ("number of deals", not "deals"), so a phrase the dataset's owner declared as a synonym is sent whole and can equal its one measure.
18+
- Four eval cases (21 to 24) cover the fallback beside a grouping candidate, the fallback beside a dimension match, the whole counting phrase, and a question with a grouping and a filter value but no word for a thing measured, which is asked which number is meant.
19+
20+
The skill file is 2 bytes shorter than before (1875 tokens by the catalog's count, before and after).

‎packages/mcp/src/ask-skill.generated.ts‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export const ASK_SKILL_DATA_LOOP: string = [
2121
'- Call `list_datasets({ terms })` with those words, as the user wrote them.',
2222
' Do not translate or reword a term: a match on a word',
2323
' you supplied is your reading, not the user\'s. A term is the noun phrase for',
24-
' the thing, kept whole ("travel budget", not "travel" and "budget")',
25-
' and without the verbs, time words',
24+
' the thing, kept whole ("travel budget", not "travel" and "budget";',
25+
' "number of deals", not "deals") and without the verbs, time words',
2626
' and question words around it ("trip days", not "trip days requested";',
2727
' "报销金额", not "报销金额合计是多少").',
2828
'- Each dataset in the answer carries `matches`: one entry per hit, with the',
@@ -43,8 +43,8 @@ export const ASK_SKILL_DATA_LOOP: string = [
4343
'| One word matches several measures, in one dataset or in two | Ask the user which one they mean. List each candidate\'s label, its dataset\'s label and its description. Do not pick one. |',
4444
'| A word with a measure among its `candidates` | Ask the same way; with one candidate, ask whether it is the one meant. |',
4545
'| A word whose `candidates` are all dimensions | At most a possible grouping: never ask about it, and it never stops a matched measure. |',
46-
'| Only a dimension matches | That is a grouping, not a number. Without a measure match, ask which number is meant. |',
47-
'| No match and no candidates for the word for a thing measured | Step 4. |',
46+
'| No word for a thing measured, only grouping or filter words | A grouping is not a number: ask which number is meant. |',
47+
'| No match and no candidates for the word for a thing measured | Step 4, without asking: a grouping word\'s match, or another word\'s, is no reason to ask. |',
4848
'| `membersWithheld: true` on a dataset | Say that it has members (measures or groupings) you may not read; the metric asked for may be among them. Do not say the metric does not exist. |',
4949
'',
5050
'When the answer has `nextStep`, follow its `decision` and `note`. If `note`',
@@ -54,8 +54,7 @@ export const ASK_SKILL_DATA_LOOP: string = [
5454
'answers. State no figure of your own in it (no count, total',
5555
'or option number): name each option by its label in a bullet, and quote its',
5656
'description as written. Ask only about matches or candidates for words the user',
57-
'wrote; when their word matched nothing and has no candidates, go to step 4',
58-
'instead of asking about some other word\'s matches. `partial: true` on the answer means the catalogue may',
57+
'wrote. `partial: true` on the answer means the catalogue may',
5958
'be incomplete; `warning` says why, and you repeat it when you fall back.',
6059
'',
6160
'Use an option only once the user picks it: compute it by its exact name',

‎packages/services/service-analytics/src/__tests__/dataset-tools.test.ts‎

Lines changed: 110 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,24 @@ const ASK_FIRST: Record<string, string> = {
12911291
'ja-JP': '使う前にどれを指しているかユーザーに確認してください。代わりに選ばないでください',
12921292
};
12931293
const FOUR_LOCALES = [ADMIN, { ...ADMIN, locale: 'zh-CN' }, { ...ADMIN, locale: 'zh-TW' }, { ...ADMIN, locale: 'ja-JP' }] as ExecutionContext[];
1294+
/** The question owed outright when every word sent is a grouping (D3 rule 5), by the locale the context names. */
1295+
const GROUPING_ALONE: Record<string, string> = {
1296+
en: 'A grouping alone is no answer: ask the user which number they mean.',
1297+
'zh-CN': '只有分组维度还不能回答:问用户想看哪个数字。',
1298+
'zh-TW': '只有分組維度還不能回答:問使用者想看哪個數字。',
1299+
'ja-JP': 'グループ分けだけでは回答になりません:どの数値を知りたいかユーザーに確認してください。',
1300+
};
1301+
/**
1302+
* The same question as a condition, after the fallback sentence of a note that
1303+
* also names a grouping: the executor cannot tell a word for a thing measured
1304+
* from a filter value, so the client, which read the question, judges it.
1305+
*/
1306+
const ONLY_IF_NO_NUMBER: Record<string, string> = {
1307+
en: 'Only when the question has no word for a thing measured, ask the user which number they mean instead.',
1308+
'zh-CN': '只有当问题本身没有说要看哪个数字时,才改为问用户想看哪个数字。',
1309+
'zh-TW': '只有當問題本身沒有說要看哪個數字時,才改為問使用者想看哪個數字。',
1310+
'ja-JP': '質問そのものがどの数値も指していない場合に限り、代わりにどの数値を知りたいかユーザーに確認してください。',
1311+
};
12941312

12951313
type ListOut = Awaited<ReturnType<ReturnType<AnalyticsService['datasetTools']>['listDatasets']>>;
12961314

@@ -1400,11 +1418,55 @@ describe('[#34919] list_datasets nextStep on examples/app-crm — the decision e
14001418
expect((await ask(['商机数', '商机金额'])).nextStep!.note).toContain('Each is its own metric');
14011419
});
14021420

1403-
it('a mixed no_measure note falls back for the unknown word and still asks which number the grouping word means', async () => {
1404-
const out = await ask(['库存周转', '销售阶段']);
1405-
expect(out.nextStep).toMatchObject({ decision: 'no_measure', terms: ['库存周转', '销售阶段'] });
1406-
expect(out.nextStep!.note).toContain('query_records');
1407-
expect(out.nextStep!.note).toContain('ask the user which number they mean');
1421+
// [#34996] One object answers "库存周转 by 销售阶段" through the fallback, so the
1422+
// note carries the fallback and never the outright question: a note that said
1423+
// both was read as "ask". The grouping word is still named as the grouping it
1424+
// equals. The executor cannot know that 库存周转 is the word for the thing
1425+
// measured, so the question survives as ONE conditional sentence after the
1426+
// fallback, for the client to judge: only when the question names no number.
1427+
it('a mixed no_measure note falls back for the unknown word; the question is a condition, never outright', async () => {
1428+
for (const ctx of FOUR_LOCALES) {
1429+
const out = await ask(['库存周转', '销售阶段'], ctx);
1430+
const where = String(ctx.locale ?? 'en');
1431+
expect(out.nextStep, where).toMatchObject({ decision: 'no_measure', terms: ['库存周转', '销售阶段'] });
1432+
const note = out.nextStep!.note;
1433+
expect(note, where).toContain('query_records');
1434+
expect(note, where).toContain('Stage');
1435+
expect(note, `${where} ⇒ no outright question`).not.toContain(GROUPING_ALONE[where]);
1436+
expect(note, `${where} ⇒ the condition`).toContain(ONLY_IF_NO_NUMBER[where]);
1437+
expect(note.indexOf('query_records'), `${where} ⇒ fallback first`).toBeLessThan(note.indexOf(ONLY_IF_NO_NUMBER[where]));
1438+
// The control, same locale: alone, the grouping word asks outright which number is meant, and sends nobody to the object tools.
1439+
const alone = (await ask(['销售阶段'], ctx)).nextStep!.note;
1440+
expect(alone, `${where} ⇒ alone asks`).toContain(GROUPING_ALONE[where]);
1441+
expect(alone, where).not.toContain(ONLY_IF_NO_NUMBER[where]);
1442+
expect(alone, where).not.toContain('query_records');
1443+
}
1444+
});
1445+
1446+
// [#34996] The same note serves a call with no word for a thing measured: a
1447+
// grouping and a filter value ("break it down by sales stage for the west
1448+
// region"). The words alone do not tell it from the case above, which is why
1449+
// the condition is written in the client's terms and is the last sentence.
1450+
it('a grouping beside a filter value gets the same note: the condition is what makes it right for a question with no number', async () => {
1451+
for (const ctx of FOUR_LOCALES) {
1452+
const where = String(ctx.locale ?? 'en');
1453+
const out = await ask(['sales stage', 'west region'], ctx);
1454+
expect(out.nextStep, where).toMatchObject({ decision: 'no_measure', terms: ['sales stage', 'west region'] });
1455+
expect(out.candidates ?? [], where).toEqual([]);
1456+
const note = out.nextStep!.note;
1457+
expect(note.endsWith(ONLY_IF_NO_NUMBER[where]), `${where} ⇒ the condition closes the note`).toBe(true);
1458+
expect(note, where).not.toContain(GROUPING_ALONE[where]);
1459+
// Controls. An unknown word with no grouping beside it has nothing to ask about: the fallback, no condition.
1460+
const unknown = (await ask(['west region'], ctx)).nextStep!;
1461+
expect(unknown, where).toMatchObject({ decision: 'no_measure', terms: ['west region'] });
1462+
expect(unknown.note, where).toContain('query_records');
1463+
expect(unknown.note, where).not.toContain(ONLY_IF_NO_NUMBER[where]);
1464+
// A matched measure beside both settles which number is meant: neither form of the question.
1465+
const measured = (await ask(['商机数', 'sales stage', 'west region'], ctx)).nextStep!;
1466+
expect(measured, where).toMatchObject({ decision: 'one_measure', terms: ['商机数'] });
1467+
expect(measured.note, where).not.toContain(ONLY_IF_NO_NUMBER[where]);
1468+
expect(measured.note, where).not.toContain(GROUPING_ALONE[where]);
1469+
}
14081470
});
14091471

14101472
it('a word with two matches ⇒ several_measures, the note naming each by its label and its dataset\'s label', async () => {
@@ -1621,6 +1683,49 @@ describe('[#35005] list_datasets nextStep — a grouping or time word with a can
16211683
}
16221684
expect((await ask(['this quarter'])).nextStep!.note).toContain('ask the user which number they mean');
16231685
});
1686+
1687+
// [#34996] "How many sales orders this quarter?" with no order-count measure:
1688+
// "sales orders" is unknown and "this quarter" is near a dimension. The object
1689+
// tools answer the count, so the note offers the grouping, sends the unknown
1690+
// word to its labelled fallback and never asks outright; the question is left
1691+
// as the closing condition, for a question that names no number.
1692+
it('a grouping candidate beside an unknown word: the unknown word falls back and the question is only the closing condition', async () => {
1693+
for (const ctx of FOUR_LOCALES) {
1694+
const out = await ask(['sales orders', 'this quarter'], ctx);
1695+
expect(out.nextStep, loc(ctx)).toMatchObject({ decision: 'candidates_only', terms: ['this quarter'] });
1696+
expect(out.candidates).toEqual([{ term: 'this quarter', dataset: 'sales_metrics', member: 'dimensions.quarter' }]);
1697+
const note = out.nextStep!.note;
1698+
expect(note, loc(ctx)).toContain(GROUPING_OFFER[loc(ctx)]);
1699+
expect(note, loc(ctx)).toContain('sales orders');
1700+
expect(note, loc(ctx)).toContain('query_records');
1701+
expect(note, `${loc(ctx)} ⇒ no outright question`).not.toContain(GROUPING_ALONE[loc(ctx)]);
1702+
expect(note.endsWith(ONLY_IF_NO_NUMBER[loc(ctx)]), `${loc(ctx)} ⇒ the condition closes the note`).toBe(true);
1703+
expect(note.indexOf('query_records'), `${loc(ctx)} ⇒ fallback first`).toBeLessThan(note.indexOf(ONLY_IF_NO_NUMBER[loc(ctx)]));
1704+
expect(note, loc(ctx)).not.toContain(ASK_BEFORE_COMPUTING[loc(ctx)]);
1705+
// The control, same locale: with no unknown word beside it, the grouping candidate still asks outright which number.
1706+
const alone = (await ask(['this quarter'], ctx)).nextStep!.note;
1707+
expect(alone, `${loc(ctx)} ⇒ alone asks`).toContain(GROUPING_ALONE[loc(ctx)]);
1708+
expect(alone, loc(ctx)).not.toContain(ONLY_IF_NO_NUMBER[loc(ctx)]);
1709+
// And a word that equals a dimension beside the candidate is a second grouping, not a fallback: still asked outright.
1710+
const groupings = (await ask(['this quarter', 'industry'], ctx)).nextStep!.note;
1711+
expect(groupings, `${loc(ctx)} ⇒ two groupings ask`).toContain(GROUPING_ALONE[loc(ctx)]);
1712+
expect(groupings, loc(ctx)).not.toContain(ONLY_IF_NO_NUMBER[loc(ctx)]);
1713+
expect(groupings, loc(ctx)).not.toContain('query_records');
1714+
}
1715+
});
1716+
1717+
// [#34996] The several-matches and measure-candidate questions are untouched
1718+
// by the above: an unknown word beside them changes nothing about the ask.
1719+
it('an unknown word beside a measure candidate does not remove the question about that candidate', async () => {
1720+
for (const ctx of FOUR_LOCALES) {
1721+
const out = await ask(['销售', 'sales orders'], ctx);
1722+
expect(out.nextStep, loc(ctx)).toMatchObject({ decision: 'candidates_only', terms: ['销售'] });
1723+
expect(out.nextStep!.note, loc(ctx)).toContain(ASK_BEFORE_COMPUTING[loc(ctx)]);
1724+
expect(out.nextStep!.note, loc(ctx)).toContain('query_records');
1725+
// No grouping in the call: the which-number condition has nothing to be about.
1726+
expect(out.nextStep!.note, loc(ctx)).not.toContain(ONLY_IF_NO_NUMBER[loc(ctx)]);
1727+
}
1728+
});
16241729
});
16251730

16261731
describe('[#34919] list_datasets nextStep — an incomplete catalogue says so (N4)', () => {

0 commit comments

Comments
 (0)