Skip to content

feat(flow): Global-to-Local (GOLD) ROI cropping and unified VetoOnlyVLMGuard - #2485

Merged
abrichr merged 4 commits into
mainfrom
gemini/local-vlm-gold-crop
Nov 22, 2026
Merged

abrichr merged 4 commits into
mainfrom
gemini/local-vlm-gold-crop

Conversation

@abrichr

@abrichr abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member

Summary

Adds deterministic Global-to-Local (GOLD) ROI cropping and a unified veto-only VLM guard across openadapt_flow/runtime/remote_vlm.py and openadapt_flow/runtime/identity_vlm.py.

What changed

  1. Deterministic GOLD ROI cropping (remote_vlm.py):

    • Added GoldCropResult and gold_crop_for_model(png, roi=None, max_dim=1024).
    • When roi is omitted, invalid, or the frame already fits <= 1024px, behavior falls back identically to _downscale_for_model (used_gold=False, zero behavior regression).
    • When max(w, h) > 1024 and a valid roi is provided, extracts a padded ROI crop directly from the unscaled source frame (preserving native 1:1 resolution whenever the padded ROI fits <= 1024px, and always bounding every output inside <= 1024px) plus a single-image global+local composite (composite_png).
    • Wired optional roi: Optional[Region] = None into RemoteGrounder.locate (maps local crop coordinates back to original full-frame pixels, falling back to the global downscaled frame on local miss) and RemoteStateVerifier.verify / holds (sends the <= 1024px GOLD composite).
  2. Unified Veto-Only Local VLM Guard (identity_vlm.py):

    • Added VetoVerdict (PASS, VETO, ABSTAIN), VetoDecision, and VetoOnlyVLMGuard.
    • Enforces strict veto-only semantics: VETO and ABSTAIN (including exceptions, timeouts, missing backends, or unrecognized answers) always halt; PASS only declines to veto and never overrides a failing deterministic check (VetoDecision.apply_to_deterministic).
    • Supports both local (IdentityVLM / MLXIdentityVLM) and remote (RemoteIdentityVLM, RemoteStateVerifier) backends, satisfies the IdentityVLM protocol, and applies GOLD ROI cropping on > 1024px frames.
  3. Unit tests (tests/test_local_vlm_gold_crop.py):

    • Verifies zero behavior regression when roi is omitted or frames are <= 1024px.
    • Verifies native-resolution contrast preservation on 2560x1440 synthetic alert-banner frames vs. uniform downscaling, bounded <= 1024px dimensions for oversized ROIs, and deterministic coordinate round-trips.
    • Verifies the full strict veto-only truth table and fail-safe ABSTAIN handling.

Generality Gate

  1. No per-app code in the engine: Yes — openadapt_flow/runtime/remote_vlm.py and openadapt_flow/runtime/identity_vlm.py are purely geometric and protocol-level; scripts/check_engine_generality.py passes with zero new hits.
  2. Fix the class, not the instance: Yes — addresses the uniform-downscale legibility loss class across all > 1024px VLM entry points (grounding, state verification, and local/remote identity vetoing) through one shared gold_crop_for_model primitive and one VetoOnlyVLMGuard contract.
  3. Held-out evidence: Not yet shown on live held-out desktop captures in this PR; verified here on synthetic 2560x1440 / 3200x2400 high-frequency contrast frames and unit tests covering all entry points.

Durability

Advances independent, veto-only local verification on high-resolution screens without cloud egress, ensuring local VLMs can only veto or abstain and never weaken deterministic system-of-record checks.

Verification

  • uv run pytest -q tests/test_local_vlm_gold_crop.py tests/test_remote_vlm_downscale.py tests/test_remote_vlm.py tests/test_wire_remote_vlm.py — 64 passed
  • uv run python scripts/check_engine_generality.py — Engine generality OK (301 baseline hits left)
  • uv run ruff check openadapt_flow/runtime/identity_vlm.py openadapt_flow/runtime/remote_vlm.py tests/test_local_vlm_gold_crop.py — All checks passed
  • uv run ruff format --check openadapt_flow/runtime/identity_vlm.py openadapt_flow/runtime/remote_vlm.py tests/test_local_vlm_gold_crop.py — 3 files already formatted
  • uv run mypy openadapt_flow/runtime/identity_vlm.py openadapt_flow/runtime/remote_vlm.py — Success: no issues found in 2 source files

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: 533b8b2

P1. The new guard hides a remote backend from replay’s screenshot-egress check. The guard stores the identity comparator and state verifier without exposing their MAY_EGRESS classification. Replay classifies the injected component before it checks the operator’s opt-in and sets the run-report flag. With a remote comparator inside the guard, both decisions treat that comparator as local. Propagate the egress classification of the wrapped backends. A transport-free regression should check both refusal without opt-in and accurate reporting with opt-in. Wrapper · Classification · Replay opt-in and report flag

P1. Grounding accepts a point outside the image the model saw. The service returns numeric coordinates without checking image bounds. The local-crop branch adds the crop origin and accepts the result immediately. An out-of-crop coordinate can therefore become an ordinary on-screen point outside the observed region and suppress the global retry. Check finite coordinates against the actual submitted image before translating them. An invalid local result should take the existing global fallback, and an invalid global result should produce no proposal. Local return and fallback · Coordinate conversion · Service response

