diff --git a/contextual_orchestrator/cost_ledger.py b/contextual_orchestrator/cost_ledger.py index 3866396dc..79f8f9264 100644 --- a/contextual_orchestrator/cost_ledger.py +++ b/contextual_orchestrator/cost_ledger.py @@ -330,6 +330,7 @@ class NoopUsageTelemetrySink: """Default sink for callers that do not wire telemetry yet.""" def emit_usage(self, event: UsageTelemetryEvent) -> None: + """Discard prompt-safe usage telemetry when export is not configured.""" return None @@ -342,12 +343,14 @@ def __init__(self, max_events: int = 512) -> None: self._lock = threading.Lock() def emit_usage(self, event: UsageTelemetryEvent) -> None: + """Retain the newest prompt-safe usage events up to the configured limit.""" with self._lock: self._events.append(event) if len(self._events) > self._max_events: del self._events[: len(self._events) - self._max_events] def events(self) -> List[UsageTelemetryEvent]: + """Return a snapshot of the retained usage telemetry events.""" with self._lock: return list(self._events) @@ -363,6 +366,7 @@ class UsageTelemetryHealth: last_error_type: Optional[str] = None def as_dict(self) -> Dict[str, Any]: + """Return operator-safe health counters as a serializable mapping.""" return { "records_accepted": self.records_accepted, "records_stored": self.records_stored, @@ -442,6 +446,7 @@ def flush(self, timeout: Optional[float] = None) -> bool: return True def telemetry_health(self) -> Dict[str, Any]: + """Return current asynchronous ledger persistence and export health.""" with self._lock: return self._health.as_dict() diff --git a/contextual_orchestrator/server.py b/contextual_orchestrator/server.py index e4d60a576..7b1dac943 100644 --- a/contextual_orchestrator/server.py +++ b/contextual_orchestrator/server.py @@ -4441,7 +4441,10 @@ def build_server( clearfolio_url = clearfolio_url.rstrip("/") class Handler(BaseHTTPRequestHandler): + """Handle authenticated orchestration, administration, and health routes.""" + def do_GET(self) -> None: # noqa: N802 + """Dispatch GET requests after applying the route's authorization scope.""" parsed = urllib.parse.urlparse(self.path) path = parsed.path query = urllib.parse.parse_qs(parsed.query) @@ -4791,6 +4794,7 @@ def do_GET(self) -> None: # noqa: N802 self._send_error(500, "internal_error", "internal server error") def do_PATCH(self) -> None: # noqa: N802 + """Apply an authenticated agent-pool worker update.""" try: self._authorize("admin") path = urllib.parse.urlparse(self.path).path @@ -4814,6 +4818,7 @@ def do_PATCH(self) -> None: # noqa: N802 self._send_error(500, "internal_error", "internal server error") def do_DELETE(self) -> None: # noqa: N802 + """Delete an authenticated agent-pool worker resource.""" try: self._authorize("admin") path = urllib.parse.urlparse(self.path).path @@ -4834,6 +4839,7 @@ def do_DELETE(self) -> None: # noqa: N802 self._send_error(500, "internal_error", "internal server error") def do_POST(self) -> None: # noqa: N802 + """Dispatch authenticated completion, agent, and simulation writes.""" try: path = urllib.parse.urlparse(self.path).path scope = "admin" if path == "/admin/simulate" or path.startswith("/api/v1/agent_pools/") else "inference" @@ -5684,6 +5690,7 @@ def _read_json(self) -> dict[str, Any]: return _coerce_json(raw) if raw else {} def log_message(self, format: str, *args: object) -> None: + """Suppress default request logging to keep service output structured.""" return def _send_error(