Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ad5ecbc
feat(verify): draft a write contract with a model, admit it only by q…
abrichr Nov 21, 2026
89c1780
feat(verify): verify draft reads only moved tables, repeats a probe w…
abrichr Nov 21, 2026
afc9d38
feat(verify): verify draft drafts as JSON (prompt v2), allowlists dra…
abrichr Nov 21, 2026
8ed183e
bench(verify): verify draft on Directus (untuned) and the prompt-2 re…
abrichr Nov 21, 2026
8969f49
docs: CAPABILITIES row links #2438; refresh llms-full
abrichr Nov 21, 2026
b837cf5
docs: CAPABILITIES row links #2438
abrichr Nov 21, 2026
946316c
fix(verify): verify draft signs actors in before the first read, refu…
abrichr Nov 21, 2026
f781abc
Merge remote-tracking branch 'origin/main' into HEAD
abrichr Nov 21, 2026
fdd364c
fix(verify-draft): register the draft results in the public artifact …
abrichr Nov 21, 2026
3917b60
Merge remote-tracking branch 'origin/main' into HEAD
abrichr Nov 22, 2026
f09853e
chore(verify-draft): the public proof carries no model prices
abrichr Nov 22, 2026
b982f64
fix(verify-draft): a missing observation never admits a contract
abrichr Nov 22, 2026
1e4d8e7
fix(cli): verify draft shows its help when the installed engine lacks it
abrichr Nov 22, 2026
03e5a28
Merge remote-tracking branch 'origin/main' into HEAD
abrichr Nov 23, 2026
4ce89eb
Merge remote-tracking branch 'origin/main' into HEAD
abrichr Nov 23, 2026
bc409d1
test(cli): refresh root CLI surface snapshot for #2438
abrichr Nov 23, 2026
2a6fc11
Merge branch 'main' into claude/verify-draft
abrichr Nov 24, 2026
d5b272a
Merge remote-tracking branch 'origin/main' into HEAD
abrichr Nov 24, 2026
b699a74
chore(flow): eliminate verdict fold hits in verify_draft admit and in…
abrichr Nov 24, 2026
8a538b9
Merge remote-tracking branch 'origin/main' into HEAD
abrichr Nov 24, 2026
c5d1b3d
fix(flow): address review findings in verify_draft masking, verdict s…
abrichr Nov 24, 2026
f8a5ff1
Merge remote-tracking branch 'origin/main' into HEAD
abrichr Nov 24, 2026
8be01f1
Merge remote-tracking branch 'origin/main' into HEAD
abrichr Nov 24, 2026
a0a8995
Merge remote-tracking branch 'origin/main' into HEAD
abrichr Nov 24, 2026
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
| Draft a system's write contract with a model at setup, admit it only by qualification: `openadapt verify draft` gives the pinned model (`claude-opus-5-5`, prompt digest recorded in the contract's `provenance`) the system's description (OpenAPI, GraphQL, FHIR CapabilityStatement, the introspected database schema, or none), one HAR trace with sign-in and secret fields masked, what that write moved in a sandbox, and the task. The draft is admitted only if, on the sandbox, it refutes planted faults (a wrong value in each written column, the wrong row, a duplicate, a sibling record edited, the write reverted after the check, and for an update another user's save overwritten through the app), confirms 5 clean writes and their rechecks, and confirms a two-users-by-two-payloads probe whose attribution of every moved column (values, user, clock, nothing) agrees with its bookkeeping exclusions. Failures go back to the model, at most 3 rounds; a person is asked at most once, only when a planted fault could go only into excluded columns. An admitted contract runs with no model calls; an edit to its check voids the admission (`--check`). Needs an SQL store the command can read and a privileged connection to plant faults | PR ([#2438](https://github.com/OpenAdaptAI/OpenAdapt/pull/2438)) | Real app, lab, synthetic data: Directus 11.5.1, never set up before: admitted in round 2 after 6.0 minutes with 0 person decisions (round 1 was lost because a sign-in fell inside the measured window; fixed after the run, not rerun), 7/7 planted faults refuted in admission and 8/8 held out (a lost update through the app among them), 0 false stops on 10 clean writes, 2 model calls. Mealie 2.8.0, never set up before: refused after 3 rounds in 9.2 minutes, since its store keeps no version, author or save history that could show a lost update. Synthetic MockLoan and workbench: admitted in round 1 in 1.3 to 1.4 minutes, 16/16 held-out faults. The pre-stated 5-minute limit on the untuned app was not met | `openadapt verify draft`, `openadapt_flow/verify_draft/`, [VERIFY_DRAFT.md](packages/flow/docs/VERIFY_DRAFT.md), [results](packages/flow/benchmark/verify_draft/RESULTS.md) |
29 changes: 29 additions & 0 deletions openadapt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1896,6 +1896,35 @@ def verify_serve(contracts: str, state: Optional[str]) -> None:
sys.exit(int(agent_main(argv) or 0))


@verify.command(
"draft",
context_settings={"ignore_unknown_options": True, "allow_extra_args": True},
add_help_option=False,
)
@click.pass_context
def verify_draft(ctx: click.Context) -> None:
"""Draft a write contract with a model; admit it only if OpenAdapt
qualifies it on a sandbox.

`openadapt verify draft --describe openapi.json --trace demo.har
--task task.yaml --sandbox sandbox.yaml --out DIR`. The model (key from
ANTHROPIC_API_KEY) works at setup only; an admitted contract runs with no
model calls. `--help` lists every option.
"""
_require_supported_python()
draft_main = _optional_engine_entrypoint(
ctx, ("openadapt_flow.verify_draft.draft",)
)
if draft_main is None:
click.echo(
"Error: this openadapt-flow installation has no verify draft command.",
err=True,
)
click.echo("Upgrade with: pip install --upgrade openadapt", err=True)
sys.exit(2)
sys.exit(int(draft_main(list(ctx.args)) or 0))


def _protected_ledger_requested() -> bool:
name = "OPENADAPT_LEDGER_AUTHORITY_CONFIG"
if name not in os.environ:
Expand Down
1 change: 1 addition & 0 deletions openadapt/cli_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
("verify", "seal"): ("seal",),
("verify", "shadow"): ("shadow",),
("verify", "ledger"): ("verify", "ledger"),
("verify", "draft"): ("verify", "draft"),
("research", "bench"): ("bench",),
("research", "eval"): ("eval",),
("research", "train"): ("train",),
Expand Down
117 changes: 117 additions & 0 deletions packages/flow/benchmark/verify_draft/PROTOCOL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Protocol: model-drafted write contracts, admitted by qualification

Written on 2026-11-21 after the first two Mealie runs and before the
second untuned app (Directus) was touched. What changed and when is under
"Addendum" below; every run, void or not, is in [RESULTS.md](RESULTS.md).

## Question

Can a model draft a system's write contract at setup time, from the system's
description and one trace, so that setup takes minutes instead of about an
hour? And does admission by qualification keep every admitted contract
honest: no planted fault missed, no false stop on a clean write?

The baseline is an earlier setup of a held-out app with the deterministic
generator and hand patches: 64.5 minutes and 12 person decisions (private
study).

## Apps

| App | Store | Task | Description given | Tuned on before? |
|---|---|---|---|---|
| MockLoan (OpenAdapt's fault server) | SQLite | create a disbursement (JSON POST) | `db` | yes (zero-config benchmark) |
| Workbench, MockMed profile (OpenAdapt's task-generation app) | PostgreSQL | update a patient's phone and email (HTML form) | `db` | yes |
| Mealie v2.8.0 | PostgreSQL | update a recipe's description and yield (JSON PATCH) | OpenAPI (`/openapi.json`) | no agent had installed or probed it before this benchmark; tuned on by this benchmark after its first valid run |
| Directus 11.5.1 | PostgreSQL | update a ticket's status and priority (JSON PATCH) | OpenAPI (`/server/specs/oas`) | no: never installed or probed before its reported run |

Mealie and Directus run on the lab's WSL host (PostgreSQL 16.4, pinned images),
reached from the Mac through an SSH tunnel to loopback. All data is
synthetic.

## Procedure per app

1. **Operator setup** (`apps.py`, timed separately). Bring the app to a
seeded state, record one demonstration as a HAR file, and write
`task.yaml` and `sandbox.yaml`. These are facts: URLs, sign-ins and
connections.
2. **`openadapt verify draft`** with the pinned model (`claude-opus-5-5`,
effort `medium`, prompt `verify-draft-prompt/1`). The benchmark never
answers the one question; a question refuses the draft.
3. **Held out**, only for an admitted contract, with no model. A second
qualification run, in which the harness chooses:
- the values: 5 clean writes, and the faults written with other values;
- the rows: the faults planted on other rows (seed 1).

Two app-level faults that the admission suite never plants are added:
- the same write also sent to another record through the app;
- for a create, the write sent twice through the app.

## Measures

- **Setup minutes**: wall time of step 2, from the command's start to the
admitted contract or the refusal.
- **Person decisions**: answers to the command's question. As in the
earlier setup log, the facts in `sandbox.yaml` are listed as operator inputs,
not decisions.
- **Admitted versus rejected drafts**: one draft per model round.
- **Planted-fault catches**: refuted faults over applicable faults, in the
admission and held out.
- **False stops**: clean writes not confirmed, or whose recheck didn't
confirm.
- **Model calls**: each call and its token counts, in `result.json`
(`model_calls`). Prices stay out of the public results.

## Kill criterion

The approach is killed if any of these holds:

- on the untuned app, setup takes more than 5 minutes;
- on the untuned app, setup takes more than 1 person decision;
- any admitted contract misses a planted fault.

The admission suite catches its own faults by construction. So a miss is
scored on the held-out faults as well.

## Spend cap

A fixed cap in all, enforced by the spend ledger, which is kept outside the
repository. A call is refused when the total plus the worst case of one call
would pass it.

## Addendum, 2026-11-21, before Directus

Written after the Mealie runs and before any draft was run on Directus. The
only Directus contact before this addendum was the operator setup dry run
(start the stack, create the collection, the second user and three
tickets).

- **Why a second untuned app.** On Mealie no draft passed the lost-update
case, and the store seems to keep nothing that could show one: no version,
no author and no save history. So Mealie can't separate "the approach
fails" from "this store can't show a lost update". Directus was picked by
one constraint: its store records each save with its author
(`directus_revisions` and `directus_activity`), and two users can sign in.
The blind trial reserves OpenProject, Taiga and BookStack, so they were
avoided.
- **Changes since the first valid Mealie run.** These were made in response
to Mealie, so Mealie no longer counts as untuned:
- the attribution probe repeats the first write, to tell a new id or a
clock from a value;
- a lower-cased copy of a value counts as written only for an email
address;
- only the tables that moved are re-read;
- a round stops at a clean write that isn't confirmed;
- a case the sandbox can't build (no second user, no other record) is
untestable: never a pass, and an operator fix;
- the draft filter is an allowlist (SQL reads only, no `${...}`);
- prompt `verify-draft-prompt/2` asks for the contract as JSON text,
because YAML with unquoted colons cost a round in two Mealie runs;
- the workbench gets a second session as its second actor;
- a parameter whose demonstrated value another parameter shares is not
varied (it can't be swapped in the trace alone);
- a sign-in token can be read from a nested reply field
(`data.access_token`).
- **Frozen.** The code and prompt for the Directus run are the commit that
adds this addendum. The tuned apps are rerun on the same commit. The
first valid Directus run is the reported number. Only an operator setup
error voids a run.
184 changes: 184 additions & 0 deletions packages/flow/benchmark/verify_draft/RESULTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
# Results: model-drafted write contracts, admitted by qualification

Protocol: [PROTOCOL.md](PROTOCOL.md) and its addendum. Runs were made on
2026-11-21 with `claude-opus-5-5` at effort `medium`. Data was synthetic,
browser-free and headless. Raw data for every run, void or not, is under
[results/](results/):

- `result.json`: the numbers;
- `draft/rounds/`: every draft and every admission case;
- `draft/contract.yaml`: the admitted contracts;
- `setup/`: the operator inputs;
- `result.json`'s `model_calls`: every model call of the run, with its
token counts.

## Verdict

**The kill criterion fires on time.** No untuned app finished setup within
5 minutes:

- **Mealie, first valid run: 9.2 minutes, and no contract was admitted.**
- **Directus, reported run: 6.0 minutes**, admitted in round 2. The first
draft passed every planted fault and every clean write. Round 1 was lost
to a qualifier bug found in review after the run. The agent signed in
inside the demonstration's window, so the model was shown the sign-in's
rows as part of the write and excluded `last_access`. The probe, signed in
by then, never saw it move (below).

The other two clauses do not fire:

- **Person decisions:** 0 on every app. The command never needed its one
question.
- **Missed planted faults:** no admitted contract missed one, in admission
or held out. Across the three admitted contracts, the held-out check
caught 24 of 24 applicable faults, with 0 false stops on 15 held-out
clean writes.

**Qualification did its job.** It refused every unsound draft:

- a Mealie check that couldn't see a lost update;
- a Mealie check that stopped every clean write;
- every draft that didn't load.

Each refusal said why. No refused draft would have been safe to admit.

**Speed is now the constraint, not judgment.** One admission round takes
130 to 180 seconds on the lab apps. Each case reads a 28- or 62-table
database several times over an SSH tunnel. A model round takes 14 to 93
seconds. So two rounds already pass 5 minutes. Setup took 1.3 to 1.4
minutes on the two local apps, with one round each.

## Per-app table (reported runs)

| App | Tuned on? | Description | Setup minutes | Person decisions | Drafts admitted / rejected | Planted faults caught, admission | Planted faults caught, held out | False stops, admission clean writes | False stops, held-out clean writes | Model calls |
|---|---|---|---|---|---|---|---|---|---|---|
| MockLoan (create) | yes | `db` | 1.4 | 0 | 1 / 0 | 8/8 | 10/10 | 0/5 | 0/5 | 1 |
| Workbench, MockMed profile (update) | yes | `db` | 1.3 | 0 | 1 / 0 | 6/6 | 6/6 | 0/5 | 0/5 | 1 |
| Mealie v2.8.0 (update), first valid run | no | OpenAPI | 9.2 | 0 | 0 / 3 | best draft 6/8 | not run (nothing admitted) | best draft 0/5 | - | 3 |
| Directus 11.5.1 (update) | no | OpenAPI | 6.0 | 0 | 1 / 1 | 7/7 | 8/8 | 0/5 | 0/5 | 2 |

How to read the columns:

- "Planted faults caught" counts the applicable faults. One `wrong_value`
case is planted per written column.
- Each admitted contract also confirmed every write in its attribution
probe: 5 writes each (2 users x 2 payloads, plus the first write
repeated).
- Each admitted contract took 1 or 2 model calls; Mealie's refusal took 3.

The benchmark made 24 model calls in all: 15 in the reported and void runs,
and 9 in development on the tuned apps.

## What each case showed

**MockLoan.** The drafted check reads the records table. It matches all
four values and the surface, and declares the columns the app sets on a new
row. It refuted the faults planted on other rows with other values. It also
refuted the two app-level faults: the same disbursement sent to another
loan, and the disbursement sent twice. MockLoan has no sign-in, so its two
actors send identical requests. The lost-update case is not applicable to a
create.

**Workbench.** The drafted check reads the patient and counts the save's own
audit row. The audit row is tied to the patient by a join, and the frame
judges it through `judged_by`. The lost-update case ran, but it is not
applicable: the workbench refuses a save from a stale form (HTTP 409). The
workbench signs in one user, so its second actor is a second session of
that user, and the attribution probe has no real actor axis. There was no
app-level held-out fault, because the harness gave no second record to
write to.

**Mealie, the first untuned app.** Mealie keeps no version, author or save
history for a recipe. Its PATCH deletes and re-creates the recipe's child
rows (instructions, ingredients, nutrition, settings) on every save. So a
lost update leaves the store exactly as a correct save would. No draft
caught one. Two drafts tried to read the re-created child rows' ids as
versions. Those ids come from a shared sequence, not a per-recipe one, so
those drafts stopped every clean write. Admission refused all of them,
which is the right outcome for a store that can't show a lost update. It
also makes Mealie a poor test of the approach, which is why Directus was
added.

**Directus, the second untuned app.** The draft read four things:

- the ticket;
- the save's revision, joined to its activity row to get the author;
- `frame.versions` from the same join, with `author_field`, so the other
user's save in the window refutes the agent's;
- the whole database, with the activity log append-only and the session
table skipped.

All 17 cases passed in round 1, including the lost update. The draft was
rejected only because it also excluded `directus_users.last_access`, which
then never moved in a probe write.

That exclusion came from a qualifier bug, found in review after the run.
Actors signed in lazily, so the agent's sign-in fell inside the
demonstration replay. The model was shown the rows a sign-in writes as part
of the write: a session, the sign-in activity row and `last_access`.

Round 2 dropped the `last_access` exclusion and was admitted. It kept
`directus_sessions: skip`. A whole-table exclusion that never moved was not
checked then. It is now, so the committed contract would be refused today.
Since the run, every actor signs in before the store is first read, and a
skipped or append-only table that never moved in the probe is refused.

The lost-update catch was checked in the case evidence. In round 2 and held
out, the first reason is `frame.versions`: "another user saved a version of
the target inside the window". In the held-out run the other user's sign-in
also moved `last_access` inside the window, for the same reason. A post-fix
Directus rerun was not made. Held out, the contract
refuted all 8 applicable faults:

- the faults planted on another ticket with other values;
- the late revert, at the recheck;
- the lost update;
- the same write sent to another ticket through the app.

## Earlier runs (kept, not reported in the table)

| Run | What happened | Minutes | Model calls |
|---|---|---|---|
| Mealie run 1, void | Operator setup error: the read-only role had no `SELECT` on the sequences, so no baseline could be taken. Stopped after round 2. The command now checks the read account once before any model call. | - | 3 |
| Mealie run 3, after the fixes below | Refused after 3 rounds. The best draft caught 6 of 7 faults, missing only the lost update. | 4.0 | 3 |
| MockLoan and workbench, prompt 1 (`results/v1/`) | Admitted in round 1 with the same numbers as the reported runs. | 1.4 and 1.2 | 1 and 1 |

Mealie run 2 exposed three faults in the qualifier. They were fixed before
Directus, and the addendum lists them:

1. **Fresh row ids counted as written values.** Without a repeated write,
the attribution probe counted the new id of a re-created row as moving
with the payload. So it flagged a correct `skip` exclusion.
2. **A derived copy counted as a written column.** A lower-cased copy
(`description_normalized`) was treated as a column the task writes, so
a wrong value was planted there.
3. **Unloadable YAML.** The prompt asked for YAML, and unquoted colons in
`reason:` strings made the YAML fail to load in two rounds. Prompt 2
asks for JSON.

Mealie run 2 also counted rounds in a way the harness has since fixed: its
`result.json` says 2 drafts, and there were 3.

## Limits of this evidence

- **Held-out coverage.** The held-out check ran only on admitted contracts.
That means the two tuned apps and Directus, not Mealie.
- **The faults are planted by OpenAdapt.** Most are written to the store
with the privileged connection. Only the lost update and the two
app-level held-out faults go through the app. No grader written by
someone else judged these runs; the blind trial covers that separately.
- **The attribution probe's definition is this PR's.** The brief describes
it as "two actors by two payloads"; [VERIFY_DRAFT.md](../../docs/VERIFY_DRAFT.md)
defines it. The rule that refuses an exclusion that never moved is
stricter than the brief, and it cost Directus a round. A rule that also
accepts an exclusion of a column the app moves at sign-in would need a
sign-in in the probe. That's a possible next step, not measured here.
- **Setup minutes are command wall time.** They don't include the
operator's work: starting the app, creating users, recording the trace
and writing `sandbox.yaml`. The harness scripted that work in 1 to 5
seconds (`operator_setup_seconds`). A person doing it by hand would take
longer.
- **Host load.** The Mac's 1-minute load was 36 at the start of the
Directus run and 18 at the end (`results/directus.load`). Most of the time went to database reads
on the lab host and to model calls.
- **One task per app.** One run per app, so no spread is reported.
Empty file.
Loading
Loading