Repository navigation
fix: require min incoming size + history overlap for unannounced-rewrite detection (#1075) - #1076
Merged
Merged
Conversation
Owner
Author
Contributor
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-1076Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr1076.tgz
npm install -g packageInstall instructions are refreshed on each push. |
Owner
Author
[bot] 🏷 PR #1076 核对完成(分支 Diff 审查
本地验证(在 rebase 后的 head 上实际运行)
CI / 冲突
流程备注:此变更影响 compaction boundary 标记时机(进而影响 ref-map prune),按 §7.4 gate 属于人审合并范畴——我不代合并。CI 绿后请 owner 自行 merge。 一句话中文摘要:在 unannounced-rewrite 检测器上加了"入站 ≥10 条且与旧史至少重叠 1 条"两道保守门,消除 Claude Code 侧边辅助请求(WebSearch/标题生成)被误判为整史重写导致的 ref map 洗空与编号雪崩;已实测回退修复时新测试精确复现事故、修复后全量 2160 通过,代码可合并。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1075
Problem
Since #1001,
detectUnannouncedHistoryRewrite(src/session.ts) had no minimum incoming-size gate (onlyincomingTotal > 0). Clients like Claude Code mechanically stamp ALL HTTP requests from a terminal with the globalx-claude-code-session-id, so standalone auxiliary requests carrying a single brand-new message (WebSearch query refinement, title generation) —incomingTotal=1,knownIncoming=0, ratio 0 < 0.5 — tripped the "client silently rewrote its whole history" detector.Each hit then ran
markCompactionBoundary+applyCompactionArchive, wipingbyRaw/byRefdown to the single live id. On the next full-history replay (6,301 messages), every message looked brand-new and took a fresh ref from the cursor → +N refs per side-request. In search-heavy long sessions the 5-digit pool (m00001–m99999) exhausts within hours →ref capacity exhausted→prepareAnthropicfails open and forwards the uncompressed 11.9 MiB / 3.63M-token history → upstream400 prompt too long→529 overloaded_errorretry loop.Fix (
src/session.ts, detection only)Two conservative gates added to
detectUnannouncedHistoryRewrite:REWRITE_MIN_INCOMING_TOTAL = 10(issue proposal): a genuine rewrite of a mature conversation never arrives as a near-empty payload.knownIncoming > 0: a genuine rewrite always shares at least one message id with the prior history (clients keep a tail through compaction); a side request shares none.Rationale for conservativism: the failure modes are asymmetric. Missing a genuine rewrite leaves stale map entries until session end (cheap, self-heals). A false positive wipes the whole ref map (fatal — this incident).
Call sites (
src/server.ts, anthropic + openai wires) are unchanged; fixing the detector covers both wires. Issue option 2 (changingapplyCompactionArchivepruning) was NOT adopted: once false positives are gone the inflation path disappears entirely, and changing prune semantics touches load-bearing persistence/ref-map behavior with no remaining benefit.Evidence
New
tests/fix-1075-side-request.test.ts:Verified pre-fix: stashing the fix makes 4 of the new tests fail exactly as the incident describes; post-fix all green.