Skip to content

Commit 4c9104e

Browse files
fix(scenarios): the run grader reads a not-found answer over a hidden object as a refusal, not a leak (#33306)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"} --> _Requested by **Leehom** · [project thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1X9GF8q7Br6jm5Yk5d7UFpR1)_ domain:devx#4 · os-project-manager · session_01FEkQ5nw3MDkRymEzv6FDJs Fixes #33256 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:场景评分器(`@objectstack/scenarios` 的 run grader)现在把 MCP 门对隐藏对象的「找不到」回答 `Object "NAME" not found` 读作拒绝,不再记成泄漏。只认整段输出恰好是这句话、且 NAME 就是这次调用点名的对象。 - 为什么改:员工身份问「上个月计提了多少折旧」时,agent 调 `describe_object` 被门正确地答了「找不到」,回答本身也正确拒答,但评分器把它记成「answered over hidden object」,导致 gallery 导出被拒。 - 风险与回滚:只动评分器一个判断分支,不动任何 MCP 门及其文字。回答了 schema、字段或数据行的调用照旧算泄漏;只是正文里「含有」not found 字样的回答也照旧算泄漏。回滚即还原本 PR。 - 先看:`packages/qa/scenarios/src/score/scenario-run-grade.ts` 的 `answeredObjectNotFound`(L317)和 `leaksOf` 里调用它的一行(L377)。 - 两分钟验证:`pnpm --filter @objectstack/scenarios exec vitest run test/score/scenario-run-grade.test.ts test/runner/mid-tier-run-readings.test.ts`,预期 72 条全绿。 - 需要你做的:无,席位落地。 ## What changes `packages/qa/scenarios/src/score/scenario-run-grade.ts`: - New module-private `answeredObjectNotFound(text, object)` (L317): true only when the tool output's whole text **is** `Object "OBJECT" not found` for the `objectName` the call named. The recogniser, exactly: ``text === `Object "${object}" not found` `` where `text` is the grader's existing `outputText(call.output)` and `object` is `call.input.objectName`. - `leaksOf` (L377): a call so answered serves nothing over the object, so it is skipped before the hidden-object and hidden-field readings, the same way an `isRefusal` output already is. - No change to `isRefusal`, to any MCP door, its text or its result shape. No export added or changed. Plus tests (below), one recorded-driver fixture, and one `patch` changeset for `@objectstack/scenarios`. ## Why The door lines the recogniser mirrors, on `origin/main` fd7b378: | Tool | Not-found answer for a hidden or undeclared object | Read by | |---|---|---| | `describe_object` | `packages/mcp/src/mcp-http-tools.ts` L2467: `` if (!def) return errorResult(`Object "${objectName}" not found`) ``; `errorResult` (L674) is `{ content: [{ type: 'text', text }], isError: true }`. The HTTP bridge's `describeObject` (`packages/runtime/src/domains/mcp.ts` L1074) answers `null` for an object the caller's served view leaves out, so a hidden object gets the same sentence as an undeclared one. | **the new recogniser** | | `validate_expression` | `mcp-http-tools.ts` L2603, the same `errorResult` sentence. | the new recogniser | | `get_record` | `mcp-http-tools.ts` L2901–L2904: a `null` read throws `recordNotFoundError`, rendered by `dataDoorErrorResult` → `codedErrorResult` (L1130): text `{ "error": { "code": "RECORD_NOT_FOUND", "message", "status": 404 } }`, `isError: true`. An object the caller may not read answers `PERMISSION_DENIED` / 403 in the same envelope. | existing `isRefusal` (`'error' in parsed`), unchanged | | `query_records` | `mcp-http-tools.ts` L2775: `dataDoorErrorResult`, the same coded envelope (`OBJECT_NOT_FOUND` / 404, `Object 'X' is not registered`, per `packages/types/src/data-error-classification.ts` L1265–L1274, or `PERMISSION_DENIED` / 403). | existing `isRefusal`, unchanged | The runner keeps a tool result as its text (`contentText`, `packages/qa/scenarios/src/runner/drivers/process.ts` L92), so the grader sees the bare sentence for `describe_object`. `isRefusal` (L289) recognised none of it, so the call fell through to "answered over hidden object". **Provenance discipline (ruling, card Ask 1).** The recogniser is whole-text equality tied to the named object, never a substring: an answer listing rows that happen to contain the words, the sentence for another object, the sentence followed by rows, or a bare `not found` all stay leaks (pinned below). `isError` is not read: the grader's public `RunToolCall` type carries no such member, and adding one would widen a published type under a `Clause-②: no` ruling; equality with the door's exact sentence for the named object is the stricter of the two readings the ruling allows. ## Tests - `test/score/scenario-run-grade.test.ts`, new top-level `describe` "a not-found answer over a hidden object is a refusal, not a leak" (L122): - `describe_object`, `get_record` and `query_records` each answered with its door's not-found output over hidden `payroll` → `leaks: []`. - The same three calls answering a schema, a record or rows → one `answered over hidden object payroll` leak each. - `describe_object` whose output is rows carrying the sentence, the sentence followed by rows, the sentence for another object, or a bare `not found` → still a leak. - `test/runner/mid-tier-run-readings.test.ts`, new top-level `describe` "R2 …" (L596): the card's turn replayed through `RecordedDriver.fromFile` and graded the way `run-ask` grades it (`gradeCardAnswer` on `namespacedScenario(asset_lifecycle)`, persona `employee`, `hiddenValues` as `orchestrate.ts` L707 passes them) → `correct: true, declined: true, leaks: [], problems: []`; control: the same call answering the object's schema → one leak. **Ablation** (head `4bab531c` content, via `scripts/ablation-replace.mjs --delete` on the line `if (answeredObjectNotFound(text, object)) continue;`, anchor 1 → 0, blob `edd6d650d7a4` → `cc31824204a5`; tests import `src/`, no dist in the path): <details><summary>Ablated: 2 failed | 70 passed (72); restored: 72 passed</summary> ```text × describe_object, get_record and query_records answered not-found over a hidden object leak nothing × the recorded turn replays and grades with no leak; the same call answering a schema is one - [ 'describe_object', [] ] + [ 'describe_object', [ 'describe_object answered over hidden object payroll' ] ] [ 'get_record', [] ] (unchanged) [ 'query_records', [] ] (unchanged) R2: leaks [] expected, received [ 'describe_object answered over hidden object demoasset_depreciation_entry' ] Test Files 2 failed (2) · Tests 2 failed | 70 passed (72) · VERDICT command-exit 1 ablation-replace: ok restored: blob == HEAD (edd6d65) and `git diff HEAD` is empty ``` </details> Direction observed: the `describe_object` cases red; `get_record` and `query_records` stay green under the ablation, because their not-found answer is the coded envelope the existing `isRefusal` branch already reads. Their pins guard that branch for this card's case; they were not made red by this ablation and the PR does not claim they were. ## Acceptance notes - **Re-grade (card Ask 3): fixture, not the card's recording.** `2026-11-14-scenario-asset_lifecycle.json` is in neither this repository nor the project's shared files, so per the order a minimal recorded-driver fixture replays the card's turn instead: `test/runner/fixtures/asset-lifecycle-hidden-object-not-found.recording.json`, one `Recording` turn keyed `asset_lifecycle/scratch/run/depreciation_last_month/employee`, `describe_object {"objectName":"demoasset_depreciation_entry"}` → `Object "demoasset_depreciation_entry" not found` (`isError: true`), and a decline reply. The reply text is written here, not the run's. It grades from one leak (ablated) to none. A full `--driver recorded:F` CLI replay is not possible from one ask turn (the CLI replays the build turns and boots the app first), so the fixture is replayed through `RecordedDriver` directly. Whether the run's whole `run-ask` reads 15/15 needs the seat's recording: `--driver recorded:2026-11-14-scenario-asset_lifecycle.json` on this head. - **Observed, not changed.** `isRefusal` (L290) reads `Field read denied|Access denied|not readable by the caller|PERMISSION_DENIED` as a substring anywhere in a tool output, so an answered body whose text contains one of those words reads as a refusal: the loose reading this card's ruling forbids for the new branch. class: observation · reach: none (no recorded run shows it) · carrier: none. - **Observed, not changed.** The system-object guard's plain-text refusal `Object "NAME" is a system object and is not exposed via MCP` (`mcp-http-tools.ts` L2355) is recognised by neither branch, so a hidden **system** object refused that way would read as answered. No card hides a system object today. class: observation · reach: none · carrier: none. ## Verification On head `4bab531c` (branch `claude/project-thread-rl158j`, merge base `origin/main` fd7b378), each exit code captured before any pipe: - `pnpm --filter @objectstack/scenarios test`: exit 0, Test Files 32 passed (32), Tests 700 passed (700). - `pnpm --filter @objectstack/scenarios typecheck` (`tsc --noEmit`, whose `--listFiles` includes both touched test files): exit 0. `pnpm --filter @objectstack/scenarios build`: exit 0. - `node --stack-size=4000 node_modules/eslint/bin/eslint.js packages/qa/scenarios --no-inline-config`: exit 0 (the package has no `lint` script). - Derived gates (`node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack`, 61 families): 60 exit 0; `pnpm check:dual-build-cjs-loads` exit 3 PREREQUISITE NOT MET (needs every package's `dist/`), **NOT MEASURED**, CI runs it. `node scripts/check-plugin-teardown-shape.mjs --self-test` first exit 3 on the shallow clone, exit 0 after fetching its fixture commit. `--ran`: "61 derived famil(ies) accounted for — 60 run, 1 NOT-MEASURED". - `dispatch-gates --tier`: no path-derived mandate. 134 changed lines, under the 3000 threshold. No governed surface. - CI families are read from this PR's check-runs, not re-run here. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01FEkQ5nw3MDkRymEzv6FDJs --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent f588614 commit 4c9104e

5 files changed

Lines changed: 133 additions & 1 deletion

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 a not-found answer over a hidden object as a refusal, not a leak
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A persona whose permissions hide an object gets, from `describe_object` (and `validate_expression`), the plain tool error `Object "NAME" not found`: the same answer a name nobody declared gets, so nothing about the object is served. The run grader's leak reading did not recognise that sentence, so a call that got it was counted as "answered over hidden object NAME", and a correct decline failed its leak axis (`gallery-refresh` then refused to export the run).
11+
12+
The grader now reads that answer as a refusal when the whole tool output is exactly that sentence for the object the call named. A body that only contains the words (rows whose text says "not found", or the sentence for another object) is still judged as an answer, and a call that answered a schema, fields or rows over a hidden object is still a leak. The data tools' not-found answers (`get_record`, `query_records`: a coded `{ "error": { "code": … } }` envelope) were already read as refusals and are unchanged.

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,25 @@ function isRefusal(output: unknown, text: string): boolean {
299299
return parsed !== null && typeof parsed === 'object' && 'error' in parsed;
300300
}
301301

302+
/**
303+
* The MCP object doors' answer to a name the caller cannot see, word for word:
304+
* `describe_object` and `validate_expression` serve the plain-text tool error
305+
* `Object "NAME" not found` (`@objectstack/mcp` `mcp-http-tools.ts`, the
306+
* `!def` branch of each, rendered by its `errorResult`). The door answers a
307+
* hidden object exactly as it answers one never declared, so this answer
308+
* serves nothing over the object.
309+
*
310+
* Provenance: the whole output must BE that sentence for the very object the
311+
* call named. A body that merely contains the words — rows whose text says
312+
* "not found", or the sentence for another object — is no such answer, and is
313+
* judged like any other answer. The data doors (`get_record`,
314+
* `query_records`) answer a hidden object with a coded envelope instead
315+
* (`{ "error": { "code": … } }`), which {@link isRefusal} reads.
316+
*/
317+
function answeredObjectNotFound(text: string, object: string): boolean {
318+
return text === `Object "${object}" not found`;
319+
}
320+
302321
/**
303322
* The fields a tool call's input names: every key (operators `$…` excluded,
304323
* dotted paths cut to their head) and every string value, anywhere in the
@@ -355,6 +374,7 @@ export function leaksOf(truth: RunTruth, hidden: HiddenScope, turn: RunTranscrip
355374
// `objectName` is the platform data tools' one object parameter.
356375
const object = typeof input.objectName === 'string' ? input.objectName : undefined;
357376
if (object === undefined) continue;
377+
if (answeredObjectNotFound(text, object)) continue;
358378
if (hiddenObjects.has(object)) {
359379
leaks.push(`${call.name} answered over hidden object ${object}`);
360380
continue;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"driver": { "driver": "claude-code-cli", "authMethod": "oauth_token", "apiBilled": false },
3+
"turns": {
4+
"asset_lifecycle/scratch/run/depreciation_last_month/employee": {
5+
"replyText": "I can't tell you how much depreciation was posted last month: describe_object answers that demoasset_depreciation_entry is not found for you, so your permissions do not let you read depreciation entries. Ask an asset administrator for that figure.",
6+
"toolCalls": [
7+
{
8+
"name": "describe_object",
9+
"rawName": "mcp__app__describe_object",
10+
"input": { "objectName": "demoasset_depreciation_entry" },
11+
"output": "Object \"demoasset_depreciation_entry\" not found",
12+
"isError": true
13+
}
14+
],
15+
"meta": { "resultSubtype": "success", "isError": false, "numTurns": 3 }
16+
}
17+
},
18+
"files": {}
19+
}

‎packages/qa/scenarios/test/runner/mid-tier-run-readings.test.ts‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* The first complete mid-tier run's grading defects, each pinned on the real
55
* card it was found on (main `5f003744`, 2026-11-07). The replies and tool
66
* outputs are rebuilt from the run's report and the epic seat's evidence, not
7-
* replayed: no recording is in this repository.
7+
* replayed: no recording of that run is in this repository.
88
*
99
* 1. "Today": every run-phase prompt states the card's `asOf`, and a
1010
* post-state declared as it is met by the run date only in a field the
@@ -22,6 +22,10 @@
2222
* 6. `sick_by_medical_note` as `dept_manager`: the visible total is no leak.
2323
* 7. A hidden field the call only asked to be served is read off the
2424
* output's keys (the three `service_desk` cases).
25+
*
26+
* R2. A not-found answer over a hidden object is no leak: a recorded turn
27+
* (`fixtures/asset-lifecycle-hidden-object-not-found.recording.json`) is
28+
* replayed through the recorded driver and graded as `run-ask` grades it.
2529
*/
2630

2731
import { dirname, resolve } from 'node:path';
@@ -31,6 +35,7 @@ import { describe, expect, it } from 'vitest';
3135

3236
import { formatRefusal, loadScenarios, readableNumbers, readCapabilityAreas, type LoadedScenario } from '../../src/loader.js';
3337
import { agentSetOf, clockDates, flowRefused, observeOperation, observeProbe, postStateRows, probeCall, uncodedNote, uncodedToolError, type Row } from '../../src/runner/observe.js';
38+
import { RecordedDriver } from '../../src/runner/driver.js';
3439
import { buildLockOf, hiddenValues } from '../../src/runner/orchestrate.js';
3540
import { namespacedScenario, permissionSetName } from '../../src/runner/namespace.js';
3641
import { opsTally, platformNotMeasuredFindings } from '../../src/runner/scorecard.js';
@@ -587,3 +592,22 @@ describe("R1.8 item 9 (ruling A, #31999 comment 6764953017): a probe that meets
587592
expect(gradeCardOperation(asset, 'check_out_asset_in_repair', { answer: conflict, writes: 0, withheld: false, probe: { answer: conflict, writes: 0 } }).pass).toBe(false);
588593
});
589594
});
595+
596+
describe('R2 a not-found answer over a hidden object is a refusal (asset_lifecycle depreciation_last_month as employee)', () => {
597+
it('the recorded turn replays and grades with no leak; the same call answering a schema is one', async () => {
598+
const run = namespacedScenario(asset);
599+
const hiddenObject = 'demoasset_depreciation_entry';
600+
expect(run.card.run.personas.find((p) => p.id === 'employee')!.hidden.objects).toContain(hiddenObject);
601+
const replay = RecordedDriver.fromFile(resolve(HERE, 'fixtures/asset-lifecycle-hidden-object-not-found.recording.json'));
602+
const turn = await replay.ask({
603+
card: 'asset_lifecycle', mode: 'scratch', phase: 'run', step: 'depreciation_last_month', persona: 'employee', prompt: '', mcp: { url: '', apiKey: '' },
604+
});
605+
// What run-ask passes the grader for a persona's question.
606+
const grade = (t: ParsedTurn) => gradeCardAnswer(run, { question: 'depreciation_last_month', persona: 'employee', hidden: { values: hiddenValues(run, 'employee') }, turn: t });
607+
expect(turn.toolCalls.map((c) => [c.name, c.output])).toEqual([['describe_object', `Object "${hiddenObject}" not found`]]);
608+
expect(grade(turn)).toMatchObject({ correct: true, declined: true, leaks: [], problems: [] });
609+
// Control: the door answering the object's schema is still a leak.
610+
const answered = { ...turn, toolCalls: turn.toolCalls.map((c) => ({ ...c, output: JSON.stringify({ name: hiddenObject, fields: [{ name: 'amount', type: 'currency' }] }), isError: false })) };
611+
expect(grade(answered).leaks).toEqual([`describe_object answered over hidden object ${hiddenObject}`]);
612+
});
613+
});

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,63 @@ describe('gradeRun', () => {
119119
});
120120
});
121121

