Skip to content

Conversation

@yyhhyyyyyy
Copy link
Collaborator

@yyhhyyyyyy yyhhyyyyyy commented Aug 22, 2025

resolve Gemini 2.5 thinking budget initialization and sync issues

old:

CleanShot.2025-08-22.at.14.13.17.mp4

new:

CleanShot.2025-08-22.at.14.14.05.mp4

Summary by CodeRabbit

  • New Features

    • Added Thinking Budget configuration to new threads and chat settings, including dynamic mode toggle and numeric input when a concrete value is set.
    • Thinking Budget is now included (optionally) when creating a thread.
  • Bug Fixes

    • Preserves user-specified Thinking Budget (including 0) instead of overwriting with model defaults.
    • Dynamic mode can be toggled even when no prior budget is defined.
    • Initializes Thinking Budget from model defaults when available, without overriding an existing user choice.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 22, 2025

Walkthrough

Implements explicit thinkingBudget handling across presenter and renderer: preserves user-provided values (including 0) in ThreadPresenter.createConversation, adds thinkingBudget state and bindings in NewThread and ChatConfig, and initializes/syncs thinkingBudget in TitleView based on model config.

Changes

Cohort / File(s) Summary of changes
Presenter: conversation defaults
src/main/presenter/threadPresenter/index.ts
In createConversation, only apply model default thinkingBudget when settings.thinkingBudget is undefined; retain explicit user values (including 0).
Renderer: chat config UI
src/renderer/src/components/ChatConfig.vue
Switch/input bindings updated: dynamic mode toggled via checked = (thinkingBudget ?? -1) === -1; disabled states aligned; removed prior disabled guard when undefined. Adds v-model:thinking-budget support and emits update:thinkingBudget.
Renderer: thread creation flow
src/renderer/src/components/NewThread.vue
Introduces reactive thinkingBudget (number | undefined), syncs from active model config, binds to ChatConfig, and includes thinkingBudget in createThread payload.
Renderer: model config load
src/renderer/src/components/TitleView.vue
On loading model defaults, initializes thinkingBudget: set from config if defined, otherwise undefined; preserves existing user-set value if present. Mirrors existing reasoningEffort/verbosity handling.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant ChatConfig as ChatConfig (UI)
  participant NewThread as NewThread.vue
  participant Store as chatStore
  participant Presenter as ThreadPresenter

  User->>ChatConfig: Toggle dynamic/explicit thinkingBudget
  ChatConfig-->>NewThread: update:thinkingBudget (v-model)
  User->>NewThread: Create Thread
  NewThread->>Store: createThread({ ..., thinkingBudget })
  Store->>Presenter: createConversation(settings)

  rect rgba(200,230,255,0.25)
  note over Presenter: thinkingBudget defaulting logic (changed)
  alt settings.thinkingBudget is undefined
    Presenter->>Presenter: Apply model default thinkingBudget
  else settings.thinkingBudget is defined (incl. 0)
    Presenter->>Presenter: Preserve provided thinkingBudget
  end
  end

  Presenter-->>Store: conversation created
  Store-->>NewThread: thread ready
  NewThread-->>User: Opens new chat
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • zerob13

Poem

A thimble of thoughts, a pocket of plans,
I tweak my budget with soft bunny hands.
When zero means zero, I nod with delight—
No defaults nibbling my carrot of right.
Threads hop forward, crisp and clear,
Logic tidy, springtime near. 🥕🐇

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/gemini-thinking-budget-initialization

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/main/presenter/threadPresenter/index.ts (1)

742-752: Guard against overwriting an inherited thinkingBudget with undefined (keep the good fix).

Nice fix to preserve explicit user input (including 0). However, if a model’s default config lacks thinkingBudget, this assignment can nullify an inherited value coming from defaultSettings/latest conversation. Add a presence check on the model default before writing.

-      if (settings.thinkingBudget === undefined) {
-        mergedSettings.thinkingBudget = defaultModelsSettings.thinkingBudget
-      }
+      // Only apply model default when user hasn't provided a value,
+      // and the model actually defines a default.
+      if (
+        settings.thinkingBudget === undefined &&
+        defaultModelsSettings.thinkingBudget !== undefined
+      ) {
+        mergedSettings.thinkingBudget = defaultModelsSettings.thinkingBudget
+      }
src/renderer/src/components/ChatConfig.vue (1)

258-260: Dynamic vs. “use model default” conflation; and input disabled logic.

Using (props.thinkingBudget ?? -1) === -1 treats “undefined” as “dynamic (-1)”, which can misrepresent the actual state when the model default isn’t -1. Recommend binding the switch/disabled strictly to -1 and letting “undefined” mean “use model default”.

