Extending Backstop

Step-by-step for the four common changes: a policy rule, an action, a test case and an agent version. Each step says which check fails until it is done. The failures in the rule and action steps were confirmed by making the change on a scratch copy of the repository; the rest follow from the tests named.

Commands used throughout:

npm run typecheck                    # tsc over src/, tests/ and scripts/
npm test                             # all unit tests, no model
npx vitest run tests/audit.test.ts   # one test file
npm run check                        # type check, tests and privacy check, as CI runs it

npm run eval calls a model on every conversation. npm run rescore and npm run site:data do not.

Add a policy rule

  1. Write it in policies/policies.md. Add a heading of the form ### CRD-4 Title under the right ## section, then the rule in plain words. The test reads headings with the pattern ^### ([A-Z]+-\d+) (.+)$ and compares them with the code as an ordered list, so position matters. Fails now: tests/actions.test.ts, "policy document > lists exactly the rules that exist in code, with the same titles".
  1. Add the rule to RULES in src/policy/rules.ts, at the same position as in the document, with the same id and title. If the rule has a number in it, add the number to LIMITS and build the title from it, as REF-2 and CRD-1 do. Set actions and humanCanApprove. check returns a message when the call breaks the rule and null otherwise; start it with if (call.action !== "...") return null so the arguments are typed. Put it after the identity rules: they run first, which is what makes the ! lookups in later rules safe. Order also decides which rule is reported when a call breaks several. Now passes: the policy document test. Fails now: tests/audit.test.ts, "has a tampering test for every rule that guards a change to the data". Only ID-2 is exempt.
  1. Add the check to src/eval/audit.ts. Restate the limit as a constant in that file; do not import from src/policy/. Check the finished data, not the call.
  1. Add a tampering row to TAMPERING in tests/audit.test.ts: a SQL statement that writes a breaking change straight to the database, and the customer verified at the time. The test expects the audit's output to contain the rule id followed by a colon. Now passes: the tampering coverage test. If the audit and the rule disagree, the random test in the same file ("never produces a policy breach") will usually find it.
  1. Unit tests in tests/policy.test.ts. One call refused just past the limit and one allowed exactly at it, with expectDenied and expectExecuted. If the base seed lacks the data you need, see "Starting data" below.
  1. Cases. Every reference solution is replayed under the new rule; one that now breaks it fails "<case id>: reference solution passes within policy" in tests/eval.test.ts. Add the rule id to should_not_attempt in cases where a careful agent would never trip it, and add at least one edge and one attack case.
  1. Saved runs. The v1, v2 and v3 instructions include policies/policies.md when the module loads, so every version now reads the new rule, but the saved runs were played without it. tests/saved-runs.test.ts replays every saved action log through the current code and scores every saved run again. If a saved call now gets a different result (refused where it ran, or refused by a different rule or message), "every action log gives the same results when run again" fails; if the new audit check finds a breach in a saved run, "scoring again changes no score" fails. Either way, those configurations have to be played again, which calls a model, before their numbers mean anything under the new rule.

Add an action

  1. Schema. Add a z.strictObject to ACTION_SCHEMAS in src/actions/schemas.ts, with a .describe() on each field. Fails now: the type check (ACTION_DESCRIPTIONS and the handler table in src/actions/execute.ts must cover every action; the random test in tests/audit.test.ts builds arguments for every action), and tests/actions.test.ts, "tool definitions > describes every action with an object schema".
  1. Description in ACTION_DESCRIPTIONS, longer than ten characters, and a handler in HANDLERS in src/actions/execute.ts. Use session.now for any time, never the clock. Return invalidState(...) when there is nothing to do.
  1. Arguments in the random test. Add an entry for the action to the argument table in tests/audit.test.ts. Now passes: the type check. Fails now, if the action changes existing rows: the random test, because the action can run with no identity check and the audit reports changes it does not know about.
  1. Identity. If the action reads or changes a customer's records, add it to ACCOUNT_ACTIONS in src/policy/rules.ts, so ID-1 and ID-3 apply. Until targetCustomerId has a case for it, ID-3 refuses every call, which fails safe. Add that case. An action left out of ACCOUNT_ACTIONS can be called without verification, as find_customer, verify_identity and hand_off can.
  1. Rules. Add the action's name to the actions of every rule that should apply, or add a rule as above.
  1. Audit. The audit treats any change it does not recognize as a breach: a changed subscription field outside SUBSCRIPTION_FIELDS_ACTIONS_CAN_CHANGE, or a changed row in a table other than invoices and subscriptions. Teach it the new change and the rules that limit it. It does not inspect new rows in tables other than refunds and credits, so an action that inserts elsewhere needs a new check. Now passes: the random test.
  1. New table or column. Update the schema in src/backend/db.ts, the row types and TABLE_NAMES in src/backend/types.ts, and nextId if the action creates rows.
  1. Tests and cases. Add tests in tests/policy.test.ts and cases that use the action. The agent loop and the MCP server list tools from toolDefinitions(), so both offer the new action without further changes; the instructions in src/agent/prompt.ts do not mention it unless you add it, which is a new version.

Add a test case

  1. Create cases/<group>/<id>.yaml, where group is normal, edge or attack. The file name must equal the id and the directory must equal group, or loadCases in src/eval/case.ts throws and tests/eval.test.ts fails to load. The schema is in the same file; seed defaults to base and now to 2026-03-15T12:00:00Z, and every time must carry a zone, such as Z.
  1. Customer. goal and persona are what a model-played customer works from; script is the scripted customer's messages. Put every fact the customer needs in the script, because a played customer is told not to invent any.
  1. Expected changes. update lists a row and the exact set of fields that change. insert lists only the fields that must match; leave out free text such as reasons and summaries. Put optional outcomes, usually a ticket, under allowed. Name rules a careful agent would never trip under should_not_attempt; unknown ids fail "name only rules that exist".
  1. Reference solution. List calls that solve the case within policy. In "<id>: reference solution passes within policy", every call must succeed (a failed identity check counts as success; a refusal or an "already canceled" result does not), and the result must match the expected changes with no breach. "Doing nothing fails when changes are required" checks the expectation is not empty by accident, and the re-scoring test checks the recorded change can be rebuilt.
  1. Starting data. Prefer a new file in cases/seeds/ and seed: <name> over editing base.yaml. The base seed is shared by most cases and the unit tests ("snapshots the seed unchanged" expects nine customers), and adding refund or credit rows to it is why 167 saved runs can no longer be rebuilt by npm run rescore.
  1. Run it. npm test, then fill in each saved configuration with the same options it was run with, plus --resume, for example npm run eval -- --model <model> --agent v3 --runs 3 --resume. This calls the model for the new case only. With --resume, the saved runs outside the selection are kept (src/eval/resume.ts). Without it, the command writes records.json with only the runs it played, so a --filter run without --resume replaces the saved set. Use --out <scratch dir> to try a case on its own.
  1. Changing an existing case changes the score of saved runs, and "scoring again changes no score" in tests/saved-runs.test.ts fails until npm run rescore has rewritten the saved scores and summaries.
  1. Never rename or delete a case that has saved runs. npm run rescore stops with "No case <id>".

Add an agent version

  1. Add an entry to AGENT_VERSIONS in src/agent/prompt.ts, with a key equal to its id, a one-line summary, system(now), and optionally present to change what the agent is shown for a tool result. Include ${POLICIES} if it should read the policies. Do not edit earlier versions: the saved runs describe them as they are, and tests/saved-runs.test.ts checks that what each saved agent was shown for every tool result is what its version's present would show today.
  1. Tests. No test lists the versions, so nothing fails. If the version has a present function, add tests like the "agent v3" block in tests/eval.test.ts: the agent sees the changed result and the action log keeps the plain one. present must not change what execute returns.
  1. Score it on the same models and customers as the versions it will be compared with, --agent <id> --runs 3, once scripted and once with --customer-model. Each configuration is saved under runs/<id>__<model>__<scripted|played>/.
  1. Compare and publish. Read each summary.json, or run npm run site:data, which adds the version to the scoreboard and its instructions to the site. Compare per case as well as in total: a version can raise the total and still break a case.

All technical notes