Skip to content

Conversation

@daniel-lxs
Copy link
Member

@daniel-lxs daniel-lxs commented Aug 5, 2025

Description

This PR provides a proper fix for the Gemini settings checkbox issue by addressing it at the schema/data layer rather than working around it in the UI.

Problem

When the Gemini settings checkboxes (enableUrlContext and enableGrounding) don't exist in the saved configuration, they have an undefined value. This causes the Save button to not activate when toggling these checkboxes.

Solution

This PR takes a comprehensive approach similar to commit 6aea8990:

  1. Schema Changes:

    • Moves enableUrlContext and enableGrounding to the base schema as optional fields (available to all providers)
    • Makes these fields required (non-optional) for the Gemini provider specifically
    • This ensures Gemini configs always have these fields defined
  2. Migration System:

    • Adds a migration to set default values (true) for existing Gemini configs
    • Cleans up these fields from non-Gemini providers where they don't belong
    • Ensures data consistency across all provider configurations
  3. Data Layer Handling:

    • Updates ProviderSettingsManager to properly handle these fields
    • Ensures Gemini configs always have these fields with proper defaults
    • Removes these fields from non-Gemini providers during save/load operations

Benefits

  • Root Cause Fix: Addresses the undefined state at its source rather than patching the UI
  • Data Integrity: Ensures consistent data structure for Gemini configurations
  • Type Safety: Better TypeScript type safety with required fields for Gemini
  • Future-Proof: Any future UI components won't need special handling for undefined states
  • Cleaner Code: No special case handling needed in the UI layer

Alternative Approach

This supersedes PR #6617 which attempted to fix this at the UI layer. The schema-level approach is more robust and prevents the issue from occurring in the first place.

Testing

  • Existing Gemini configurations will be migrated to have these fields set to true by default
  • New Gemini configurations will always have these fields defined
  • The Save button now properly activates when toggling these checkboxes
  • Non-Gemini providers are cleaned up to not have these irrelevant fields

Fixes #6616


Important

Fix Gemini settings handling by updating schema and data layer to ensure required fields are always defined for Gemini and cleaned up for non-Gemini providers.

  • Schema Changes:
    • Move enableUrlContext and enableGrounding to base schema as optional fields in provider-settings.ts.
    • Make these fields required for Gemini provider in geminiSchema.
  • Migration System:
    • Add migration in ProviderSettingsManager.ts to set default values for existing Gemini configs.
    • Remove these fields from non-Gemini providers.
  • Data Layer Handling:
    • Update ProviderSettingsManager to ensure Gemini configs have these fields with defaults.
    • Clean up these fields from non-Gemini providers during save/load operations.

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

- Move enableUrlContext and enableGrounding to base schema as optional
- Make these fields required (non-optional) for Gemini provider specifically
- Add migration to set default values (true) for existing Gemini configs
- Clean up these fields from non-Gemini providers
- Ensure Gemini configs always have these fields defined

This eliminates the undefined state that was causing the Save button issue,
fixing it at the data layer rather than working around it in the UI.

Fixes #6616
@daniel-lxs daniel-lxs requested review from cte, jr and mrubens as code owners August 5, 2025 20:48
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Aug 5, 2025
Copy link
Contributor

@roomote roomote bot left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution! I've reviewed the changes and found some issues that need attention.

}
}

private async migrateEnableUrlContextAndGrounding(providerProfiles: ProviderProfiles) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing test coverage for this new migration. This is a critical migration that affects data integrity and should be thoroughly tested. Could we add tests similar to the other migrations (like migrateTodoListEnabled at line 190)?

}

// Only run migration if either flag is false
if (
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this intentional? The migration checks and updates are done separately for each flag. If an error occurs between updating the flags, it could leave the migration in an inconsistent state. Consider combining both flag updates into a single operation:

Suggested change
if (
if (
!providerProfiles.migrations.enableUrlContextMigrated ||
!providerProfiles.migrations.enableGroundingMigrated
) {
await this.migrateEnableUrlContextAndGrounding(providerProfiles)
providerProfiles.migrations.enableUrlContextMigrated = true
providerProfiles.migrations.enableGroundingMigrated = true
isDirty = true
}

// Only apply migration to gemini provider settings
if (apiConfig.apiProvider === "gemini") {
// Type assertion to access gemini-specific properties
const geminiConfig = apiConfig as any
Copy link
Contributor

Choose a reason for hiding this comment

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

The use of any type assertions here bypasses TypeScript's type checking. Could we consider using proper type guards or creating a more specific type for Gemini configurations? This would improve type safety and make the code more maintainable.

providerProfiles.apiConfigs[name] = { ...filteredConfig, id }

// Handle gemini-specific fields - only ensure they exist for Gemini configs
if (filteredConfig.apiProvider === "gemini") {
Copy link
Contributor

Choose a reason for hiding this comment

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

This logic for ensuring Gemini fields have defaults is duplicated in export (lines 536-547) and in the load method (lines 599-610). Could we extract this into a helper function to reduce duplication? Something like:

Suggested change
if (filteredConfig.apiProvider === "gemini") {
private ensureGeminiDefaults(config: any): void {
if (config.apiProvider === "gemini") {
config.enableUrlContext = config.enableUrlContext ?? true
config.enableGrounding = config.enableGrounding ?? true
} else {
delete config.enableUrlContext
delete config.enableGrounding
}
}

modelMaxThinkingTokens: z.number().optional(),

// URL context and grounding (optional for most providers, required for Gemini)
enableUrlContext: z.boolean().optional(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Good approach moving these to the base schema as optional fields! This provides flexibility while maintaining backward compatibility. The comment clearly explains the intent.

@daniel-lxs
Copy link
Member Author

Closing this PR as the schema-level approach introduces TypeScript compilation issues with the cloud package. The fix needs more comprehensive testing and coordination with the types system.

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

Labels

bug Something isn't working size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

New Gemini settings can not be set if not already set

2 participants