-            <Switch
-              :checked="(props.thinkingBudget ?? -1) === -1"
-              @update:checked="handleDynamicThinkingToggle"
-            />
+            <Switch
+              :checked="props.thinkingBudget === -1"
+              @update:checked="handleDynamicThinkingToggle"
+            />
-              :disabled="(props.thinkingBudget ?? -1) === -1"
+              :disabled="props.thinkingBudget === -1"

Additionally, the number input can emit null/NaN when the field is cleared or contains invalid text (v-model.number). Normalize in the computed setter so empty/invalid becomes undefined (use model default), and clamp the range.

Add this setter (outside the changed lines) to replace the current displayThinkingBudget setter:

const displayThinkingBudget = computed<number | undefined>({
  get: () => (props.thinkingBudget !== undefined ? props.thinkingBudget : undefined),
  set: (value) => {
    // Treat empty/invalid as "use model default"
    if (value === null || value === undefined || Number.isNaN(value as unknown as number)) {
      emit('update:thinkingBudget', undefined)
      return
    }
    // Preserve -1 for dynamic; otherwise round-and-clamp
    const n = Math.round(Number(value))
    const clamped = n < -1 ? -1 : Math.min(32768, n)
    emit('update:thinkingBudget', clamped)
  }
})

Also applies to: 279-281

src/renderer/src/components/NewThread.vue (1)

93-101: Thinking budget is correctly plumbed end-to-end; tighten types to avoid as any.

Wiring v-model, local state, default syncing, and thread creation looks good and should fix initialization/sync issues. Minor nit: the options object passed to createThread is cast to any, which hides shape errors (including this new field). Prefer updating the options type to include thinkingBudget?: number.

I can help propagate the thinkingBudget?: number property into the relevant types (e.g., the chat store’s createThread options and the CONVERSATION_SETTINGS) so we can drop as any. Want me to open a follow-up diff?

Also applies to: 163-166, 184-187, 416-420

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 37fe0c5 and 1370765.

📒 Files selected for processing (4)
  • src/main/presenter/threadPresenter/index.ts (1 hunks)
  • src/renderer/src/components/ChatConfig.vue (2 hunks)
  • src/renderer/src/components/NewThread.vue (4 hunks)
  • src/renderer/src/components/TitleView.vue (1 hunks)
🧰 Additional context used
📓 Path-based instructions (15)
**/*.{ts,tsx,js,jsx,vue}

📄 CodeRabbit inference engine (CLAUDE.md)

Use English for logs and comments

Files:

  • src/main/presenter/threadPresenter/index.ts
  • src/renderer/src/components/TitleView.vue
  • src/renderer/src/components/ChatConfig.vue
  • src/renderer/src/components/NewThread.vue
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Strict type checking enabled for TypeScript

**/*.{ts,tsx}: 始终使用 try-catch 处理可能的错误
提供有意义的错误信息
记录详细的错误日志
优雅降级处理
日志应包含时间戳、日志级别、错误代码、错误描述、堆栈跟踪(如适用)、相关上下文信息
日志级别应包括 ERROR、WARN、INFO、DEBUG
不要吞掉错误
提供用户友好的错误信息
实现错误重试机制
避免记录敏感信息
使用结构化日志
设置适当的日志级别

Files:

  • src/main/presenter/threadPresenter/index.ts
src/main/**/*.ts

📄 CodeRabbit inference engine (CLAUDE.md)

Main to Renderer: Use EventBus to broadcast events via mainWindow.webContents.send()

Use Electron's built-in APIs for file system and native dialogs

Files:

  • src/main/presenter/threadPresenter/index.ts
src/main/presenter/**/*.ts

📄 CodeRabbit inference engine (CLAUDE.md)

One presenter per functional domain

Files:

  • src/main/presenter/threadPresenter/index.ts
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development-setup.mdc)

**/*.{js,jsx,ts,tsx}: 使用 OxLint 进行代码检查
Log和注释使用英文书写

Files:

  • src/main/presenter/threadPresenter/index.ts
src/{main,renderer}/**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/electron-best-practices.mdc)

src/{main,renderer}/**/*.ts: Use context isolation for improved security
Implement proper inter-process communication (IPC) patterns
Optimize application startup time with lazy loading
Implement proper error handling and logging for debugging

Files:

  • src/main/presenter/threadPresenter/index.ts
src/main/**/*.{ts,js,tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)

主进程代码放在 src/main

Files:

  • src/main/presenter/threadPresenter/index.ts
src/renderer/src/**/*.vue

📄 CodeRabbit inference engine (CLAUDE.md)

src/renderer/src/**/*.vue: Use Composition API for all Vue 3 components
Use Tailwind CSS with scoped styles for styling
Organize components by feature in src/renderer/src/
Follow existing component patterns in src/renderer/src/ when creating new UI components
Use Composition API with proper TypeScript typing for new UI components
Implement responsive design with Tailwind CSS for new UI components
Add proper error handling and loading states for new UI components

Use scoped styles to prevent CSS conflicts between components

Files:

  • src/renderer/src/components/TitleView.vue
  • src/renderer/src/components/ChatConfig.vue
  • src/renderer/src/components/NewThread.vue
src/renderer/src/**/*.{ts,tsx,vue}

📄 CodeRabbit inference engine (CLAUDE.md)

src/renderer/src/**/*.{ts,tsx,vue}: Use Pinia for frontend state management
Renderer to Main: Use usePresenter.ts composable for direct presenter method calls

Files:

  • src/renderer/src/components/TitleView.vue
  • src/renderer/src/components/ChatConfig.vue
  • src/renderer/src/components/NewThread.vue
src/renderer/src/**/*

📄 CodeRabbit inference engine (.cursor/rules/i18n.mdc)

src/renderer/src/**/*: All user-facing strings must use i18n keys (avoid hardcoded user-visible text in code)
Use the 'vue-i18n' framework for all internationalization in the renderer
Ensure all user-visible text in the renderer uses the translation system

Files:

  • src/renderer/src/components/TitleView.vue
  • src/renderer/src/components/ChatConfig.vue
  • src/renderer/src/components/NewThread.vue
src/renderer/**/*.{vue,ts,js,tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)

渲染进程代码放在 src/renderer

Files:

  • src/renderer/src/components/TitleView.vue
  • src/renderer/src/components/ChatConfig.vue
  • src/renderer/src/components/NewThread.vue
src/renderer/src/**/*.{vue,ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/vue-best-practices.mdc)

src/renderer/src/**/*.{vue,ts,tsx,js,jsx}: Use the Composition API for better code organization and reusability
Implement proper state management with Pinia
Utilize Vue Router for navigation and route management
Leverage Vue's built-in reactivity system for efficient data handling

Files:

  • src/renderer/src/components/TitleView.vue
  • src/renderer/src/components/ChatConfig.vue
  • src/renderer/src/components/NewThread.vue
src/renderer/**/*.{ts,tsx,vue}

📄 CodeRabbit inference engine (.cursor/rules/vue-shadcn.mdc)

src/renderer/**/*.{ts,tsx,vue}: Use descriptive variable names with auxiliary verbs (e.g., isLoading, hasError).
Use TypeScript for all code; prefer types over interfaces.
Avoid enums; use const objects instead.
Use arrow functions for methods and computed properties.
Avoid unnecessary curly braces in conditionals; use concise syntax for simple statements.

Files:

  • src/renderer/src/components/TitleView.vue
  • src/renderer/src/components/ChatConfig.vue
  • src/renderer/src/components/NewThread.vue
src/renderer/**/*.{vue,ts}

📄 CodeRabbit inference engine (.cursor/rules/vue-shadcn.mdc)

Implement lazy loading for routes and components.

Files:

  • src/renderer/src/components/TitleView.vue
  • src/renderer/src/components/ChatConfig.vue
  • src/renderer/src/components/NewThread.vue
src/renderer/**/*.{ts,vue}

📄 CodeRabbit inference engine (.cursor/rules/vue-shadcn.mdc)

src/renderer/**/*.{ts,vue}: Use useFetch and useAsyncData for data fetching.
Implement SEO best practices using Nuxt's useHead and useSeoMeta.

Files:

  • src/renderer/src/components/TitleView.vue
  • src/renderer/src/components/ChatConfig.vue
  • src/renderer/src/components/NewThread.vue
🧬 Code graph analysis (1)
src/main/presenter/threadPresenter/index.ts (1)
src/main/presenter/configPresenter/modelDefaultSettings.ts (1)
  • defaultModelsSettings (3-1909)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-check (x64)
🔇 Additional comments (1)
src/renderer/src/components/TitleView.vue (1)

118-124: Initialize thinkingBudget from model defaults only when unset — LGTM.

This preserves user overrides and avoids stomping on set values. Good alignment with the PR goal.

@zerob13 zerob13 merged commit 6cb27aa into dev Aug 22, 2025
2 checks passed
@zerob13 zerob13 deleted the fix/gemini-thinking-budget-initialization branch January 6, 2026 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants