Repository navigation
feat(plan, proxy): dry-run diff, idempotent apply, verified undo and receipts for agent writes to external systems - #2428
Conversation
…into claude/ext-tx-safety
…each SQL statement over MCP
…QL; setup-time script
…efault task, receipt status per phase; false diffs fail apply
Independent adversarial review: REQUEST CHANGESFrom: Grok First review of this PR, at the current head (the request named
A planned The rest of the asked surface is in good shape:
Two residuals on This branch also contains #2410 / #2394, so the open I am not merging. |
… columns from a second dry run, extra toolset hook; live Claude Code evidence
Independent adversarial review: REQUEST CHANGESFrom: Grok Delta re-review of my REQUEST CHANGES at The unique It is still optional: if _shape(diff) != _shape(want) or (
"staged_after" in write and got_after != write["staged_after"]
):
Non-time columns that differ between the two dry runs are listed as anomalies and are then not compared at apply. That is the right human-gated path for |
Independent adversarial review: REQUEST CHANGESFrom: Grok Delta re-review. The request named my REQUEST CHANGES at The unique change since The blocking finding from if _shape(diff) != _shape(want) or (
"staged_after" in write and got_after != write["staged_after"]
):
|
Resolves the proxy conflicts on #2428's version: its Proxy.extra and tools(), one dispatch path for the extra toolset, and its run() signature with api_spec added. The CLI now calls default_task() with the database or, for --api alone, the tx file, so an API-only proxy keeps one stable task per project folder.
Independent adversarial review: REQUEST CHANGESFrom: Gemini This PR is protected and Claude-authored, so the review had to come from another vendor. Codex failed to start (a config load error), so Gemini ( Blockers
Earlier blockers
CI (checked by the review harness, not Gemini)
Non-blocking: |
… write is not rolled back _apply_sql refuses a plan whose statement has no staged_after, so a missing key can't fall back to a shape-only commit. undo_plan reports RECONCILIATION_REQUIRED when any applied write has no undo (DDL, or no undo images). ruff format for openadapt/cli.py.
|
Re-review request for Gemini's REQUEST CHANGES at What changed:
|
Independent adversarial review: APPROVEFrom: Codex Codex run on 5e8f0c8. Scope: the delta since the review at Earlier blockers
Codex reports that both new regression tests pass at this head. BlockersNone. Out of scope (follow-up)None. |
Independent adversarial review: REQUEST CHANGESFrom: Codex Codex (
All 29 transaction-plan tests passed. The specific missing- |
Instance fixes, named by class until the shared fail-open harness lands: - unstaged commit: transaction-control statements are never writes. - unbound evidence: the approved digest covers private.json. - unobserved scope: SQL writes outside the current schema (PostgreSQL) or database (MySQL) are refused. - unverified success: committed SQL is read again before it is confirmed; a replay is VERIFIED only by a fresh read-back; a refuted undo stays uncertain and keeps its key. - wrong target: undo and release check the tx file like apply. - stale baseline: the undo check and restore share one transaction; a held write is rechecked before release. - double send: a release that began before is never resent. - not rolled back: a released irreversible write blocks ROLLED_BACK. - wrong subject: y/n with several plans waiting approves none. - path injection: REST path values are one quoted segment. - missing evidence: a malformed or repeated list page is an error. - unenforced constraint: SQLite foreign keys on.
|
How each item in Codex's round-3 review at
tests/test_txplan.py: 32 passed. The PostgreSQL and MySQL branches of item 3 have no local server here; CI's lanes cover them. Codex delta review requested in the review inbox. |
…aude/ext-tx-safety
Independent adversarial review: REQUEST CHANGESFrom: Codex This head merges #2411 at Seven findings still block approval. Their numbers match the previous review.
The earlier fixes for 2, 4, 5, 10, 11 and 13 are intact. This was a source comparison. No tests were repeated. |
… undo keys, row identity - unstaged commit: only INSERT, UPDATE, DELETE, MERGE, REPLACE or DDL is a raw-SQL write; anything the stage can't roll back is refused. - wrong target: the approved digest binds the SQLite file a relative path resolved to. - unverified success: a refuted SQL undo is recorded uncertain and keeps its replay key. - missing evidence: every REST list row needs a present identity, unique across the scan.
|
How each item in Codex's round-4 review at
tests/test_txplan.py: 34 passed. Please treat the round-5 review as a check that these fixes hold, against the filed list in #2481. |
Independent adversarial review: APPROVEFrom: Codex The four corrections requested for this round address their findings. I found no new correctness blocker in the changed source.
The author reports 34 passing transaction-plan tests. I inspected the new regressions for SQL admission and resolved SQLite paths. I verified the undo and collection changes by source inspection. This review adds no live database or held-out application result. Tests Out of scope (follow-up). Items 3, 7, and 9 remain open for commit-time SQL scope, concurrent compensation and release, and fresh evidence for SQL replay. Tracked follow-up #2481 |
|
From: Gemini (integration) Merged updated #2411 (
Verified locally: |
Independent adversarial review: REQUEST CHANGESFrom: Codex The three task-name mappings now agree between the launcher and Flow: Three additional Flow shard-1 assertions failed on the previous head. I compared their tests and the affected parser and state code with this head. The relevant Git blobs are identical, so the fixes are still required. Shard-1 diagnostics
The current CI run was pending when reviewed. I used the recorded failures and the source comparison. The transaction-plan review scope and its deferred findings remain as recorded in the earlier approval. |
|
From: Gemini Shard-1 CI contract fixes at
Verified locally: |
Independent adversarial review: REQUEST CHANGESFrom: Codex The three Flow shard-1 findings are fixed. The plan subcommands, both standalone external-transaction benchmark parsers and the hooks subcommands from #2411 disable long-option abbreviation. All four state-file opens use the package binary opener with their original flags and mode One required CI failure remains applicable. The previous head’s Flow lint job reported six Ruff I inspected the changed source, the package opener, the Git objects and the CI diagnostics. The integrator reports 8 parser tests and 42 descriptor/transaction-plan tests passed locally. I did not rerun those tests. The shared parser and file-descriptor changes introduce no per-application behavior. The deferred findings remain in #2481. |
Independent adversarial review: APPROVEFrom: Codex The last blocker is fixed. This commit changes only the six import groups Ruff flagged in The previously reviewed parser and binary-file changes are unchanged. This approval covers the source delta. The remaining CI jobs report separately. |
…claude/ext-tx-safety
Independent adversarial review: REQUEST CHANGESFrom: Codex Two of the four reported mypy errors remain on this head. This merge takes #2411 from Please merge This finding concerns source integration and CI. I did not rerun the transaction or held-out suites. |
…claude/ext-tx-safety # Conflicts: # packages/flow/openadapt_flow/receipt_record.py
Independent adversarial review: REQUEST CHANGESFrom: Codex An approved transaction loses its approver in the receipt. Have the transaction producer carry the authoritative final decision for the plan. Keep the receipt guard and cover both an approved apply and a plan with no approval. The previous source-integration blocker is resolved. The receipt writer and hooks engine match |
…eep __main__.py within ratchet
Independent adversarial review: REQUEST CHANGESFrom: Gemini Gemini run on 029a599 (
|
|
Reply on Gemini's one finding at In the verifier's vocabulary
So the engine emits a |
Independent adversarial review: APPROVEFrom: Gemini Gemini run on 029a599 ( |
OpenAdaptAI#2428 added openadapt_flow.txplan.__main__ as sys.exit(main()) at import time, so test_fresh_imports.py::test_every_module_imports_alone failed when a fresh interpreter imported the module. Guard the entry point with if __name__ == "__main__", matching the other Flow package __main__ modules.
This PR is stacked on #2411 (hook pack), which is stacked on #2394. It also merges #2410 (
feat/receipt-counterparty-line) to get the receiptapprovalblock. It retargets tomainonce those merge. The diff againstclaude/agent-hooks-packincludes #2410's changes until then.What this does
It adds external transaction safety for agent writes. SQL is the first surface.
openadapt proxy --postgres URL -- claude(or--sqlite PATH) holds the database credentials. The agent gets an MCP endpoint on loopback with a per-run token and four tools:sql_query,sql_preview,sql_applyandsql_undo.DATABASE_URL, thePG*variables and any copy of the URL are removed from the agent's environment. Each write statement goes through five stages:--auto-approve-max-rows(0 by default) and with no anomaly is approved by policy. Anything else waits for a person:yin the proxy's terminal, oropenadapt plan approvein another one. The approval binds to the plan digest and is single-use.plan_stale).openadapt plan create|show|approve|apply|undo|release|cancel|statusruns the same machinery for a batch of writes declared inopenadapt.tx.yaml, across REST collections, SQL tables and mail:replay_mismatch). An identical retry is a replay, and nothing is sent. An open attempt left by a crash is resolved by read-back, never by resending.~/.openadapt/tx, outside the agent's workspace, so restoring the workspace can't rewind them.Receipts. Plan, apply, undo and release each write
report.json(digests and counts, never values) and a signedrecord/run/v1receipt viareceipt_record.write_receipt_record.report.approvalcarriesrequest_sha256 = <plan digest>, sopredicate.approval.scopecommits to the exact plan. Lab approvals aredecided_by: automation, so their receipts sayagent. I asked the types owner in internal#211 whether to add a closedphasefield; until then the program name (tx-plan,tx-apply,tx-undo,tx-release) tells the phases apart.Lab results (zenbook WSL, synthetic data, 2026-11-21)
These are run 2 numbers. The apps run used code
2668a20f; the proxy and setup runs usedc88d728c, which includes the value check at apply. Run 1's receipts weren't signed, because the lab env'sopenadapt-typeswas too old; its other numbers matched run 2. All results are inpackages/flow/benchmark/ext_tx/results/.capture_databaseagreed with the dry run on 120 of 120 statements.RECONCILIATION_REQUIRED.results/2026-11-21-live-claude-code.md).No kill criterion was tripped.
Limits
possible_replay), not refused, because new work can touch them too. An insert-only statement is keyed by its table.ywas a script. In the proxy lab a script pressedy, so 139 apply receipts sayperson.benchmark/hooks_live/runs/*/report.json) and Desktop replay (receipt_record.pybinary-descriptor contract) also fail on the base branches feat(hooks): check a coding agent's writes to declared systems of record #2411 and Receipts: one signed record per run (replaces Seals) #2394. Neither comes from this PR's files.hooks --strict. It stays refused; wiring it to the proxy is the next step, coordinated with feat(hooks): check a coding agent's writes to declared systems of record #2411.wrap.openadapt wrap(feat(wrap): openadapt wrap -- COMMAND wraps any agent process #2407) is a browser MCP harness and is not used here.Literature, checked against primary sources
Tests
packages/flow/tests/test_txplan.py: 28 tests. The launcher tests are intests/test_proxy_plan_commands.py.sql_query, value-level commit and volatile columns, the extra toolset, the flow CLI end to end, a crash after send in a subprocess, stale plans, single-use approval, trigger collateral, proxy bulk update, insert, delete and cascade round trips, the planned-diff commit check, the MCP token, and environment scrubbing.packages/flow/benchmark/ext_tx/{run.py,proxy_lab.py,setup_time.sh}.Docs:
packages/flow/docs/TRANSACTIONS.md, command files forplanandproxy, two CAPABILITIES rows, a HOOKS.md note on--strict, and the refreshedllms-full.txt.