fix(index): 别 20 秒 clearInterval,否则第二轮 inject 被宿主裁短

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 的开销可忽略。
This commit is contained in:
叫我小杨同学 committed 2026-10-09 13:11:19 +08:00
1 parent 599c818c34
commit 90d0f7b702
1 file changed
+5 -5
+5 -5
View File
@@ -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 {