Skip to content

Fix Add Index functionality #2

@jsbattig

Description

@jsbattig

Bug Description

The "Add Index" functionality in the Golden Repos admin UI only offers "Semantic + FTS" as a combined option. Users cannot add Semantic or FTS indexes independently. When a repo already has FTS (but not Semantic), selecting "Semantic + FTS" errors because FTS already exists.

Environment

  • Version: $(git describe --tags --always 2>/dev/null || echo "current")
  • OS: Linux
  • Component: CIDX Server Web UI - Golden Repos management page
  • Discovered In: stepscommand repo (has FTS only, needed to add Semantic)

Steps to Reproduce

  1. Have a golden repo with FTS index only (no Semantic) - e.g., stepscommand repo
  2. Navigate to Golden Repos admin page
  3. Click "Details" to expand the repo
  4. Click "Add Index" button
  5. Observe: Only "Semantic + FTS" option is available (no "Semantic only" option)
  6. Select "Semantic + FTS" and click Submit
  7. Error occurs because FTS already exists

Expected Behavior

  • Should be able to add Semantic, FTS, Temporal, and SCIP indexes independently
  • Should be able to rebuild/recreate existing indexes
  • Should be able to select multiple indexes to create at once
  • Confirmation dialog should warn differently when rebuilding vs creating new

Actual Behavior

  • Only combined "Semantic + FTS" option exists
  • Cannot add Semantic alone when FTS exists
  • Cannot rebuild existing indexes (blocked by _index_exists() check)
  • No granular control over individual index types

Error Messages / Logs

ValueError: Index type 'semantic_fts' already exists for golden repo 'stepscommand'

(Error occurs in golden_repo_manager.py line 1806-1808 when FTS exists but Semantic doesn't)

Impact Assessment

Severity: High - Blocks core admin workflow
Affected Users: All admins managing golden repositories
Frequency: Every time user needs to add a single index type when partial indexes exist
Workaround: None - cannot add missing index independently through UI

Root Cause Analysis

UI Layer (golden_repos_list.html:178-181)

{% if not (repo.has_semantic and repo.has_fts) %}
<option value="semantic_fts">Semantic + FTS</option>
{% endif %}

Only offers combined option, no individual Semantic or FTS choices.

Backend Layer (golden_repo_manager.py)

  1. Valid types restricted (line 1797):
valid_index_types = ["semantic_fts", "temporal", "scip"]
  1. Existence check blocks rebuild (line 1805-1808):
if self._index_exists(golden_repo, index_type):
    raise ValueError(f"Index type '{index_type}' already exists...")
  1. _index_exists() uses AND logic (line 1927-1946):
    Returns True only when BOTH semantic AND FTS exist, but error is thrown when either exists during creation.

  2. Combined creation (line 1824-1825):

if index_type == "semantic_fts":
    command = ["cidx", "index", "--fts"]  # Creates BOTH indexes

Affected Files

  • src/code_indexer/server/web/templates/partials/golden_repos_list.html - UI dropdown
  • src/code_indexer/server/web/static/js/golden_repo_indexes.js - JS submission logic
  • src/code_indexer/server/repositories/golden_repo_manager.py - Backend validation and creation
  • src/code_indexer/server/app.py - AddIndexRequest model, valid_index_types validation

Fix Implementation

Changes Required

1. Backend (golden_repo_manager.py)

  • Change valid index types to: ["semantic", "fts", "temporal", "scip"]
  • Remove semantic_fts combined type entirely (no backwards compatibility)
  • Update CLI command mapping:
    • semantic -> cidx index (no --fts flag)
    • fts -> cidx index --rebuild-fts-index
    • temporal -> cidx index --index-commits ...
    • scip -> cidx scip generate
  • Remove _index_exists() blocker - allow rebuilding
  • Support multiple index types per request (List instead of single string)

2. API (app.py)

  • Update AddIndexRequest model to accept index_types: List[str]
  • Update valid_index_types validation

3. UI (golden_repos_list.html)

  • Replace dropdown with multi-select checkboxes
  • Always show all 4 options: Semantic, FTS, Temporal, SCIP
  • Indicate existing indexes with "(rebuild)" label
  • Allow selecting multiple indexes at once

4. JavaScript (golden_repo_indexes.js)

  • Update to collect multiple selected checkboxes
  • Update confirmation dialog:
    • New indexes: "Add [types] index to repository?"
    • Rebuilds: "This will rebuild the existing [types] index. Continue?"
    • Mixed: Show both clearly
  • Update request body to send array: { index_types: [...] }

Testing Required

  • Unit tests for new index types validation
  • Unit tests for multi-select request handling
  • Integration tests for each index type creation
  • E2E test: Add semantic when FTS exists
  • E2E test: Rebuild existing index
  • E2E test: Multi-select index creation

Implementation Status

  • Core fix implemented
  • Tests added and passing
  • Code review approved
  • Manual testing completed
  • Documentation updated
  • Regression tests added

Completion: 0/6 tasks complete (0%)

Verification Evidence

[To be added after fix]


Reported By: Claude Code
Assigned To: [Unassigned]
Found In: current master branch
Fixed In: [To be updated]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions