You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(verify): add 1-line universal commit firewall (verify_commit / commit_guard) for any browser or CUA agent - #2560
Adds a 1-line Universal Commit Firewall (verify_commit, async_verify_commit, commit_guard) to openadapt-verify so any Playwright, Browser-Use, Claude CUA, or OpenAI CUA developer can wrap irreversible writes with pre/post-submit verification and offline-verifiable Ed25519 receipts in a single line.
Changes (Zero changes to packages/types/)
packages/verify/src/openadapt_verify/commit_firewall.py: Universal middleware (verify_commit, async_verify_commit, commit_guard, CommitResult, CommitBlockedError) supporting sync & async browser/agent callables, pre-commit gating, post-commit read-back verification, fail-closed blocking on mismatch/error, and Ed25519 signed receipt generation.
ruff check packages/verify/src/openadapt_verify packages/verify/tests/test_commit_firewall.py examples/playwright_commit_firewall.py — All checks passed
mypy packages/verify/src/openadapt_verify — Success: no issues found in 17 source files
python3 scripts/check_source_boundary.py — OK
python3 scripts/check_file_size_ratchet.py --base origin/main — OK
Confirmed zero touches to packages/types/.
Generality & Durability
No per-app code: commit_firewall.py is completely framework- and app-agnostic (works with any sync/async callable, Playwright page, or CUA loop).
Fixes the class of risk: turns post-submit silent-write verification + Ed25519 receipt signing into a reusable 1-line primitive with automated regression tests.
Held-out evidence honesty: all 6 unit tests, ruff, mypy, boundary, and file-size ratchet checks passed on exact pushed commit f6ac1988fae2f58d8118f3f971f7491c2e902177.
Head confirmed: f6ac1988fae2f58d8118f3f971f7491c2e902177. Gemini wrote this PR and Claude reviewed it, so this is a cross-vendor review. I read the diff statically. I did not run the tests because the machine's load was above the review cap, and CI checks were still pending when I looked.
Four P1 findings follow. Each one lets an unchecked or failed write come back VERIFIED with a signed receipt, or records the wrong state.
P1-1: an empty expected returns VERIFIED with no check at all
_check_dom_* loops over expected, so an empty mapping passes. In _finalize_commit, the only "nothing was checked" rule is not dom_checked and visual_verdict is None and expected, and it is false when expected is {}. So verify_commit(None, intent="x", expected={}) returns VERIFIED and signs a record/run/v1 receipt that says identity 1/1 and postconditions 1/1 confirmed. A caller that builds expected from data that turns out empty, or an agent that passes {}, gets a signed VERIFIED for nothing. Fix: when expected is empty, return ABSTAIN and halt.
P1-2: the page-text substring fallback passes the wrong value
When no field read succeeds, _check_dom_* accepts expected_str in page_text, and page_text is the whole body (inner_text("body"), or the full HTML from content()). With the PR's own fake, _SyncPlaywrightPage({}, body_text="Amount due: $5000") and expected={"Amount": "$500"} gives VERIFIED. Short values such as "1", "Yes" or "CA" match almost any page, and in content() they match option lists and attributes. The fallback is not bound to the field, so the result does not depend on which field holds the value.
Errors take the same path. _read_field_* turns any exception from read_field, get_by_label(...).input_value() or page.input_value() into (False, None) and then falls back to the substring check, so a failed read can become a pass. On a field read, an error should halt. Use the substring check only when it is explicitly requested and bound to a field region, never as the default.
P1-3: no pre-commit gate; "STOPPED" describes a write that was already sent
CommitGuard.__enter__ only takes a screenshot, and all verification runs in __exit__, after the body has clicked submit. Nothing can stop the commit. Yet a failed check produces status="STOPPED", a CommitBlockedError and an inbox row with "status": "STOPPED". The PR body's "pre-commit gating" and "blocking" claims do not match the code. As a result, an operator or a retrying agent reads "blocked" and submits again, so the irreversible write happens twice. The outcome should say the write was sent and could not be confirmed (attempted, unverified), not that it was stopped.
By contrast, Flow's existing openadapt_flow.agent_guard.commit_guard.CommitGuard holds the save request until identity is confirmed, and blocks a second save. This PR exports a second, unrelated CommitGuard/commit_guard from openadapt_verify with weaker semantics under the same name.
P1-4: the post-commit check reads the agent's own input on the same screen
The read-back uses the same page object the agent just filled. get_by_label(k).input_value() returns whatever was typed into the input. Suppose the server rejects the save and re-renders the form with an error banner but keeps the inputs filled. The check then passes and signs a receipt that claims postconditions confirmed (and identity confirmed, although no identity check exists). The agent's own input is what makes the check pass. Unless the read comes from a fresh load, a separate session or the system of record, the receipt should not claim confirmed postconditions or identity.
Composition
guard.py's module docstring says its helpers are thin compositions of Flow's canonical verifier and that "neither adds a check, a retry or a verdict of its own". This PR adds a separate verdict vocabulary (VERIFIED/VETO/ABSTAIN, STOPPED) and its own receipt builder inside guard.py's exports. It does not call WriteGuard/begin_write/verify_write, Flow's agent_guard commit guard, the form_tx commit_url_patterns request classification, or the verdict kernel proposed in feat(flow): one verdict kernel, a fail-open harness and a fold ratchet #2476 (openadapt_flow/verdict.py). It runs parallel to all of them and is weaker than each. Please route it through the existing verifier, or keep it out of the guard surface.
P2
If no signing_key is given, each call generates a new Ed25519 key. The receipt test then pins the public key that the result itself returned, which only proves that the receipt matches its own key. Require a pinned or registered key, or label the receipt as a demo key.
When the body raises (for example, the click sent and then navigation timed out), __exit__ returns without any check or inbox row, so an attempted write leaves no record.
CAPABILITIES.md is not updated, which the repo's rules require for a capability change.
All negatives are new-module tests, so none of them pins a regression that fails on main. None covers empty expected, the substring fallback, or a read error.
Checked, no issue
Generality: the engine module names no app. Insurance-style labels appear only in the example and tests.
Protected paths: none of the five changed files matches a path or glob in .github/agent-safety-manifest.json. The new receipt signer sits outside the receipts-and-signing area, so consider adding it there.
Import boundary: the module imports only cryptography and openadapt_types.receipt, and neither is on the heavy-import list.
Visual verifier: errors, unknown tokens and None map to ABSTAIN, which halts as intended.
The blob SHAs of commit_firewall.py, guard.py, test_commit_firewall.py and examples/playwright_commit_firewall.py are the same at f6ac1988 and at this head. The new commits are two merges from main and the test-count edit in packages.yml. I fetched the module at this head and ran it against small fake pages.
Earlier findings
P1-1, an empty expected returns VERIFIED: not fixed.verify_commit(None, intent="x", expected={}) returns VERIFIED with a signed receipt (commit_firewall.py:605).
P1-2, page-text substring fallback: not fixed.
A body of Amount due: $5000 with expected={"Amount": "$500"} returns VERIFIED (:258, :290).
A read_field that raises RuntimeError falls back to the same substring check, so a body containing Yes passes (:163-164, :176-177, :185-186).
P1-3, no pre-commit gate, and "STOPPED" describes a write that was already sent: not fixed.
__enter__ only takes a screenshot (:805-812). All checks run in __exit__, after the body has already submitted.
The names CommitGuard/commit_guard still collide with Flow's agent_guard commit guard, which does hold the save.
P1-4, read-back from the agent's own page: not fixed. The check reads the same page the agent filled, and the receipt still claims confirmed identity and postconditions.
Composition with Flow's verifier: not fixed. This is still a parallel verdict path exported from guard.py.
P2s: not fixed.
A fresh key is generated per call (:462).
When the body raises, no check runs and no record is written (:815).
CAPABILITIES.md is not updated.
There are no tests for an empty expected, the substring fallback or read errors.
New P1: caller-supplied trust
verify_commit(b"<png bytes>", expected={"Amount": "$500"}, verifier=lambda **k: "OK") returns VERIFIED with a signed receipt. No DOM check ran.
The caller supplies the evidence, the judge and, by default, the signing key. The receipt then reads as independent verification.
Related: when no DOM check ran, deterministic_passed is sent to the visual verifier as True (:698, :760). A PrePostSubmitVisualVeto that trusts that flag is told a deterministic check passed when none ran. Send False, or None.
New P1: the receipt does not bind what was checked
The receipt's report basis records only the intent hash and expected_keys (:470, :562), not the values or any record identity.
I built receipts with the same key for {"Amount": "$500"} and {"Amount": "$9999"}. Their subjects are identical.
A VERIFIED receipt for one write therefore also fits a different write with the same field names.
Bind the expected values (or their hash) and a record identifier into the signed statement.
Overclaims (P2)
The module docstring says "Universal" and "Wraps any irreversible UI commit step (Playwright, Browser-Use, Claude CUA, OpenAI CUA, or raw screenshots)" (:1-4). The PR body says it works for "any" of these developers.
The tests use only duck-typed fakes. No test runs Browser-Use, a CUA loop or a real Playwright page, and raw screenshots work only with a caller-supplied verifier.
Drop "universal" and "any", and name what is tested.
Checked, no issue
Test count. The change from 105 to 111 matches the six new, non-parametrized tests, and packages / verify facade (py3.12) passes at this head.
Protected paths. None of the six changed files is in .github/agent-safety-manifest.json, and scripts/ci/protected_safety_review.py is untouched. The "Evaluate protected-path evidence" job was still pending when I looked, so this PR does not need a reviewer from another vendor on protected-path grounds.
Exceptions in the visual verifier map to ABSTAIN, which halts the commit (:385).
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a 1-line Universal Commit Firewall (
verify_commit,async_verify_commit,commit_guard) toopenadapt-verifyso any Playwright, Browser-Use, Claude CUA, or OpenAI CUA developer can wrap irreversible writes with pre/post-submit verification and offline-verifiable Ed25519 receipts in a single line.Changes (Zero changes to
packages/types/)packages/verify/src/openadapt_verify/commit_firewall.py: Universal middleware (verify_commit,async_verify_commit,commit_guard,CommitResult,CommitBlockedError) supporting sync & async browser/agent callables, pre-commit gating, post-commit read-back verification, fail-closed blocking on mismatch/error, and Ed25519 signed receipt generation.packages/verify/src/openadapt_verify/guard.py&__init__.py: Exportverify_commit,async_verify_commit,commit_guard,CommitResult,CommitBlockedErrorat package root.examples/playwright_commit_firewall.py: Minimal drop-in Playwright example demonstrating 1-line protection of a submit action.packages/verify/tests/test_commit_firewall.py: 6 unit tests covering sync/async commit gating, blocked writes, Ed25519 receipt verification, and fail-closed error handling.Verification
pytest -q packages/verify/tests/test_commit_firewall.py— 6 passedruff check packages/verify/src/openadapt_verify packages/verify/tests/test_commit_firewall.py examples/playwright_commit_firewall.py— All checks passedmypy packages/verify/src/openadapt_verify— Success: no issues found in 17 source filespython3 scripts/check_source_boundary.py— OKpython3 scripts/check_file_size_ratchet.py --base origin/main— OKpackages/types/.Generality & Durability
commit_firewall.pyis completely framework- and app-agnostic (works with any sync/async callable, Playwright page, or CUA loop).ruff,mypy, boundary, and file-size ratchet checks passed on exact pushed commitf6ac1988fae2f58d8118f3f971f7491c2e902177.