187 lines
9.3 KiB
Markdown
187 lines
9.3 KiB
Markdown
|
|
# Komplette Schadensanalyse — LeoCRM
|
||
|
|
|
||
|
|
**Datum:** 2026-08-21 03:24 CEST
|
||
|
|
**Methode:** Systematische Prüfung von Schema, API (60+ Endpunkte), Plugins, Logs (1344 Errors), Tests, Frontend, RLS-Policies
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 1. RLS-Konfigurationsfehler: 8 Tabellen mit falschem Parameter ❌ KRITISCH
|
||
|
|
|
||
|
|
8 RLS-Policies in der Produktion referenzieren `app.tenant_id` der nicht als PostgreSQL-Parameter existiert. Der Code verwendet `app.current_tenant_id`. Das verursacht **500 Internal Server Error** auf allen Endpunkten die diese Tabellen abfragen.
|
||
|
|
|
||
|
|
| Tabelle | Policy | Problem | Status |
|
||
|
|
|---------|--------|---------|--------|
|
||
|
|
| roles | tenant_isolation | `current_setting('app.tenant_id')` → 500 | Migration 0136 geschrieben |
|
||
|
|
| sequences | tenant_isolation | `current_setting('app.tenant_id')` → 500 | Migration 0136 geschrieben |
|
||
|
|
| ai_decision_records | tenant_isolation | `current_setting('app.tenant_id')` → 500 | Migration 0136 geschrieben |
|
||
|
|
| approval_requests | tenant_isolation | `current_setting('app.tenant_id')` → 500 | Migration 0136 geschrieben |
|
||
|
|
| automation_agent_run_steps | tenant_isolation | `current_setting('app.tenant_id')` → 500 | Migration 0136 geschrieben |
|
||
|
|
| wiki_articles | tenant_isolation | `current_setting('app.tenant_id')` → 500 | Migration 0136 geschrieben |
|
||
|
|
| wiki_article_versions | tenant_isolation | `current_setting('app.tenant_id')` → 500 | Migration 0136 geschrieben |
|
||
|
|
| wiki_categories | tenant_isolation | `current_setting('app.tenant_id')` → 500 | Migration 0136 geschrieben |
|
||
|
|
|
||
|
|
**Fix:** Migration 0136 — DROP + CREATE POLICY mit `app.current_tenant_id` für alle 8 Tabellen.
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 2. Schema-Drifts: 111 Drifts ❌
|
||
|
|
|
||
|
|
Siehe `SCHEMA_DRIFTS.md` für Details.
|
||
|
|
|
||
|
|
### Kritisch (5):
|
||
|
|
| Tabelle | Spalte | Model | Produktion | Status |
|
||
|
|
|---------|--------|-------|------------|--------|
|
||
|
|
| contacts | status | VARCHAR(30) | VARCHAR(20) | Migration 0135 geschrieben |
|
||
|
|
| notifications | type | VARCHAR(100) | VARCHAR(20) | Migration 0135 geschrieben |
|
||
|
|
| notification_preferences | type_key | VARCHAR(100) | VARCHAR(20) | Migration 0135 geschrieben |
|
||
|
|
| forgejo_reported_errors | * | Model existiert | Tabelle fehlt | Migration 0135 geschrieben |
|
||
|
|
| pgp_keys | * | Model existiert | Tabelle fehlt | Migration 0135 geschrieben |
|
||
|
|
|
||
|
|
### Weniger kritisch (106):
|
||
|
|
- 78 `owner_id` Spalten in DB aber nicht in Models
|
||
|
|
- 13 search/embedding Spalten in DB aber nicht in Models
|
||
|
|
- 15 false positives (Models existieren aber Script importierte sie nicht)
|
||
|
|
|
||
|
|
### Fix:
|
||
|
|
- Migration 0135: Fixt die 5 kritischen Drifts (geschrieben, nicht deployed)
|
||
|
|
- conftest.py: Muss auf `alembic upgrade head` umgestellt werden (nicht gemacht)
|
||
|
|
- Models: Müssen um owner_id und search/embedding Spalten ergänzt werden (nicht gemacht)
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 3. API-Endpunkte: 60+ getestet
|
||
|
|
|
||
|
|
### 200 OK (34 Endpunkte) ✅
|
||
|
|
contacts, companies, workflows, tags, audit-log, system/dashboard, system/alerts, system-settings, users, groups, tenants, notifications, bank-accounts, currencies, saved-filters, saved-views, ai-proactive/suggestions, ai-proactive/settings, mail/accounts, dms/files, dms/folders, calendar/entries, tasks, knowledge/review, improvement/signals, improvement/proposals, improvement/patterns, compliance/ai-registry, compliance/incidents, compliance/retention-policies, plugins, plugins/active-manifests, comm/conversations
|
||
|
|
|
||
|
|
### 500 Internal Server Error (2 Endpunkte) ❌
|
||
|
|
| Endpunkt | Fehler | Ursache |
|
||
|
|
|----------|--------|---------|
|
||
|
|
| /api/v1/roles | internal_error | RLS app.tenant_id (Migration 0136) |
|
||
|
|
| /api/v1/sequences | internal_error | RLS app.tenant_id (Migration 0136) |
|
||
|
|
|
||
|
|
### 404 Not Found (10 Endpunkte) ❌
|
||
|
|
| Endpunkt | Ursache |
|
||
|
|
|----------|---------|
|
||
|
|
| /api/v1/search/search | Route nicht gefunden — Plugin unified_search Routes nicht registriert? |
|
||
|
|
| /api/v1/graph/entities | Route nicht gefunden — Plugin graph_rag Routes nicht registriert? |
|
||
|
|
| /api/v1/wiki/articles | Route nicht gefunden — Plugin wiki Routes nicht registriert? |
|
||
|
|
| /api/v1/permissions | Route nicht gefunden — entity_permissions prefix ist /api/v1/permissions aber Route gibt 404 |
|
||
|
|
| /api/v1/entity-history | Route nicht gefunden — entity_history prefix ist /api/v1/entity-history aber Route gibt 404 |
|
||
|
|
| /api/v1/import-export | Route nicht gefunden — import_export prefix ist /api/v1 aber Route gibt 404 |
|
||
|
|
| /api/v1/tax-rates | Route nicht gefunden — tax-rates Route nicht registriert |
|
||
|
|
| /api/v1/workflow-instances | Route nicht gefunden — workflow-instances Route nicht registriert |
|
||
|
|
| /api/v1/calendar/shares | Route nicht gefunden — calendar/shares Route nicht registriert |
|
||
|
|
| /api/v1/ai-proactive/context | Route nicht gefunden — ai-proactive/context Route nicht registriert |
|
||
|
|
|
||
|
|
### 400 Bad Request (5 Endpunkte) ⚠️
|
||
|
|
| Endpunkt | Ursache |
|
||
|
|
|----------|---------|
|
||
|
|
| /api/v1/automation/agents | Validation error — benötigt Query-Parameter |
|
||
|
|
| /api/v1/automation/automations | Validation error — benötigt Query-Parameter |
|
||
|
|
| /api/v1/automation/cron-jobs | Validation error — benötigt Query-Parameter |
|
||
|
|
| /api/v1/automation/skills | Validation error — benötigt Query-Parameter |
|
||
|
|
| /api/v1/automation/agent-runs | Validation error — benötigt Query-Parameter |
|
||
|
|
|
||
|
|
### 422 Unprocessable Entity (4 Endpunkte) ⚠️
|
||
|
|
| Endpunkt | Ursache |
|
||
|
|
|----------|---------|
|
||
|
|
| /api/v1/attachments | Fehlende Query-Parameter (entity_type, entity_id) |
|
||
|
|
| /api/v1/addresses | Fehlende Query-Parameter (entity_type, entity_id) |
|
||
|
|
| /api/v1/mail/folders | Fehlende Query-Parameter (account_id) |
|
||
|
|
| /api/v1/compliance/dpia-template | Fehlende Query-Parameter (agent_id) |
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 4. Produktions-Logs: 1344 Errors ❌
|
||
|
|
|
||
|
|
- **Hauptfehler:** `unrecognized configuration parameter "app.tenant_id"` — tritt bei jeder Abfrage der 8 betroffenen Tabellen auf
|
||
|
|
- **Permission-Cache-Fehler:** `cannot access local variable 'current_version'` — Folge des app.tenant_id Fehlers
|
||
|
|
- **automation plugin on_activate:** Session-Flush-Fehler bei jedem Container-Start
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 5. Plugin-Status: Alle 24 aktiv ✅
|
||
|
|
|
||
|
|
Alle 24 Plugins sind in der Produktion aktiv. Aber einige Plugin-Routes geben 404 (wiki, graph_rag, unified_search) was bedeutet dass die Routes nicht in die App registriert wurden obwohl die Plugins aktiv sind.
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 6. Tests: 2096 Tests, 3 Collection-Errors ❌
|
||
|
|
|
||
|
|
- 2096 Tests gesammelt
|
||
|
|
- 3 Collection-Errors: test_agent_loop.py, test_p1_6_dms_streaming.py, test_phase_f_agents.py
|
||
|
|
- Tests laufen gegen `create_all` Schema, nicht gegen Alembic-Schema
|
||
|
|
- Das bedeutet: Tests testen ein anderes Schema als die Produktion
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 7. Frontend ❌
|
||
|
|
|
||
|
|
- tsc --noEmit: 0 errors ✅
|
||
|
|
- Vite Build: Erfolgreich ✅
|
||
|
|
- Frontend deployed: Ja (HTTP 200, HTML kommt zurück) ✅
|
||
|
|
- Frontend im Browser: User sieht 'Objekt Objekt' — JavaScript-Rendering-Fehler ❌
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 8. Heute gefixte Bugs (6):
|
||
|
|
|
||
|
|
1. ✅ Permission-Cache gibt None zurück → jeder API-Call 500 (fix: fall-through)
|
||
|
|
2. ✅ Frontend-Deploy Script: docker exec ohne -u root → weiße Seite (fix: -u root + chown)
|
||
|
|
3. ✅ Plugin-Discovery: __init__.py importiert Plugin-Klasse nicht (fix: import hinzugefügt)
|
||
|
|
4. ✅ automation plugin: User.tenant_id existiert nicht (fix: UserTenant join)
|
||
|
|
5. ✅ prestart.sh: Keine Plugin-Auto-Aktivierung (fix: auto-activate + rollback)
|
||
|
|
6. ✅ notification_types: VARCHAR(20) zu klein (fix: Migration 0134, deployed)
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 9. Noch offene Probleme (10):
|
||
|
|
|
||
|
|
1. ❌ RLS-Konfigurationsfehler: 8 Tabellen mit `app.tenant_id` → Migration 0136 geschrieben, nicht deployed
|
||
|
|
2. ❌ Schema-Drifts: 5 kritische → Migration 0135 geschrieben, nicht deployed
|
||
|
|
3. ❌ Schema-Drifts: 106 weniger kritische (78 owner_id, 13 search/embedding) → nicht fixt
|
||
|
|
4. ❌ conftest.py: Tests laufen gegen create_all, nicht gegen Alembic → nicht fixt
|
||
|
|
5. ❌ Frontend: 'Objekt Objekt' JavaScript-Rendering-Fehler → nicht untersucht
|
||
|
|
6. ❌ 3 Test-Collection-Errors → nicht untersucht
|
||
|
|
7. ❌ automation plugin on_activate: Session-Flush-Fehler → nicht gefixt
|
||
|
|
8. ❌ 10 API-Endpunkte geben 404 → nicht untersucht (Plugin-Routes nicht registriert?)
|
||
|
|
9. ❌ Migration 0135 + 0136: Geschrieben aber nicht deployed
|
||
|
|
10. ❌ Models: 78 owner_id und 13 search/embedding Spalten fehlen in Models
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 10. Statistik:
|
||
|
|
|
||
|
|
| Metrik | Wert |
|
||
|
|
|--------|------|
|
||
|
|
| Migrationen | 137 (0135 + 0136 geschrieben, nicht deployed) |
|
||
|
|
| Models | 253 |
|
||
|
|
| API Routes | 554 |
|
||
|
|
| Plugins | 24 (alle aktiv) |
|
||
|
|
| Tests | 2096 (3 Collection-Errors) |
|
||
|
|
| Schema-Drifts | 111 (5 kritisch, 106 weniger kritisch) |
|
||
|
|
| RLS-Policies mit falschem Parameter | 8 |
|
||
|
|
| Produktions-Log-Errors | 1344 |
|
||
|
|
| API-Endpunkte 200 | 34 |
|
||
|
|
| API-Endpunkte 500 | 2 |
|
||
|
|
| API-Endpunkte 404 | 10 |
|
||
|
|
| API-Endpunkte 400/422 | 9 |
|
||
|
|
| Heute gefixte Bugs | 6 |
|
||
|
|
| Noch offene Probleme | 10 |
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## 11. Einschätzung:
|
||
|
|
|
||
|
|
Die Software ist nicht komplett kaputt. 34 von 55 API-Endpunkten geben 200. Alle 24 Plugins sind aktiv. Die Architektur ist nicht falsch.
|
||
|
|
|
||
|
|
Aber es gibt systematische Probleme:
|
||
|
|
1. **RLS-Policies** (8 Tabellen) verursachen 500er — Migration 0136 fixt das
|
||
|
|
2. **Schema-Drifts** (111) zwischen Models und DB — Migration 0135 fixt die 5 kritischen
|
||
|
|
3. **Tests** testen gegen falsches Schema — conftest.py muss umgestellt werden
|
||
|
|
4. **10 API-Endpunkte** geben 404 — Plugin-Routes nicht registriert oder falsche Pfade
|
||
|
|
5. **Frontend** hat JavaScript-Rendering-Fehler — nicht untersucht
|
||
|
|
|
||
|
|
Die Migrationen 0135 + 0136 sind geschrieben und fixen die kritischsten Probleme. Sie müssen deployed werden. Danach müssen die 404er und das Frontend untersucht werden.
|