Skip to content

fix(flow): readiness import reads minimized network captures - #2785

Merged
abrichr merged 3 commits into
mainfrom
fix/red-main-nightly
Nov 30, 2026
Merged

abrichr merged 3 commits into
mainfrom
fix/red-main-nightly

Conversation

@abrichr

@abrichr abrichr commented Nov 30, 2026

Copy link
Copy Markdown
Member

Problem

The nightly full run on main has failed in flow core unit since #2480 landed (24 Nov), and #2698 tracks it. Four tests/e2e/test_readiness_adversarial_e2e.py tests fail because import_episodes refuses every task: save_unreadable: the capture did not keep the save's body.

#2480 made network captures keep only declared field values. A save is now written as body_minimized (kept values plus a keyed hash of each other field), with no body. readiness.reference._from_network still read body. So every readiness recording made the way READINESS.md described (record --capture-network, no declared fields) could not be imported. Pull requests never run tests/e2e; only the nightly run does, which is why this lasted five days.

Fix

  • _from_network rebuilds the save from body_minimized's kept fields (capture_privacy.restore_kept_json).
  • The comparison needs the person's values, so each compared field must have been kept: the task's fields when it names them, else every field of the save. A withheld one refuses the task with save_fields_withheld, naming the field and --param / --identifier (or raw bodies on a sealed recording). It never compares part of the save.
  • Withheld session tokens and secrets are expected. They count toward withheld_fields, as they do for a raw body.
  • READINESS.md step 1 now records with --identifier patient_id --param type --param note.
  • The e2e recorder declares the save's fields, as record --param does.

Tests

  • tests/e2e/test_readiness_adversarial_e2e.py and tests/e2e/test_readiness_e2e.py pass locally in a clean uv sync --frozen --extra dev env (7 passed, 1 skipped).
  • New unit tests: kept fields import, with the token counted as withheld; undeclared fields refuse with save_fields_withheld; a task naming its fields needs only those kept.
  • tests/test_readiness_*.py: 92 passed.

The other nightly failure, Desktop replay since #2291 (25 Nov), is separate and isn't fixed here.

Since #2480, network captures keep only declared fields by default and write
`body_minimized` instead of `body`. `readiness import` still read `body`,
found none, and refused every recorded task with `save_unreadable`. That
included recordings made exactly as READINESS.md said, and four nightly
readiness e2e tests failed.

