Skip to content

fix(stats): do not hide metadata query failures as successful zero counts #49

Closed

Description

@spelech

Finding

GET /admin/api/stats turns relational query failures into successful zero counts. Missing/broken application metadata is indistinguishable from a healthy, empty index in the dashboard and API.

Related reproducer: #45. Fixing selected-database access does not eliminate the need to distinguish failed queries from legitimate empty results.

Observed evidence

At source revision 41ec093a745f1c0277893dc8f758b96b216c970f, an isolated full-PostgreSQL deployment initialized its PostgreSQL schema and healthy pgvector backend, but legacy metadata queries opened an empty SQLite database.

Authenticated /admin/api/repos returned HTTP 500 with no such table: git_repositories logged. Indexing and polling also logged missing-table failures.

In the same state, authenticated GET /admin/api/stats returned HTTP 200:

{
  "files_count": 0,
  "git_repos": 0,
  "local_paths": 0,
  "total_symbols": 0,
  "total_routes": 0,
  "total_relationships": 0,
  "vector_db_status": "Healthy"
}

These zeros are not successful count-query results: the local _count() helper catches every query exception and returns 0.

Expected outcome

  • Distinguish genuine zero counts from failed/unavailable counts.
  • Required relational query failures should produce the API's explicit error response, or a deliberately documented degraded result with unavailable counts and visible error state; do not silently substitute zero.
  • Log useful, sanitized diagnostics and make the failure visible to the dashboard.
  • Do not report the entire application as healthy just because its vector backend is healthy.

Acceptance checks

Activity

  1. spelech commented on Oct 27, 2026

    @spelech
    OwnerAuthor

    Triage & Implementation Brief

    1. Scope & Effort

    • Effort: Small (~25 lines of code + test)
    • Component: Settings API / Observability

    2. Root Cause & Context

    In app/api/routers/settings.py, the internal _count() helper catches all query exceptions and returns 0. When the relational database is broken or missing tables, GET /admin/api/stats returns HTTP 200 with all zero counts and reports vector_db_status: "Healthy", masking database faults.

    3. Implementation Plan

    • Refactor _count() in settings.py to distinguish between a successful zero count and an execution failure.
    • On database failure, return an explicit error response (HTTP 500) or a structured degraded response where unavailable counts are null and a failure indicator is present.
    • Ensure vector_db_status does not cause the entire service to report healthy if relational metadata is failing.

    4. Acceptance Criteria

  2. google-labs-jules commented on Oct 27, 2026

    @google-labs-jules
    Contributor

    Jules is on it. When finished, you will see another comment and be able to review a PR.

  3. google-labs-jules commented on Oct 27, 2026

    @google-labs-jules
    Contributor

    Ready for a review! A PR has been created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    julesgoogle-jules-bot

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions