Skip to content

fix(verify): require only written values, and a fresh view of the saved record, to verify a save - #2877

Open
abrichr wants to merge 9 commits into
mainfrom
fix/write-intent-obligations-fresh-view
Open

abrichr wants to merge 9 commits into
mainfrom
fix/write-intent-obligations-fresh-view

Conversation

@abrichr

@abrichr abrichr commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Stacked on #2851 and #2852, which are merged into this branch.

Bug

openadapt.wrap(agent) compiled an obligation for every date, amount, ID and quoted phrase it found. It searched the instruction and every document that appeared during the run (compile_obligations_from_spec, merge_obligations_from_document). This had two effects:

  • Correct runs were held. A pasted letter or a referral carries facts the task never saves, and every one of them became required. The saved record never shows them, so a correct save was held at DONE and released unverified.
  • VERIFIED did not rest on the saved record. A save was marked VERIFIED when any attached check said so. That included a same-screen read, a wire receipt, facts proven across views, a Rung 2 verifier returning a bare True, and an obligation read-back with zero obligations plus a completeness audit. None of these is a fresh look at the record the save produced.

Change

Required values come only from what the instruction asks to write. A new openadapt.transducer_write_intents.compile_write_obligations recognizes these forms:

  • set / change / update … X to 'v', including X from 'a' to 'b', where only b is required, and A to 'x', B to 'y';
  • X should be 'v';
  • enter / type … 'v' into X;
  • select 'v' as X;
  • with X 'v', Y 'w';
  • numbered or bulleted X: v lines under a write request;
  • check and uncheck X.

It also compiles the record the values go to, from phrases such as named 'v', with code 'v', whose X is 'v' and the <noun> 'v'. That value must be the whole value of a field on the read-back, so a correct save on the wrong record does not verify.

Declarative text compiles to nothing. That covers a letter's dates and amounts, and a form's Phone: lines when no numbered list sits under a write request. One known limit: an imperative request with a quoted value inside a pasted document (please change the Delivery Address to '9 Quay St') is read as a write. Such a request can hold a run, because the record won't show it, but it can never verify one on its own. A test pins this.

Facts from documents never block or verify. merge_obligations_from_document still tracks document facts, but marks them required=False. compile_obligations_from_spec is unchanged and is now documented as a fact extractor.

Written values are matched strictly. On a read-back with one field per line, the whole line after the instruction's label decides. A free-text value with ; matches only the whole value, so Ships Monday doesn't match Remarks: Ships Monday; call first.. Otherwise a written value must equal its field's bound value under the shared strict matcher. If the page names the field differently, it must equal the whole value of a field whose label shares a word with the instruction's label. 5 never matches Dose: 50 mg.

A save verifies only on a fresh view. openadapt.transducer_fresh_view.evaluate_save_evidence decides whether a read-back may verify a GUI or remote save. All of these must hold:

  • The verifier did not refuse.
  • The read-back is neither a toast nor an editable form.
  • It declares a fresh view: either {"kind": "server_reload", "fetches": [{url, status 2xx}, ...]} or {"kind": "separate_session", "session": "<id>"}.
  • At least one required write exists.
  • Every required value is proven on the read-back.

OpenAdapt checks only the shape of the fetch evidence. The caller that reloads the record must observe the fetch, for example from the browser's network events.

Every entry point uses the same check. SimplexTransducer runs it from:

  • Rung 2 and Rung 3 at DONE and in mid-run reconcile;
  • the reopen executor;
  • verification frames;
  • the obligation read-back;
  • the step-cap finalize.

The facts gate no longer verifies a save. As a backstop, _mark_verified marks nothing, and _emit_receipt turns a VERIFIED into COMPLETED_UNVERIFIED ("VERIFIED withheld: …"), unless fresh-view evidence was admitted after the latest commit.

Other changes:

  • An obligation read-back with no required value releases unverified.
  • The step-cap open-obligation guard counts only required obligations.
  • SupervisorConfig(require_fresh_view_for_saves=False) restores the old rule. Runs with only workspace commits or no commit are unaffected.

Behaviour change. A Rung 2 or Rung 3 verifier that returns a bare True no longer verifies a GUI save. It must return its read-back (readback_text) and how that read-back was fetched (fresh_view). The same applies when the value to save appears only in a document, not in the instruction (for example "record its supporting reference"): the run now ends unverified.

Tests

  • New, tests/test_transducer_fresh_view.py (68 cases):
    • write-intent phrasings;
    • a pasted letter and an intake form that compile to nothing;
    • the old value in from … to, and an apostrophe that must not open a quote;
    • 5 against Dose: 5, 5 mg, 50 mg and 0.5, and under Previous Dose:;
    • free-text values with ; matched as the whole line;
    • a quoted request inside a pasted document, which compiles and can only block;
    • label variants;
    • every refusal of evaluate_save_evidence: a bare True, no fresh view, a refusal, an editable read-back, a toast, a mismatch, the wrong record, a 304 or empty fetch list, and a separate session with no id;
    • document facts alone, and an unsaved document fact next to a correct save.
  • One test across every entry point: Rung 2 at DONE, Rung 2 reconcile, Rung 3, verification frame, reopen executor, step cap with Rung 2, and step cap with a frame. Each is crossed with no fresh view, a fresh mismatch, a fresh wrong record and a fresh match. Only the fresh match verifies.
  • Separate tests cover:
    • the facts gate;
    • the receipt backstop;
    • evidence for commit 1 not covering commit 2;
    • a run with no save.
  • Mutation checks: turning off each gate, the coverage check, or required=False on document facts makes these tests fail.
  • Existing tests:
    • Tests of WAL, reconcile, ledger and cartridge mechanics that use bare-boolean verifiers now opt out with require_fresh_view_for_saves=False.
    • Three tests now use written instructions (Set Reference to 'REF-20') where they used Record REF-20.
    • The document-obligation test now asserts that a document fact neither holds nor verifies DONE. It previously asserted that it held.
  • Results: pytest on the transducer, obligation, fact-ledger, v3-runtime, wrap and fail-closed test files gives 731 passed and 31 xfailed. Unchanged files that fail locally fail the same way on main, because openadapt_flow is not installed here.
  • Capability row: added as capabilities/10-computer-use-agents/0105-….

Generality gate

  1. No per-app code in the engine. The write-intent grammar is English phrasing and the fresh-view contract is a data shape. Neither names or branches on an app.
  2. Fix the class, not the instance. The defect class is "a save marked VERIFIED without a fresh read-back of the values it was asked to write". Its known siblings are the obligation read-back, Rung 2 and Rung 3 at DONE and in reconcile, the reopen executor, verification frames, the facts gate, the step-cap finalize, and an empty obligation list with an audit. All of them go through one check, with a parametrized test over every entry point.
  3. Held-out evidence. Shown on held-out tasks on a server-backed app that did not motivate the change. The task set, split, frozen commit and pass line were committed before the run. Results are recorded privately.

…tions are open

finalize_on_step_cap looked up the v3 hooks as owner._v3_runtime, which never
exists (the hooks live at owner._v3), so the open-obligation guard never ran.
A passing end-state check could stamp VERIFIED at the step cap while every
obligation compiled from the instruction was still unverified.
A phrase obligation verified on a page field only when every word of the
field's label was a free-text kind word, so 'Customer Details: <phrase>'
or 'Clinical Notes: <phrase>' rejected correct saves. A compound label now
names a phrase when its head noun (last word) is a free-text word and no
word before it points at another record or an unsaved state ('Previous
Notes', 'Draft Comment'). Amounts, dates, codes and IDs keep the full rule.
Adds adversarial tests, including 5 against 'Dose: 50 mg'.
…' into fix/write-intent-obligations-fresh-view
…ard' into fix/write-intent-obligations-fresh-view
…ed record, to verify a save

Obligations came from every date, amount, ID and quoted phrase in the
instruction and in any document seen mid-episode, so facts the task never
saves blocked correct runs, and any passing read-back (same screen, wire
receipt, a bare True) could verify a save.

- compile_write_obligations: only values the instruction asks to be written
  or set, plus the record they go to, are required.
- Document facts are tracked with required=False and never block or verify.
- A GUI or remote save is VERIFIED only when a read-back from a fresh view
  (a recorded server fetch or a separate session) proves every required
  value with the strict matcher. Every verification entry point goes through
  one check; _mark_verified and _emit_receipt refuse without it.
- SupervisorConfig(require_fresh_view_for_saves=False) keeps the old rule.
…ided by the whole line

The shared matcher's label binding ends a value at ';' or a run of spaces,
so 'Ships Monday' matched 'Remarks: Ships Monday; call first.' and a correct
free-text value with ';' never matched. When the read-back has a line for the
instruction's label, that line's whole value decides.
@abrichr

abrichr commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: 4aae9fb

The direction is right: required obligations should come only from write intents, document facts should be required=False, and a GUI/remote save should not become VERIFIED on a bare True, a toast, a same-screen read, or an empty obligation list. I recounted the unique work against the #2851/#2852 stack merge (4a2031b4c): the new compiler, evaluate_save_evidence, the shared admit path, the _mark_verified / _emit_receipt backstops, and the capability row all follow that design, and the row is honest that OpenAdapt checks only the shape of fetch evidence.

This head is not mergeable: the verdict-fold ratchet fails on the unique commits.

Blocker

python packages/flow/scripts/check_verdict_folds.py is clean at the stack merge 4a2031b4c ("Verdict folds OK (2615 baseline folds left)") and fails at this head:

New hand-written verdict folds. Build the verdict on openadapt_flow.verdict.settle inside a function marked @verdict_site, and add its spec under tests/failopen/sites (docs/FAIL_CLOSED.md):
  cmp_literal: 783 (baseline 782); rose in ... openadapt/simplex_transducer.py 1 ...
  bool_fold: 217 (baseline 216); rose in ... openadapt/transducer_obligations.py 2 ...

The new cmp_literal is the backstop in _emit_receipt that compares outcome == "VERIFIED" and then rewrites the receipt by hand. The new bool_fold hits are the all(...) / any(...) reductions over matcher verdicts in _write_value_proven and _identity_proven. Please route those decisions through @verdict_site / settle (or otherwise split them so the checker is clean) and rerun the script. Until that is green, smoke will fail the same way.

This branch is also still a draft, stacked on #2851 and #2852, and its merge-base with main is 5cdeecb30. #2851 still has an open REQUEST CHANGES at 0e82d5e0 for a slice_count ratchet hit in _label_names_obligation (len(words) and words[:-1] in one return). That pattern is still in this tree. The checker did not report slice_count here, but the earlier request stands and should be fixed before or with this PR, then rechecked after a rebase onto current main.

What I checked

Against this worktree on Python 3.12 I ran tests/test_transducer_fresh_view.py, tests/test_transducer_obligations.py, tests/test_transducer_fact_ledger.py, tests/test_transducer_v3_runtime.py and tests/test_simplex_transducer.py: 256 passed. The three failures are test_simplex_transducer.py cases that import openadapt_types and fail only because that package is not installed in this slim environment, not because of this change. packages/flow/scripts/check_engine_generality.py reported "Engine generality OK (7 baseline hits left)".

I also probed the new matchers. 5 does not prove Dose: 50 mg, a Previous Dose: 5 line does not prove Dose, and a mention of Delta Co in Notes does not prove record identity. A correct Name: Delta Co / Dose: 5 read-back does. Default require_fresh_view_for_saves is True; existing mechanic tests opt out explicitly.

Limitation, not the merge blocker

fresh_view is still a shape check on the verifier's payload. A caller that invents {"kind": "separate_session", "session": "..."} plus matching readback_text can still satisfy evaluate_save_evidence. The capability row states this. It is a real remaining gap in the "VERIFIED without real evidence" class, but it is disclosed. Closing it would mean admitting fetches or session ids only from runtime-observed evidence, not from an untrusted result dict.

CI at this head: Evaluate review verdict, ci, run-ci and packages-gate are red, as expected for a draft with no Reviewed-Head comment and with the fold check failing. I am not merging. A release decision, if any, still sits with the maintainer after the ratchet is clean and the stack is ready.

…iour change)