The importer now rebuilds the save from the kept fields. A field the
comparison needs (the task's `fields`, else every field of the save) that was
withheld refuses the task with `save_fields_withheld`, naming the field and
the recording flag that keeps it, instead of comparing part of the save.
Withheld session tokens and secrets are expected and are counted, as for a
raw body. READINESS.md now says to record with `--identifier`/`--param` for
the save's fields, and the e2e recorder declares them.
@abrichr

abrichr commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: 6787617

The fix does what the nightly needs. The readiness e2e tests that fail on main with save_unreadable pass at this head. A minimized JSON save with every field declared imports, and one with nothing declared refuses with save_fields_withheld. Two gaps remain in the same function: one lets a compared field through when it was withheld, and form-encoded saves still can't be imported.

Blocking

  1. A withheld compared field passes when its last path segment matches a kept field.
    • _kept_body reduces each kept path to its last segment (packages/flow/openadapt_flow/readiness/reference.py:349-352) and checks the task's fields against those segments (:364).
    • parse_body_fields names JSON fields by their full dotted path (shadow_hold._flatten), and _from_network then filters on those names (:293). So the two sides compare different names.
    • Probe. I minimized a real save with BodyMinimizer(keep_fields=["patient_id", "type", "meta.note"]). Its body was {"patient_id", "type", "note", "meta": {"note"}}, so meta.note was kept and the top-level note was withheld. The task had fields: ["type", "note"].
    • Result. The import succeeds with human_fields = patient_id and type, and note is silently dropped. The PR's rule ("a withheld one refuses the task … instead of comparing part of the save") is broken.
    • Effect downstream. compare.py only compares the reference's fields (:308). A candidate that never writes the note at all can reach MATCHED (:341-353).
    • Fix. Compare fields against the full kept paths, the same names parse_body_fields produces. Also refuse when a named field is absent from the rebuilt body.
  2. Form-encoded saves still refuse with save_unreadable.
    • For application/x-www-form-urlencoded and multipart saves, NetworkCapture writes form and no body. minimize_line then replaces form with form_minimized (capture_privacy.py).
    • _from_network reads only body_minimized (:272-277) and form (:283). It never reads form_minimized.
    • Probe. A form save with all three fields declared, minimized by the real minimizer, is refused with save_unreadable: the capture did not keep the save's body.
    • This is the same regression from feat(flow): keep only declared fields of captured bodies on disk #2480 in the same function, for a common kind of save. It fails closed, but the title says readiness import reads minimized captures.
    • Fix. When form is absent, rebuild form_pairs from form_minimized["kept"], with the same withheld-field refusal.

Non-blocking

  1. A truncated or opaque body gets the wrong refusal code. When the body was truncated or opaque, body_minimized has no kept. _kept_body runs before the body_omitted check and refuses with save_fields_withheld … every field, which suggests that declaring fields would help. save_unreadable is the accurate code.
  2. Other readers have the same problem (Generality gate point 2). These readers still look only at line["body"] or line["form"], so they see nothing in a minimized capture. Name them in the PR, or in an issue, as the same class:
    • undo_proposal.py:387
    • record_check_proof.py:166
    • record_check_synthesis.py:542
    • compiler/api_proposal.py:1092-1173

Tests at this head (Linux, Python 3.12, clean venv from the locks)

  • pytest tests/test_readiness_*.py tests/e2e/test_readiness_e2e.py tests/e2e/test_readiness_adversarial_e2e.py: 108 passed, 7 skipped.
  • The two e2e files on their own: 7 passed, 1 skipped (scrubbed egress needs the OS egress block (macOS)).
  • The same two e2e files on main at b13f96a1: 5 failed, 2 passed, 1 skipped, all with save_unreadable, matching main is red #2698. Pull requests don't run these, so I ran them here.
  • Probes (temporary tests that use the real BodyMinimizer and minimize_line):
    • All fields declared: imports, with the token counted as withheld.
    • Nothing declared: save_fields_withheld.
    • Truncated: refused.
    • Matching last segment: imports without note (item 1).
    • Form save with all fields declared: save_unreadable (item 2).

Generality gate:

  1. Pass. check_engine_generality.py: "Engine generality OK (7 baseline hits left)". No app-specific code. MockMed appears only in the e2e fixture.
  2. Fails as it stands. The defect class is "readers of a minimized capture". The PR fixes one reader, and only its JSON case. Items 2 and 4 are siblings.
  3. Held-out evidence: the fix is shown only on the MockMed e2e app that motivated it.

Not run: a real recorded session with record --capture-network (the e2e uses NetworkCapture with keep_fields), and the macOS egress test.

CI at this head: 24 pass, 20 skipped, and packages / packages-gate was still pending.

I didn't push to this branch, and I won't merge it.

… truncated bodies as unreadable

Grok on #2785:
- the task's fields were checked against the last segment of each kept
  path, so a kept meta.note satisfied a withheld note and the import
  silently dropped it. Fields are now compared by full path, the names
  parse_body_fields gives them, and a named field the save doesn't carry
  refuses.
- form saves are minimized to form_minimized, which the importer never
  read: they are rebuilt from its kept pairs with the same refusal.
- an opaque or truncated body kept nothing and now refuses as
  save_unreadable, not save_fields_withheld.
@abrichr

abrichr commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Grok
Reviewed-Head: a1e5c01

All four items from my last review are addressed, and the probes now use the real minimizer. One fail-open path is left, in the new "a named field the save doesn't carry refuses" check: it compares names without regard to case, but the filter right after it is case-sensitive.

Prior blockers

  1. Full kept paths: fixed. I ran the suffix probe with the real BodyMinimizer (body {patient_id, type, note, meta: {note}}, keep_fields=["patient_id", "type", "meta.note"], task fields: ["type", "note"]). It now refuses with save_fields_withheld … note. A nested field that was kept (fields: ["type", "meta.note"]) imports as meta.note.
  2. Form saves: fixed. A minimized form save with every field declared imports all three fields. With note undeclared, the same save refuses with save_fields_withheld. A truncated form (form_minimized opaque) refuses with save_unreadable.
  3. Opaque or truncated body: fixed. A truncated JSON body now refuses with save_unreadable.
  4. Sibling readers: filed as Readers of network captures ignore minimized bodies since #2480 #2789, which is open. Good.

Blocking

A. A task field named in a different case passes the presence check and is then dropped.

  • packages/flow/openadapt_flow/readiness/reference.py:308-309 checks the task's fields against the save's field names in lower case. :317-318 then keeps only the fields whose exact name is in fields or expected_record.
  • Probe. A save of {patient_id, type, note}, with the task naming fields: ["type", "Note"]. It imports with human_fields = patient_id, type, so note is silently gone. This happens for a minimized save with note declared, and for a raw body.
  • Effect downstream. compare.py only compares the reference's fields (:290), and it treats as extra only names that aren't declared (:308). So a candidate that never writes the note can reach MATCHED. A candidate that does write it gets MISMATCHED with an extra field.
  • Main has no presence check at all, so on main this drop already happens for raw bodies. But this PR adds the check to rule it out, and the check misses this case.
  • Fix: compare the same way in both places. Make the presence check case-sensitive (JSON and form names are case-sensitive), or filter by the lower-cased name. Add the probe as a test.

Tests at this head (Linux, Python 3.12, editable venv from the locks)

  • pytest tests/test_readiness_*.py tests/e2e/test_readiness_e2e.py tests/e2e/test_readiness_adversarial_e2e.py: 112 passed, 7 skipped.
  • The two readiness e2e files on their own: 7 passed, 1 skipped (scrubbed egress needs the OS egress block (macOS)). On main they fail with save_unreadable, as I reported last round. Pull requests don't run them.
  • tests/test_readiness_reference.py plus the capture-privacy and network-capture tests: 86 passed, 1 skipped.
  • ruff check and ruff format --check on the two changed files: clean.
  • Probes: 11 temporary tests that use the real BodyMinimizer and minimize_line. They cover all fields declared, nothing declared, the suffix collision, a nested kept field, an array body, a form save with all fields declared, a form save with a withheld field, a truncated form, a truncated body (two variants) and a case mismatch. 10 pass. The case mismatch is item A.

Generality gate:

  1. Pass. packages/flow/scripts/check_engine_generality.py: "Engine generality OK (7 baseline hits left)". MockMed appears only in the e2e fixture.
  2. Pass for this reader. JSON and form captures both go through one _kept_fields with the same refusal, and the other readers are tracked in Readers of network captures ignore minimized bodies since #2480 #2789.
  3. Held-out evidence: the unit probes use generic synthetic saves, beyond the MockMed e2e app.

Not run: a real recorded session with record --capture-network, and the macOS egress test.

CI at this head (when I checked): 19 pass, 19 skipped, and 5 pending: flow agent frameworks, flow default at rest (shard 2/4), and flow core unit shards 1, 2 and 4.

I didn't push to this branch, and I won't merge it.

Grok on #2785: the presence check lower-cased names while the filter after
it is case-sensitive, so a task naming "Note" passed the check and then
silently dropped "note". JSON and form field names are case-sensitive;
both checks now compare them exactly, and a differently cased name refuses.
@abrichr

abrichr commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 7ad0140

The case-sensitivity gap from my last review is closed. The presence check and the filter in _from_network now compare field names exactly, so a task that names Note against a save that carries note refuses with save_fields_withheld instead of importing with the field silently dropped. I found no remaining fail-open path.

Prior blocker

  • Name compared in a different case: fixed. A save of {patient_id, type, note} with the task naming fields: ["type", "Note"] now refuses with save_fields_withheld … Note, both for a raw body and for a minimized save produced by the real BodyMinimizer with note declared. It is a parametrized regression test (test_a_task_field_named_in_another_case_refuses_instead_of_dropping).

Verification at this head (Linux, Python 3.12)

  • pytest tests/test_readiness_*.py tests/e2e/test_readiness_e2e.py tests/e2e/test_readiness_adversarial_e2e.py: 114 passed, 7 skipped.
  • packages/flow/scripts/check_engine_generality.py: "Engine generality OK (7 baseline hits left)".

New adversarial probes (throwaway, not committed; each run for a raw body and a real-minimizer save)

  • Trailing-space name ("note " in the save, note in the task): refuses in both.
  • Unicode case folding (Straße in the save, STRASSE in the task): refuses in both.
  • Array element (items[0].note kept; task names note): refuses. Task naming items[0].note: refuses with the path in the message (the array path form is not accepted as a task field name; this fails closed).
  • Nested leaf only (meta.note kept; task names note): refuses. Task naming meta.note: imports as meta.note.
  • Literal dotted flat key ("meta.note"): imports.
  • Task naming a session-token field (csrf_token): refuses.
  • Empty-string and null values for a named field: import, value preserved.
  • No fields in the task, only secret-named fields withheld: imports and counts them as withheld. No fields and nothing kept: refuses for the minimized save, imports for a raw one (correct).
  • Duplicate JSON key (note twice): imports the last value, in both raw and minimized form.
  • Task fields entry that is an integer next to a digit-named save key: raw imports; the minimized save refuses (fail-closed, an edge I did not pursue).
  • No fail-open case found; every deviation between raw and minimized forms is a refusal.

Generality gate

  1. No per-app code: pass. The change is generic path and name handling in readiness/reference.py.
  2. Fix the class: pass. One exact-name rule is used by both the presence check and the filter, and applies to JSON and form saves alike.
  3. Held-out evidence: the probes above use generic synthetic saves beyond the added test.

CI at this head

When checked: 15 pass, 19 skipped by the path filter, 9 pending (the flow core unit and flow default at rest shards and the on-prem offline install job). No failures.

Not run

A real recorded session with record --capture-network, and the macOS-only egress test.

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

@abrichr
abrichr added this pull request to the merge queue Nov 30, 2026
Merged via the queue into main with commit 013c9b4 Nov 30, 2026
49 checks passed
@abrichr
abrichr deleted the fix/red-main-nightly branch November 30, 2026 15:56
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