Repository navigation
fix: prefer usage-grade anchor over anonymous raw-history fallback (#2033) - #2036
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2071-pr.2036.d4fe0bbThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2036.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 PR #2036 review 完成。分支基于当前 master(merge-base == e6b2857,无需 rebase),单提交 f37882d + 我补的一个注释修正提交 90ea8ad。查重:open/closed 全检索无重复项,#2033 是唯一来源 issue。 审核过程(不是只读 diff):
结构化七问:
CI:新 head 90ea8ad 上 16 个 check(test 矩阵 ubuntu/windows × node 22/24、codex/dsh/opencode/pi 真客户端 e2e、registry e2e、real-image billing、build-artifact)正在跑, |
[bot] 🏷 CI 跟进:head |
Closes #2033
What
effectiveTokenCount(src/server.ts) returned the full raw-history upper bound for every anonymous-prefix-affinity session, before thelastUsageGradeTokensanchor check could run. An anonymous session that had already received a real usage report therefore lost its measured anchor after a single failed turn (503 / no usage):armFailureShrinkarms an estimate-grade baseline, and the next sizing decision took the anonymous early return withraw = estimateCoreMessagesUpper(msgs) + inboundImageTokens— the client's full resubmitted history, which carries unfolded content server-side folding never shrank. Explicit-identity sessions were protected by the anchor check (#1839/#1846); anonymous sessions were not.Repro numbers from the regression test (window 120K, real input 5000): pre-fix the next nudge sized at 58701 (raw bound, ~12× the real input,
usage=49%of window); post-fix it sizes at 5000 (source: "usage").Fix
One reordering inside
effectiveTokenCount: the positivelastUsageGradeTokenscheck now runs before the anonymous-prefix-affinity raw-history return. The usage/overflow-arm fast path stays first; the raw-history fallback remains immediately after, still serving genuinely anchor-less anonymous sessions (#553) and never-reporting upstreams (#728 — their anchor is absent by construction, so this change cannot affect them).Behavior change disclosure (old → new)
estimate)usage) — the fixest <= 0 && grade > 0path is unreachable: the anchor is only written bysettleUsageReport, which requires a prior prepare having writtenlocalInputEstimate > 0; neither stat is persisted, so restart resets both together)No caps added, no failure rescue removed, no percentage display logic touched. Image accounting (#1137): anchored sessions return the anchor without adding
inboundImageTokens— identical to today's explicit-session behavior; anchor-less anonymous sessions keep images inraw. Fork isolation verified: fork adoption copies compression blocks only, not stats, so pfa-* forks start anchor-less and keep the conservative bound.Tests
New
tests/issue2033-anonymous-anchor.test.ts(genuine anonymous OpenAI client, no identity headers):5000, sourceusage), zero preflight forwards, no emergency marker in the stream. Fails pre-fix with58701 !== 5000.estimate) — pins the fork 会话 lastInputTokens=0 时 preflight 退化为字符估算,大载荷被低估后不压缩直接裸转上游 #553/[Bug] 上游从不报告 usage 时 nudge 永不触发——上下文无界增长直到超窗(ChatGPT 登录态后端) #728 guardrail.Related suites green locally (targeted, per local-test discipline): issue1839-ghost-denominator (G1–G3), issue1569 (A1–A6, B1/B2), silent-backend-nudge (#728A/B/C, #1119), fork-adoption; typecheck clean. Full suite + codex e2e run in CI (request-pipeline change).
Config surface
None touched.