fix: address code review feedback — schema, comment, key collision, streaming fallback

Co-authored-by: qinfendebingshuo <207279273+qinfendebingshuo@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-03-10 10:02:39 +00:00
parent a7a7832674
commit ebefa1f1da
4 changed files with 9 additions and 6 deletions

View File

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

View File

@ -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();

View File

@ -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次以上才冷却
}
/**

View File

@ -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": "开发者状态" }
}
},