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
12 changes: 12 additions & 0 deletions .changeset/33596-scenario-grader-build-denies-write.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@objectstack/scenarios': patch
---

fix(scenarios): a write the card gives a persona that the build denies it is charged to the build, not the operation

Clause-②: yes (widening) — new exports `buildDeniesWrite` and `isWriteDenial` (`./score`, `./score/full`), `probesBuildDenial` (`.`), `buildDenialFindings` (`./runner`); new optional fields `OperationGrade.notMeasured` (`./score`, `./score/full`) and `OperationResult.buildDenial` (`./runner`)
Metadata-protocol: none

An operation declared `applied` whose agent write was refused 403 `PERMISSION_DENIED` counted as the operation's failure, even when the built app's permission set denied the persona a write the card gives it: the loss landed on the asking side for a build error.

The runner now sends the declared write itself as the persona when the agent's own write on an `applied` create or update was denied 403 and nothing was written. When the door denies the probe too, and the build declares no lock that routes the write through an action, the operation is not measured ("the build denies the persona this write"): out of passed and total, and the scorecard lists a Build finding naming the persona, the object and the verb. The `write_validation` probe that meets the same 403 is reported the same way. A 403 the card declares (`refused PERMISSION_DENIED`) and a `pending_confirmation` operation grade as before, and the probe that meets the build's routed lock keeps its own not-measured reason. A hook's own refusal served at 403 (its code on `declaredCode`) is the app's rule, not a denial, and grades as before.
12 changes: 12 additions & 0 deletions docs/qa/scenarios/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,18 @@ Every other `refused` create or update is graded the same way, a permission over
included: an agent that declines without touching the door passes its half, and the
runner's own write says whether the platform refused it.

A write the card gives a persona that the build denies it is charged to the build, never to
the operation. When the agent's own write on an `applied` create or update is refused 403
`PERMISSION_DENIED` and nothing is written, the runner sends the declared write itself as that
persona; when the door denies that too, the operation is **not measured: the build denies the
persona this write** (out of passed and total), and the scorecard carries a Build finding
naming the persona, the object and the verb. The `write_validation` probe that meets the same
403 is reported the same way: its platform half is not measured, and so is the agent half
when the agent's own write met the 403. A 403 the card declares (`refused`
`PERMISSION_DENIED`) still grades as a pass of that refusal, and a `pending_confirmation`
operation grades as before: the MCP delete door asks for confirmation before it checks
permission, so a 403 there follows the agent's own `confirm: true`.

## The library

