fix: P0+P1 audit — memory leak, hardcoded camera/GPS, lifespan init, background processing, batch validation, ABC interfaces

This commit is contained in:
Yuzviak
2026-03-22 23:35:12 +02:00
parent 8649d13a78
commit ca327034c0
9 changed files with 161 additions and 38 deletions
+17 -3
View File
@@ -23,6 +23,7 @@ from gps_denied.schemas.flight import (
BatchMetadata,
BatchResponse,
BatchUpdateResponse,
CameraParameters,
DeleteResponse,
FlightCreateRequest,
FlightDetailResponse,
@@ -76,6 +77,7 @@ class FlightProcessor:
# Per-flight processing state
self._flight_states: dict[str, TrackingState] = {}
self._prev_images: dict[str, np.ndarray] = {} # previous frame cache
self._flight_cameras: dict[str, CameraParameters] = {} # per-flight camera
# Lazy-initialised component references (set via `attach_components`)
self._vo = None # SequentialVisualOdometry
@@ -130,11 +132,10 @@ class FlightProcessor:
vo_ok = False
if self._vo and flight_id in self._prev_images:
try:
from gps_denied.schemas.flight import CameraParameters
cam = CameraParameters(
cam = self._flight_cameras.get(flight_id, CameraParameters(
focal_length=4.5, sensor_width=6.17, sensor_height=4.55,
resolution_width=640, resolution_height=480,
)
))
rel_pose = self._vo.compute_relative_pose(
self._prev_images[flight_id], image, cam
)
@@ -246,6 +247,9 @@ class FlightProcessor:
altitude=req.altitude,
camera_params=req.camera_params.model_dump(),
)
# P0#2: Store camera params for process_frame VO calls
self._flight_cameras[flight.id] = req.camera_params
for poly in req.geofences.polygons:
await self.repository.insert_geofence(
flight.id,
@@ -308,8 +312,18 @@ class FlightProcessor:
async def delete_flight(self, flight_id: str) -> DeleteResponse:
deleted = await self.repository.delete_flight(flight_id)
# P0#1: Cleanup in-memory state to prevent memory leaks
self._cleanup_flight(flight_id)
return DeleteResponse(deleted=deleted, flight_id=flight_id)
def _cleanup_flight(self, flight_id: str) -> None:
"""Remove all in-memory state for a flight (prevents memory leaks)."""
self._prev_images.pop(flight_id, None)
self._flight_states.pop(flight_id, None)
self._flight_cameras.pop(flight_id, None)
if self._graph:
self._graph.delete_flight_graph(flight_id)
async def update_waypoint(
self, flight_id: str, waypoint_id: str, waypoint: Waypoint
) -> UpdateResponse: