From 9b07384038d439f21c070be8696696f1f93dcfe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=AB=E6=88=91=E5=B0=8F=E6=9D=A8=E5=90=8C=E5=AD=A6?= Date: Fri, 9 Oct 2026 21:20:01 +0800 Subject: [PATCH] =?UTF-8?q?feat(inject):=20.hung-disabled=20=E5=90=AF?= =?UTF-8?q?=E7=94=A8=E6=96=B9=E6=A1=882=20=E2=80=94=20assemble=20=E6=8C=89?= =?UTF-8?q?=20user=20turn=20=E5=8E=BB=E9=87=8D=20+=20retry=20=E4=BE=8B?= =?UTF-8?q?=E5=A4=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - shouldInjectAssembly(context, home): 开关存在时,只在 last message role===user 或 __dshPurgeRetryPending 为真时放行,tool-call 回环返原 assembled - rewriteFn(installAssembleGuard 路径) + system-prompt/assemble 回调两条路径同判断 - installHungPromptGlobal: hung 永久返空,把 patch #81 的 "system 不含 inject 时 补塞" 补救逻辑废掉,让 inject 完全由 cordis 层决策,避免绕过规则 - continue-retry.js: tracker.takeRetry 成功后设 __dshPurgeRetryPending=true, 下次 assemble 消费后清零 — 救场链路保留 --- lib/continue-retry.js | 4 ++++ lib/index.js | 47 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/lib/continue-retry.js b/lib/continue-retry.js index f81b131..8f717f2 100644 --- a/lib/continue-retry.js +++ b/lib/continue-retry.js @@ -323,6 +323,10 @@ export function installContinueRetry(ctx, options = {}) { const id = sessionIdOf(payload?.agent); const key = `${payload?.turn || 0}:${payload?.step || 0}:${payload?.failure?.code || ""}`; if (!tracker.takeRetry(id, key, cfg.retryMax)) return downstream; + // [方案2] 标记 retry pending,让下次 system-prompt/assemble 强制塞 inject + // (消费一次后由 shouldInjectAssembly 清掉)。user 发消息自然塞,不需要; + // retry 不是 user 触发,messages 结构没变,必须靠这个 flag 让 assemble 吃到。 + globalThis.__dshPurgeRetryPending = true; return { kind: "retry" }; }); diff --git a/lib/index.js b/lib/index.js index 77c3b31..080c607 100644 --- a/lib/index.js +++ b/lib/index.js @@ -201,10 +201,11 @@ function installHungPromptGlobal() { const fn = () => { try { const home = core.findDshHome(); - // [dsh-purge-fix 2026-10-09 方案A] 开关文件 DSH_HOME/.hung-disabled 存在时, - // hung 返空串 → 每步 model.step 不再追加 prompt-inject.md 全文 (省 ~9000 token/步)。 - // system 层由 patch #67/#68/#74 保证不被 rewind/compaction 洗掉,够兜底。 - // 想关掉开关恢复全量 inject: 删掉 .hung-disabled 文件 + 重启 DSH。 + // [dsh-purge-fix 2026-10-09 方案2] 开关文件 DSH_HOME/.hung-disabled 存在时, + // hung 永久返空 — 把 patch #81 的 "system 不含 inject 时补塞" 补救逻辑废掉, + // 让 inject 完全由 cordis 的 system-prompt/assemble 回调 (按 user turn + retry + // 条件) 决策,避免 hung 补塞绕过规则。 + // rm .hung-disabled + 重启 → 回到旧行为 (全量 inject 每步都塞)。 if (home) { try { if (fs.existsSync(`${home}/.hung-disabled`)) return ""; @@ -219,6 +220,36 @@ function installHungPromptGlobal() { return fn; } +// [dsh-purge-fix 2026-10-09 方案2] 按 user turn 去重 + 自动重试例外。 +// 规则: +// - .hung-disabled 开关不存在 → 原行为 (每次 assemble 都塞 inject) +// - .hung-disabled 开关存在 → 只在以下场景塞 inject: +// 1. messages 最后一条 role === "user" (user 刚发消息,新 turn 的首次 model.step) +// 2. globalThis.__dshPurgeRetryPending === true (continue-retry 刚触发) +// tool-call 回环 (last role === "tool" / "assistant") → 不塞 +// 命中后清掉 retry flag,保证单次消费。 +function shouldInjectAssembly(context, home) { + if (!home) return true; + try { + if (!fs.existsSync(`${home}/.hung-disabled`)) return true; // 开关没开 → 原行为 + } catch { return true; } + if (globalThis.__dshPurgeRetryPending) { + globalThis.__dshPurgeRetryPending = false; + return true; + } + // 从 context 多个可能路径找 messages (cordis 版本间字段名有差异,保守多试)。 + const msgs = + context?.session?.messages || + context?.messages || + context?.conversation?.messages || + context?.history || + null; + if (!Array.isArray(msgs) || msgs.length === 0) return true; // 拿不到 → 保守塞 + const last = msgs[msgs.length - 1]; + if (!last) return true; + return last.role === "user"; +} + function injectSnapshot(dshHome = core.findDshHome()) { const resolved = rules.resolveInjectText(dshHome); return { @@ -498,7 +529,11 @@ function installIdentityOverride(ctx, config = {}) { wrapDisposers.add(d); return d; }; - const rewriteFn = (assembled, context) => rewriteLiveAssembly(config, assembled, context); + const rewriteFn = (assembled, context) => { + // [方案2] installAssembleGuard 走的也是这条路径,同样按 user turn / retry 条件决策。 + if (!shouldInjectAssembly(context, core.findDshHome())) return assembled; + return rewriteLiveAssembly(config, assembled, context); + }; const wrapAssemble = () => { try { const prompt = ctx.systemPrompt; @@ -526,6 +561,8 @@ function installIdentityOverride(ctx, config = {}) { } } try { + // [方案2] 工具回环/非 user turn 不塞 inject,直接返原生 assembled。 + if (!shouldInjectAssembly(context, core.findDshHome())) return assembled; return rewriteLiveAssembly(config, assembled, context); } catch (err) { try { console.warn("[dsh-purge] rewriteLiveAssembly failed:", err?.message || err); } catch {}