From a7073446783ac06ce12be815a66f2ec9f9184361 Mon Sep 17 00:00:00 2001 From: kicer Date: Mon, 23 Nov 2026 09:18:32 +0800 Subject: [PATCH] =?UTF-8?q?fix(chat):=20=E5=88=86=E5=8F=89=E5=8F=AA?= =?UTF-8?q?=E6=90=AC=E6=9C=89=E6=95=88=E4=B8=8A=E4=B8=8B=E6=96=87=E2=80=94?= =?UTF-8?q?=E2=80=94=E8=B7=B3=E8=BF=87=20archived=20=E6=AE=B5=EF=BC=8Csumm?= =?UTF-8?q?ary=20=E5=8F=AA=E7=95=99=E6=9C=80=E5=90=8E=E4=B8=80=E4=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 分叉时原来是把分叉点之前的消息整段复制,连压缩产生的 archived 行也带过去。新会话 不会再压缩它们,搬过去只是白占地方,界面上还多一截淡色存档段。 - 跳过 type='archived' 的行 - summary 只保留最后一个(压缩后的上下文起点,更早的已被它概括),靠 MAX(id) WHERE type='summary' AND id < 分叉点 定位 --- app/server/engine.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/server/engine.js b/app/server/engine.js index 041e85d..21df5e3 100644 --- a/app/server/engine.js +++ b/app/server/engine.js @@ -1372,12 +1372,21 @@ function forkSession(sessionId, messageId, user) { null, src.assistant_type || 'secretary', src.user || user || '', src.work_dir || '', ts, ts, src.deep_think ? 1 : 0); // 思考开关随会话走:分叉后新会话保持源会话的思考状态 profile.freezeSnapshot(db, id); // 画像快照随会话冻结:分叉也要一份,否则新会话首轮没有画像 + // 只搬「有效上下文」:archived 行不复制(新会话不会再压缩它们,搬过去只白占地方、 + // UI 还多一截淡色存档段);summary 只留最后一个(压缩后的上下文起点,更早的已被它概括)。 + const lastSum = db.prepare( + "SELECT MAX(id) AS id FROM messages WHERE session_id = ? AND id < ? AND type = 'summary'" + ).get(sessionId, point.id); + const lastSumId = (lastSum && lastSum.id) || 0; // tool_calls / tool_call_id 原样复制,配对关系不变;tool_call_msg_ids 由 GET /sessions/:id 现算 const r = db.prepare( 'INSERT INTO messages (session_id, role, content, reasoning, tool_calls, tool_call_id, name, type, is_error, usage, created_at) ' + 'SELECT ?, role, content, reasoning, tool_calls, tool_call_id, name, type, is_error, usage, created_at ' + - 'FROM messages WHERE session_id = ? AND id < ? ORDER BY id' - ).run(id, sessionId, point.id); + 'FROM messages WHERE session_id = ? AND id < ? ' + + " AND COALESCE(type, '') != 'archived' " + + " AND (COALESCE(type, '') != 'summary' OR id = ?) " + + 'ORDER BY id' + ).run(id, sessionId, point.id, lastSumId); log.info('task', sessionId + ' 分叉 → ' + id + '(复制 ' + r.changes + ' 条,分叉点 #' + point.id + ')'); return { id, copied: r.changes, prefill: point.content || '' }; }