ruvnet/RuView · error · HTTPException

An internal error occurred. Please try again later.

Error message

An internal error occurred. Please try again later.

What it means

Catch-all on GET /stream/status in archive/v1/src/api/routers/stream.py. The handler merges stream_service.get_status() with connection_manager.get_connection_stats() and builds a StreamStatus response. A likely failure is built into the response assembly itself: `connections.get("total_clients", status["connections"]["active"])` and `status["buffers"]["pose_buffer_size"]` use hard bracket lookups, so a status dict missing 'connections' or 'buffers.pose_buffer_size' raises KeyError, which is swallowed and returned as HTTP 500 logged as 'Error getting stream status'. Note this route has no auth dependency.

Source

Thrown at archive/v1/src/api/routers/stream.py:353

        # Calculate uptime (simplified for now)
        uptime_seconds = 0.0
        if status.get("running", False):
            uptime_seconds = 3600.0  # Default 1 hour for demo
        
        return StreamStatus(
            is_active=status.get("running", False),
            connected_clients=connections.get("total_clients", status["connections"]["active"]),
            streams=[{
                "type": "pose_stream",
                "active": status.get("running", False),
                "buffer_size": status["buffers"]["pose_buffer_size"]
            }],
            uptime_seconds=uptime_seconds
        )
        
    except Exception as e:
        logger.error(f"Error getting stream status: {e}")
        raise HTTPException(
            status_code=500,
            detail="An internal error occurred. Please try again later."
        )


@router.post("/start")
async def start_streaming(
    stream_service: StreamService = Depends(get_stream_service),
    current_user: Dict = Depends(require_auth)
):
    """Start the streaming service."""
    try:
        logger.info(f"Starting streaming service by user: {current_user['id']}")
        
        if await stream_service.is_active():
            return JSONResponse(
                status_code=200,
                content={"message": "Streaming service is already active"}

View on GitHub (pinned to 4685618388)

Solutions

  1. Read the server log line 'Error getting stream status: {e}' — it is usually a KeyError naming the missing key
  2. Confirm stream_service.get_status() returns 'connections' (with 'active') and 'buffers' (with 'pose_buffer_size')
  3. Replace the hard bracket lookups with .get() defaults (e.g., status.get("connections", {}).get("active", 0)) so a sparse status dict degrades gracefully
  4. If StreamStatus validation is the cause, align the response_model fields with what the service actually returns

Example fix

# before
connected_clients=connections.get("total_clients", status["connections"]["active"]),
streams=[{"type": "pose_stream", "active": status.get("running", False), "buffer_size": status["buffers"]["pose_buffer_size"]}],

# after
connected_clients=connections.get("total_clients", status.get("connections", {}).get("active", 0)),
streams=[{"type": "pose_stream", "active": status.get("running", False), "buffer_size": status.get("buffers", {}).get("pose_buffer_size", 0)}],
Defensive patterns

Strategy: retry

Validate before calling

import httpx

# probe the cheaper, dependency-free liveness path before relying on /status
resp = httpx.get(f"{API}/stream/status", timeout=5)
assert resp.status_code != 500 or retry_once(), "status assembly failing server-side"

Type guard

def status_response_ok(resp: httpx.Response) -> bool:
    if resp.status_code != 200:
        return False
    body = resp.json()
    return isinstance(body.get("connected_clients"), int) and isinstance(body.get("streams"), list)

Try / catch

for attempt in range(2):
    try:
        resp = httpx.get(f"{API}/stream/status", timeout=5)
        if resp.status_code == 200:
            break
    except httpx.RequestError:
        continue
else:
    raise RuntimeError("stream status unavailable after retry")

Prevention

When it happens

Trigger: GET /stream/status when stream_service.get_status() returns a dict without the 'connections' key (so the .get() fallback itself raises KeyError); status lacking 'buffers.pose_buffer_size'; connection_manager.get_connection_stats() raising; StreamStatus model validation failing on the constructed payload.

Common situations: Calling status before the streaming service was ever started, so its internal status dict is partially initialized; schema drift between StreamService.get_status() and this router after an upgrade; Pydantic StreamStatus rejecting a field type (e.g., connected_clients=None when connection stats are unavailable).

Related errors


AI-assisted analysis of ruvnet/RuView@4685618388 (2026-08-16). Data as JSON: /api/errors/dc354099d631f66a. Report an issue: GitHub.