The library holds nine scenarios. The three **simple controls**, tier `control`, are here:
Expand Down
13 changes: 12 additions & 1 deletion packages/qa/scenarios/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ gradeCardAnswer(card, { question: 'account_count', persona: 'sdr', turn }); // a
scorecard's findings, when the probe met the build's own lock: refused 403
`PERMISSION_DENIED`, nothing written, and the build locks a field the probe writes for the
persona and declares an action on the object (`buildLockOf`; ruling A on #31999 item 9).
Beside it, `buildDeniesWrite`: a write the card gives the persona that the build denies it.
An `applied` create or update whose agent write was refused 403 `PERMISSION_DENIED` with
nothing written is probed too (`probesBuildDenial`); a probe denied the same way, with no
such lock, makes the whole operation not measured (`OperationGrade.notMeasured`), and the
`write_validation` probe that meets it leaves its platform half not measured (the agent
half too when the agent's own write met it). Each is a Build finding naming persona,
object and verb (`buildDenialFindings`). A declared 403 and `pending_confirmation` grade as
before.
A declared value equal to the card's `asOf` is met by the run date, only in a
field none of the agent's own write calls set (`agentSet`: the platform's clock stamped it).
- `scenario-run-grade.ts` — an answer graded on correct / cited / leaks, per persona against
Expand Down Expand Up @@ -257,7 +265,10 @@ npx @objectstack/scenarios help # the comma
reads that answer as the **probe**: the app's validation is measured on every run, whether or not the agent sent
the bad value, and a careful agent that caught it first is not failed for it. A failed probe is the platform's
failure, never the agent's. Every other `refused` create or update is probed the same way, so a permission
overstep the agent declined still measures the platform's refusal. An answer that carries no code is reported
overstep the agent declined still measures the platform's refusal. An `applied` create or update is probed only
when the agent's own write met 403 `PERMISSION_DENIED` and nothing was written (a probe after a write that
landed would apply it twice): a denied probe charges the write to the build. A probe the door applies leaves the
runner's row in place for the operations after it. An answer that carries no code is reported
with whose throw it was (`uncodedNote`: the build's own hook or action, named off the sandbox's wrapper, or the
door's text). The runner also records the run dates (each clock instant's UTC and local date) and the fields
the agent's own write calls set (`agentSetOf`: a create's or update's `data`, a `run_action`'s `params`); a
Expand Down
47 changes: 37 additions & 10 deletions packages/qa/scenarios/src/runner/orchestrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
* its persona, each over the app's own MCP, and a probed
* operation's declared write — the validation operation's and
* each permission overstep's — re-sent by the runner itself as
* that persona, `observeProbe`) → the iterate change →
* that persona, `observeProbe`; an `applied` operation's too
* when the agent's own write was denied 403, `probesBuildDenial`)
* → the iterate change →
* rebuild + re-score Build, and (unless disabled) re-run the Run half.
* A build whose authoring turn did not finish (killed by the
* runner's timeout, no result, an error result) is NOT MEASURED,
Expand All @@ -32,10 +34,12 @@
*/

import { applyExpectDelta, readableNumbers, truthsOver, type LoadedScenario } from '../loader.js';
import { isProbedOperation, PERSON_USER_FIELD, scenarioNamespace, type CardTitle } from '../schema.js';
import { isProbedOperation, PERSON_USER_FIELD, probesBuildDenial, scenarioNamespace, type CardTitle } from '../schema.js';
import {
gradeCardAnswer,
buildDeniesWrite,
gradeCardOperation,
isWriteDenial,
readArtifactFacts,
scoreCardArtifact,
type OperationGrade,
Expand All @@ -47,7 +51,7 @@ import {
import type { AppHarness, PersonaAccount } from './app.js';
import { servedAsRequested, type AgentDriver, type StepRef } from './driver.js';
import { citationLabels, namespaceOfArtifact, namespacedScenario, permissionSetName, templateHostName } from './namespace.js';
import { agentSetOf, clockDates, observeOperation, observeProbe, probeCall, touchedRowId, type Row } from './observe.js';
import { agentSetOf, clockDates, observeOperation, observeProbe, probeCall, touchedRowId, writeCallsOn, type Row } from './observe.js';
import type { CommandResult } from './project.js';
import { buildPrompt, iteratePrompt, operationPrompt, personaHandles, personaRecords, questionPrompt, rowOwner, templateIteratePrompt, userHandleFields, verifyArgs } from './prompts.js';
import { lookupKey, requiredLookups, seedPlan, type SeedLookup } from './seed.js';
Expand Down Expand Up @@ -150,8 +154,19 @@ export interface QuestionResult {
export interface OperationResult {
operation: string;
persona: string;
/** Why this operation was not run: it acts on a row the seed could not load ({@link seedDependence}). Not measured, never a fail. */
/**
* Why this operation is not measured: it was not run, because it acts on a
* row the seed could not load ({@link seedDependence}); or it ran and its
* grade measured nothing (`OperationGrade.notMeasured`: the build denies the
* persona the write the card gives it, `buildDeniesWrite`). Never a fail.
*/
notMeasured?: string;
/**
* The write the build denies the acting persona, when the grade charged a
* check to it (`buildDeniesWrite`): the persona, the operation's object as
* the app names it, and the verb. The scorecard lists it as a Build finding.
*/
buildDenial?: { persona: string; object: string; verb: 'create' | 'update' };
observation?: OperationObservation;
grade?: OperationGrade;
turn?: TurnSummary;
Expand Down Expand Up @@ -743,12 +758,20 @@ export async function runHalf(
const id = touchedRowId(op, rowsByObject, today);
auditActor = id === undefined ? null : personaOfUser(await app.auditActorUserId(op.object, id), accounts, app.adminUserId());
}
// A probed operation's probe (the validation operation, or a permission
// overstep): the runner sends the declared write itself, as the same
// persona through the same MCP door, after the turn. A probe that cannot
// be sent leaves the platform half "not observed".
const observed = { op, turn, before, after, rowsByObject, today, ...(auditActor !== undefined ? { auditActor } : {}) };
// The runner's probe: it sends the declared write itself, as the same
// persona through the same MCP door, after the turn. A probed operation
// (the validation operation, or a permission overstep) is always
// probed; an `applied` one only when the agent's own write was denied
// 403 and nothing was written (`probesBuildDenial`), so the build's
// denial is told from the agent's (`buildDeniesWrite`). A probe that
// cannot be sent leaves the platform half "not observed".
const agentDenied = () => {
const seen = observeOperation(observed);
return writeCallsOn(turn, op.object).length > 0 && isWriteDenial(seen.answer, seen.writes);
};
let probe: ProbeObservation | undefined;
if (isProbedOperation(card, op.id)) {
if (isProbedOperation(card, op.id) || (probesBuildDenial(card, op.id) && agentDenied())) {
try {
const call = probeCall(op, probeValues(card, op, accounts, app.adminUserId()));
const answer = await app.callTool(keyOf(op.actingAs), call.tool, call.args);
Expand All @@ -759,8 +782,12 @@ export async function runHalf(
res.error = `probe: ${errText(e)}`;
}
}
res.observation = observeOperation({ op, turn, before, after, rowsByObject, today, ...(auditActor !== undefined ? { auditActor } : {}), ...(probe ? { probe } : {}) });
res.observation = observeOperation({ ...observed, ...(probe ? { probe } : {}) });
res.grade = gradeCardOperation(scenario, op.id, res.observation);
if (res.grade.notMeasured !== undefined) res.notMeasured = res.grade.notMeasured;
if (op.kind !== 'delete' && res.grade.checks.some((c) => c.notMeasured?.startsWith(buildDeniesWrite))) {
res.buildDenial = { persona: op.actingAs, object: op.object, verb: op.kind };
}
} catch (e) {
res.error = errText(e);
}
Expand Down
29 changes: 26 additions & 3 deletions packages/qa/scenarios/src/runner/scorecard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@
* the card. It is stated only when EVERY authoring turn that ran reported
* one; otherwise it is `not reported` — a turn that reported none is never
* read as zero, and a partial sum is never shown as the channel's cost.
* - Run-operations: one per operation; it passes when its grade passes.
* - Run-operations: one per operation; it passes when its grade passes. An
* operation whose grade measured nothing (`OperationGrade.notMeasured`:
* the build denies the acting persona the write the card gives it, and
* the runner's own probe of the declared write was denied 403 too) is
* NOT MEASURED, like a seed-dependent one below. Each write the build
* denies — that one, or a validation operation's probe met by the same
* denial — is a Build finding naming persona, object and verb
* ({@link buildDenialFindings}).
* - A turn that errored counts in the total and not in passed.
* - Seed: rows loaded of rows sent. A refused row is shown as
* `⚠ seed: N refused`, and every question turn and operation that depends
Expand Down Expand Up @@ -68,8 +75,9 @@ export interface HalfScores {
ask?: Tally & { leaks: number; notMeasured: number };
/**
* `platformNotMeasured`: measured operations whose platform half met the
* build's own lock — graded on the agent half alone, the reason in the
* mode's findings ({@link platformNotMeasuredFindings}). Absent ⇒ none.
* build's own lock, or the build's denial of the write — graded on the
* agent half alone, the reason in the mode's findings
* ({@link platformNotMeasuredFindings}). Absent ⇒ none.
*/
operations?: Tally & { notMeasured: number; platformNotMeasured?: number };
/** The models the half's question and operation turns were served ({@link modelTally}). */
Expand Down Expand Up @@ -184,6 +192,19 @@ export function platformNotMeasuredFindings(r: RunHalf | undefined, half: string
});
}

/**
* One Build finding per operation whose grade charged a write to the build's
* denial (`OperationResult.buildDenial`, `buildDeniesWrite`): the build denies
* the acting persona a write the card gives it.
*/
export function buildDenialFindings(r: RunHalf | undefined, half: string): string[] {
return (r?.operations ?? []).flatMap((o) =>
o.buildDenial === undefined
? []
: [`${half}: the build denies ${o.buildDenial.persona} the ${o.buildDenial.verb} on ${o.buildDenial.object} that the card gives it (operation ${o.operation}: its probe of the declared write was refused PERMISSION_DENIED (403))`],
);
}

export function modelTally(r: RunHalf | undefined): ModelTally | undefined {
const turns = [...(r?.questions ?? []), ...(r?.operations ?? [])].flatMap((x) => (x.turn ? [x.turn] : []));
if (turns.length === 0) return undefined;
Expand Down Expand Up @@ -261,9 +282,11 @@ export function modeScorecard(m: ModeRun): ModeScorecard {
...m.findings,
...bareNameFindings(m.build, 'build'),
...requiredCycleFindings(m.build, 'build'),
...buildDenialFindings(m.run, 'build'),
...platformNotMeasuredFindings(m.run, 'run'),
...bareNameFindings(m.iterate?.build, 'iterate build'),
...requiredCycleFindings(m.iterate?.build, 'iterate build'),
...buildDenialFindings(m.iterate?.run, 'iterate build'),
...platformNotMeasuredFindings(m.iterate?.run, 'iterate run'),
],
};
Expand Down
18 changes: 18 additions & 0 deletions packages/qa/scenarios/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,3 +601,21 @@ export function isProbedOperation(card: Pick<ScenarioCard, 'run'>, operationId:
const op = card.run.operations.find((o) => o.id === operationId);
return op !== undefined && op.outcome.kind === 'refused' && op.kind !== 'delete';
}

/**
* The operations the runner may probe for the build's denial: every `applied`
* create or update (#33596). The card gives the acting persona that write, so
* when the agent's own write met 403 `PERMISSION_DENIED` and nothing was
* written, the runner sends the declared write itself as that persona; a
* probe the door denies as well makes the operation not measured, charged to
* the build (`buildDeniesWrite`). It probes only then: a probe after a write
* that landed would apply it twice and shift the rows later operations read.
* An `applied` `delete` is not probed (the runner sends no delete of its own;
* no card declares one today), and neither is a `pending_confirmation` one:
* the MCP delete door asks for confirmation before it checks permission, so a
* 403 there follows the agent's own `confirm: true` and stays the agent's.
*/
export function probesBuildDenial(card: Pick<ScenarioCard, 'run'>, operationId: string): boolean {
const op = card.run.operations.find((o) => o.id === operationId);
return op !== undefined && op.outcome.kind === 'applied' && op.kind !== 'delete';
}
Loading
Loading