Replaces LICENSE (GPLv3 -> AGPLv3) and prepends `SPDX-License-Identifier: AGPL-3.0-or-later` to every source file across decnet/, decnet_web/, tests/, scripts/, and tools/. Rationale: closes the GPLv3 ASP loophole so any party operating a modified DECNET as a network service must offer their modified source. Personal copyright (Samuel Paschuan) + inbound=outbound contributions make a future unilateral relicense infeasible. - LICENSE: full AGPL-3.0 text (gnu.org/licenses/agpl-3.0.txt) - COPYRIGHT: project copyright notice - tools/add_spdx_headers.py: idempotent header injector (shebang- and PEP 263-aware) Touches 1565 source files (.py, .ts, .tsx, .js, .jsx, .css, .sh). No behavior change; comments only.
60 lines
2.1 KiB
Python
60 lines
2.1 KiB
Python
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
"""LLM status surfaces in the orchestrator's heartbeat ``extra``.
|
|
|
|
Exposes the realism subsystem's LLM backend / model / circuit-breaker
|
|
state so the dashboard can render a status badge without poking
|
|
worker process memory.
|
|
|
|
Pinned by `feedback_push_principled_answer.md`: heartbeat is the
|
|
canonical worker self-report channel, so this rides the existing
|
|
``run_health_heartbeat(extra=...)`` extension hook rather than carving
|
|
a new bus topic.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from decnet.orchestrator.worker import _realism_health_snapshot
|
|
from decnet.realism.llm.circuit import LLMCircuitBreaker
|
|
|
|
|
|
class _FakeLLM:
|
|
model = "llama3.1:8b"
|
|
|
|
|
|
def test_snapshot_reports_disabled_when_no_llm():
|
|
snap = _realism_health_snapshot(llm=None, breaker=None)
|
|
assert snap == {
|
|
"llm_enabled": False,
|
|
"llm_backend": None,
|
|
"llm_model": None,
|
|
"llm_breaker_state": None,
|
|
}
|
|
|
|
|
|
def test_snapshot_carries_backend_model_breaker_state(monkeypatch):
|
|
monkeypatch.setenv("DECNET_REALISM_LLM", "ollama")
|
|
breaker = LLMCircuitBreaker(failure_threshold=2, cooldown_seconds=1.0)
|
|
snap = _realism_health_snapshot(llm=_FakeLLM(), breaker=breaker)
|
|
assert snap["llm_enabled"] is True
|
|
assert snap["llm_backend"] == "ollama"
|
|
assert snap["llm_model"] == "llama3.1:8b"
|
|
assert snap["llm_breaker_state"] == "closed"
|
|
|
|
|
|
def test_snapshot_reflects_open_breaker(monkeypatch):
|
|
monkeypatch.setenv("DECNET_REALISM_LLM", "ollama")
|
|
breaker = LLMCircuitBreaker(failure_threshold=2, cooldown_seconds=60.0)
|
|
breaker.record_failure()
|
|
breaker.record_failure()
|
|
snap = _realism_health_snapshot(llm=_FakeLLM(), breaker=breaker)
|
|
assert snap["llm_breaker_state"] == "open"
|
|
|
|
|
|
def test_snapshot_handles_llm_without_breaker(monkeypatch):
|
|
"""Defensive: if init left ``breaker=None`` for any reason, the
|
|
snapshot still publishes — just without breaker state."""
|
|
monkeypatch.setenv("DECNET_REALISM_LLM", "fake")
|
|
snap = _realism_health_snapshot(llm=_FakeLLM(), breaker=None)
|
|
assert snap["llm_enabled"] is True
|
|
assert snap["llm_backend"] == "fake"
|
|
assert snap["llm_breaker_state"] is None
|