Skip to content

fix(flow): capture readers rebuild minimized bodies or refuse (#2789) - #2819

Merged
abrichr merged 7 commits into
mainfrom
fix/2789-capture-readers-minimized
Dec 1, 2026
Merged

abrichr merged 7 commits into
mainfrom
fix/2789-capture-readers-minimized

Conversation

@abrichr

@abrichr abrichr commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Fixes #2789, fixes #2820.

Since #2480, a network capture keeps only declared fields. A save is written as body_minimized/form_minimized, and a response as response_minimized. Five readers still looked only at body, form or response_text, so in a default capture they saw an empty body. Each one now rebuilds what it can use from the kept fields, or refuses and names the withheld field and the recording flag that fixes it.

Shared reader

openadapt_flow/capture_bodies.py follows the approach of #2785:

  • It rebuilds a minimized form as its kept [name, value] pairs. It rebuilds a minimized JSON body with capture_privacy.restore_kept_json.
  • An opaque or cut body raises BodyUnreadable.
  • A needed field that was withheld raises FieldsWithheld. Needed fields are compared as full paths, case-exact. Session tokens and secrets (is_withheld_name) count as withheld.
  • request_hidden and response_hidden separate "minimized away" from the opaque descriptors a raw capture also writes: a multipart body with a file, a body that isn't UTF-8 (including one over the size cap), and a response type it keeps as bytes, such as text/xml. Readers that have the recording trust the capture header (bodies: raw), so nothing is hidden in a raw capture.
  • readiness/reference.py now uses this reader instead of its own _kept_fields. Its codes and messages are unchanged, and the fix(flow): readiness import reads minimized network captures #2785 tests pass as they are.

Readers

Reader Minimized capture, after this PR
undo_proposal Finds the save by its kept selector fields and reads the record id from the kept response fields. It refuses when a selector field was withheld, when a later write was withheld (that write could be the save), or when the response id was withheld. The refusal suggests --identifier. When form fields are named differently from the selector (form_lname for lname), the match falls back to values; a later write whose withheld values could hold the selector's values also refuses.
record_check_synthesis _write_values returns the kept sent values. A write it can't read is listed as not covered, with the real reason instead of "no read returns what this request sent". Withheld sent constants are noted. Minimized read responses are not used to build a check; a note says raw bodies are needed.
record_check_proof.body_template Uses the rebuilt body only when every field, secrets included, was kept. Otherwise it raises ProofUnavailable (surfaced as ScaffoldRefused) instead of quietly proving the fixture's default body. A rebuilt body loses key order and empty containers. That is acceptable here because the template is already a flat rendering (top-level keys, values as text) sent only to the caller's local proof fixture.
read_discovery.cover and discover Refuse when a write's body is unreadable or any of its fields were withheld (_write_unseen), since a withheld value would count as "not sent" and a read holding only the kept values could be promoted. cover also refuses when no write sent a recorded parameter value, because "the read holds every written value" would then pass vacuously (#2820).
compiler/api_proposal Refuses on both paths with an accurate reason, instead of "no form request was sent". An API step sends every field of the save again, and a form save also needs the form page's HTML, which a minimized capture keeps as opaque. The screen-text pre-check guard also refuses when the responses it would search were minimized.
tx/network_bridge Raises ValueError instead of writing a HAR with empty bodies for lens induction.

The local_edit and compile.py readers look only at methods and times, so they were left unchanged.

One departure from the four-case test list: for api_proposal and network_bridge, the "kept field is used" case is a refusal even when every field was kept. A rebuilt body loses key order and empty objects and lists, and the HMAC key is gone, so it can't be proven to match what was sent. That is fine for finding a request and not fine for one that gets sent again.

Tests

tests/test_capture_readers_minimized.py (38 tests) builds every capture with the real BodyMinimizer/minimize_line, with the header a minimized recording writes. For each reader it covers a kept field, a withheld field, an opaque (cut) body and a raw capture. It also checks that the three raw-capture opaque shapes leave each reader as it is on main. tests/test_read_discovery_cover.py adds the #2820 regression test: a raw capture whose write sent no recorded parameter. The existing tests for these modules, and the import-layer tests, pass.

Docs

docs/NETWORK_CAPTURE.md now says what each reader does with a minimized capture. docs/LIMITS.md has a short paragraph in the privacy section.

Since #2480 a capture keeps only declared fields: a save is written as
body_minimized/form_minimized and a response as response_minimized. The
undo proposal, record check synthesis and proof, API step proposal and the
network-to-HAR bridge read only body/form/response_text, so in a default
capture they saw an empty body.

A shared reader (capture_bodies) rebuilds kept JSON and form fields and
refuses an opaque body or a withheld field the reader needs, as #2785 did
for readiness import (which now uses it). Each reader rebuilds what it can
use or refuses with the recording flag that fixes it.
…uard

Core modules reach the undo proposal and record check synthesis; the agent
guard import pulled a forbidden chain into core (test_import_layers).
…ack, cover guard

A raw capture also writes opaque descriptors (a multipart body with a file,
a binary body over the cap, a response type it keeps as bytes). Those are
no longer read as minimized away; readers that have the capture header
trust it. The undo match that falls back to values now refuses a later
write whose withheld values may be the selector's, and the read cover
refuses a write the capture kept nothing of.
@abrichr

abrichr commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: ba0c481

capture_bodies.request_body / response_body rebuild kept fields or raise, and request_hidden / response_hidden correctly return false for a raw capture and for opaque shapes a raw capture also cannot read (multipart with a file / body_omitted, a non-UTF-8 body, text/xml responses). I agree with the deliberate split: api_proposal must refuse even a fully kept minimized JSON save, because a rebuilt body drops key order and empty containers and cannot be checked against the HMAC; body_template may accept a fully kept rebuild because it only renders a flat template for the local proof fixture, and it still refuses when any field, secrets included, was withheld. undo_proposal, record_check_synthesis, body_template, api_proposal, network_bridge and readiness all refuse an opaque or withheld body instead of treating it as empty. The 36 tests in test_capture_readers_minimized.py passed locally (4.61s), and ruff is clean on the touched files.

The gap is read_discovery.cover. It only consults _write_unreadable, so a cut or opaque write is refused, but a write that kept some fields and withheld others is treated as if the withheld fields were never sent. _sent_params is built from _write_values, which returns only kept fields. I checked this on the real minimize_line helper used by the new tests: a save of {"patient_id": "p1", "type": "Triage", ...} minimized to keep only patient_id has _write_unseen naming type and note, while _sent_params(..., {"patient_id": "p1", "type": "Triage"}) returns only {"patient_id": "p1"}. cover then confirms the "whole save" against that incomplete sent set, so a read that holds patient_id and not type can be promoted. Synthesis already uses _write_unseen for this case; cover should refuse the same way, and there is no test for it. discover() has the same _sent_params path and was not updated.

Hosted flow unit, lint, and the critical job were still queued or running when I posted. I did not wait for them, and I did not run the Windows-only jobs.

Please teach cover (and, if this is in scope, discover) to refuse when _write_unseen is set, and add a test that a withheld sent parameter cannot be treated as "not sent."

…ent set

cover() and discover() built the written values from kept fields only, so
a value the capture withheld counted as not sent and a read holding only
the kept values could be promoted. Both now refuse when a write's body is
unreadable or any field was withheld. cover() also refuses when no write
sent a recorded parameter value, where the subset check passed vacuously
(#2820).
@abrichr

abrichr commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 3a5cb4d

The blocker I raised at ba0c481b15 is fixed. cover() and discover() now share _unseen_write, which uses record_check_synthesis._write_unseen, so both refuse when a write's body is unreadable or when any field of it was withheld, secrets included. They refuse before probing: the new tests pass a get that would fail if it were called. cover() also refuses when no write sent a recorded parameter value, with the same reason discover() already skips, so set(sent) <= bound can no longer pass vacuously.

I checked this against a real minimize_line save that kept patient_id and withheld type (and note). _sent_params would otherwise have treated type as not sent. I ran tests/test_capture_readers_minimized.py and tests/test_read_discovery_cover.py against this head: 63 passed in 107.47s, including test_read_cover_refuses_a_write_whose_sent_fields_were_withheld, test_read_discover_refuses_a_write_whose_sent_fields_were_withheld, and test_cover_refuses_when_no_write_sent_a_recorded_value. Ruff is clean on the touched files.

Generality gate: pass. The delta is generic capture-reader refusal. scripts/check_engine_generality.py reports "Engine generality OK (7 baseline hits left)". The new tests use the existing synthetic encounter save and the local transfer fixture.

CI on this head: gitleaks, smoke, validate-platform-manifest, launcher, the GTK no-skip check, and freerdp all passed. Flow unit, lint, critical, default-at-rest, and the Windows replay job were still running when I posted. I did not wait for them, and I did not run the Windows-only jobs locally.

I did not push to this branch, and I will not merge it.

@abrichr

abrichr commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 9e49eab

This head is a clean merge of the previously approved 3a5cb4d0fc43a6ff575805346fe785cc7f215011 with main at 263a0b126 (which includes #2795, fda882acd). The auto-merge tree equals the commit tree (0f0dc496eb9b2e7ad08928442424b775b2f90f60); there was no manual conflict resolution.

The only file touched by both sides is packages/flow/docs/LIMITS.md. Both additions survived intact in their own sections: the Windows-approval limit from #2795 near the top, and this PR's minimized-capture paragraph in the privacy section. There are no conflict markers. The eleven PR-unique source, test and NETWORK_CAPTURE.md files are byte-identical to the previously approved head. main's flow delta is the Windows/CLI/approval work; it did not change any module those files import.

I re-ran the exact-head tests at 9e49eabcf2df787abd381bafc86b9e87d2060e08: tests/test_capture_readers_minimized.py and tests/test_read_discovery_cover.py — 63 passed in 107.96s, including the withheld-field and empty-sent-set cover/discover cases. Ruff is clean on the touched files.

Generality gate: pass. scripts/check_engine_generality.py reports "Engine generality OK (7 baseline hits left)". The delta remains generic capture-reader refusal; the merge did not add app-specific engine code.

CI on this head: platform manifest, internal links and anchors, the GTK no-skip check, and freerdp all passed. The Windows replay job (the reason for this merge) was still in progress when I posted. gitleaks, dependency-review and the packages CI workflow had not finished (packages CI was still pending, with no jobs started yet). I did not wait for them, and I did not run the Windows-only jobs locally.

I did not push to this branch, and I will not merge it.

@abrichr
abrichr enabled auto-merge November 30, 2026 22:20
@abrichr

abrichr commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: fa7f591

This head is a clean merge of the previously approved 9e49eabcf2df787abd381bafc86b9e87d2060e08 with main at 3646d65d8 (which includes #2845, 43f4a4158). The auto-merge tree equals the commit tree (2a3205b8a53af54af5929a093d8c24e52ea390f9); there was no manual conflict resolution.

All twelve PR-unique files are byte-identical to the previously approved head. The only files this merge brought in from main are scripts/build_results_table.py, openadapt/transducer_fact_ledger.py, and tests/test_transducer_fact_ledger.py.

I re-ran the exact-head tests at fa7f59107d7512ca016a9a462d11b8c29e855432: tests/test_capture_readers_minimized.py and tests/test_read_discovery_cover.py — 63 passed in 107.02s. Ruff is clean on the touched files.

Generality gate: pass. scripts/check_engine_generality.py reports "Engine generality OK (7 baseline hits left)". The delta remains generic capture-reader refusal; the merge did not add app-specific engine code.

CI on this head: platform manifest, internal links, gitleaks, dependency-review, the GTK no-skip check, and freerdp all passed. review-verdict passed with "no protected paths". Packages CI was still pending when I posted. Windows replay (desktop-replay.yml) failed: test_native_windows_campaign_reads_back_normal_and_all_faults, case fault-ambiguity, expected HALTED and got FAILED. The three representative trials on that same run were VERIFIED. That same job was green on the previous approved head 9e49eabcf. This PR's unique files did not change, so the failure arrived with main at 3646d65d8, not with this PR's readers. I did not run the Windows job locally.

I did not push to this branch, and I will not merge it.

@abrichr
abrichr added this pull request to the merge queue Dec 1, 2026
@abrichr
abrichr removed this pull request from the merge queue due to a manual request Dec 1, 2026
@abrichr
abrichr added this pull request to the merge queue Dec 1, 2026
Merged via the queue into main with commit 28da1cf Dec 1, 2026
53 of 54 checks passed
@abrichr
abrichr deleted the fix/2789-capture-readers-minimized branch December 1, 2026 22:38
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.

read_discovery.cover promotes a read when no write sent a recorded value Readers of network captures ignore minimized bodies since #2480

1 participant