From 90d0f7b702098b69a1563f68d973dbb5ed02364b 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?= <188421097+HunYiSage@users.noreply.github.com> Date: Fri, 9 Oct 2026 13:11:19 +0800 Subject: [PATCH] =?UTF-8?q?fix(index):=20=E5=88=AB=2020=20=E7=A7=92=20clea?= =?UTF-8?q?rInterval,=E5=90=A6=E5=88=99=E7=AC=AC=E4=BA=8C=E8=BD=AE=20injec?= =?UTF-8?q?t=20=E8=A2=AB=E5=AE=BF=E4=B8=BB=E8=A3=81=E7=9F=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit installIdentityOverride 的 400ms 轮询 20 秒后 clearInterval,挂上就停。但 cordis 会在 session 内切预设、subagent fork、live-mount 时换新的 systemPrompt 代理,此时 wrap 挂不上 → 走原生 assemble → 宿主按 token 预算把长 system 段 裁短 → 用户看到"第二轮只截取了部分"。 session/created / agent-preset/selected / agent/pre-step 这几个事件在正常 session 内第二轮并不触发(保存按钮能救是因为它触发了等价事件链让 guard 重挂), 不能单靠事件覆盖所有换代理路径。 installAssembleGuard 是幂等的(bb850ce/8173f6f),400ms 调一次只是对象 identity + Map get,持续跑到 ctx dispose 的开销可忽略。 --- lib/index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/index.js b/lib/index.js index 9c81a5e..ce6894b 100644 --- a/lib/index.js +++ b/lib/index.js @@ -493,11 +493,11 @@ function installIdentityOverride(ctx, config = {}) { installHungPromptGlobal(); // complete:true 会在 waterfall 之后盖掉 sections;包住 assemble 返回值,每轮都补回注入。 wrapAssemble(); - const started = Date.now(); - const timer = setInterval(() => { - wrapAssemble(); - if (Date.now() - started > 20000) clearInterval(timer); - }, 400); + // guard 需要在每次 cordis 换 systemPrompt 代理时重挂(session 内切预设、subagent fork、 + // live-mount)。原本 20 秒后 clearInterval,之后换代理就包不上 → 第二轮 inject 走原生 + // assemble → 宿主按 token 预算裁剪 → 用户看到"只截取了部分"。installAssembleGuard 幂等 + // (只做对象 identity 校验 + Map get),400ms 持续跑到 ctx dispose 的 CPU 代价可忽略。 + const timer = setInterval(wrapAssemble, 400); if (typeof timer.unref === "function") timer.unref(); try { ctx.on("session/created", wrapAssemble); } catch { /* ignore */ } try {