P2. An identity comparison can pair an identifier crop with a whole screenshot. The guard decides whether to use the crop independently for the recorded and live frames. If just one frame exceeds the size threshold, it compares that crop with the entire other frame and reports that cropping was used. This gives the comparator different subjects and can send pixels outside the requested identity region. For an identity check with an explicit region, supply corresponding crops on both sides or abstain before invoking the backend. Identity inputs · Size threshold

All three findings apply across applications. The veto-only truth table is correct. The identity ladder treats a model match as permission to continue checking identity. It cannot authorize the target from that match alone. Existing replay callers do not supply the new region argument. The state drift check still has its existing, separate semantics for non-write steps. The PR reports 64 passing tests and synthetic images. This review inspected the source and assertions and added no live model, screenshot or held-out measurement. At review time dependency review and Gitleaks had passed and package CI was queued. Identity ladder · State check · CI

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: 250241d

The egress finding is resolved. The guard propagates the classification of both wrapped backends. Replay checks that property before wiring the component and carries the result into the run report. The transport-free constructor test covers refusal without opt-in, reporting with opt-in and a fully local backend. Guard · Replay opt-in · Run report · Regression

Two cases from the prior review remain.

  1. Grounding still returns a point when it cannot establish the submitted image dimensions. When _png_dimensions(sent) returns None, any finite nonnegative point passes the new check. The existing client test supplies just the PNG signature and expects (120, 45) as a valid proposal. Treat unavailable dimensions as a miss, allowing the local path to retry globally and the global path to return no proposal. Use a valid small PNG in the client success fixture and retain the unreadable case as a refusal. The new checks do handle negative, nonfinite and out-of-range service coordinates on readable images. Bounds and mapping · Fallback · Existing fixture · Existing success assertion
  2. A partly clipped identity region still reaches the comparator. The extractor clips the requested ROI independently on each image and returns a crop for any nonempty intersection. For example, the existing 320-pixel-wide ROI starting at x=900 fits the 2560-pixel frame, while just 124 pixels of the requested region fit the 1024-pixel frame. The guard forwards both crops because both are nonempty. A different part of the identifier can therefore be absent on one side. For this identity check, require the requested subject region to be visible on both sides or abstain before calling the backend. The new tests correctly cover an interior ROI, a wholly offscreen ROI and unreadable identity input. Crop bounds · Comparator inputs · Existing mixed-size tests

The partial-region finding applies to callers using the optional ROI argument. The current replay resolver calls grounding without it. Both findings are application-independent. Resolver call This source review traced the callers and synthetic assertions. I made no model calls and did not rerun suites or measure held-out accuracy. Package CI

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 405ef88

Delta versus the prior Codex REQUEST CHANGES at 250241de (7070836259). Both remaining findings are addressed. I did not re-open the already-resolved egress finding; this delta does not touch those paths.

  1. Unreadable submitted-image dimensions are a miss. _ground_and_map now returns None when _png_dimensions(sent) is None, instead of accepting any finite nonnegative point. On the GOLD path a local miss still falls through to the global frame; a miss on the global (or non-GOLD) path returns no proposal. The transport success fixture now uses a valid 200×100 PNG, and test_grounder_refuses_unreadable_image_bytes keeps the signature-only stub as a refusal. Out-of-range and nonfinite service coordinates on readable images remain rejected.

  2. A partly clipped identity ROI no longer reaches the comparator. extract_roi_crop requires the entire requested subject region to lie inside the image and returns None if any edge is clipped, rather than forwarding a nonempty intersection. Context padding after that check may still clamp at the image border; the subject itself must be fully visible. The mixed-size identity test covers a 320-pixel-wide ROI starting at x=900 on the 1024-wide frame: the guard abstains with identity_roi_unavailable, should_halt is true, and the backend is not invoked.

This source review traced the grounder retry path, the crop helper, and the new tests. I made no model calls and did not rerun CI.

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 81700ae

Delta versus my prior APPROVE at 405ef884 (7071485560). This head is a clean GitHub "Update branch" merge: parents are the approved first parent 405ef884 and main 7ea502b7 (the #2496 merge I already approved at a0c67d62). The combined merge diff is empty, so there were no conflict resolutions. The unique-versus-main patch is byte-identical to the approved tree, including fail-closed unreadable grounder dimensions and abstention on a partly clipped identity ROI.

I reviewed only this merge delta, not the already-reviewed unique work or the already-merged main trees. I did not rerun CI.

@abrichr
abrichr merged commit f8b7275 into main Nov 22, 2026
51 of 52 checks passed
@abrichr
abrichr deleted the gemini/local-vlm-gold-crop branch November 22, 2026 02:48
abrichr added a commit that referenced this pull request Nov 22, 2026
…ncy signs

The branch's first commit was cut against a newer main than its tree, so it
reverted the GOLD crop and veto guard work from #2485. This puts those files
back as they are on main. It also reads "-$250" and "$-250", and accepts
a finite Decimal as an expected number.
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