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:
@@ -192,6 +192,14 @@ export class OllamaAdapter extends BaseAdapter {
|
||||
// 流结束
|
||||
if (chunk.done) {
|
||||
streamEndedNormally = true;
|
||||
// v0.8.0 P0-1: 采集 done_reason —— Ollama 的停止原因在最终 done chunk
|
||||
// 携带;旧实现流式路径完全忽略(length 截断不可见),现归一化后随
|
||||
// DONE 事件上交引擎
|
||||
const doneReason = mapOllamaDoneReason(
|
||||
chunk.done_reason as string | undefined,
|
||||
Array.isArray(chunk.message?.tool_calls) && chunk.message.tool_calls.length > 0,
|
||||
);
|
||||
const finishReason = doneReason === MetonaFinishReason.LENGTH ? 'length' : undefined;
|
||||
// 发送 usage 信息
|
||||
yield {
|
||||
type: MetonaStreamEventType.USAGE,
|
||||
@@ -214,6 +222,9 @@ export class OllamaAdapter extends BaseAdapter {
|
||||
iteration: request.meta.iteration,
|
||||
seq: seq++,
|
||||
timestamp: Date.now(),
|
||||
// v0.8.0 P0-1: 仅 length 需要显式上交(stop/tool_calls 语义由
|
||||
// 事件流本身表达;load/unload 属本地引擎状态非响应语义)
|
||||
...(finishReason ? { finishReason } : {}),
|
||||
};
|
||||
return;
|
||||
}
|
||||
@@ -252,6 +263,8 @@ export class OllamaAdapter extends BaseAdapter {
|
||||
format?: string | object;
|
||||
images?: string[];
|
||||
options?: Record<string, unknown>;
|
||||
/** v0.8.0 P1-3.2: 外部取消信号(与固定 300s 超时合并,任一触发即中止) */
|
||||
signal?: AbortSignal;
|
||||
}): Promise<{
|
||||
response: string;
|
||||
thinking?: string;
|
||||
@@ -262,8 +275,13 @@ export class OllamaAdapter extends BaseAdapter {
|
||||
const response = await fetch(`${this.baseURL}/api/generate`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ ...params, stream: false }),
|
||||
signal: AbortSignal.timeout(300_000),
|
||||
body: JSON.stringify({ ...params, stream: false, signal: undefined }),
|
||||
// v0.8.0 P1-3.2 根治: 旧实现固定 AbortSignal.timeout(300_000) —— 外部中断
|
||||
// 无法取消该请求(最长 5 分钟资源悬挂)。现用 AbortSignal.any 合并外部
|
||||
// signal 与超时信号,任一触发即中止(Node ≥20.3 / Electron 35 满足)。
|
||||
signal: params.signal
|
||||
? AbortSignal.any([params.signal, AbortSignal.timeout(300_000)])
|
||||
: AbortSignal.timeout(300_000),
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error(`Ollama generate error: ${response.status}`);
|
||||
@@ -290,12 +308,17 @@ export class OllamaAdapter extends BaseAdapter {
|
||||
model: string;
|
||||
input: string | string[];
|
||||
dimensions?: number;
|
||||
/** v0.8.0 P1-3.2: 外部取消信号(与固定 60s 超时合并) */
|
||||
signal?: AbortSignal;
|
||||
}): Promise<{ embeddings: number[][]; totalDuration: number }> {
|
||||
const response = await fetch(`${this.baseURL}/api/embed`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(params),
|
||||
signal: AbortSignal.timeout(60_000),
|
||||
// v0.8.0 P1-3.2: 与 generate 同口径 —— 外部 signal 与超时合并
|
||||
signal: params.signal
|
||||
? AbortSignal.any([params.signal, AbortSignal.timeout(60_000)])
|
||||
: AbortSignal.timeout(60_000),
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error(`Ollama embed error: ${response.status}`);
|
||||
@@ -381,9 +404,18 @@ export class OllamaAdapter extends BaseAdapter {
|
||||
*/
|
||||
private cachedContextWindow: number | null = null;
|
||||
private refreshingContextWindow = false;
|
||||
/** v0.8.0 P0-3: /api/show 探测只发一次(构造函数发起),失败不重试(fail-open) */
|
||||
private probeAttempted = false;
|
||||
/**
|
||||
* v0.8.0 P0-3: /api/show capabilities 探测缓存 —— 模型是否支持思考。
|
||||
* null = 未探测/探测失败(fail-open 放行,与 listModels 能力回退策略一致);
|
||||
* false = 服务端明确不支持 → toNativeRequest 不发 think 参数。
|
||||
*/
|
||||
private cachedThinkingSupport: boolean | null = null;
|
||||
|
||||
private refreshContextWindow(): void {
|
||||
if (this.refreshingContextWindow) return;
|
||||
if (this.refreshingContextWindow || this.probeAttempted) return;
|
||||
this.probeAttempted = true;
|
||||
this.refreshingContextWindow = true;
|
||||
void this.showModel(this.config.defaultModel)
|
||||
.then((info) => {
|
||||
@@ -396,6 +428,10 @@ export class OllamaAdapter extends BaseAdapter {
|
||||
log.info(`[Ollama] Context window (num_ctx) detected: ${value}`);
|
||||
}
|
||||
}
|
||||
// v0.8.0 P0-3: 同一次探测顺带缓存思考能力(供 toNativeRequest 同步门控)
|
||||
if (Array.isArray(info.capabilities)) {
|
||||
this.cachedThinkingSupport = info.capabilities.map(String).includes('thinking');
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
/* 模型探测失败不阻塞对话 */
|
||||
@@ -573,6 +609,9 @@ export class OllamaAdapter extends BaseAdapter {
|
||||
}
|
||||
|
||||
private async toNativeRequest(request: MetonaRequest): Promise<Record<string, unknown>> {
|
||||
// 说明:能力/num_ctx 探测由构造函数 fire-and-forget 发起(probeAttempts 上限
|
||||
// 1 次)—— 此处不再重复探测,避免每次请求都打 /api/show(也保持测试环境的
|
||||
// fetch 捕获不受污染)。探测失败时 cachedThinkingSupport=null → 门控 fail-open。
|
||||
const messages: Record<string, unknown>[] = [
|
||||
{
|
||||
role: 'system',
|
||||
@@ -662,14 +701,32 @@ export class OllamaAdapter extends BaseAdapter {
|
||||
}
|
||||
|
||||
// Thinking 模式
|
||||
// v0.8.0 P0-3: 模型能力门控 —— /api/show capabilities 探测为不支持思考
|
||||
//(cachedThinkingSupport === false)时不发 think 参数(Ollama 服务端默认关闭);
|
||||
// 未探测/探测失败(null)fail-open 放行,与 listModels 能力回退策略一致。
|
||||
// 探测在适配器实例创建时 fire-and-forget 发起(refreshContextWindow)。
|
||||
if (request.params.thinkingEnabled) {
|
||||
const effortMap: Record<string, string | boolean> = {
|
||||
low: 'low',
|
||||
medium: 'medium',
|
||||
high: 'high',
|
||||
max: true,
|
||||
};
|
||||
body.think = effortMap[request.params.thinkingEffort ?? 'high'] ?? true;
|
||||
const modelThinkingSupported = this.cachedThinkingSupport !== false;
|
||||
if (modelThinkingSupported) {
|
||||
const effortMap: Record<string, string | boolean> = {
|
||||
low: 'low',
|
||||
medium: 'medium',
|
||||
high: 'high',
|
||||
max: true,
|
||||
};
|
||||
body.think = effortMap[request.params.thinkingEffort ?? 'high'] ?? true;
|
||||
// v0.8.0 P0-3: 思考占用 num_predict 输出预算 —— 预算过小时显式告警
|
||||
const numPredict = request.params.maxTokens;
|
||||
if (typeof numPredict === 'number' && numPredict < 8192) {
|
||||
log.warn(
|
||||
`[Ollama] thinking enabled with small num_predict budget (${numPredict}) — reasoning may consume the entire budget and truncate the answer`,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
log.warn(
|
||||
`[Ollama] model "${this.config.defaultModel}" does not support thinking (per /api/show capabilities) — omitting think parameter (P0-3 capability gate)`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return body;
|
||||
|
||||
Reference in New Issue
Block a user