Skip to content

[Bug]: /health endpoint no longer returns user identity after #2503 refactor #2977

Description

@dfwgj

Bug Description

The /health endpoint no longer returns user identity information (role, account_id, user_id) when an API key is provided. This causes the frontend dashboard to display "Usage/Audit 未初始化,暂无实时统计" (Usage/Audit not initialized, no live stats available) even though the backend is functioning correctly.

The regression was introduced in commit fd73dcf2 (#2503) which removed the identity resolution logic from the health check endpoint.

Steps to Reproduce

  1. Start OpenViking with API key authentication:
    {
      "server": {
        "root_api_key": "your-api-key"
      }
    }
  2. Call the /health endpoint with an API key:
    curl -H "X-API-Key: your-api-key" http://localhost:1933/health
  3. Observe the response does not contain role, account_id, or user_id

Expected Behavior

The /health endpoint should return user identity information when a valid API key is provided:

{
  "status": "ok",
  "healthy": true,
  "version": "0.0.0+local",
  "auth_mode": "api_key",
  "account_id": "default",
  "user_id": "default",
  "role": "root"
}

This allows the frontend to determine the user's role and display the dashboard metrics.

Actual Behavior

The /health endpoint only returns basic status information:

{
  "status": "ok",
  "healthy": true,
  "version": "0.0.0+local.72d04cd4",
  "auth_mode": "api_key"
}

The missing role field causes the frontend to set connectionRole to 'unknown', which triggers the "Usage/Audit 未初始化" message on the dashboard.

Minimal Reproducible Example

The regression was introduced in commit `fd73dcf2` (#2503). Compare the health endpoint before and after:

**Before (commit `6f6d8464`):**

@router.get("/health", tags=["system"])
async def health_check(request: Request):
    result = {"status": "ok", "healthy": True, "version": __version__}
    
    # Try to get user identity
    try:
        x_api_key = request.headers.get("X-API-Key")
        authorization = request.headers.get("Authorization")
        
        if x_api_key or authorization:
            try:
                identity = await resolve_identity(
                    request,
                    x_api_key=x_api_key,
                    authorization=authorization,
                    ...
                )
                result["account_id"] = str(identity.account_id)
                result["user_id"] = str(identity.user_id)
                result["role"] = str(identity.role)
            except Exception as e:
                logger.warning(f"Failed to resolve identity: {e}")
    except Exception as e:
        logger.error(f"Failed to get health check: {e}")
    
    return result


**After (commit `fd73dcf2`):**

@router.get("/health", tags=["system"])
async def health_check(request: Request):
    """Health check endpoint (no authentication or identity resolution required)."""
    result = {"status": "ok", "healthy": True, "version": __version__}
    
    try:
        config = getattr(request.app.state, "config", None)
        effective_auth_mode = AuthMode.API_KEY.value
        if config is not None and hasattr(config, "get_effective_auth_mode"):
            effective_auth_mode = config.get_effective_auth_mode()
        result["auth_mode"] = effective_auth_mode
    except Exception as e:
        logger.error(f"Failed to get health check: {e}")
    
    return result
    # ❌ Identity resolution logic removed

Error Logs

Frontend behavior when `role` is missing:


// use-app-connection.tsx:226
role: isConnectionRole(data?.role) ? data.role : 'unknown',
// data?.role is undefined → role becomes 'unknown'

// route.tsx:87-88
const metricsUnavailable =
    (!isConnectionRoleLoading && connectionRole === 'unknown') ||
    isDisabledPayload(summary)
// connectionRole === 'unknown' → metricsUnavailable = true
// → Dashboard shows "Usage/Audit 未初始化"

OpenViking Version

main

Python Version

3.13

Operating System

Linux

Model Backend

None

Additional Context

This is a regression introduced by the recent "自进化(经验记忆)框架重构" (#2503) commit. The health endpoint's identity resolution was working correctly before this commit.

The frontend (web-studio/src/hooks/use-app-connection.tsx:200-228) relies on the /health endpoint to determine the user's role, which is used to gate dashboard metrics display.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions