From 9ab472ce1b38158903f7334b4bf36a9306654c0d Mon Sep 17 00:00:00 2001 From: MythEclipse Date: Fri, 12 Jun 2026 16:43:53 +0000 Subject: [PATCH 1/2] fix(ml-service): add missing status field in PredictionResponse + fix unused variable - PredictionResponse::status was missing in prediction_response() - Prefix preprocess_start with underscore for unused variable warning Co-Authored-By: Claude --- apps/ml-service/src/routes.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/ml-service/src/routes.rs b/apps/ml-service/src/routes.rs index b966918..2bc61bc 100644 --- a/apps/ml-service/src/routes.rs +++ b/apps/ml-service/src/routes.rs @@ -61,6 +61,7 @@ pub fn metadata_response(model_path: String, model_loaded: bool, input_size: u32 pub fn prediction_response(prediction: Prediction) -> PredictionResponse { PredictionResponse { + status: "ok".to_string(), label: prediction.label, confidence: prediction.confidence, probabilities: prediction.probabilities, @@ -131,7 +132,7 @@ pub async fn predict( }; // Preprocess the image - let preprocess_start = std::time::Instant::now(); + let _preprocess_start = std::time::Instant::now(); let input = preprocess_image(&bytes, state.model.input_size())?; // Record image size metric From c116a2c4a5ceee165fc810a08a2da1d123436da4 Mon Sep 17 00:00:00 2001 From: MythEclipse Date: Fri, 12 Jun 2026 17:08:27 +0000 Subject: [PATCH 2/2] fix(ml-service): test logic + prediction_response status forward - calibrate_probs_selects_top_label: use logits that produce confidence >= 0.70 - prediction_response: forward status from Prediction struct instead of hardcode Co-Authored-By: Claude --- apps/ml-service/src/model.rs | 6 ++++-- apps/ml-service/src/routes.rs | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/ml-service/src/model.rs b/apps/ml-service/src/model.rs index 90ce430..218c220 100644 --- a/apps/ml-service/src/model.rs +++ b/apps/ml-service/src/model.rs @@ -161,13 +161,15 @@ mod tests { #[test] fn calibrate_probs_selects_top_label() { - let logits = [1.0, 2.0, 3.0, 0.5]; + // [1, 2, 3, 0.5] → softmax ≈ [0.086, 0.235, 0.638, 0.040] + // 0.638 < 0.70 → "uncertain". Use larger gap for "confident". + let logits = [0.0, 0.0, 10.0, 0.0]; // softmax ≈ [0, 0, ~1, 0] let result = ModelService::calibrate_prediction(&logits, T, HIGH, LOW); assert!(result.is_ok()); let p = result.unwrap(); // Index 2 = Hawar Daun (highest logit) assert_eq!(p.label, "Hawar Daun"); - assert!(p.confidence > 0.5); + assert!(p.confidence >= 0.999); assert_eq!(p.status, "confident"); } diff --git a/apps/ml-service/src/routes.rs b/apps/ml-service/src/routes.rs index 2bc61bc..86d0818 100644 --- a/apps/ml-service/src/routes.rs +++ b/apps/ml-service/src/routes.rs @@ -61,7 +61,7 @@ pub fn metadata_response(model_path: String, model_loaded: bool, input_size: u32 pub fn prediction_response(prediction: Prediction) -> PredictionResponse { PredictionResponse { - status: "ok".to_string(), + status: prediction.status, label: prediction.label, confidence: prediction.confidence, probabilities: prediction.probabilities,