P-041a: GC-Reset Bug fix — Stufe 1 (Plugin-seitig)
TEIL 1: _GC_TIMEOUT_S variable gemacht
- Statt harter 30.0-Konstante: Env-Variable PRESENCE_GC_TIMEOUT_S mit Default 1800.0s (30 Min)
- os.getenv('PRESENCE_GC_TIMEOUT_S', '1800') -> float in __init__
- GC_TIMEOUT_DEFAULT_S = 1800.0 als Klassenkonstante dokumentiert
TEIL 2: Progress-Refresh bei Core-Aktivitaet
- refresh_chat_profile_timestamp() in PresenceEngine hinzugefuegt
- Setzt self._counter_timestamps['chat_profile'] = time.time() unter transition_lock
- Im adapter.py send(): bei jeder ausgehenden Nachricht mit '⏳' wird der Timestamp refreshed
- Optional-additiv: wenn Refresh nicht feuert, greift 1800s-Cap als Notbremse
TEIL 3: Doku
- GC-Block-Kommentar in _drift_correction() auf P-041a erweitert
- install.sh: PRESENCE_GC_TIMEOUT_S env-Variable dokumentiert (Default 1800s)
Pitfalls: P-039, P-041, P-041a
This commit is contained in:
@@ -103,6 +103,11 @@ read_env() {
|
|||||||
GATEWAY_ALLOW_ALL_USERS="${GATEWAY_ALLOW_ALL_USERS:-true}"
|
GATEWAY_ALLOW_ALL_USERS="${GATEWAY_ALLOW_ALL_USERS:-true}"
|
||||||
ROCKETCHAT_PING_SEC="${ROCKETCHAT_PING_SEC:-8}"
|
ROCKETCHAT_PING_SEC="${ROCKETCHAT_PING_SEC:-8}"
|
||||||
ROCKETCHAT_IDLE_SEC="${ROCKETCHAT_IDLE_SEC:-900}"
|
ROCKETCHAT_IDLE_SEC="${ROCKETCHAT_IDLE_SEC:-900}"
|
||||||
|
# P-041a: GC-Timeout für PresenceEngine Hook-gesetzte Counter.
|
||||||
|
# Default 1800s (30 Min) — ein Turn ohne Activity ist definitiv tot.
|
||||||
|
# Der Progress-Refresh (⏳ Working-Meldungen) setzt den Timer neu.
|
||||||
|
# Community-Instanzen mit sehr langsamen Modellen können erhöhen.
|
||||||
|
PRESENCE_GC_TIMEOUT_S="${PRESENCE_GC_TIMEOUT_S:-1800}"
|
||||||
# Ollama: -1 = Modell nie entladen (dauerhaft warm, ~5GB RAM).
|
# Ollama: -1 = Modell nie entladen (dauerhaft warm, ~5GB RAM).
|
||||||
# Multi-Room-Agent braucht warmes Modell für ruckelfreies Routing.
|
# Multi-Room-Agent braucht warmes Modell für ruckelfreies Routing.
|
||||||
OLLAMA_KEEP_ALIVE="${OLLAMA_KEEP_ALIVE:--1}"
|
OLLAMA_KEEP_ALIVE="${OLLAMA_KEEP_ALIVE:--1}"
|
||||||
|
|||||||
@@ -7111,6 +7111,22 @@ class RocketChatAdapter(BasePlatformAdapter):
|
|||||||
)
|
)
|
||||||
return await self._send_split(real_room_id, content)
|
return await self._send_split(real_room_id, content)
|
||||||
|
|
||||||
|
# ── P-041a: Progress-Refresh für PresenceEngine GC ─────────
|
||||||
|
# Bei '⏳ Working'-Meldungen den chat_profile-Timestamp refreshen,
|
||||||
|
# damit der GC-Reset nicht während aktiver Lang-Turns greift.
|
||||||
|
# Der Refresh ist optional-additiv — wenn das Core-Format sich
|
||||||
|
# ändert, greift trotzdem der 1800s-Cap als Notbremse.
|
||||||
|
if content and '⏳' in content:
|
||||||
|
_has_presence = (
|
||||||
|
hasattr(self, '_presence_engine')
|
||||||
|
and self._presence_engine is not None
|
||||||
|
)
|
||||||
|
if _has_presence:
|
||||||
|
try:
|
||||||
|
self._presence_engine.refresh_chat_profile_timestamp()
|
||||||
|
except Exception:
|
||||||
|
pass # Graceful degradation — GC-Cap greift als Fallback
|
||||||
|
|
||||||
success = await self._post_message_with_retry(real_room_id, content, attachments=attachments)
|
success = await self._post_message_with_retry(real_room_id, content, attachments=attachments)
|
||||||
if success:
|
if success:
|
||||||
# If this message has buttons, mark the room so the next user
|
# If this message has buttons, mark the room so the next user
|
||||||
|
|||||||
@@ -1017,6 +1017,10 @@ class PresenceEngine:
|
|||||||
AWAY_GRACE_DEFAULT_S: float = 2.0
|
AWAY_GRACE_DEFAULT_S: float = 2.0
|
||||||
REST_TIMEOUT_S: float = 10.0
|
REST_TIMEOUT_S: float = 10.0
|
||||||
RETRY_DELAY_S: float = 2.0
|
RETRY_DELAY_S: float = 2.0
|
||||||
|
# P-041a: GC-Timeout für Hook-gesetzte Counter (chat_profile, background_term).
|
||||||
|
# Default 1800s (30 Min) — ein Turn ohne Activity ist definitiv tot.
|
||||||
|
# Überschreibbar via Env-Variable PRESENCE_GC_TIMEOUT_S.
|
||||||
|
GC_TIMEOUT_DEFAULT_S: float = 1800.0
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@@ -1041,6 +1045,12 @@ class PresenceEngine:
|
|||||||
self._use_ddp = use_ddp
|
self._use_ddp = use_ddp
|
||||||
self._adapter = adapter
|
self._adapter = adapter
|
||||||
|
|
||||||
|
# P-041a: GC-Timeout aus Env-Variable (Default 1800s = 30 Min).
|
||||||
|
# Überschreibbar via PRESENCE_GC_TIMEOUT_S für Community-Instanzen.
|
||||||
|
self._gc_timeout_s = float(
|
||||||
|
os.getenv("PRESENCE_GC_TIMEOUT_S", str(self.GC_TIMEOUT_DEFAULT_S))
|
||||||
|
)
|
||||||
|
|
||||||
# ── Counter-Dict: 5 Zähler (P-043: +manual_task) ──────────────────
|
# ── Counter-Dict: 5 Zähler (P-043: +manual_task) ──────────────────
|
||||||
self.counters: Dict[str, int] = {
|
self.counters: Dict[str, int] = {
|
||||||
"main_agent": 0,
|
"main_agent": 0,
|
||||||
@@ -1257,14 +1267,19 @@ class PresenceEngine:
|
|||||||
delegate_counter, real_delegated,
|
delegate_counter, real_delegated,
|
||||||
)
|
)
|
||||||
|
|
||||||
# ── P-041: GC für Hook-gesetzte Counter ──────────────────────
|
# ── P-041 / P-041a: GC für Hook-gesetzte Counter ──────────────
|
||||||
# chat_profile + background_term werden via Hooks gesetzt und
|
# chat_profile + background_term werden via Hooks gesetzt und
|
||||||
# sind NICHT pgrep-detektierbar. Wenn der Hook complete() nicht
|
# sind NICHT pgrep-detektierbar. Wenn der Hook complete() nicht
|
||||||
# feuert (Crash, SIGTERM), bleibt der Counter hängen.
|
# feuert (Crash, SIGTERM), bleibt der Counter hängen.
|
||||||
# GC-Check: Counter > 0 + Timestamp > 30s → Reset auf 0.
|
# GC-Check: Counter > 0 + Timestamp > GC-Timeout → Reset auf 0.
|
||||||
# 30s Timestamp-Guard verhindert premature Reset bei Race
|
#
|
||||||
# zwischen Prozess-Start und Hook-Feuer.
|
# P-041a: Der Timeout ist jetzt variable (self._gc_timeout_s),
|
||||||
_GC_TIMEOUT_S = 30.0
|
# Default 1800s (30 Min) via PRESENCE_GC_TIMEOUT_S Env-Variable.
|
||||||
|
# Der Progress-Refresh (refresh_chat_profile_timestamp()) setzt
|
||||||
|
# den Timestamp bei jeder '⏳ Working'-Meldung neu → GC-Timer
|
||||||
|
# startet neu. Der 1800s-Cap ist die Notbremse für echte Crashes.
|
||||||
|
# P-039: chat_profile + background_term via Hooks nie via pgrep
|
||||||
|
# resetten — nur via GC (dieser Block).
|
||||||
for _gc_counter in ("chat_profile", "background_term"):
|
for _gc_counter in ("chat_profile", "background_term"):
|
||||||
_gc_value = self.counters.get(_gc_counter, 0)
|
_gc_value = self.counters.get(_gc_counter, 0)
|
||||||
if _gc_value <= 0:
|
if _gc_value <= 0:
|
||||||
@@ -1274,12 +1289,12 @@ class PresenceEngine:
|
|||||||
# Kein Timestamp — defensiv: nichts tun
|
# Kein Timestamp — defensiv: nichts tun
|
||||||
continue
|
continue
|
||||||
_gc_age = time.time() - _gc_ts
|
_gc_age = time.time() - _gc_ts
|
||||||
if _gc_age > _GC_TIMEOUT_S:
|
if _gc_age > self._gc_timeout_s:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"[presence-v10] Drift-Korrektur: GC-Reset für %s — "
|
"[presence-v10] Drift-Korrektur: GC-Reset für %s — "
|
||||||
"Counter=%d, Timestamp-Alter=%.1fs (>%.0fs), "
|
"Counter=%d, Timestamp-Alter=%.1fs (>%.0fs), "
|
||||||
"Grund=pgrep-leer+timeout (P-041)",
|
"Grund=pgrep-leer+timeout (P-041/P-041a)",
|
||||||
_gc_counter, _gc_value, _gc_age, _GC_TIMEOUT_S,
|
_gc_counter, _gc_value, _gc_age, self._gc_timeout_s,
|
||||||
)
|
)
|
||||||
self.counters[_gc_counter] = 0
|
self.counters[_gc_counter] = 0
|
||||||
self._counter_timestamps[_gc_counter] = 0.0
|
self._counter_timestamps[_gc_counter] = 0.0
|
||||||
@@ -1288,8 +1303,8 @@ class PresenceEngine:
|
|||||||
logger.debug(
|
logger.debug(
|
||||||
"[presence-v10] Drift-Korrektur: GC-Skip für %s — "
|
"[presence-v10] Drift-Korrektur: GC-Skip für %s — "
|
||||||
"Counter=%d, Timestamp-Alter=%.1fs (<%.0fs) — "
|
"Counter=%d, Timestamp-Alter=%.1fs (<%.0fs) — "
|
||||||
"Race-Schutz aktiv (P-041)",
|
"Race-Schutz aktiv (P-041/P-041a)",
|
||||||
_gc_counter, _gc_value, _gc_age, _GC_TIMEOUT_S,
|
_gc_counter, _gc_value, _gc_age, self._gc_timeout_s,
|
||||||
)
|
)
|
||||||
|
|
||||||
# ── P-043: GC für manuelle Tasks (> 60 Min) ──────────────────
|
# ── P-043: GC für manuelle Tasks (> 60 Min) ──────────────────
|
||||||
@@ -1544,6 +1559,26 @@ class PresenceEngine:
|
|||||||
with self._manual_task_lock:
|
with self._manual_task_lock:
|
||||||
return dict(self._manual_tasks)
|
return dict(self._manual_tasks)
|
||||||
|
|
||||||
|
# ── P-041a: Progress-Refresh ─────────────────────────────────────────
|
||||||
|
|
||||||
|
def refresh_chat_profile_timestamp(self) -> None:
|
||||||
|
"""P-041a: Setzt den chat_profile-Timestamp auf time.time().
|
||||||
|
|
||||||
|
Wird vom Adapter bei jeder '⏳ Working'-Progress-Meldung aufgerufen.
|
||||||
|
Dadurch startet der GC-Timer in _drift_correction() neu — der
|
||||||
|
GC-Reset greift nicht während eines aktiven Lang-Turns.
|
||||||
|
|
||||||
|
Der Refresh ist optional-additiv: wenn er nicht feuert (z.B.
|
||||||
|
Core-Format-Änderung), greift trotzdem der 1800s-Cap als Notbremse.
|
||||||
|
"""
|
||||||
|
with self._transition_lock:
|
||||||
|
if self.counters.get("chat_profile", 0) > 0:
|
||||||
|
self._counter_timestamps["chat_profile"] = time.time()
|
||||||
|
logger.debug(
|
||||||
|
"[presence-v10] P-041a: chat_profile-Timestamp refreshed "
|
||||||
|
"(GC-Timer neu gestartet)"
|
||||||
|
)
|
||||||
|
|
||||||
# ── Schicht 1: Counter + Phase-Resolver ──────────────────────────────
|
# ── Schicht 1: Counter + Phase-Resolver ──────────────────────────────
|
||||||
|
|
||||||
def _apply_counter_delta(self, counter_name: str, delta: int) -> None:
|
def _apply_counter_delta(self, counter_name: str, delta: int) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user