Enhance .env loading mechanism and EdgeDTO creation with error handling
Deploy mindnet to llm-node / deploy (push) Successful in 4s
Deploy mindnet to llm-node / deploy (push) Successful in 4s
- Updated the .env loading process to first check for an explicit path, improving reliability in different working directories. - Added logging for successful .env loading and fallback mechanisms. - Enhanced EdgeDTO creation with robust error handling, including fallbacks for unsupported provenance values and logging of errors for better traceability.
This commit is contained in:
1 parent
df5f9b3fe4
commit
6d268d9dfb
7 files changed
+620
-12
No files matched your search
@@ -0,0 +1,105 @@
|
||||
# Debug: .env-Lade-Problem in Prod
|
||||
|
||||
**Datum**: 2026-01-12
|
||||
**Version**: v4.5.10
|
||||
**Status**: 🔴 Kritisch
|
||||
|
||||
## Problem
|
||||
|
||||
Möglicherweise wird die `.env`-Datei in Prod nicht korrekt geladen, was zu:
|
||||
- Falschen Log-Levels (DEBUG=true wird ignoriert)
|
||||
- Falschen Collection-Präfixen
|
||||
- Falschen Konfigurationen
|
||||
führen kann.
|
||||
|
||||
## Diagnose
|
||||
|
||||
### Schritt 1: Prüfe, ob .env-Datei existiert
|
||||
|
||||
```bash
|
||||
# In Prod
|
||||
cd ~/mindnet
|
||||
ls -la .env
|
||||
cat .env | head -20
|
||||
```
|
||||
|
||||
### Schritt 2: Prüfe Arbeitsverzeichnis beim Start
|
||||
|
||||
```bash
|
||||
# In Prod - prüfe, von wo uvicorn gestartet wird
|
||||
ps aux | grep uvicorn
|
||||
# Oder in systemd service:
|
||||
cat /etc/systemd/system/mindnet.service | grep WorkingDirectory
|
||||
```
|
||||
|
||||
### Schritt 3: Verifikations-Script ausführen
|
||||
|
||||
```bash
|
||||
# In Prod
|
||||
cd ~/mindnet
|
||||
source .venv/bin/activate
|
||||
python3 scripts/verify_env_loading.py
|
||||
```
|
||||
|
||||
**Erwartete Ausgabe**:
|
||||
```
|
||||
✅ .env geladen von: /path/to/mindnet/.env
|
||||
✅ COLLECTION_PREFIX = mindnet
|
||||
✅ DEBUG = true
|
||||
```
|
||||
|
||||
### Schritt 4: Manuelle Verifikation
|
||||
|
||||
```python
|
||||
# In Python-REPL in Prod
|
||||
import os
|
||||
from pathlib import Path
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Prüfe aktuelles Verzeichnis
|
||||
print(f"CWD: {Path.cwd()}")
|
||||
print(f"Projekt-Root: {Path(__file__).parent.parent.parent}")
|
||||
|
||||
# Lade .env
|
||||
env_file = Path(".env")
|
||||
if env_file.exists():
|
||||
load_dotenv(env_file, override=True)
|
||||
print(f"✅ .env geladen: {env_file.absolute()}")
|
||||
else:
|
||||
print(f"❌ .env nicht gefunden in: {env_file.absolute()}")
|
||||
|
||||
# Prüfe kritische Variablen
|
||||
print(f"DEBUG: {os.getenv('DEBUG', 'NICHT GESETZT')}")
|
||||
print(f"COLLECTION_PREFIX: {os.getenv('COLLECTION_PREFIX', 'NICHT GESETZT')}")
|
||||
```
|
||||
|
||||
## Mögliche Ursachen
|
||||
|
||||
### 1. Arbeitsverzeichnis-Problem
|
||||
- **Problem**: uvicorn wird aus einem anderen Verzeichnis gestartet
|
||||
- **Lösung**: Expliziter Pfad in `config.py` (bereits implementiert)
|
||||
|
||||
### 2. .env-Datei nicht im Projekt-Root
|
||||
- **Problem**: .env liegt in `config/prod.env` statt `.env`
|
||||
- **Lösung**: Symlink erstellen oder Pfad anpassen
|
||||
|
||||
### 3. Systemd-Service ohne WorkingDirectory
|
||||
- **Problem**: Service startet ohne korrektes Arbeitsverzeichnis
|
||||
- **Lösung**: `WorkingDirectory=/path/to/mindnet` in systemd service
|
||||
|
||||
### 4. Mehrere .env-Dateien
|
||||
- **Problem**: Es gibt `.env`, `prod.env`, `config/prod.env` - welche wird geladen?
|
||||
- **Lösung**: Expliziter Pfad oder Umgebungsvariable `DOTENV_PATH`
|
||||
|
||||
## Fix-Implementierung
|
||||
|
||||
Der Code in `app/config.py` wurde erweitert:
|
||||
- ✅ Expliziter Pfad für `.env` im Projekt-Root
|
||||
- ✅ Fallback auf automatische Suche
|
||||
- ✅ Debug-Logging (wenn verfügbar)
|
||||
|
||||
## Verifikation nach Fix
|
||||
|
||||
1. **Log prüfen**: Sollte `✅ .env geladen von: ...` zeigen
|
||||
2. **Umgebungsvariablen prüfen**: `echo $DEBUG`, `echo $COLLECTION_PREFIX`
|
||||
3. **Settings prüfen**: `python3 -c "from app.config import get_settings; s = get_settings(); print(f'DEBUG: {s.DEBUG}, PREFIX: {s.COLLECTION_PREFIX}')"`
|
||||
@@ -0,0 +1,134 @@
|
||||
# Deployment-Checkliste: Prod vs. Dev Retrieval-Problem
|
||||
|
||||
**Datum**: 2026-01-12
|
||||
**Version**: v4.5.10
|
||||
**Status**: 🔴 Kritisch
|
||||
|
||||
## Problem
|
||||
|
||||
Prod-System findet keine Suchergebnisse, während Dev-System korrekt funktioniert. Identischer Code, identische Daten.
|
||||
|
||||
## Identifizierte Ursachen
|
||||
|
||||
### 1. 🔴 **KRITISCH: Alte EdgeDTO-Version in Prod**
|
||||
|
||||
**Symptom**:
|
||||
```
|
||||
ERROR: 1 validation error for EdgeDTO
|
||||
provenance
|
||||
Input should be 'explicit', 'rule', 'smart' or 'structure'
|
||||
[type=literal_error, input_value='explicit:callout', input_type=str]
|
||||
```
|
||||
|
||||
**Ursache**:
|
||||
- Prod verwendet eine **alte Version** des `EdgeDTO`-Modells aus `app/models/dto.py`
|
||||
- Die alte Version unterstützt nur: `"explicit", "rule", "smart", "structure"`
|
||||
- Die neue Version (v4.5.3+) unterstützt: `"explicit:callout", "explicit:wikilink", "explicit:note_zone", ...`
|
||||
|
||||
**Lösung**:
|
||||
- ✅ Code in `dto.py` ist bereits korrekt (Zeile 51-56)
|
||||
- ⚠️ **Prod muss neu gestartet werden**, um die neue Version zu laden
|
||||
- ⚠️ **Python-Modul-Cache leeren** falls nötig: `find . -type d -name __pycache__ -exec rm -r {} +`
|
||||
|
||||
### 2. ✅ Collection-Präfix korrekt
|
||||
|
||||
- Prod: `COLLECTION_PREFIX=mindnet` → `mindnet_chunks` ✅
|
||||
- Dev: `COLLECTION_PREFIX=mindnet_dev` → `mindnet_dev_chunks` ✅
|
||||
- **Kein Problem hier**
|
||||
|
||||
## Sofortmaßnahmen
|
||||
|
||||
### Schritt 1: Code-Verifikation in Prod
|
||||
|
||||
```bash
|
||||
# In Prod-System
|
||||
cd /path/to/mindnet
|
||||
grep -A 10 "provenance.*Literal" app/models/dto.py
|
||||
```
|
||||
|
||||
**Erwartete Ausgabe**:
|
||||
```python
|
||||
provenance: Optional[Literal[
|
||||
"explicit", "rule", "smart", "structure",
|
||||
"explicit:callout", "explicit:wikilink", "explicit:note_zone", ...
|
||||
]] = "explicit"
|
||||
```
|
||||
|
||||
**Falls nicht vorhanden**: Code ist nicht aktualisiert → Deployment erforderlich
|
||||
|
||||
### Schritt 2: Python-Cache leeren
|
||||
|
||||
```bash
|
||||
# In Prod-System
|
||||
find . -type d -name __pycache__ -exec rm -r {} +
|
||||
find . -name "*.pyc" -delete
|
||||
```
|
||||
|
||||
### Schritt 3: Service neu starten
|
||||
|
||||
```bash
|
||||
# FastAPI/uvicorn neu starten
|
||||
# Oder Docker-Container neu starten
|
||||
```
|
||||
|
||||
### Schritt 4: Verifikation
|
||||
|
||||
1. **Test-Query ausführen**:
|
||||
```bash
|
||||
curl -X POST http://localhost:8001/api/chat \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"message": "Was für einen Status hat das Projekt mindnet?"}'
|
||||
```
|
||||
|
||||
2. **Log prüfen**:
|
||||
- ✅ Keine `validation error for EdgeDTO` mehr
|
||||
- ✅ `✨ [SUCCESS] Stream 'facts_stream' lieferte X Treffer.`
|
||||
- ✅ Ergebnisse werden zurückgegeben
|
||||
|
||||
## Code-Vergleich
|
||||
|
||||
### Aktuelle Version (sollte in Prod sein):
|
||||
|
||||
```python
|
||||
# app/models/dto.py (Zeile 51-56)
|
||||
provenance: Optional[Literal[
|
||||
"explicit", "rule", "smart", "structure",
|
||||
"explicit:callout", "explicit:wikilink", "explicit:note_zone", "explicit:note_scope",
|
||||
"inline:rel", "callout:edge", "semantic_ai", "structure:belongs_to", "structure:order",
|
||||
"derived:backlink", "edge_defaults", "global_pool"
|
||||
]] = "explicit"
|
||||
```
|
||||
|
||||
### Alte Version (verursacht Fehler):
|
||||
|
||||
```python
|
||||
# Alte Version (nur 4 Werte)
|
||||
provenance: Optional[Literal[
|
||||
"explicit", "rule", "smart", "structure"
|
||||
]] = "explicit"
|
||||
```
|
||||
|
||||
## Weitere mögliche Ursachen (wenn Fix nicht hilft)
|
||||
|
||||
### 1. Unterschiedliche Python-Versionen
|
||||
- Prüfen: `python --version` in Dev vs. Prod
|
||||
- Pydantic-Verhalten kann zwischen Versionen variieren
|
||||
|
||||
### 2. Unterschiedliche Pydantic-Versionen
|
||||
- Prüfen: `pip list | grep pydantic` in Dev vs. Prod
|
||||
- `requirements.txt` sollte identisch sein
|
||||
|
||||
### 3. Unterschiedliche Embedding-Modelle
|
||||
- Prüfen: `MINDNET_EMBEDDING_MODEL` in beiden Systemen
|
||||
- **Beide verwenden**: `nomic-embed-text` ✅
|
||||
|
||||
### 4. Unterschiedliche Vektor-Dimensionen
|
||||
- Prüfen: `VECTOR_DIM` in beiden Systemen
|
||||
- **Beide verwenden**: `768` ✅
|
||||
|
||||
## Erwartetes Ergebnis nach Fix
|
||||
|
||||
- ✅ Keine Pydantic-Validierungsfehler mehr
|
||||
- ✅ Alle Streams liefern Ergebnisse
|
||||
- ✅ Retrieval funktioniert identisch in Dev und Prod
|
||||
- ✅ `explicit:callout` Provenance wird korrekt akzeptiert
|
||||
@@ -0,0 +1,134 @@
|
||||
# Fix: Python-Modul-Cache-Problem in Prod
|
||||
|
||||
**Datum**: 2026-01-12
|
||||
**Version**: v4.5.10
|
||||
**Status**: 🔴 Kritisch
|
||||
|
||||
## Problem
|
||||
|
||||
Code in `app/models/dto.py` ist korrekt (enthält `explicit:callout`), aber Prod verwendet trotzdem eine alte Version.
|
||||
|
||||
**Symptom**:
|
||||
```
|
||||
ERROR: 1 validation error for EdgeDTO
|
||||
provenance
|
||||
Input should be 'explicit', 'rule', 'smart' or 'structure'
|
||||
[type=literal_error, input_value='explicit:callout', input_type=str]
|
||||
```
|
||||
|
||||
## Ursache
|
||||
|
||||
**Python-Modul-Cache**: Python speichert kompilierte `.pyc` Dateien in `__pycache__` Verzeichnissen. Wenn der Code aktualisiert wird, aber der Service nicht neu gestartet wird, lädt Python die alte gecachte Version.
|
||||
|
||||
## Sofortmaßnahmen
|
||||
|
||||
### Schritt 1: Python-Cache leeren
|
||||
|
||||
```bash
|
||||
# In Prod-System
|
||||
cd ~/mindnet
|
||||
|
||||
# Finde und lösche alle __pycache__ Verzeichnisse
|
||||
find . -type d -name __pycache__ -exec rm -r {} + 2>/dev/null || true
|
||||
|
||||
# Finde und lösche alle .pyc Dateien
|
||||
find . -name "*.pyc" -delete
|
||||
|
||||
# Speziell für dto.py
|
||||
rm -rf app/models/__pycache__
|
||||
rm -rf app/__pycache__
|
||||
rm -rf __pycache__
|
||||
```
|
||||
|
||||
### Schritt 2: Verifikation des Codes
|
||||
|
||||
```bash
|
||||
# Prüfe, ob der Code korrekt ist
|
||||
grep -A 10 "provenance.*Literal" app/models/dto.py | grep "explicit:callout"
|
||||
```
|
||||
|
||||
**Erwartete Ausgabe**: Sollte `explicit:callout` enthalten
|
||||
|
||||
### Schritt 3: Service neu starten
|
||||
|
||||
**Option A: FastAPI/uvicorn direkt**:
|
||||
```bash
|
||||
# Service stoppen (Ctrl+C oder kill)
|
||||
# Dann neu starten
|
||||
source .venv/bin/activate
|
||||
uvicorn app.main:app --host 0.0.0.0 --port 8001 --reload
|
||||
```
|
||||
|
||||
**Option B: Systemd-Service**:
|
||||
```bash
|
||||
sudo systemctl restart mindnet-prod
|
||||
# oder
|
||||
sudo systemctl restart mindnet
|
||||
```
|
||||
|
||||
**Option C: Docker-Container**:
|
||||
```bash
|
||||
docker-compose restart mindnet
|
||||
# oder
|
||||
docker restart mindnet-container
|
||||
```
|
||||
|
||||
### Schritt 4: Verifikation zur Laufzeit
|
||||
|
||||
**Test-Script ausführen** (wenn verfügbar):
|
||||
```bash
|
||||
python3 scripts/verify_dto_import.py
|
||||
```
|
||||
|
||||
**Erwartete Ausgabe**:
|
||||
```
|
||||
✅ EdgeDTO unterstützt 'explicit:callout'
|
||||
✅ 'explicit:callout' ist in der Literal-Liste enthalten
|
||||
✅ EdgeDTO mit 'explicit:callout' erfolgreich erstellt!
|
||||
```
|
||||
|
||||
**Oder manuell testen**:
|
||||
```python
|
||||
python3 -c "
|
||||
from app.models.dto import EdgeDTO
|
||||
test = EdgeDTO(
|
||||
id='test', kind='test', source='test', target='test',
|
||||
weight=1.0, provenance='explicit:callout'
|
||||
)
|
||||
print('✅ EdgeDTO mit explicit:callout funktioniert!')
|
||||
"
|
||||
```
|
||||
|
||||
## Code-Fix (Fallback-Mechanismus)
|
||||
|
||||
Ein Fallback-Mechanismus wurde in `retriever.py` implementiert:
|
||||
- Wenn `EdgeDTO` mit `explicit:callout` fehlschlägt, wird automatisch `explicit` als Fallback verwendet
|
||||
- Dies verhindert, dass der gesamte Retrieval-Prozess fehlschlägt
|
||||
- **WICHTIG**: Dies ist nur eine temporäre Lösung - der Cache muss trotzdem geleert werden!
|
||||
|
||||
## Verifikation nach Fix
|
||||
|
||||
1. **Test-Query ausführen**:
|
||||
```bash
|
||||
curl -X POST http://localhost:8001/api/chat \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"message": "Was für einen Status hat das Projekt mindnet?"}'
|
||||
```
|
||||
|
||||
2. **Log prüfen**:
|
||||
- ✅ Keine `validation error for EdgeDTO` mehr
|
||||
- ✅ Keine `⚠️ [EDGE-DTO] Provenance 'explicit:callout' nicht unterstützt` Warnungen
|
||||
- ✅ `✨ [SUCCESS] Stream 'facts_stream' lieferte X Treffer.`
|
||||
- ✅ Ergebnisse werden zurückgegeben
|
||||
|
||||
## Warum passiert das?
|
||||
|
||||
1. **Code wurde aktualisiert**, aber Service läuft noch mit alter Version im Speicher
|
||||
2. **Python lädt Module nur einmal** - nach dem ersten Import wird die gecachte Version verwendet
|
||||
3. **__pycache__ Verzeichnisse** enthalten kompilierte Bytecode-Versionen der alten Dateien
|
||||
|
||||
## Prävention
|
||||
|
||||
- **Immer Service neu starten** nach Code-Änderungen
|
||||
- **Cache regelmäßig leeren** bei Deployment
|
||||
- **Verwende `--reload` Flag** bei uvicorn für automatisches Neuladen (nur für Dev!)
|
||||
Reference in new issue
Block a user