fix(history): 空答复不落历史 + 发送前过滤空消息(根治会话毒化)
现象:某轮 LLM 返回空(余额不足/失败/降级)→ 空 assistant 消息被写进会话历史 → 此后该 session 每次请求都带一条空 content 的 assistant 消息 → DeepSeek 400 "Invalid assistant message: content or tool_calls must be set" → 又空 → 又写空 → 自我循环毒化。 - Fix A(断源):orchestrator.memorize 对空答复直接 return,不落历史(失败的一轮不留痕)。 - Fix B(兜底):buildMessages 发送前剔除 content 与 tool_calls 均空的历史消息, 防御任何来源的脏历史(含存量)。 验证:清理被污染的 default 会话后恢复正常;新逻辑下空答复不再写入。dispatcher build+vet+test 全绿。 注:诊断中发现激活模型 deepseek-v4-pro 是推理模型(答案在 reasoning_content,content 为空), 已在管理端切回 deepseek-chat。仍待办:LLM 调用失败应暴露为 failed 而非 done-空输出。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"log/slog"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -270,6 +271,11 @@ const consolidateEveryTurns = 3
|
||||
|
||||
// memorize 写回阶段(异步、离热路径):落短期历史;每 N 轮做一次记忆对账(consolidate)。
|
||||
func (o *Orchestrator) memorize(t *contract.Task, answer string) {
|
||||
// 空答复(LLM 失败/降级/拒绝)不落历史:空 assistant 消息会被 LLM API 拒绝(400),
|
||||
// 一旦写入会毒化该会话后续所有请求。失败的一轮干脆不留痕。
|
||||
if strings.TrimSpace(answer) == "" {
|
||||
return
|
||||
}
|
||||
uid, _ := t.Meta[contract.MetaUserID].(string)
|
||||
sid, _ := t.Meta[contract.MetaSessionID].(string)
|
||||
if sid != "" && o.tools != nil {
|
||||
|
||||
Reference in New Issue
Block a user