Skip to content

Bug: Invalid repository status 'indexed' causes 500 error when listing repositories #23

@Anthony-Bible

Description

@Anthony-Bible

Bug Description

When listing repositories via the /repositories endpoint, the API returns a 500 Internal Server Error because some repositories in the database have an invalid status value indexed that is not recognized by the domain layer.

Error Logs

time=2025-11-29T17:27:43.169-07:00 level=INFO msg="{\"timestamp\":\"2025-11-30T00:27:43Z\",\"level\":\"ERROR\",\"message\":\"Failed to convert to entity\",\"correlation_id\":\"c57f1b9b-4bba-4f76-af5a-c7295c497170\",\"component\":\"\",\"metadata\":{\"error\":\"invalid repository status: invalid repository status: indexed\",\"id\":\"e9873ca1-318e-458a-ac68-3208aee4aa72\"}}"

time=2025-11-29T17:27:43.169-07:00 level=INFO msg="{\"timestamp\":\"2025-11-30T00:27:43Z\",\"level\":\"ERROR\",\"message\":\"Failed to retrieve repositories from database\",\"correlation_id\":\"798c3e14-1013-4d1e-a13e-1c362ed7563f\",\"component\":\"\",\"metadata\":{\"error\":\"invalid repository status: invalid repository status: indexed\",\"filters\":{\"Status\":null,\"Name\":\"\",\"URL\":\"\",\"Limit\":20,\"Offset\":0,\"Sort\":\"created_at:desc\"}}}"

time=2025-11-29T17:27:43.169-07:00 level=INFO msg="{\"timestamp\":\"2025-11-30T00:27:43Z\",\"level\":\"ERROR\",\"message\":\"Repository service returned error\",\"correlation_id\":\"9d7a8372-9eb6-4aaf-a157-5eef79ea54c0\",\"component\":\"\",\"metadata\":{\"error\":\"failed to retrieve repositories: invalid repository status: invalid repository status: indexed\",\"query\":{\"Status\":\"\",\"Name\":\"\",\"URL\":\"\",\"Limit\":20,\"Offset\":0,\"Sort\":\"created_at:desc\"}}}"

time=2025-11-29T17:27:43.169-07:00 level=INFO msg="{\"timestamp\":\"2025-11-30T00:27:43Z\",\"level\":\"ERROR\",\"message\":\"Internal server error\",\"correlation_id\":\"6cbb05be-91dd-4d52-84e2-1c4187a8a93d\",\"component\":\"\",\"metadata\":{\"error\":\"failed to retrieve repositories: invalid repository status: invalid repository status: indexed\",\"path\":\"/repositories\",\"type\":\"internal\"}}"

Root Cause Analysis

The valid repository statuses defined in internal/domain/valueobject/repository_status.go are:

  • pending
  • cloning
  • processing
  • completed
  • failed
  • archived

However, some integration tests and possibly production data have repositories with status indexed, which is not in the valid status list.

Affected Test Files

Multiple integration tests insert repositories directly with status = 'indexed':

  • internal/adapter/outbound/repository/vector_storage_repository_integration_test.go (multiple occurrences)
  • internal/adapter/outbound/repository/chunk_repository_findorcreate_multirow_test.go (multiple occurrences)

Proposed Solutions

Option 1: Add indexed as a valid status (if semantically appropriate)

Add RepositoryStatusIndexed to the valid statuses in repository_status.go. This would be appropriate if indexed is a distinct state from completed.

Option 2: Update tests to use completed (recommended)

Replace all instances of "indexed" status in test files with "completed", which semantically represents a successfully indexed repository.

Option 3: Create a database migration

Create a migration to update any existing indexed status values to completed:

UPDATE codechunking.repositories SET status = 'completed' WHERE status = 'indexed';

Steps to Reproduce

  1. Run the integration tests which insert repositories with status = 'indexed'
  2. Call GET /repositories
  3. Observe 500 Internal Server Error

Impact

  • Severity: High - Completely breaks the repository listing functionality
  • Affected endpoint: GET /repositories
  • User impact: Unable to list or view repositories

Labels

bug, domain, data-integrity

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions