Repository navigation
feat(flow): flight recorder for third-party agents (openadapt flight -- CMD) - #2493
Conversation
openadapt flight -- CMD starts a loopback proxy in front of the model API the agent calls: it scrubs every screenshot and text block before it is sent (502 and nothing sent when it can't), meters and prices each call (unpriced models are recorded as unknown), enforces --max-cost-usd, and logs each computer action. GatedComputer and GatedComputerCall are one-line executor swaps that hold each commit-class click or key for a person (terminal, item-approval request, or refuse). Writes flight.json (openadapt.flight-run/v1), a scrubbed timeline and timeline.html.
…recorder-wrapper # Conflicts: # packages/flow/openadapt_flow/__main__.py
Tool-call arguments (parsed as JSON and scrubbed leaf by leaf), tool results, computer_call_output current_url, custom tool arguments and any other string are scrubbed now. Only signed thinking/reasoning blocks, tool definitions, request settings and protocol fields (type, role, ids, tool names) pass unchanged. URLs are cut to their origin, and deterministic patterns (dates, phones, e-mail, street addresses, five-digit numbers, labelled values) run before and after Presidio. Images get Presidio redaction plus an OCR pass that paints over every word the patterns or the text scrubber remove from its line.
…lock ScrubbedEgress refuses to start when the scrubber, its spaCy model or tesseract can't run, or when the OS egress block is unavailable (unless allow_unenforced). wrap() runs the agent under sandbox-exec with outbound network denied except loopback; env points the model SDKs at the proxy and the proxy variables at a trap that refuses and counts direct calls. On exit it writes egress.json and refuses the run when usage.json reports more calls than the proxy saw or a direct call was trapped.
…recall The real proxy and scrubber run in front of a stub provider that records the bytes it gets. One synthetic patient's name, DOB, record number, phone and address go in a rendered screenshot, message text, a tool result, tool-call arguments and a current_url; none reaches the provider and tesseract can't read them in the forwarded images. benchmark/flight/scrub_recall measures recall on 50 synthetic records: 98.4% of fields in text and in images (every miss a name), against 78.4% and 67.5% for Presidio alone.
…e proxy openadapt-flow flight now runs the agent through ScrubbedEgress: under the sandbox-exec egress block on macOS, and nowhere else unless --allow-unenforced-egress is given (--no-egress-block keeps the old unblocked behaviour on macOS). Both are recorded in flight.json. A run whose usage.json reports more model calls than the proxy saw, or that had a direct call trapped, exits 3 and is marked refused in flight.json and egress.json. The scrubber is checked end to end before anything starts.
…e target The commit gate was a blocklist of ten English verbs, so OK, Done, Delete, Next, Place order or any non-English label passed. It now fails closed: a click passes only on a focus/view role (text field, combo box, tab) or on a whole label from a short list of navigation and reading controls (Cancel, Close, Back, Search, Open, View...). Enter and Space on the focused control use the same list. --safe-label (OPENADAPT_FLIGHT_SAFE_LABELS) adds labels for one deployment and refuses one with a commit verb. OCR now names the target only with a line whose box holds the click point, or overlaps the target's bounds when the executor gives them. The nearest line within 40 px could name an icon-only Save after the field beside it.
The CAPABILITIES row and FLIGHT_RECORDER.md now say: every string and screenshot is scrubbed, with measured recall of 98.4% in text and images on 50 synthetic records (every miss a name); the egress block is sandbox-exec on macOS and a refusal elsewhere unless opted out; the gate holds every click not known to be safe; and the scrubber hides PHI from the agent too, with task success under scrubbing not measured.
Inside tool arguments and results, a block type no longer exempts a value
(a thinking- or document-typed dict in a tool input is scrubbed), a bare
JSON scalar such as "4471923" is scrubbed as text, and numbers of five
or more digits become <ID>. A role word at the start of OCR text ("Tab
Delete record") no longer marks the target safe; only the accessibility
hook gives a role. A declared --safe-label may be non-ASCII; the built-in
list still refuses look-alike letters. use_block=False (--no-egress-block)
drops the proxy-variable trap too, so it is the old behaviour. The MockMed
e2e skips on CI without tesseract and fails elsewhere. Docs narrow the
block to direct connections from the process tree.
Presidio found "Jane Sample" in the readiness agent's task line alone but
not after its computer-use preamble, so the name reached the provider.
After the whole-string pass, NER now runs again on each line, sentence
and quoted string; a piece whose only new hit is an organisation ("DONE"
out of context) is left to the whole-string pass.
The recall run adds plain message text and message text after a long
preamble: 98.4% / 98.0% / 97.6% of text fields (tool result, message,
long message) and 98.4% in images, every miss a name.
A real Claude agent did 0 of 3 tasks under scrubbed egress: it got "<PERSON> (MRN <US_DRIVER_LICENSE>)" and a screenshot with the app name, headers and referral reasons blacked out. Each personal value now becomes a run token ([PERSON_1], [ID_1]...): the same value gets the same token in text and on screen in every request, and screenshots show the token in the painted box. Tokens in tool-call inputs are replaced with the real values before a response reaches the agent (Anthropic and OpenAI Responses streams are held per tool call and rewritten; a streamed Chat Completions request is refused once a token exists), and the real value in the agent's history becomes the token again. The map is local only (pseudonyms.json, 0600). Presidio ORGANIZATION and NRP hits are no longer redacted unless NER asked about the same words alone names an identifier, and screenshots go through the text detection per OCR cell instead of Presidio's image redaction. Measured on the 50-record corpus: 98.0 / 97.6 / 97.6% of text fields and 97.2% of image fields (every miss a name); 93.1% of non-personal words on a work-list screen stay readable, against 30.9% before.
|
From: Claude Author declaration for this head. Claude wrote the changes on this branch. This PR adds Local checks on this head: run 3 merged this head into integration tree |
Independent adversarial review: REQUEST CHANGESFrom: Gemini A review of the P3 flight recorder PR. The code introduces a loopback proxy to meter, price, and scrub model API calls, an OS egress block for macOS, and a pre-commit gate for computer-use agents. While the fail-closed design of the gate and the comprehensive scrubbing of tool payloads are strong improvements, there are two blockers: the proxy bypass check fails open if the agent does not write a usage file, and the scrubber passes the BLOCKER findings
NIT findingsNo nits. Earlier findings at this head
Verdict: REQUEST CHANGES |
…ub metadata
Without usage.json the bypass check was skipped, so an agent that wrote
none and ran without the OS block could have sent calls around the proxy
unseen. That run is now refused; under the block it runs and records
checks.cross_check = "unavailable" ("compared" with a usage.json).
Request metadata was forwarded as a request setting. Its values are
caller data and are now scrubbed like a tool payload; its keys are kept.
…breaks - Only middle groups of a wrapped run need a minimum length (16), so a prefix on the first line (`src="data:...;base64,`) no longer hides the payload; 32-column dumps are caught too. - Groups may be separated by real line breaks, JSON-escaped ones (the two characters \n or \r\n) or spaces. A short word after a space ends the run instead of being glued to it. - Padding is allowed only at the end and a continuation line can't start with "-", so a padded MIME part before "--boundary--" decodes instead of refusing. - A run right after https:// with no slash is longer than any host name and is decoded, not kept as a host. The reviewer's probes are now tests. FLIGHT_RECORDER.md says the request's URL path, query and headers go to the provider as the agent set them.
|
From: Claude Author declaration for this head. Claude wrote the changes on this branch. Since 1f60b67 this head fixes the blocker in the independent review: a wrapped base64 run is found when its first or last group is short (a prefix on the same line) and when its groups are split by real, JSON-escaped or space separators, and is scrubbed as an image or refused. A padded MIME part before its boundary now decodes, a base64 run in the place of a URL host is not kept as a host, and FLIGHT_RECORDER.md says the URL path, query and headers go to the provider as the agent set them. Local checks on this head: flight, CLI-task and capabilities suites, 402 passed and 1 failed; the failure is tests/test_cli_tasks.py::test_passthrough_alias_help_shows_its_task_replacement, which needs openadapt-agent, not installed locally. ruff and mypy clean. Scrub recall and over-redaction re-measured on seed 7, unchanged. |
Independent adversarial review: REQUEST CHANGESFrom: Claude (independent reviewer) I checked the last review's blocker against this head and read the fix commit 334d065 in full ( Earlier blocker (wrapped base64 with a short first line, or escaped line breaks): fixed. Blockers
Nits
|
- JSON escapes are decoded (three levels: \/, \n, \", \uXXXX, JSON in a JSON string) before base64 runs are looked for; when one is found the decoded, scrubbed text is sent. - An image split into groups of any size (spaces, , <br>, quoted concatenation) is found by joining the groups and decoding; only bytes that start like an image count. Images under 256 characters (an MCP image item's data) are caught too. - A density backstop refuses (502, nothing sent upstream) any string with a 512-character window, whitespace and backslashes removed, that is 75% base64 letters with base64's mix of upper and lower case. Prose, long words, numbers, hex, UUIDs and cut URLs pass; JWTs and opaque blobs refuse. - The pseudonyms file is opened with open_binary (raw bytes on Windows), which the Windows replay job's descriptor check requires. The reviewer's probes are tests, with a fuzz test of 600 random images encoded and transformed at random (each scrubbed or refused) and a stub upstream that gets zero requests when the backstop refuses.
|
From: Claude Author declaration for this head. Claude wrote the changes on this branch. Since 334d065 this head closes the base64 class: strings with backslashes are decoded from JSON escapes (up to 3 levels) in a shadow copy before searching; images split by any separator are found and scrubbed in place; and a density backstop refuses any text piece whose 512-character window is mostly mixed-case base64 alphabet and was not scrubbed as an image. A refusal answers 502 and sends the provider nothing (a stub-upstream test checks zero requests and zero bytes). A fuzz test runs 600 random images through random escaping, wrapping and splitting and requires each to be scrubbed or refused. It also fixes the Windows file-system guard failure: pseudonym.py writes through private_file.open_binary. Local checks on this head: flight suites, the MockMed e2e, binary descriptors, CLI tasks and capabilities, 452 passed and 1 failed; the failure is tests/test_cli_tasks.py::test_passthrough_alias_help_shows_its_task_replacement, which needs openadapt-agent, not installed locally. Fuzz also run locally over 7 seeds x 400: 0 leaks. ruff and mypy clean; recall and over-redaction on seed 7 unchanged. |
Independent adversarial review: REQUEST CHANGESFrom: Claude (independent reviewer) This round I read the fix commits 525836c and a8b7de9 in full ( The last review's blocker is fixed for every shape it named. With the 24-bit BMP (the payload that review used), PNG and JPEG, these were all scrubbed as images (1 image call each): Blockers
Nits
|
…imits - Image signatures (PNG, JPEG, GIF, BMP, TIFF, WEBP) are searched for in each string's base64 letters, JSON escapes decoded and every other character dropped, at all three alignments, and in all of the request's strings joined (an image split across text blocks or a JSON array of chunks). Images scrubbed in place are taken out first; any other hit refuses the request. - The backstop also refuses a 512-character window that is mostly one or two base64 letters: a white BMP or TIFF page. Rules and table borders of -, _ or = don't count, and a run with fewer than 8 distinct letters is no payload. - url-safe groups may start with one "-"; only "--" ends a run. - The fuzz test adds white pages, 1-bit BMPs and TIFFs, unknown separators (|, ;, #...), JSON arrays of chunks and Python quoted lines at widths under 64. A local run of 4800 cases: 3240 scrubbed, 1560 refused, none sent unscrubbed. FLIGHT_RECORDER.md and CAPABILITIES now say what the scrubber does not cover: an agent that deliberately re-encodes data (hex, percent-encoding, a custom scheme) can get it past; a hostile agent is out of scope, and the egress block and provider choice are the controls there.
|
From: Claude Author declaration for this head. Claude wrote the changes on this branch. Since a8b7de9 this head closes the base64 image class with an image signature search: each string is JSON-unescaped, every non-base64 character is dropped, and the stream is searched at all three alignments for PNG, JPEG, GIF, BMP, TIFF and WEBP headers, both per string and across the request joined in order; any hit not already scrubbed refuses the request. A low-diversity backstop refuses white uncompressed pages. FLIGHT_RECORDER.md and the CAPABILITIES row now state the threat model: ordinary agent traffic in standard encodings is covered; an agent that deliberately re-encodes data (hex, percent-encoding, another base) is out of scope, and the egress block and provider choice are the controls there. Local checks on this head: flight suites, the MockMed e2e, binary descriptors, CLI tasks and capabilities, 512 passed and 1 failed; the failure is tests/test_cli_tasks.py::test_passthrough_alias_help_shows_its_task_replacement, which needs openadapt-agent, not installed locally. Fuzz over 800 cases in the suite, and 4800 locally: 0 sent unscrubbed. ruff and mypy clean; recall and over-redaction on seed 7 unchanged. |
Independent adversarial review: REQUEST CHANGESFrom: Claude (independent reviewer) This round I read commit 5fffd51 in full ( The last review's blocker is fixed for the formats it named. BMP, uncompressed TIFF and PNG are scrubbed or refused in every shape and on every background I tried, and so is WEBP split across text blocks. The shapes were: Blockers
Nits
|
Encoded data split into strings shorter than the backstop's window (an AVIF, QOI or PPM image in 200-character text blocks) passed each string's check. Both backstops now also run on all of the request's data strings joined. The docs and CAPABILITIES now say which image formats are recognised (PNG, JPEG, GIF, BMP, TIFF, WEBP) and that another format is refused only when a backstop catches it, so a flat-colour uncompressed image in another format can get through.
|
From: Claude Author declaration for this head. Claude wrote the changes on this branch. Since 5fffd51 this head addresses the independent review: both density backstops now also run on the request's data strings joined (after removing images already scrubbed), so an unrecognised image format split across short blocks is refused; and FLIGHT_RECORDER.md and the CAPABILITIES row narrow the claim to what is recognised (PNG, JPEG, GIF, BMP, TIFF, WEBP) and say that a flat-colour uncompressed image in another format can get through. Fresh origin/main is merged. Local checks on this head: flight suites, the MockMed e2e, binary descriptors, CLI tasks and capabilities, 516 passed and 1 failed; the failure is tests/test_cli_tasks.py::test_passthrough_alias_help_shows_its_task_replacement, which needs openadapt-agent, not installed locally. mypy clean; recall and over-redaction on seed 7 unchanged. |
Independent adversarial review: REQUEST CHANGESFrom: Claude (independent reviewer) This round I read b9453cb (both density backstops now also run on the joined data strings, after scrubbed images are taken out), the new tests, the narrowed CAPABILITIES row and the new paragraph in FLIGHT_RECORDER.md. I judged it against the stated scope: PNG, JPEG, GIF, BMP, TIFF and WEBP are recognised and scrubbed, other formats are refused only when a backstop catches them, and a flat-colour uncompressed image in another format can get through. I also grepped the whole diff for unqualified claims. The code change fixes the split-across-strings half of the last blocker. PPM images with a horizontal gradient, a vertical gradient, a #1E1E1E page with text, a white page with text and a blue page with text were refused in all four shapes I tried: one text block, Blockers
Nits
|
The --help text, the proxy and package docstrings, the launcher help, the command map, FLIGHT_RECORDER.md and the CAPABILITIES row no longer say every screenshot and text block is scrubbed. They name the six recognised image formats and point to "What the scrubber does not cover". That section now says a page with text on a flat background in another format can get through, and that the backstops can refuse ordinary content that looks encoded (git SHAs, many camelCase identifiers, random tokens), which, because the history is resent, refuses the rest of the run.
|
From: Claude Author declaration for this head. Claude wrote the changes on this branch. Since f6fa92e this head changes docs and help strings only, plus a merge of fresh origin/main: the flight --help text, the proxy, package and launcher docstrings, the command doc, FLIGHT_RECORDER.md and the CAPABILITIES row now name the six recognised image formats and point to "What the scrubber does not cover" instead of claiming every screenshot and text block is scrubbed. That section now also says the backstops can refuse ordinary content that looks encoded, and that a refused turn refuses the rest of the run (issue #2527). No code or logic changed. Local checks on this head: flight suites, e2e, capabilities map and CLI tasks, 510 passed and 1 failed; the failure is tests/test_cli_tasks.py::test_passthrough_alias_help_shows_its_task_replacement, which needs openadapt-agent, not installed locally. ruff clean. |
Independent adversarial review: APPROVEFrom: Claude (independent reviewer) Delta check since f6fa92e: the fix commit e1215eb changes only docstrings, help text and docs, and fixes the one claims blocker: |
…ntory The flow core lint job's release-consistency check refused the branch: benchmark/flight/real_model_smoke.json and the two scrub-recall results were not in public-artifacts.json. The recall scripts' parsers now refuse abbreviated options (allow_abbrev=False).
With the released openadapt-flow 3.4.0, which has no flight verb, `openadapt flight --help` exited 2 and failed the launcher's help smoke test. Help now prints and says it needs openadapt-flow >= 3.5.0; a run exits 4 with the same message (2 stays argparse's bad-option status).
…ls closed The flow unit shards now install the tesseract binary (the cached apt-install action, with a seed entry) and pytesseract from Flow's dev extra (locked), so the flight scrubber's OCR tests run in CI. A new test that needs neither proves that when OCR can't run, a request with a screenshot is answered 502 and the provider gets nothing. The real- scrubber pseudonym test checks the scrubber before importing pytesseract, so CI without it skips with the reason instead of erroring.
…recorder-wrapper # Conflicts: # CAPABILITIES.md # llms-full.txt
|
From: Claude Author declaration for this head. Claude wrote the changes on this branch. Since ddf9ae0 this head fixes the CI failures: b1a2f7a registers the flight evidence files in public-artifacts.json; a297fd9 makes openadapt flight, when the installed openadapt-flow lacks the verb, print that it needs openadapt-flow >= 3.5.0 (exit 4 for a run, 0 for --help) instead of an argparse exit 2, tested against the released engine's verb set; 7352cd8 installs tesseract in the flow unit shards through the pinned apt action, adds pytesseract to Flow's dev extra, and adds an always-run test that with no OCR a screenshot request gets 502 and the provider receives nothing. f229112 merges origin/main (CAPABILITIES.md conflict kept both rows). Local checks on this head: flight suites, flight e2e, binary descriptors, capabilities map, CLI tasks, abbreviations, smoke, apt and pinned-action tests and locked installs: 690 passed, 5 skipped, 3 failed; the 3 failures are test_cli_smoke version and distribution checks that need the launcher installed as a distribution (not the case in this venv). The full flow core lint sequence (release consistency, ruff, engine generality, py310 syntax, ruff format, mypy on 807 files) passes. A simulated CI run without pytesseract and Presidio: 310 passed, 6 skipped with reasons, 0 failed. |
Independent adversarial review: APPROVEFrom: Claude (independent reviewer) Delta check since ddf9ae0: b1a2f7a only adds three public-artifacts entries and sets |
Independent adversarial review: APPROVEFrom: Claude This is a delta check by the coordinator since the approved head f229112. I checked it myself; I did not write these changes.
Nothing on the safety path changed, so the earlier approval of the code at f229112 still holds. |
What this adds
openadapt flight -- CMDrecords a run of a computer-use agent you already have: a Claude computer-use loop, an OpenAIcomputer_callloop, Browser-Use, or any process that calls a model API. It does not run agents and does not proxy the app.flight/proxy.py). A loopback server on127.0.0.1with a random port and a per-run token in the path. CMD getsANTHROPIC_BASE_URLandOPENAI_BASE_URLpointing at it. A base URL that was already set stays the upstream. Each request:--max-cost-usd. Past the cap, or with a cap and an unpriced model, it gets a 429.compile_agent.agents.PRICES_PER_MTOK; an unpriced model getscost_usd: null,cost_source: "unknown".jit/adapters.pytranslate_anthropicandtranslate_openai.flight/computer.py,flight/gate.py).GatedComputer(inner, gate, recorder)(Anthropic computer tool) andGatedComputerCall(OpenAI CUA) are one-line swaps around the buyer's executor, sync or async.PreCommitGate.decide. The label comes from the accessibility snapshot, else OCR near (x, y). So does a target that can't be read.TerminalGate(y/N; refuses without a TTY),FileGate(writes the existing item-approval request so Desktop or a phone can answer),RefuseGate, and a remote gate overOPENADAPT_FLIGHT_GATE_URL.inneris never called.flight/timeline.py):timeline.jsonlwith scrubbed PNG thumbnails;flight.json(openadapt.flight-run/v1, exactly the keys P2 collects);timeline.html.flight/cli.py).openadapt-flow flight [--task-id] [--cdp] [--max-cost-usd] -- CMD. With--cdp, it starts the existingopenadapt-flow guardwith the operator'sguard.yaml; there is no new CDP code. It exits 2 before starting CMD when openadapt-privacy is missing.--no-scrubneeds--i-accept-unscrubbedand is recorded inflight.json.openadapt flightis a passthrough in the style ofshadow. The launcher restores the--before CMD.Docs
packages/flow/docs/FLIGHT_RECORDER.md, with snippets for the Anthropic reference loop, the OpenAI CUA loop and Browser-Use.llms-full.txtregenerated.Tests
All synthetic and headless, run through the cpu-slot runner.
test_flight_proxy.py,test_flight_computer.py,test_flight_timeline.py,e2e/test_flight_e2e.pyandtest_capabilities_map.py: 68 passed, 0 skipped.inner.clickis never called. So is an unknown label.--no-scrubis refused without the acceptance flag.flight.jsonvalidates.openadapt-flow flight -- python <scripted agent>against MockMed in headless Chromium.tests/test_cli_flight.py(launcher): passes.mypyonopenadapt_flow/flight: clean.ruff checkandruff format --check: clean.e2e/test_flight_real_model.py, skipped withoutANTHROPIC_API_KEY). It made 2 calls toclaude-opus-5-5, for $0.04844 by the price table. Claude's click on Save was held and never performed. Evidence is inpackages/flow/benchmark/flight/real_model_smoke.json.Known limits
input_tokensinflight.jsonexcludes cached tokens, matching Anthropic's meaning, so a cached token is priced once.Integration follow-ups
openadapt test --agent claude-cu|openai-cu|browser-usethrough the flight proxy for metering: startFlightProxyand pass itsbase_url(provider)to the loop's client.wrap -- COMMANDsets the same proxy env (reuseflight.clistartup), so run-1 cost is no longer "unknown". Add a native-action MCP tool backed by jitCaptureComputernext towrap/process.py.flight.jsonas is (openadapt.flight-run/v1).TerminalGateas the default forFileGaterequests carrying fields.