|
| 1 | +# 🚨 FIX: État Corrompu CompreFace - 1BIP |
| 2 | + |
| 3 | +## 📋 PROBLÈME ACTUEL |
| 4 | + |
| 5 | +### Vos Symptômes: |
| 6 | +``` |
| 7 | +❌ 500 (INTERNAL SERVER ERROR) - "Something went wrong, code: 0" |
| 8 | +❌ 409 (CONFLICT) × 3 - Soumissions multiples |
| 9 | +✅ 201 (SUCCESS) - Mais après plusieurs tentatives |
| 10 | +``` |
| 11 | + |
| 12 | +### Ce Qui S'est Passé: |
| 13 | + |
| 14 | +1. **Vous avez supprimé directement dans PostgreSQL**: |
| 15 | + ```sql |
| 16 | + -- ❌ PROBLÈME: Suppression manuelle |
| 17 | + DELETE FROM subject WHERE ... |
| 18 | + DELETE FROM img WHERE ... |
| 19 | + DELETE FROM embedding WHERE ... |
| 20 | + ``` |
| 21 | + |
| 22 | +2. **CompreFace garde des données en cache**: |
| 23 | + - Cache en mémoire (Redis ou interne) |
| 24 | + - Index de recherche |
| 25 | + - État interne non synchronisé |
| 26 | + - Résultat: `code: 0` = "Je ne sais pas quoi faire" |
| 27 | + |
| 28 | +3. **Mon fix n'est pas appliqué**: |
| 29 | + - Le service dashboard n'a pas été reconstruit |
| 30 | + - Résultat: 4 requêtes simultanées (500, 409, 409, 409) |
| 31 | + |
| 32 | +--- |
| 33 | + |
| 34 | +## ✅ SOLUTION COMPLÈTE |
| 35 | + |
| 36 | +### Étape 1: Redémarrer Proprement (OBLIGATOIRE) |
| 37 | + |
| 38 | +**Sur votre serveur, exécutez**: |
| 39 | + |
| 40 | +```bash |
| 41 | +cd /home/user/CompreFaceModeling |
| 42 | + |
| 43 | +# 1. Arrêter TOUS les services |
| 44 | +docker compose down |
| 45 | + |
| 46 | +# 2. Redémarrer dans le bon ordre (important!) |
| 47 | +docker compose up -d compreface-postgres-db |
| 48 | +sleep 10 # Attendre PostgreSQL |
| 49 | + |
| 50 | +docker compose up -d compreface-api |
| 51 | +sleep 15 # Attendre CompreFace (cache cleared) |
| 52 | + |
| 53 | +# 3. REBUILD dashboard avec mon fix |
| 54 | +docker compose up -d --build dashboard-service |
| 55 | + |
| 56 | +# 4. Démarrer camera |
| 57 | +docker compose up -d camera-service |
| 58 | + |
| 59 | +# 5. Vérifier |
| 60 | +docker compose ps |
| 61 | +``` |
| 62 | + |
| 63 | +**Pourquoi cet ordre?** |
| 64 | +- PostgreSQL d'abord (base de données) |
| 65 | +- CompreFace ensuite (reconstruit ses caches depuis la DB propre) |
| 66 | +- Dashboard REBUILD (applique mon fix anti-submissions multiples) |
| 67 | +- Camera en dernier (dépend de CompreFace) |
| 68 | + |
| 69 | +--- |
| 70 | + |
| 71 | +### Étape 2: Tester avec un NOUVEAU Nom |
| 72 | + |
| 73 | +**⚠️ IMPORTANT: N'UTILISEZ PLUS "mellal badr" ou "badr mellal"** |
| 74 | + |
| 75 | +CompreFace peut avoir des traces résiduelles. Utilisez un nouveau nom: |
| 76 | + |
| 77 | +``` |
| 78 | +✅ Test 1: "Ahmed Hassan" |
| 79 | +✅ Test 2: "Youssef Alami" |
| 80 | +✅ Test 3: "Mohammed Benjelloun" |
| 81 | +``` |
| 82 | + |
| 83 | +**Procédure de test**: |
| 84 | +1. Allez sur http://194.168.2.138:5000 |
| 85 | +2. Onglet "👤 Gestion du Personnel" |
| 86 | +3. Remplissez: |
| 87 | + - Nom: **"Ahmed Hassan"** (nouveau nom) |
| 88 | + - Bataillon: 10BPAG |
| 89 | + - Compagnie: Compagnie 1 |
| 90 | + - Grade: Lieutenant |
| 91 | + - Photos: 3 photos minimum |
| 92 | +4. Cliquez UNE FOIS sur "Ajouter Personnel" |
| 93 | +5. Attendez 5-10 secondes |
| 94 | + |
| 95 | +**Résultat attendu**: |
| 96 | +``` |
| 97 | +✅ Personnel "Ahmed Hassan" ajouté avec succès (3/3 photos téléchargées) |
| 98 | +``` |
| 99 | + |
| 100 | +**Dans les logs** (docker compose logs -f dashboard-service): |
| 101 | +``` |
| 102 | +INFO - Uploaded photo 1/3 for Ahmed Hassan |
| 103 | +INFO - Uploaded photo 2/3 for Ahmed Hassan |
| 104 | +INFO - Uploaded photo 3/3 for Ahmed Hassan |
| 105 | +POST /api/personnel HTTP/1.1" 201 ← Une seule requête! |
| 106 | +``` |
| 107 | + |
| 108 | +--- |
| 109 | + |
| 110 | +### Étape 3: Si Vous Voyez Encore des Problèmes |
| 111 | + |
| 112 | +#### Problème A: Encore des soumissions multiples (4 requêtes) |
| 113 | +**Cause**: Dashboard pas reconstruit correctement |
| 114 | + |
| 115 | +**Fix**: |
| 116 | +```bash |
| 117 | +docker compose stop dashboard-service |
| 118 | +docker compose rm -f dashboard-service |
| 119 | +docker compose up -d --build dashboard-service |
| 120 | + |
| 121 | +# Vérifiez la reconstruction |
| 122 | +docker compose logs dashboard-service | grep "Starting" |
| 123 | +``` |
| 124 | + |
| 125 | +#### Problème B: "Subject already exists" pour un nouveau nom |
| 126 | +**Cause**: CompreFace cache pas vidé |
| 127 | + |
| 128 | +**Fix**: |
| 129 | +```bash |
| 130 | +# Redémarrer JUSTE CompreFace (vide le cache) |
| 131 | +docker compose restart compreface-api |
| 132 | +sleep 20 |
| 133 | + |
| 134 | +# Réessayer |
| 135 | +``` |
| 136 | + |
| 137 | +#### Problème C: "Something went wrong, code: 0" persiste |
| 138 | +**Cause**: État vraiment corrompu, besoin de RESET complet |
| 139 | + |
| 140 | +**Fix NUCLÉAIRE** (⚠️ Supprime TOUTES les données): |
| 141 | +```bash |
| 142 | +cd /home/user/CompreFaceModeling |
| 143 | + |
| 144 | +# Arrêter tout |
| 145 | +docker compose down |
| 146 | + |
| 147 | +# Supprimer les volumes (⚠️ PERTE DE DONNÉES) |
| 148 | +docker volume rm comprefacemodeling_postgres-data |
| 149 | + |
| 150 | +# Tout reconstruire |
| 151 | +docker compose up -d --build |
| 152 | + |
| 153 | +# Réattendre l'initialisation complète (2-3 minutes) |
| 154 | +sleep 180 |
| 155 | +``` |
| 156 | + |
| 157 | +--- |
| 158 | + |
| 159 | +## 🔧 POURQUOI NE PAS MODIFIER DIRECTEMENT LA BASE DE DONNÉES |
| 160 | + |
| 161 | +### ❌ Ce que vous avez fait: |
| 162 | +```sql |
| 163 | +-- Suppression manuelle dans PostgreSQL |
| 164 | +DELETE FROM subject WHERE name = 'mellal badr'; |
| 165 | +DELETE FROM img WHERE subject_id = ...; |
| 166 | +DELETE FROM embedding WHERE subject_id = ...; |
| 167 | +``` |
| 168 | + |
| 169 | +### Pourquoi c'est problématique: |
| 170 | + |
| 171 | +1. **CompreFace a des couches de cache**: |
| 172 | + ``` |
| 173 | + [Application] → [Cache Redis/Mémoire] → [Index ML] → [PostgreSQL] |
| 174 | + ``` |
| 175 | + Votre suppression n'affecte que PostgreSQL, pas les autres couches. |
| 176 | + |
| 177 | +2. **Données dénormalisées**: |
| 178 | + - CompreFace garde des copies en mémoire |
| 179 | + - Index de recherche vectorielle (embeddings) |
| 180 | + - Métadonnées en cache pour performance |
| 181 | + |
| 182 | +3. **Résultat**: |
| 183 | + - CompreFace: "Le sujet existe" (cache) |
| 184 | + - PostgreSQL: "Le sujet n'existe pas" (DB) |
| 185 | + - → **Conflit** → `code: 0` (erreur incohérente) |
| 186 | + |
| 187 | +### ✅ TOUJOURS Utiliser l'API CompreFace: |
| 188 | + |
| 189 | +**Pour SUPPRIMER un personnel**: |
| 190 | +```bash |
| 191 | +# Via Dashboard (port 5000) |
| 192 | +1. Onglet "Gestion du Personnel" |
| 193 | +2. Liste du personnel |
| 194 | +3. Cliquez "🗑️ Supprimer" à côté du nom |
| 195 | +``` |
| 196 | + |
| 197 | +**Ou via API directe**: |
| 198 | +```bash |
| 199 | +curl -X DELETE \ |
| 200 | + http://194.168.2.138:8000/api/v1/recognition/subjects/mellal%20badr \ |
| 201 | + -H 'x-api-key: YOUR_API_KEY' |
| 202 | +``` |
| 203 | + |
| 204 | +Cela garantit que: |
| 205 | +- ✅ Cache vidé |
| 206 | +- ✅ Index ML mis à jour |
| 207 | +- ✅ Database nettoyée |
| 208 | +- ✅ État cohérent |
| 209 | + |
| 210 | +--- |
| 211 | + |
| 212 | +## 💡 RÉPONSE À VOTRE QUESTION |
| 213 | + |
| 214 | +> "should i add it in backend port 8000 and then modify the unit and section and other stuff from port 5000 under gestion du personnel tab?" |
| 215 | +
|
| 216 | +### Réponse Actuelle: |
| 217 | + |
| 218 | +**NON, ne faites PAS ça.** |
| 219 | + |
| 220 | +**Pourquoi?** |
| 221 | +1. Le port 5000 (Dashboard) permet déjà d'ajouter le personnel AVEC toutes les métadonnées (bataillon, compagnie, grade) |
| 222 | +2. Le port 8000 (CompreFace UI) ne connaît PAS nos métadonnées militaires (il est générique) |
| 223 | +3. Nous n'avons PAS encore d'endpoint pour MODIFIER un personnel existant |
| 224 | + |
| 225 | +**Workflow ACTUEL** (après le fix): |
| 226 | +``` |
| 227 | +1. Port 5000 → Ajouter Personnel (TOUT en une fois) |
| 228 | + ✅ Nom + Bataillon + Compagnie + Grade + Photos |
| 229 | +
|
| 230 | +2. Port 5000 → Liste Personnel (voir tout) |
| 231 | + ✅ Voir la liste complète |
| 232 | +
|
| 233 | +3. Port 5000 → Supprimer Personnel (si erreur) |
| 234 | + ✅ Bouton "🗑️ Supprimer" |
| 235 | +
|
| 236 | +4. ❌ MODIFIER → Pas encore disponible |
| 237 | +``` |
| 238 | + |
| 239 | +### Si Vous Voulez MODIFIER un Personnel: |
| 240 | + |
| 241 | +**Option 1: Supprimer + Re-créer** (Actuel) |
| 242 | +``` |
| 243 | +1. Supprimez l'ancien via Dashboard port 5000 |
| 244 | +2. Re-créez avec les bonnes infos |
| 245 | +``` |
| 246 | + |
| 247 | +**Option 2: Ajouter l'endpoint UPDATE** (Je peux le faire) |
| 248 | +``` |
| 249 | +1. Je crée un endpoint PUT /api/personnel/<name> |
| 250 | +2. Vous pourrez modifier bataillon, compagnie, grade |
| 251 | +3. Les photos restent les mêmes (ou upload de nouvelles) |
| 252 | +``` |
| 253 | + |
| 254 | +**Voulez-vous que j'ajoute l'endpoint UPDATE?** Dites-moi si c'est nécessaire. |
| 255 | + |
| 256 | +--- |
| 257 | + |
| 258 | +## 📊 CHECKLIST DE VÉRIFICATION |
| 259 | + |
| 260 | +Après avoir appliqué le fix, vérifiez: |
| 261 | + |
| 262 | +- [ ] **Redémarrage propre effectué** (ordre: postgres → compreface → dashboard rebuild → camera) |
| 263 | +- [ ] **Dashboard reconstruit** avec `--build` |
| 264 | +- [ ] **Test avec nouveau nom** (pas "mellal badr") |
| 265 | +- [ ] **Une seule requête POST** dans les logs (plus de 409 × 3) |
| 266 | +- [ ] **Code 201 SUCCESS** au premier essai |
| 267 | +- [ ] **Photos uploadées** (3/3 confirmation) |
| 268 | +- [ ] **Personnel visible** dans l'onglet Gestion du Personnel |
| 269 | + |
| 270 | +--- |
| 271 | + |
| 272 | +## 🎯 RÉSUMÉ RAPIDE |
| 273 | + |
| 274 | +### LE FIX EN 3 COMMANDES: |
| 275 | + |
| 276 | +```bash |
| 277 | +# 1. Redémarrage propre |
| 278 | +docker compose down && docker compose up -d compreface-postgres-db && sleep 10 && docker compose up -d compreface-api && sleep 15 && docker compose up -d --build dashboard-service && docker compose up -d camera-service |
| 279 | + |
| 280 | +# 2. Vérifier |
| 281 | +docker compose ps |
| 282 | + |
| 283 | +# 3. Tester avec un NOUVEAU nom (pas "mellal badr") |
| 284 | +# → http://194.168.2.138:5000 → Gestion du Personnel → Ajouter |
| 285 | +``` |
| 286 | + |
| 287 | +### CE QUI VA CHANGER: |
| 288 | + |
| 289 | +**Avant**: |
| 290 | +``` |
| 291 | +❌ Clic → 500 error + 409 × 3 → Confusion |
| 292 | +❌ Suppression manuelle DB → État corrompu |
| 293 | +``` |
| 294 | + |
| 295 | +**Après**: |
| 296 | +``` |
| 297 | +✅ Clic → 201 success immédiat (1 seule requête) |
| 298 | +✅ Suppression via Dashboard → État cohérent |
| 299 | +✅ Pas de redémarrages constants |
| 300 | +``` |
| 301 | + |
| 302 | +--- |
| 303 | + |
| 304 | +## 📞 SI ÇA NE MARCHE TOUJOURS PAS |
| 305 | + |
| 306 | +Envoyez-moi: |
| 307 | + |
| 308 | +1. **Output du redémarrage**: |
| 309 | + ```bash |
| 310 | + docker compose ps |
| 311 | + ``` |
| 312 | + |
| 313 | +2. **Logs dashboard** (dernières 50 lignes): |
| 314 | + ```bash |
| 315 | + docker compose logs --tail=50 dashboard-service |
| 316 | + ``` |
| 317 | + |
| 318 | +3. **Logs CompreFace** (dernières 50 lignes): |
| 319 | + ```bash |
| 320 | + docker compose logs --tail=50 compreface-api |
| 321 | + ``` |
| 322 | + |
| 323 | +4. **Quel nom vous avez essayé**: (assurez-vous que ce n'est PAS "mellal badr") |
| 324 | + |
| 325 | +--- |
| 326 | + |
| 327 | +**Date du Fix**: 30 octobre 2025 |
| 328 | +**Système**: 1BIP - Troupes Aéroportées - Reconnaissance Faciale |
| 329 | +**Services Affectés**: CompreFace + Dashboard |
| 330 | +**Temps Estimé**: 3-5 minutes |
| 331 | +**Impact**: Résolution complète du problème |
0 commit comments