From ebefa1f1da81c1294f219eaa900ad109eae8d0fd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Mar 2026 10:02:39 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20address=20code=20review=20feedback=20?= =?UTF-8?q?=E2=80=94=20schema,=20comment,=20key=20collision,=20streaming?= =?UTF-8?q?=20fallback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: qinfendebingshuo <207279273+qinfendebingshuo@users.noreply.github.com> --- backend-integration/api-proxy.js | 8 +++++--- src/brain/memory-manager.js | 4 ++-- src/brain/model-router.js | 2 +- src/schemas/hli/brain/prompt.schema.json | 1 + 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/backend-integration/api-proxy.js b/backend-integration/api-proxy.js index 94734a3b..d4821948 100644 --- a/backend-integration/api-proxy.js +++ b/backend-integration/api-proxy.js @@ -413,15 +413,17 @@ async function handleChat(req, res) { recordProxyFailure(curProv); console.error(`[代理] ${curProv} 请求失败: ${err.message}`); - if (isLastAttempt && !res.headersSent) { + // If headers already sent (partial streaming started), can't switch provider + if (res.headersSent) return; + + if (isLastAttempt) { jsonResponse(res, 502, { error: true, code: 'ALL_PROVIDERS_FAILED', message: '所有模型提供商均请求失败,请稍后重试' }); } - // If not last attempt and headers not sent, try next provider - if (res.headersSent) return; + // Otherwise continue to next provider } } } diff --git a/src/brain/memory-manager.js b/src/brain/memory-manager.js index ccafaeb8..3d2c4e17 100644 --- a/src/brain/memory-manager.js +++ b/src/brain/memory-manager.js @@ -55,8 +55,8 @@ function generateCandidates(text, source = 'user') { const end = Math.min(text.length, idx + 80); const excerpt = text.slice(start, end).replace(/\n/g, ' ').trim(); - // 检查中期记忆中的出现次数 - const memKey = type + ':' + excerpt.slice(0, 20); + // 检查中期记忆中的出现次数(使用类型+摘要前40字符作为键,降低碰撞风险) + const memKey = type + ':' + excerpt.slice(0, 40).replace(/\s+/g, '_'); const taskEntry = taskMemory.get(memKey) || { count: 0 }; taskEntry.count++; taskEntry.lastSeen = Date.now(); diff --git a/src/brain/model-router.js b/src/brain/model-router.js index a6cb3557..f203d4a5 100644 --- a/src/brain/model-router.js +++ b/src/brain/model-router.js @@ -100,7 +100,7 @@ function isInCooldown(provider, model) { failureLog.delete(key); return false; } - return entry.count >= 3; // 5分钟内失败3次以上才冷却 + return entry.count >= 3; // 5分钟内失败3次及以上才冷却 } /** diff --git a/src/schemas/hli/brain/prompt.schema.json b/src/schemas/hli/brain/prompt.schema.json index 1a81c99f..c49c9e43 100644 --- a/src/schemas/hli/brain/prompt.schema.json +++ b/src/schemas/hli/brain/prompt.schema.json @@ -13,6 +13,7 @@ "ghUser": { "type": "string", "description": "GitHub 用户名" }, "role": { "type": "string", "enum": ["founder", "supreme", "main", "dev", "guest"] }, "mode": { "type": "string", "enum": ["chat", "build", "review", "brain"] }, + "text": { "type": "string", "description": "当前用户输入文本(用于自动检测模式)" }, "devStatus": { "type": "object", "description": "开发者状态" } } },