V9.0.1: Sync-Hooks — invoke_hook() limitation fix
Root Cause: invoke_hook() im Core ruft Callbacks synchron auf (ret = cb(**kwargs)). Async-Callbacks wurden als Coroutine-Objekt zurückgegeben aber nie awaited → Hook-Code wurde NIE ausgeführt. Symptom: Andreas sah immer nur GRÜN (Hooks registriert, feuerten nie). Änderungen: - presence_engine.py: Alle Hook-Callbacks synchron (kein async/await) - Counter-Mutation unter threading.Lock (statt asyncio.Lock) - REST-Calls via fire-and-forget Daemon-Threads (statt asyncio.create_task) - away-grace via threading.Timer (statt asyncio.Task) - _rest_set_status() synchron (urllib ist von Natur aus sync) - __init__.py: Wrapper-Funktionen synchron (kein async def) - adapter.py: bind_loop() für PresenceEngine entfernt (nicht mehr nötig) - Tests: Alle 39 V9-Tests auf sync umgestellt (kein asyncio, kein await) Tests: 39 passed, 82 skipped in 3.24s
This commit is contained in:
+24
-19
@@ -200,11 +200,16 @@ def _register_presence_hooks() -> None:
|
||||
|
||||
try:
|
||||
# ── Wrapper: Holt die PresenceEngine via _active_adapter ──────────
|
||||
async def _get_engine_and_call(method_name: str, **kwargs):
|
||||
# V9.0.1: SYNCHRON — invoke_hook() im Core ruft Callbacks via
|
||||
# ret = cb(**kwargs) auf. Async-Callbacks würden als Coroutine-Objekt
|
||||
# zurückgegeben aber nie awaited → Hook-Code wird NIE ausgeführt.
|
||||
def _get_engine_and_call(method_name: str, **kwargs):
|
||||
"""Hole PresenceEngine aus dem aktiven Adapter und rufe Methode auf.
|
||||
|
||||
Nutzt die Modul-Level-Referenz _active_adapter (F1.1: offizielle
|
||||
API statt privater ctx._adapter/ctx._platforms).
|
||||
|
||||
V9.0.1: Synchron — invoke_hook() erwartet sync-Callbacks.
|
||||
"""
|
||||
try:
|
||||
adapter = _active_adapter
|
||||
@@ -215,35 +220,35 @@ def _register_presence_hooks() -> None:
|
||||
return
|
||||
method = getattr(engine, method_name, None)
|
||||
if method is not None:
|
||||
await method(**kwargs)
|
||||
method(**kwargs)
|
||||
except Exception as e:
|
||||
logger.debug("[presence-v9] Hook %s fehlgeschlagen: %s", method_name, e)
|
||||
|
||||
# ── 6 Core-Hooks ──────────────────────────────────────────────────
|
||||
async def _on_pre_gateway_dispatch(**kwargs):
|
||||
await _get_engine_and_call("on_pre_gateway_dispatch", **kwargs)
|
||||
# ── 6 Core-Hooks (V9.0.1: synchron) ──────────────────────────────
|
||||
def _on_pre_gateway_dispatch(**kwargs):
|
||||
_get_engine_and_call("on_pre_gateway_dispatch", **kwargs)
|
||||
|
||||
async def _on_post_llm_call(**kwargs):
|
||||
await _get_engine_and_call("on_post_llm_call", **kwargs)
|
||||
def _on_post_llm_call(**kwargs):
|
||||
_get_engine_and_call("on_post_llm_call", **kwargs)
|
||||
|
||||
async def _on_subagent_start(**kwargs):
|
||||
await _get_engine_and_call("on_subagent_start", **kwargs)
|
||||
def _on_subagent_start(**kwargs):
|
||||
_get_engine_and_call("on_subagent_start", **kwargs)
|
||||
|
||||
async def _on_subagent_stop(**kwargs):
|
||||
await _get_engine_and_call("on_subagent_stop", **kwargs)
|
||||
def _on_subagent_stop(**kwargs):
|
||||
_get_engine_and_call("on_subagent_stop", **kwargs)
|
||||
|
||||
async def _on_session_start(**kwargs):
|
||||
await _get_engine_and_call("on_session_start", **kwargs)
|
||||
def _on_session_start(**kwargs):
|
||||
_get_engine_and_call("on_session_start", **kwargs)
|
||||
|
||||
async def _on_session_end(**kwargs):
|
||||
await _get_engine_and_call("on_session_end", **kwargs)
|
||||
def _on_session_end(**kwargs):
|
||||
_get_engine_and_call("on_session_end", **kwargs)
|
||||
|
||||
# ── 2 Tool-Filter-Hooks (O-1: Background-Terminal-Workaround) ─────
|
||||
async def _on_pre_tool_call(**kwargs):
|
||||
await _get_engine_and_call("on_pre_tool_call", **kwargs)
|
||||
def _on_pre_tool_call(**kwargs):
|
||||
_get_engine_and_call("on_pre_tool_call", **kwargs)
|
||||
|
||||
async def _on_post_tool_call(**kwargs):
|
||||
await _get_engine_and_call("on_post_tool_call", **kwargs)
|
||||
def _on_post_tool_call(**kwargs):
|
||||
_get_engine_and_call("on_post_tool_call", **kwargs)
|
||||
|
||||
# ── Registrierung via offizielle API ──────────────────────────────
|
||||
ctx.register_hook("pre_gateway_dispatch", _on_pre_gateway_dispatch)
|
||||
|
||||
Reference in New Issue
Block a user