feat: v0.8.0 流语义补全 · 会话可靠 · 恢复力 — finish_reason 全链路贯通根治"思考中停止" · 2445 用例全量回归
P0 会话可靠性收口(根治"模型思考着会话就停止"): - P0-1 finish_reason 全链路贯通:DONE 事件与 IterationStep 新增 finishReason,OpenAI 共享 SSE / Anthropic message_delta.stop_reason / Ollama done_reason 三路采集,TRACE 层弃用硬编码 'stop' 记录真值 - P0-2 空响应守卫 + 降级重试:零产出流→可重试错误走退避;思考耗尽输出预算(reasoning-only + length)→自动关闭思考降级重试一次;仍失败→OUTPUT_LENGTH_EXCEEDED 结构化错误 + 故障转移;附带根治 abort 恰逢零工具调用轮被 COMPLETED 抢占的真实缺陷 - P0-3 思考×能力×预算三对齐:DeepSeek/MiMo/Agnes/Ollama 四家 supportsThinking=false 强制不发思考参数;小输出预算告警;设置页联动提示 - P0-4 渲染层可见性:截断/空完成/友好错误三类提示,i18n 全部出层 - P0-5 回归四件套:reasoning-only 终止判定、集成级空闲超时、504 引擎重试归类、思考中 abort→USER_INTERRUPT、P4-2 强制收尾路径 FEAT-1:LLM 设置新增「最大输出上限」——Provider 支持矩阵显隐 + 模型上限钳制提示 + 超限保存警告 + llm.maxTokens 热生效 P1 修复面收口: - 渲染层三缺陷根治:后台会话回放缓冲(2000 条/4MB 有界 + agent:getReplayState + 事件总线)+ abort 双层自愈 + sendMessage 收尾兜底 + 中断卡片清扫 - 工具 abort 信号全覆盖:web_search/web_fetch/http_request/code_search/git 系列/delegate_task 全部接入引擎中断;web_search 时间预算收敛(720s→≤240s);移除伪造 ToolExecutionContext 与死代码 - 安全:本地 Pinned CONNECT 代理根治浏览器通道 DNS rebinding(校验期 IP pinning,可注入 resolver 表测);配置 URL 域名解析深校验(DeepCheckSoftFailure 软失败);SSE 空 error 帧防御修复;Ollama generate/embed AbortSignal.any 合并 - 缺陷清单:UTF-16 BOM 读取、tmp 同毫秒碰撞(nanoid 后缀)、code_search JS 回退参数对称(case_sensitive/前后文独立)、list_directory include_node_modules、崩溃自愈退避(60s 窗 ≥3 次停 reload)、MemoryViewer/Sidebar i18n 收口 P2 能力演进: - 会话回收站:SCHEMA_VERSION 3 + 迁移 10(deleted_at,存在性守卫),软删除/恢复/彻底删除/30 天自动清理(启动+24h),searchMessages 聚合剔除,Sidebar 回收站面板 - 会话回放播放器:sessions:listRecordings/readRecording(白名单+目录边界+20MB 上限),SessionReplayPlayer 时间轴/步进/变速,Trace 面板入口 - electron-updater 自动更新:双轨(手动 feed 比对保留),生产环境启动静默检查 + update:status 广播 + app:updateInstall + LogsSettings UpdatePanel + builder publish 配置 - @ 文件提及:workspace.listFiles/readFileClip(边界/512KB/NUL 拒绝/MEMORY.md 保护),ChatInput Fuse 联想+键盘导航+附件管线注入 - MCP Resources/Prompts 发现:可选能力 try/catch 降级,mcp:listServerContents,MCPSettings 展开视图 - 文档对齐:内部 API 标准 HTML(Adapter 清单补 MiMo/已实现注记/STREAM_RESET/DONE.finishReason/ repetition_truncation 映射);README v0.8.0 亮点表 P3 测试基建: - 新增 4 个测试文件:engine-stream-contract(6)、engine-stream-reliability(4:集成空闲超时/504 重试/思考中 abort/P4-2 强制收尾)、thinking-capability-gate(7)、pinned-proxy(9,含深校验 5)、session-trash(5,DB 域)、use-agent-stream hook 级(5)、agent.test 回放缓冲(2) - 契约更新:orchestrator 被中断 SubAgent success=false(abort 优先级修复语义)、SSE 空 error 帧、UTF-16 正常读取、DeepSeek 未配置思考显式 disabled、迁移矩阵 v2→3 - 弱断言根治:registry WEBP 单向断言、hooks-contracts 自比恒真、memory 空 token 补强 全量验证:typecheck 0 错误 / lint 0 问题 / 系统 Node 2144 通过(301 DB 用例按 ABI 跳过)/ Electron ABI 2445/2445 全量通过 0 跳过
This commit is contained in:
+106
-15
@@ -11,6 +11,11 @@ import { useSessionStore } from './session-store';
|
||||
import { toDisplayResult } from '../lib/tool-result-display';
|
||||
// v0.7.3 P3-3: Trace 生命周期 —— metadata 只保留最近 N 个 run 的步骤
|
||||
import { keepRecentRuns } from '../lib/trace-lifecycle';
|
||||
// v0.8.0 P1-1a: 后台会话回放经事件总线灌入 useAgentStream 管线
|
||||
import { emitStreamBus } from '../lib/stream-event-bus';
|
||||
// v0.8.0 P1-1b/c: 文案出层
|
||||
import { t } from '../lib/i18n';
|
||||
import '../lib/i18n-strings';
|
||||
|
||||
// L-1: 消息 ID 防碰撞计数器
|
||||
let _msgIdCounter = 0;
|
||||
@@ -380,6 +385,46 @@ export const useAgentStore = create<AgentState>((set, get) => ({
|
||||
console.error('[AgentStore]', err);
|
||||
});
|
||||
}
|
||||
|
||||
// v0.8.0 P1-1a: 后台会话运行内容恢复 —— 该会话正在后台运行(或刚结束但
|
||||
// 缓冲未清)时,拉取主进程回放缓冲并按序灌入事件总线,重建消息/Trace 状态;
|
||||
// 实时事件随后经同一总线无缝衔接(runId 对齐由缓冲记录提供)。
|
||||
if (id && window.metona?.agent?.getReplayState) {
|
||||
window.metona.agent
|
||||
.getReplayState(id)
|
||||
.then((r) => {
|
||||
// 竞态保护:用户已切走则丢弃
|
||||
if (get().currentSessionId !== id) return;
|
||||
if (!r?.success || !r.data || r.data.events.length === 0) return;
|
||||
const { events, truncated, runId, isRunning } = r.data;
|
||||
// 恢复流式态与 run 归属:回放的内容事件需要 isStreaming=true 才能通过
|
||||
// 准入层(non-streaming-content 过滤);终止事件(done/error)会正常
|
||||
// 收尾并把 isStreaming 复位为 false。
|
||||
if (runId) {
|
||||
set({ currentRunId: runId, isStreaming: true });
|
||||
}
|
||||
for (const ev of events) {
|
||||
emitStreamBus(ev.channel, ev.payload);
|
||||
}
|
||||
if (truncated) {
|
||||
get().addMessage({
|
||||
id: genMsgId('system'),
|
||||
role: 'system',
|
||||
content: t('agent.system.replay_truncated'),
|
||||
timestamp: Date.now(),
|
||||
});
|
||||
}
|
||||
// 已运行中的会话:回放后实时事件继续;stateChange THINKING 自愈
|
||||
//(P1-1b)会在流式态意外复位时恢复。此处对 isRunning 会话兜底确保
|
||||
// isStreaming 不为 false(done 未到达时 bus 回放不会复位它)。
|
||||
if (isRunning && runId && !get().isStreaming) {
|
||||
set({ isStreaming: true });
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('[AgentStore] getReplayState failed:', err);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
setMessages: (messages) => set({ messages }),
|
||||
@@ -544,20 +589,54 @@ export const useAgentStore = create<AgentState>((set, get) => ({
|
||||
content: llmContent,
|
||||
images: llmImages.length > 0 ? llmImages : undefined,
|
||||
};
|
||||
window.metona.agent.sendMessage(messageWithImages, sessionId).catch((err) => {
|
||||
console.error('[AgentStore]', 'IPC sendMessage failed:', err);
|
||||
set({ agentStatus: 'error', isStreaming: false });
|
||||
get().addMessage({
|
||||
id: genMsgId('error'),
|
||||
role: 'system',
|
||||
content: `错误: 消息发送失败 — ${(err as Error).message}`,
|
||||
timestamp: Date.now(),
|
||||
});
|
||||
// 额外弹 toast 作为通知,确保用户感知(system message 仅在聊天流内可见)
|
||||
import('@metona-team/metona-toast')
|
||||
.then((mod) => mod.default.error(`消息发送失败:${(err as Error).message}`))
|
||||
.catch(() => {});
|
||||
});
|
||||
window.metona.agent.sendMessage(messageWithImages, sessionId).then(
|
||||
(r) => {
|
||||
// v0.8.0 P1-1c: 收尾兜底 —— agent:sendMessage 的 invoke 在整个 run 结束后
|
||||
// 才 resolve。resolve 时若本地仍处于流式态,说明 DONE/ERROR 收尾事件
|
||||
// 未到达(事件投递异常/主进程异常收尾),渲染层将永久卡在流式状态。
|
||||
const st = get();
|
||||
if (st.currentSessionId !== sessionId || !st.isStreaming) return;
|
||||
if (r && r.success === false) {
|
||||
// 主进程显式失败(注入拦截/防重入/adapter 加载失败等)——通常已广播
|
||||
// ERROR 事件;若事件未达,本地以返回的 error 消息兜底收尾
|
||||
set({ agentStatus: 'error', isStreaming: false, currentRunId: null });
|
||||
get().addMessage({
|
||||
id: genMsgId('error'),
|
||||
role: 'system',
|
||||
content: t('agent.error.generic', { message: r.error ?? '消息发送失败' }),
|
||||
timestamp: Date.now(),
|
||||
});
|
||||
return;
|
||||
}
|
||||
// 成功 resolve:给事件投递留 2s 宽限,仍卡流式则强制收尾
|
||||
setTimeout(() => {
|
||||
const s2 = get();
|
||||
if (s2.currentSessionId !== sessionId || !s2.isStreaming) return;
|
||||
set({ agentStatus: 'idle', isStreaming: false, currentRunId: null });
|
||||
s2.addMessage({
|
||||
id: genMsgId('system'),
|
||||
role: 'system',
|
||||
content: t('agent.system.finalize_missing'),
|
||||
timestamp: Date.now(),
|
||||
});
|
||||
s2.saveTraceData();
|
||||
}, 2_000);
|
||||
},
|
||||
(err) => {
|
||||
console.error('[AgentStore]', 'IPC sendMessage failed:', err);
|
||||
set({ agentStatus: 'error', isStreaming: false });
|
||||
get().addMessage({
|
||||
id: genMsgId('error'),
|
||||
role: 'system',
|
||||
content: `错误: 消息发送失败 — ${(err as Error).message}`,
|
||||
timestamp: Date.now(),
|
||||
});
|
||||
// 额外弹 toast 作为通知,确保用户感知(system message 仅在聊天流内可见)
|
||||
import('@metona-team/metona-toast')
|
||||
.then((mod) => mod.default.error(`消息发送失败:${(err as Error).message}`))
|
||||
.catch(() => {});
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -810,11 +889,23 @@ export const useAgentStore = create<AgentState>((set, get) => ({
|
||||
// 不清除 currentRunId — 保留用于过滤旧 run 的延迟终止事件(DONE/TERMINATED)
|
||||
// 旧 run 的 DONE 到达时会匹配 currentRunId,处理后清除;新 run 的 INIT 会覆盖
|
||||
set({ agentStatus: 'idle', isStreaming: false });
|
||||
// v0.7.2 P3-11: 立即熄灭运行指示点;若中断未生效,后续 THINKING 状态事件会重新点亮(自愈)
|
||||
// v0.7.2 P3-11: 立即熄灭运行指示点。
|
||||
// v0.8.0 P1-1b 修正注释与实现:此前注释称"中断未生效时 THINKING 事件会重新
|
||||
// 点亮(自愈)",但 isStreaming=false 下内容事件仍被准入层丢弃。现两层自愈:
|
||||
// ① 本处 IPC 失败 → 回滚本地状态并恢复运行指示(下方 catch);
|
||||
// ② IPC 成功但引擎未真正停止 → useAgentStream 的 stateChange THINKING
|
||||
// 自愈(runId 匹配时恢复 isStreaming=true)。
|
||||
if (sessionId) get().updateSessionRunState(sessionId, null);
|
||||
if (sessionId && window.metona?.agent?.abortSession) {
|
||||
window.metona.agent.abortSession(sessionId).catch((err) => {
|
||||
console.error('[AgentStore]', err);
|
||||
// v0.8.0 P1-1b: 中断请求失败 —— 引擎很可能仍在运行,回滚本地状态
|
||||
// 并恢复运行指示与实时显示(内容事件不再被准入层丢弃)
|
||||
set({ agentStatus: 'thinking', isStreaming: true });
|
||||
if (sessionId) get().updateSessionRunState(sessionId, 'thinking');
|
||||
import('@metona-team/metona-toast')
|
||||
.then((mod) => mod.default.warning(t('agent.system.abort_failed')))
|
||||
.catch(() => {});
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user