Skip to content

Commit f555352

Browse files
feat(scenarios): the confirm-first line asks the build to lock the change a gated action makes (#36091)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} --> _Requested by **Elon** · [project thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9D7UBkcmf1Qy7iEMxarYt8wU)_ Fixes #35908 Clause-②: no Metadata-protocol: none ## 维护者速读 - 评测场景卡的搭建提示词变了,用户无感:需先确认的操作那一行,现在还要求搭建方把这次改动锁住,只能经该操作改。 - 属于场景卡评测工具;落实维护者「三个问题 同意」里的补充:确认门不扩到直接改记录,所以由搭建方加锁堵住绕行。 - 出错只影响评测跑出的应用:锁错了某人的其他正常改动会被拒,评测分数失真;只改提示词文本,可直接撤回。 - 无 ## What changes `packages/qa/scenarios/src/runner/prompts.ts`: the build contract's line for each confirm-gated agent action (`run.agentActions[].confirm: true`) used to end in `(confirm first)` only. The gate (`ai.requiresConfirmation`) guards the action's own door, and on the maintainer's ruling it is not widened to `update_record`, so an agent that met the gate could still write the target state through the raw data door. The line now also asks the build to lock that change, with the mechanism the published skills teach (objectstack-ai pitfall "Gating the action, not the state"; objectstack-data `rules/security.md`, row-conditioned edit lock): > (confirm first; the confirmation guards this action’s own door only, so also lock the change it makes: if it changes fields of its row, make those fields not editable for each person who runs it, at the stage it acts on (a field permission `when` in their permission set), and have the action write them elevated, so a plain record update cannot make that change while those people’s other changes to the same fields still land; an action that deletes its row locks nothing, and those people keep their delete right) Two limits come from the card audit below, and are why the wording is not a bare field lock: 1. **Stage-scoped, per person** (a field permission `when`, not `readonly: true` and not an unconditional field permission). A whole-field lock on `ticket.status` for the team lead would refuse `resolve_without_code` with `403 PERMISSION_DENIED` before validation runs, breaking service_desk's `write_validation` guardrail, which expects `VALIDATION_FAILED`. `readonly: true` would strip every non-system write of the field, including the support agent's applied resolve. 2. **Deletes lock nothing.** Four cards gate a delete action and give the same persona an applied plain delete of the same object; locking deletion would deny them. Lines for actions that are not confirm-gated are unchanged. No card JSON changes. ## Card audit (the card's ask) Gated action → the op that exercises it (`pending_confirmation`) → what the stage-scoped lock covers → the same persona's other operations on that field. | Card | Gated action (object) | Runs it | Lock under the new wording | Same persona's other ops on the field | Verdict | |:--|:--|:--|:--|:--|:--| | asset_lifecycle | `dispose_asset` (disposal_request) | asset_admin (`dispose_scrapped_asset`, dr04 `approved`) | `status`, `disposed_on` at `approved` | none (asset_admin's applied ops write `asset` and `checkout`). dept_manager's applied `manager_approves_scrap` writes `status` too: another persona, its set is not locked | no conflict | | crm_account_with_contacts | `delete_contact` (contact) | sdr (`remove_tech_contact`) | nothing: a delete | `remove_ben`: sdr, applied delete of a contact | no conflict, because the wording exempts deletes | | invoice_with_line_items | `delete_invoice_line` (invoice_line) | sales_rep (`remove_inv001_line`) | nothing: a delete | `remove_line`: sales_rep, applied delete of a line | no conflict, because the wording exempts deletes | | leave_balances | `delete_leave_request` (leave_request) | hr_officer (`delete_zoes_withdrawn_request`) | nothing: a delete | `delete_withdrawn_request`: hr_officer, applied delete of a request | no conflict, because the wording exempts deletes | | order_to_cash | `write_off_balance` (invoice) | ar_clerk (`write_off_balance`, inv005 `open`) | `status` at the open-balance stages | none applied. `overpay_invoice` (refused `VALIDATION_FAILED`) is a `payment` insert, refused before any invoice write | no conflict | | project_with_tasks | `delete_task` (task) | contractor (`drop_relaunch_task`) | nothing: a delete | `drop_packing`: contractor, applied delete of a task | no conflict, because the wording exempts deletes | | requisition_to_receipt | `cancel_purchase_order` (purchase_order) | buyer (`cancel_sent_po`, po116 `sent`) | `status` at `sent` | `raise_po_from_text` (applied; target state `status: sent`) moves draft to sent, a different stage. `fix_chair_quantity` writes `po_line` on a `draft` PO | no conflict, with one hazard: an insert sent straight at `sent` meets a `when` lock (an insert is judged on the row as sent). The wording asks that the same people's other changes still land, so the build routes the raise through draft or an elevated action | | service_desk | `close_ticket` (ticket) | team_lead (`close_ticket`, t062 `resolved`) | `status` at `resolved` | `reassign_ticket` (applied) writes `assignee` only. `resolve_without_code` (refused `VALIDATION_FAILED`, the `write_validation` guardrail) writes `status` on t114 at `open`, outside the lock's stage, so validation still answers | a whole-field lock conflicts; resolved by the stage wording | | travel_expense | `pay_claim` (expense_claim) | finance_officer (`pay_claim`, c118 `finance_approved`) | `status`, `paid_on` at `finance_approved` | none on the card. The finance step's approval moves the claim at `manager_approved`, a different stage | no conflict | Result: no card needs an edit. Every conflict is resolved in the prompt wording: the delete exemption covers crm, invoice, leave and project; the stage scope covers service_desk and requisition. The PM brief named three same-persona applied deletes (leave `delete_withdrawn_request`, crm `remove_ben`, invoice `remove_line`). The audit found a fourth: project_with_tasks `drop_packing`. ## Tests - New top-level `describe` in `packages/qa/scenarios/test/runner/units.test.ts` (the package's prompt harness): - service_desk: the confirm-first `close_ticket` line carries the lock, the stage scope and the delete exemption, and the three plain action lines carry none of it. - Across all nine cards, each confirm-gated line asks for the lock and each plain line does not (9 gated lines counted). - `pnpm --filter @objectstack/scenarios build && … test && … typecheck`: Test Files 40 passed (40), Tests 1213 passed (1213), `tsc --noEmit` exit 0. The package tsconfig includes `test/**/*`. - Ablation: the line restored to ` (confirm first)` through `scripts/ablation-replace.mjs` (anchor 1 → 0, blob b0cd816 → 582d46117f0c). Result: 2 failed and 77 passed in `units.test.ts`, both new pins red. Restored: blob equals HEAD and `git diff HEAD` is empty. The tests import `src/` directly, so no rebuild leg was needed. ## Acceptance notes - The wording does not name fields or values. The build contract never states operations or their outcomes (`prompts.ts` header), so the build reads which fields change, and at which stage, from the action summary and the app prompt. - Out of reach of this card: the scorer does not check that the lock exists. `gradeAgentActions` checks `ai.exposed` and `ai.requiresConfirmation` only. Whether a build obeys the new line shows up only in a run's confirm turn. ## Verification Two-minute check: run `pnpm --filter @objectstack/scenarios exec vitest run --maxWorkers=2 test/runner/units.test.ts -t "stage-scoped field lock"`. Expected result: 2 passed. <details><summary>Dry-run of the build prompt (service_desk, crm_account_with_contacts): the action section</summary> ```text == service_desk Business actions an AI agent may call (expose each to AI; ask before acting where marked): - `demohelpdesk_log_ticket` on `demohelpdesk_ticket`: Log a ticket for a customer, with its first comment, in the right group's queue. - `demohelpdesk_reply_to_customer` on `demohelpdesk_ticket_comment`: Post a public reply or an internal note on a ticket, with the minutes spent. - `demohelpdesk_resolve_ticket` on `demohelpdesk_ticket`: Resolve a ticket with its resolution code; this sends the satisfaction survey. - `demohelpdesk_close_ticket` on `demohelpdesk_ticket`: Close a resolved ticket for good; irreversible. (confirm first; the confirmation guards this action’s own door only, so also lock the change it makes: if it changes fields of its row, make those fields not editable for each person who runs it, at the stage it acts on (a field permission `when` in their permission set), and have the action write them elevated, so a plain record update cannot make that change while those people’s other changes to the same fields still land; an action that deletes its row locks nothing, and those people keep their delete right) == crm_account_with_contacts Business actions an AI agent may call (expose each to AI; ask before acting where marked): - `democrm_create_contact` on `democrm_contact`: Add a contact, optionally under an account. - `democrm_reassign_contact` on `democrm_contact`: Move a contact to another account. - `democrm_delete_contact` on `democrm_contact`: Delete a contact; irreversible. (confirm first; …same line…) ``` </details> <details><summary>Local gate subset at 274fb5f: 61 derived families, 59 exit 0, 2 NOT MEASURED</summary> - `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` derived 61 commands. Each was run with its exit code captured before any pipe. `--ran` reconciliation: "61 derived famil(ies) accounted for — 59 run, 2 NOT-MEASURED (2 DERIVED from a recorded exit 3)". - NOT MEASURED: `pnpm check:dual-build-cjs-loads`, exit 3, PREREQUISITE NOT MET (reads every package's dist; only the scenarios closure was built). Left to CI. - NOT MEASURED: `node scripts/check-plugin-teardown-shape.mjs --self-test`, exit 3 (pinned fixture commit unreachable from a shallow clone). Left to CI. - `scripts/pm/overlap-check.mjs` before each push: VERDICT clean exit 0, 0 PR heads overlap. - Pre-push `check:commit-card-trailers`: 2 commit messages carry no card relation and no model identifier. </details> Files to read first, by risk: 1. `packages/qa/scenarios/src/runner/prompts.ts`: the `CONFIRM_FIRST_LOCK` text and its docblock. This is the hunk at risk: the wording decides what every gated build locks. 2. `packages/qa/scenarios/test/runner/units.test.ts`: the new `describe`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_016WV4cypybwgoxE3ZMZy8kt --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
1 parent 2b540f4 commit f555352

3 files changed

Lines changed: 77 additions & 1 deletion

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/scenarios': patch
3+
---
4+
5+
Clause-②: no
6+
Metadata-protocol: none
7+
8+
feat(scenarios): the build prompt's confirm-first line asks the build to lock the change a gated action makes
9+
10+
A confirm-gated agent action (`ai.requiresConfirmation`) guards its own door only; the gate is not widened to the raw data door, so an agent that met the gate could still write the target state with a plain record update. The build contract's line for each confirm-first action now also asks the build to lock that change: when the action changes fields of its row, those fields are made not editable for each person who runs it, at the stage the action acts on (a field permission `when` in their permission set), and the action writes them elevated, so the same people's other changes to those fields still land. An action that deletes its row locks nothing, and its people keep their delete right. Lines for actions that are not confirm-gated are unchanged.

‎packages/qa/scenarios/src/runner/prompts.ts‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,29 @@ function rowOwnership(card: Card): string[] {
420420
return lines;
421421
}
422422

423+
/**
424+
* What a confirm-gated agent action's line asks of the build. The gate
425+
* (`ai.requiresConfirmation`) guards the action's own door only, and it is not
426+
* widened to the raw data door (`update_record`), so without a lock an agent
427+
* that meets the gate can write the target state directly. The lock is the one
428+
* the objectstack-ai skill teaches (pitfall "Gating the action, not the
429+
* state"): the fields made not editable for the people who run the action,
430+
* written elevated by the action itself.
431+
*
432+
* Two limits keep it from denying a card's own operations: it is scoped to the
433+
* stage the action acts on (a field permission `when`), so the same people's
434+
* other changes to those fields still land (a team lead's resolve, refused by
435+
* validation, meets no lock before the ticket is resolved); and an action that
436+
* deletes its row locks nothing, since the same people's plain deletes are
437+
* applied operations on several cards.
438+
*/
439+
const CONFIRM_FIRST_LOCK =
440+
'confirm first; the confirmation guards this action’s own door only, so also lock the change it makes: ' +
441+
'if it changes fields of its row, make those fields not editable for each person who runs it, at the stage it acts on ' +
442+
'(a field permission `when` in their permission set), and have the action write them elevated, ' +
443+
'so a plain record update cannot make that change while those people’s other changes to the same fields still land; ' +
444+
'an action that deletes its row locks nothing, and those people keep their delete right';
445+
423446
/** The runner's contract, appended to every build prompt. */
424447
export function dataContract(card: Card): string {
425448
const lines: string[] = [];
@@ -461,7 +484,7 @@ export function dataContract(card: Card): string {
461484
if (card.run.agentActions?.length) {
462485
lines.push('');
463486
lines.push('Business actions an AI agent may call (expose each to AI; ask before acting where marked):');
464-
for (const a of card.run.agentActions) lines.push(`- \`${a.name}\` on \`${a.object}\`: ${a.summary}${a.confirm ? ' (confirm first)' : ''}`);
487+
for (const a of card.run.agentActions) lines.push(`- \`${a.name}\` on \`${a.object}\`: ${a.summary}${a.confirm ? ` (${CONFIRM_FIRST_LOCK})` : ''}`);
465488
}
466489
return lines.join('\n');
467490
}

‎packages/qa/scenarios/test/runner/units.test.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,49 @@ describe('namespace-relative cards', () => {
795795
});
796796
});
797797

