Skip to content

[PR] fix(#5925): fail the #4805 membership gate closed on absent evidence - #5926

Open
ranxianglei wants to merge 2 commits into
masterfrom
2026-11-08_membership-fail-closed
Open

ranxianglei wants to merge 2 commits into
masterfrom
2026-11-08_membership-fail-closed

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #5925

What this fixes

Two residual holes in the #4805 anchor-pollution defense (reported against v0.1.213, still present on master):

  1. The settle gate failed open on absent evidence. probeRequestMembership deletes the verdict when a request carries no message ids at all, and isForeignMembership(undefined) evaluates to "member" — so a side-lane sample under a shared session id settled over the main conversation's anchor. Right after a fold (credit window open) it nets to max(0, tiny − credit) = 0, growth drops below the nudge floor (default 22500), and compression stops until window overflow — and failed requests return no usage, so the anchor cannot heal itself.
  2. The outbound estimate channel was ungated. The same foreign request also rewrote localInputEstimate (noteOutboundContextEstimates runs at the relay send chokepoint for every outbound, no membership check) — even with the anchor write guarded, effectiveTokenCount's fallback min(localInputEstimate, raw) stays pinned at foreign scale.

Fix

One three-state admission predicate (membershipBlocksSettlement) applied at BOTH scale-state writers:

  • proven member → admit; proven foreign → refuse; absent verdict → admit ONLY while no needle is planted (bootstrap unchanged).
  • settleUsageReport: the gate uses the predicate; the refusal log distinguishes proven-foreign from absent-evidence and names the needle.
  • noteOutboundContextEstimates: early-returns under the same predicate.
  • resetSessionCompression clears the needle + payload scale: the rebuilt conversation starts a fresh host id generation, so a dead pre-rebase needle would stall bootstrap forever under the fail-closed gate.

Behavior change (intended, disclosed)

old new
no-id usage sample while the family is known (needle planted) anchor write admitted refused (still bills cumulatively); heals via the next id-carrying report
no-id sample before any family is known (bootstrap) writes writes (unchanged)
outbound estimate for a non-member / absent-evidence request while family known written skipped
post-rebase bootstrap — needle cleared; first id-carrying report replants the family

Cumulative billing (inputTokens / USD ledger) is unaffected in every case — refusals only protect this conversation's anchor family.

Why slot 1 of the reporter's patch is not taken

Adding !anchorImpossible to the compress-credit early return would regress #5135: in that incident shape the session's own honest post-fold credited anchor (180K) faced a resent upper of ~38.7M chars (client resends covered originals, ≈64× tower), so anchorImpossible legitimately fires there, and gating the credit branch manufactures a false OVER-LIMIT demotion right after a successful fold. tests/issue5135-post-fold-credit.test.ts pins that shape. With hole 2 closed at the writers, polluted anchors can no longer reach the meter through the main path. The baseline readers (statusInputBaseline/usageGradeInputBaseline) are safe by construction: they take no message list, cannot compute the guard, and are protected at their single writer side.

Tests

  • New tests/issue5925-membership-fail-closed.test.ts (7 cases): core refusal + cumulative billing, post-fold impact chain (credited anchor survives), bootstrap preserved, estimate-channel gate with control, heal, rebase needle clear, predicate truth table.
  • tests/issue4805-anchor-pollution.test.ts T3e deliberately updated: it pinned the old fail-open settle; it now asserts refusal + heal, still parametrized over previous member/foreign verdicts.
  • Local: typecheck clean, build clean, unused-export gate clean, targeted suites green (issue5925/issue4805/issue4383/issue5134/issue5135/issue1933/issue2117/issue1820 — 56 tests).

No config surface change. No kernel change.

The settle-side anchor-pollution defense (#4805) failed open when a request carried no message ids at all: probeRequestMembership deletes the verdict on empty id lists and isForeignMembership(undefined) read as 'member', so a side-lane sample under a shared session id settled over the main conversation's anchor. Right after a fold (credit window open) it nets to max(0, tiny - credit) = 0, growth drops below the nudge floor, and compression stops until window overflow — failed requests return no usage, so the anchor cannot heal itself.

- ONE three-state admission predicate (membershipBlocksSettlement): proven member admits, proven foreign refuses, absent verdict admits only while no needle is planted (bootstrap unchanged). Applied at BOTH scale-state writers: settleUsageReport's anchor family AND noteOutboundContextEstimates — the same foreign request also rewrote localInputEstimate, pinning effectiveTokenCount's min(localInputEstimate, raw) fallback at foreign scale even with the anchor guarded.
- resetSessionCompression clears the needle: the rebuilt conversation starts a fresh host id generation; a dead pre-rebase needle would stall bootstrap forever under the fail-closed gate.
- The compress-credit meter branch is deliberately NOT gated with anchorImpossible: #5135 proved the guard fires on the session's own honest credited anchor when the client resends covered originals.

Behavior change: a no-id usage sample after the conversation's id family is known now skips the anchor write (previously admitted) — it still bills cumulatively, and the anchor heals through the next id-carrying report. The outbound estimate channel applies the same rule. Bootstrap (no family known) is unchanged in both.
@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-08_membership-fail-closed (e729c47)

Latest build — install this exact version

npm install -g billion-context@0.0.8596-pr.5926.3b9d10f

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Recent builds (commit → version)

commit version build
e729c47 billion-context@0.0.8596-pr.5926.3b9d10f build
c5f1ad7 billion-context@0.0.8594-pr.5926.be23528 build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr5926.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix(#5925): fail the #4805 membership gate closed on absent evidence [PR] fix(#5925): fail the #4805 membership gate closed on absent evidence Nov 8, 2026
CI caught a second pin of the pre-fix behavior that the local targeted
run missed: tests/request-membership-http.test.ts asserted end-to-end
over HTTP that a no-ID sample settles after either foreign or member
evidence (the old abstain-and-admit semantics). Flip it deliberately:
the verdict still clears on a no-ID request (abstention unchanged), but
while the id family is known the sample is refused and the anchor heals
through the next id-carrying report. One extra heal turn per variant;
forwarded count 10 -> 12.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

查重: 不重复。 This is the single fix PR for #5925 (two residual holes in the #4805 anchor-pollution defense); family map checked live — #4805 (closed, original fix #4849), #4425 (write-side aux-settle clearing, different mechanism, still open), #5135/#5136 (closed, the regression this PR correctly avoids), #4859 (closed decision request) — none overlaps this diff's scope. One open [PR] row targets this thread, satisfying one-fix-PR-per-thread.

标签: bug / p1 / scope/wiring(会话不可恢复类——压缩停摆到窗口溢出;p1 按 owner 修订不可降档。wiring:修复在服务端 scale-state 写者,车道无关)。

Reviewed at head e729c473 (2 commits; base = current master, no rebase needed; 6 files, +226/−13). Commit 2 (test(#5925): re-pin the HTTP membership suite) landed while I was reviewing and fixes exactly what CI caught on the first head. Verified against the code, not just the PR description:

  1. Both holes exist as described. probeRequestMembership (src/request-membership.ts:73) deletes the verdict when ids.length === 0, and the old gate isForeignMembership(undefined) read as "member" — a no-id side sample settled over the known family's anchor. noteOutboundContextEstimates (src/cache-ledger.ts:1838) ran at the relay send chokepoint with zero membership checks. Failure chain confirmed end-to-end: fold → credit window open → max(0, tiny − credit) = 0 → growth below the 22500 nudge floor → nudge dark until window overflow, and failed requests return no usage so the anchor cannot heal itself.
  2. One predicate at both writers, correct truth table. membershipBlocksSettlement: proven member → admit; proven foreign → refuse; absent verdict → admit ONLY while no needle is planted. T7 pins all six rows including "an explicit member verdict outranks the needle rule." Billing stays outside the gate — inputTokens/USD accrue on refused samples too (pinned in T1 and re-pinned T3e). The estimate-channel early-return is symmetric with the anchor gate, so a refused request cannot poison either scale reading.
  3. Slot-1 rejection is correct. The compress-credit meter branch (src/server.ts:2932) deliberately lacks !anchorImpossible, and the in-tree [Bug] 0.1.209: Claude Code CLI main conversation forks onto <id>|sub:<fp>; the session-title call claims the raw key (regression from #4774) #5135 comment says exactly why: post-fold, the client resends covered originals (~64× tower over the credited anchor), so anchorImpossible legitimately fires on the session's own honest anchor — gating the credit branch manufactures a false OVER-LIMIT demotion right after a successful fold. With both writers closed, polluted anchors cannot reach the meter through the main path, so no reader-side guard is needed. Baseline readers verified safe by construction: statusInputBaseline (src/session.ts:922) and usageGradeInputBaseline (src/server.ts:2987) take no message list, compute no guard, and are protected at their single writer side.
  4. Rebase needle clear is necessary and sufficient. resetSessionCompression runs only via reconcileNativeCompactionBoundary (codex/Responses rebase), which already zeroes every other scale state; without the needle clear, a dead pre-rebase needle would fail-close every post-rebase sample forever (the host mints fresh ids that never match it). T6 pins exactly that regression.
  5. Tests have teeth. Every new case asserts state that differs pre/post fix (T1 fails pre-fix with lastInputTokens=5100; T2 with 0; T4 with localInputEstimate=2600; T6 with 0). T3e and the HTTP-suite re-pin replaced stale assertions encoding the old fail-open settle — required, not scope creep; their surrounding assertions (subsequent foreign still refused, heal via next id-carrying report) are preserved. I scanned every other test file calling settleUsageReport: none plants a needle except these three suites, so no other stale pin exists — consistent with CI showing exactly one failing file spread across three matrix legs.
  6. Residuals, stated honestly: (a) bootstrap window unchanged — a no-id sample before any family is known still writes (disclosed; inherent to the evidence model; self-heals on the next id-carrying report); (b) fork children inherit the parent's needle (src/plugin.ts:1708) — if such a child's lane never stamped ids, its samples stay refused until it reaches mainScale of the inherited payload upper; the meter degrades to the fork-time seeded estimate rather than corrupting, strictly better than the pre-fix poisoning risk, and same-host forks stamp ids and join immediately (T3d pins); (c) concurrent interleaving can briefly attribute a stale verdict across two in-flight requests on one session — pre-existing exposure of the shared-transient design, self-heals on the next report.

Local at e729c473: typecheck clean, build clean, targeted family green — request-membership-http, side-lane-invariants, issue5925, issue4805, issue5135, issue5134, issue4383 (both files), issue1933, issue2117, issue1820 — 78/78. CI: on c5f1ad7d three red shards = the one stale HTTP suite on three legs; on e729c473 the run showed 28 success / 10 in progress / 0 failures at time of writing (the mirror check-cache had not picked up the new push yet, so I verified via direct API; expect the remaining shards to close out shortly).


结构化八问

  1. 是什么问题:Bypass requests overwrite the main session's usage anchor, causing long sessions to permanently stop compressing. | 旁路请求覆盖主会话 usage 锚点,导致长会话永久停止压缩 #4805 锚点污染防御的两个残留洞——成员资格门对无 msgid 请求 fail-open(无证据被当成"已证明是成员",侧车道样本覆写主对话的 usage 锚点,折叠后锚点净值归零、nudge 永不再触发、压缩停摆直到上下文爆窗);出站估计通道完全没有成员检查,外部规模的估计把仪表的 fallback 值钉死在外国尺度上。
  2. 什么原因导致的:成员证据模型是二元的——"判决存在与否"——把"证据缺席"与"证明是成员"混为一谈;且守卫面只覆盖了锚点写者,漏掉第二个 scale-state 写者(出站估计),即使补上前者,污染仍能经 min(localInputEstimate, raw) 到达 effectiveTokenCount。
  3. 影响范围与严重程度:p1。受影响面:宿主在共享 session id 下盖 msgid 且有活跃侧车道的会话(dsh 类辅助 persona);触发条件 = 刚折叠(credit 窗口开)+ 一个无 id 侧样本落定 → 压缩永久停摆至窗口溢出,失败请求不返回 usage、锚点无法自愈。静默失效,用户可见症状是"压缩不工作了"。
  4. 怎么修复的:一个三态准入谓词(证明成员→放行 / 证明外国→拒绝 / 证据缺席→仅当针未植入时放行)统一施加在两个 scale-state 写者上(settleUsageReport 锚点块 + noteOutboundContextEstimates);计费(token/USD)留在门外交付照常累计;resetSessionCompression 在 rebase 清针(host 重新铸 id,死针会把 fail-closed 永久化);刻意不给 compress-credit 仪表分支加 !anchorImpossible——那会回归 [Bug] 0.1.209: Claude Code CLI main conversation forks onto <id>|sub:<fp>; the session-title call claims the raw key (regression from #4774) #5135 钉住的形状(成功折叠后客户端重发覆盖原文 ≈64× 塔,守卫合法触发,门控会制造假 OVER-LIMIT 降级)。
  5. 是否有回归问题:逐项审过既有行为——bootstrap 无针写入不变(T3);累计计费不变(拒绝样本仍累加 inputTokens,T1/T3e);校准对 roll-forward 在拒绝样本上仍执行(只跳过入环,与估计通道门控一致);fork 子代带 id 请求语义不变(T3d);[Bug] 0.1.209: Claude Code CLI main conversation forks onto <id>|sub:<fp>; the session-title call claims the raw key (regression from #4774) #5135 折叠后 credit 形状保持(该套件绿);emergency shrink / preflight 的本地估算用错了视图:超长会话(客户端历史 127 万,压缩后 outbound 仅 ~16 万)在上游失败无 usage report 时,bili 按原始历史估算 #1492 B"usage-grade 总是自我修复"契约保持(side-lane-invariants (K)/(K2) 绿,无针路径);T3e 与 HTTP 套件重钉属有意行为变更更新且 PR 正文已披露。未发现无意回归;残留(bootstrap 窗口、跨车道 fork 子代冻结角、并发瞬态竞态)见正文第 6 条,均优雅降级并自愈。
  6. 是否破坏缓存:不涉及。未触碰任何缓存/重试/增量游标/去重键;无线协议变化(prefix-cache 字节零影响);拒绝只影响本会话的 scale-state 写入。
  7. 是否改了设计方向:不改。既有 Bypass requests overwrite the main session's usage anchor, causing long sessions to permanently stop compressing. | 旁路请求覆盖主会话 usage 锚点,导致长会话永久停止压缩 #4805/[PR] fix(#4805): side-lane usage samples can no longer pollute the session anchor (settle gate + meter size guard) #4849 守卫面从二元扩为三态,同写者、同谓词家族,无架构转向。
  8. 是否引入了新的配置:不涉及。

判定:建议合并 —— 待 e729c473 上最后 10 个 CI job 收尾(截至写作时零失败)。

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

effectiveTokenCount: compress-credit early return bypasses the anchorImpossible guard, and the membership guard fails open on empty id lists

1 participant