Self-improving AI Employees for everyone
Python ai-agentsai-employeeai-employeesassistantautonomous-agentsco-employeescompanygrok-botinstinctloop-agentsmuseown-your-datapersonalself-hosted
fix(temporal): refresh_temporal_status accepts broadcaster arg + invariant lock
trohitg8d0c8ac520d4
diff --git a/server/services/temporal/_refresh.py b/server/services/temporal/_refresh.pyindex a32d8a1f..85180aa8 100644--- a/server/services/temporal/_refresh.py+++ b/server/services/temporal/_refresh.py@@ -11,10 +11,13 @@ this refresh callback and ``_handlers.py``'s WS commands."""from __future__ import annotations-from typing import Any+from typing import TYPE_CHECKING, Anyfrom core.logging import get_logger+if TYPE_CHECKING:+ from services.status_broadcaster import StatusBroadcaster+logger = get_logger(__name__)@@ -38,11 +41,16 @@ def temporal_status_snapshot() -> dict[str, Any]:}-async def refresh_temporal_status() -> None:- """Broadcast the Temporal + Postgres status snapshots on WS connect."""- from services.status_broadcaster import get_status_broadcaster+async def refresh_temporal_status(broadcaster: "StatusBroadcaster") -> None:+ """Broadcast the Temporal + Postgres status snapshots on WS connect.- broadcaster = get_status_broadcaster()+ Signature matches the ``register_service_refresh`` callback contract+ — :meth:`StatusBroadcaster._refresh_all_services` invokes every+ registered callback as ``callback(self)`` (passes the broadcaster+ as the sole positional argument). Without the parameter the+ framework's ``TaskGroup`` swallows a ``TypeError: takes 0 positional+ arguments but 1 was given`` on every server boot.+ """await broadcaster.broadcast({"type": "temporal_status","data": temporal_status_snapshot(),diff --git a/server/tests/test_status_broadcasts.py b/server/tests/test_status_broadcasts.pyindex 58da30e1..8a3343f0 100644--- a/server/tests/test_status_broadcasts.py+++ b/server/tests/test_status_broadcasts.py@@ -491,6 +491,79 @@ class TestSendCustomEventPayload:)+# ============================================================================+# 5) Service-refresh callback signature contract+# ============================================================================+++class TestServiceRefreshCallbackSignature:+ """``StatusBroadcaster._refresh_all_services`` invokes every callback+ registered via ``register_service_refresh`` as ``callback(self)`` — the+ broadcaster is passed as the sole positional argument.++ Regression: a callback declared ``async def refresh() -> None`` (no+ args) crashes at refresh-fan-out time with ``TypeError: takes 0+ positional arguments but 1 was given``. The TaskGroup swallows the+ exception and logs at WARNING, so the broken callback never throws+ loudly — observed in prod for ``refresh_temporal_status`` until the+ Wave 13 follow-up. This invariant catches the shape mismatch at+ test time so future refresh registrations can't reintroduce it.+ """++ def test_every_registered_callback_accepts_one_positional_arg(self):+ import inspect++ # Importing the broadcaster module triggers plugin-side+ # ``register_service_refresh(...)`` calls via the standard+ # plugin import side-effects.+ from services.status_broadcaster import _SERVICE_REFRESH_CALLBACKS++ offenders: list[str] = []+ for cb in list(_SERVICE_REFRESH_CALLBACKS):+ try:+ sig = inspect.signature(cb)+ except (TypeError, ValueError): # pragma: no cover — defensive+ offenders.append(f"{cb!r} (couldn't introspect)")+ continue++ params = [+ p for p in sig.parameters.values()+ if p.kind in (+ inspect.Parameter.POSITIONAL_ONLY,+ inspect.Parameter.POSITIONAL_OR_KEYWORD,+ )+ ]+ required = [p for p in params if p.default is inspect.Parameter.empty]+ # Must accept at least one positional arg (the broadcaster);+ # additional defaults are fine, varargs (*args) is fine.+ accepts_one_positional = (+ any(+ p.kind == inspect.Parameter.VAR_POSITIONAL+ for p in sig.parameters.values()+ )+ or len(params) >= 1+ )+ # Must NOT require MORE than one positional — the framework+ # only supplies the broadcaster, nothing else.+ too_many_required = len(required) > 1++ if not accepts_one_positional or too_many_required:+ offenders.append(+ f"{cb.__module__}.{cb.__qualname__}{sig}"+ )++ assert not offenders, (+ f"register_service_refresh callbacks must accept the "+ f"StatusBroadcaster as their sole positional argument: "+ f"``async def refresh(broadcaster) -> None``. These "+ f"violate that contract: {offenders}. The framework calls "+ f"each callback as ``callback(self)`` inside "+ f"``StatusBroadcaster._refresh_all_services`` — a 0-arg "+ f"callback raises ``TypeError: takes 0 positional arguments "+ f"but 1 was given`` and the TaskGroup swallows it at WARNING."+ )++# ============================================================================# Module-private helpers (used by the test bodies above)# ============================================================================