Repository navigation
[PR] fix(#1916): usage-grade baseline write authority gate — isolate concurrent same-session small-stream samples | [PR] fix(#1916): usage-grade 基线写入权威门——隔离并发同 session 小流样本 - #1938
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.3959-pr.1938.4ba0090This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr1938.tgz
npm install -g packageInstall instructions are refreshed on each push. |
0321e60 to
e2a2413
Compare
[bot] 🏷 PR #1938 review + 修复完成(head: 开始 review 时 CI 是红的(test matrix 4×全红 + image-billing e2e;master HEAD 同矩阵全绿,确认本 PR 引入)。根因与处置: 发生了什么:新权威门隔离一切「无解释的大幅下移」。#767/#1843/#1857 的五个 fixture 直接往 session 里戳一个 stale-high 基线(外生陈旧——生产中不可达)并期望一轮内恢复真实 usage;门对这类样本没有任何请求级解释可给,且这些会话是年轻会话/单消息流,shape-gated 路径也走不通 → 断言全部落在被隔离的旧基线上。
结构化七问:
行为变更披露(旧→新):
本地验证(定向;全量交 CI):issue1916 13/13 · usage-observability+cache-ledger 44/44 · issue767+e2e-image-billing 17/17 · typecheck clean · build OK。全量回归 + E2E(codex/registry/native lanes)等 判定:CI 转绿即可合并。 |
[bot] 🏷 CI 全绿,收工判定确认。
无回归。PR #1938 head = 唯一遗留:PR 正文残留 ② 的持久化事实错误(详见上一条回复的更正段),建议作者会话修订正文措辞后合并。 |
…rent same-session streams Concurrent request families sharing one session id let a small foreign stream's usage report clobber the main stream's lastInputTokens baseline (incident: 251655 -> 69419), firing #1595 re-anchor and poisoning every downstream consumer (nudge timing, preflight floor, window self-heal, cache ledger) before a degenerate fold misread the poisoned denominator (#1911). settleUsageReport now consults admitUsageSample first: a large unexplained drop below a usage-grade baseline quarantines the sample (baseline, nudge refs, ledger, seam forensics all untouched). The gate only arms once the session has accumulated substantial history (>= REWRITE_MIN_KNOWN_REFS known refs) — the clobber needs a resident main stream to displace, and young sessions / thin stateless clients must keep their stale-baseline rescue and learned-cost correction (e2e-image-billing). Explanations that open the gate: non-usage provenance baselines, upward / within-interval samples, this-request folds (request-scoped postFold — session-scoped fold flags are unsafe under concurrency), client compaction boundaries (single-use, multi-message shaped only), meter switches (#1536 wire/upstream/model identity change = incomparable meters), and an escape valve (3 consecutive low samples from conversation-shaped requests, >= 10 msgs). Single-message foreign samples can never move the baseline down.
…ed contract The valve run counter drifted looser than its documented contract in two ways: 1. Unshaped samples (single-message / unknown count) incremented the run even though only shaped samples can admit through the valve — three B-family spam samples pre-charged the counter so a single shaped low sample was admitted at 'count 3' it never earned. Now unshaped samples neither advance nor break the run. 2. Admitted samples (upward / within-margin / non-usage provenance) did not reset the run, so a stale pre-admission run survived into the next drop and could fire the valve early. Every admission path now resets. Both changes are strictly tighter (the approved fail-safe direction): worst case delays an escape-valve admission by one honest cycle. New case M pins both halves with teeth — each half fails on the pre-fix code (stolen streak admission at 88k; stale-run valve admission at 80k). Completes the stale header pin list (J, M). Builds on e2a2413 (arm threshold). Verified locally: issue1916 13/13, usage-observability+cache-ledger 44/44, issue767+e2e-image-billing 17/17, typecheck clean, build OK.
049539d to
8490519
Compare
(ai: vllm-qwen/qwen3.8-27b) 冲突已解决并推送。分支已 rebase 到当前 master(745be9f),最终 head 冲突原因(全部来自 master 在 PR 分出后的结构性重构,不在门禁逻辑本身):
解决原则:双方意图取并集,不改任何语义。门禁逻辑( 一处必要附带修改:master 给 Session 加了必填字段( 验证(本地定向,全量交给 CI):
八问:
判定:分支恢复干净,等 CI 全量把关;CI 绿即可合并。 |
Fixes #1916(子缺陷 1–2:写者权威;子缺陷 3「B 族身份」待 ACP_DUMP_BODY 转储确认,宿主侧入口路由由在途 PR #1431 承接)
问题
同一 session id 上并发两条请求流时,小流(单消息、无 tools、正常 max_tokens 的宿主内部调用——生产实例为 DSH auto-review,见 #1307/#1309/#1314 与 @heptaspirit 的独立样本)的 usage 报告以 usage-grade 身份覆盖大流的会话基线:事故中主流基线 251,655 被拽到 69,419,触发 #1595 re-anchor(247,994 → 69,419),污染 nudge 时序、preflight 触发地板、窗口自愈输入与缓存台账;下游折叠又用被污染的基线做分母,产出 postCtx≈0 退化折叠(#1911 的症状)。#1913 修了折叠计量空间,但基线本身仍被覆盖。
修法
在唯一 settle 汇合点
settleUsageReport(src/cache-ledger.ts)加权威门,判定逻辑在admitUsageSample(src/session.ts,与 nudge 参考同模块同 margin 刻度):门仅在会话积累出实质历史后武装(known refs ≥ REWRITE_MIN_KNOWN_REFS=20,复用 #1001 静默重写检测的「实质历史」阈值):覆盖机制需要一段驻留的主流可被顶替;年轻会话没有值得保卫的主流基线,且无状态瘦客户端(每轮一条消息、不共享 id)的低值真样本(stale 基线救援、learned-cost 修正——e2e-image-billing 钉住的场景)本就没有形状门可以走。CI 首轮即抓到缺此条件的回归:image-billing e2e 的 stale-high 基线救援样本被误隔离。
默认规则:门已武装、当前基线 provenance 为
usage、样本 total 大幅低于基线(超过一个 nudge growth interval)且无解释事件 → 隔离该样本——基线、nudge 三件套、input/cached 聚合、缓存台账行、seam 取证全部不写,emit[acp-usage] quarantined foreign usage sample …warn。隔离是 fail-safe 方向:sticky-high 基线只会让 nudge 偏晚一轮,随后任何真实的大流样本(向上方向恒放行)即自愈。放行解释(按序判定,均继承同一门,满足 issue 建议第 3 条):
postFold:loop 内折叠经 LoopCtx 逐轮置位、preflight 折叠经 Prepared.preflightFolded 单次盖章)——不用 session 级 fold 标志(pendingFoldUsage/compressCreditTokens):并发小流的 settle 会中途清 pfu、并发 prepare 会清零 credit,小流样本可借被偷走的标志获准入并重写基线(不安全方向);三条 settle 通道全部接上:loop SSE(LoopCtx 透传)、非流 JSON(Prepared 直传)、plugin 管道(pipePluginChatWithStrip / pipePluginResponsesWithStrip / pipePluginJson / applyUsageSample 尾部可选参数透传)。两种压缩模式均覆盖(plugin-mode 代理侧同样走该门;agent 本地执行的压缩不经此路径,不涉及)。
config surface
无新增/重命名/语义变更:无新配置字段、env、CLI flag;无持久化格式变更(
foreignSampleStreak内存态,buildRecord 显式枚举自动排除);无 wire/message-shape 变更。行为变更披露(旧 → 新)
[acp-usage])已知残留(均为 fail-safe 方向,文档化):① plugin 管道若上游调用点拿不到消息数则阀/边界消费退化为保守拒绝(本 PR 已把 msgCount 从 server 各调用点透传,常规路径可用);② 进程重启后内存态清空,首份样本按非 usage provenance 放行(有界);③ JSON 通道 loop 内折叠不打 postFold 戳(该组合罕见,sticky-high 自愈)。
与在途 PR 的关系
Pre-flight