Skip to content

fix: handle codebase search indexing state properly (#5662) #6118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

MuriloFP
Copy link
Collaborator

@MuriloFP MuriloFP commented Jul 23, 2025

Related GitHub Issue

Closes: #5662

Roo Code Task Context (Optional)

No Roo Code task context for this PR

Description

This PR addresses the issue where Roo would sometimes try to use semantic search even when indexing wasn't complete. The solution implements runtime state checking as suggested by @daniel-lxs in the issue comments.

Key implementation details:

  • The codebase_search tool is now always included in the tool list instead of being hidden
  • Added runtime state checking in the tool itself that provides user-friendly feedback
  • Different messages are shown for each indexing state (Standby, Indexing, Error)
  • Suggests using file reading tools (read_file, search_files) as alternatives when semantic search is unavailable
  • Removed the strict state check in the search service that was throwing errors

Design choice: Following the suggestion in the comments, I kept the tool always available and added runtime checks instead of hiding it. This makes state transitions smoother and helps users understand why semantic search isn't being used.

Test Procedure

Automated tests:

  • Added comprehensive unit tests in src/core/tools/__tests__/codebaseSearchTool.spec.ts
  • All tests pass: cd src && npx vitest run core/tools/__tests__/codebaseSearchTool.spec.ts
  • Existing tests still pass: cd src && npx vitest run core/prompts/sections/__tests__/

Manual testing:

  1. Disable code indexing in settings
  2. Try to use semantic search - should see a message about indexing being disabled
  3. Enable indexing but don't wait for it to complete
  4. Try to use semantic search - should see a message about indexing in progress
  5. Wait for indexing to complete
  6. Try to use semantic search - should work normally

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

No UI changes in this PR

Documentation Updates

  • No documentation updates are required.

Additional Notes

This implementation follows the approach suggested by @daniel-lxs in the issue comments. The tool remains available at all times but provides clear feedback about the indexing state, making the experience more transparent for users.

Get in Touch

@MuriloFP


Important

Improves codebase_search tool by adding runtime state checks for indexing, providing user feedback, and updating tests.

  • Behavior:
    • codebase_search tool now always included in tool list, with runtime state checks for user feedback.
    • Provides messages for indexing states: Standby, Indexing, Error.
    • Suggests alternative tools when semantic search is unavailable.
    • Removed strict state check in search-service.ts.
  • Tests:
    • Added unit tests in codebaseSearchTool.spec.ts for new state handling logic.
    • Tests cover all indexing states and feature configuration scenarios.
  • Misc:
    • Minor changes in index.ts to conditionally exclude codebase_search based on feature configuration.

This description was created by Ellipsis for 5ce9ea5. You can customize this summary. It will automatically update as commits are pushed.

MuriloFP and others added 25 commits July 3, 2025 15:26
- Always show codebase_search tool in the tool list
- Add runtime state checking with user-friendly feedback
- Provide clear messages for each indexing state (Standby, Indexing, Error)
- Suggest alternative tools when semantic search is unavailable
- Add comprehensive tests for the new behavior

This ensures Roo doesn't try to use semantic search when indexing
is incomplete and provides clear feedback to users about the current state.
@dosubot dosubot bot added the bug Something isn't working label Jul 23, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 23, 2025
- Only show codebase_search when feature is enabled AND configured
- Tool is now visible during indexing (Standby/Indexing states)
- Added test to verify tool availability during initialization
@MuriloFP
Copy link
Collaborator Author

MuriloFP commented Jul 23, 2025

Fixed the an issue pointed out. The codebase_search tool is now:

  • Hidden when the feature is disabled or not configured (as it should be)
  • Visible when the feature is enabled and configured, even if indexing is not complete
  • Provides runtime feedback about the indexing state when used

This maintains the original behavior for disabled/unconfigured states while adding the new runtime state checking for when indexing is in progress.

@MuriloFP MuriloFP marked this pull request as draft July 23, 2025 14:22
@MuriloFP MuriloFP marked this pull request as ready for review July 23, 2025 14:26
@MuriloFP MuriloFP moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jul 23, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Jul 23, 2025
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jul 23, 2025
@daniel-lxs daniel-lxs force-pushed the fix/issue-5662-codebase-search-indexing-state branch from 2ff2b04 to 5ce9ea5 Compare July 23, 2025 17:52
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Jul 23, 2025
Copy link
Collaborator

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @MuriloFP, I left some minor suggestions.

Let me know what you think

// Allow search during Indexing too
throw new Error(`Code index is not ready for search. Current state: ${currentState}`)
if (currentState === "Error") {
throw new Error(`Code index is in error state. Please check your configuration.`)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a facing error can we take the opportunity to internationalize it?

@@ -82,6 +82,33 @@ export async function codebaseSearchTool(
throw new Error("Code Indexing is not configured (Missing OpenAI Key or Qdrant URL).")
}

// Check indexing state at runtime
const indexingState = manager.state
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add telemetry here to track when users encounter non-indexed states? This could help understand how often users try to use semantic search before indexing is complete:

TelemetryService.instance.captureEvent(TelemetryEventName.CODE_INDEX_SEARCH_ATTEMPTED, {
  state: indexingState,
  query: query ? 'provided' : 'missing'
});

This would provide valuable insights into user behavior patterns.

const indexingState = manager.state
if (indexingState !== "Indexed") {
let stateMessage = ""
switch (indexingState) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider extracting the state message generation into a separate function for better maintainability and potential reuse:

function getIndexingStateMessage(state: IndexingState): string {
  switch (state) {
    case "Standby":
      return "Code indexing has not started yet. Please wait for the initial indexing to complete.";
    case "Indexing":
      return "Code indexing is currently in progress. Semantic search will be available once indexing is complete.";
    case "Error":
      return "Code indexing encountered an error. Please check your configuration and try again.";
    default:
      return `Code indexing is in an unexpected state: ${state}`;
  }
}

This would make it easier to update messages in one place and potentially reuse them in other parts of the codebase.

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Changes Requested] in Roo Code Roadmap Jul 23, 2025
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jul 23, 2025
- Added translations for codeIndex.errorState to all 17 language files
- Ensures consistent error messaging across all supported languages
@MuriloFP
Copy link
Collaborator Author

Hi @daniel-lxs, I've implemented all your suggestions:

  1. Internationalized the error message in search-service.ts

    • Added the translation key to English embeddings.json
    • Added translations to all 17 other language files
  2. Added telemetry tracking when users encounter non-indexed states

    • Using the existing TOOL_USED event with additional metadata
    • Tracks the indexing state and whether a query was provided
  3. Extracted state message generation into a separate function

    • Created getIndexingStateMessage() function for better maintainability
    • Makes it easier to update messages in one place
  4. Simplified the test cases to reduce redundancy

    • Combined the three separate state tests into a single parameterized test
    • Removed the incomplete test for hasQuery tracking

All tests are passing and CI checks are green. Thanks for the great suggestions!

@MuriloFP MuriloFP moved this from PR [Changes Requested] to PR [Needs Prelim Review] in Roo Code Roadmap Jul 23, 2025
!(codeIndexManager.isFeatureEnabled && codeIndexManager.isFeatureConfigured && codeIndexManager.isInitialized)
) {
// Note: We still show the tool when it's initialized but indexing is in progress
if (!codeIndexManager || !codeIndexManager.isFeatureEnabled || !codeIndexManager.isFeatureConfigured) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to also not show it if it's not finished indexing

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Changes Requested] in Roo Code Roadmap Jul 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working PR - Changes Requested size:XL This PR changes 500-999 lines, ignoring generated files.
Projects
Status: PR [Changes Requested]
Development

Successfully merging this pull request may close these issues.

Please add proper file search or reading guideline including indexing state context.
3 participants