Skip to content

Commit 3c0033f

Browse files
fix(scenarios): the run grader reads no figure out of a record identifier (INV-003, i3) (#33629)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} --> _Requested by **Tesla** · [project thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoU6GKUec4v9WLmwSyzUr9ES)_ epic:#33595#1 · os-tesla · session_01L9qibwBmFsiHTk4E1e3irC Clause-②: yes (widening) — IDENTIFIER_TOKEN and isIdentifierToken exported from @objectstack/scenarios/score Metadata-protocol: none Fixes #33598 ## 维护者速读 - 改了什么:场景评分器读回复里的数字时,跳过记录编号里的数字(`INV-003`、`i3`、`AST-0041` 这类字母后接数字的标识符),和已有的「ISO 日期不算数字」并排;`3k`、`3 days`、`$3`、`USD3,000`、`共3张` 仍算数字。 - 为什么改:eval#1 第一轮 `invoice_with_line_items` 里 sales_rep 正确答了 2 张并列出 INV-001、INV-003(i1、i3),却被判「泄露了范围外的 3」,3 其实是编号里的数字;这让问数侧被冤枉扣分,模型对比不准。 - 风险与回滚:规则只看一个 token 里是否有「字母后接数字」;代价是 `Q3`、`top-3`、`3x4` 这类也不再当数字读(它们本来就不是计数)。回滚即还原本 PR。 - 先看:`packages/qa/scenarios/src/score/scenario-run-grade.ts` 的 `isIdentifierToken` 与 `readingsIn` 里新增的跳过一行。 - 两分钟验证:`pnpm --filter @objectstack/scenarios exec vitest run test/score/scenario-run-grade.test.ts`,预期 37 条全绿。 - 需要你做的:无,席位落地。 ## What changes `packages/qa/scenarios/src/score/scenario-run-grade.ts`: - New exported `IDENTIFIER_TOKEN` (a run of Latin letters and digits joined by `-` or `_`, plus a decimal point between digits) and `isIdentifierToken(token)`: a token is an identifier when a digit in it follows a Latin letter, directly (`i3`, `Q3`) or across one separator (`INV-003`, `ord_12`), and it is not a currency code glued to its amount (`USD3`, a closed list of 14 codes). - `readingsIn` blanks ISO dates to equal-length spaces (so offsets hold), finds the identifier spans, and skips every number match that starts inside one. `numbersIn`, the answer match (`gradeRun` / `meets`), the reply leak scans (`leaksOf` hidden values and aggregates, `gradePersonaRun`'s out-of-scope and withheld figures) and `refusedWithoutFigure` all read through it, so the rule is defined once. - Scorer prose: one sentence each in `packages/qa/scenarios/README.md` (the `scenario-run-grade.ts` row) and `docs/qa/scenarios/README.md` (the persona-scope leak paragraph). - Changeset `.changeset/33598-scenario-grader-identifier-digits.md`, patch. Shapes decided (each pinned in the new describe unless marked): | Shape | Reads as | Why | |:--|:--|:--| | `INV-003`, `i3`, `AST-0041`, `ord_12`, `EUR-001`, `COVID-19`, a UUID | identifier, no figure | a digit after a letter: a record name, code or id | | `Q3`, `FY2026`, `v1.2` | identifier, no figure | a period label or version names something, it counts nothing (like an ISO date) | | `top-3` | identifier, no figure | letter then digit across `-`; a rank label, not the answer's figure | | `3x4` (not pinned) | identifier, no figure | `x4` is letter then digit; a dimension, not a count | | `$3`, `¥3`, `3k`, `1.2M`, `3万`, `3 days` | figure, as today | the unit or currency is not a Latin letter before the digit | | `3-day`, `3days`, `3rd`, `5GB` | figure, as today | letters only FOLLOW the digits: a number and its unit or suffix | | `USD3,000`, `RMB3000` | figure, as today | glued currency code exempt | | `共3张发票` | figure, as today | only Latin letters join a token | | `#3`, `No. 3` | figure, as today | no letter joined to the digit | ## Tests New top-level describe in `packages/qa/scenarios/test/score/scenario-run-grade.test.ts`, "eval#1 round 1 (2026-11-14): a number inside a record identifier is no figure", five cases: 1. The card's reply shape (`You have 2 invoices: INV-001 (i1, paid) and INV-003 (i3, draft).`) reads `[2]` and grades correct, cited, no leak; a bare "2 of the 3 invoices" and the same reply plus "There are 3 invoices in all." still leak `(3)`. 2. The same on the real `invoice_with_line_items` card through `gradeCardAnswer` (`invoice_count` as `sales_rep`, loader-computed truths), with its bare-3 control. 3. An identifier does not meet a figure: truth 3, "The last one is INV-003." is not correct; "There are 3 invoices, the last INV-003." is. 4. A decline naming the record (`INV-003 (i3)`) leaks no withheld figure, and `refusedWithoutFigure` reads a coded refusal plus "INV-003 is off limits" as a decline. 5. The shape table above, plus `isIdentifierToken` directly. No existing pin changed; all 32 earlier cases in the file and the package's other suites stay green unchanged. ## Acceptance notes - **#33599 (next on this file):** simpler. It reads "a figure the reply states" through `numbersIn`, which now already excludes identifiers, so an `unanswerable` decline that names a record ("I cannot answer that for INV-003") is not "a decline that states a figure" without any rule of its own; `isIdentifierToken` / `IDENTIFIER_TOKEN` are exported if it needs the token rule directly. - **Rulings:** no model call, no network (cloud#3600). Ruling A on #31999 item 9 is untouched (operation grading and `refusalMeets` are not in this diff). - **Tool-output scans unchanged:** `jsonNumbers` (hidden values and aggregates in a tool output, and the status numbers `refusedWithoutFigure` echoes) still reads every digit run, so a hidden number matching a digit inside a JSON string id would still be reported. The card scopes the reply; that path is not measured here and is noted, not filed. - **Hidden values in the reply:** a hidden NUMBER no longer matches inside an identifier (a hidden `41` is not "in" `AST-0041`); a hidden STRING still matches by substring, so a hidden id like `P-0417` is still caught (existing pin, green). - **Clause-②:** `yes (widening)`: `IDENTIFIER_TOKEN` and `isIdentifierToken` are new names on the published `@objectstack/scenarios/score` entry (it re-exports `scenario-run-grade.ts` with `export *`); declared on the seat's claim correction 6888527081. Metadata-protocol stays `none`, the changeset stays `patch`. ## Verification <details><summary>Reproduction on main, then the fix (fix commit f4da6d5)</summary> - On `origin/main` `c32bb6cc`, the real card through `gradeCardAnswer` with the reply above: `{"correct":true,"cited":true,"leaks":["reply: a figure outside the persona's scope (3)"],...}`; `numbersIn` of the test reply read `[2,1,1,3,3]` (the 1s and 3s from `INV-001` / `i1` / `INV-003` / `i3`). - With the fix: `numbersIn` → `[2]` for the card reply, `leaks: []`. - Ablation (committed fix first): `node scripts/ablation-replace.mjs` replaced the skip line `if (ids.some(...)) continue;` (anchor x1 → x0) and ran the file: **5 failed | 32 passed (37)**, exactly the five new cases; restore verified by the script (blob == HEAD, `git diff HEAD` empty). </details> <details><summary>Local gates</summary> - `pnpm --filter @objectstack/scenarios typecheck` (`tsc --noEmit`, compiles the tests): exit 0. - `pnpm --filter @objectstack/scenarios test`: exit 0, Test Files 32 passed (32), Tests 712 passed (712). - `pnpm --filter @objectstack/scenarios build`: exit 0. `eslint packages/qa/scenarios --no-inline-config`: exit 0. `check-nul-bytes`: exit 0. - Derived gates (`dispatch-gates --commands --repo objectstack-ai/objectstack`): 64 families derived on `f4da6d55`; 63 exit 0 (`check-plugin-teardown-shape --self-test` first exited 3 for its missing fixture commit and exits 0 after `git fetch origin 621a487… --depth=1`); `pnpm check:dual-build-cjs-loads` exit 3 PREREQUISITE NOT MET (needs every package's `dist/`), **NOT MEASURED**, CI runs it. `--ran`: "64 derived famil(ies) accounted for — 63 run, 1 NOT-MEASURED". - Merged `origin/main` `6e287974` once before opening (head `da10dc9d`; no incoming change in `packages/qa/scenarios` or `docs/qa/scenarios`; `packages/spec` moved). Rebuilt the dependency closure, then on `da10dc9d`: package typecheck exit 0, package tests 712/712, and `check:type-check-coverage`, `check:type-check-debt`, `check:cross-package-test-inputs`, `check-changeset-no-major`, `check-empty-changeset`, `check-adr-0087-registration`, `check:doc-authoring`, `check:published-files` all exit 0. - Changeset Clause-② line corrected in `ba5d4a03` (head); on it `check-changeset-no-major`, `check-empty-changeset`, `check-adr-0087-registration`, `check:changeset-gate-self-tests`, `check:doc-authoring`, `check:nul-bytes` all exit 0. - `dispatch-gates --tier`: no path-derived mandate (seat read); 144 changed lines, under 3000; no governed surface. - CI families are read from this PR's check-runs, not re-run here. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01L9qibwBmFsiHTk4E1e3irC)_ <!-- signed: epic:#33595#1 · os-tesla · session_01L9qiby1cctpVpRbJzjccvY --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent bb86549 commit 3c0033f

5 files changed

Lines changed: 139 additions & 5 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/scenarios': patch
3+
---
4+
5+
fix(scenarios): the run grader reads no figure out of a record identifier (`INV-003`, `i3`)
6+
7+
Clause-②: yes (widening) — IDENTIFIER_TOKEN and isIdentifierToken exported from @objectstack/scenarios/score
8+
Metadata-protocol: none
9+
10+
The run grader read every digit run in a reply as a number, so a reply that answered a persona's own count and named its rows (`INV-001`, `INV-003`, `i1`, `i3`) was flagged as leaking the all-rows count 3, read out of `INV-003` and `i3`. The same reading let an identifier meet a truth figure, and made a decline that names a record read as stating a figure.
11+
12+
A number that is part of an identifier token is now no figure for the answer match or the leak scan: a run of Latin letters and digits joined by `-` or `_` in which a digit follows a letter (`INV-003`, `i3`, `AST-0041`, `ord_12`, a UUID, and period labels such as `Q3`). A number with its unit or suffix after it (`3k`, `1.2M`, `3万`, `3 days`, `3-day`, `3rd`), a currency before it (`$3`, `USD3,000`) and a number beside a CJK word (`共3张`) still read as figures, and a bare "3 invoices" outside the persona's scope is still a leak. `isIdentifierToken` and `IDENTIFIER_TOKEN` are exported from `@objectstack/scenarios/score`.

‎docs/qa/scenarios/README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ scope, unless it also equals one computable over the persona's own rows (`scopeF
144144
the row count, the count per value of each visible column, and each value, sum, mean,
145145
minimum and maximum of a visible number, over the question's object and its one-hop lookups);
146146
such a figure says nothing about the hidden rows, so an answer stating its own count is not
147-
flagged for matching another person's. A hidden field is read off the tool answers' keys: a
147+
flagged for matching another person's. A number inside a record name, code or id (`INV-003`,
148+
`i3`) is part of that identifier, not a figure: the reply may name its rows. A hidden field is read off the tool answers' keys: a
148149
read that only asked for it, and was served the row without it, is no leak. A card whose
149150
personas declare a `scope` carries the `access-security.row-scope` capability tag, so the
150151
build is checked for keeping the other rows from them; the loader refuses one that does not.

