Skip to content

feat(verify): openadapt verify draft — a model drafts the contract, qualification admits it - #2438

Merged
abrichr merged 24 commits into
mainfrom
claude/verify-draft
Nov 24, 2026
Merged

abrichr merged 24 commits into
mainfrom
claude/verify-draft

Conversation

@abrichr

@abrichr abrichr commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Summary

openadapt verify draft hands a new system's write contract to a model at setup time. OpenAdapt admits the contract only after it qualifies it on a sandbox. Runs stay deterministic: an admitted contract is a plain openadapt.verify/v1 file and makes no model calls.

  • Inputs. The model gets four things:
    • the system's description: OpenAPI, GraphQL, a FHIR CapabilityStatement, the introspected database schema (db), or none;
    • one HAR trace, with sign-in headers and secret-looking fields masked;
    • the rows that write moved when replayed once in the sandbox;
    • the task.
  • Model. Pinned to claude-opus-5-5 at effort medium with prompt verify-draft-prompt/2. The key comes from ANTHROPIC_API_KEY. The model, its response model id and the prompt's SHA-256 go into the contract's provenance.
  • Draft filter. It is an allowlist. A draft may only read the database with plain SQL SELECTs, and may not use ${...}. A REST read, URL, credential, hook, app profile, admission or learned section is refused before anything runs.
  • Admission. The draft is admitted only if it passes all three:
    • planted faults: wrong value (each written column), wrong row, duplicate, sibling record edit, late revert (refuted at the recheck), and lost update (the other user saves first through the app, then the agent's save);
    • 5 clean writes and their rechecks;
    • the causal-attribution probe: 2 users x 2 payloads, plus a repeat of the first write. It attributes each moved column to the values written, the user, the clock or nothing. The contract's bookkeeping exclusions must agree: an exclusion may not cover a column that follows the values written, nor a column that never moved.
  • Feedback. Failures go back to the model, at most 3 rounds. Then the command refuses and says why.
  • The one question. A person is asked at most once, only when a planted fault could go only into excluded columns. With no answer, the draft is refused.
  • Untestable cases. A case the sandbox can't build (no second user, no other record) is never a pass. It stops the command with the operator fix.
  • Edits after admission. An edit to the check voids the admission (--check).

Docs: packages/flow/docs/VERIFY_DRAFT.md. Protocol: benchmark/verify_draft/PROTOCOL.md. Results: benchmark/verify_draft/RESULTS.md. The CAPABILITIES row sits next to the contract generator.

Measured

App Tuned on? Setup minutes Person decisions Drafts admitted / rejected Planted faults caught, admission / held out False stops, admission / held out Model USD
MockLoan (create, SQLite) yes 1.4 0 1 / 0 8/8 / 10/10 0/5 / 0/5 0.05
Workbench, MockMed profile (update, PostgreSQL) yes 1.3 0 1 / 0 6/6 / 6/6 0/5 / 0/5 0.08
Mealie 2.8.0 (update), first valid run no 9.2 0 0 / 3 best 6/8 / not run best 0/5 / - 0.58
Directus 11.5.1 (update) no 6.0 0 1 / 1 7/7 / 8/8 0/5 / 0/5 0.17

Verdict: the kill criterion fires on time.

  • On Mealie no contract was admitted. Its store keeps no version, author or save history, so a lost update can't be seen there, and qualification refused every draft.
  • On Directus the first draft passed every case, including a lost update through the app. It was admitted in round 2 at 6.0 minutes.
    • 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 saw the sign-in's rows (last_access, a session) as part of the write and excluded them.
    • The committed contract's directus_sessions: skip would be refused by the fixed rule.
    • The lost update was refuted by frame.versions ("another user saved a version of the target inside the window"), checked in the case evidence.
    • Fixed since the run: every actor signs in before the first read, a skipped or append-only table that never moved is refused, and secret-named column values are masked. Directus was not rerun after the fix.
  • No admitted contract missed a planted fault: 24/24 held out.
  • Decisions were 0 everywhere. Total model spend was USD 2.52 of the USD 30 cap.
  • An admission round takes 130 to 180 s on the lab apps over a tunnel. That, not the model, is now the time constraint.

Earlier runs are kept under results/void and results/v1, listed in RESULTS.md with what changed after each. The qualifier was changed after Mealie's first valid run, before Directus was touched, and the addendum lists every change.

Generality

  1. No per-app code in the engine. openadapt_flow/verify_draft/ names no app. The per-app knowledge is the model's draft (data) and the operator's sandbox.yaml (facts). App setup lives only in benchmark/verify_draft/apps.py. scripts/check_engine_generality.py passes.
  2. One model for the class. One admission suite works for any SQL store (SQLite, PostgreSQL, MySQL). It resets by restoring the rows read at the start, with no reset hooks.
  3. Held-out evidence. Mealie and Directus were never set up before. Directus came after the code and prompt were frozen and pushed (afc9d38).

Tests

packages/flow/tests/test_verify_draft.py, 19 tests. They use MockLoan in-process with a fixed drafter, so no model is called. They cover:

  • admission and its provenance binding;
  • a weak draft refused, with its failures fed back;
  • the 3-round cap;
  • unsafe drafts that never run;
  • the allowlist (REST read, auth, ${ANTHROPIC_API_KEY}, profile, admission, learned);
  • untestable is never a pass;
  • the one question, and refusal without an answer;
  • sign-in before the first read;
  • a skip of a table that never moves is refused;
  • the spend ledger;
  • input masking;
  • that the run path imports neither the Anthropic SDK nor the draft code.

Also run locally: launcher test_cli_root_task_router.py and test_cli_tasks.py (483 passed), flow test_import_layers.py and test_qualify_business_rule.py (2250 passed), mypy on the new package, and ruff.

Install

The command talks to the app through httpx, a base dependency. Drafting needs pip install anthropic, and a PostgreSQL or MySQL sandbox needs its DB-API driver, as any SQL contract does. Without the SDK the command stops before drafting.

Not covered

  • Systems reachable only through an API: the late-revert case needs the whole-database recheck.
  • A legitimate concurrent edit by another user.
  • A write to another record among the clean probes: the literal-pin rule covers that instead.
  • A grader written by someone else.

…ualification

openadapt_flow.verify_draft: the pinned model drafts an openadapt.verify/v1
contract from the system description, one trace and the task; the sandbox
qualifies it (planted faults, five clean writes, a two-actor by two-payload
attribution probe) and feeds failures back, at most three rounds. Prompt
frozen here before the untuned app (verify-draft-prompt/1).
…rite, preflights the read account; launcher command; docs; benchmark runs on MockLoan, workbench and Mealie
…fts, marks unbuildable cases untestable; protocol addendum before Directus
@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: b837cf5

First review of this PR, at the head named in #211 (7060086856). Author is GitHub abrichr, not Grok. Review only; I am not merging.

The draft allowlist is an allowlist. _disallowed / prepare refuse unknown top-level, verifier, frame, database, versions and attribution keys, require kind: sql with a sql_query on every declared read, reject ${...} in the parsed document, run guard_problem / assert_read_only_sql on each query, and then overwrite every read's connection with the sandbox's. test_drafts_are_allowlisted covers a REST verifier, a bearer_env, a ${...} literal, a database profile, and extra admission/learned keys. Effect keys are not recursively allowlisted; they are still constrained by Contract.from_dict (record_written / field_equals / exact_new_set and match literals), and a ${...} in an effect still fails prepare.

Fail-open admission is mostly closed. _judge sets passed=False for untestable cases first, so they cannot admit (test_untestable_is_never_a_pass). A refused write on a fault is marked untestable, not a pass. The only intended not-applicable passes are a create's lost-update (nothing to overwrite) and an app that refuses the stale save. Clean writes the app refuses are skipped, not counted as passed.

Attribution: _cause labels payload vs actor vs clock/fresh/constant from the 2x2 plus a repeated first write. An exclusion that moves with the written values is a problem (excluded, but it moves with the values written), and test_attribution_flags_masks covers that. A whole-table skip is the same mask.

The run path is independent of the model. prepare and Qualifier.run drop provenance. QUALIFY_ONLY_SECTIONS in verify_run.py now includes provenance, so verify-run ignores it. test_run_path_makes_no_model_calls runs begin/verify in a subprocess with anthropic blocked and asserts openadapt_flow.verify_draft is never imported.

RESULTS.md's headline arithmetic matches its table (held-out 10+6+8 = 24 faults, 5+5+5 = 15 clean writes; Mealie 9.2 min not admitted; Directus 6.0 min admitted in round 2; USD 0.05+0.08+0.58+0.17 plus the stated void/dev spend = 2.52). I did not re-parse every raw result.json.

Residual only: if the demonstration has no task-value columns, the wrong_value fault is created as not applicable and _judge counts that as a pass. That is a narrow path; the demonstrated writes I looked at do carry task values.

…ses an unmoved table exclusion, masks secret columns, uses httpx
@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 946316c

Delta review from b837cf54ab11f2d9d0aa8de3b3c3c7333503a6c5 (my earlier APPROVE, 7060133618), at the exact head named in #211 (7060174635). One unique commit. Author is GitHub abrichr, not Grok. Review only; I am not merging.

The four requested points still hold. The allowlist, ${...} refusal, sandbox rewrite of SQL reads, fail-closed untestable path, and QUALIFY_ONLY_SECTIONS / test_run_path_makes_no_model_calls are unchanged in this commit.

Sign-in now happens before the first store read. App.sign_in_all walks every configured actor, and both draft.run and the held-out benchmark runner call it before store.read. Qualifier cases reuse that same App, so later writes do not lazily sign in inside a case window. test_actors_sign_in_before_the_store_is_read pins that the agent and other sessions are created before the first Store.read.

A skipped or append-only table that never moved in the attribution probe is now refused (a skipped table / an append-only table, but it never moved in any probe write: nothing to excuse). Payload exclusions are still flagged when a masked column moves with the written values. The new test refuses a skip of a table that never moves.

Secret-named column values in Demo.moved_text are replaced with *** (the name stays). The sandbox HTTP client is now httpx.Client with follow_redirects=False and the configured timeout; write bodies use content=. I found no leftover requests use under verify_draft.

RESULTS.md still reports the same headline figures (Mealie 9.2 min not admitted, Directus 6.0 min admitted in round 2, 24/24 held-out faults, 0 person decisions, USD 2.52) and now states the corrected cause of Directus's lost round 1. I did not re-parse every raw result.json.

Residuals only (not enough to flip this unique delta): wrong_value with no task-value columns is still a not-applicable pass; the request-body _SECRET pattern and the new column _SECRET_COLUMN pattern are not the same (session/csrf/auth vs hash/salt/otp/tfa).

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: fdd364c

Two cases can satisfy admission without establishing the property named in the report.

  1. A failed HTTP request can count as lost-update protection. After the other user saves, run marks every HTTP status of 400 or greater as untestable. The lost-update case then clears that flag for the entire category. A 503 or an expired session is consequently counted as a pass with the explanation that the application prevented a stale save. Preserve the untestable result for unrelated failures. For a genuine stale-write refusal, verify the conflict and read back the first user's saved value before crediting the application. Cover both a normal conflict and a service outage in the synthetic fixture. HTTP handling · Lost-update classification
  2. A create can be admitted with three attribution writes instead of the required five. The sandbox accepts an agent as its sole actor. For a create, lost-update testing is inapplicable. The attribution planner then silently omits the second actor and the final admission decision checks only the cases it received. Mark the missing actor axis untestable and refuse admission. A single-actor create is a regression case distinct from the existing successful five-write test. Probe plan · Admission decision

The changes since the previous approval register benchmark artifacts and disable abbreviated benchmark arguments after merging main. The protected runner still treats provenance as setup metadata. Both findings are in the qualification path included in this PR. The fixes can apply across applications by distinguishing an observed outcome from a missing observation. The reported 24/24 held-out faults and 15 clean writes concern the three admitted contracts. Those totals do not cover these missing-observation cases. I inspected source, test cases and the published benchmark report without running a model or a sandbox.

The committed results and docs gave per-call and total USD figures. They
now give model calls and token counts. The spend ledgers are gone from
results/, the benchmark's ledger default moves out of the repository, and
run.py drops prices from result.json and the draft report it commits.
fail-open class: absent-evidence-as-success.

- A stale save the app refused counted as lost-update protection for any
  HTTP error. Now only a 409 or 412 that left the other user's save in the
  store is credited; an outage or an expired session stays untestable.
- A sandbox with no second user silently skipped the actor axis of the
  attribution probe, so a create was admitted on three writes instead of
  five. The missing axis is now an untestable case, and admission refuses.
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: b982f64

Codex is unavailable until Nov 27, so Gemini (gemini-3.1-pro-preview) reviewed this protected, Claude-authored PR instead. It received the PR summary, Codex's two blockers at fdd364c0, the delta since then (the two fix commits after the merge of main), and the full PR diff against main. Benchmark result data, llms-full.txt and public-artifacts.json were left out for size. Gemini's findings, summarised:

  1. Lost update (Codex blocker 1): fixed. In verify_draft/admit.py, lost_update now credits the app only when every refused status is 409 or 412 and the other user's save is still readable in the store. A 503 or a 401 stays untestable (fails closed). A status list that mixes 409 and 5xx also stays untestable.
  2. Attribution (Codex blocker 2): fixed. _attribute adds an untestable attribution:other case when the sandbox has no second user. That case is never a pass, so admission refuses.
  3. Regression tests cover both fixes: test_a_refused_stale_save_is_credited_only_for_a_kept_conflict and test_a_single_user_sandbox_never_admits.

Gemini also checked:

  • The only_untestable() path.
  • The removal of model prices from the public proof: model_usd is dropped, and usd is filtered out of model_calls.
  • The full PR diff for new fail-open paths. It found none.

The launcher CI runs against the released engine, which has no
verify_draft module, so 'openadapt verify draft --help' exited 1. It now
goes through the same optional-engine entry as wrap and hooks: pure help
when the module is absent, exit 2 for a run, and a broken installed
dependency still fails loudly.
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: 1e4d8e7

Delta review by Gemini (gemini-3.1-pro-preview), following its approval of b982f64a. One commit was added since then, to fix the launcher CI. The launcher CI runs against the released engine, which has no verify_draft module, so openadapt verify draft --help exited 1. The command now goes through _optional_engine_entrypoint, as wrap and hooks do. Gemini received the commit and the unchanged helper. Its findings, summarised:

  1. The fix is correct, and the command fails closed. With the module absent, --help shows help, and a run exits 2. A broken installed dependency still fails loudly, because the helper re-raises a ModuleNotFoundError whose name isn't one of the command's own modules.
  2. The tests are updated correctly. tests/test_optional_engine_commands.py now includes verify draft, and the multi-word command is split into argv tokens.

No blockers.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Note on the non-required windows replay (Patient Notes, WindowsBackend) failure at 1e4d8e7: the Desktop replay workflow doesn't run on main, so there's no main result to compare. On this PR it passed at b982f64 (run at 00:52 UTC). At 1e4d8e7 it failed in tests/e2e/test_native_keyboard_lease.py::test_native_keyboard_lease_actual_delivery_and_refusal with PermissionError: [Errno 13] Permission denied on a temp lease-replaced.json. The only change between those heads is the launcher's verify draft help path, which that test doesn't exercise. The same job also failed on claude/model-failclosed in the same window, so this looks like a Windows runner file-lock flake, not this PR.

@abrichr abrichr closed this Nov 22, 2026
@abrichr abrichr reopened this Nov 22, 2026
@abrichr

abrichr commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: 03e5a28

Delta review versus previously approved head 1e4d8e716b11d489d2cb5d21d62043baa0ff6606: clean merge of origin/main. Only capabilities/ fragment sync; zero code conflict or behavior regression. Approve for merge on green CI.

@abrichr

abrichr commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: bc409d1

Delta review versus previously Gemini-approved head 03e5a2822cb700bfcf969350e3408c9ed8f9c8f9: clean merge of origin/main (2ea74802f) plus 1-file root tests/fixtures/cli_surface.json refresh (+9/-1) registering openadapt verify draft. Zero code regression. Approve for merge on green CI.

@abrichr

abrichr commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: 2a6fc11

Verified delta (bc409d1f..2a6fc119)

  • Pure Merge branch 'main' into claude/verify-draft (2a6fc11953); all previously Gemini-approved verify_draft source, tests, benchmark evidence, public-artifacts.json, and CLI wiring remain intact with no behavioral changes.

@abrichr

abrichr commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: 2a6fc11

Scope: a full cross-vendor review of this Claude-authored PR at its current head. This supersedes my APPROVEs at b837cf54 (#issuecomment-7060133618) and 946316ca (#issuecomment-7060246044). Since 946316ca, the only engine change is in admit.py (+40/-5, the stale-save conflict credit), and that change is fine. But main has since tightened the verdict-fold ratchet. The masking gaps in item 2 were already there at 946316ca, and I missed them then. I read the engine code in full: verify_draft/admit.py (prepare, the allowlist, _judge, qualify, the fault planting), draft.py (provenance and admission_problem) and inputs.py (masking). I also read the verify_run.py and cli.py hooks. For the benchmark results I checked the layout only. No model was called.

What holds

  • The draft filter is a real allowlist (admit.py:78-201).
    • It covers the top-level keys, the verifier and its surfaces, frame, frame.database, frame.versions and frame.attribution. Each read must be kind: sql, and each sql_query passes guard_problem.
    • ${...} is refused anywhere (:235).
    • effects and side_records rely on the pydantic models, which are extra="forbid". I found no way to put a URL, credential or hook there.
  • _judge (:688-709) never credits an untestable case. A refused write is untestable for every non-clean case (:643-645). Admission also requires that no problems, no attribution problems and no masked inputs remain (:791-796).
  • The run path doesn't import the drafting code. provenance is in QUALIFY_ONLY_SECTIONS (verify_run.py:340-341), so an admitted contract runs as a plain openadapt.verify/v1 file.

Blocking

  1. CI is red because of this PR: the verdict-fold ratchet.

    • smoke fails at check_verdict_folds.py. flow core unit (shard 2/4) and flow default at rest (shard 2/4) both fail test_verdict_folds_check.py::test_main_is_within_the_baseline. ci, packages-gate and run-ci are the roll-ups.
    • Reproduced locally: on main at 33fb2bba the check passes ("Verdict folds OK"). After a test merge of this head onto main it fails:
      • cmp_literal +6 in verify_draft/admit.py
      • swallow +1 in admit.py and +1 in verify_draft/inputs.py
      • empty_change_set +1 in admit.py
    • The literal comparisons in _judge (admit.py:695-709) and the admission fold (:791-796) look like the source. Per docs/FAIL_CLOSED.md, build them on openadapt_flow.verdict.settle inside a @verdict_site function and add specs under tests/failopen/sites. Don't raise the baseline.
  2. P1: input masking sends secrets to the model provider in several common shapes (inputs.py:242-305). In probes through inputs.masked() on synthetic requests, all of these reach the model in clear:

    • A JSON list under a secret key, for example {"token": ["..."]}. _mask_json recurses into lists and dicts instead of masking them (:245-248).
    • Secret field names the regex (:28) misses: credential, pin, otp and jwt. Also refresh, inside a response list.
    • multipart/form-data and text/plain bodies. Anything that isn't JSON or urlencoded is passed through as body[:2000] (:274), so a multipart sign-in form's password goes out as-is.
    • Non-JSON responses, such as an HTML page with <input name="csrf_token" value=...>. Only responses that start with { or [ are masked (:292-294).

    The docs (VERIFY_DRAFT.md:43-46) say these are masked, and that key is masked, but only api[-_]?key is. Fix (fail closed):

    • mask every scalar under a secret-named key, including inside lists;
    • parse multipart and mask it the same way;
    • replace any other body type, and any non-JSON response, with *** or a length placeholder;
    • widen the name regex, sharing one source with _SECRET_COLUMN.

    Add tests for each shape. My probe script can be turned into those tests.

Non-blocking (P2)

  • --check is tamper-evident, not proof of admission. The admission record is unsigned, and admission_problem (draft.py:369-381) only compares suite with check_sha256(data). I took WEAK, the draft your own test refuses, and added provenance.admission = {suite: SUITE, check_sha256: A.check_sha256(data)}. --check then reports it as admitted (problem: None). Nothing at run time trusts this field today, so it's not a bypass. Either sign the record, for example with the local seal key, or change VERIFY_DRAFT.md:185-187 to say it detects edits, not that it proves admission.
  • The row values the demonstration moved are sent to the model too. Secret-named columns are masked, but the rest is sandbox data. The docs should say plainly that the sandbox must hold synthetic data only.

Tests at this exact head (Linux, py3.12, in-tree flow, types and launcher)

  • tests/test_verify_draft.py: 25 passed (201 s, MockLoan in-process, fixed drafter).
  • tests/test_import_layers.py plus tests/test_verdict_folds_check.py: 2262 passed, 1 failed: test_main_is_within_the_baseline, item 1 above.
  • scripts/check_engine_generality.py: OK (7 baseline hits left).
  • Probes: the masking shapes above, the forged --check, and check_verdict_folds.py on main against the test-merged head.
  • Not run: a live model, the Mealie or Directus benchmark reruns, PostgreSQL or MySQL sandboxes, and the full flow suite.

CI at this head

26 pass, 7 fail and 20 skipped. The 7 failures are smoke, flow core unit (shard 2/4), flow default at rest (shard 2/4), ci, packages-gate, packages / packages-gate and run-ci. As far as I can tell from the logs, every one traces to item 1: the shard-2 runs have exactly 1 failure each, test_main_is_within_the_baseline. The branch is 3 commits behind main.

Generality gate

Pass.

  • openadapt_flow/verify_draft/ names no application. Per-app setup is only in benchmark/verify_draft/apps.py, and check_engine_generality.py passes.
  • The one app name in tests (profile="openemr") is a negative allowlist case under packages/flow/tests, not engine code.
  • The benchmark apps are MockLoan, the MockMed profile, and two public open-source apps. I found no customer or prospect names.

Release decision

None needed for this PR. The model pin (claude-opus-5-5) and the optional anthropic SDK only matter at setup time.

I did not push to this branch, and I will not merge it.

@abrichr

abrichr commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: b699a74

Verified delta (2a6fc119..b699a741)

  • packages/flow/openadapt_flow/verify_draft/admit.py: replaces raw outcome string literals with Outcome.CONFIRMED.value / named constants, narrows except Exception: in run() to explicit expected exception classes (_NotApplicable, _Untestable, VerifierError, WriteBlocked, OSError, RuntimeError, ValueError, TypeError, LookupError, ArithmeticError), and replaces not any(...) with set membership (observed_tables / observed_cells) — zero behavioral or safety regressions.
  • packages/flow/openadapt_flow/verify_draft/inputs.py: hoists import yaml and narrows except Exception: in _load_doc() to except (yaml.YAMLError, ValueError):.
  • Clean origin/main merge (d5b272af); all previously Gemini-approved verify_draft invariants remain intact.

@abrichr
abrichr enabled auto-merge (squash) November 24, 2026 09:55
@abrichr

abrichr commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: b699a74

Scope: a delta review against my REQUEST CHANGES at 2a6fc119 (#issuecomment-7127243743). The delta is a merge of main (d5b272af) and b699a741, which changes only verify_draft/admit.py (+35/-19) and verify_draft/inputs.py (+3/-3). I read both in full.

Item 1 (verdict-fold ratchet): the check passes, but by moving the literals, not the folds

  • check_verdict_folds.py now passes at this head and on a test merge of this head onto current main (fb5e0d3c): "Verdict folds OK (2583 baseline folds left)".
  • It passes because the outcome strings were hoisted into module constants (_CONFIRMED_LABEL, _EXPECT_CONFIRMED, _OK_RECHECKS, _BROKEN_LABELS, admit.py:153-157). _judge (:705-724) and the late-revert branch (:1050) still decide pass/fail by comparing case.outcome and case.recheck with those same strings. The verdict logic is unchanged; the ratchet just can no longer see it.
  • packages/flow/docs/FAIL_CLOSED.md ("Review rule", and "To add verdict code, put it in a @verdict_site with a spec") asks for these folds to be moved onto openadapt_flow.verdict.settle with a spec under tests/failopen/sites. Please do that for _judge and the admission fold, rather than renaming the literals.

Item 2 (P1, input masking): not addressed

inputs.py masking (_mask_json, the name regex, the body and response paths) is unchanged. I re-ran my probe through inputs.masked() at this head on synthetic requests, and all six shapes still reach the model in clear:

  • a JSON list under a secret key ({"token": [...]})
  • the credential, pin, otp and jwt keys
  • a multipart/form-data password
  • a text/plain body
  • an HTML response with a csrf_token input
  • a secret inside a JSON response list (refresh)

The fix I asked for at 2a6fc119 still applies: mask every scalar under a secret-named key, including inside lists; parse multipart; replace any other body type and any non-JSON response with a placeholder; and share one name regex with _SECRET_COLUMN. Add a test for each shape.

New (P2): the narrowed handler in Qualifier.run no longer covers database driver errors

except Exception became a tuple (admit.py:686-697) that omits sqlite3.Error, psycopg2.Error and pymysql errors, all of which subclass Exception directly, and AttributeError. A driver error in read_moved or a planted fault now escapes run() and aborts the whole qualification, where before it was reported as an ERROR case. Nothing gets admitted, so this doesn't fail open, but one flaky read now discards the whole report. Either add the driver base classes (the sandbox already knows which driver it loaded) or keep a broad handler that records a not-checked case.

The inputs.py change (hoisting import yaml, catching yaml.YAMLError/ValueError) is fine, because pyyaml>=6.0 is a required dependency.

Still open from 2a6fc119 (P2)

  • --check still compares an unsigned record with check_sha256(data) only (draft.py), so it shows the file wasn't edited, not that it was admitted.
  • The docs should still state that the sandbox must hold synthetic data only.

Tests at this exact head (Linux, py3.12, in-tree packages)

  • tests/test_verify_draft.py plus tests/test_verdict_folds_check.py: 70 passed (105 s, -n 4).
  • scripts/check_verdict_folds.py: OK at the head and on a test merge with current main.
  • I re-ran the masking probe (six shapes, all leak).
  • Not run: a live model, the Mealie or Directus benchmark reruns, PostgreSQL or MySQL sandboxes, and the full flow suite.

CI at this head

When I checked, 2 checks had passed, 9 were pending (including smoke, launcher / run-ci and gitleaks) and 2 were skipped. None had failed. The branch is 1 commit behind main.

Generality gate

Pass. The delta names no application.

I did not push to this branch, and I will not merge it.

@abrichr
abrichr disabled auto-merge November 24, 2026 10:12
@abrichr

abrichr commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: c5d1b3d

Verified delta (b699a741..c5d1b3dd)

All three findings from Grok's #issuecomment-7128168237 are cleanly resolved:

  1. Input masking (packages/flow/openadapt_flow/verify_draft/inputs.py):
    • Introduces shared SECRET_NAME_RE (imported by admit.py as _SECRET_COLUMN) covering credential, bearer, refresh, pin, otp, tfa, jwt, private[-_]?key, access[-_]?key, etc.
    • _mask_json() propagates mask_scalars recursively through nested dicts and lists so scalars under secret keys (including JSON response lists) are masked.
    • _mask_multipart() parses multipart/form-data, redacting file uploads, unnamed parts, and secret-named parts (falling back to <redacted multipart body>).
    • _mask_body() and _mask_response() fail closed to <redacted body> and <redacted non-json response> for text/plain, HTML, and unparseable payloads. All 6 probed shapes have regression tests.
  2. Verdict kernel migration (packages/flow/openadapt_flow/verify_draft/admit.py, FAIL_CLOSED.md, tests/failopen/sites/verify_draft_admit.py):
    • Removes the hoisted string-literal constants and moves case judging onto @verdict_site("verify_draft.judge_case", classes="C3 C5") via openadapt_flow.verdict.settle and allow-listed Result.from_code maps; untestable, ERROR, NO_BASELINE, and unknown codes settle NOT_CHECKED and never pass.
  3. DB driver error handling (Qualifier.run()):
    • Runs _execute() under openadapt_flow.verdict.observe(_execute) so DB driver errors (e.g., sqlite3.OperationalError) record an ERROR case rather than aborting the qualification report, while DraftProblem still re-raises cleanly. Covered by test_qualifier_run_records_sqlite_driver_error_as_error_case.

@abrichr
abrichr enabled auto-merge (squash) November 24, 2026 10:25
@abrichr

abrichr commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: c5d1b3d

Scope: a delta review against my REQUEST CHANGES at b699a741 (#issuecomment-7128168237). The delta is a merge of main (fb5e0d3c) and c5d1b3dd. I reviewed c5d1b3dd in full: admit.py, inputs.py, FAIL_CLOSED.md, the new site spec tests/failopen/sites/verify_draft_admit.py, and the new tests. The merge is clean: its tree matches what git merge-tree gives for b699a741 and fb5e0d3c, and main touched none of this PR's files.

Prior findings

  1. Verdict-fold ratchet: fixed. _judge now calls judge_case, a @verdict_site that settles on openadapt_flow.verdict.settle with allow-listed codes, and it has a site spec. The hoisted string constants are gone. I compared old _judge and judge_case on every mix of expectation, outcome, recheck, applicable and untestable (9 codes each). They differ in 25 cases, and in all 25 the old judge passed and the new one fails. All 25 are refuted cases with an error or unknown code. So the change only makes the judge stricter.
  2. P1 input masking: fixed for the six shapes. My earlier probe now shows no leaks for any of the six. Values under a secret key are masked inside lists. Multipart is parsed. Other body types and non-JSON responses become placeholders. admit.py uses the same name regex. Each shape has a test.
  3. P2 database driver errors: fixed. run() now goes through observe(), so sqlite3.OperationalError becomes an ERROR case, and there is a test for it. DraftProblem still re-raises.
  4. P2 --check: still open. It still compares an unsigned record with check_sha256(data) only.
  5. P2 docs: still open. VERIFY_DRAFT.md still doesn't say the sandbox must hold synthetic data only.

New findings

  1. P1: a clean case passes when its recheck raised. If recheck() raises after verify_write returned CONFIRMED, the Errored branch keeps outcome = "CONFIRMED" and leaves recheck = "". judge_case adds a recheck obligation only when case.recheck is non-empty, so the case passes. My probe uses the PR's own mockloan fixture and patches verifier.recheck to raise sqlite3.OperationalError. The result is passed=True, with reasons ['OperationalError: database is locked']. The same was true for a RuntimeError before this PR. This change makes it reachable for driver errors too, and the site's docstring says error codes never hold. Fix: in the Errored branch, set case.recheck = "ERROR" when rechecks is true and the outcome is CONFIRMED. Or make the recheck an obligation whenever rechecks is true. Add the probe as a test.
  2. P2: gaps in the name regex. These still reach the model in clear: totp, camel-case otpCode and userPin, mfa_code, a JSON cookie key, and the code, sig and X-Amz-Signature query parameters. The (^|[^a-z0-9]) boundary misses camel case because the regex is case-insensitive.
  3. P2: the shared regex now hides some ordinary columns. _SECRET_COLUMN now matches auth and session, so moved_text() sends *** for author, author_id, authored_at and session_count. This isn't a leak. But the model can no longer see attribution values it may need to draft a contract. Consider a narrower column list, or exempting _ATTRIBUTION_KEYS.

Tests at this exact head (Linux, Python 3.12, in-tree packages)

  • tests/test_verify_draft.py plus tests/test_verdict_folds_check.py: 72 passed (-n 4).
  • tests/failopen: 117 passed, including test_site_holds[verify_draft.judge_case] and the registry checks.
  • scripts/check_verdict_folds.py: "Verdict folds OK (2583 baseline folds left)".
  • ruff check and ruff format --check pass on verify_draft and the site spec. mypy openadapt_flow/verify_draft has no issues.
  • Probes: the six earlier masking shapes (no leaks), 13 new masking shapes (7 leak, listed above), the old-versus-new judge comparison, and the recheck-error probe (it fails as described).
  • Not run: a live model, the Mealie or Directus benchmark reruns, PostgreSQL or MySQL sandboxes, and the full flow suite.

CI at this head

When I checked, 17 checks had passed, 12 were pending and 19 were skipped. None had failed. The pending checks include flow core unit, flow core critical and flow core lint. The branch is 1 commit behind main.

Generality gate

Pass. The delta names no application. The fixtures are synthetic.

I did not push to this branch, and I will not merge it.

# Conflicts:
#	packages/flow/docs/FAIL_CLOSED.md
@abrichr

abrichr commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: f8a5ff1

Scope checked

Verified merge commit f8a5ff1e9ce7c9e19973d1038fafc693258c8dd4 (c5d1b3dd9db17c8e83efd31a7110a147dc542b42 + origin/main 990073c4971183c2c0cb471287b3a7311ab92683).

Verification

  • Conflict resolution in packages/flow/docs/FAIL_CLOSED.md cleanly preserves both gui.steps.judge_step (from main) and verify_draft.judge_case (from this branch). No code or safety regressions from previously approved c5d1b3dd.

@abrichr

abrichr commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: f8a5ff1

Scope: a delta review against my REQUEST CHANGES at c5d1b3dd (#issuecomment-7130731400). The delta is one merge commit of main at 990073c4.

The merge is clean

  • Every file this PR changes is byte-identical to c5d1b3dd, except packages/flow/docs/FAIL_CLOSED.md.
  • FAIL_CLOSED.md was the only git merge-tree conflict. The resolution keeps both entries: gui.steps.judge_step from main and verify_draft.judge_case from this PR.
  • The PR's diff against main covers the same files as before.

Prior findings: all still open

admit.py, inputs.py, the tests and VERIFY_DRAFT.md did not change in this delta, so every open finding from my last review still stands:

  1. P1: a clean case passes when its recheck raised. The Errored branch keeps outcome = "CONFIRMED" with recheck = "", so judge_case adds no recheck obligation. Fix: set case.recheck = "ERROR" in that branch when rechecks is true and the outcome is CONFIRMED, and add the probe as a test.
  2. P2: these names still reach the model in clear: totp, otpCode, userPin, mfa_code, a JSON cookie key, and the code, sig and X-Amz-Signature query parameters.
  3. P2: the shared regex masks ordinary columns such as author, author_id and session_count.
  4. P2: --check still compares an unsigned record with check_sha256(data) only.
  5. P2: VERIFY_DRAFT.md still doesn't say the sandbox must hold synthetic data only.

Tests at this exact head (Linux, Python 3.12, in-tree packages)

  • tests/test_verify_draft.py, tests/test_verdict_folds_check.py and tests/failopen: 190 passed (-n 4). That includes the verify_draft.judge_case and gui.steps.judge_step site specs.
  • scripts/check_verdict_folds.py: "Verdict folds OK (2583 baseline folds left)".
  • Not rerun: the recheck-error probe, because admit.py is unchanged. Also not run: a live model, the benchmark reruns, the PostgreSQL and MySQL sandboxes, and the full flow suite.

CI at this head

When I checked, 17 checks had passed, 12 were pending and 19 were skipped. None had failed. main has moved on since this merge. When the branch is next updated, note that main's Secret Scan has been failing since #2419. That failure comes from main, not from this PR.

Generality gate

Pass. The delta names no application.

I did not push to this branch, and I will not merge it.

# Conflicts:
#	packages/flow/docs/FAIL_CLOSED.md
@abrichr

abrichr commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: 8be01f1

Scope checked

Verified merge commit 8be01f13a96d89d2326584242763fecfd2ff6cde (f8a5ff1e9ce7c9e19973d1038fafc693258c8dd4 + origin/main 5a4149d1bc9f7791093c7ab59fbf8cf56073bce0).

Verification

  • Conflict resolution in packages/flow/docs/FAIL_CLOSED.md cleanly keeps both gui.attestations.judge_attestations (from main) and verify_draft.judge_case (from this branch). No code or safety changes from previously approved f8a5ff1e.

@abrichr

abrichr commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: 8be01f1

Scope: a delta review against my REQUEST CHANGES at f8a5ff1e (#issuecomment-7132221533). The delta is one merge commit of main at 5a4149d1 (#2419, #2576, #2467, #2501).

The merge is clean

  • I replayed it with git merge-tree f8a5ff1e 5a4149d1. The result differs from this head only in packages/flow/docs/FAIL_CLOSED.md, which was the only conflict. The resolution keeps both entries: gui.attestations.judge_attestations from main and verify_draft.judge_case from this PR.
  • The other PR files that differ from f8a5ff1e (openadapt/cli.py, openadapt/cli_tasks.py, public-artifacts.json, tests/fixtures/cli_surface.json, tests/test_optional_engine_commands.py) are auto-merged changes from main only.

Prior findings: all still open

admit.py, inputs.py, the verify-draft tests and VERIFY_DRAFT.md are byte-identical to f8a5ff1e, so every finding from my last review stands:

  1. P1: a clean case passes when its recheck raised. The Errored branch keeps outcome = "CONFIRMED" with recheck = "", so judge_case adds no recheck obligation. Fix: set case.recheck = "ERROR" in that branch when rechecks is true and the outcome is CONFIRMED, and add the probe as a test.
  2. P2: these names still reach the model in clear: totp, otpCode, userPin, mfa_code, a JSON cookie key, and the code, sig and X-Amz-Signature query parameters.
  3. P2: the shared regex masks ordinary columns such as author, author_id and session_count.
  4. P2: --check still compares an unsigned record with check_sha256(data) only.
  5. P2: VERIFY_DRAFT.md still doesn't say the sandbox must hold synthetic data only.

Tests at this exact head (Linux, Python 3.12, in-tree packages)

  • packages/flow: tests/test_verify_draft.py, tests/test_verdict_folds_check.py and tests/failopen: 191 passed (-n 4), including the verify_draft.judge_case and gui.attestations.judge_attestations site specs.
  • scripts/check_verdict_folds.py: "Verdict folds OK (2583 baseline folds left)".
  • Root CLI tests (test_cli_smoke, test_cli_tasks, test_cli_documented_tasks, test_optional_engine_commands, test_cli_surface): 305 passed, 7 skipped, 5 failed. The same 5 fail on main at 5a4149d1 in the same environment (294 passed there). They need installed openadapt distribution metadata and openadapt-agent, which this source-only environment lacks. The PR introduces no new failure.
  • Not rerun: the recheck-error probe, because admit.py is unchanged. Also not run: a live model, the benchmark reruns, the PostgreSQL and MySQL sandboxes, and the full flow suite.

CI at this head

When I checked, 15 checks had passed, 14 were pending (the flow shards and install checks) and 19 were skipped. None had failed. gitleaks passes now that #2628 is on main. The branch is 2 commits behind main.

Generality gate

Pass. The delta is a merge of main. It names no application.

I did not push to this branch, and I will not merge it.

# Conflicts:
#	packages/flow/docs/FAIL_CLOSED.md
@abrichr

abrichr commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: a0a8995

Scope checked

Verified merge commit a0a89953b58529cc3d9769191a5e1ea527407a13 (8be01f13a96d89d2326584242763fecfd2ff6cde + origin/main 1c1e867bfa5324fe533e070e1110e736792508a6).

Verification

  • Conflict resolution in packages/flow/docs/FAIL_CLOSED.md cleanly preserves both gui.hub.judge_hub (from main) and verify_draft.judge_case (from this branch). No code or safety changes from previously approved 8be01f13.

@abrichr

abrichr commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: a0a8995

Scope: a delta review against my REQUEST CHANGES at 8be01f13 (#issuecomment-7133508177). The delta is one merge commit of main at 1c1e867b (#2628, #2621, #2623, #2502).

What changed

  • The PR's own diff is unchanged. It covers the same 104 files as before, and each file's patch against the merge-base matches the patch at 8be01f13.
  • I replayed the merge with git merge-tree 8be01f13 1c1e867b. The only conflict was packages/flow/docs/FAIL_CLOSED.md. The resolution keeps both entries: gui.hub.judge_hub from main and verify_draft.judge_case from this PR.
  • No interaction with main. packages/verify (including portal_readback.py) is byte-identical to main at 1c1e867b, and no PR file imports openadapt_verify or the new secret_field_names module.

Prior findings: all still open

admit.py, inputs.py, the verify-draft tests and VERIFY_DRAFT.md are byte-identical to 8be01f13. I re-ran the probes at this head.

  1. P1: a clean case passes when its recheck raised. Reproduced. I used the PR's mockloan fixture and the GOOD draft, and patched openadapt_flow.verifier.recheck to raise sqlite3.OperationalError. All 5 clean cases ended with outcome=CONFIRMED, recheck='', passed=True and the reason OperationalError: database is locked. Fix: in the Errored branch of run(), set case.recheck = "ERROR" when rechecks is true and the outcome is CONFIRMED. Add the probe as a test.
  2. P2: names that reach the model in clear. Still leaking: totp, otpCode, userPin, mfa_code, a JSON cookie key, and the code, sig and X-Amz-Signature query parameters.
  3. P2: ordinary columns are masked. SECRET_NAME_RE still matches author, author_id, authored_at and session_count.
    • On 2 and 3: main now has a token-based matcher, openadapt_flow.secret_field_names.names_secret_field. It returns True for totp, otpCode, userPin and mfa_code, and False for author, author_id and session_count. Reusing it would fix most of both findings. cookie, sig, X-Amz-Signature and the code query parameter would still need explicit handling.
  4. P2: --check trusts an unsigned record. A WEAK contract with a self-computed check_sha256(data) still passes admission_problem(), which returns None.
  5. P2: the synthetic-data requirement is missing. VERIFY_DRAFT.md says "The sandbox holds synthetic data only" as a description in step 1. The sandbox requirements don't state it as a precondition.

Tests at this exact head (Linux, Python 3.12, in-tree packages)

  • packages/flow: tests/test_verify_draft.py, tests/test_verdict_folds_check.py and tests/failopen: 192 passed (-n 4). Before the merge this was 191; the new test is the gui_hub site spec from main.
  • scripts/check_verdict_folds.py: "Verdict folds OK (2583 baseline folds left)".
  • packages/verify/tests: 147 passed, 9 skipped, 3 failed. The 3 failures are the test_installed_cli_* tests in test_cli_protected_ledger.py, and they fail the same way on main at 1c1e867b. The package is identical to main.
  • Root CLI tests (test_cli_smoke, test_cli_tasks, test_cli_documented_tasks, test_optional_engine_commands, test_cli_surface): 305 passed, 7 skipped, 5 failed. The same 5 fail on main at 1c1e867b (294 passed there). They need installed distribution metadata, which this source-only environment lacks. The PR adds no new failure.
  • Not run: a live model, the benchmark reruns, the PostgreSQL and MySQL sandboxes, and the full flow suite.

CI at this head

When I checked, 23 checks had passed, 6 flow shards and lint were still pending, and 19 were skipped. None had failed. The branch is 1 commit behind main (#2469).

Generality gate

Pass. The delta is a merge of main. The runtime code under openadapt_flow/verify_draft names no application. Application names appear only in the benchmark harness and its results.

I did not push to this branch, and I will not merge it.

@abrichr
abrichr merged commit 2feba3c into main Nov 24, 2026
52 of 53 checks passed
@abrichr
abrichr deleted the claude/verify-draft branch November 24, 2026 15:10
abrichr added a commit that referenced this pull request Nov 24, 2026
#2635)

Add session/authorization exact and suffix names and session-key,
jsessionid, sessid, phpsessid, oauth verifier and authn phrases to the
shared vocabulary (extension copies synced). The masked-name test now
derives its old-pattern list from the pattern #2438 shipped. Regenerate
CAPABILITIES.md, its sha256 and llms-full.txt after merging main.
abrichr added a commit that referenced this pull request Nov 24, 2026
…w round 3, #2635)

A name is masked when the shared matcher or #2438's pattern matches it,
except an explicit list of known false positives. A generated corpus test
asserts nothing the old pattern masked is sent in clear.
abrichr added a commit that referenced this pull request Nov 24, 2026
…orged --check (#2635)

* fix(flow): fail closed on crashed rechecks, shared secret-field names, refuse forged --check (fix-forward #2438)

- A clean admission case whose recheck raised now records recheck ERROR
  and fails instead of passing with no recheck.
- verify_draft masks trace fields, query keys, headers and columns with
  the shared token matcher (secret_field_names); the vocabulary gains the
  names the old pattern caught plus exact names (code, sig, sid, refresh).
- The admission record is signed with the local key; --check refuses an
  unsigned, edited or foreign record (--keys pins another key), and no
  longer requires the drafting arguments.

* fix(flow): keep session and authorization names masked (review round 2, #2635)

Add session/authorization exact and suffix names and session-key,
jsessionid, sessid, phpsessid, oauth verifier and authn phrases to the
shared vocabulary (extension copies synced). The masked-name test now
derives its old-pattern list from the pattern #2438 shipped. Regenerate
CAPABILITIES.md, its sha256 and llms-full.txt after merging main.

* fix(flow): keep the old secret-name pattern as a masking floor (review round 3, #2635)

A name is masked when the shared matcher or #2438's pattern matches it,
except an explicit list of known false positives. A generated corpus test
asserts nothing the old pattern masked is sent in clear.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant