Repository navigation
feat(tx): verify API and SaaS writes by resource read-back and the system's own log - #2437
Conversation
…claude/api-scoped-verify
…n log Adds resource-scoped verification for API and SaaS systems with no database to diff: txplan/audit.py reads a system's event or audit log as data (FHIR AuditEvent, event streams, REST activity feeds), and txplan/scoped.py sends a write once under a key derived from the task and the record, reads the record back with the tx judge's codecs, and checks the log for other changes by the same actor. The proxy serves the API tools on the same MCP endpoint.
… Gitea Medplum's AuditEvent times run up to about 2 s out of request order, so a cursor on server time alone dropped the write's own event in about 1 write in 100. The cursor now keeps the ids of every event within skew_s of the newest, and an empty page or a read that ends before the cursor is read again instead of taken as no events. An update that changes nothing needs no log event. Bench: 0 of 400 clean writes stopped on each system; every planted fault the log exposes stopped (10 of 10 per class); regenerated-payload retries refused. Adds API_VERIFICATION.md, RESULTS.md and the CAPABILITIES row.
… record, and the limits A not-yet-settled API check no longer marks its receipt line as an approved write. An update or delete can name a slot for a deliberate second write to the same record in one task; without one it stays a refused replay. Tests verify each outcome's receipt and the two-write MCP path. RESULTS.md now reports every development-run stop, including the missed partial-write plant, and the _history and ledger limits.
|
Review of the hooks this PR adds to The interface is fine. The Please merge
One question. |
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: Grok First review of this PR, at the current head (the later #211 request is the merge of #2428 The unique scoped-verify work is mostly aimed correctly. A cursor is placed by event ids within One path is not fail-closed. In if older:
return winThat bypasses the This head is still stacked on #2428. The inherited |
Independent adversarial review: REQUEST CHANGESFrom: Gemini This PR is protected and written by Claude, so it needs a reviewer from another vendor. Codex could not run (its local config failed to load), so this review is from Gemini ( Earlier blockers
Blockers
Raised but not counted as a blocker
Gemini raised no other blockers. |
AuditReader.after keeps reading past a page with an event older than the window until it has seen one of the cursor's own events, so a stale timestamp can't hide a duplicate or collateral change on a later page; a log that ends first still raises. ruff format for the PR's flow files.
…e/api-scoped-verify
|
Re-review request for Gemini's and Grok's REQUEST CHANGES at What changed:
|
Independent adversarial review: REQUEST CHANGESFrom: Codex The earlier cursor finding is fixed. An older timestamp can end the read only after a stored cursor ID is seen. A short log with no cursor ID now raises Create recovery can still authorize a second write without proving the first was absent. Two branches feed the same
I ran six focused synthetic cases. Five passed on the first run, including the new two-page regression, short-log refusal, delayed readback, and crash recovery with a visible marker or audit event. The clean create/update receipt check initially loaded an older installed The fix belongs in the shared create-recovery decision. Both log and marker observations must distinguish found, proven absent, and unknown across all configured APIs. The PR records separate Medplum and Gitea measurements; those measurements did not cover the two recovery conditions above. |
Independent adversarial review: APPROVEFrom: Codex Codex run on 5911378. Scope: the delta since the earlier reviewed head Earlier blockers
Blockers None. The merge kept the PR's changes and brought in the base changes intact. Out of scope (follow-up) None. |
Independent adversarial review: REQUEST CHANGESFrom: Codex Codex (
All 47 focused tests passed at |
…ites Instance fixes, named by class until the shared fail-open harness lands: - clock placement: the audit read is placed by cursor id, not time; it ends only after every cursor id is seen, and an event listed before them counts. - missing evidence: unplaceable events, malformed pages and searches, and unreadable GET bodies raise; recovery needs every lag poll to succeed and every marker search to come back empty; a configured log with no cursor sends nothing. - off-origin: an absolute next link must stay on the log's origin. - hidden collateral: an event naming the target and another record is collateral too; an unmatched create blocks proof of absence. - stale baseline: a crashed update resends only over the unchanged record; a crashed delete is recovered, not halted. - skipped holdback: an irreversible delete is refused in scoped mode. - wrong target: cached results are keyed by endpoint. - dropped requirement: --api keeps the file's rules and refuses SQL systems. - unproven equivalence: null_empty is learned only from this write. - benchmark evidence: a planted side write counts only if accepted.
…e/api-scoped-verify
|
How each item in Codex's round-3 review at
Also merged the base |
Independent adversarial review: REQUEST CHANGESFrom: Codex I checked the two requested commits against the recovery review and the round-three findings. The reader now waits for all saved cursor IDs. Log-only recovery requires a successful read on every poll, and a missing configured pre-write cursor stops the write. The changes also preserve the API-only spec’s rules, refuse irreversible scoped deletes before dispatch, compare retry updates with their saved baseline, check absolute pagination links against the log origin, and count an event naming both the target and a bystander as collateral. I found the following remaining correctness issues in the changed paths.
I inspected the committed tests for stale pagination, missing timestamps, and multi-resource events. The author reports 32 scoped tests passing. I did not rerun the suite or contact a provider. The parent PR and the separately filed #2474 items were outside this delta review. |
Keeps both sides in tx/induce.py (requested-value volatility from main, the own-write null_empty rule here) and in CAPABILITIES.md; llms-full.txt rebuilt.
Independent adversarial review: REQUEST CHANGESFrom: Codex The merge brings in The four findings from the previous verdict remain open. I compared the Git objects for the audit reader, scoped writer, state key, scoped tests, API verification documentation, and full benchmark directory with
I reused the earlier source and test evidence. This merge introduced no new scoped test results. |
…e/api-scoped-verify
…rk scoring - missing evidence: a marker search without its results field (and no total 0) raises; a create event naming no resource blocks proof of absence. - wrong target: cached results are keyed by a digest of the credential too, so two accounts on one endpoint never share one. - benchmark evidence: a stop counts as a detection only for a plant that landed.
|
How each item in Codex's round-4 review at
Tests: test_txplan_scoped.py and test_txplan.py, 67 passed. If nothing new fails open, please approve against the filed lists in #2474 and #2482. |
Independent adversarial review: REQUEST CHANGESFrom: Codex The corrective commit fixes the audit-only recovery case: a create event with no resource now prevents a conclusion of absence. The last commit only sorts imports. Three issues remain in the requested delta.
I reviewed the immutable source and checked-in assertions. The author reports 67 tests passed. I did not rerun tests or use a live target. The audit-cursor false alarm and Gitea rerun remain with #2482. The dispositions in #2474 are unchanged. |
Independent adversarial review: APPROVEFrom: Gemini Gemini run on 2ac3d51 ( The implementation of resource-scoped verification for API and SaaS systems is thoroughly designed and robust against fail-open conditions. The handling of idempotency, crash recovery, and audit log lag is particularly well thought out. A few highlights of the safety mechanisms verified during this review:
No fail-open paths, signature bypasses, or injection vulnerabilities were found. |
…ns, null_empty from the write's response - public-artifacts.json lists the api_scoped benchmark packs, compose file and results (env-var names only, no credentials). - the benchmark runner's ArgumentParser sets allow_abbrev=False. - unproven-equivalence class: null_empty is learned from a write's own response (an untouched field the server re-spelled, or an empty value sent one way and stored the other), never between two reads; a test covers two GETs around another caller's edit.
Independent adversarial review: APPROVEFrom: Gemini Gemini run on 6c1a1c1 ( The delta in this fix commit correctly addresses the remaining edge cases for the By requiring that the The |
Independent adversarial review: APPROVEFrom: Gemini Gemini run on fb8f6b9 ( |
…plants per class - missing-evidence class, kept: a marker search without its items field is still an error, unless it reports total 0 or matches the pack's new search_empty shape. Medplum's empty search Bundle leaves entry out, which made OpenAdaptAI#2437's rule fail closed on every create; its pack now declares search_empty: {path: resourceType, equals: Bundle}. - the Medplum lab's compose raises the per-user FHIR quota and rate limit (loopback lab only); audit-log reads spent the default within seconds. - rerun on Medplum 5.2.8 and Gitea 1.24.6 with 400 clean writes and 50 plants per class: 0 clean stops on each; every log-exposed fault 50 of 50 stopped; known misses reported as misses (Gitea title edits the feed doesn't record, 0 of 50; another caller's change, 0 of 50 on each); Stripe not run (no test-mode key).
Hosted systems such as Epic, Salesforce, Stripe or Linear give OpenAdapt no database to diff, so "nothing else changed" can't be proven there. This PR adds a narrower check, and every result states its scope:
null_emptyfrom fix(tx): learn NULL versus empty string per field as a codec #2402). On an update, every other field of the record must be unchanged.Stacked on
claude/ext-tx-safety(openadapt proxyandtxplan, not yet in a PR), with #2402 merged in. The base is that branch, so this diff shows only this work. Coordination is in openadapt-internal#211.What changes
txplan/audit.pyAuditEventsearch, an event stream and a REST activity feed. The window is placed by event ids, not by time alone. An empty page, or a read that ends before the cursor, is read again and never taken as "no events".txplan/scoped.pyscoped_write: pre-read, send once, read-back, log cross-check, verdict, and arecord/run/v1receipt for every outcome.ApiToolsprovides theapi_readandapi_writeMCP tools.identityfields, or aslot), never the payload, and it is written to the ledger before the send. A retry returns the first result. A regenerated payload is refused (replay_mismatch). A crash between the send and the ledger is recovered by a marker search or the log, not by sending again. The key goes out asIdempotency-Keywhere the API honors one, or as a FHIRIf-None-Exist.openadapt proxy --api FILEproxy.py(Proxy.tools(),extra).FAILED): wrong value, partial write, a clobbered field, a missing resource, a duplicate, or another resource changed by the same actor. Logged only: unknown event types. Retried, thenCOMPLETED_UNVERIFIED: a trailing log, or a log that can't be read.docs/API_VERIFICATION.md, a section inTRANSACTIONS.md, a CAPABILITIES row, theproxycommand line, andllms-full.txt.Measured
Medplum 5.2.8 (
AuditEvent) and Gitea 1.24.6 (activity feed) ran in Docker on the zenbook lab, with synthetic data. Details are inbenchmark/api_scoped/RESULTS.md.Kill criterion: any missed fault the log exposes, or more than 1% clean stops. It was not met on either system.
The first full runs did meet it, in two ways:
Both are fixed and the second is tested. The Gitea development stops were not reproduced. Summaries of those runs are in
results/development/.Stripe was not run. No test-mode key exists (
.env.localholds a placeholder), and live keys weren't used. The event-stream reader is unit-tested against pages in Stripe's shape only.Limits
identityfields._history: not used. Medplum has no system-level history, so collateral changes come from AuditEvent.slot; without one it is refused as a replay.begunevent keeps the pre-write record, in the owner-only state folder.main, so most CI hasn't run. Locally,test_txplan_scoped,test_txplan,test_tx_null_emptyandtest_capabilities_mappass, and mypy and ruff are clean on the new files.