Repository navigation
fix: resolve compaction ownership for pi virtual-model selections (#1961) - #1962
Conversation
) pi 0.99+ virtual models (router/auto, api "pi-virtual") carry an empty baseUrl — the selection names a router, not a destination — so detectProxyBase(ctx.model.baseUrl) had nothing to read and ownsCompaction bailed, leaving pi's native compaction enabled while the physical requests still reached the proxy: double compression. Resolve the proxy from where the traffic actually went instead: the latest non-failed assistant response's registry baseUrl (launcher httpRewrites and manually /bili/-wrapped models.json both land there), then the launcher's BILI_PROVIDER_REWRITES manifest entry for that provider, then the plain env fallback. Every candidate passes through detectProxyBase so the kill switch and URL validation apply uniformly; any shape mismatch degrades to today's behavior. The downstream carriage gates (#1382/#1392) are untouched — this only fixes WHICH proxy is asked, never WHETHER we own. Closes #1961
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.1975-pr.1962.106fd77This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr1962.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 收到,开始 review PR #1962(pi virtual-model compaction ownership)。初步状态:
|
[bot] 🏷 Review 结论:可合(CI 全绿 + 本地定向验证 + 测试牙齿检查通过)。合并由人执行。 结构化七问
验证证据
review 未发现需顺手修的小问题,也未发现需另行立项的新缺陷。判定:可合,请人工合并 #1962 。 |
…ot exist on the host (#1961) pi v0.99.1 ModelRegistry exposes find(provider, modelId) (delegating to the private runtime.getModel); there is no public getModel, so ctx.modelRegistry?.getModel?.(...) always short-circuited to undefined — tier ① (the only tier that can resolve ownership in the issue's own lane: manual /bili/ wrapping, no env, no rewrite manifest) was dead code on the real host. Tests passed because the stubs invented the same non-existent method; they are now shaped like the real registry surface, and a mutation check confirms the #1961 repro test fails against the old call. Same failure class as #1943: object-literal stubs cannot catch host-API drift.
|
评审发现并追加修复(bad516d):tier ① 调用了宿主上不存在的方法,原提交里它是死代码。 缺陷:原提交 影响:三层层级里 ②(BILI_PROVIDER_REWRITES env)③(BILLION_CONTEXT_PROXY env)在 launcher/attach 模式都在,没事;但 #1961 报告者自己的场景(models.json 手动 /bili/ 包装、裸 pi、无任何 env)只有 tier ① 能解析——它是死的,issue 的复现路径原样保留。其余 4 个 call site(pi.ts:276/696/764/820)宣称的无 env carriedSids 收益同样经过这个死层。 为什么 CI 是绿的:测试桩写的是 修复(bad516d):
验证:typecheck ✔ build ✔ plugin-agent.test.ts 61/63(2 个失败在未含本修复的原提交 de69864 上同样失败、且与本次改动无关——沙箱网络边界所致,GitHub CI 此前对该 head 14/14 绿)。其余设计(branchEntries/reason 载荷、AssistantMessage 字段、StopReason、Model.baseUrl、getBranch 白名单、carriage 门不动)均已对照 pi 0.99.1 源码核实无误。 |
[bot] 🏷 已核对追加修复 先认账:我上一轮 review 放过了这个死层——只核对了代码内部一致性,没有对照 pi 宿主的真实 API 面,而测试桩恰好按补丁自己的假设塑形( 核对结果(bad516d = de69864 + 1 commit)
七问(增量部分)
判定:可合,请人工合并 #1962 。 |
Closes #1961
Problem
pi 0.99 added virtual models (
pi.registerVirtualModel): the selected model (e.g.router/auto,api: "pi-virtual") routes to a physical model per request and has an emptybaseUrl. The plugin's compaction ownership check (ownsCompaction) resolved the proxy base fromctx.model.baseUrl->detectProxyBase(""). When the process env does not carryBILLION_CONTEXT_PROXY(manual/bili/baseUrl wrapping in models.json, or any setup where the routing evidence lives in the model catalog rather than env), that returnsundefined,session_before_compactis not cancelled, pi's native compaction stays enabled, while the physical requests still go through the proxy -> double compression of one session (the failure the README warns about).Verified against pi v0.99.1 source (
packages/coding-agent/src/core/virtual-models.ts): virtual entries hardcodebaseUrl: ""; "Everything below the routing step only sees physical models ... A virtual model never reaches a provider"; assistant messages record the physicalprovider/model.Fix
For a virtual selection only (
ctx.model.api === "pi-virtual"), resolve the proxy base from where the conversation's traffic actually went, in priority order:findLatestResponse: skipsstopReasonerror/aborted) -> its physical model's registry entry (ctx.modelRegistry.getModel(provider, modelId)?.baseUrl). In launcher mode the registry holds the rewritten<origin>/bili/<upstream>URL; in manual wrapping it holds the user's wrapped URL - both carry the proxy origin exactly.BILI_PROVIDER_REWRITES[provider]for that provider (covers httpsRewrites lanes where the registry URL is raw upstream).detectProxyBase(undefined)) - status quo.Every candidate passes through
detectProxyBase, so theBILLION_CONTEXT_PLUGIN=0kill switch and URL validation apply uniformly; any shape mismatch degrades to today's behavior. The event's ownbranchEntriesis preferred over re-queryingsessionManager.getBranch().All downstream carriage gates are untouched (#1382 carriedSids/fetchStatus probe, #1392 opaque-scheme veto): this changes which proxy is asked, never whether we own - probe failure still defers to native compaction.
The same resolution automatically benefits
before_provider_headers(carriedSids stamping now works for virtual sessions without env) andregisterTools; the omp-lane call sites are unaffected (omp predates virtual models; the guard makes it moot).Behavior change disclosure (old -> new)
BILLION_CONTEXT_PROXYenv, physical route resolvable (registry/manifest)BILLION_CONTEXT_PLUGIN=0Config surface
No new config fields/env vars/CLI flags. Only reads existing ones:
BILLION_CONTEXT_PROXY(fallback, unchanged semantics),BILI_PROVIDER_REWRITES(launcher-injected manifest, already parsed byparseProviderRewrites),BILLION_CONTEXT_PLUGIN(kill switch, now applied uniformly to all candidates viadetectProxyBase). No migration needed.Tests
New
#1961test in tests/plugin-agent.test.ts (9 cases): repro (cancel without env via registry), carriage gate preserved against unknown proxy, manifest +getBranch()fallback, raw-upstream -> no claim, failed-route skipping, empty-branch env fallback intact, full stamp flow (carriedSids without env), non-virtual regression guards (both directions), kill switch beats candidates. Verified the test fails on the unfixed code (stash -> not ok -> pop).typecheck clean - tests/plugin-agent.test.ts 63/63 - build OK - rebased onto current master