Skip to content

Conversation

@MuriloFP
Copy link
Contributor

@MuriloFP MuriloFP commented Jul 3, 2025

fix: correct export/import of OpenAI Compatible codebase indexing settings (#5035)

Related GitHub Issue

Closes: #5035
Closes: #4962
Closes: #5091

Roo Code Task Context (Optional)

Description

This PR fixes the export/import functionality for OpenAI Compatible codebase indexing settings. The issue was that exported settings were missing the codebaseIndexEmbedderModelDimension property and contained an incorrect codebaseIndexEmbedderBaseUrl.

Key implementation details:

  • Modified exportSettings function to correctly fetch OpenAI Compatible settings from global state instead of provider profiles
  • Added missing codebaseIndexEmbedderModelDimension property to the codebaseIndexConfigSchema type definition
  • Updated test mocking strategy to properly mock contextProxy.getGlobalState calls

Design choice: The fix maintains the existing architecture where OpenAI Compatible indexing settings are stored in global state rather than provider profiles, ensuring consistency with the current implementation.

Test Procedure

Automated Testing:

  • Added new test case specifically for OpenAI Compatible export functionality
  • Updated 8 existing tests to align with the corrected implementation
  • All 2643 tests pass successfully

Manual Testing Steps:

  1. Configure OpenAI Compatible provider for codebase indexing with custom base URL and model dimension
  2. Export settings via Settings > Import/Export > Export Settings
  3. Verify exported JSON contains both codebaseIndexEmbedderBaseUrl and codebaseIndexEmbedderModelDimension
  4. Import the exported settings on a fresh instance
  5. Verify all OpenAI Compatible settings are correctly restored

Test Commands:

cd src
npx vitest core/config/__tests__/importExport.spec.ts

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

Documentation Updates

Additional Notes

This fix ensures that users can properly export and import their OpenAI Compatible codebase indexing configurations, including custom base URLs and model dimensions. The bug was caused by the export function looking for these settings in the wrong location (provider profiles instead of global state).

I had some extra issues with this PR because the import/export settings were not properly updating the UI state and the OpenAI Compatible Provider specific fields... The tests were created to ensure that these work correctly.

Get in Touch

@MuriloFP


Important

Fixes export/import of OpenAI Compatible codebase indexing settings by ensuring correct handling of global state and provider-specific settings.

  • Behavior:
    • Fixes export/import of OpenAI Compatible codebase indexing settings by fetching settings from global state in importExport.ts.
    • Ensures codebaseIndexEmbedderModelDimension is included in exports and imports.
    • Corrects provider-specific settings handling during import.
  • Schema:
    • Adds codebaseIndexEmbedderModelDimension to codebaseIndexConfigSchema in codebase-index.ts.
  • Tests:
    • Adds tests in importExport.spec.ts to verify correct export/import of settings, including edge cases and provider mismatches.

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

@MuriloFP MuriloFP requested review from cte, jr and mrubens as code owners July 3, 2025 20:11
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. bug Something isn't working labels Jul 3, 2025
Copy link
Contributor

Choose a reason for hiding this comment

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

The variable 'targetProviderName' is set but never used. Consider removing it to simplify the code.

@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jul 3, 2025
Copy link
Member

@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.

I've conducted a thorough analysis of this PR and discovered a critical architectural issue that explains the root cause of all three linked issues (#5035, #4962, #5091).

Critical Finding: Storage Location Mismatch

There's a fundamental mismatch between where OpenAI Compatible settings are saved vs. where they're read:

1. Writing (src/core/webview/webviewMessageHandler.ts lines 1841-1842)

Settings are saved INSIDE the codebaseIndexConfig object:

const globalStateConfig = {
  ...currentConfig,
  codebaseIndexOpenAiCompatibleBaseUrl: settings.codebaseIndexOpenAiCompatibleBaseUrl,
  codebaseIndexOpenAiCompatibleModelDimension: settings.codebaseIndexOpenAiCompatibleModelDimension,
}
await updateGlobalState("codebaseIndexConfig", globalStateConfig)

2. Reading (src/services/code-index/config-manager.ts lines 62-65)

The code tries to read them as SEPARATE global state keys:

const openAiCompatibleBaseUrl = this.contextProxy?.getGlobalState("codebaseIndexOpenAiCompatibleBaseUrl") ?? ""
const openAiCompatibleModelDimension = this.contextProxy?.getGlobalState("codebaseIndexOpenAiCompatibleModelDimension")

Why This Causes All Three Issues

  • #5035: Export reads from the wrong location (separate keys that don't exist)
  • #4962: Settings "disappear" because they're saved in one place but read from another
  • #5091: Indexing fails to start because config-manager can't find the settings

Current PR Assessment

While this PR does fix the export/import functionality, it's essentially implementing a workaround by:

  1. Reading from global state during export (which happens to work because it reads from the correct location)
  2. Duplicating settings to provider profiles during import

The complex provider mapping logic (lines 72-112) is trying to work around the core issue rather than fixing it.

Recommended Solution

Instead of this workaround, we should fix the root cause. Two options:

Option 1: Update config-manager.ts to read from the correct location:

const codebaseIndexConfig = this.contextProxy?.getGlobalState("codebaseIndexConfig") ?? {}
const openAiCompatibleBaseUrl = codebaseIndexConfig.codebaseIndexOpenAiCompatibleBaseUrl ?? ""
const openAiCompatibleModelDimension = codebaseIndexConfig.codebaseIndexOpenAiCompatibleModelDimension

Option 2: Update webviewMessageHandler.ts to save as separate keys:

await updateGlobalState("codebaseIndexOpenAiCompatibleBaseUrl", settings.codebaseIndexOpenAiCompatibleBaseUrl)
await updateGlobalState("codebaseIndexOpenAiCompatibleModelDimension", settings.codebaseIndexOpenAiCompatibleModelDimension)

Code Quality Issues

  1. Unused variable (line 77): targetProviderName is assigned but never used
  2. Empty catch block (line 227): Silently swallows errors without logging

Questions for Consideration

  1. Should we fix the root cause instead of implementing this workaround?
  2. If we keep the provider profile approach, what's the migration strategy for existing users?
  3. Why maintain duplicate state in both global state and provider profiles?

While this PR does solve the immediate symptoms, addressing the underlying storage mismatch would provide a cleaner, more maintainable solution.

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Changes Requested] in Roo Code Roadmap Jul 4, 2025
@MuriloFP MuriloFP force-pushed the fix/issue-5035-openai-compatible-export branch from eca9074 to eeb5b0a Compare July 5, 2025 00:02
@MuriloFP
Copy link
Contributor Author

