Skip to content

feat(flow): hardware-tiered local model router and PrePostSubmitVisualVeto - #2536

Merged
abrichr merged 1 commit into
mainfrom
gemini/tiered-local-model-runtime
Nov 22, 2026
Merged

abrichr merged 1 commit into
mainfrom
gemini/tiered-local-model-runtime

Conversation

@abrichr

@abrichr abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member

Summary

Adds a domain-agnostic hardware-tiered local model policy/router and a pre/post-submit visual veto guard under openadapt_flow/models/ (__init__.py, runtime.py), building directly on the GOLD ROI cropping and VetoOnlyVLMGuard primitives from #2485.

What changed

  1. Hardware-Tiered Local Model Policy & Router (openadapt_flow/models/runtime.py):

    • Tier 1 (DETERMINISTIC_ONLY): Zero-model fast path; default whenever deterministic API/DB/SQL/DOM authority covers the check (prefer_deterministic=True).
    • Tier 2 (LOCAL_ACCELERATED / LAN_APPLIANCE): Routes to local Apple Silicon MLX / CUDA acceleration (zero egress) or an explicitly opted-in LAN GPU appliance (allow_lan_appliance=True, strict MAY_EGRESS = True propagation).
    • Tier 3 (CPU_LIGHTWEIGHT): Allows lightweight ONNX locate-only grounding on CPU-only hosts and explicitly refuses interactive 4B+ VLM calls (CpuVlmRefusedError when require_vlm=True, or a fail-closed abstaining guard when require_vlm=False) unless allow_slow_cpu_vlm=True is opted in for offline/async jobs.
    • detect_hardware_capabilities probes host capabilities via importlib.util.find_spec without importing heavy ML stacks.
  2. Pre/Post-Submit Visual Veto (PrePostSubmitVisualVeto):

    • Wraps VetoOnlyVLMGuard with GOLD ROI cropping (<= 1024px budget) for check_pre_submit (identity + optional state) and check_post_submit (state verification).
    • Enforces strict veto-only semantics: VETO and ABSTAIN always halt (allowed=False); PASS never overrides a failing deterministic check (deterministic_passed=False).
    • Propagates MAY_EGRESS cleanly into component_may_egress / Replayer opt-in enforcement.
  3. Unit tests (packages/flow/tests/test_tiered_local_model_runtime.py):

    • Covers capability detection, Tier 1/2/3 routing, CPU interactive 4B+ VLM refusal and offline opt-in, MAY_EGRESS propagation into Replayer, GOLD-cropped pre/post-submit veto truth tables, combined identity+state vetoes, and partly clipped ROI abstention.

Generality Gate

  1. No per-app code in the engine: Yes — openadapt_flow/models/ is purely hardware-capability and protocol-level; scripts/check_engine_generality.py passes with zero new hits.
  2. Fix the class, not the instance: Yes — addresses the cross-host model-routing and submit-boundary visual veto class (preventing interactive CPU VLM stalls, silent LAN egress, and VLM overrides of deterministic gates) through one shared policy router and veto wrapper.
  3. Held-out evidence: Not yet shown on live held-out desktop captures or live GPU/MLX hosts in this PR; verified here with transport-free unit tests and synthetic >1024px frames covering all tiers and veto truth tables.

Durability

Advances independent, accountable, hardware-aware local verification: deterministic system-of-record checks remain primary, visual models stay strictly veto-only, egress requires explicit opt-in, and CPU-only runners fail closed instead of stalling interactively.

Verification

  • uv run pytest -q tests/test_tiered_local_model_runtime.py tests/test_local_vlm_gold_crop.py tests/test_remote_vlm.py — 78 passed
  • uv run python scripts/check_engine_generality.py — Engine generality OK (199 baseline hits left)
  • python3 scripts/check_file_size_ratchet.py — passed (exit 0)
  • uv run ruff check openadapt_flow/models/__init__.py openadapt_flow/models/runtime.py tests/test_tiered_local_model_runtime.py — All checks passed
  • uv run ruff format --check openadapt_flow/models/__init__.py openadapt_flow/models/runtime.py tests/test_tiered_local_model_runtime.py — 3 files already formatted
  • uv run mypy openadapt_flow/models/__init__.py openadapt_flow/models/runtime.py — Success: no issues found in 2 source files

@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: 5f6db4b

Cross-vendor review of this Gemini-authored PR. I did not write these changes. The unique tree is three new files (packages/flow/openadapt_flow/models/{__init__,runtime}.py and packages/flow/tests/test_tiered_local_model_runtime.py; 830 insertions). The models package does not exist on main.

Safety and routing

  • TierPolicy defaults are fail-closed: prefer_deterministic=True, allow_lan_appliance=False, allow_slow_cpu_vlm=False, interactive=True.
  • When deterministic evidence is available, routing is DETERMINISTIC_ONLY with may_egress=False even if a LAN appliance is opted in.
  • OPENADAPT_FLOW_VLM_URL alone does not enable egress; LAN routing requires allow_lan_appliance=True.
  • On CPU-only hosts, build_veto_guard(require_vlm=True) raises CpuVlmRefusedError. Without that flag it returns an empty VetoOnlyVLMGuard that abstains without calling the injected VLM.
  • SubmitVetoResult.allowed uses existing VetoDecision.apply_to_deterministic: bool(deterministic_passed) and not should_halt. PASS never overrides a failed deterministic check. Tests cover the full pre- and post-submit truth table on synthetic 2560×1440 frames, including GOLD ROI crops (used_gold_crop and sent dimensions ≤ 1024).
  • MAY_EGRESS is propagated from the router, the built guard, and PrePostSubmitVisualVeto. Existing Replayer construction raises EgressNotPermitted unless allow_model_grounding=True is passed with an egress-capable guard.

No per-app names in the new engine module. No CI or safety weakening.

Residuals (not blockers of this PR's own content)

  • This PR does not auto-wire the router into the live replay/submit path. The Replayer test injects the built guard into the existing constructor to prove MAY_EGRESS is honored. Live integration is follow-up.
  • Held-out live desktop/hardware captures are not in this PR (disclosed; tests are transport-free / synthetic).
  • The CUDA LOCAL_ACCELERATED path does not auto-construct a VLM (only Apple Silicon gets MLXIdentityVLM()). Without an injected backend the guard fail-closes by abstaining.
  • appliance_from_env (pre-existing, unchanged) does not restrict the appliance URL to a private LAN.

No merge from this review.

@abrichr
abrichr merged commit fea84f2 into main Nov 22, 2026
91 of 97 checks passed
@abrichr
abrichr deleted the gemini/tiered-local-model-runtime branch November 22, 2026 15:13
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