fix(ai): bind model scope to immutable geometry
GeoIntel release gates / Compile, test, contracts and builds (push) Canceled after 0s
GeoIntel release gates / Python and npm vulnerability policy (push) Canceled after 0s
GeoIntel release gates / GIS image, SBOM and container scan (push) Canceled after 0s

This commit is contained in:
Jens
2026-08-09 10:54:52 +02:00
parent f41392a415
commit b76cd1837b
19 changed files with 431 additions and 58 deletions
+20 -5
View File
@@ -22,6 +22,7 @@ from app.services.detection_qa_service import DetectionQaService
from app.services.dataset_consumption_gate_service import DatasetConsumptionGate
from app.services.model_asset_catalog_service import ModelAssetCatalogService
from app.services.model_registry_service import ModelRegistryService
from app.services.model_validation_scope_service import ModelValidationScopeService
from app.services.qa_service import QaService
from app.services.quality_service import QualityService
from app.services.runtime_model_provenance_service import RuntimeModelProvenance, RuntimeModelProvenanceService
@@ -235,16 +236,30 @@ class DetectionService:
@staticmethod
def _validate_model_area_scope(db, dataset: Dataset, settings: Settings) -> None:
allowed_names = [value.strip().casefold() for value in settings.yolo_validated_area_names.split(",") if value.strip()]
area = db.get(Area, dataset.area_id) if dataset.area_id else None
area_name = area.name.strip() if area is not None else ""
if not area_name or not any(token in area_name.casefold() for token in allowed_names):
if area is None or area.geometry is None:
raise AppError(
code="DETECTION_VALIDATION_SCOPE_UNAVAILABLE",
message="Configured YOLO inference is not validated for this Dataset area.",
details={"dataset_id": str(dataset.id), "dataset_area": area_name or None, "validated_area_names": allowed_names},
message="Configured YOLO inference requires a persisted Dataset area geometry.",
details={"dataset_id": str(dataset.id)},
status_code=422,
)
try:
area_geometry = to_shape(area.geometry)
except Exception as exc:
raise AppError(
code="DETECTION_VALIDATION_SCOPE_UNAVAILABLE",
message="The persisted Dataset area geometry cannot be validated for model inference.",
details={"dataset_id": str(dataset.id), "error_type": type(exc).__name__},
status_code=422,
) from exc
ModelValidationScopeService.assert_area_covered(
area_geometry=area_geometry,
manifest_path=settings.yolo_validation_scope_manifest_path,
expected_manifest_sha256=settings.yolo_validation_scope_manifest_sha256,
model_id=settings.yolo_model_id,
model_path=settings.yolo_model_path,
)
@staticmethod
def _fail_run_after_exception(db, analysis_run: AnalysisRun, job: Job, exc: Exception, fallback_code: str) -> None:
try: