Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1 +1 @@
| Wrapped tasks that sign in: during `openadapt wrap`'s first run the recorder finds a password field (`type=password`, or `autocomplete` `current-password`/`new-password`) and the username field paired with it (`autocomplete=username`, or a unique text, email or phone candidate paired across all password controls in the composed form; ambiguous or unreadable controls refuse declared inputs) from the page's markup alone. Automatic withholding requires that observation seam; a missing or noncallable seam refuses before capture or actor entry. Screen-only native backends use the existing explicit person-secret handoff instead of this automatic path. Their inputs become secret parameters: the recording, program, run records, receipts and publish upload keep the name and never the value, the observed field regions are blacked out in recording frames (arbitrary field movement or echoes are not proven redacted), a credential field given text that matches no declared input is refused before typing, a form with exactly a username and current password is classified as sign-in without lowering independent keyword risk, and replay run screenshots contain black frames while checks use the original pixels in memory. Secret environment/vault aliases must be unambiguous, and managed params files cannot supply secret values. The canary and cached runs type them from `OPENADAPT_FLOW_SECRET_<NAME>`, set from memory for one run; `publish` lists them as `secret_parameters`, outside the call's inputs | On main ([#2294](https://github.com/OpenAdaptAI/OpenAdapt/pull/2294), merged 2026-11-20) | Synthetic (a sign-in notes app in headless Chromium through the real wrap path: first run, canary, admission, publish staging, and a cached run under mcp 2, with a byte scan for the values in every file; unit tests with a fake backend for detection, frame redaction, refusals and the sign-in submit rule). Genuine RDP/Citrix backends refuse automatic withholding before input; explicit person-secret handoff remains tested. Hosted runs need an endpoint vault set (openadapt-cloud) | `openadapt_flow.recorder` (`withhold_credentials`), `openadapt_flow.secret_inputs`, [WRAP_PUBLISH.md](packages/flow/docs/WRAP_PUBLISH.md#tasks-that-sign-in), `packages/flow/tests/test_wrap_sign_in.py`, `packages/flow/tests/e2e/test_wrap_sign_in_e2e.py` |
| Wrapped tasks that sign in: during `openadapt wrap`'s first run the recorder finds a password field (`type=password`, or `autocomplete` `current-password`/`new-password`) and the username field paired with it (`autocomplete=username`, or a unique text, email or phone candidate paired across all password controls in the composed form; ambiguous or unreadable controls refuse declared inputs) from the page's markup alone. Automatic withholding requires that observation seam; a missing or noncallable seam refuses before capture or actor entry. Screen-only native backends use the existing explicit person-secret handoff instead of this automatic path. Their inputs become secret parameters: the recording, program, run records, receipts and publish upload keep the name and never the value, the observed field regions are blacked out in recording frames (arbitrary field movement or echoes are not proven redacted), a credential field given text that matches no declared input is refused before typing, a form with exactly a username and current password is classified as sign-in without lowering independent keyword risk, and replay run screenshots contain black frames while checks use the original pixels in memory, and no compiled pixel check covers a withheld field's black box (it is clipped clear of it or dropped). Secret environment/vault aliases must be unambiguous, and managed params files cannot supply secret values. The canary and cached runs type them from `OPENADAPT_FLOW_SECRET_<NAME>`, set from memory for one run; `publish` lists them as `secret_parameters`, outside the call's inputs | On main ([#2294](https://github.com/OpenAdaptAI/OpenAdapt/pull/2294), merged 2026-11-20) | Synthetic (a sign-in notes app in headless Chromium through the real wrap path: first run, canary, admission, publish staging, and a cached run under mcp 2, with a byte scan for the values in every file; unit tests with a fake backend for detection, frame redaction, refusals and the sign-in submit rule). Genuine RDP/Citrix backends refuse automatic withholding before input; explicit person-secret handoff remains tested. Hosted runs need an endpoint vault set (openadapt-cloud) | `openadapt_flow.recorder` (`withhold_credentials`), `openadapt_flow.secret_inputs`, [WRAP_PUBLISH.md](packages/flow/docs/WRAP_PUBLISH.md#tasks-that-sign-in), `packages/flow/tests/test_wrap_sign_in.py`, `packages/flow/tests/e2e/test_wrap_sign_in_e2e.py` |
10 changes: 10 additions & 0 deletions packages/flow/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@

### Fixes

- A wrapped sign-in no longer compiles a pixel check that freezes a withheld
credential field. The recorder blacks out a withheld field in every frame
that still shows it, so a `REGION_STABLE` crop that overlapped one held a
black rectangle that never matched the unredacted screenshot at replay
time, failing a step whose region overlapped a credential box during the
run, for example the click into the password field. Such a check is now
clipped to the part of its region clear of the box and re-cropped from the
same frame. When no usable part is left, it is dropped and recorded in
`param_hygiene.json`. This applies to mined checks and to the
focused-field pass.
- A FHIR searchset Bundle's `OperationOutcome` entry (`search.mode:
outcome`) is no longer read as a marker match. Packs can declare
`search_match` on the entry parent (Medplum uses `path: search.mode`,
Expand Down
155 changes: 155 additions & 0 deletions packages/flow/openadapt_flow/compiler/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,129 @@ def _crop_png(png: bytes, region: Region) -> bytes:
return encoded


def _shows_blackout(png: Optional[bytes], region: Region) -> bool:
"""Whether ``region`` of the frame is the recorder's solid black box.

The recorder fills a withheld credential field with black in every frame
that still shows it (``Recorder._redact``). Undecodable input counts as
blacked out, the safe direction for dropping a pixel invariant.
"""
if png is None:
return False
img = imgops.decode_bgr(png)
if img is None:
return True
x, y, w, h = region
crop = img[max(y, 0) : max(y, 0) + h, max(x, 0) : max(x, 0) + w]
if crop.size == 0:
return False
return bool((crop <= 8).all(axis=-1).mean() >= 0.95)


def _clip_away(region: Region, box: Region) -> Optional[Region]:
"""The largest part of ``region`` above, below, left or right of ``box``."""
x, y, w, h = region
bx, by, bw, bh = box
parts = [
(x, y, w, by - y),
(x, by + bh, w, y + h - (by + bh)),
(x, y, bx - x, h),
(bx + bw, y, x + w - (bx + bw), h),
]
parts = [p for p in parts if p[2] >= 8 and p[3] >= 8]
return max(parts, key=lambda p: p[2] * p[3]) if parts else None


def _checks_without_withheld_fields(
step: Step,
after_png: Optional[bytes],
boxes: list[Region],
bundle: Path,
) -> list[dict[str, Any]]:
"""Keep ``step``'s pixel checks off withheld credential fields.

The recorder fills a withheld field with black in every frame that still
shows it, so a REGION_STABLE crop over one froze a black box that no live
screen shows and would refute every run. The check is clipped to the part
of its region clear of the box, re-cropped from the same recorded frame;
a region with no usable part left is dropped. Returns one note per change.
"""
notes: list[dict[str, Any]] = []
if not boxes or not step.expect or after_png is None:
return notes
kept: list[Postcondition] = []
for pc in step.expect:
hits = [
box
for box in boxes
if pc.kind is PostconditionKind.REGION_STABLE
and pc.region is not None
and _regions_intersect(pc.region, box)
and _shows_blackout(after_png, box)
]
if not hits:
kept.append(pc)
continue
region: Optional[Region] = pc.region
for box in hits:
if region is not None and _regions_intersect(region, box):
region = _clip_away(region, box)
if region is not None and any(_regions_intersect(region, b) for b in hits):
region = None
note = {"step": step.id, "region": list(pc.region or ())}
if region is None:
notes.append(
{
**note,
"change": "drop_region_stable_over_withheld_field",
"evidence": "the recorded crop holds a withheld field's black box",
}
)
continue
rel = pc.template or f"templates/{step.id}_expect.png"
_sealed.write_bytes(bundle / rel, _crop_png(after_png, region))
kept.append(
pc.model_copy(
update={
"region": region,
"phash": phash_png(after_png, region=region),
"template": rel,
}
)
)
notes.append(
{
**note,
"change": "clip_region_stable_off_withheld_field",
"evidence": "the recorded crop held a withheld field's black box",
"clipped_region": list(region),
}
)
step.expect = kept
return notes


def _record_withheld_field_changes(
changes: list[dict[str, Any]],
param_region_drops: list[tuple[str, Region, str]],
) -> None:
"""Log each clip; record each drop in ``param_hygiene.json`` like the
other dropped REGION_STABLE checks (no new bundle file)."""
for change in changes:
if change["change"].startswith("drop_"):
param_region_drops.append(
(change["step"], tuple(change["region"]), "<withheld credential field>")
)
else:
logger.info(
"compile-pass %s: REGION_STABLE %s clipped to %s, clear of a "
"withheld credential field",
change["step"],
change["region"],
change["clipped_region"],
)


def _regions_intersect(a: Region, b: Region) -> bool:
ax, ay, aw, ah = a
bx, by, bw, bh = b
Expand Down Expand Up @@ -3850,6 +3973,9 @@ def cached_lines(i: int, suffix: str, png: bytes) -> list[OcrLine]:
# changed region rendered a demonstrated parameter value. Reported (not
# raised) below — the drop is the safe outcome, but it must not be silent.
param_region_drops: list[tuple[str, Region, str]] = []
# Boxes of withheld credential fields seen so far (recorder
# ``redacted_region``); recorded frames show them blacked out.
secret_field_regions: list[Region] = []
# Submit-binding observations recorded on click events (unlabeled
# controls only), attached once every risk decision is final.
binding_observations: dict[str, object] = {}
Expand Down Expand Up @@ -3935,6 +4061,18 @@ def cached_lines(i: int, suffix: str, png: bytes) -> list[OcrLine]:
)
for region, matched in step_region_drops:
param_region_drops.append((step.id, region, matched))
# A withheld credential field is blacked out in this and every later
# recorded frame; keep pixel checks off it (_checks_without_withheld_fields).
redacted = event.get("redacted_region")
if isinstance(redacted, (list, tuple)) and len(redacted) == 4:
x0, y0, x1, y1 = (int(v) for v in redacted)
secret_field_regions.append((x0, y0, x1, y1))
_record_withheld_field_changes(
_checks_without_withheld_fields(
step, step_after, secret_field_regions, bundle
),
param_region_drops,
)
if not step.expect:
# Nothing visual survived mining: fall back to structural
# postconditions (URL/title change, new tab) so the step is not
Expand Down Expand Up @@ -4300,6 +4438,23 @@ def cached_lines(i: int, suffix: str, png: bytes) -> list[OcrLine]:
pixel_verify_enabled=pixel_verify_enabled,
drop_redundant_keys=drop_redundant_keys,
)
# The focused-field pass above crops the clicked box from the recorded
# after-frame, which can still show a neighbouring withheld credential
# field as the recorder's black box. Apply the same rule as mining.
withheld_boxes: list[Region] = []
after_by_step: dict[str, tuple[Optional[bytes], list[Region]]] = {}
for step, _sb, after_png, event in pending:
redacted = event.get("redacted_region")
if isinstance(redacted, (list, tuple)) and len(redacted) == 4:
x0, y0, x1, y1 = (int(v) for v in redacted)
withheld_boxes.append((x0, y0, x1, y1))
after_by_step[step.id] = (after_png, list(withheld_boxes))
for step in steps:
after, boxes = after_by_step.get(step.id, (None, []))
_record_withheld_field_changes(
_checks_without_withheld_fields(step, after, boxes, bundle),
param_region_drops,
)
compile_notes = [
*compile_notes,
*guard_notes,
Expand Down
15 changes: 15 additions & 0 deletions packages/flow/tests/e2e/test_wrap_sign_in_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ def test_a_sign_in_becomes_secret_parameters_and_never_persists(

_assert_nothing_holds_a_credential(tmp_path, capfd)
_assert_fields_blacked_out(Path(program["task_dir"]))
_assert_no_pixel_check_froze_a_black_box(Path(program["bundle"]), workflow)

# What `openadapt wrap publish` would upload holds no credential either,
# and names the sign-in inputs as secret parameters, not call inputs.
Expand Down Expand Up @@ -311,6 +312,20 @@ def test_a_sign_in_becomes_secret_parameters_and_never_persists(
_assert_nothing_holds_a_credential(tmp_path, capfd)


def _assert_no_pixel_check_froze_a_black_box(bundle: Path, workflow) -> None:
"""A REGION_STABLE crop over a withheld field would hold the recorder's
black box, which no live screen shows, and refute every hosted run."""
import numpy as np
from PIL import Image

for step in workflow.steps:
for pc in step.expect:
if pc.kind.value != "region_stable" or not pc.template:
continue
pixels = np.asarray(Image.open(bundle / pc.template).convert("L"))
assert (pixels <= 8).mean() < 0.05, (step.id, pc.template)


def _assert_nothing_holds_a_credential(
tmp_path: Path, capfd: pytest.CaptureFixture[str]
) -> None:
Expand Down
120 changes: 120 additions & 0 deletions packages/flow/tests/test_compile_withheld_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
"""Pixel checks never freeze a withheld credential field's black box.

The recorder fills a withheld field with black in every frame that still
shows it, so a REGION_STABLE crop over one would refute every live run.
"""

from __future__ import annotations

import io
from pathlib import Path

from PIL import Image, ImageDraw

from openadapt_flow.compiler.compile import (
_checks_without_withheld_fields,
_clip_away,
_record_withheld_field_changes,
_shows_blackout,
)
from openadapt_flow.ir import ActionKind, Postcondition, PostconditionKind, Step

USERNAME_BOX = (20, 10, 120, 20) # withheld, blacked out by the recorder
PASSWORD_BOX = (20, 45, 120, 20)


def _frame(
*, black: tuple[int, int, int, int] | None = None, whole: bool = False
) -> bytes:
image = Image.new("RGB", (200, 100), "white")
draw = ImageDraw.Draw(image)
draw.rectangle((20, 45, 140, 65), outline=(30, 90, 200), width=2)
if whole:
draw.rectangle((0, 0, 199, 99), fill="black")
elif black is not None:
x, y, w, h = black
draw.rectangle((x, y, x + w - 1, y + h - 1), fill="black")
buf = io.BytesIO()
image.save(buf, format="PNG")
return buf.getvalue()


def _step(region: tuple[int, int, int, int]) -> Step:
return Step(
id="step_002",
intent="click recorded visual target",
action=ActionKind.CLICK,
expect=[
Postcondition(
kind=PostconditionKind.REGION_STABLE,
region=region,
phash="0" * 16,
template="templates/step_002_expect.png",
),
Postcondition(kind=PostconditionKind.TEXT_PRESENT, text="Sign in"),
],
)


def test_blackout_is_read_from_the_frame_not_assumed():
assert _shows_blackout(_frame(black=USERNAME_BOX), USERNAME_BOX)
assert not _shows_blackout(_frame(), USERNAME_BOX)
assert _shows_blackout(_frame(whole=True), USERNAME_BOX)
assert not _shows_blackout(None, USERNAME_BOX)


def test_clip_keeps_the_largest_part_clear_of_the_box():
assert _clip_away((10, 0, 160, 80), USERNAME_BOX) == (10, 30, 160, 50)
# Nothing of 8 x 8 or more survives inside the box itself.
assert _clip_away(USERNAME_BOX, USERNAME_BOX) is None


def test_a_check_over_the_black_box_is_clipped_and_recropped(tmp_path: Path):
(tmp_path / "templates").mkdir()
step = _step((10, 0, 160, 80))
changes = _checks_without_withheld_fields(
step, _frame(black=USERNAME_BOX), [USERNAME_BOX], tmp_path
)
region_checks = [
pc for pc in step.expect if pc.kind is PostconditionKind.REGION_STABLE
]
assert [pc.region for pc in region_checks] == [(10, 30, 160, 50)]
assert region_checks[0].phash != "0" * 16
template = Image.open(tmp_path / "templates/step_002_expect.png").convert("L")
assert template.size == (160, 50)
pixels = list(template.getdata())
assert sum(p <= 8 for p in pixels) / len(pixels) < 0.05
assert [c["change"] for c in changes] == ["clip_region_stable_off_withheld_field"]
# The other check on the step is untouched.
assert any(pc.kind is PostconditionKind.TEXT_PRESENT for pc in step.expect)


def test_a_check_inside_the_black_box_is_dropped_and_recorded(tmp_path: Path):
step = _step(USERNAME_BOX)
changes = _checks_without_withheld_fields(
step, _frame(black=USERNAME_BOX), [USERNAME_BOX], tmp_path
)
assert [pc.kind for pc in step.expect] == [PostconditionKind.TEXT_PRESENT]
drops: list = []
_record_withheld_field_changes(changes, drops)
assert drops == [("step_002", USERNAME_BOX, "<withheld credential field>")]


def test_a_frame_from_before_the_field_was_typed_keeps_its_check(tmp_path: Path):
step = _step((10, 0, 160, 80))
assert (
_checks_without_withheld_fields(step, _frame(), [USERNAME_BOX], tmp_path) == []
)
assert step.expect[0].region == (10, 0, 160, 80)


def test_a_check_clear_of_every_box_is_untouched(tmp_path: Path):
step = _step(PASSWORD_BOX)
before = step.model_copy(deep=True)
assert (
_checks_without_withheld_fields(
step, _frame(black=USERNAME_BOX), [USERNAME_BOX], tmp_path
)
== []
)
assert step == before
Loading