MuriloFP commented Jul 5, 2025

I've addressed the root cause issue identified in the review. The fix includes:

  1. Fixed the storage mismatch in config-manager.ts: The OpenAI Compatible settings are now correctly read from the nested \codebaseIndexConfig\ object instead of non-existent top-level keys.

  2. Updated type definitions: Added the OpenAI Compatible fields to the \CodebaseIndexConfig\ interface to ensure type safety.

  3. Removed workaround code: The complex logic in import/export that was compensating for the bug is no longer needed and has been removed.

  4. Fixed UI display bug: The settings popover now correctly displays saved OpenAI Compatible settings instead of showing blank fields.

  5. Updated tests: All unit tests have been updated to match the corrected architecture.

The settings now properly persist across restarts, display correctly in the UI, and are included in exports/imports as expected. All tests are passing.

MuriloFP and others added 4 commits July 4, 2025 22:19
…gs storage mismatch

- Updated config-manager to read settings from correct location (codebaseIndexConfig object)
- Added OpenAI Compatible fields to official type definitions
- Removed complex workaround code from import/export functions
- Fixed empty catch block by adding error logging
- Updated all unit tests to reflect new architecture
- All tests now passing (82 total)
- Fixed storage mismatch in config-manager.ts where settings were read from incorrect top-level keys instead of nested codebaseIndexConfig object
- Updated CodebaseIndexConfig type definition to include OpenAI Compatible fields
- Removed complex workaround logic from import/export that is no longer needed
- Fixed UI bug in CodeIndexPopover where saved settings were not displayed
- Updated unit tests to match the corrected architecture

This addresses Dan's review feedback about the root cause of the bug and ensures OpenAI Compatible provider settings are properly saved, displayed, and exported.
@MuriloFP MuriloFP force-pushed the fix/issue-5035-openai-compatible-export branch from eeb5b0a to 51e153c Compare July 5, 2025 01:42
@MuriloFP
Copy link
Contributor Author

MuriloFP commented Jul 5, 2025

Related GitHub Issue

Closes: #5035
Also fixes: #4962, #5091

Roo Code Task Context (Optional)

No Roo Code task context for this PR.

Description

This PR addresses the review feedback and fixes identified issues for PR #5383.

Key Changes:

  • Fixed the root cause of OpenAI Compatible codebase indexing settings persistence issues
  • Resolved merge conflicts with the latest main branch by properly integrating both codebaseIndexSearchMaxResults and OpenAI Compatible fields
  • Ensured proper alignment between storage write and read operations for OpenAI Compatible settings
  • All settings now correctly persist within the codebaseIndexConfig object structure

Review Comments Addressed:

  • ✅ Code quality issues (unused variable and empty catch block) - Already resolved during rebase
  • ✅ Merge conflicts in packages/types/src/codebase-index.ts - Successfully resolved
  • ✅ Root cause fix verified - Storage location mismatch properly addressed

Root Cause Analysis:
The core issue was a mismatch between where settings were written (inside codebaseIndexConfig) and where they were read (from non-existent top-level keys). This has been fixed by ensuring both read and write operations use the same nested structure.

Test Procedure

Testing performed:

  1. Ran all unit tests locally: npm test
    • importExport.spec.ts: 32/32 tests passed
    • config-manager.spec.ts: 51/51 tests passed
    • service-factory.spec.ts: 26/26 tests passed
  2. Ran TypeScript type checking: npx tsc --noEmit
  3. Manual testing steps:
    • Configure OpenAI Compatible provider in Code Index settings
    • Export settings and verify OpenAI Compatible fields are included
    • Restart VSCode and verify settings persist
    • Import settings and verify OpenAI Compatible fields are restored

To verify these changes:

  1. Check out this branch
  2. Run npm install && npm test
  3. Configure an OpenAI Compatible provider in the Code Index settings
  4. Export settings and verify the JSON includes codebaseIndexOpenAiCompatibleBaseUrl and codebaseIndexOpenAiCompatibleModelDimension
  5. Restart VSCode and confirm settings persist

Test Environment:

  • Node.js version: 18.x
  • OS: Windows 11
  • VSCode version: Latest

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

All review feedback has been addressed. The rebase process resolved the code quality issues mentioned in the review, and the merge conflicts have been properly resolved. The fix addresses the root cause of three related issues (#5035, #4962, #5091) by ensuring consistent storage location for OpenAI Compatible settings.

Files Modified:

packages/types/src/codebase-index.ts - Resolved merge conflict, integrated all fields
src/core/config/importExport.ts - Already has proper export logic
src/services/code-index/config-manager.ts - Correctly reads from nested structure
src/core/webview/webviewMessageHandler.ts - Correctly writes to nested structure
webview-ui/src/components/chat/CodeIndexPopover.tsx - Handles UI for settings

Get in Touch

Discord: @MuriloFP

@daniel-lxs daniel-lxs moved this from PR [Changes Requested] to PR [Needs Prelim Review] in Roo Code Roadmap Jul 7, 2025
Copy link
Member

@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.

LGTM

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jul 7, 2025
@mrubens mrubens merged commit 6ec017c into RooCodeInc:main Jul 7, 2025
17 checks passed
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jul 7, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Prelim Review] to Done in Roo Code Roadmap Jul 7, 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 lgtm This PR has been approved by a maintainer PR - Needs Preliminary Review size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

Archived in project

4 participants