Define control-level semantics for evaluator failures and timeouts
Summary
Define control-level fail-open / fail-closed behavior at the /evaluate API boundary.
This issue proposes:
- Add a configurable Control field:
on_evaluation_error, with valuesfail_openandfail_closed. - Default
on_evaluation_errortofail_closed. - Remove evaluator-local fail-open / fail-closed fields such as
on_erroras part of a major-version migration. - Make
/evaluatereturn evaluator failures inEvaluationResponse.errorsinstead of hiding them as normal matches or non-matches. - Define
EvaluationResponse.matches[].actionandEvaluationResponse.errors[].actionas the effective action the caller should take for that result. - Keep failures visible in
EvaluationResponse.errors, even when the configured control policy fails open. - Remove
EvaluationResponse.is_safeas part of the major-version API cleanup, so callers enforce from effective actions instead of a derived boolean. - Specify compound-condition error semantics so a transient failure in one branch cannot silently weaken enforcement in a sibling.
Motivation
PR https://github.com/agentcontrol/agent-control/pull/196 surfaced this in the detect-secrets evaluator, but the issue is API-wide.
Today, several evaluators expose evaluator-local failure policy:
cisco.ai_defensegalileo.luna2yelp.detect_secrets
That makes failure behavior evaluator-specific instead of control-specific. It also forces evaluators to convert runtime failures into ordinary boolean evaluation results.
Worse, the evaluator-local policy defeats the engine's own fail-closed mechanism. The engine has a working primitive at engine/src/agent_control_engine/core.py: when an evaluator returns a non-null error, deny controls flip is_safe=False via the deny_errored path. But the three evaluators above catch their own failures and return matched=True, error=None (a fake match) when configured on_error="deny". Because error=None, the engine never sees a failure, deny_errored never fires, and the fail-closed signal flows through the match path instead of the error path. Two policy layers stack, and the upper one silently bypasses the lower one. This is a working safety primitive being short-circuited by per-evaluator config.
At the /evaluate boundary, callers need to be able to distinguish:
normal evaluation result:
the control condition matched or did not match
evaluation failure:
the control condition could not be evaluated, and the control's error policy decided the effective action
This distinction matters for enforcement, observability, debugging, SDK behavior, and composite control conditions.
Current Behavior
Evaluator failure handling is currently split across evaluator configs and generic engine error handling.
Current evaluator-local config shape:
{
"condition": {
"selector": {"path": "output"},
"evaluator": {
"name": "example.evaluator",
"config": {
"on_error": "allow"
}
}
},
"action": {"decision": "deny"}
}
Problems with this shape:
- Different evaluators can interpret
on_errordifferently. - Some failures become normal
matched=true/matched=falseresults. - Some failures become result-level errors.
- Some failures are caught only by generic engine handling.
- Response consumers cannot rely on one API-level rule for enforcement.
Target Control API
Add a configurable field to Control:
on_evaluation_error: "fail_open" | "fail_closed"
default: "fail_closed"
This is a control-level policy, not evaluator config. It tells /evaluate how to turn runtime evaluation failures into an effective response action.
Example control config:
{
"name": "Block leaked secrets",
"enabled": true,
"condition": {
"selector": {"path": "output"},
"evaluator": {
"name": "yelp.detect_secrets",
"config": {
"timeout_ms": 10000
}
}
},
"action": {"decision": "deny"},
"on_evaluation_error": "fail_closed"
}
Target /evaluate Response Contract
/evaluate should return normal matches, normal non-matches, and evaluation failures as separate response categories:
{
"matches": [],
"errors": [],
"non_matches": []
}
Response category meaning:
matches
Controls whose condition evaluated successfully and matched.
non_matches
Controls whose condition evaluated successfully and did not match.
errors
Controls whose condition could not be evaluated successfully.
For entries in matches and errors, action means the effective action the caller should take for that result:
{
"control_id": 123,
"control_name": "Block leaked secrets",
"action": "deny",
"result": {
"matched": true,
"error": null
}
}
Important distinction:
Control action config
What should happen when the control condition successfully matches.
EvaluationResponse entry action
What the caller should do for this specific /evaluate result.
Effective Action Mapping
Successful condition matches use the configured control action:
| configured control action | EvaluationResponse.matches[].action |
|---|---|
deny |
deny |
steer |
steer |
observe |
observe |
Evaluation failures use on_evaluation_error:
| configured control action | on_evaluation_error |
EvaluationResponse.errors[].action |
|---|---|---|
deny |
fail_open |
observe |
steer |
fail_open |
observe |
observe |
fail_open |
observe |
deny |
fail_closed |
deny |
steer |
fail_closed |
deny |
observe |
fail_closed |
observe |
Notes:
- Fail-open never hides the failure. The control still appears in
errors; its effective action isobserve. - Error entries should never use action
steer; evaluation failed, so there is no reliable steering guidance. - A configured
steercontrol withfail_closedshould return an error entry with actiondeny. - A configured
observecontrol should never block, even if evaluation fails. - Error entries should not carry a
steering_context; there is no reliable steering when evaluation failed.
Compound Condition Error Semantics
For compound conditions, error is the answer only when the tree is truly indeterminate. The engine should continue evaluating siblings past errors and resolve the final disposition after the full subtree has been visited.
| node | match if | non-match if | otherwise |
|---|---|---|---|
or |
any child matched | all children non-matched (no errors) | error |
and |
all children matched | any child non-matched | error |
not |
child non-matched | child matched | error (cannot invert an error) |
The current engine short-circuits on the first child error in and / or. Under fail_open this silently weakens enforcement compared to evaluating the rest of the tree. Example:
or:
- leaf A: <flaky network evaluator> # errors
- leaf B: <regex catches a credit card> # would match
Old behavior: error in leaf A short-circuits the or. Control returns in errors[] with effective action observe. Caller does not block.
New behavior: leaf B is still evaluated. The or matches. Control returns in matches[] with the configured deny action.
Short-circuit on success is preserved (an or that already saw a match does not need to evaluate the rest, and the engine's existing cancel-on-deny remains intact). The change is purely about not short-circuiting on errors.
Response Examples
Successful Match
Configured deny control, condition matches:
{
"matches": [
{
"control_id": 123,
"control_name": "Block leaked secrets",
"action": "deny",
"result": {
"matched": true,
"error": null
}
}
],
"errors": [],
"non_matches": []
}
Fail-Open Error
Configured deny control, evaluator times out, on_evaluation_error="fail_open":
{
"matches": [],
"errors": [
{
"control_id": 123,
"control_name": "Block leaked secrets",
"action": "observe",
"result": {
"matched": false,
"error": "TimeoutError: evaluator timed out"
}
}
],
"non_matches": []
}
Fail-Closed Steer Error
Configured steer control, evaluator fails, on_evaluation_error="fail_closed":
{
"matches": [],
"errors": [
{
"control_id": 456,
"control_name": "Steer unsafe output",
"action": "deny",
"result": {
"matched": false,
"error": "RuntimeError: evaluator failed"
}
}
],
"non_matches": []
}
Rationale: the API cannot return useful steering guidance when evaluation failed, so fail-closed steer becomes effective deny.
Enforcement Contract
Callers should enforce from EvaluationResponse actions.
Blocking behavior:
matches[].action == "deny" -> block
matches[].action == "steer" -> steer / block according to existing SDK behavior
matches[].action == "observe" -> do not block
errors[].action == "deny" -> block
errors[].action == "observe" -> do not block
non_matches -> do not block
As part of the same major-version API cleanup, remove EvaluationResponse.is_safe. Callers should not rely on a derived safety boolean; they should enforce from matches[] and errors[] effective actions directly.
EvaluationResult.__bool__ should be redefined in lockstep so that if result: keeps working, with a precise meaning derived from effective actions:
def __bool__(self) -> bool:
matches = self.matches or []
errors = self.errors or []
return not (
any(m.action in ("deny", "steer") for m in matches)
or any(e.action == "deny" for e in errors)
)
Document this as: "truthy iff the caller need not block on this result." Defining __bool__ in terms of effective actions (rather than a parallel is_safe boolean) eliminates the possibility of drift between the two.
Failure Cases Covered
on_evaluation_error applies to runtime evaluation failures such as:
selector evaluation failure
evaluator runtime exception
evaluator returned error result
evaluator timeout
unexpected condition evaluation failure
Invalid control definitions should still fail validation at create/update time. They should not be converted into /evaluate fail-open / fail-closed behavior.
Migration Plan
This is a major-version breaking change. The migration has three coordinated parts: schema, stored data, and runtime config validation.
Schema migration (alembic)
Add on_evaluation_error to the controls table with server_default="fail_closed":
def upgrade():
op.add_column(
"controls",
sa.Column(
"on_evaluation_error",
sa.String(),
nullable=False,
server_default="fail_closed",
),
)
Data migration
Stored controls must have on_error stripped from each leaf's evaluator config and a single on_evaluation_error value derived for the control root. Run this as a Python data migration in the same alembic revision.
For each control row:
- Walk the condition tree and collect
on_errorfrom every leaf'sevaluator.config. Treat absent as the evaluator's current default (allowfor cisco, galileo, detect_secrets). - Reduce with most-conservative-wins:
- any leaf was
deny→ controlon_evaluation_error = "fail_closed" - otherwise →
"fail_open"
- any leaf was
- Strip
on_errorfrom every leaf's evaluator config. - Write the row back.
Most-conservative is the right reduction: fail_closed is strictly safer than fail_open, and we should not silently drop signal from any leaf in a multi-leaf control.
Log every migrated row (control id, original on_error values, derived on_evaluation_error) so operators can audit edge cases — particularly multi-leaf controls with mixed on_error and rows whose evaluator config fails to parse.
Default-shift hazard
The three contrib evaluators all defaulted to on_error="allow" (effectively fail_open). The new control default is fail_closed. Without the data migration above, controls authored without an explicit on_error would silently flip from fail-open to fail-closed on schema upgrade. The data migration prevents that for existing rows; only newly authored controls (post-upgrade) get the new default. Call this out in the changelog so operators can audit whether their controls were previously relying on the implicit fail-open default.
Config validation
agent_control_models.controls.EvaluatorSpec.validate_evaluator_config calls evaluator_cls.config_model(**self.config) strictly. The instant on_error is removed from the three evaluator config models, any payload still containing on_error raises ValidationError. The data migration above ensures stored rows are clean. For raw /evaluate payloads submitted by clients, document that on_error in evaluator config is no longer accepted and must be moved to on_evaluation_error at the control root.
Value mapping (for client-side migrations)
evaluator on_error="allow" -> control on_evaluation_error="fail_open"
evaluator on_error="deny" -> control on_evaluation_error="fail_closed"
absent -> control on_evaluation_error="fail_closed" (new default)
Evaluator config models and failure paths
Remove on_error (and any related fallback fields) from:
cisco.ai_defense config
galileo.luna2 config
yelp.detect_secrets config
Audit each evaluator's failure path. The three current implementations differ:
yelp.detect_secrets: encodes failures asmatched=True/False, error=None— the worst case; the engine cannot distinguish failures from real outcomes.galileo.luna2: same pattern as detect_secrets.cisco.ai_defense: setserroronly whenon_error="allow"; underon_error="deny"it returnsmatched=True, error=None, same fake-match pattern.
After the migration, all three must surface failures by setting EvaluatorResult.error and never encode failures as matched=True/False. The engine and on_evaluation_error policy take it from there.
New evaluators should not introduce evaluator-local failure policy.
SDK Coordination
The engine, Python SDK, and TypeScript SDK must release together. Today's SDK enforcement (sdks/python/src/agent_control/integrations/_core.py:69, sdks/python/src/agent_control/control_decorators.py:506) raises on any errors[] entry, regardless of action — which is the wrong behavior under the new contract for observe controls and for fail_open errors. A split deploy where the engine surfaces non-blocking observe-errors but an old SDK still raises would silently regress callers' enforcement behavior between versions.
Implementation Checklist
Public API / Models
- Add configurable Control field
on_evaluation_errorwith valuesfail_openandfail_closed. - Default
on_evaluation_errortofail_closed. - Document
EvaluationResponse.matches[].actionandEvaluationResponse.errors[].actionas effective response actions. - Remove
EvaluationResponse.is_safe. - Redefine
EvaluationResult.__bool__in terms of effective actions per the snippet above. - Ensure
errors[]entries do not carry asteering_context(effective steering is impossible after a failed evaluation). - Regenerate OpenAPI / SDK models as needed.
/evaluate Behavior
- Route successful matching controls to
matches. - Route successful non-matching controls to
non_matches. - Route evaluation failures to
errors. - Apply the effective action mapping above to entries in
matchesanderrors. - Implement compound-condition semantics per the table above (do not short-circuit on errors; only short-circuit on success).
- Keep failed-open controls in
errors; do not convert them into clean non-matches. - Remove
EvaluationResponse.is_safeas part of the major-version cleanup tracked in issue https://github.com/agentcontrol/agent-control/issues/201.
Migration
- Alembic revision: add
on_evaluation_errorcolumn withserver_default="fail_closed". - Same revision: data migration walking each control row, deriving
on_evaluation_errorper the most-conservative-wins reduction, and strippingon_errorfrom all leaf evaluator configs. - Changelog note covering the default-shift hazard.
- Migration log of per-row decisions for ops audit.
SDKs
- Enforce using
EvaluationResponse.matches[].actionandEvaluationResponse.errors[].action. - Stop treating every
EvaluationResponse.errorsentry as blocking. - Treat
errors[action="observe"]as non-blocking but still visible to callers. - Treat
errors[action="deny"]as blocking. - Update
EvaluationResult.__bool__consumers; removeis_safereferences. - Ship engine, Python SDK, and TypeScript SDK in lockstep — no split-deploy window.
Evaluators
- Remove evaluator-local
on_errorfields as part of the major-version migration. - Rewrite each contrib evaluator's failure path to set
EvaluatorResult.erroron failures and never encode failures asmatched=True/False. - New evaluators must not introduce evaluator-local failure policy.
Observability
- Count evaluator failures as failures regardless of effective action.
- Include effective action as an action dimension where applicable.
- A fail-open error should be observable as both:
- an error event
- effective action
observe
Test Plan
Effective action matrix:
fail_open + configured deny -> errors[action=observe], non-blocking
fail_open + configured steer -> errors[action=observe], non-blocking
fail_open + configured observe -> errors[action=observe], non-blocking
fail_closed + configured deny -> errors[action=deny], blocking
fail_closed + configured steer -> errors[action=deny], blocking
fail_closed + configured observe -> errors[action=observe], non-blocking
Normal response categories:
successful match -> matches[]
successful non-match -> non_matches[]
evaluation failure -> errors[]
fail-open failure -> errors[], not non_matches[]
fail-closed failure -> errors[], not matches[]
Failure source cases:
evaluator raises exception -> errors[] with policy-applied action
evaluator returns error result -> errors[] with policy-applied action
evaluator times out -> errors[] with policy-applied action
selector evaluation fails -> errors[] with policy-applied action
compound condition cannot be evaluated due to failure -> errors[] with policy-applied action
Compound condition semantics:
or with [error, match] -> matches[] (match wins)
or with [error, non_match] -> errors[] (indeterminate)
or with [error, error] -> errors[]
and with [error, non_match] -> non_matches[] (non_match wins)
and with [error, match] -> errors[] (indeterminate)
and with [error, error] -> errors[]
not(error) -> errors[]
SDK enforcement cases:
matches[action=deny] blocks
matches[action=steer] steers/blocks according to existing SDK behavior
matches[action=observe] does not block
errors[action=deny] blocks
errors[action=observe] does not block
non_matches never block
Migration cases:
old evaluator config with on_error is migrated to control on_evaluation_error
multi-leaf control with mixed on_error values reduces to most-conservative-wins
old evaluator config with on_error in raw /evaluate payloads is rejected
new root on_evaluation_error defaults to fail_closed
OpenAPI includes on_evaluation_error
SDK generated models include on_evaluation_error
EvaluationResult.__bool__ derives from effective actions
Open Questions
- Until issue https://github.com/agentcontrol/agent-control/issues/201 removes confidence, how should
EvaluationResponse.confidencetreat failed-open errors? Proposed:0.0for entries inerrors[]regardless of effective action, since no successful evaluation occurred.
Related Work
- PR that surfaced the issue: https://github.com/agentcontrol/agent-control/pull/196
- Related major API cleanup issue: https://github.com/agentcontrol/agent-control/issues/201
Relevant code:
engine/src/agent_control_engine/core.py
models/src/agent_control_models/controls.py
models/src/agent_control_models/evaluation.py
sdks/python/src/agent_control/evaluation.py
sdks/python/src/agent_control/integrations/_core.py
sdks/python/src/agent_control/control_decorators.py
Evaluator configs to migrate:
evaluators/contrib/detect_secrets/src/agent_control_evaluator_detect_secrets/detect_secrets/evaluator.py
evaluators/contrib/cisco/src/agent_control_evaluator_cisco/ai_defense/evaluator.py
evaluators/contrib/galileo/src/agent_control_evaluator_galileo/luna2/evaluator.py
Evaluator timeouts are the moment governance gets real. A system has to be honest about whether it stopped something, allowed it, or simply could not decide in time. Anything else looks safe right up until it isn't.
We're working through the same question in MartinLoop for autonomous coding runs. The useful output is not a vague pass/fail; it is a clear receipt of the policy decision, the failure mode, and what the human should do next. It keeps a retriable interruption from being mistaken for a clean result, and it keeps a risky unknown from slipping through as success.
I would love to hear where you land on fail-open versus fail-closed for different evaluator classes. MartinLoop is open source: https://github.com/Keesan12/martin-loop. Thoughts are welcome here or at [email protected].
ran the current behavior on main (a77589b) against the plan before this lands. three things that look worth folding into the migration:
1. allow -> fail_open keeps the label but loosens what people actually get today
on main, a deny control with a cisco leaf on on_error="allow" (which is also the default) doesn't fail open in practice. the evaluator sets error, the engine flips is_safe=False via deny_errored, and both sdk paths (_evaluate_and_enforce in integrations/_core.py, _handle_evaluation_result in control_decorators.py) raise on any errors[] entry. so it blocks:
deny + cisco(on_error=allow), evaluator raises -> is_safe=False, errors=[c], blocks
with the proposed mapping that becomes fail_open -> errors[action=observe] -> doesn't block. matches what allow was supposed to mean, but it's a loosening vs observed behavior, so kind of the inverse of the "default-shift hazard" section. either derive the migrated value from the control action (deny/steer -> fail_closed) or flag it in the changelog as a weakening, not a no-op.
same for the compound example btw: today or: [<erroring leaf>, <regex that matches>] on a deny control short-circuits into errors[] with is_safe=False and the sdk blocks. the "old behavior: caller does not block" line is really the post-migration fail_open path, not what ships now.
2. the fake match is polarity-blind, so not turns fail-closed into a silent allow
on_error="deny" encodes failure as matched=True, error=None, which only means deny at positive polarity. wrap it in not and it inverts into a clean non-match:
deny + not(cisco(on_error=deny)), evaluator raises
-> is_safe=True, matches=[], errors=[], non_matches=[c]
nothing in errors[], so the sdk's errors-first check never sees it. the target semantics already cover this ("cannot invert an error"), but probably worth an explicit case in the test plan, both compound and migration: not(failing leaf with on_error=deny) -> errors[action=deny].
3. dropping is_safe (#201) gives the old python decorator a false allow, not a false block
_handle_evaluation_result does result.get("is_safe", True) and only looks at deny/steer matches inside if not is_safe. against a server that stops sending it:
{"is_safe": false, "matches": [deny]} -> ControlViolationError
{"matches": [deny]} -> no raise, runs
{} -> no raise, runs
the sdk coordination section covers the false-block direction (old sdk raising on observe errors), this is the nastier one. options: keep is_safe on the wire for one major, derived from effective actions, or version the response contract and have sdks fail closed on an unknown version. integrations going through _action_error read matches directly so they're fine.
small aside, the evaluator list looks partly stale: galileo.luna (not luna2 anymore) already returns matched=False, error=... with no on_error, and yelp.detect_secrets isn't in evaluators/contrib yet. cisco is the only fake-match path left that i could find.
since the effective-action mapping is a pure function of (control action, on_evaluation_error, leaf outcomes, tree shape), it pins down nicely with frozen vectors that the engine + python sdk + ts sdk all run. that'd make "ship in lockstep" something ci checks instead of a convention. happy to put a vector set together if that's useful.