From 2afcfff4e38fda50739b18a5b23a29c50db4136f Mon Sep 17 00:00:00 2001
From: t8y2 <1156263951@qq.com>
Date: Tue, 19 May 2026 18:08:08 +0800
Subject: [PATCH] fix(ai): extend timeout and token budget for thinking models
Thinking models like DeepSeek V4 Flash can exceed the 120s stream
timeout during long reasoning, causing truncated output and missing
answers. Increase stream timeout to 600s when thinking is enabled,
raise max_tokens floor to 8192, and bump reasoning display max-height.
Closes #326
---
apps/desktop/src/components/editor/AiAssistant.vue | 2 +-
apps/desktop/src/lib/ai.ts | 3 ++-
crates/dbx-core/src/ai.rs | 3 ++-
3 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/apps/desktop/src/components/editor/AiAssistant.vue b/apps/desktop/src/components/editor/AiAssistant.vue
index 10ccfa65e1..8f18b1601c 100644
--- a/apps/desktop/src/components/editor/AiAssistant.vue
+++ b/apps/desktop/src/components/editor/AiAssistant.vue
@@ -738,7 +738,7 @@ const messageRenderer = createAiMessageRenderer({ markdown: formatInlineText });
diff --git a/apps/desktop/src/lib/ai.ts b/apps/desktop/src/lib/ai.ts
index 0a647b3a8e..87dcd4a373 100644
--- a/apps/desktop/src/lib/ai.ts
+++ b/apps/desktop/src/lib/ai.ts
@@ -94,6 +94,7 @@ export async function runAiStream(
const sid = sessionId || uuid();
const params = actionParams(input.action);
+ const maxTokens = input.config.enableThinking ? Math.max(params.maxTokens, 8192) : params.maxTokens;
await api.aiStream(
sid,
@@ -101,7 +102,7 @@ export async function runAiStream(
config: input.config,
systemPrompt,
messages,
- maxTokens: params.maxTokens,
+ maxTokens,
temperature: params.temperature,
},
(chunk) => {
diff --git a/crates/dbx-core/src/ai.rs b/crates/dbx-core/src/ai.rs
index 3bea21dd25..adf1d8d20a 100644
--- a/crates/dbx-core/src/ai.rs
+++ b/crates/dbx-core/src/ai.rs
@@ -504,7 +504,8 @@ pub async fn stream(
) -> Result<(), String> {
validate_config(&request.config)?;
- let client = build_ai_http_client(&request.config, 120)?;
+ let stream_timeout = if request.config.enable_thinking { 600 } else { 120 };
+ let client = build_ai_http_client(&request.config, stream_timeout)?;
match request.config.provider {
AiProvider::Claude => stream_claude(&client, session_id, request, cancelled, &on_chunk).await,