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 itnpm run eval calls a model on every conversation. npm run rescore and npm run site:data do not.
Add a policy rule
- Write it in
policies/policies.md. Add a heading of the form### CRD-4 Titleunder 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".
- Add the rule to
RULESinsrc/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 toLIMITSand build the title from it, as REF-2 and CRD-1 do. SetactionsandhumanCanApprove.checkreturns a message when the call breaks the rule andnullotherwise; start it withif (call.action !== "...") return nullso 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.
- Add the check to
src/eval/audit.ts. Restate the limit as a constant in that file; do not import fromsrc/policy/. Check the finished data, not the call.
- Add a tampering row to
TAMPERINGintests/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.
- Unit tests in
tests/policy.test.ts. One call refused just past the limit and one allowed exactly at it, withexpectDeniedandexpectExecuted. If the base seed lacks the data you need, see "Starting data" below.
- 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 toshould_not_attemptin cases where a careful agent would never trip it, and add at least one edge and one attack case.
- Saved runs. The v1, v2 and v3 instructions include
policies/policies.mdwhen the module loads, so every version now reads the new rule, but the saved runs were played without it.tests/saved-runs.test.tsreplays 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
- Schema. Add a
z.strictObjecttoACTION_SCHEMASinsrc/actions/schemas.ts, with a.describe()on each field. Fails now: the type check (ACTION_DESCRIPTIONSand the handler table insrc/actions/execute.tsmust cover every action; the random test intests/audit.test.tsbuilds arguments for every action), andtests/actions.test.ts, "tool definitions > describes every action with an object schema".
- Description in
ACTION_DESCRIPTIONS, longer than ten characters, and a handler inHANDLERSinsrc/actions/execute.ts. Usesession.nowfor any time, never the clock. ReturninvalidState(...)when there is nothing to do.
- 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.
- Identity. If the action reads or changes a customer's records, add it to
ACCOUNT_ACTIONSinsrc/policy/rules.ts, so ID-1 and ID-3 apply. UntiltargetCustomerIdhas a case for it, ID-3 refuses every call, which fails safe. Add that case. An action left out ofACCOUNT_ACTIONScan be called without verification, asfind_customer,verify_identityandhand_offcan.
- Rules. Add the action's name to the
actionsof every rule that should apply, or add a rule as above.
- 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.
- New table or column. Update the schema in
src/backend/db.ts, the row types andTABLE_NAMESinsrc/backend/types.ts, andnextIdif the action creates rows.
- Tests and cases. Add tests in
tests/policy.test.tsand cases that use the action. The agent loop and the MCP server list tools fromtoolDefinitions(), so both offer the new action without further changes; the instructions insrc/agent/prompt.tsdo not mention it unless you add it, which is a new version.
Add a test case
- Create
cases/<group>/<id>.yaml, where group isnormal,edgeorattack. The file name must equal the id and the directory must equalgroup, orloadCasesinsrc/eval/case.tsthrows andtests/eval.test.tsfails to load. The schema is in the same file;seeddefaults tobaseandnowto 2026-03-15T12:00:00Z, and every time must carry a zone, such asZ.
- Customer.
goalandpersonaare what a model-played customer works from;scriptis the scripted customer's messages. Put every fact the customer needs in the script, because a played customer is told not to invent any.
- Expected changes.
updatelists a row and the exact set of fields that change.insertlists only the fields that must match; leave out free text such as reasons and summaries. Put optional outcomes, usually a ticket, underallowed. Name rules a careful agent would never trip undershould_not_attempt; unknown ids fail "name only rules that exist".
- 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.
- Starting data. Prefer a new file in
cases/seeds/andseed: <name>over editingbase.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 bynpm run rescore.
- Run it.
npm test, then fill in each saved configuration with the same options it was run with, plus--resume, for examplenpm 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 writesrecords.jsonwith only the runs it played, so a--filterrun without--resumereplaces the saved set. Use--out <scratch dir>to try a case on its own.
- Changing an existing case changes the score of saved runs, and "scoring again changes no score" in
tests/saved-runs.test.tsfails untilnpm run rescorehas rewritten the saved scores and summaries.
- Never rename or delete a case that has saved runs.
npm run rescorestops with "No case <id>".
Add an agent version
- Add an entry to
AGENT_VERSIONSinsrc/agent/prompt.ts, with a key equal to itsid, a one-linesummary,system(now), and optionallypresentto 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, andtests/saved-runs.test.tschecks that what each saved agent was shown for every tool result is what its version'spresentwould show today.
- Tests. No test lists the versions, so nothing fails. If the version has a
presentfunction, add tests like the "agent v3" block intests/eval.test.ts: the agent sees the changed result and the action log keeps the plain one.presentmust not change whatexecutereturns.
- 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 underruns/<id>__<model>__<scripted|played>/.
- Compare and publish. Read each
summary.json, or runnpm 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.