Repository navigation
fix(#2110): pi/omp compaction takeover watchdog — release native compaction when no proxy fold lands - #2113
fix(#2110): pi/omp compaction takeover watchdog — release native compaction when no proxy fold lands#2113ranxianglei wants to merge 3 commits into
Conversation
…action when no proxy fold lands
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2160-pr.2113.f326134This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2113.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 PR #2113 review 结论(结构化七问) 审前核对:分支已 rebase 到当前 master( ① 原 issue 方向:正确。#2110 三个根因中 RC1(takeover 无释放路径)是用户直接症状的根因,本 PR 只修 RC1;RC2(nudge 双门槛饥饿,kernel 默认值属产品决策)与 RC3(#1818 preflight 修复未合入)明确排除在外、各自跟踪——范围切分干净,没有顺手扩大。 ② 回归审查(逐项既有行为):
③ 代码审查(超出 diff 的验证):
④ 测试有效性:7 个场景 (A–G) 各钉一个独立分支(stale streak 边界、healthy 持续武装、timeout OR 支路、legacy 兼容、null≠证据、unknown conversation、omp 对等+复用),断言有牙——每一步边界都精确区分
⑤ diff 整洁度:4 文件全部与本 PR 目的相关(src/agent/pi.ts、src/plugin.ts、两个测试文件),无锁文件/生成物漂移、无 version 触碰、无无关重排。干净。 结构化七问:
判定:可合并。wire-shape 增量(status 端点新字段)使其落在 §7.4 auto-merge 门外,需人工合并;合并前等 |
[bot] 🏷 补充确认:两个 review 小修 commit( |
Review: #2113 — takeover watchdog先说结论:方向我认可,这是我在这类插件里第一次看到的"证据化降级"。 下面三点是想在合并前讨论的,按重要性排序。 1. 交还给原生压缩时,bili 侧的 block / visibility marker 账本谁来兜?review 里写的是:
我怀疑这个引用不对。#395 讲的是 pi 自己的 block 存档机制——原生压缩的产物存进 pi 会话。但这里真正的风险面是 bili 侧:
也就是说这个 PR 修好了「不压缩」,但可能引入「压缩了、账本烂掉」。 我同意在 255616 已经越线的场景下这属于两害相权,原生压缩不触发只会更糟。但「两害相权」不等于「无风险」——建议在 PR 描述里把这层交互明确披露出来(哪怕只是一段 warning),而不是用一句 (不阻塞合并,但希望写进文档。) 2.
|
| 指标 | 实测值 |
|---|---|
| 会话请求数 | 101 |
| nudge idle / 实际 fold | 99 / 1 |
| 峰值 usage | 348%(709,995 / 204,000) |
| 峰值 outbound | 946.4 KiB / 541 msgs |
| preflight 一次耗时 | 748,357 ms |
在这种状态下,8 次 streak 意味着 8 次 ~946KB 的无效上游请求,按我这里观察到的单轮延迟算要等好几分钟——而这段时间用户看到的仍然是 Auto-compaction cancelled 刷屏。watchdog 生效的那一刻,症状已经持续很久了。
TAKEOVER_TIMEOUT_MS = 600_000 能兜一部分,但注意它只在 session_before_compact 事件触发时才被检查(activeSince 在无 fold 时不重置),所以它和 streak 是同时生效的竞争条件,不是"6 分钟内必然放行"。
建议(如果标定还有余地):
MAX_STALE_CANCELS降到 2~3。它的作用是防抖动——防止"恰好一两次没 fold"就交出控制权。2 已经足够,8 偏保守。- 或者保留 streak 但把
TAKEOVER_TIMEOUT_MS压到 2~3 分钟,让 timeout 主导、streak 只做兜底。因为两者代价不对称:streak 错了多烧几轮巨型请求;timeout 错了顶多多交还一次原生压缩。
(这条我有实际数据支撑,如果标定已经定了、理解取舍,那当我没说。)
3. 旧代理兼容分支:在 npm 同包安装下近乎不可达
lastCompressAt 缺失时保持无条件 cancel 的保守取向我完全同意——无法区分「旧代理折叠正常」与「旧代理饥饿」,宁可不动。
不过有个观察:插件和代理来自同一个 npm 包(billion-context),同步升级,混合版本窗口很窄。所以这个分支的论证成本 > 它覆盖的概率。它真正的效果是让**"新插件 + 旧代理"的用户继续裸奔**——但考虑到 auto-update 默认开,这个组合本身就短暂。
不是说要去掉(保守是对的),只是如果这个分支有对应测试(场景 D 看起来有),权重大概可以降低,把注意力留给上面第 1、2 点。
一个小的确认
knownFoldAt: Number.NEGATIVE_INFINITY + entry === undefined 分支,代理重启后 lastCompressAt 归 null,第一次会被当作"有新折叠"白送一次取消额度。你在评论里说了"每周期最多送一次基线免费额",测试 A 也 pin 了。
想确认:release 之后 takeovers.delete(sid) 会清掉 entry,那下一轮又变成 -Infinity 基线 again → 是不是每放行一轮就要多烧一轮注定失败的取消?如果是「释放 → 基线 → 8 → 释放」循环,代价可以接受;如果基线额度会累积复用,那是个 bug。倾向于是前者,但想听你确认。
最后
合并这个 PR 是对的。 只是想说明:它修的是「接管后永不降级」,没修 nudge 双闸门饿死本身(那个涉及 acp-kernel 和 KDD #8「flat 50K by design」的契约,应该单独决策)。所以 watchdog 是兜底,不是治本——合并后我这边大概率还需要保留 compress.nudgeGrowthTokens 的 workaround。
合并发版后我会回来验证,并在 #2110 留结论。
[bot] 🏷 三点都对着代码核过了,逐条回。先说结论:第 1 点你指得对、我已改 PR 描述;第 2 点机制成立、我认这个代价,但标定值按仓库规则留给 owner 定(我没擅改);确认问题答案是「前者」,无累积 bug。 1. fold-state 交互 —— 你对了一半,我已补披露核了代码,这里其实是两套独立机制在兜底,不是单一 #395:
所以你说的核心成立:我那句一行带过确实不准,只点了归档路径、没surface #1921 的 drift 交互。但我想对「账本烂掉」稍微纠一下措辞——按代码,最坏结果是部分 fold 重新展开(token 回涨)+ warn 级 drift 日志,不是账本损坏/丢数。而且这两套机制都早于本 PR 存在,watchdog 只是让它们在 owned session 上变得可达(以前 bili 持有压缩权时原生压缩根本不会跑)。 已做:PR 描述加了一节 2. 标定代价 —— 机制成立,我认,但值留给 owner代码确认你的两个子判断都对:释放判定在 代价不对称我也独立认同:放太早 = 多一轮原生压缩(有界、#395 安全、自愈);放太晚 = 又一轮完整巨型 outbound 请求零压缩 + 用户继续看刷屏,逼近原 bug。你那个场景(~946KB/pass)下 8 轮 ≈ 好几分钟无效上游 + 持续刷屏,第一次放行前症状已经跑很久了。这是我当初选 8 时低估的真实成本。 但我没有擅改常量:这是个降级阈值/产品决策,按本仓库规则(fallback/默认值变更归 human)留给 owner。我的建议——若合并前想收紧: 3. 旧代理兼容分支 —— 同意降权,但不删同意同包同步升级 + auto-update 默认开让这个分支概率很低。它是刻意的保守默认(无法区分「旧代理折得好」vs「旧代理饿死」,跨版本中途翻转会静默改变混合安装行为),由测试 (D) 钉住( 确认问题:release → baseline → release 循环答案是前者,无累积 bug。 证据:释放时 一个精确细节值得说清:
两种都是严格 per-cycle、不累积。不是 bug;每周期成本 ≈ 8(null)或 9(旧时间戳)次注定失败的取消——正好就是第 2 点要收紧的那个量级。 立场同意你的定性:本 PR 修的是「接管后永不降级」(RC1),不修 nudge 双闸门饿死本身(RC2,kernel KDD #8 flat-50K 契约,单独决策)也不修 preflight 预算(RC3,#1818)。watchdog 是兜底不是治本,合并发版后你保留 合并判定不变:该合。 唯一建议在合并前定的就是第 2 点的标取值(owner 拍板即可);第 1 点的披露已进 PR 描述;当前 head CI 全绿。 |
|
Closed per owner decision on #2110 (2026-10-06): a release-back watchdog masks proxy-side folding failures (nudge starvation / fold rollback / preflight timeout) as silent degradation — "348% is an alarm; replacing it with a silencer keeps the root cause hidden". Takeover safety must come from making the replacement genuinely reliable (#1818 for RC3; separate decision track for RC2), not from post-facto fallback. Branch |
Part of #2110
What
The pi/omp plugin's
session_before_compactunconditionally cancels host auto-compaction once bili claims ownership (ownsCompactiontrue). If the proxy then never folds — e.g. nudge double-gate starvation in slow-growth sessions (#2110 RC2), or a preflight that exhausts its budget/time before a fold lands (#2110 RC3) — NOTHING compresses anymore: pi's safety net is cancelled and bili's replacement never fires. Production symptom: context grew to 348% of the effective window whileAuto-compaction cancelledrepeated.This PR adds the missing takeover reliability protocol (issue fix 1): the cancellation is only trusted while the proxy is demonstrably folding.
How
GET /__bili/plugin/statusnow exposeslastCompressAt— epoch ms of the last landed fold (session.lastCompress.at, stamped by BOTH model-driven compress and preflight throughapplyRanges),nulluntil the first fold in this process. Field PRESENCE (vs absence on older proxies) is part of the contract.undefined, warn logged citing [pi plugin] session_before_compact 无条件接管后无降级路径:nudge 双闸门饿死 → Auto-compaction cancelled 反复出现,上下文涨到有效窗口 348% #2110);/compactuntouched (reason gate unchanged); omp'sautoPendingconsumption order preserved; ownership decision logic unchanged (refactored only to also return the already-fetched status).Constants are hardcoded (
TAKEOVER_MAX_STALE_CANCELS=8,TAKEOVER_TIMEOUT_MS=600_000) — see Config surface below.Behavior change (old → new)
Scope: pi + omp plugin lanes only. Proxy mode (no plugin header) has no
session_before_compacthook — zero change there.Interaction with fold-state (#1921) — disclosure
Releasing a native pass on a session that already carries bili folds lets pi's native compaction rewrite/remove those folded originals from its history. Two EXISTING mechanisms keep bili consistent — this PR merely makes them reachable for owned sessions, where they previously could not fire:
session_compacthandler POSTs/__bili/plugin/compact(fire-and-forget, 5s) so the proxy archives the now-unreachable blocks (applyCompactionArchive).[acp-drift] fold coverage mismatch/[fold-reconcile] resent history drifted(warn). No silent data loss.Residuals a debugger should expect (pre-existing, not new defects introduced here): (a) worst case some folds re-expand (token re-growth) rather than being retained; (b) the #395 notification is fire-and-forget, so the next request can race ahead of it and log an
[acp-drift]warn before the archive lands. Net: a released native pass is safe (no data loss) but can surface #1921 drift warnings + possible fold re-expansion in sessions that had prior folds.Config surface
None added. No new env var / config key / CLI flag. The two watchdog thresholds are module constants, deliberately hardcoded per Configuration Surface Discipline; a
createBiliPluginopts seam exists for tests only. The only wire change is the additive read-onlylastCompressAtfield on the diagnostic status endpoint (never model-consumed; unknown fields are ignored by older plugins).Regression review (existing behaviors audited)
kernel/.Human review required: the wire-shape addition (status endpoint) puts this outside the §7.4 auto-merge gate.
Tests
tests/plugin-agent.test.ts"[pi plugin] session_before_compact 无条件接管后无降级路径:nudge 双闸门饿死 → Auto-compaction cancelled 反复出现,上下文涨到有效窗口 348% #2110: takeover watchdog releases auto compaction when no proxy fold lands" — 7 subcases: stale-streak release + fresh restart, advancing-fold credit, wall-clock timeout, old-proxy legacy,nullvalue, unknown-conversation sustained, omp parity (incl. probe-status reuse, no second fetch).tests/issue2110-status-lastcompress.test.tspins the status-field contract (null pre-fold, byte-exact epoch ms post-fold).Rebased onto current master; no conflict with the #2029 status-reader work — the new field sits alongside the provenance-aware fields.
中文摘要
pi/omp 插件在判定 bili 接管压缩后无条件取消宿主自动压缩;若代理侧随后一直不折叠(nudge 双闸门饿死、preflight 超预算等),上下文会失去所有兜底(#2110 生产事故:涨到有效窗口的 348%)。本 PR 补上「接管可靠性协议」:status 端点新增
lastCompressAt(最近一次落地折叠的时间戳,模型 compress 与 preflight 两条路径都写入);插件每轮接管后核对——连续 8 次取消或 10 分钟内没有新折叠落地,即放行原生压缩(可自愈:原生跑完上下文降到阈值以下,钩子自然停跳;代理恢复折叠则下一轮重新接管)。旧版代理(响应无该字段)保持原有无条件取消行为不变;手动 /compact、未接管、空 sid 路径全部不变。不新增任何配置项(两个阈值为模块常量,按配置面纪律硬编码)。