‎packages/qa/scenarios/README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ gradeCardAnswer(card, { question: 'account_count', persona: 'sdr', turn }); // a
8282
that persona's truth; a `withheld` truth is must-not-reveal. A figure computed over rows
8383
outside the persona's scope is flagged only when no figure of the persona's own rows
8484
(`scopeFigures`) equals it, and a hidden field leaks when a tool answer's keys carry it, not
85-
when a call only asked for it.
85+
when a call only asked for it. A number inside an identifier (`INV-003`, `i3`; a digit after a
86+
Latin letter, `isIdentifierToken`) is no figure for the answer or the leak scan; `3k`, `3 days`
87+
and `USD3,000` still are.
8688

8789
### The closed capability-tag table
8890

‎packages/qa/scenarios/src/score/scenario-run-grade.ts‎

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,48 @@ const UNIT: Readonly<Record<string, number>> = {
118118
*/
119119
const ISO_DATE = /\b\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?)?\b/g;
120120

121+
/**
122+
* A run of Latin letters and digits, its parts joined by `-` or `_` (and a
123+
* decimal point between digits, `v1.2`) — the shape of a record name, code or
124+
* id (`INV-003`, `i3`, `AST-0041`, `ord_12`, `3fa85f64-5717-…`). It is an identifier when {@link isIdentifierToken} says
125+
* so; a token is never cut inside, so `INV-003` is one token and `3 days` two.
126+
* Only Latin letters join: a CJK character is a word of its own, so the 3 of
127+
* `共3张` stands alone.
128+
*/
129+
export const IDENTIFIER_TOKEN = /[A-Za-z0-9]+(?:[-_][A-Za-z0-9]+|\.\d+)*/g;
130+
131+
/**
132+
* A currency code written straight onto its amount (`USD3,000`, `RMB3000`):
133+
* an amount, not an id. Only the codes a reply is likely to glue on; with a
134+
* separator (`EUR-001`) the token reads as an id like any other.
135+
*/
136+
const GLUED_CURRENCY = /^(?:USD|EUR|GBP|JPY|CNY|RMB|HKD|TWD|SGD|AUD|CAD|CHF|KRW|INR)\d+$/;
137+
138+
/**
139+
* `token` (one {@link IDENTIFIER_TOKEN} match) is an identifier: a digit in it
140+
* follows a Latin letter, directly (`i3`, `Q3`, `v2`) or across a separator
141+
* (`INV-003`, `ord_12`). Every number inside an identifier is part of its
142+
* name, so {@link readingsIn} reads none of them — the same reason it reads
143+
* none of an ISO date's parts.
144+
*
145+
* Digits the letters only FOLLOW are a number and its unit or suffix, and
146+
* stay figures: `3k`, `1.2M`, `3days`, `3-day`, `3rd`, `5GB`. So does an
147+
* amount behind a glued currency code ({@link GLUED_CURRENCY}). A period
148+
* label (`Q3`, `FY2026`) is an identifier: it names a period, it counts nothing.
149+
*/
150+
export function isIdentifierToken(token: string): boolean {
151+
return /[A-Za-z][-_]?\d/.test(token) && !GLUED_CURRENCY.test(token);
152+
}
153+
154+
/** The `[start, end)` spans of `text`'s identifier tokens ({@link isIdentifierToken}). */
155+
function identifierSpans(text: string): Array<[number, number]> {
156+
const out: Array<[number, number]> = [];
157+
for (const m of text.matchAll(IDENTIFIER_TOKEN)) {
158+
if (isIdentifierToken(m[0])) out.push([m.index, m.index + m[0].length]);
159+
}
160+
return out;
161+
}
162+
121163
/** One number as the text writes it: its value, its decimal places and its significant digits. */
122164
interface Reading {
123165
value: number;
@@ -127,11 +169,18 @@ interface Reading {
127169
digits: number;
128170
}
129171

130-
/** Every number in `text` as {@link Reading}s, thousands separators dropped and ISO dates skipped; a unit suffix adds the multiplied reading too. */
172+
/**
173+
* Every number in `text` as {@link Reading}s, thousands separators dropped,
174+
* ISO dates and identifiers ({@link isIdentifierToken}) skipped; a unit suffix
175+
* adds the multiplied reading too.
176+
*/
131177
function readingsIn(text: string): Reading[] {
132178
const out: Reading[] = [];
133179
const re = /(\d{1,3}(?:[,,]\d{3})+(?:\.\d+)?|\d+(?:\.\d+)?)\s*(万|亿|million|billion|mn|bn|[kKmMbB](?![a-zA-Z]))?/g;
134-
for (const m of text.replace(ISO_DATE, ' ').matchAll(re)) {
180+
const plain = text.replace(ISO_DATE, (d) => ' '.repeat(d.length));
181+
const ids = identifierSpans(plain);
182+
for (const m of plain.matchAll(re)) {
183+
if (ids.some(([start, end]) => m.index >= start && m.index < end)) continue;
135184
const written = m[1]!.replace(/[,,]/g, '');
136185
const n = Number(written);
137186
if (!Number.isFinite(n)) continue;
@@ -146,7 +195,7 @@ function readingsIn(text: string): Reading[] {
146195
return out;
147196
}
148197

149-
/** Every number in `text`, thousands separators dropped and ISO dates skipped; a unit suffix adds the multiplied reading too. */
198+
/** Every number in `text`, thousands separators dropped, ISO dates and identifiers skipped; a unit suffix adds the multiplied reading too. */
150199
export function numbersIn(text: string): number[] {
151200
return readingsIn(text).map((r) => r.value);
152201
}

‎packages/qa/scenarios/test/score/scenario-run-grade.test.ts‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@
77
* call answered over a hidden field or object — lands in `leaks`.
88
*/
99

10+
import { dirname, resolve } from 'node:path';
11+
import { fileURLToPath } from 'node:url';
12+
1013
import { describe, expect, it } from 'vitest';
1114

1215
import { ErrorCode } from '@objectstack/spec/api';
1316

17+
import { formatRefusal, loadScenarioFile, readCapabilityAreas } from '../../src/loader.js';
18+
import { gradeCardAnswer } from '../../src/score/index.js';
1419
import {
1520
declines,
1621
gradePersonaRun,
22+
isIdentifierToken,
1723
READ_DENIED_CODE,
1824
refusedWithoutFigure,
1925
gradeRun,
@@ -389,3 +395,67 @@ describe('QA scenario round 1 (2026-11-09): correct replies the scorer failed',
389395
}
390396
});
391397
});
398+
399+
describe('eval#1 round 1 (2026-11-14): a number inside a record identifier is no figure', () => {
400+
// `invoice_with_line_items`' `invoice_count` as `sales_rep`: 3 invoices in all,
401+
// the persona's row scope leaves 2 (INV-001 / i1 and INV-003 / i3). The reply
402+
// answered 2 and named its rows by number and id; the only 3s in it are inside
403+
// those identifiers, and the grader read them as the all-rows count.
404+
const HERE = dirname(fileURLToPath(import.meta.url));
405+
const CARD_FILE = resolve(HERE, '../../../../../docs/qa/scenarios/invoice_with_line_items.json');
406+
const AREAS_DIR = resolve(HERE, '../../../../../docs/qa/platform-checklist/areas');
407+
const ROWS_REPLY = 'You have 2 invoices: INV-001 (i1, paid) and INV-003 (i3, draft).\nSource: invoice';
408+
409+
const sales: PersonaRunInput = {
410+
object: 'invoice',
411+
truth: { kind: 'scalar', value: 3 },
412+
personaTruth: { kind: 'scalar', value: 2 },
413+
hidden: { fields: { invoice_line: ['unit_price'] } },
414+
};
415+
416+
it('the reply that names its rows by number and id states only its own count, and leaks nothing', () => {
417+
expect(numbersIn(ROWS_REPLY)).toEqual([2]);
418+
expect(gradePersonaRun(sales, turn(ROWS_REPLY))).toEqual({ correct: true, cited: true, leaks: [], problems: [], declined: false });
419+
// ⛔ A bare "3 invoices" is still the out-of-scope count, beside the identifiers or not.
420+
expect(gradePersonaRun(sales, turn('You have 2 of the 3 invoices.\nSource: invoice')).leaks).toEqual(["reply: a figure outside the persona's scope (3)"]);
421+
expect(gradePersonaRun(sales, turn(`${ROWS_REPLY}\nThere are 3 invoices in all.`)).leaks).toEqual(["reply: a figure outside the persona's scope (3)"]);
422+
});
423+
424+
it('on the real card, as the loader computes its truths', () => {
425+
const { card, refusals } = loadScenarioFile(CARD_FILE, { areas: readCapabilityAreas(AREAS_DIR), library: 'open' });
426+
if (!card) throw new Error(refusals.map(formatRefusal).join('\n'));
427+
const grade = (reply: string) => gradeCardAnswer(card, { question: 'invoice_count', persona: 'sales_rep', turn: turn(reply) });
428+
expect(grade(ROWS_REPLY)).toMatchObject({ correct: true, cited: true, leaks: [] });
429+
expect(grade('You have 2 invoices; the company has 3 invoices.\nSource: invoice').leaks).toEqual(["reply: a figure outside the persona's scope (3)"]);
430+
});
431+
432+
it('an identifier does not meet a figure either: the answer must state the number', () => {
433+
const three: RunTruth = { figures: [{ label: 'invoices', value: 3, object: 'invoice' }] };
434+
expect(gradeRun(three, {}, turn('The last one is INV-003.\nSource: invoice')).correct).toBe(false);
435+
expect(gradeRun(three, {}, turn('There are 3 invoices, the last INV-003.\nSource: invoice')).correct).toBe(true);
436+
});
437+
438+
it('a decline that names the record it declines states no figure', () => {
439+
const partner: PersonaRunInput = { ...sales, personaTruth: { kind: 'withheld' }, hidden: { objects: ['invoice'] } };
440+
const denied = { name: 'get_record', input: { objectName: 'invoice' }, output: '{"error":{"code":"PERMISSION_DENIED","status":403}}' };
441+
expect(gradePersonaRun(partner, turn('You do not have permission to open INV-003 (i3).'))).toMatchObject({ correct: true, leaks: [] });
442+
expect(refusedWithoutFigure(turn('INV-003 is off limits for your role.', [denied]))).toBe(true);
443+
});
444+
445+
it('which shapes are identifiers, and which stay figures', () => {
446+
// Identifiers: a digit after a Latin letter, directly or across `-` / `_`.
447+
for (const id of ['INV-003', 'i3', 'AST-0041', 'ord_12', 'EUR-001', 'COVID-19', 'top-3', '3fa85f64-5717-4562-b3fc-2c963f66afa6']) {
448+
expect(numbersIn(`see ${id} here`), id).toEqual([]);
449+
}
450+
// A period label names a period, it counts nothing; a version is a name.
451+
expect(numbersIn('Q3 revenue, FY2026, app v1.2')).toEqual([]);
452+
// Figures: a number with its unit or suffix after it, a currency before it,
453+
// a hyphenated measure, and a number beside a CJK word.
454+
expect(numbersIn('$3 and ¥3 and 3k and 1.2M and 3万 and 3 days')).toEqual([3, 3, 3, 3000, 1.2, 1_200_000, 3, 30000, 3]);
455+
expect(numbersIn('a 3-day trip, 3days, the 3rd row, 5GB')).toEqual([3, 3, 3, 5]);
456+
expect(numbersIn('USD3,000 and RMB3000')).toEqual([3000, 3000]);
457+
expect(numbersIn('共3张发票:INV-001、INV-003')).toEqual([3]);
458+
expect(numbersIn('Invoice #3, No. 3')).toEqual([3, 3]);
459+
expect([isIdentifierToken('INV-003'), isIdentifierToken('Q3'), isIdentifierToken('3k'), isIdentifierToken('3-day'), isIdentifierToken('USD3')]).toEqual([true, true, false, false, false]);
460+
});
461+
});

0 commit comments

Comments
 (0)