feat(P-078): GREEN_PULSE-Fix Steps 1-3 — delegation_tracker als Golden Source, pgrep als Telemetrie, Hook-Symmetrie on_review_fork_close
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
# Projekt-STATUS — Hermes Rocket.Chat Plugin
|
# Projekt-STATUS — Hermes Rocket.Chat Plugin
|
||||||
|
|
||||||
> **Stand:** 11. August 2026 — ✅ AKTUELL
|
> **Stand:** 18. August 2026 — ✅ AKTUELL
|
||||||
> **Aktiver Branch:** `main`
|
> **Aktiver Branch:** `main`
|
||||||
> **Letzter Commit:** `5fc3dbd` — fix: entferne doppelte clear_clarify_modal()-Blöcke (11.08. 19:27)
|
> **Letzter Commit:** `feat(P-078)` — GREEN_PULSE-Fix Steps 1-3 (delegation_tracker als Golden Source, pgrep als Telemetrie, Hook-Symmetrie on_review_fork_close)
|
||||||
> **Gitea-Remote:** ✅ SSH synchron — `Andreas/Hermes_rocket.chat_Plugin` (git@192.168.180.47:222)
|
> **Gitea-Remote:** ✅ SSH synchron — `Andreas/Hermes_rocket.chat_Plugin` (git@192.168.180.47:222)
|
||||||
> **Uncommitted:** ✅ 0
|
> **Uncommitted:** ✅ 0
|
||||||
> **Deployment-Pfad:** `~/.hermes/plugins/platforms/rocketchat/`
|
> **Deployment-Pfad:** `~/.hermes/plugins/platforms/rocketchat/`
|
||||||
@@ -14,29 +14,50 @@
|
|||||||
|
|
||||||
| Datei | Deployed MD5 | Git MD5 | Status |
|
| Datei | Deployed MD5 | Git MD5 | Status |
|
||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
| `adapter.py` | `49b3895...` | `49b3895...` | ✅ identisch |
|
| `adapter.py` | `2f3baac7...` | `2f3baac7...` | ✅ identisch |
|
||||||
| `__init__.py` | ✅ | ✅ | ✅ identisch |
|
| `__init__.py` | `d081804a...` | `d081804a...` | ✅ identisch |
|
||||||
| `rc_tools.py` | ✅ | ✅ | ✅ identisch |
|
| `rc_tools.py` | `1fd47d1d...` | `1fd47d1d...` | ✅ identisch |
|
||||||
| `conftest.py` | ✅ | ✅ | ✅ identisch |
|
| `conftest.py` | `9753e447...` | `9753e447...` | ✅ identisch |
|
||||||
|
| `crash_forensics.py` | `42cafee3...` | `42cafee3...` | ✅ identisch |
|
||||||
|
|
||||||
> Alle 4 Plugin-Dateien auf .101 entsprechen dem aktuellen Git-Stand (`5fc3dbd`).
|
> Core-Plugin-Dateien auf .101 entsprechen dem aktuellen Git-Stand (`f7cbe7d`).
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Aktuelle Commits (Chronologisch, neueste zuerst)
|
## Aktuelle Commits (Chronologisch, neueste zuerst — seit 11.08.)
|
||||||
|
|
||||||
| Commit | Beschreibung | Datum |
|
| Commit | Beschreibung | Datum |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
|
| `feat(P-078)` | GREEN_PULSE-Fix Steps 1-3 — delegation_tracker als Golden Source, pgrep als Telemetrie, Hook-Symmetrie on_review_fork_close | 18.08. |
|
||||||
|
| `f7cbe7d` | fix(P-075): crash_forensics.py an reales gateway_state.json-Schema anpassen | 15.08. |
|
||||||
|
| `8af0c03` | fix(P-074c): gateway_state.json updated_at ist ISO-String, nicht Unix-Float | 15.08. |
|
||||||
|
| `0700f40` | fix(P-074): Crash-Forensik Pfad-Mismatch + SIGKILL-Klassifikation | 15.08. |
|
||||||
|
| `0deb3a5` | fix(P-073): crash_forensics-Import im Gateway-Kontext — expliziter sys.path-Eintrag | 15.08. |
|
||||||
|
| `8dc62f1` | fix(P-072): Crash-Forensik Race-Condition — start_time-Vergleich bei PID-Match | 14.08. |
|
||||||
|
| `bb91300` | fix(crash_forensics): P0-Schema-Fixes + P1-Takeover-Fix + Integrationstest | 14.08. |
|
||||||
|
| `438d4bc` | plugin: Post-Crash-Forensik + skip_background_review-Integration | 14.08. |
|
||||||
|
| `10c52cd` | fix(P-067): send_clarify aktiviert Clarify-Modal-Puls | 13.08. |
|
||||||
|
| `9018683` | fix(P-066-followup): send_clarify nutzt button_builder-Pipeline | 13.08. |
|
||||||
|
| `2ffb7cb` | fix(P-066): Clarify-Buttons gerendert + deutsche Labels | 13.08. |
|
||||||
|
| `0ac5031` | tune(P2): adaptive pause factor ×3 → ×6 | 13.08. |
|
||||||
|
| `4ad0cf5` | feat(B7): Natürliche Sprache als Hilfetrigger | 13.08. |
|
||||||
|
| `5363405` | fix(P-064+P-065): Hook-Registrierung in connect() + Onboarding ACTIVE-Guard | 13.08. |
|
||||||
|
| `3471d8e` | fix(P-063): RC-Status-Reset nach Gateway-Neustart + Drift-Korrektur | 13.08. |
|
||||||
|
| `3fa3b59` | fix: stay_tracker nur bei stay_here (Option 2) | 13.08. |
|
||||||
|
| `db06190` | fix(P-061): restliche V8.6-Zombie-Referenzen entfernt | 13.08. |
|
||||||
|
| `379140d` | fix(P-060-followup): V8.6 PresenceEngine Methodenaufrufe entfernt | 13.08. |
|
||||||
|
| `71ade40` | fix(P-060): ungeschützte _pulse_controller-Referenzen entfernt | 12.08. |
|
||||||
|
| `da08382` | fix: P-057 Folgefix + P-058 DM-Ausschluss-Korrektion | 12.08. |
|
||||||
|
| `da9517f` | fix: P-059 — PresenceEngine coalesce_ms/pulse_interval Inkompatibilität | 12.08. |
|
||||||
|
| `2cb506c` | fix: P-056 + P-057 + P-058 — Themenring, stay_once neutral, Button 4 | 12.08. |
|
||||||
|
| `400bdd5` | test: P-054 + P-055 — Unit-Tests | 12.08. |
|
||||||
|
| `fed5656` | fix: P-054 + P-055 — Onboarding-State-Bug und Clarify-Dispatch-Schleife | 12.08. |
|
||||||
|
| `0d6db77` | test(live_rc): test_08_clarify | 12.08. |
|
||||||
|
| `cd84fd3` | fix(P-052): Modal-Puls ignoriert Cooldown | 12.08. |
|
||||||
|
| `328532b` | fix(P-051): action_id in allen Button-Dicts (RC 6.x Rendering-Fix) | 12.08. |
|
||||||
|
| `338fa14` | feat(P-044): install.sh-Migration pip → offizieller Hermes-Installer | 12.08. |
|
||||||
| `5fc3dbd` | fix: entferne doppelte clear_clarify_modal()-Blöcke | 11.08. |
|
| `5fc3dbd` | fix: entferne doppelte clear_clarify_modal()-Blöcke | 11.08. |
|
||||||
| `a743914` | feat: P-049 Clarify-Modal busy↔offline 1,5s + P-047 Mobile-Buttons | 11.08. |
|
| `a743914` | feat: P-049 Clarify-Modal + P-047 Mobile-Buttons | 11.08. |
|
||||||
| `28714b1` | feat: Clarify-Status-Text 'wartet auf Antwort' (Presence-Engine) | 10.08. |
|
|
||||||
| `9f80da6` | P-045: CLARIFY — 2 Root-Cause-Fixes | 10.08. |
|
|
||||||
| `232fde3` | P-044: CLARIFY-Auflösung — 3 Bugfixes (session=?, pending_questions) | 10.08. |
|
|
||||||
| `f0a7e83` | hotfix: CLARIFY-Button ::-Format — resolve_gateway_clarify() | 10.08. |
|
|
||||||
| `cc687c7` | send_clarify(): chunk buttons max 3 per row | 10.08. |
|
|
||||||
| `bd579bd` | fix: Clarify-UX — Emoji-Zahlen + Plain-Digit Text-Intercept | 10.08. |
|
|
||||||
| `fa9091e` | P-041a: GC-Reset Bug fix — Stufe 1 (Plugin-seitig) | 10.08. |
|
|
||||||
| `9dbdfd7` | P-041b E6: CancelledError-Fix — Sweep-Threshold 2.0s → 5.0s | 09.08. |
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -44,25 +65,60 @@
|
|||||||
|
|
||||||
| P-ID | Problem | Status |
|
| P-ID | Problem | Status |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| P-041a | GC-Reset trifft aktive Lang-Turns | ✅ Stufe 1 deployt |
|
| P-044 | pip deprecated → offizieller Hermes-Installer | ✅ Migration implementiert |
|
||||||
| P-043 | Gateway-Blocker via `_HERMES_GATEWAY=0` | ✅ gelöst |
|
| P-051 | Clarify-Buttons ohne action_id → RC 6.x ignoriert | ✅ gefixt, Mobile bestätigt |
|
||||||
| P-045 | Clarify-Button-Klick nicht weitergeleitet | ✅ gefixt |
|
| P-052 | Modal-Puls blockiert durch Cooldown | ✅ gefixt |
|
||||||
| P-046 | Clarify session=? Mapping | ✅ gefixt |
|
| P-053 | Self-Improvement-Loop crasht Gateway während Clarify | ✅ gefixt |
|
||||||
| P-047 | Mobile: Buttons nicht klickbar | ✅ Workaround (msg_in_chat_window=False) |
|
| P-054 | In-Memory Onboarding-State nach Restart leer | ✅ 3-Stage Fallback |
|
||||||
| P-048 | Clarify visual Chunking nicht sichtbar | ✅ GELÖST — Screenshot beweist 3-Spalten-Grid |
|
| P-055 | Clarify-Dispatch-Schleife (stay_once + Nachklärungs-Buttons) | ✅ skip_direct_dispatch |
|
||||||
| P-049 | Clarify-Modal: Status-Änderung als Phase | ✅ implementiert |
|
| P-056 | Themenring greift nicht nach stay_here (Room-ID-Mismatch) | ✅ _normalize_room_id |
|
||||||
| P-050 | 1,5s-Puls triggert RC Sub-Limiter | ✅ Adaptives Backoff — Status quo, wird getestet |
|
| P-057 | stay_once lernt falsch (neutral statt negativ) | ✅ feedback_type='neutral' |
|
||||||
|
| P-058 | Button 4 "Falsch geroutet" (reject feedback_type) | ✅ implementiert + DM-Ausschluss |
|
||||||
|
| P-059 | PresenceEngine coalesce_ms/pulse_interval Inkompatibilität | ✅ reverted zu away_grace_s |
|
||||||
|
| P-060 | V9-Refactor: ungeschützte _pulse_controller-Referenzen | ✅ entfernt |
|
||||||
|
| P-061 | V8.6-Zombie-Methoden in adapter.py | ✅ alle entfernt |
|
||||||
|
| P-063 | Drift-Korrektur Auto-Inkrement + fehlender RC-Status-Reset | ✅ gefixt |
|
||||||
|
| P-064 | _register_presence_hooks() nie aufgerufen — Status permanent GRÜN | ✅ in connect() verdrahtet |
|
||||||
|
| P-065 | _is_onboarding_phase_active() behandelt ACTIVE als laufend | ✅ aufgespalten |
|
||||||
|
| P-066 | send_clarify baut Buttons manuell — keine Pipeline-Features | ✅ button_builder genutzt |
|
||||||
|
| P-067 | send_clarify aktiviert Clarify-Modal-Puls nie | ✅ set_clarify_modal verdrahtet |
|
||||||
|
| P-072 | Crash-Forensik Race-Condition — Core-Heartbeat überschreibt PID vor Plugin-Connect | ✅ start_time-Vergleich bei PID-Match (14.08., .45 deployed) |
|
||||||
|
| P-073 | crash_forensics-Import schlägt im Gateway-Kontext fehl (sys.path) | ✅ expliziter sys.path-Eintrag (15.08.) |
|
||||||
|
| P-074 | Crash-Forensik Pfad-Mismatch + SIGKILL-Klassifikation | ✅ gefixt (15.08.) |
|
||||||
|
| P-074c | gateway_state.json updated_at ist ISO-String, nicht Unix-Float | ✅ gefixt (15.08.) |
|
||||||
|
| P-075 | crash_forensics.py an reales gateway_state.json-Schema angepasst | ✅ gefixt (15.08.) |
|
||||||
|
| P-076 | background_review.py ist Core-Code, nicht Plugin-Code | ✅ erkannt — Core-Änderung als eigener Deploy-Schritt (18.08.) |
|
||||||
|
| P-077 | _review_fork_ran-Flag muss VOR run_conversation gesetzt werden | ✅ gefixt — Flag vor run_conversation, idempotenter Clamp (18.08.) |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## GAP-Analyse (13.08. — verifiziert am Code)
|
||||||
|
|
||||||
|
| GAP | Stand 13.08. | Aufwand |
|
||||||
|
|---|---|---|
|
||||||
|
| B1: V7-2 Sticky thematisch | ✅ Implementiert | Nur Doku |
|
||||||
|
| B2: V7-3 "Jetzt verblasst" | ⚠️ Teilweise (24h-Verfall, adaptiv fehlt) | Mittel |
|
||||||
|
| B3: V7-4 Rückbezüge | ⚠️ Teilweise (sentence_markers.py, Verdrahtung fehlt) | Klein-Mittel |
|
||||||
|
| B4: V7-5 Pause-Definition | ⚠️ Teilweise (24h hard limit, adaptiv fehlt) | Klein |
|
||||||
|
| B5: Onboarding ohne Neustart | ⚠️ Teilweise (DDP-Events, Trigger fehlt) | Klein |
|
||||||
|
| B6: FAKT-Speicherort-Dialog | ✅ Implementiert (::setfakt) | Kein GAP |
|
||||||
|
| B7: Hilfeseite natürliche Sprache | ✅ Implementiert (Commit 4ad0cf5) | Kein GAP |
|
||||||
|
| B8: Taskliste (Notizzettel) | ⚠️ Teilweise (Counter + ::task, Nachhake-Logik fehlt) | Mittel |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Offene Punkte
|
## Offene Punkte
|
||||||
|
|
||||||
1. **P-048** — Visuelle Verifikation Chunking in produktiver UI (5 Buttons in einer Reihe statt 2×3)
|
1. **P-050** — Rate-Limiting-Telemetrie vor Release prüfen
|
||||||
2. **P-050** — Rate-Limiting-Telemetrie vor Release prüfen
|
2. **P-041a Stufe 2** — Core-API `on_session_progress` Hook (langfristig)
|
||||||
3. **P-041a Stufe 2** — Core-API `on_session_progress` Hook (langfristig)
|
3. ~~**install.sh-Migration** — Rainers X1-X7 Plan, Andreas' 3 Entscheidungen offen~~ **✅ ERLEDIGT (11.08.)** — A1/A2/A3 im Decision Log als ✅ Angenommen, Feature-Register Eintrag 62 (Commit `338fa14`), Pitfall P-044. Implementiert von Miguel.
|
||||||
4. **Clarify-Test Round 3** — noch nicht durchgeführt
|
4. **.45 Plugin** — ältere Version, Update ausstehend
|
||||||
5. **install.sh-Migration** — Rainers X1-X7 Plan, Andreas' 3 Entscheidungen offen
|
5. **GAP B2/B4** — Adaptive Verfall-Logik (V7-3/V7-5)
|
||||||
6. **.45 Plugin** — ältere Version (kein manual_task-Counter), Update ausstehend
|
6. **GAP B3** — Rückbezug-Verdrahtung (V7-4)
|
||||||
|
7. **GAP B5** — Onboarding-Trigger ohne Neustart
|
||||||
|
8. **GAP B8** — Taskliste-Nachhake-Logik
|
||||||
|
9. **24h-Rekonvaleszenz-Check** — Listener stabil seit 13.08.?
|
||||||
|
10. **Alte state.db-Backups** — Aufräumen WV 16.08. (4,6 GB, 5 Dateien)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
+12
-3
@@ -189,7 +189,7 @@ def register(ctx):
|
|||||||
|
|
||||||
|
|
||||||
def _register_presence_hooks() -> None:
|
def _register_presence_hooks() -> None:
|
||||||
"""Registriere 10 Presence-Hooks via ctx.register_hook().
|
"""Registriere 12 Presence-Hooks via ctx.register_hook().
|
||||||
|
|
||||||
Wird von RocketChatAdapter.connect() aufgerufen, sobald der Adapter
|
Wird von RocketChatAdapter.connect() aufgerufen, sobald der Adapter
|
||||||
vollständig initialisiert ist (REST-Login, PresenceEngine, asyncio-Loop).
|
vollständig initialisiert ist (REST-Login, PresenceEngine, asyncio-Loop).
|
||||||
@@ -282,12 +282,21 @@ def _register_presence_hooks() -> None:
|
|||||||
ctx.register_hook("post_tool_call", _on_post_tool_call)
|
ctx.register_hook("post_tool_call", _on_post_tool_call)
|
||||||
ctx.register_hook("background_process_stop", _on_background_process_stop)
|
ctx.register_hook("background_process_stop", _on_background_process_stop)
|
||||||
|
|
||||||
|
# ── STEP 3: on_review_fork_close Hook (Hook-Symmetrie) ──────────
|
||||||
|
# Der Review-Fork (background_review.py) feuert on_session_start
|
||||||
|
# (chat_profile += 1), aber on_session_finalize feuert NICHT
|
||||||
|
# (_end_session_on_close=False). Dieser Hook dekrementiert idempotent.
|
||||||
|
def _on_review_fork_close(**kwargs):
|
||||||
|
_get_engine_and_call("on_review_fork_close", **kwargs)
|
||||||
|
|
||||||
|
ctx.register_hook("on_review_fork_close", _on_review_fork_close)
|
||||||
|
|
||||||
_hooks_registered = True
|
_hooks_registered = True
|
||||||
logger.info(
|
logger.info(
|
||||||
"[presence-v10] 11 Hooks registriert: "
|
"[presence-v10] 12 Hooks registriert: "
|
||||||
"pre_gateway_dispatch, post_llm_call, subagent_start, subagent_stop, "
|
"pre_gateway_dispatch, post_llm_call, subagent_start, subagent_stop, "
|
||||||
"on_session_start, on_session_end, on_session_finalize, on_session_reset, "
|
"on_session_start, on_session_end, on_session_finalize, on_session_reset, "
|
||||||
"pre_tool_call, post_tool_call, background_process_stop"
|
"pre_tool_call, post_tool_call, background_process_stop, on_review_fork_close"
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ Zero external dependencies — stdlib only.
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import enum
|
import enum
|
||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
@@ -1547,32 +1548,49 @@ class PresenceEngine:
|
|||||||
# ── P-036 Fix 3: Counter-Drift-Korrektur ─────────────────────────────
|
# ── P-036 Fix 3: Counter-Drift-Korrektur ─────────────────────────────
|
||||||
|
|
||||||
def _drift_correction(self) -> None:
|
def _drift_correction(self) -> None:
|
||||||
"""Periodischer Abgleich der In-Memory Counter gegen reale Subagent-Anzahl.
|
"""Periodischer Abgleich der In-Memory Counter gegen die Agenten-Taskliste.
|
||||||
|
|
||||||
Nutzt pgrep/argv-basiertes Matching (P-008, P-009 Pitfalls).
|
STEP 1 (Golden Source): delegation_tracker.json (Agenten-Taskliste) ist
|
||||||
Korrigiert Counter-Drift und loggt als Telemetry-Event.
|
die Primärquelle für die Anzahl aktiver delegierter Tasks. Andreas'
|
||||||
P-039: Nur delegate_subagent wird via pgrep geprüft.
|
Anforderung: 'Task offen = 0 = grün.'
|
||||||
|
STEP 2 (Telemetrie): pgrep läuft weiter, ist aber NUR Telemetrie —
|
||||||
|
sein Ergebnis überschreibt die Taskliste NIEMALS.
|
||||||
|
|
||||||
|
P-039: Nur delegate_subagent wird via Drift-Korrektur geprüft.
|
||||||
chat_profile + background_term (Hook-gesetzt) bleiben unverändert.
|
chat_profile + background_term (Hook-gesetzt) bleiben unverändert.
|
||||||
"""
|
"""
|
||||||
# P-039: pgrep-Aufruf ist in den transition_lock-Block verschoben
|
|
||||||
# (siehe _count_delegated_subagents() unten).
|
|
||||||
|
|
||||||
with self._transition_lock:
|
with self._transition_lock:
|
||||||
# P-031: transition_lock vor mediator_lock
|
# P-031: transition_lock vor mediator_lock
|
||||||
# P-039: Nur delegate_subagent via pgrep prüfen.
|
# P-039: Nur delegate_subagent via Drift-Korrektur prüfen.
|
||||||
# chat_profile + background_term werden via Hooks gesetzt und
|
# chat_profile + background_term werden via Hooks gesetzt und
|
||||||
# sind NICHT über pgrep verifizierbar — nie automatisch zurücksetzen.
|
# sind NICHT über pgrep verifizierbar — nie automatisch zurücksetzen.
|
||||||
delegate_counter = self.counters.get("delegate_subagent", 0)
|
delegate_counter = self.counters.get("delegate_subagent", 0)
|
||||||
real_delegated = self._count_delegated_subagents()
|
|
||||||
|
# STEP 1: Taskliste als Primärquelle (Golden Source).
|
||||||
|
active_tasks = self._count_active_tasks_from_tracker()
|
||||||
|
|
||||||
|
# STEP 2: pgrep als Fallback — NUR Telemetrie, nicht entscheidungsrelevant.
|
||||||
|
pgrep_count = self._count_delegated_subagents()
|
||||||
|
|
||||||
|
# Taskliste gewinnt: real_delegated = active_tasks (überschreibt pgrep).
|
||||||
|
real_delegated = active_tasks
|
||||||
|
|
||||||
|
# Telemetrie: pgrep False-Positive erkennen (Taskliste leer, pgrep > 0).
|
||||||
|
if active_tasks == 0 and pgrep_count > 0:
|
||||||
|
logger.warning(
|
||||||
|
"[presence-v10] pgrep found %d processes but tasklist is empty — "
|
||||||
|
"likely false positive (GREEN_STATIC bleibt)",
|
||||||
|
pgrep_count,
|
||||||
|
)
|
||||||
|
|
||||||
if delegate_counter > 0 and real_delegated == 0:
|
if delegate_counter > 0 and real_delegated == 0:
|
||||||
# delegate_subagent > 0 aber keine realen delegierten Subagenten:
|
# delegate_subagent > 0 aber keine aktiven Tasks in der Taskliste:
|
||||||
# Nur delegate_subagent resetten (pgrep-detektierbar).
|
# Nur delegate_subagent resetten (Golden Source sagt 0).
|
||||||
# chat_profile + background_term bleiben unverändert (P-039).
|
# chat_profile + background_term bleiben unverändert (P-039).
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"[presence-v10] Drift-Korrektur: delegate_subagent-Drift erkannt — "
|
"[presence-v10] Drift-Korrektur: delegate_subagent-Drift erkannt — "
|
||||||
"delegate_counter=%d, real_delegated=%d — setze delegate_subagent auf 0",
|
"delegate_counter=%d, active_tasks=%d (pgrep=%d) — setze delegate_subagent auf 0",
|
||||||
delegate_counter, real_delegated,
|
delegate_counter, real_delegated, pgrep_count,
|
||||||
)
|
)
|
||||||
self.counters["delegate_subagent"] = 0
|
self.counters["delegate_subagent"] = 0
|
||||||
self._telemetry_drift_corrections += 1
|
self._telemetry_drift_corrections += 1
|
||||||
@@ -1587,19 +1605,18 @@ class PresenceEngine:
|
|||||||
elif delegate_counter == 0 and real_delegated > 0:
|
elif delegate_counter == 0 and real_delegated > 0:
|
||||||
# P-063: Auto-Inkrement entfernt (P-039-Verletzung).
|
# P-063: Auto-Inkrement entfernt (P-039-Verletzung).
|
||||||
# Drift-Korrektur darf nur Counter RESETTEN, niemals AUTO-SETZEN.
|
# Drift-Korrektur darf nur Counter RESETTEN, niemals AUTO-SETZEN.
|
||||||
# pgrep matched ggf. den eigenen Chat als Subagent (False-Positive).
|
|
||||||
# Nur LOG schreiben, kein Counter-Update.
|
# Nur LOG schreiben, kein Counter-Update.
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"[presence-v10] Drift-Korrektur: delegate_subagent-Drift erkannt — "
|
"[presence-v10] Drift-Korrektur: delegate_subagent-Drift erkannt — "
|
||||||
"delegate_counter=%d, real_delegated=%d — KEIN Auto-Inkrement (P-063)",
|
"delegate_counter=%d, active_tasks=%d (pgrep=%d) — KEIN Auto-Inkrement (P-063)",
|
||||||
delegate_counter, real_delegated,
|
delegate_counter, real_delegated, pgrep_count,
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"[presence-v10] Drift-Korrektur: OK — "
|
"[presence-v10] Drift-Korrektur: OK — "
|
||||||
"delegate_counter=%d, real_delegated=%d",
|
"delegate_counter=%d, active_tasks=%d (pgrep=%d)",
|
||||||
delegate_counter, real_delegated,
|
delegate_counter, real_delegated, pgrep_count,
|
||||||
)
|
)
|
||||||
|
|
||||||
# ── P-041 / P-041a: GC für Hook-gesetzte Counter ──────────────
|
# ── P-041 / P-041a: GC für Hook-gesetzte Counter ──────────────
|
||||||
@@ -1728,6 +1745,77 @@ class PresenceEngine:
|
|||||||
except Exception:
|
except Exception:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _pid_alive(pid: int) -> bool:
|
||||||
|
"""Prüfe ob ein Prozess mit der gegebenen PID noch lebt.
|
||||||
|
|
||||||
|
os.kill(pid, 0) sendet Signal 0 (kein Signal) — prüft nur die Existenz.
|
||||||
|
ProcessLookupError → Prozess existiert nicht (tot).
|
||||||
|
PermissionError → existiert, aber kein Zugriff (lebt).
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
os.kill(pid, 0)
|
||||||
|
return True
|
||||||
|
except (ProcessLookupError, PermissionError):
|
||||||
|
return False
|
||||||
|
except OSError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def _get_tracker_path(self) -> str:
|
||||||
|
"""Liefere den Pfad zur delegation_tracker.json (Golden Source).
|
||||||
|
|
||||||
|
Überschreibbar via DELEGATION_TRACKER_PATH (für Tests).
|
||||||
|
P-011: Env-Variable wird zur Laufzeit gelesen, nicht auf Modulebene.
|
||||||
|
"""
|
||||||
|
return os.getenv(
|
||||||
|
"DELEGATION_TRACKER_PATH",
|
||||||
|
os.path.expanduser("~/.hermes/delegation_tracker.json"),
|
||||||
|
)
|
||||||
|
|
||||||
|
def _count_active_tasks_from_tracker(self) -> int:
|
||||||
|
"""Zähle aktive (running) Tasks aus der delegation_tracker.json (Golden Source).
|
||||||
|
|
||||||
|
Andreas' Anforderung: 'Task offen = 0 = grün.' Die Agenten-Taskliste
|
||||||
|
(delegation_tracker.py) ist die Golden Source für die Anzahl aktiver
|
||||||
|
delegierter Tasks. pgrep ist nur noch Fallback/Telemetrie (STEP 2).
|
||||||
|
|
||||||
|
Liest die JSON-Datei, zählt Einträge mit status == "running" und
|
||||||
|
lebendem PID. pid_exists-Safety: toter Prozess → stale Task ignorieren.
|
||||||
|
FileNotFoundError/JSONDecodeError werden graceful abgefangen (→ 0).
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Anzahl aktiver (running + lebender PID) Tasks.
|
||||||
|
"""
|
||||||
|
path = self._get_tracker_path()
|
||||||
|
try:
|
||||||
|
with open(path, "r") as f:
|
||||||
|
entries = json.load(f)
|
||||||
|
except (FileNotFoundError, json.JSONDecodeError, OSError):
|
||||||
|
return 0
|
||||||
|
if not isinstance(entries, list):
|
||||||
|
return 0
|
||||||
|
active = 0
|
||||||
|
for entry in entries:
|
||||||
|
if not isinstance(entry, dict):
|
||||||
|
continue
|
||||||
|
if entry.get("status") != "running":
|
||||||
|
continue
|
||||||
|
pid = entry.get("pid")
|
||||||
|
if pid is None:
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
pid = int(pid)
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
continue
|
||||||
|
if not self._pid_alive(pid):
|
||||||
|
logger.debug(
|
||||||
|
"[presence-v10] Taskliste: PID %d tot — stale Eintrag ignoriert",
|
||||||
|
pid,
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
active += 1
|
||||||
|
return active
|
||||||
|
|
||||||
# ── Hook-Callbacks (6 Core-Hooks + 2 Tool-Filter) ────────────────────
|
# ── Hook-Callbacks (6 Core-Hooks + 2 Tool-Filter) ────────────────────
|
||||||
# V10: Unverändert aus V9. Hooks bleiben SYNCHRON (P-024).
|
# V10: Unverändert aus V9. Hooks bleiben SYNCHRON (P-024).
|
||||||
|
|
||||||
@@ -1784,6 +1872,22 @@ class PresenceEngine:
|
|||||||
"""
|
"""
|
||||||
self._apply_counter_delta("chat_profile", -1)
|
self._apply_counter_delta("chat_profile", -1)
|
||||||
|
|
||||||
|
def on_review_fork_close(self, **kwargs) -> None:
|
||||||
|
"""Hook: on_review_fork_close → chat_profile -= 1 (idempotent).
|
||||||
|
|
||||||
|
STEP 3 (Hook-Symmetrie): Der Review-Fork (background_review.py) feuert
|
||||||
|
on_session_start (chat_profile += 1) via run_conversation, aber
|
||||||
|
on_session_finalize feuert NICHT — weil der Fork _end_session_on_close=False
|
||||||
|
setzt (er teilt die session_id des Parents und darf die Session nicht
|
||||||
|
finalisieren). Ohne diesen Hook bleibt chat_profile nach jedem Review
|
||||||
|
dauerhaft +1 → GREEN_PULSE im Leerlauf.
|
||||||
|
|
||||||
|
Dieser Hook wird vom Core im finally-Block des Review-Threads gefeuert
|
||||||
|
und stellt die Symmetrie her. Idempotent: _apply_counter_delta klemmt
|
||||||
|
bei 0 (P-032), ein doppelter Aufruf ist harmlos.
|
||||||
|
"""
|
||||||
|
self._apply_counter_delta("chat_profile", -1)
|
||||||
|
|
||||||
def on_session_reset(self, **kwargs) -> None:
|
def on_session_reset(self, **kwargs) -> None:
|
||||||
"""Hook: on_session_reset → alle Counter auf 0 (P-032 Fix).
|
"""Hook: on_session_reset → alle Counter auf 0 (P-032 Fix).
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,354 @@
|
|||||||
|
"""
|
||||||
|
V10: Drift-Korrektur mit Taskliste als Golden Source (Rainer-Spezifikation).
|
||||||
|
|
||||||
|
Tests für die Umstellung der Drift-Korrektur von pgrep auf die
|
||||||
|
Agenten-Taskliste (delegation_tracker.json) als Primärquelle.
|
||||||
|
|
||||||
|
STEP 1: Taskliste als Primärquelle.
|
||||||
|
STEP 2: pgrep als Fallback (nur Telemetrie).
|
||||||
|
STEP 3: Hook-Symmetrie (on_review_fork_close) — separat getestet.
|
||||||
|
|
||||||
|
Test-Pflicht (Rainer):
|
||||||
|
- Taskliste 0 → GREEN_STATIC (nicht GREEN_PULSE)
|
||||||
|
- Taskliste 1 + pgrep 0 → GREEN_PULSE (Taskliste gewinnt)
|
||||||
|
- Taskliste 0 + pgrep 1 → GREEN_STATIC (pgrep ist Telemetrie)
|
||||||
|
- Integration: pgrep-False-Positive auf eigene Session → GREEN_STATIC
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import tempfile
|
||||||
|
from pathlib import Path
|
||||||
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
# Ensure the plugin package is importable
|
||||||
|
sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
|
||||||
|
|
||||||
|
|
||||||
|
def _make_engine(rest=None, enabled=True, away_grace_s=0.1):
|
||||||
|
"""Erzeuge eine PresenceEngine V10 für Tests."""
|
||||||
|
from plugin.archivar.presence_engine import PresenceEngine
|
||||||
|
if rest is None:
|
||||||
|
rest = MagicMock()
|
||||||
|
rest.auth_token = "test-token"
|
||||||
|
rest.user_id = "test-user"
|
||||||
|
rest._request = MagicMock()
|
||||||
|
return PresenceEngine(rest=rest, enabled=enabled, away_grace_s=away_grace_s)
|
||||||
|
|
||||||
|
|
||||||
|
def _write_tracker(path: Path, entries: list) -> None:
|
||||||
|
"""Schreibe eine delegation_tracker.json mit den gegebenen Einträgen."""
|
||||||
|
path.write_text(json.dumps(entries, indent=2))
|
||||||
|
|
||||||
|
|
||||||
|
def _running_entry(pid: int, agent: str = "rainer", task: str = "Test") -> dict:
|
||||||
|
"""Erzeuge einen 'running'-Eintrag mit lebendem PID."""
|
||||||
|
return {
|
||||||
|
"pid": pid,
|
||||||
|
"agent": agent,
|
||||||
|
"task": task,
|
||||||
|
"timeout_sec": 600,
|
||||||
|
"start_epoch": 0,
|
||||||
|
"start_iso": "2026-01-01T00:00:00+0000",
|
||||||
|
"status": "running",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
# STEP 1: Taskliste als Primärquelle
|
||||||
|
# ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
|
class TestTasklistGoldenSource:
|
||||||
|
"""Taskliste (delegation_tracker.json) ist die Golden Source."""
|
||||||
|
|
||||||
|
def test_tasklist_zero_green_static(self, tmp_path):
|
||||||
|
"""Taskliste 0 → GREEN_STATIC (nicht GREEN_PULSE).
|
||||||
|
|
||||||
|
delegate_subagent=1 (Drift), Taskliste leer → Reset → GREEN_STATIC.
|
||||||
|
"""
|
||||||
|
from plugin.archivar.presence_engine import Phase
|
||||||
|
|
||||||
|
tracker = tmp_path / "delegation_tracker.json"
|
||||||
|
_write_tracker(tracker, []) # leere Taskliste
|
||||||
|
|
||||||
|
engine = _make_engine()
|
||||||
|
# Simuliere Drift: delegate_subagent=1 (Hook gesetzt, aber Taskliste leer)
|
||||||
|
engine.counters["delegate_subagent"] = 1
|
||||||
|
|
||||||
|
with patch.object(engine, "_get_tracker_path", return_value=str(tracker)):
|
||||||
|
engine._drift_correction()
|
||||||
|
|
||||||
|
assert engine.counters["delegate_subagent"] == 0
|
||||||
|
assert engine.get_current_phase() == Phase.GREEN_STATIC
|
||||||
|
|
||||||
|
def test_tasklist_one_pgrep_zero_green_pulse(self, tmp_path):
|
||||||
|
"""Taskliste 1 + pgrep 0 → GREEN_PULSE (Taskliste gewinnt).
|
||||||
|
|
||||||
|
delegate_subagent=1 (Hook gesetzt), Taskliste=1 (lebender PID),
|
||||||
|
pgrep=0. Ohne Fix würde pgrep=0 → Reset → GREEN_STATIC (falsch).
|
||||||
|
Mit Fix: Taskliste=1 → kein Reset → GREEN_PULSE bleibt.
|
||||||
|
"""
|
||||||
|
from plugin.archivar.presence_engine import Phase
|
||||||
|
|
||||||
|
tracker = tmp_path / "delegation_tracker.json"
|
||||||
|
# Lebender PID: os.getpid() ist garantiert lebendig.
|
||||||
|
_write_tracker(tracker, [_running_entry(pid=os.getpid())])
|
||||||
|
|
||||||
|
engine = _make_engine()
|
||||||
|
engine.counters["delegate_subagent"] = 1
|
||||||
|
|
||||||
|
with patch.object(engine, "_get_tracker_path", return_value=str(tracker)), \
|
||||||
|
patch.object(engine, "_count_delegated_subagents", return_value=0):
|
||||||
|
engine._drift_correction()
|
||||||
|
|
||||||
|
# Taskliste gewinnt: kein Reset, delegate_subagent bleibt 1.
|
||||||
|
assert engine.counters["delegate_subagent"] == 1
|
||||||
|
assert engine.get_current_phase() == Phase.GREEN_PULSE
|
||||||
|
|
||||||
|
def test_tasklist_zero_pgrep_one_green_static(self, tmp_path):
|
||||||
|
"""Taskliste 0 + pgrep 1 → GREEN_STATIC (pgrep ist Telemetrie).
|
||||||
|
|
||||||
|
delegate_subagent=1 (Drift), Taskliste leer, pgrep=1 (False-Positive).
|
||||||
|
Ohne Fix würde pgrep=1 → kein Reset → GREEN_PULSE (der Bug!).
|
||||||
|
Mit Fix: Taskliste=0 → Reset → GREEN_STATIC.
|
||||||
|
"""
|
||||||
|
from plugin.archivar.presence_engine import Phase
|
||||||
|
|
||||||
|
tracker = tmp_path / "delegation_tracker.json"
|
||||||
|
_write_tracker(tracker, []) # leere Taskliste
|
||||||
|
|
||||||
|
engine = _make_engine()
|
||||||
|
engine.counters["delegate_subagent"] = 1
|
||||||
|
|
||||||
|
with patch.object(engine, "_get_tracker_path", return_value=str(tracker)), \
|
||||||
|
patch.object(engine, "_count_delegated_subagents", return_value=1):
|
||||||
|
engine._drift_correction()
|
||||||
|
|
||||||
|
# pgrep ist nur Telemetrie: Taskliste=0 gewinnt → Reset → GREEN_STATIC.
|
||||||
|
assert engine.counters["delegate_subagent"] == 0
|
||||||
|
assert engine.get_current_phase() == Phase.GREEN_STATIC
|
||||||
|
|
||||||
|
|
||||||
|
# ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
# STEP 2: pgrep als Fallback (nur Telemetrie)
|
||||||
|
# ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
|
class TestPgrepTelemetryOnly:
|
||||||
|
"""pgrep überschreibt die Taskliste NIEMALS."""
|
||||||
|
|
||||||
|
def test_pgrep_false_positive_logs_warning(self, tmp_path, caplog):
|
||||||
|
"""Taskliste 0 + pgrep > 0 → LOG WARNING, aber GREEN_STATIC."""
|
||||||
|
from plugin.archivar.presence_engine import Phase, logger as pe_logger
|
||||||
|
|
||||||
|
tracker = tmp_path / "delegation_tracker.json"
|
||||||
|
_write_tracker(tracker, [])
|
||||||
|
|
||||||
|
engine = _make_engine()
|
||||||
|
engine.counters["delegate_subagent"] = 1
|
||||||
|
|
||||||
|
# presence_engine setzt logger.propagate = False (Modul-Level, Z.55),
|
||||||
|
# damit Logs in journalctl landen. caplog fängt nur propagierte
|
||||||
|
# Records — daher temporär propagation aktivieren (Muster aus
|
||||||
|
# test_v8_4_5.py::test_telemetry_flush_logs_info).
|
||||||
|
pe_logger.propagate = True
|
||||||
|
try:
|
||||||
|
with patch.object(engine, "_get_tracker_path", return_value=str(tracker)), \
|
||||||
|
patch.object(engine, "_count_delegated_subagents", return_value=3):
|
||||||
|
with caplog.at_level("WARNING"):
|
||||||
|
engine._drift_correction()
|
||||||
|
finally:
|
||||||
|
pe_logger.propagate = False
|
||||||
|
|
||||||
|
# WARNING über False-Positive geloggt
|
||||||
|
assert any(
|
||||||
|
"pgrep found 3 processes but tasklist is empty" in r.message
|
||||||
|
for r in caplog.records
|
||||||
|
)
|
||||||
|
# Phase bleibt GREEN_STATIC (pgrep überschreibt nicht)
|
||||||
|
assert engine.get_current_phase() == Phase.GREEN_STATIC
|
||||||
|
|
||||||
|
def test_pgrep_never_overrides_tasklist_zero(self, tmp_path):
|
||||||
|
"""pgrep > 0 darf die Phase NIE auf PULSE setzen wenn Taskliste 0 sagt."""
|
||||||
|
from plugin.archivar.presence_engine import Phase
|
||||||
|
|
||||||
|
tracker = tmp_path / "delegation_tracker.json"
|
||||||
|
_write_tracker(tracker, [])
|
||||||
|
|
||||||
|
engine = _make_engine()
|
||||||
|
engine.counters["delegate_subagent"] = 1
|
||||||
|
|
||||||
|
# pgrep findet 5 Prozesse, aber Taskliste ist leer.
|
||||||
|
with patch.object(engine, "_get_tracker_path", return_value=str(tracker)), \
|
||||||
|
patch.object(engine, "_count_delegated_subagents", return_value=5):
|
||||||
|
engine._drift_correction()
|
||||||
|
|
||||||
|
assert engine.get_current_phase() == Phase.GREEN_STATIC
|
||||||
|
assert engine.counters["delegate_subagent"] == 0
|
||||||
|
|
||||||
|
|
||||||
|
# ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
# pid_exists-Safety: stale Tasks ignorieren
|
||||||
|
# ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
|
class TestPidExistsSafety:
|
||||||
|
"""Tote PIDs in der Taskliste werden als stale ignoriert."""
|
||||||
|
|
||||||
|
def test_dead_pid_ignored(self, tmp_path):
|
||||||
|
"""running-Eintrag mit totem PID → nicht als aktiv gezählt."""
|
||||||
|
tracker = tmp_path / "delegation_tracker.json"
|
||||||
|
# PID 99999999 ist praktisch sicher tot.
|
||||||
|
_write_tracker(tracker, [_running_entry(pid=99999999)])
|
||||||
|
|
||||||
|
engine = _make_engine()
|
||||||
|
with patch.object(engine, "_get_tracker_path", return_value=str(tracker)):
|
||||||
|
assert engine._count_active_tasks_from_tracker() == 0
|
||||||
|
|
||||||
|
def test_live_pid_counted(self, tmp_path):
|
||||||
|
"""running-Eintrag mit lebendem PID → als aktiv gezählt."""
|
||||||
|
tracker = tmp_path / "delegation_tracker.json"
|
||||||
|
_write_tracker(tracker, [_running_entry(pid=os.getpid())])
|
||||||
|
|
||||||
|
engine = _make_engine()
|
||||||
|
with patch.object(engine, "_get_tracker_path", return_value=str(tracker)):
|
||||||
|
assert engine._count_active_tasks_from_tracker() == 1
|
||||||
|
|
||||||
|
def test_done_entries_ignored(self, tmp_path):
|
||||||
|
"""done-Einträge werden nicht als aktiv gezählt."""
|
||||||
|
tracker = tmp_path / "delegation_tracker.json"
|
||||||
|
done = _running_entry(pid=os.getpid())
|
||||||
|
done["status"] = "done"
|
||||||
|
_write_tracker(tracker, [done])
|
||||||
|
|
||||||
|
engine = _make_engine()
|
||||||
|
with patch.object(engine, "_get_tracker_path", return_value=str(tracker)):
|
||||||
|
assert engine._count_active_tasks_from_tracker() == 0
|
||||||
|
|
||||||
|
|
||||||
|
# ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
# Graceful Degradation: fehlende/kaputte Datei
|
||||||
|
# ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
|
class TestTrackerGracefulDegradation:
|
||||||
|
"""FileNotFoundError / JSONDecodeError → 0 (graceful)."""
|
||||||
|
|
||||||
|
def test_missing_file_returns_zero(self, tmp_path):
|
||||||
|
"""Fehlende Datei → 0 aktive Tasks."""
|
||||||
|
engine = _make_engine()
|
||||||
|
with patch.object(
|
||||||
|
engine, "_get_tracker_path",
|
||||||
|
return_value=str(tmp_path / "does_not_exist.json"),
|
||||||
|
):
|
||||||
|
assert engine._count_active_tasks_from_tracker() == 0
|
||||||
|
|
||||||
|
def test_invalid_json_returns_zero(self, tmp_path):
|
||||||
|
"""Kaputtes JSON → 0 aktive Tasks."""
|
||||||
|
tracker = tmp_path / "delegation_tracker.json"
|
||||||
|
tracker.write_text("{ invalid json !!!")
|
||||||
|
|
||||||
|
engine = _make_engine()
|
||||||
|
with patch.object(engine, "_get_tracker_path", return_value=str(tracker)):
|
||||||
|
assert engine._count_active_tasks_from_tracker() == 0
|
||||||
|
|
||||||
|
def test_non_list_returns_zero(self, tmp_path):
|
||||||
|
"""JSON ist kein Array → 0 aktive Tasks."""
|
||||||
|
tracker = tmp_path / "delegation_tracker.json"
|
||||||
|
tracker.write_text(json.dumps({"not": "a list"}))
|
||||||
|
|
||||||
|
engine = _make_engine()
|
||||||
|
with patch.object(engine, "_get_tracker_path", return_value=str(tracker)):
|
||||||
|
assert engine._count_active_tasks_from_tracker() == 0
|
||||||
|
|
||||||
|
|
||||||
|
# ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
# Integration: pgrep-False-Positive auf eigene Session → GREEN_STATIC
|
||||||
|
# ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
|
class TestIntegrationFalsePositive:
|
||||||
|
"""Integration: pgrep matcht eigene Session als Subagent → GREEN_STATIC."""
|
||||||
|
|
||||||
|
def test_false_positive_own_session_green_static(self, tmp_path):
|
||||||
|
"""pgrep findet die eigene Session (False-Positive), Taskliste leer.
|
||||||
|
|
||||||
|
Dies ist der Kern-Bug: pgrep matcht Bernds eigene Session als
|
||||||
|
'hermes chat --profile' → real_delegated=1 → GREEN_PULSE im Leerlauf.
|
||||||
|
Mit Taskliste als Golden Source: Taskliste=0 → GREEN_STATIC.
|
||||||
|
"""
|
||||||
|
from plugin.archivar.presence_engine import Phase
|
||||||
|
|
||||||
|
tracker = tmp_path / "delegation_tracker.json"
|
||||||
|
_write_tracker(tracker, []) # Golden Source: keine offenen Tasks
|
||||||
|
|
||||||
|
engine = _make_engine()
|
||||||
|
# Drift: delegate_subagent wurde fälschlich auf 1 gesetzt
|
||||||
|
# (durch den alten pgrep-False-Positive-Pfad).
|
||||||
|
engine.counters["delegate_subagent"] = 1
|
||||||
|
|
||||||
|
# pgrep simuliert den False-Positive: findet 1 Prozess
|
||||||
|
# (die eigene Session), obwohl kein echter Subagent läuft.
|
||||||
|
with patch.object(engine, "_get_tracker_path", return_value=str(tracker)), \
|
||||||
|
patch.object(engine, "_count_delegated_subagents", return_value=1):
|
||||||
|
engine._drift_correction()
|
||||||
|
|
||||||
|
# Taskliste gewinnt: GREEN_STATIC, nicht GREEN_PULSE.
|
||||||
|
assert engine.get_current_phase() == Phase.GREEN_STATIC
|
||||||
|
assert engine.counters["delegate_subagent"] == 0
|
||||||
|
|
||||||
|
def test_no_auto_increment_p063(self, tmp_path):
|
||||||
|
"""P-063: Drift-Korrektur inkrementiert NIE (kein Auto-Set).
|
||||||
|
|
||||||
|
delegate_subagent=0, Taskliste=1 (lebender PID). Die Drift-Korrektur
|
||||||
|
darf den Counter NICHT auf 1 setzen (P-063: nur Reset, nie Auto-Set).
|
||||||
|
"""
|
||||||
|
tracker = tmp_path / "delegation_tracker.json"
|
||||||
|
_write_tracker(tracker, [_running_entry(pid=os.getpid())])
|
||||||
|
|
||||||
|
engine = _make_engine()
|
||||||
|
# delegate_subagent=0 (kein Hook gefeuert)
|
||||||
|
assert engine.counters["delegate_subagent"] == 0
|
||||||
|
|
||||||
|
with patch.object(engine, "_get_tracker_path", return_value=str(tracker)), \
|
||||||
|
patch.object(engine, "_count_delegated_subagents", return_value=0):
|
||||||
|
engine._drift_correction()
|
||||||
|
|
||||||
|
# P-063: kein Auto-Inkrement — Counter bleibt 0.
|
||||||
|
assert engine.counters["delegate_subagent"] == 0
|
||||||
|
|
||||||
|
|
||||||
|
# ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
# STEP 3: Hook-Symmetrie (on_review_fork_close)
|
||||||
|
# ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
|
class TestReviewForkCloseHook:
|
||||||
|
"""on_review_fork_close → chat_profile -= 1 (idempotent)."""
|
||||||
|
|
||||||
|
def test_review_fork_close_decrements_chat_profile(self):
|
||||||
|
"""chat_profile=1 → on_review_fork_close → 0."""
|
||||||
|
engine = _make_engine()
|
||||||
|
engine.on_session_start() # chat_profile=1 (Review-Fork feuert on_session_start)
|
||||||
|
assert engine.counters["chat_profile"] == 1
|
||||||
|
|
||||||
|
engine.on_review_fork_close()
|
||||||
|
assert engine.counters["chat_profile"] == 0
|
||||||
|
|
||||||
|
def test_review_fork_close_idempotent(self):
|
||||||
|
"""Doppelter Aufruf → bleibt 0 (kein negativer Counter)."""
|
||||||
|
engine = _make_engine()
|
||||||
|
engine.on_review_fork_close() # chat_profile=0 → Clamp bei 0
|
||||||
|
engine.on_review_fork_close() # nochmal → bleibt 0
|
||||||
|
assert engine.counters["chat_profile"] == 0
|
||||||
|
|
||||||
|
def test_review_fork_close_returns_to_green_static(self):
|
||||||
|
"""Nach Review-Fork-Close: GREEN_STATIC (nicht GREEN_PULSE)."""
|
||||||
|
from plugin.archivar.presence_engine import Phase
|
||||||
|
|
||||||
|
engine = _make_engine()
|
||||||
|
engine.on_session_start() # GREEN_PULSE (chat_profile=1)
|
||||||
|
assert engine.get_current_phase() == Phase.GREEN_PULSE
|
||||||
|
|
||||||
|
engine.on_review_fork_close() # chat_profile=0 → GREEN_STATIC
|
||||||
|
assert engine.get_current_phase() == Phase.GREEN_STATIC
|
||||||
Reference in New Issue
Block a user