diff --git a/app.py b/app.py index d9d0f39..b9c5d2a 100644 --- a/app.py +++ b/app.py @@ -2694,6 +2694,23 @@ def agent_bootstrap(payload: AgentBootstrapRequest): with get_database_connection() as conn: with conn.cursor() as cur: + # Vor dem Update geprueft: war agent_secret_issued_at NOCH NIE + # gesetzt? Das unterscheidet den ALLERERSTEN Bootstrap (echte + # Neuinstallation, siehe postinstall.sh) von einem spaeteren + # Self-Heal-Re-Bootstrap (401 auf checkin, agent.py) - nur beim + # allerersten Mal wird gleich anschliessend automatisch der + # Debug-Modus aktiviert (Nutzer-Wunsch 02.09.2026: kurz nach dem + # ersten Boot des fertig installierten Systems soll ein frisch + # zugewiesenes Merkmal ohne stundenlange Wartezeit ankommen, + # ohne dass der Debug-Modus jedesmal bei jedem Re-Bootstrap + # erneut anspringt). + cur.execute( + "SELECT agent_secret_issued_at FROM devices WHERE id = %s", + (payload.device_id,), + ) + vorher = cur.fetchone() + ist_erstinstallation = vorher is not None and vorher[0] is None + cur.execute( """ UPDATE devices @@ -2715,6 +2732,14 @@ def agent_bootstrap(payload: AgentBootstrapRequest): (payload.device_id,), ) existing = cur.fetchone() + elif ist_erstinstallation: + cur.execute( + "UPDATE devices SET debug_mode_until = %s WHERE id = %s", + ( + datetime.now(timezone.utc) + timedelta(hours=DEBUG_MODE_DURATION_HOURS), + payload.device_id, + ), + ) if updated is None: if existing is not None and existing[0] is not None: