Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6a5a08a
test(flow): reproduce remote-model fail-open and egress findings
abrichr Nov 21, 2026
f0078d6
test(flow): format fail-open reproductions
abrichr Nov 21, 2026
edbe4a6
test(flow): keep drift reproductions valid once unmarked counts as eg…
abrichr Nov 21, 2026
7675ad7
fix(flow): count a model component with no MAY_EGRESS marker as egress
abrichr Nov 21, 2026
b583ff1
fix(flow): count identity-VLM and abstaining grounder calls, ledger o…
abrichr Nov 21, 2026
8972556
fix(flow): a drift-oracle yes is a hint for the reviewer, never a pass
abrichr Nov 21, 2026
a873de8
fix(flow): pass VLM_VLLM_URL to the vLLM backend
abrichr Nov 21, 2026
74fe91b
fix(flow): refuse cleartext off-box endpoints under regulated; no fal…
abrichr Nov 21, 2026
db1f3e5
test(flow): pin the egress ledger, placement split and transport rule…
abrichr Nov 21, 2026
c5ee3d5
Merge remote-tracking branch 'origin/main' into claude/model-failclosed
abrichr Nov 21, 2026
8b0c712
docs(flow): describe the regulated transport rule, egress ledger and …
abrichr Nov 21, 2026
0b70133
refactor(flow): move per-step model-call counts out of ir.py [fail-op…
abrichr Nov 22, 2026
21e69de
Merge remote-tracking branch 'origin/main' into claude/model-failclosed
abrichr Nov 22, 2026
d872a91
refactor(flow): keep the per-step model-call counts in ir.py within i…
abrichr Nov 22, 2026
bede781
fix(flow): refuse an empty pinned model; read the regulated profile f…
abrichr Nov 22, 2026
7c770d3
fix(flow): split the receipt model-call rule by placement
abrichr Nov 22, 2026
ae517cf
fix(flow): drop undrained model-call counts when a new run binds
abrichr Nov 22, 2026
916e42b
docs: lower the replayer and ir budgets; describe the receipt and emp…
abrichr Nov 22, 2026
d10be25
docs: refresh llms-full.txt
abrichr Nov 22, 2026
94cf681
fix(flow): check a built model grounder at the URL its client sends to
abrichr Nov 22, 2026
5ed33ba
fix(flow): no ledger bound means no off-box model call
abrichr Nov 22, 2026
a57af17
docs(flow): ledger refusal when unbound; transport checked at the cli…
abrichr Nov 22, 2026
e565505
docs: mark the fail-closed model row as on a branch (#2497)
abrichr Nov 22, 2026
45a0b3a
fix(flow): open the egress ledger as a binary descriptor
abrichr Nov 22, 2026
fbbea65
test(flow): mark the resolver fuzz grounder as in process
abrichr Nov 22, 2026
41c9bbe
Merge remote-tracking branch 'origin/main' into HEAD
abrichr Nov 22, 2026
08c8abb
Merge remote-tracking branch 'origin/main' into HEAD
abrichr Nov 22, 2026
36abd6a
fix(flow): count each model send, record the real host, lazy egress r…
abrichr Nov 23, 2026
0c2e7c8
Merge remote-tracking branch 'origin/main' into HEAD
abrichr Nov 23, 2026
4b3fd41
fix(flow): keep the fail-closed row as a capabilities/ row file
abrichr Nov 23, 2026
fd5689d
fix(flow): wrap model components on every assignment, not just at init
abrichr Nov 23, 2026
ebe3a89
Merge remote-tracking branch 'origin/main' into HEAD
abrichr Nov 23, 2026
cd1a8cb
Merge remote-tracking branch 'origin/main' into HEAD
abrichr Nov 23, 2026
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
@@ -0,0 +1 @@
| Model calls fail closed: a component with no `MAY_EGRESS` marker counts as sending frames off the box and needs the egress opt-in; a model "yes" from the drift oracle is a hint for the person reviewing the halt, never a pass; identity-VLM calls count as model calls, split by placement (off-box into `model_calls`, in process into `local_model_calls`), so off-box identity crops never report no external calls; every frame sent off the box is first written to a local append-only ledger (`egress-ledger.jsonl` beside the run directory, hashes and sizes only) and is not sent if that write fails; a signed record that counts off-box model calls must say external calls were observed, while in-process calls never require it; the regulated profile refuses a cleartext appliance or grounding endpoint that is not loopback; a pinned grounding model that can't be wired, or names no model, never falls back to a default model or to the appliance | Branch ([#2497](https://github.com/OpenAdaptAI/OpenAdapt/pull/2497)) | Unit tests (`tests/test_model_failclosed.py`, `tests/test_drift_oracle.py`) | `runtime/model_egress.py`, `model_transport.py`, `model_call_evidence.py`, [ON_PREM_VLM.md](packages/flow/docs/deployment/ON_PREM_VLM.md) |
35 changes: 28 additions & 7 deletions packages/flow/docs/deployment/ON_PREM_VLM.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ unqualified**: the appliance validation measured it non-functional at native
frames are downscaled below ~1024px first) and ~12.5% false-rescue on
genuinely-ambiguous in-progress screens (a `"Saving…"` read as saved). See
[docs/LIMITS.md](../LIMITS.md) for the measured trap-set numbers before
relying on it. Because of that false-rescue rate, the replayer never asks the
oracle about a step that can change a record (see the drift-oracle entry
below).
relying on it. Because of that false-rescue rate, a "yes" never clears a
failed postcondition: it is a hint shown to the person who reviews the halt,
and the replayer doesn't ask at all about a step that can change a record (see
the drift-oracle entry below).

## Fail-safe behaviour (mandatory)

Expand Down Expand Up @@ -199,9 +200,11 @@ handles into the `Replayer`.
tier can only veto; a down appliance means more halts, never a wrong click.
- **Drift-oracle postcondition** (`RemoteStateVerifier`): after deterministic
checks and one settle retry fail, the replayer asks the verifier only about
render-drift-sensitive `text_present` and `region_stable` conditions. Only a
confident `yes` rescues the condition. A `no`, `uncertain`, error, or appliance
outage keeps the failure. Every call and rescue is recorded in the run result.
render-drift-sensitive `text_present` and `region_stable` conditions. The
answer never clears the failure: the step halts and goes to a person, and a
confident `yes` is recorded on the step (`postcondition_drift_rescues`) and
printed as a hint that the failure may be render drift. Every call is
recorded in the run result and counted as a model call.
The replayer does not ask at all on an irreversible or effect-bearing step
(the same steps the run gate treats as consequential, plus steps waiting for
risk review). There a failed check stays failed. Unless the workflow has its
Expand Down Expand Up @@ -243,7 +246,25 @@ through. Scrubbing here would **defeat the safety check**, not add safety.
3. **In-flight PHI, treated as such.** The crop is PHI moving inside the trust
boundary. Run the appliance HTTPS-only on the LAN, gate it with the bearer
token (`VLM_SERVICE_TOKEN`), and keep it inside the same network zone as the
runners.
runners. Under the `regulated` execution profile the runner enforces the
transport: it wires an appliance or a grounding model only over `https`, or
over `http` to loopback, and prints why it refused any other URL. It checks
the URL the built client sends to, including one the client library reads
from its own environment.
4. **Every frame sent off the box is on a local ledger.** Before each off-box
call the runner appends one line to `egress-ledger.jsonl` beside the run
directory (or the file `OPENADAPT_FLOW_EGRESS_LEDGER` names). The line holds
the frame's SHA-256 and size, the component, the destination host, the run,
the step and the time, and never pixels or text. The file is append-only,
mode `0600` and fsynced per line. If the line can't be written, or no
ledger is set (a replayer driven outside a run), the frame is not sent and the component gives its fail-safe answer, so the step halts.
Halted runs are on the ledger too, because each line is written when its
frame is sent.
5. **No fallback to another model.** When `grounding_model` is pinned and
can't be wired, the appliance grounder does not stand in for it. A pinned
section must name its `model`; an empty one is refused, never given a
default. The grounding rung stays off, and a target the deterministic rungs
can't resolve halts for a person.

An operator auditing the appliance should confirm no reverse proxy, WSGI, or
model-server logs the request body — that is the only way a crop could persist.
Expand Down
2 changes: 1 addition & 1 deletion packages/flow/docs/design/DECOMPOSITION.md
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ The encryption-at-rest default lowered `__main__.py`: the `at-rest` command, `--
| `packages/flow/openadapt_flow/runtime/replayer.py` | 18693 |
| `packages/flow/openadapt_flow/__main__.py` | 14237 |
| `packages/flow/openadapt_flow/qualification/__init__.py` | 4891 |
| `packages/flow/openadapt_flow/ir.py` | 6830 |
| `packages/flow/openadapt_flow/ir.py` | 6829 |
| `packages/desktop/openadapt_desktop/dispatch.py` | 6524 |
| `packages/capture/openadapt_capture/recorder.py` | 4836 |
| `packages/flow/openadapt_flow/interactive_recorder.py` | 4808 |
Expand Down
2 changes: 2 additions & 0 deletions packages/flow/import_layers.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
"openadapt_flow.form_tx.receipt",
"openadapt_flow.key_rotation",
"openadapt_flow.local_state_sources",
"openadapt_flow.model_call_evidence",
"openadapt_flow.model_transport",
"openadapt_flow.offline_seal",
"openadapt_flow.policy",
"openadapt_flow.production_qualification",
Expand Down
68 changes: 55 additions & 13 deletions packages/flow/openadapt_flow/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,8 +823,8 @@ class GroundingModelConfig(BaseModel):
#: Root URL of an ``openai_compatible`` endpoint (``/chat/completions`` is
#: appended). Required for ``openai_compatible``; ignored for ``anthropic``.
base_url: str = ""
#: The vision-capable model id to request. For ``anthropic`` an empty value
#: uses the shipped default; for ``openai_compatible`` it is required.
#: The vision-capable model id to request. Required for both providers: an
#: enabled section with no model is refused, never given a default.
model: str = ""
#: NAME of the environment variable holding the API key (never the key
#: itself). Empty => no auth header sent (a loopback vLLM/Ollama needs none);
Expand Down Expand Up @@ -1707,15 +1707,23 @@ def build_model_grounder(cfg: GroundingModelConfig) -> Optional[Any]:
api_key = os.environ.get(cfg.api_key_env, "") if cfg.api_key_env else ""

if provider == "anthropic":
from openadapt_flow.runtime.grounder import _DEFAULT_MODEL, AnthropicGrounder
from openadapt_flow.runtime.grounder import AnthropicGrounder

model = (cfg.model or "").strip() or _DEFAULT_MODEL
model = (cfg.model or "").strip()
if not model:
# A pinned grounding model must name its model: an empty value
# never silently becomes the shipped default.
print(
"grounding_model.provider 'anthropic' requires a model; "
"replaying FULLY LOCAL."
)
return None
try:
client = None
if api_key:
import anthropic

client = anthropic.Anthropic(api_key=api_key)
client = anthropic.Anthropic(api_key=api_key, max_retries=0)
return AnthropicGrounder(model=model, client=client)
except ImportError:
print(
Expand Down Expand Up @@ -1843,6 +1851,20 @@ def build_replayer(
if not ok:
print(f"PHI mode: {reason}; replaying FULLY LOCAL.")
appliance = None
# Regulated if either the authorization or the deployment names it.
regulated = "regulated" in {
getattr(governed_authorization, "execution_profile", None),
getattr(runtime_config, "profile", None),
}
if appliance is not None and regulated:
from openadapt_flow.model_transport import regulated_transport_refusal

# The URL the appliance client actually sends to.
sent_to = getattr(getattr(appliance, "client", None), "_base_url", "")
refusal = regulated_transport_refusal(sent_to or "")
if refusal is not None:
print(f"Regulated profile: {refusal}; the appliance is NOT wired.")
appliance = None
if appliance is not None:
print(
"Using on-prem VLM appliance at "
Expand Down Expand Up @@ -1875,18 +1897,38 @@ def build_replayer(
wire = False
if wire:
model_grounder = build_model_grounder(grounding_cfg)
if model_grounder is not None:
print(
"Model grounder wired: "
f"{type(model_grounder).__name__} "
f"(provider={grounding_cfg.provider}). WARNING: "
"screenshots WILL leave the box for this run."
if model_grounder is not None and (regulated or phi_on):
from openadapt_flow.model_transport import (
built_endpoint,
regulated_transport_refusal,
)

# Check the URL the built client sends to, not the config.
sent_to = built_endpoint(model_grounder)
refusal = regulated_transport_refusal(sent_to) if regulated else None
if refusal is None and phi_on:
ok, reason = phi_grounding_endpoint_allowed(
_host_of(sent_to), allowlist=allowlist, attested=attested
)
refusal = None if ok else reason
if refusal is not None:
print(f"Model grounder refused: {refusal}; replaying FULLY LOCAL.")
model_grounder = None
if model_grounder is not None:
print(
"Model grounder wired: "
f"{type(model_grounder).__name__} "
f"(provider={grounding_cfg.provider}). WARNING: "
"screenshots WILL leave the box for this run."
)

# The configured model grounder takes precedence as the VLM fallback; the
# on-prem appliance grounder is used only when no model grounder is wired.
# on-prem appliance grounder is used only when no model is pinned. A pinned
# model that can't be wired (unavailable, refused) never falls back to
# another placement or model: the grounding rung stays off and a target
# the deterministic rungs can't resolve halts for a person.
fallback = model_grounder
if fallback is None and appliance is not None:
if fallback is None and appliance is not None and not grounding_cfg.enabled:
fallback = appliance.grounder
local_model: Optional[Any] = None
if runtime_config is not None and runtime_config.local_grounding:
Expand Down
25 changes: 12 additions & 13 deletions packages/flow/openadapt_flow/ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -5168,10 +5168,9 @@ class StepResult(BaseModel):
# effects were declared with no verifier configured). None is also used for
# an explicitly approved but unverified GUI write; the separate
# ``effect_approved_unverified`` flag makes that risk acceptance visible.
# ``effect_results``
# holds one human-readable verdict line per declared effect, for the
# audit trail (mirrors the identity check's report surface). ZERO model
# calls on this path — effect verification reads the system of record.
# ``effect_results`` holds one human-readable verdict line per declared
# effect for the audit trail. ZERO model calls on this path: effect
# verification reads the system of record.
effect_verified: Optional[bool] = None
effect_approved_unverified: bool = False
# A governed identity/effect/postcondition refusal is not an ordinary
Expand All @@ -5197,12 +5196,9 @@ class StepResult(BaseModel):
"continuation_preempted",
]
] = None
# One stable, NON-secret-bearing SHA-256 digest per verified effect, taken
# AFTER the effect's ValueExpr contract was bound to THIS run's params
# (P0-3). Records THAT a parameterized run verified against its own resolved
# record/value/idempotency-key (and lets an auditor confirm two runs
# resolved differently) without persisting the underlying value (e.g. a
# patient identifier). Empty when the step declared no effects.
# One NON-secret SHA-256 digest per verified effect, taken AFTER its
# ValueExpr contract was bound to THIS run's params (P0-3): proof a run
# verified its own record/value/idempotency key, without the value.
effect_contract_hashes: list[str] = Field(default_factory=list)
# How this step's write was PERFORMED: "api" when actuated via an
# ApiBinding (GUI resolve/act skipped), None when it went through the GUI
Expand Down Expand Up @@ -5241,11 +5237,14 @@ class StepResult(BaseModel):
"as proof that settled-state detection ran."
),
)
# Drift-oracle: postconditions that deterministically FAILED but were
# confirmed by the optional on-prem VLM state-verifier under render drift
# (recorded for audit; empty unless an appliance is configured).
# Drift-oracle hints: FAILED postconditions the optional VLM state-verifier
# said hold. A hint only: they stay failed and the step halts for a person.
postcondition_drift_rescues: list[str] = Field(default_factory=list)
drift_oracle_calls: int = 0 # VLM state-verifier calls this step
# Model calls by placement (runtime.model_egress); omitted when zero.
identity_vlm_calls: int = Field(default=0, ge=0, exclude_if=lambda v: v == 0)
local_identity_vlm_calls: int = Field(default=0, ge=0, exclude_if=lambda v: v == 0)
grounder_calls: int = Field(default=0, ge=0, exclude_if=lambda v: v == 0)
#: The uniform page scale (for example 1.25 under 125% zoom) at which a
#: ``region_stable`` check found its recorded content, when it was found
#: only there. Set only when this step's own click showed the same scale.
Expand Down
39 changes: 39 additions & 0 deletions packages/flow/openadapt_flow/model_call_evidence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""The receipt rule for model calls, split by where the frame went.

A signed record's ``model_calls`` counts only calls that may have sent a frame
off the box: drift-oracle calls, off-box identity-VLM calls and off-box
grounder calls (:func:`openadapt_flow.runtime.model_egress.model_calls_off_box`).
Calls that ran in process are counted on the run report as
``local_model_calls`` and never enter ``model_calls``.

The two placements carry different rules:

* **Off the box.** Any off-box call is model evidence, and the record must say
``external_network_calls == "observed"``. A record that counts off-box calls
and says ``"none"`` is refused, so off-box identity crops can never be
reported as a run with no external calls.
* **In process.** An in-process call sends nothing over the network, so it
never requires ``"observed"`` and never makes a record with no off-box calls
claim model evidence.

The receipt (:class:`openadapt_flow.receipt.RunReceipt`) applies
:func:`model_call_evidence_error`; the terminal verification payload
checks the same two rules in its own validator.
"""

from __future__ import annotations

from collections.abc import Iterable
from typing import Optional


def model_call_evidence_error(
off_box_calls: int, evidence_classes: Iterable[str], network: str
) -> Optional[str]:
"""Why a record's off-box model-call count contradicts it, or None."""

if (off_box_calls > 0) != ("model" in set(evidence_classes)):
return "model-call count and evidence class disagree"
if off_box_calls > 0 and network != "observed":
return "model calls require observed external network calls"
return None
56 changes: 56 additions & 0 deletions packages/flow/openadapt_flow/model_transport.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""Which model endpoints a regulated run may send frames to.

Under the ``regulated`` execution profile a frame may leave the process only
over TLS (``https``), or over plain ``http`` to this machine's loopback
interface. Every other URL is refused: cleartext to another host, any other
scheme, and anything that doesn't parse.
"""

from __future__ import annotations

import ipaddress
from typing import Optional
from urllib.parse import urlsplit


def _loopback(host: str) -> bool:
if host == "localhost":
return True
try:
return ipaddress.ip_address(host).is_loopback
except ValueError:
return False


def regulated_transport_refusal(url: str) -> Optional[str]:
"""Why a regulated run must not send frames to ``url``, or None if it may."""

try:
parts = urlsplit((url or "").strip())
host = (parts.hostname or "").lower()
except ValueError:
return "the model endpoint URL does not parse"
if not host:
return "the model endpoint URL names no host"
if parts.scheme == "https":
return None
if parts.scheme == "http" and _loopback(host):
return None
if parts.scheme == "http":
return f"the model endpoint {host} is cleartext http off this machine"
return f"the model endpoint scheme {parts.scheme!r} is not https"


def built_endpoint(component: object) -> str:
"""The URL a built model client actually sends to, or ``""`` if unknown.

Reads the constructed object, not the configuration, so a URL the client
library takes from its own environment (``ANTHROPIC_BASE_URL``) is seen.
"""

for holder in (component, getattr(component, "_client", None)):
for name in ("_url", "_base_url", "base_url"):
url = getattr(holder, name, None)
if url:
return str(url)
return ""
11 changes: 7 additions & 4 deletions packages/flow/openadapt_flow/receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,13 @@ def _complete_verified_contract(self) -> "RunReceipt":
and self.effect_assurance != _ASSURANCE_BY_TIER[self.effect_tier_reached]
):
raise ValueError("effect assurance disagrees with the effect tier")
if (self.model_calls > 0) != ("model" in self.evidence_classes):
raise ValueError("model-call count and evidence class disagree")
if self.model_calls > 0 and self.external_network_calls != "observed":
raise ValueError("model calls require observed external network calls")
# ``model_calls`` is off-box calls only; in-process ones never count.
from openadapt_flow.model_call_evidence import model_call_evidence_error

if error := model_call_evidence_error(
self.model_calls, self.evidence_classes, self.external_network_calls
):
raise ValueError(error)
expected = hashlib.sha256(self.canonical_json(include_digest=False)).hexdigest()
if self.receipt_digest != expected:
raise ValueError("receipt digest does not match its canonical payload")
Expand Down
Loading