plugin: Post-Crash-Forensik + skip_background_review-Integration

Feature 1: crash_forensics.py (~447 Zeilen)
- classify_crash_source() — Plugin vs Core aus Traceback
- reconstruct_counter_drift() — Counter Soll/Ist Vergleich
- format_crash_forensic_report() — 6 Datenpunkte mit CRASH-FORENSIK: Präfix
- gather_journal_for_pid() — journalctl via asyncio.create_subprocess_exec
- check_for_predecessor_crash() — 4-Quellen-Korrelation:
  (1) Heartbeat-Leiche, (2) journalctl, (3) restart_loop.json, (4) gateway_state.json
- run_post_crash_forensic_test() — Test-Mode mit simulierten Daten
- Filter: Heartbeat >1h skip, planned_takeover skip
- try/except — blockiert NIEMALS den Gateway-Start

Feature 2: adapter.py connect() Integration
- _crash_forensic_done Flag in __init__()
- Forensik-Aufruf ALS ALLERERSTES in connect() (vor REST-Login, vor DDP)
- Nur beim initialen Connect, nicht bei Reconnects

Rainers 5 Prüfpunkte verifiziert:
1. Heartbeat-Pfad: ~/.hermes/state/gateway.heartbeat
2. journalctl: systemctl --user (User-Unit)
3. AIAgent-Aufrufstellen: 3 Stellen in gateway/run.py (Z.5336, 18427, 21209)
4. planned_takeover: shutdown_forensics.py .gateway-takeover.json
5. subprocess: asyncio.create_subprocess_exec (async-konform)

Tests:
- run_post_crash_forensic_test(): 6 Datenpunkte korrekt
- check_for_predecessor_crash() ohne Heartbeat: None (kein False-Positive)
This commit is contained in:
Bernd (Hermes)
2026-08-14 20:44:22 +02:00
parent 7857bc1aea
commit 438d4bc2cb
2 changed files with 468 additions and 0 deletions
+21
View File
@@ -1206,6 +1206,9 @@ class RocketChatAdapter(BasePlatformAdapter):
self._inline_commands = InlineCommandRegistry()
self._register_inline_commands()
# Post-Crash-Forensik: Flag verhindert Doppel-Aufrufe bei Reconnects
self._crash_forensic_done = False
# V9: PresenceEngine — Schachuhr-Architektur (Hook-basiert)
try:
from archivar.presence_engine import PresenceEngine
@@ -1660,6 +1663,24 @@ class RocketChatAdapter(BasePlatformAdapter):
Silent-Death-Erkennung). Core ruft connect() mit diesem Keyword-Arg
auf; fehlt es → TypeError. Siehe Bug M3.
"""
# ── Post-Crash-Forensik: ALS ALLERERSTES vor REST-Login, vor DDP ──
# Läuft nur beim initialen Connect (nicht bei Reconnects).
# try/except — Forensik-Fehler blockieren NIEMALS den Gateway-Start.
if not self._crash_forensic_done and not is_reconnect:
self._crash_forensic_done = True
try:
from crash_forensics import check_for_predecessor_crash
report = await check_for_predecessor_crash()
if report:
for line in report.splitlines():
logger.info(line)
except Exception as _forensic_exc:
logger.debug(
"[rocketchat] Crash-Forensik fehlgeschlagen (nicht blockierend): %s",
_forensic_exc,
)
# ── Ende Post-Crash-Forensik ─────────────────────────────────────
if not self.base_url or not self.user or not self.password:
logger.error("[rocketchat] Missing configuration")
return False