mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
Fix: open findings cleanup (#122)
* refactor(usage): remove the unconsumed per-agent USAGE_UPDATE event USAGE_UPDATE was published per active agent each sweep, bridged, and broadcast to /ws/system, but no panel client ever consumed it — the dashboard reads only the aggregate USAGE_SNAPSHOT. Every emission was wasted event-bus and WebSocket traffic. Drop the UsageUpdate payload, publish_usage_update and its throttle, the EventType member, and the bridge subscription. Keep USAGE_SNAPSHOT, which already carries the per-agent breakdown, so no live data is lost. * refactor(prompter): remove the legacy local-LLM HTTP endpoints The panel uses only the live SDK-intake path (/prompter/live/*); the legacy /prompter/chat, /draft and /sessions/* endpoints — backed by the local Ollama LLM with hardcoded prompts — had no remaining caller. Remove the router, its mount in app.py, and its integration test. The live router and the shared draft-confirmation service are untouched. * refactor(prompter): drop the dead legacy local-LLM service + schemas With the legacy HTTP endpoints gone, the local-LLM chat/draft/session methods, their prompt constants, the ConfirmOverrides/TurnResult dataclasses, and the entire prompter schema module had no production caller (only their own tests). Remove them, keeping the live-intake path: create_task_from_draft / confirm_live_draft, the enum/priority/team coercion, and the pure description/readiness helpers. * refactor(agents): stop granting the Task sub-agent tool to roles Every agent role was granted the built-in Task tool, but no role prompt or workflow uses it and there are no custom sub-agent definitions — so a Task call only spawns a context-blind generic sub-agent that burns budget (ToolSearch, the comment's stated use, is MCP-only and not callable in agent containers). Drop Task from all three grant points in lockstep: the --tools spawn flag and both _ROLE_BUILTIN_TOOLS maps (system-prompt + briefing layers), with a regression guard added to each layer's test. --------- Co-authored-by: Renn F <rennf93@users.noreply.github.com>
This commit is contained in:
@@ -1,21 +1,15 @@
|
||||
"""
|
||||
Usage Event Publisher
|
||||
|
||||
Throttled helpers for publishing USAGE_UPDATE and USAGE_SNAPSHOT events
|
||||
to the StreamEventBus. Consumed by the orchestrator token sweep and
|
||||
forwarded to /ws/system WebSocket clients via the websocket_bridge.
|
||||
Helper for publishing USAGE_SNAPSHOT aggregate events to the StreamEventBus.
|
||||
Consumed by the orchestrator token sweep and forwarded to /ws/system WebSocket
|
||||
clients via the websocket_bridge.
|
||||
|
||||
Throttle window: one USAGE_UPDATE publish per agent per 5-second window.
|
||||
Subsequent calls within the window are silently dropped so a frequent
|
||||
sweep loop cannot flood the event bus or WebSocket clients.
|
||||
|
||||
USAGE_SNAPSHOT is always published (no per-agent throttle) — it is an
|
||||
aggregate and published at most once per sweep cycle.
|
||||
USAGE_SNAPSHOT is an aggregate, published at most once per sweep cycle.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import time
|
||||
from dataclasses import dataclass
|
||||
from datetime import UTC, datetime
|
||||
from typing import TYPE_CHECKING, Any
|
||||
@@ -23,64 +17,6 @@ from typing import TYPE_CHECKING, Any
|
||||
if TYPE_CHECKING:
|
||||
from roboco.events.stream_bus import StreamEventBus
|
||||
|
||||
_THROTTLE_WINDOW_SECONDS: float = 5.0
|
||||
|
||||
|
||||
class _UsageThrottle:
|
||||
"""Per-agent last-publish timestamp tracker.
|
||||
|
||||
Uses ``time.monotonic()`` so clock adjustments (NTP, DST) don't cause
|
||||
spurious suppressions or double-fires.
|
||||
"""
|
||||
|
||||
def __init__(self, window: float = _THROTTLE_WINDOW_SECONDS) -> None:
|
||||
self._window = window
|
||||
self._last: dict[str, float] = {}
|
||||
|
||||
def should_publish(self, agent_id: str) -> bool:
|
||||
"""Return True if the agent is outside the throttle window.
|
||||
|
||||
Also records the current monotonic time as the new *last published*
|
||||
timestamp when it returns True, so the caller does not need to call a
|
||||
separate ``record()`` method.
|
||||
"""
|
||||
now = time.monotonic()
|
||||
if now - self._last.get(agent_id, 0.0) >= self._window:
|
||||
self._last[agent_id] = now
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
# Module-level singleton — shared across all callers in this process.
|
||||
_throttle = _UsageThrottle()
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class UsageUpdate:
|
||||
"""Per-agent cumulative token counts carried by a USAGE_UPDATE event.
|
||||
|
||||
Fields map directly onto the event payload the panel consumes (the
|
||||
backend emits these per active agent during the token sweep).
|
||||
"""
|
||||
|
||||
agent_id: str
|
||||
task_id: str | None
|
||||
input_tokens: int
|
||||
output_tokens: int
|
||||
model: str
|
||||
timestamp: datetime | None = None
|
||||
|
||||
def event_data(self) -> dict[str, Any]:
|
||||
"""Render the event payload, stamping ``timestamp`` if not supplied."""
|
||||
return {
|
||||
"agent_id": self.agent_id,
|
||||
"task_id": self.task_id,
|
||||
"input_tokens": self.input_tokens,
|
||||
"output_tokens": self.output_tokens,
|
||||
"model": self.model,
|
||||
"timestamp": (self.timestamp or datetime.now(UTC)).isoformat(),
|
||||
}
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class UsageSnapshot:
|
||||
@@ -108,20 +44,6 @@ class UsageSnapshot:
|
||||
}
|
||||
|
||||
|
||||
async def publish_usage_update(bus: StreamEventBus, update: UsageUpdate) -> bool:
|
||||
"""Publish a USAGE_UPDATE event if the per-agent throttle window has elapsed.
|
||||
|
||||
Returns True if the event was published; False if suppressed by the throttle.
|
||||
"""
|
||||
if not _throttle.should_publish(update.agent_id):
|
||||
return False
|
||||
|
||||
from roboco.models.events import Event, EventType # lazy — avoids circular import
|
||||
|
||||
await bus.publish(Event(type=EventType.USAGE_UPDATE, data=update.event_data()))
|
||||
return True
|
||||
|
||||
|
||||
async def publish_usage_snapshot(bus: StreamEventBus, snapshot: UsageSnapshot) -> None:
|
||||
"""Publish a USAGE_SNAPSHOT aggregate event (no throttle)."""
|
||||
from roboco.models.events import Event, EventType # lazy — avoids circular import
|
||||
|
||||
Reference in New Issue
Block a user