798+
describe('the build contract asks for a stage-scoped field lock on a confirm-first action, and on no other action', () => {
799+
// The gate guards the action's own door only and is not widened to `update_record`, so the
800+
// line asks the build to lock the change itself. The fragments below are what the build reads.
801+
const LOCK = 'lock the change it makes';
802+
const STAGE = 'at the stage it acts on (a field permission `when` in their permission set)';
803+
const DELETE_EXEMPT = 'an action that deletes its row locks nothing, and those people keep their delete right';
804+
const actionLines = (contract: string): string[] => contract.split('\n').filter((l) => / on `[a-z0-9_]+`: /.test(l) && l.startsWith('- `'));
805+
806+
it('service_desk: the confirm-first `close_ticket` line carries the lock; `log_ticket`, `reply_to_customer` and `resolve_ticket` do not', () => {
807+
const desk = namespacedScenario(load(resolve(HERE, '../../../../../docs/qa/scenarios/service_desk.json'))).card;
808+
const lines = actionLines(dataContract(desk));
809+
expect(lines).toHaveLength(4);
810+
const close = lines.find((l) => l.includes('close_ticket` on '))!;
811+
expect(close).toContain(': Close a resolved ticket for good; irreversible. (confirm first; ');
812+
for (const fragment of [LOCK, STAGE, DELETE_EXEMPT]) expect(close).toContain(fragment);
813+
for (const plain of lines.filter((l) => l !== close)) {
814+
expect(plain).not.toContain('confirm first');
815+
expect(plain).not.toContain(LOCK);
816+
}
817+
});
818+
819+
it('every card: each confirm-gated action line asks for the lock, and each plain one asks for nothing', () => {
820+
const files = ['asset_lifecycle', 'crm_account_with_contacts', 'invoice_with_line_items', 'leave_balances', 'order_to_cash', 'project_with_tasks', 'requisition_to_receipt', 'service_desk', 'travel_expense'];
821+
let gated = 0;
822+
for (const f of files) {
823+
const card = namespacedScenario(load(resolve(HERE, `../../../../../docs/qa/scenarios/${f}.json`))).card;
824+
const lines = actionLines(dataContract(card));
825+
expect(lines, f).toHaveLength(card.run.agentActions!.length);
826+
card.run.agentActions!.forEach((a, i) => {
827+
if (a.confirm) {
828+
gated += 1;
829+
expect(lines[i], `${f} ${a.name}`).toContain(`(confirm first; `);
830+
expect(lines[i], `${f} ${a.name}`).toContain(LOCK);
831+
expect(lines[i], `${f} ${a.name}`).toContain(DELETE_EXEMPT);
832+
} else {
833+
expect(lines[i], `${f} ${a.name}`).not.toContain(LOCK);
834+
}
835+
});
836+
}
837+
expect(gated).toBe(9);
838+
});
839+
});
840+
798841
// ── The seed's load plan ────────────────────────────────────────────────────
799842

800843
const SCENARIOS_DIR = resolve(HERE, '../../../../../docs/qa/scenarios');

0 commit comments

Comments
 (0)