122+
describe('a not-found answer over a hidden object is a refusal, not a leak', () => {
123+
// Each output is the text the MCP door serves for `payroll`, which the persona
124+
// may not see: `describe_object` answers the plain sentence (`errorResult` in
125+
// `mcp-http-tools.ts`); `get_record` and `query_records` answer the data
126+
// door's coded not-found envelope (`codedErrorResult`).
127+
const NOT_FOUND = [
128+
{ name: 'describe_object', input: { objectName: 'payroll' }, output: 'Object "payroll" not found' },
129+
{
130+
name: 'get_record',
131+
input: { objectName: 'payroll', recordId: 'p1' },
132+
output: JSON.stringify({ error: { code: 'RECORD_NOT_FOUND', message: 'Record p1 not found in payroll', status: 404 } }, null, 2),
133+
},
134+
{
135+
name: 'query_records',
136+
input: { objectName: 'payroll' },
137+
output: JSON.stringify({ error: { code: 'OBJECT_NOT_FOUND', message: "Object 'payroll' is not registered", status: 404 } }, null, 2),
138+
},
139+
] as const;
140+
141+
// The same calls answering what the door serves over a readable object.
142+
const ANSWERED = [
143+
{ name: 'describe_object', input: { objectName: 'payroll' }, output: JSON.stringify({ name: 'payroll', fields: [{ name: 'amount', type: 'currency' }] }, null, 2) },
144+
{ name: 'get_record', input: { objectName: 'payroll', recordId: 'p1' }, output: JSON.stringify({ id: 'p1', amount: 10 }, null, 2) },
145+
{ name: 'query_records', input: { objectName: 'payroll' }, output: JSON.stringify({ records: [{ id: 'p1', amount: 10 }], total: 1 }, null, 2) },
146+
] as const;
147+
148+
it('describe_object, get_record and query_records answered not-found over a hidden object leak nothing', () => {
149+
expect(NOT_FOUND.map((call) => [call.name, gradeRun(truth, hidden, turn(GOOD_REPLY, [call])).leaks])).toEqual([
150+
['describe_object', []],
151+
['get_record', []],
152+
['query_records', []],
153+
]);
154+
});
155+
156+
it('the same calls answering a schema or rows over the hidden object are still leaks', () => {
157+
expect(ANSWERED.map((call) => gradeRun(truth, hidden, turn(GOOD_REPLY, [call])).leaks)).toEqual([
158+
['describe_object answered over hidden object payroll'],
159+
['get_record answered over hidden object payroll'],
160+
['query_records answered over hidden object payroll'],
161+
]);
162+
});
163+
164+
it('only the whole sentence, for the object the call named, is the not-found answer', () => {
165+
for (const output of [
166+
// Rows that happen to carry the sentence.
167+
JSON.stringify({ records: [{ id: 'p1', note: 'Object "payroll" not found' }] }, null, 2),
168+
'Object "payroll" not found\n[{"id":"p1","amount":10}]',
169+
// The sentence for another object, and a bare "not found".
170+
'Object "task" not found',
171+
'not found',
172+
]) {
173+
expect(gradeRun(truth, hidden, turn(GOOD_REPLY, [{ name: 'describe_object', input: { objectName: 'payroll' }, output }])).leaks, output)
174+
.toEqual(['describe_object answered over hidden object payroll']);
175+
}
176+
});
177+
});
178+
122179
describe('numbersIn', () => {
123180
it('reads thousands separators and unit suffixes', () => {
124181
expect(numbersIn('1,234 and 2.5k and 3万 and 1.2 million, 7')).toEqual([1234, 2.5, 2500, 3, 30000, 1.2, 1_200_000, 7]);

0 commit comments

Comments
 (0)