The receipt backstop compares against ReceiptOutcome.VERIFIED.value, and
the two new matcher reductions are explicit loops (the all() ran only on a
non-empty list). check_verdict_folds.py is back at its baseline.
@abrichr

abrichr commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

The blocker is fixed in 3298ad848 (refactor(verify): fold-free save backstop and matcher loops). The behaviour is unchanged:

  • The _emit_receipt backstop now compares against ReceiptOutcome.VERIFIED.value.
  • _write_value_proven and _identity_proven now use explicit loops. The all() only ever ran on a non-empty list, so the loops change nothing.

Checks at the new head:

  • check_verdict_folds.py: "Verdict folds OK (2615 baseline folds left)".
  • check_engine_generality.py: OK.
  • The transducer, obligation, fact-ledger, v3-runtime, wrap, fail-closed and fresh-view test files: 294 passed, 31 xfailed.

Not addressed here:

The branch is still a draft stacked on #2851 and #2852.

@abrichr
abrichr marked this pull request as ready for review December 1, 2026 19:19
@abrichr

abrichr commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 61760e6

The two commits after my REQUEST CHANGES at 4aae9fb2e831 fix the blockers I raised, with no behaviour change in the unique work.

Previous blockers

python packages/flow/scripts/check_verdict_folds.py is now clean at this head: "Verdict folds OK (2615 baseline folds left)". The same baseline was clean at the #2851/#2852 stack merge 4a2031b4c and failed at 4aae9fb2. The fixes are:

  • _emit_receipt now compares outcome == ReceiptOutcome.VERIFIED.value instead of the "VERIFIED" literal (cmp_literal).
  • _write_value_proven and _identity_proven replace the all(...) / any(...) reductions with explicit loops (bool_fold).
  • _label_names_obligation splits len(words) from the words[:-1] slice before the free-text phrase check, which was the slice_count hit I left open from fix(verify): let a quoted phrase verify under a compound free-text label #2851. The earlier "too many words or not free-text" case still returns False first; the phrase-head and modifier test is unchanged.

packages/flow/scripts/check_engine_generality.py reports "Engine generality OK (7 baseline hits left)". The unique work is still application-agnostic: write-intent compilation and fresh-view admission are data shapes, with no per-app code in the engine.

What I rechecked

Against this worktree on Python 3.12 I ran tests/test_transducer_fresh_view.py, tests/test_transducer_obligations.py, tests/test_transducer_fact_ledger.py, tests/test_transducer_v3_runtime.py and tests/test_simplex_transducer.py: 259 passed. The matcher probes still hold: 5 does not prove Dose: 50 mg, a mention of the name in Notes does not prove record identity, and a correct Name: Delta Co / Dose: 5 read-back does. Default require_fresh_view_for_saves is True.

The unique design is unchanged: required obligations come only from write intents, document facts stay required=False, and a GUI/remote save still cannot become VERIFIED on a bare True, a toast, a same-screen read, or an empty obligation list. _mark_verified and _emit_receipt still backstop that.

Limitations and merge conditions

This branch conflicts with current main in openadapt/simplex_transducer.py and openadapt/transducer_v3_runtime.py (merge-base 5cdeecb30). I am not merging main into this branch and I am not pushing. The author should merge main, resolve those two files, and retrigger CI.

GitHub reports no check runs at this head (61760e606252). The last workflow runs on the branch are still from 4aae9fb2e831. Until CI is green on this SHA after the main merge, this is not merge-ready, even though the unique work is sound.

This head still admits a fresh view from the shape of a verifier-supplied fresh_view payload. That remaining gap in the "VERIFIED without real evidence" class is what #2892 closes; I reviewed that PR separately. A release decision, if any, still sits with the maintainer after the stack is conflict-free and green.

This branch has not been deployed

No deployments
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