orchestrata_ultimate.verification.impossibility.handler
Reference › orchestrata_ultimate › verification › impossibility › handler
ImpossibilityHandler finds constraints that can never be met, so the pipeline can report that instead of retrying. detect_contradictions groups constraints by predicate and reports each pair that disagrees as a tuple of the two ids and a reason; a pair is contradictory when both are performance constraints, or both are quality constraints, with different numeric expected values. detect_impossible reports single constraints that cannot hold: a performance target of zero or less, or a quality percentage above 100. The handler is stateless and has no importers inside the package. Types are in types.
At a glance
| Source | src/orchestrata_ultimate/verification/impossibility/handler.py |
| Lines of code | 91 |
| Classes | 1 |
| Functions | 0 |
| Imports (internal) | orchestrata_ultimate.core.base.traces, orchestrata_ultimate.verification.types |
| Imported by | none |
| Tests that import it | tests/generated_recovery/test_verification_impossibility_handler.py, tests/verification/impossibility/test_handler.py, tests/verification/test_impossibility_handler.py, tests/verification/test_integrations_session_config.py, tests/verification/test_small_modules.py |
Class diagram
Dependency diagram
API
Classes
ImpossibilityHandler
Decorators: traces(spec='035', story='US-001', reqs=['REQ-035-US-001-001']) · Line 14
Detects and handles impossible or contradictory constraints.
| Method | Signature | Summary |
|---|---|---|
detect_contradictions |
detect_contradictions(constraints: list[Constraint]) -> list[tuple[str, str, str]] |
Detect contradictory constraints. |
detect_impossible |
detect_impossible(constraints: list[Constraint]) -> list[tuple[str, str]] |
Detect individually impossible constraints. |
_are_contradictory |
_are_contradictory(c1: Constraint, c2: Constraint) -> bool |
Check if two constraints with the same predicate are contradictory. |
_check_impossible |
_check_impossible(constraint: Constraint) -> str |
Check if a single constraint is impossible. |
Source
"""Impossibility detection and handling."""
# Spec: 035 - Verification Agent
import logging
from orchestrata_ultimate.core.base.traces import traces
from orchestrata_ultimate.verification.types import Constraint, ConstraintType
logger = logging.getLogger(__name__)
@traces(spec="035", story="US-001", reqs=["REQ-035-US-001-001"])
class ImpossibilityHandler:
"""Detects and handles impossible or contradictory constraints."""
def detect_contradictions(
self, constraints: list[Constraint]
) -> list[tuple[str, str, str]]:
"""Detect contradictory constraints.
Returns list of (constraint_id_1, constraint_id_2, reason).
"""
contradictions = []
by_predicate: dict[str, list[Constraint]] = {}
for c in constraints:
by_predicate.setdefault(c.predicate, []).append(c)
for predicate, group in by_predicate.items():
if len(group) < 2:
continue
for i, c1 in enumerate(group):
for c2 in group[i + 1 :]:
if self._are_contradictory(c1, c2):
contradictions.append(
(
c1.id,
c2.id,
f"Contradictory values for '{predicate}': {c1.expected} vs {c2.expected}",
)
)
return contradictions
def detect_impossible(self, constraints: list[Constraint]) -> list[tuple[str, str]]:
"""Detect individually impossible constraints.
Returns list of (constraint_id, reason).
"""
impossible = []
for c in constraints:
reason = self._check_impossible(c)
if reason:
impossible.append((c.id, reason))
return impossible
def _are_contradictory(self, c1: Constraint, c2: Constraint) -> bool:
"""Check if two constraints with the same predicate are contradictory."""
if c1.expected is None or c2.expected is None:
return False
if (
c1.type == ConstraintType.PERFORMANCE
and c2.type == ConstraintType.PERFORMANCE
):
return (
isinstance(c1.expected, (int, float))
and isinstance(c2.expected, (int, float))
and c1.expected != c2.expected
)
if c1.type == ConstraintType.QUALITY and c2.type == ConstraintType.QUALITY:
return (
isinstance(c1.expected, (int, float))
and isinstance(c2.expected, (int, float))
and c1.expected != c2.expected
)
return False
def _check_impossible(self, constraint: Constraint) -> str:
"""Check if a single constraint is impossible."""
if constraint.type == ConstraintType.PERFORMANCE:
if (
isinstance(constraint.expected, (int, float))
and constraint.expected <= 0
):
return f"Impossible performance target: {constraint.expected}"
if constraint.type == ConstraintType.QUALITY:
if (
isinstance(constraint.expected, (int, float))
and constraint.expected > 100
):
return f"Impossible quality percentage: {constraint.expected}"
return ""