Skip to content

feat(auto-compile): run an agent once, replay it with no agent and no YAML - #2904

Open
abrichr wants to merge 1 commit into
mainfrom
feat/wrap-auto-compile-run1-to-run2
Open

abrichr wants to merge 1 commit into
mainfrom
feat/wrap-auto-compile-run1-to-run2

Conversation

@abrichr

@abrichr abrichr commented Dec 3, 2026

Copy link
Copy Markdown
Member

What this adds

openadapt/auto_compile.py: run a Python agent once, then repeat its work with no agent and no YAML.

from openadapt.auto_compile import auto_compile
result = auto_compile(agent, workflow_id="new-contact").run(driver, params)
  • Run 1 (cold). The agent runs through a recording driver. It can be a callable agent(driver, params) (a Playwright script or a Browser Use wrapper) or a step agent with act(observation, task, history). Field fills are never gated. The one save (driver.submit(target)) is held for an optional on_before_commit(card). If the card is refused, nothing is sent. After the save the post-save screen is read back. The run is VERIFIED only when every typed value shows as whole words and no new error text appeared. Then the trace is compiled into a JSON program under cache_dir that carries its own SHA-256. The program holds the steps with each value replaced by its parameter, the post-save check, and the parameters that name the record.
  • Run 2..N (warm). The program is replayed with new parameters. The agent is never called (agent_calls == 0).
  • Both runs claim (app, item key) in SharedWorkLease and save through BoundedSettleAndReconcile. A repeat of a record, or two workers racing on one, gives DUPLICATE_SKIPPED. These all give STOPPED: a missing field, parameters that don't match the program, a changed program file, a refused card, or a failed post-save check. If a save was sent but not confirmed, the record stays held as uncertain, so a retry stops too until someone checks it.
  • Each result carries an openadapt.wrap WrapReceipt. It is signed with this computer's openadapt trust init key, or with signing_key=. If there is no key it is digest-only, and it says so. verify_wrap_receipt(result.receipt, trusted_keys=[...]) checks it offline. A refused card or a drift stop before the save maps to blocked. A failed screen check maps to refuted with the checked_how that ran. A sent but unconfirmed save maps to uncertain.
  • The post-save check is folded with openadapt_flow.verdict (Obligations + Result.from_observation + settle). Driver and agent calls go through verdict.observe. Outcome words use the enum.auto() pattern from ReceiptOutcome. check_verdict_folds.py stays at baseline.
  • PlaywrightDriver(page) is a thin sync-Page adapter. A driver that has reopen_text(params) also gets the reopened record checked, and the receipt then says reopened.

