From e55d209f59086f1c0aa4630895845455d5786fe9 Mon Sep 17 00:00:00 2001 From: kicer Date: Tue, 17 Nov 2026 23:38:03 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=A2=9E=E9=87=8F=E4=B8=8A=E4=B8=8B?= =?UTF-8?q?=E6=96=87):=20409=20=E9=87=8D=E8=AF=95=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E6=B3=84=E6=BC=8F=E5=86=85=E9=83=A8=E9=94=AE=20=5F=5FrowId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 上一版改锚点判时,409 重试分支仍是 body.messages = messages(原始数组), 而 buildMessages 现在给每行都挂了 __rowId。结果重试那次把 __rowId 一路发到上游。 修复:map 完先存一份「已剥键的全量数组」strippedFull, 增量分支切 strippedFull.slice(st.len),409 重试用 strippedFull。 实测四条路径(假上游捕获请求体): 首轮 → 3 条 + Reset 正常追加 → 1 条,无 Reset 编辑截断 → 4 条 + Reset 作废指针 → 全量 + Reset __rowId 全程零泄漏 --- app/server/llm.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/server/llm.js b/app/server/llm.js index 619723f..bbb0516 100644 --- a/app/server/llm.js +++ b/app/server/llm.js @@ -744,15 +744,17 @@ async function callModel(cfg, modelId, messages, tools, options) { const cid = opts.context_id; const storeOn = !!(modelCfg.store && cid); const fullBody = JSON.stringify(body); + // 已剥内部键的全量数组(上面 map 的产物,保序保长)。增量分支会把它替换成尾部切片, + // 所以先存一份:409 重试要拿它重发全量,不能拿原始 messages(那上面挂着 __rowId)。 + const strippedFull = body.messages; if (storeOn) { const st = ctxState.get(cid); headers['X-Context-Id'] = cid; const anchor = st && st.len > 0 ? messages[st.len - 1] : null; const anchored = !!(st && messages.length > st.len && anchor && anchor.__rowId === st.lastRowId); if (anchored) { - // 用 body.messages(已剥内部键)而不是 messages(原始数组,带 __rowId): - // 两者长度与顺序一致(上面的 map 保序保长),索引可直接沿用。 - body.messages = body.messages.slice(st.len); // 只发新增 + // body.messages 此时是已剥键的全量数组,与 messages 同序同长,索引可直接沿用。 + body.messages = strippedFull.slice(st.len); // 只发新增 } else { headers['X-Context-Reset'] = '1'; // 全量:首轮 / 进程重启 / 压缩后新 id / 历史被改 } @@ -768,7 +770,7 @@ async function callModel(cfg, modelId, messages, tools, options) { // 409 = relay 那边没有这个 id 的缓存(重启 / TTL / LRU / 压缩换了 id):改发全量重试一次。 // 只重试一次:重发的是全量(带 Reset 头),relay 会整段存下,不可能再 409。 if (storeOn && res.status === 409) { - body.messages = messages; + body.messages = strippedFull; // 已剥内部键的全量,不能拿原始 messages headers['X-Context-Reset'] = '1'; res = await fetch(modelCfg.url + '/chat/completions', { method: 'POST',