Repository navigation
fix: anchor post-rebuild meter to rebuilt payload size (#1820) - #1824
ranxianglei wants to merge 2 commits into
Conversation
[bot] 🏷 PR #1824 review — 代码正确、方向对;但 base 已过期需 rebase,且不能自动合并 先给结论:我把 PR head( 结构化七问
合并判定:代码可合,但须人工处理前置,不能自动合并:
建议下一步:作者把 |
… conflict: keep master's mergeAdjacentConfigurationUpdates import + drop ensureCanonicalId, add postRebuildAnchor* to session.js imports)
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.1825-pr.1824.fbd6f46This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr1824.tgz
npm install -g packageInstall instructions are refreshed on each push. |
What
After a big preflight rebuild the usage-grade baseline is momentarily absent (the rebuild request's own report hasn't landed yet — or the upstream never reports one), so
effectiveTokenCountfell through to branches sizing on the INCOMING RAW history: the very mass the rebuild just folded away. On code/JSON payloads the char-count upper bound inflates ~3.4×, so the first post-rebuild turn decided against a phantom meter (repro: 597900 vs ~178079 real,usage=358%), lit the kernel's uncadenced EMERGENCY branch, pinned the growth reference phantom-high, and injected a 7K-char nudge into an already-at-window context. #1595's re-anchor only corrected it one more round-trip later.Fix (per the issue's suggested direction): the preflight fit gate already measures the rebuilt payload — the view that actually goes out. Stamp that size as a bounded meter anchor:
preflightCompressIfNeededsuccess path stampssession.metadata.postRebuildAnchor = { tokens: rebuiltSize, remainingPrepares: 3 }(same measurement as the fit gate, with the raw-body fallback mirroringoutboundPayloadBreakdown).effectiveTokenCountconsults the anchor AFTER the usage-grade fast path, BEFORE the raw/estimate fallback branches.runPreparetop) and the last tick deletes it → never-reporting upstreams fall back to legacy per-turn sizing instead of a frozen meter; a real usage-grade sample supersedes it immediately (settleUsageReportclears it); a native-compaction boundary drops it (resetSessionCompression, same lineage argument as [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's calibration reset).Behavior change (old → new)
processedMessagesempty, raw body rides),fitsnow measuresoriginalMessagesinstead of an empty array — previously such a request could read "fits" purely from overhead+images and skip the refold path.Tests
tests/issue1820-post-rebuild-anchor.test.ts(3 tests, real proxy + relay harness modeled on [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): (A) non-reporting upstream — poison an estimate-grade baseline, stamp the anchor, assert the meter reads exactly the anchor for its budget, no nudge marker in forwarded bytes, then legacy char-scale sizing resumes after expiry; (B) reporting upstream — a real usage sample supersedes the anchor before its budget runs out and the fast path outranks it; (C) corrupt-stamp validation + compaction-boundary clear. Verified the suite FAILS without the src changes (regression property).Part of #1812 (defect B — merged back from #1820). Umbrella stays open until #1818/#1828 land too.