Decisions a reviewer may question

  • check_before_submit=False: the lease carries idempotency, because a post-save screen can't show that a record is absent before it exists.
  • A refuted post-save screen reads back as UNKNOWN, never ABSENT. A refuted screen does not prove the record is missing: the save may have landed wrong. So even with settle_options={"absent_is_final": True} the settle step can't release the lease for a resubmit. The test test_refuted_screen_never_frees_the_record_for_a_retry fails if the old ABSENT mapping is put back (checked by hand).
  • A run that finds the record held by a live claim (WAIT or HELD_UNCERTAIN) waits up to lease_wait_s (default 30 s), then claims again. A commit ends in DUPLICATE_SKIPPED. A save left uncertain by a worker that died keeps the record held, so the wait runs out and the run stops.
  • A typed value that matches two parameters is not compiled. Run 1 still reports its own outcome, with compiled=False.
  • Values are matched as whole words on case- and space-folded text, so "1" does not match "12". An empty value never counts as shown, and a check with no typed value never passes on "no error text" alone.
  • Scope: this is the in-process Python path. It has no admission, canary or MCP tool. The governed path (openadapt flow wrap, the skill cache in capability rows 0130/0157) is unchanged.
  • The module needs openadapt-flow at run time for verdict. If flow is missing (Python 3.13 and later, where the launcher doesn't install it), run() raises an ImportError with the install hint.

Files

  • openadapt/auto_compile.py (new). AutoCompiler, AutoRunOutcome, AutoRunResult, PlaywrightDriver and StagedCard are exported lazily from openadapt. The function stays at openadapt.auto_compile.auto_compile, because a top-level openadapt.auto_compile would collide with the submodule name.
  • examples/zero_yaml_wrap_compile.py: runs with no browser and no model.
  • tests/test_auto_compile.py: 21 tests.
  • capabilities/10-computer-use-agents/0135-…md: new row. CAPABILITIES.md is not touched.

Test results (local, macOS)

The tests ran with PYTHONPATH=.:packages/flow:packages/types. The shared local env has openadapt-flow 2.6.0 installed from another worktree. The launcher floor is flow >= 4.1.0, and verdict.py is in every 4.x tag.

tests/test_auto_compile.py                                   21 passed in 6.03s
auto_compile + transducer_* + simplex_transducer + openadapt_wrap + wrap_receipt_trust
  + import_integrity + build_capabilities + python_support   835 passed, 1 skipped in 41.46s
race test repeated 30 times                                  0/30 failures
ruff check openadapt tests                                   All checks passed!
ruff format --check (3 new files)                            3 files already formatted
packages/flow/scripts/check_verdict_folds.py                 Verdict folds OK (2615 baseline folds left)
scripts/check_source_boundary.py                             OK: no boundary violations
packages/flow tests/failopen/test_registry_complete.py       5 passed

What the tests show:

  • Run 1 makes 6 agent calls, compiles, and is VERIFIED with a signed receipt.
  • Run 2 makes 0 agent calls with new values, and is VERIFIED with a receipt that verifies against the trusted key. An edited receipt and an untrusted key both fail.
  • The same record again gives DUPLICATE_SKIPPED, and two threads racing on one record make 1 save.
  • A missing field gives STOPPED with 0 saves, and the lease is released.
  • A value dropped on save, or error text after the save, gives STOPPED, and the retry is blocked.
  • A refused card makes 0 save clicks, compiles no program, and releases the lease.

Example output:

Run 1: VERIFIED (cold, 1 agent calls)
Run 2: VERIFIED (warm, 0 agent calls)
Run 3: DUPLICATE_SKIPPED (warm, 0 agent calls)
2 records saved

Not tested here: a real browser (Playwright is covered only by a duck-typed stub) and a real model-driven agent.

… YAML

openadapt.auto_compile: Run 1 calls the agent through a recording driver,
holds its one save for an optional on_before_commit card, checks the
post-save screen, and compiles the trace into a JSON program (parameterized
steps, the post-save check, the record's key fields). Run 2..N replay the
program with 0 agent calls. Every run claims (app, item key) in
SharedWorkLease and saves through BoundedSettleAndReconcile; results are
VERIFIED, STOPPED or DUPLICATE_SKIPPED with an openadapt.wrap receipt.
@abrichr

abrichr commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: 3af2acd

Two blockers. The lease, compile, receipt, and "don't free a refuted save for retry" work I read looks sound, and all 21 tests in tests/test_auto_compile.py passed on the GitHub launcher run (https://github.com/OpenAdaptAI/OpenAdapt/actions/runs/47100847960, job 144233887796). Those tests do not catch the holes below, because they only go through driver.submit and they paint stored values onto the success screen.

1. Ungated click (and the raw page) can save and then release the lease.

_Recorder.submit is the only gated write. _Recorder.click calls the real driver immediately, and __getattr__ forwards everything else, including PlaywrightDriver.page.

A callable agent written as a normal Playwright script — the PR's own example says "a Playwright script or a Browser Use wrapper" — that does driver.click("#save") (or driver.page.click("#save")) will:

  • persist the record with no on_before_commit, no BoundedSettleAndReconcile, and no lease commit;
  • finish without a submit, so _cold releases the claim as "run 1 ended before a save" and returns STOPPED;
  • leave the record free for a retry or another worker to save again.

A step agent that emits {"type": "click", "target": "#save"} has the same hole: only type == "submit", or click with a truthy commit field, is gated.

If a trace both clicks the save control and later calls submit, _compile keeps the click in program.steps, and _warm will click commit_target twice (once while replaying steps, once in the settler).

The intended path (driver.submit only) is fine. It is not the path a Playwright or Browser Use agent will take unless the wrapper is rewritten.

2. Default VERIFIED is stamped from same-screen text that can still show the typed values after a bad save.

_ScreenCheck on a driver without reopen_text (PlaywrightDriver has none) looks for whole-word typed values in driver.screen_text() after the save. A partial or optimistic save — the form closes and the success banner still shows the typed note, while the store dropped or rejected it — would hold those checks and stamp VERIFIED, then compile a program. The receipt would say checked_how="same_screen".

The in-repo tests hide this: FakeDriver and examples/zero_yaml_wrap_compile.py put only the stored values on the success screen ("Member saved. " + " ".join(saved.values())). test_value_missing_after_save_stops_and_blocks_retry therefore fails the screen check only because the fixture also removed the dropped field from the banner. That is not how the product's own tutorial fault works (see #2905 / #2883: the screen still shows the note).

Please do not stamp VERIFIED from same_screen alone, or require a reopen_text (or an equivalent independent read) before VERIFIED and compile. Add a test where the banner still contains the typed value and the store does not.

What I checked and it looks right

  • A refuted post-save maps to ReadBack.UNKNOWN, not ABSENT; test_refuted_screen_never_frees_the_record_for_a_retry holds even with absent_is_final.
  • A changed program SHA-256, a param-set mismatch, a refused card (0 submits, lease released), an ambiguous compile (verified but compiled=False), empty values never counting as shown, and "1" not matching "12" all behave as described.
  • Receipt mapping: VERIFIED → confirmed, submit+refuted → refuted, submit otherwise → uncertain, no submit → blocked.
  • Generality gate: no files under packages/flow/openadapt_flow changed; the new module names no application.

CI at 3af2acd94bf311777a7363e9cdf7f08b4bca6155. launcher / run-ci (ubuntu-latest, 3.12) passed, including all 21 test_auto_compile tests. packages-gate, smoke, gitleaks, dependency-review, review-verdict (no protected paths), and validate-platform-manifest passed. Package unit jobs were correctly skipped (this PR only adds root openadapt/ + tests + an example + a capabilities row). I did not run a real browser or a model-driven agent. I will not merge this PR.

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