Repository navigation
fix: deliver configured v2 model windows to the proxy; anchor nudge sizing on real usage (#1569) - #1589
Conversation
…izing on real usage (#1569)
ec4848b to
210cddc
Compare
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.1528-pr.1589.1d436baThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr1589.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 PR review — fix for #1569 (rebased onto current master) ① 原 issue / 方向
Stale base → 已直接 rebase ② 回归审查(既有行为清点)
③ 代码审查
④ 测试有效性 ⑤ diff 整洁度 Behavior changes(flagged,与 PR 披露一致)
验证证据(final head
Out-of-scope 观察(未动,不另立项): 结论:可以合并(待新 head CI 转绿)。 中文摘要:修复了 v2 宿主配置的 limit.context 无法送达代理、以及 estimate-grade 轮次按字符上界(~3.5× 高估)误触发压缩的问题(改为以真实 usage 报告为锚点使用校准估算);原分支基线过旧,已直接 rebase 到当前 master 并把三处锚点写入收敛进共享 settleUsageReport(语义完全等价),typecheck/build/全量测试(0 失败)全部通过,可以合并。 |
[bot] 🏷 补充:新 head |
Fixes #1569
What & why
#1569 reported that on opencode v2 (stable) the context limit configured in opencode.json never reaches the bili proxy:
x-bili-plugin-context-windowis never stamped, so the proxy silently falls back to registry-peek windows — (a) suppressing proactive nudges for months and (b) misfiring emergency shrink. Triage found two independent defects.A — window never stamped (plugin side). The V2 plugin only read windows from
ctx.catalog.model.list()— but stable v2.0.x builds expose NOctx.catalogat all (probed @opencode/cli 2.0.18: Context exposesmodel/providerdomains instead;ModelApi.list() → { location, data: ModelInfo[] }withlimit = { context, output }). So on every stable release the header went unstamped and the proxy degraded into registry/configured-window sizing silently.Fix:
refreshWindowsnow harvests from three seams —ctx.model.list()(v2.0.x stable),ctx.catalog.model.list()(kept as a hedge for builds/tests exposing it), andcatalog.provider.list()records (newer dev builds; Map or plain-object model maps, sync or thenable). When all seams yield zero usable limits, the plugin emits a one-shot console.warn telling the user that opencode.json's limit.context is NOT reaching the proxy. On the proxy side, a plugin-marked request that still carries no window from any source now logs one warn per model (previously silent).Timing note: each seam commits independently with one
.thenhop — the same microtask profile as the original single-await implementation. A sharedPromise.allsettlement point costs an extra hop that the client's next request outruns under Node's microtask FIFO; that deterministically reproduced the round-2 stamp miss in tests/opencode-v2.test.ts#6 during development.B — estimate-grade sizing misfires (proxy side). While the latest baseline is estimate-grade (the transient window right after a failed turn), nudge/truncation sizing used
min(char-count upper bound, localInputEstimate)— ~3.5× high on code/JSON-heavy tool results. That inflation lit spurious nudge bands whose kernel growth-reference pin then blocked GENUINE nudges until context regrew past the artifact (false T1 at 66%, false EMERGENCY at 120%, ~20-min dead zone in the #1569 log).Fix: new
SessionStats.lastUsageGradeTokensanchor, written ONLY by real upstream usage reports (streamingapplyUsageSample, JSON non-stream path, looprecordUsage; the arming paths never touch it). While anchored,effectiveTokenCountsizes on the billing-calibrated CJK-aware estimate of the current view (estimateCoreMessages) instead of the char-count upper bound. Never-reporting upstreams keep the fail-closed upper-bound behavior (#553/#728) — their anchor stays absent. The anchor is dropped at native-compaction boundaries (pre-compaction billing evidence describes a payload lineage that no longer exists).Behavior changes (disclosure)
min(char-count upper bound, localInputEstimate)→ new = calibratedestimateCoreMessages(current view). Why: the old value over-counts code/JSON-heavy tool results ~3.5×, producing spurious nudge bands plus a dead zone that suppressed genuine nudges ([OpenCode v2] Configured model context limit never reaches the proxy (x-bili-plugin-context-window not stamped) - silent registry-peek fallback suppresses proactive nudge and misfires emergency shrink #1569 log). Never-reporting upstreams are unchanged.armOverflowShrinkpath); safety unchanged (the 400 arm remains the backstop).ctx.model.list+catalog.providerseams now; warns once per plugin instance when all seams are empty (was silent).lastUsageGradeTokens(persisted like other stats; absent on legacy session files → legacy path). No config-schema change.Pre-flight
npm run typecheck✅npm test: 3054 tests, 3034 pass, 8 fail — all 8 reproduce identically on clean master baseline (1c60633) in a temp worktree (e2e bug(ccr): retrieval-drop correction notes are consumed before upstream delivery is confirmed #1457 drop-note lanes ×2, resolveCompressSurface ×2, wire-contract goldens ×4) → pre-existing here, not caused by this changenpm run build✅tests/issue1569-window-stamp-and-anchor.test.ts: 8/8 (A1–A6 seam matrix incl. malformed-entry inertness + one-shot warn; B1/B2 integration A/B: poisoned estimate view, reporting vs never-reporting upstream)tests/opencode-v2.test.ts: 28/28 (round-2 stamp timing preserved)