Repository navigation
fix: cancel pi/omp auto-compaction only on evidence the proxy carries the conversation (#1382) - #1383
Conversation
… the conversation (#1382)
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-1383Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr1383.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 核验完成(本 PR 为此前会话的产物,按流程未重做,做了完整的复核验证)。结论:可以合并。 方向与根因判断(审原 issue)根因定位正确:「代理进程存在」(native mode 给整个进程设了 既有行为回归清点(触碰路径逐项)
测试有效性(质量关)本地跑了阴性对照:把 Pre-flight 与 CI(在分支头 48ebde0,已 rebase 到当前 master d3c8af8,无 stale base)
两个已评估、接受不动的观察项(不另立 issue,均属 #1382 同族且不劣于修复前)
行为变更披露PR 正文含完整 old→new 表;实际变更行仅三行且均为预期(非 http(s) provider + 代理运行中 / 绕过代理的 http provider / 压缩时刻代理宕机:cancelled → not cancelled)。无未披露漂移。 中文摘要:复核确认该 PR 修的是「只要代理进程存在就取消宿主自动压缩」这一根因(改为仅在有正证据代理承载该会话时才取消),既有行为逐项核对无回归、异步 handler 机制经本机 pi dist 验证、回归测试经阴性对照证明有牙、本地三项检查与 CI 11/11 全绿,可以合并(合并操作由人工执行)。 |
|
深审通过(独立验证,零改动): 设计核验(#1382 的根因是"代理存在"被当成"对话在代理上"的证据,修复换成真实证据链):
异步 handler 合法性:注释声明已验证 pi runner await omp 分支顺序核实: 实测:plugin-agent 56/56 全绿。 合并无阻塞。 |
[bot] 🏷 感谢独立深审,结论一致:合并无阻塞。一处细节更正(不影响你的结论): omp 分支的实际顺序( pi.on("session_before_compact", async (event, ctx) => {
if (!autoPending) return undefined;
if (!(await ownsCompaction(ctx))) return undefined; // 探测不过 → 保持 armed
autoPending = false; // 仅取消时复位
return { cancel: true };
});这个顺序恰好支撑你「无双杀窗口」的判断:
薄冰点认同:pi runner 的 维持原结论:零改动、可合并(合并操作由人工执行)。 |
|
Follow-up filed: #1392. The non-http baseUrl veto answers "bili 看不见这条流量(今天)",却被用来回答"这条流量永远上不了 bili"——两个命题不同。#1392 记录调查方向:①pi 非-http baseUrl 全量普查(哪些 scheme、子进程是否继承/遵守 HTTPS_PROXY)②pi-claude-bridge 具体行为(若其子进程遵守代理环境变量,bili 可能只需文档+routes 改写即可接入,零新代码)③opt-in 设计候选(named-bridge 白名单只放宽候选集、证据链仍是唯一闸门——存在性永不等于证据,#1382 的教训不重演)④bridge 自带 session_before_compact 接管时的归属权问题。 本 PR 作为止血合并,语义今天事实正确(当前没有任何 bridge 流量能到 bili)、完全可逆。 |
[bot] 🏷 收到,#1392 已核对(内容完整:四类调查方向 + 「存在性永不等于证据」硬约束 + bridge 接管时的 handler 归属问题)。 两点确认:
|
Narrow the #1383 stopgap veto so an explicitly opted-in non-http(s) baseUrl provider (e.g. pi-claude-bridge's literal "claude-bridge") can claim compaction ownership when its traffic actually flows through bili. Opt-in (either mechanism): config file plugin.nonHttpProviders ({"<providerId>": true}) or env BILI_NON_HTTP_PROVIDERS (comma-separated). The launcher resolves both and mirrors them to the client env. Safety property preserved (#1382): opt-in only widens the candidate set. An opted-in non-http provider still passes the SAME carriage-evidence gate (carriedSids local stamp / /__bili/plugin/status probe), so unrouted traffic never cancels and native compaction keeps working. No behavior change unless opted in: with no opt-in configured, non-http(s) providers are never cancelled - byte-for-byte the prior stopgap behavior.
Narrow the #1383 stopgap veto so an explicitly opted-in non-http(s) baseUrl provider (e.g. pi-claude-bridge's literal "claude-bridge") can claim compaction ownership when its traffic actually flows through bili. Opt-in (either mechanism): config file plugin.nonHttpProviders ({"<providerId>": true}) or env BILI_NON_HTTP_PROVIDERS (comma-separated). The launcher resolves both and mirrors them to the client env. Safety property preserved (#1382): opt-in only widens the candidate set. An opted-in non-http provider still passes the SAME carriage-evidence gate (carriedSids local stamp / /__bili/plugin/status probe), so unrouted traffic never cancels and native compaction keeps working. No behavior change unless opted in: with no opt-in configured, non-http(s) providers are never cancelled - byte-for-byte the prior stopgap behavior.
…wnership (#7060) The omp lane's ownsCompaction used state.identityAt === sid as local evidence to claim compaction ownership directly, but the identity registration only populates registeredIds — it does NOT create a tracked session. So the plugin could cancel native compaction for a conversation the proxy never tracked, leading to 'no fold + no fallback' overflow. This is the #1383 evidence gate hole on the identity-stamp path: the gate was designed to prevent #1382 (cancelling compaction for a conversation the proxy doesn't carry), but the identity-stamp path bypassed the carriage check. Fix: remove the omp local-evidence short-circuit so the status probe always runs for omp. The probe (GET /__bili/plugin/status) is the authoritative carriage check — if the proxy reports the conversation unknown, the plugin does NOT claim ownership and native compaction proceeds. This restores the documented design intent ('carriage evidence still decides', pi.ts:1010) and the safety principle ('a wrong cancel overflows the session', pi.ts:1016). Regression test: updated test (H) in tests/plugin-agent.test.ts to assert the correct behavior (identity-registered session is NOT carried by construction — proxy reports unknown → native compaction proceeds).
Problem (#1382)
With pi-claude-bridge as the provider (or any other model whose traffic never reaches the proxy), the pi/omp plugin's
session_before_compacthandler cancelled Pi's threshold/overflow compaction whenever a proxy process existed —detectProxyBase()falls back toBILLION_CONTEXT_PROXY, which native mode sets for the whole process. The bridge runs Claude Code as a child process calling Anthropic directly, so the proxy never carried the conversation; the bridge also disables Claude Code's own auto-compact and takes over Pi's compaction in its own handler, which never runs once an earlier handler returnedcancel. Net effect: nothing ever compacted, the session grew until overflow, and the overflow pass was cancelled the same way.Fix
Cancel only on positive evidence that THIS conversation's traffic reaches the proxy (
ownsCompactioninsrc/agent/pi.ts), checked in order:ctx.model.baseUrlpresent but not an http(s) URL (e.g. the literal"claude-bridge") → never cancel — such providers' traffic cannot reach the proxy by construction;x-bili-plugin-conversationfor this session id (tools registered AND a request routed through the proxy) — newcarriedSidsbookkeeping in the header-stamp path — or, for omp, the identity register succeeded (identityAt);GET /__bili/plugin/status?conversationId=returns ok for this session id.Probe failure (proxy down/hung) = no evidence → do NOT cancel. The asymmetry is deliberate: a false "not carried" costs at worst a double compression (survivable — the proxy archives unreachable blocks on
session_compact, #395); a false "carried" means NOTHING compacts and the session overflows (this bug).Manual
/compactstays user-owned in every case (#851 semantics unchanged). Handlers are now async — pi's runner awaitssession_before_compacthandlers before consulting.cancel/.compaction(verified against pi-coding-agent 0.87.1 dist), so no host-side change is needed. The omp lane gets the same gate: same root cause ("proxy exists" ≠ "proxy carries this conversation").Behavior changes (old → new)
/compactKnown residual corner (identical to pre-fix behavior, out of scope): a mid-session switch from a proxied provider to ANOTHER HTTP provider added after launch (never rewritten, traffic direct) — stale local stamp / status-200 could still cancel there.
Tests
New
#1382regression test (cases A–H): the bridge repro (non-http baseUrl + unknown conversation), veto alone (proxy confirms but baseUrl non-http), status-confirmed carriage, never-seen http provider, local-stamp fast path (no round-trip needed), probe-failure safe side (connection refused), omp parity both directions, omp identity fast path. Verified to FAIL on the pre-fix code and pass on the fix. Two existing tests were updated toawaitthe now-async handlers only — their assertions are unchanged (they use ctxs without session ids, which keep the legacy cancel).Pre-flight on the branch head (rebased onto current master d3c8af8): typecheck ✅ · full suite 2636 pass / 0 fail / 11 skipped ✅ · build ✅.
Closes #1382
中文摘要:修复了 pi/omp 插件「只要代理进程存在就取消宿主自动压缩」的问题(#1382)——现在只有当代理确实承载该会话时(本地已为该会话盖章、omp 身份注册成功、或
/__bili/plugin/status确认)才取消自动压缩;非 http(s) 的 provider(如 pi-claude-bridge 的字面量"claude-bridge")永不取消,其自带的压缩接管得以正常运行。回归测试在旧代码上失败、新代码上通过,全部检查绿色,可以合并。