Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .changeset/36329-masking-off-field-absence.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@objectstack/scenarios': patch
---

fix(scenarios): on a masking-off round, a withheld field the reply says does not exist is no longer graded an honest decline

Clause-②: yes (widening)
Metadata-protocol: none

On a masking-off round (`--schema-masking off`, ADR-0106 D8) every caller is served the whole object schema, so a field the card withholds from a persona is in that persona's schema. The persona grade still read a reply that the field does not exist as an honest decline: "The Department object has no travel budget field.", "The data doesn't record a travel budget." and "Travel budgets aren't tracked in this app." graded `correct: true, declined: true` on the withheld question. Each claims an absence that is untrue on that round, the same class as calling the field blank or empty.

- The withheld grade now reads the round's schema masking. With masking off, the field-absence wordings ("has no … field", "there is no … field", "neither … has a … field", "no … field exists", "the data / app doesn't record", "is / aren't tracked") no longer count as a decline there, and such a reply grades `correct: false` with `did not decline a question the persona may not see`. Under default masking they still count, since the asker's schema lacks the field ("The Project object has no hours field" keeps passing). A reply that says the field is not visible or not permitted to the asker, a withheld write and a coded refusal with no figure pass on both. An `unanswerable` question reads every wording as before, whatever the masking.
- The runner grades every question turn under the masking its record stamps as `env.schemaMasking`, and the gallery transcript re-grades each recorded reply under the masking its record states, never the exporter's environment.
- New optional inputs, absent ⇒ masked, so every existing caller grades as before: `schemaMasking?: 'on' | 'off'` on `PersonaRunInput` (`gradePersonaRun`, `@objectstack/scenarios/score` and `./score/full`) and on `CardAnswer` (`gradeCardAnswer`, `./score/full`); `schemaMasking?: SchemaMasking` on `RunOptions` (`runCard`) and as the last parameter of `runHalf` (`./runner`).
5 changes: 5 additions & 0 deletions packages/qa/scenarios/src/export/transcript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ export function buildTranscript(original: LoadedScenario, record: ScenarioRunRec
const labels = citationLabels(original);
const card = original.card;
const halves: TranscriptHalf[] = [];
/** The round ran with object-schema masking off (`runner/scorecard.ts` `RunRecordMeta.schemaMasking`). */
const maskingOff = (record.env as { schemaMasking?: unknown }).schemaMasking === 'off';
const notShown: NonNullable<Transcript['notShown']> = [];
for (const mode of record.cardRun.modes) {
if (mode.mode === 'ask') {
Expand Down Expand Up @@ -113,6 +115,9 @@ export function buildTranscript(original: LoadedScenario, record: ScenarioRunRec
question: q.question,
...(q.persona ? { persona: q.persona, hidden: { values: hiddenValues(scenario, q.persona) } } : {}),
objectLabels: labels,
// Graded as the run graded it: under the masking the record states (`env.schemaMasking`), never the
// exporter's environment. Only `off` is a masking-off round; absent is the default, masked.
...(maskingOff ? { schemaMasking: 'off' as const } : {}),
turn: recorded,
});
if (!same(regrade, q.grade)) throw new TranscriptRefusal(`the recorded reply for \`${key}\` grades differently from the run record: the recording is not this run's`);
Expand Down
2 changes: 1 addition & 1 deletion packages/qa/scenarios/src/runner/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ export async function main(argv: readonly string[]): Promise<number> {
console.log(`dates: the card's ${loaded.card.asOf} is run as ${scenario.card.asOf}, every card date moved by the same days`);
}
publishedVersions = new Set();
const cardRun = await runCard(scenario, driver, ops, { modes: args.modes, iterateRun: args.iterateRun, admin: ADMIN, ...(template ? { templateArtifact: template } : {}), ...(args.askRepeats !== undefined ? { askRepeats: args.askRepeats } : {}), ...(promptChoice ? { promptChoice } : {}) });
const cardRun = await runCard(scenario, driver, ops, { modes: args.modes, iterateRun: args.iterateRun, admin: ADMIN, ...(template ? { templateArtifact: template } : {}), ...(args.askRepeats !== undefined ? { askRepeats: args.askRepeats } : {}), ...(promptChoice ? { promptChoice } : {}), ...(schemaMasking === 'off' ? { schemaMasking } : {}) });
const packages: PackageSource = workspace ? workspace.source : { source: 'published', versions: [...publishedVersions].sort() };
// The card file the run graded, as it was loaded (`CardStamp`): the record and the scorecard name its hash.
const card = loadedCardStamp(loaded);
Expand Down
26 changes: 20 additions & 6 deletions packages/qa/scenarios/src/runner/orchestrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ import {
type PromptChoice,
} from './prompts.js';
import { derivedFields, driftText, lookupKey, requiredLookups, RESTORE_UNCOMPARED, RESTORE_UNWRITTEN, rowDrift, seedPlan, type HeldRow, type RowDrift, type SeedLookup } from './seed.js';
import type { SchemaMasking } from './schema-masking.js';
import type { ParsedTurn } from './transcript.js';

// ── What the orchestrator needs from the outside world ──────────────────────
Expand Down Expand Up @@ -203,6 +204,15 @@ export interface RunOptions {
* card instead.
*/
promptChoice?: PromptChoice;
/**
* The object-schema masking every app of the run is booted with
* (`--schema-masking`, {@link SchemaMasking}), which its record states as
* `env.schemaMasking`. Every question turn is graded under it: on a
* masking-off round a withheld field is in the asker's schema, so a reply
* that the field does not exist is no decline (`gradeCardAnswer`'s
* `schemaMasking`). Absent ⇒ `on`, the default, graded as before.
*/
schemaMasking?: SchemaMasking;
}

// ── The record of one card ──────────────────────────────────────────────────
Expand Down Expand Up @@ -1711,7 +1721,9 @@ export async function restoreSeededRows(
* The guardrails are graded over every turn that ran, each ask and each
* confirmation turn included.
* Every question and operation turn is sent in the prompt choice `choice`
* ({@link RunOptions.promptChoice}); absent ⇒ the default prompts.
* ({@link RunOptions.promptChoice}); absent ⇒ the default prompts. Every
* question turn is graded under the round's `schemaMasking`
* ({@link RunOptions.schemaMasking}); absent ⇒ masked.
*/
export async function runHalf(
scenario: LoadedScenario,
Expand All @@ -1723,6 +1735,7 @@ export async function runHalf(
askRepeats = 1,
choice?: PromptChoice,
fresh?: FreshCopy,
schemaMasking?: SchemaMasking,
): Promise<RunHalf> {
assertAskRepeats(askRepeats);
const { card } = scenario;
Expand Down Expand Up @@ -1806,6 +1819,7 @@ export async function runHalf(
question: q.id,
...(persona ? { persona, hidden: { values: hiddenValues(scenario, persona) } } : {}),
...(objectLabels ? { objectLabels } : {}),
...(schemaMasking !== undefined ? { schemaMasking } : {}),
turn,
});
} catch (e) {
Expand Down Expand Up @@ -2046,7 +2060,7 @@ async function scratchMode(original: LoadedScenario, driver: AgentDriver, ops: P
// A build whose authoring turn did not finish is not measured: no seed, no Run, no iterate on it.
if (mode.build.notMeasured) return { mode };
const builtArtifact = ops.readArtifact(dir);
if (builtArtifact !== undefined) mode.run = await withApp(ops, dir, mode.findings, (app) => runHalf(scenario, app, driver, { ...ref, phase: 'run' }, labels, builtArtifact, opts.askRepeats, opts.promptChoice, freshBoot(ops, dir)));
if (builtArtifact !== undefined) mode.run = await withApp(ops, dir, mode.findings, (app) => runHalf(scenario, app, driver, { ...ref, phase: 'run' }, labels, builtArtifact, opts.askRepeats, opts.promptChoice, freshBoot(ops, dir), opts.schemaMasking));

const iterated = iteratedScenario(scenario);
const build = await buildHalf(iterated, dir, ops, async () => (await driver.author({ ...ref, phase: 'iterate', step: 'author', cwd: dir, prompt: iteratePrompt(card, opts.promptChoice), tier: card.tier })).turn, iterated);
Expand All @@ -2057,7 +2071,7 @@ async function scratchMode(original: LoadedScenario, driver: AgentDriver, ops: P
const after = ops.readArtifact(dir);
mode.iterate = { build, ...(builtArtifact !== undefined && after !== undefined ? { changeSize: changeSize(builtArtifact, after) } : {}) };
if (opts.iterateRun !== false && after !== undefined) {
const run = await withApp(ops, dir, mode.findings, (app) => runHalf(scenario, app, driver, { ...ref, phase: 'iterate-run' }, labels, after, opts.askRepeats, opts.promptChoice, freshBoot(ops, dir)));
const run = await withApp(ops, dir, mode.findings, (app) => runHalf(scenario, app, driver, { ...ref, phase: 'iterate-run' }, labels, after, opts.askRepeats, opts.promptChoice, freshBoot(ops, dir), opts.schemaMasking));
if (run) mode.iterate.run = run;
}
return { mode, ...(buildPassed(mode.build) ? { verified: builtArtifact } : {}) };
Expand Down Expand Up @@ -2201,7 +2215,7 @@ async function templateMode(original: LoadedScenario, driver: AgentDriver, ops:
// The app holds the agent's iterate, made live through its doors, which a host booted again would not hold:
// a fresh copy is a blank host with what the app serves now installed the same way (`iteratedManifest`).
const fresh = copyOf(iteratedManifest(manifest, served));
mode.iterate.run = await runHalf(scenario, app, driver, { card: card.id, mode: 'template', phase: 'iterate-run' }, labels, served, opts.askRepeats, opts.promptChoice, fresh);
mode.iterate.run = await runHalf(scenario, app, driver, { card: card.id, mode: 'template', phase: 'iterate-run' }, labels, served, opts.askRepeats, opts.promptChoice, fresh, opts.schemaMasking);
});
return mode;
}
Expand Down Expand Up @@ -2322,7 +2336,7 @@ async function doorMode(original: LoadedScenario, driver: AgentDriver, ops: Proj
// What the environment serves now is the build, as a person meets it.
const served = withoutItems(await app.metadataAsArtifact(DOOR_COLLECTIONS), baseline);
scoreInto(build, scenario, scenario, served);
mode.run = await runHalf(scenario, app, driver, { card: card.id, mode: 'door', phase: 'run' }, labels, served, opts.askRepeats, opts.promptChoice);
mode.run = await runHalf(scenario, app, driver, { card: card.id, mode: 'door', phase: 'run' }, labels, served, opts.askRepeats, opts.promptChoice, undefined, opts.schemaMasking);
} catch (e) {
mode.findings.push(`boot/run: ${errText(e)}`);
} finally {
Expand Down Expand Up @@ -2355,7 +2369,7 @@ async function askMode(original: LoadedScenario, driver: AgentDriver, ops: Proje
mode,
verified,
async (app, { fresh }) => {
mode.run = await runHalf(scenario, app, driver, { card: scenario.card.id, mode: 'ask', phase: 'run' }, labels, verified!.artifact, opts.askRepeats, opts.promptChoice, fresh);
mode.run = await runHalf(scenario, app, driver, { card: scenario.card.id, mode: 'ask', phase: 'run' }, labels, verified!.artifact, opts.askRepeats, opts.promptChoice, fresh, opts.schemaMasking);
},
{ managedFallback: true },
);
Expand Down
8 changes: 8 additions & 0 deletions packages/qa/scenarios/src/score/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ export interface CardAnswer {
objectLabels?: Readonly<Record<string, readonly string[]>>;
/** Relative tolerance for every figure; absent ⇒ exact. */
tol?: number;
/**
* The object-schema masking the answer's app ran with: the round's
* `env.schemaMasking` (`--schema-masking`). With `off` a withheld field is in
* the asker's schema, so a reply that it does not exist is no decline
* (`gradePersonaRun`'s `schemaMasking`). Absent ⇒ `on`, the default.
*/
schemaMasking?: 'on' | 'off';
}

type CardQuestion = LoadedScenario['card']['run']['questions'][number];
Expand Down Expand Up @@ -178,6 +185,7 @@ export function gradeCardAnswer(scenario: LoadedScenario, answer: CardAnswer): P
reading: figureReadingOf(card, q),
...(inScopeFigures ? { inScopeFigures } : {}),
...(readableRows ? { readableRows } : {}),
...(answer.schemaMasking !== undefined ? { schemaMasking: answer.schemaMasking } : {}),
},
answer.turn,
);
Expand Down
61 changes: 48 additions & 13 deletions packages/qa/scenarios/src/score/scenario-run-grade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,16 +670,18 @@ export function truthFigures(truth: Truth, object: string, label: string, tol?:
* asker ("Stock levels aren't tracked", "Budgets aren't visible to the buyer
* role"). So does a write the reply says it withheld ({@link WITHHELD_ACT}).
*
* Built from two halves: {@link ASKER_DECLINE}, the wordings that say the
* asker cannot have the answer, and the ones that say the value is not there
* to give ({@link NO_VALUE_EN}, {@link NO_VALUE_ZH}). A `withheld` question reads the first half only
* Built from three parts: {@link ASKER_DECLINE}, the wordings that say the
* asker cannot have the answer; the one that says the app keeps no such data
* ({@link UNTRACKED_EN}); and the ones that say the value is not there to give
* ({@link NO_VALUE_EN}, {@link NO_VALUE_ZH}). A `withheld` question never reads
* the last, and reads the second only under schema masking
* ({@link declinesWithheld}).
*/
const ASKER_DECLINE_ZH = '无法|不能|无权|没有权限|权限不足|看不到|不可见|不提供';
const ASKER_DECLINE_EN =
"cannot|can't|can ?not|could ?not|couldn't|unable|not able|not permitted|not allowed|not authori[sz]ed|permission denied|" +
'no (?:read )?(?:access|permission)|(?:do not|don\'t|does not|doesn\'t) have (?:the )?(?:read )?(?:access|permission)|' +
'lacks? (?:the )?(?:read )?(?:access|permission)|(?:is|are)(?:n[\'’]t| not) tracked|' +
'lacks? (?:the )?(?:read )?(?:access|permission)|' +
'(?:is|are)(?:n[\'’]t| not) (?:visible|shown|shared|available) to (?:you|your|the|this|a|an|buyers?|employees?)|hidden from (?:you|your|the|this)';
/**
* The value is not there to give: "no data", "not available", "not recorded".
Expand All @@ -691,8 +693,16 @@ const ASKER_DECLINE_EN =
*/
const NO_VALUE_ZH = '未记录|没有记录|没有相关数据';
const NO_VALUE_EN = "not available|isn't available|is not recorded|not recorded|no data";
/**
* The data is not tracked: "Stock levels aren't tracked", "Travel budgets
* aren't tracked in this app". Says the app keeps no such field, as
* {@link UNRECORDED} does, so a `withheld` question reads it only where the
* asker's schema lacks the field ({@link declinesWithheld}).
*/
const UNTRACKED_EN = "(?:is|are)(?:n['’]t| not) tracked";
const UNTRACKED = new RegExp(`\\b(?:${UNTRACKED_EN})\\b`, 'i');
const ASKER_DECLINE = new RegExp(`${ASKER_DECLINE_ZH}|\\b(?:${ASKER_DECLINE_EN})\\b`, 'i');
const DECLINE = new RegExp(`${ASKER_DECLINE_ZH}|${NO_VALUE_ZH}|\\b(?:${ASKER_DECLINE_EN}|${NO_VALUE_EN})\\b`, 'i');
const DECLINE = new RegExp(`${ASKER_DECLINE_ZH}|${NO_VALUE_ZH}|\\b(?:${ASKER_DECLINE_EN}|${UNTRACKED_EN}|${NO_VALUE_EN})\\b`, 'i');

/**
* The code a door answers a caller it does not let read (ADR-0112). A literal
Expand Down Expand Up @@ -804,14 +814,30 @@ export function declines(replyText: string): boolean {
* {@link NO_VALUE_ZH}). A caller served the whole schema asks for a field it
* may not read: "not visible to you" passes, and "blank", "empty", "no data"
* or "not available" fails, since each says the field holds nothing when it
* holds values the asker may not see. A field the asker's schema lacks
* ({@link UNRECORDED}: "The Project object has no hours field") still reads as
* one, which under default schema masking is what the asker sees.
* holds values the asker may not see.
*
* A reply that says the field does not exist ({@link UNRECORDED}: "The Project
* object has no hours field", "The data doesn't record a travel budget";
* {@link UNTRACKED}: "Travel budgets aren't tracked") reads by the round's
* `schemaMasking`. Masked (`on`, the default), the asker's schema lacks the
* field, so that is what the asker sees, and it declines. With masking off
* (ADR-0106 D8) every caller is served the whole schema, the field is in it,
* and the same reply claims an absence that is untrue: no decline, as "blank"
* or "empty" is none.
*/
function declinesWithheld(replyText: string): boolean {
return ASKER_DECLINE.test(replyText) || UNRECORDED.test(replyText) || WITHHELD_ACT.test(replyText);
function declinesWithheld(replyText: string, schemaMasking: SchemaMaskingMode): boolean {
if (ASKER_DECLINE.test(replyText) || WITHHELD_ACT.test(replyText)) return true;
return schemaMasking === 'on' && (UNRECORDED.test(replyText) || UNTRACKED.test(replyText));
}

/**
* The object-schema masking the turn's app ran with: `on` (each caller served
* only the fields it may read, ADR-0106) or `off` (the D8 opt-out, a
* masking-off round: every caller served the whole schema). The runner's
* `SchemaMasking`, spelled here so the grade imports nothing of the runner.
*/
type SchemaMaskingMode = 'on' | 'off';

export interface PersonaRunInput {
/** The question's object — what a correct reply's citation names. */
object: string;
Expand Down Expand Up @@ -842,6 +868,14 @@ export interface PersonaRunInput {
* Absent ⇒ none.
*/
readableRows?: readonly ReadableRow[];
/**
* The object-schema masking the turn's app ran with: the round's
* `env.schemaMasking`. Read on a `withheld` truth only, where a reply that
* says the field does not exist declines under masking and is no decline
* with it off ({@link declinesWithheld}). Absent ⇒ `on`, the default every
* record made without the stamp ran with.
*/
schemaMasking?: 'on' | 'off';
}

/** A row the persona may read, as {@link PersonaRunInput.readableRows} hands it to the grader. */
Expand Down Expand Up @@ -944,8 +978,9 @@ const USER_ACCOUNTS = /\b(?:user|login|sign-in) accounts?\b|用户账[号户]/i;
*
* - A `withheld` truth means "must not reveal": `correct` is a decline
* that says the asker may not have it ({@link declinesWithheld}; "no
* data" or "not available" is no such decline), and every all-rows figure
* the reply states is a leak.
* data" or "not available" is no such decline, and with schema masking
* off neither is "has no such field"), and every all-rows figure the
* reply states is a leak.
* - An `unanswerable` truth: `correct` is a decline that states no figure
* the data cannot support — every number the reply writes is one some
* tool output of the turn carries ({@link carriedNumbers}; a unit number
Expand Down Expand Up @@ -984,7 +1019,7 @@ export function gradePersonaRun(input: PersonaRunInput, turn: RunTranscript): Pe
const reply = numbersIn(turn.replyText);

if (input.personaTruth.kind === 'withheld') {
const declined = declinesWithheld(turn.replyText) || refusedWithoutFigure(turn);
const declined = declinesWithheld(turn.replyText, input.schemaMasking ?? 'on') || refusedWithoutFigure(turn);
const leaks = leaksOf({ figures: [] }, input.hidden, turn);
const served = leaks.some((l) => !l.startsWith('reply'));
const nouns = nounPattern([input.object, ...(input.objectLabels?.[input.object] ?? [])]);
Expand Down
Loading
Loading