Repository navigation
fix: guard rememberedPluginMessages against side-shaped snapshot eviction (#1307) - #1312
Conversation
…tion (#1307) Auxiliary requests (DSH auto-review etc.) ride the main session key with a NORMAL output budget — the layer stack fills one in — so the #388 <=200 side-request heuristic never fires and they walk the full pipeline with a 1-2 message synthetic view. The post-forward rememberPluginMessages() then evicted the main turn's remembered snapshot with that view, and the plugin tool API (compress) anchored ranges from a 1-message window: every long- session ref turned dangling ("Requested range(s) cannot be anchored"); production log in the issue: 163/163 compress failures with ctx==1, 62/62 successes with ctx>1, 0 crossovers. Fix: shape-guard the WRITE POINT — an incoming view of <=2 messages never evicts a richer remembered snapshot (shrink direction only; fresh sessions and same-size refreshes still write). Verified end-to-end: main turn -> review-shaped request (no tools, normal budget, system+user pair) -> plugin-path compress still anchors. Fix B from the issue (pipeline-entry non-snapshot classification via zero ref overlap) was implemented and deliberately dropped: the shape is ambiguous on the wire. Wire-mode thin clients legitimately send stateless 1-2 message no-tools turns (compress injection, #1075's one-ref contract) and the plugin lane's per-request window resolution (anthropic-beta) rides the same shape — classifying those breaks 14 existing e2e contracts. The residual side effects (nudge baseline rewrite, orphan-GC streaks after 3+ consecutive auxiliary requests) are bounded and self-heal on the next main turn; tracked in the issue thread.
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-1312Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr1312.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 ## PR Review — #1312 (fix: guard Reviewed head ① Original issue (direction gate) — pass#1307's root-cause analysis is sound and I independently re-verified the code path on master: ② Regression review — existing behaviors on touched paths, itemizedThe only write site is
No unintended regressions found. ③ Code reviewGuard logic is correct and minimal; the
④ Test validity — real teeth, independently re-verified
⑤ Diff cleanlinessClean. Every line serves the fix; no unrelated files, no whitespace churn, Behavior-change disclosure (Deliverables #4) — confirmed presentOld: any prepared view overwrote Duplicate screeningDirect fix for #1307 (whose §4 documents the #388/#398-family dedup). Earlier attempt PR #1308 is closed-unmerged (superseded by this one). Follow-up #1309 (Fix B vs #1075 policy conflict) open for owner decision. No duplicates. 结论(中文一句话): 修复了辅助请求(auto-review 等「≤2 条消息 + 正常输出预算」形状)冲掉 plugin 会话 |
[bot] 🏷 Addendum (base moved during review): master advanced by one merge since the PR was opened — #1311 ( |
The ≤2-message threshold is the same class of proxy the issue convicted in the ≤200 budget: a 3+ message auxiliary prompt (few-shot review shapes) walks straight through it. The causal signal is identity — a main turn RESENDS the conversation, so it always carries messages the previous snapshot already holds (content-hash ids are stable); an auxiliary prompt shares nothing with it by construction. Guard becomes: zero overlap AND smaller than the snapshot → refuse to evict. - 3-message zero-overlap auxiliary shapes are now refused (count missed them) - a smaller view that OVERLAPS is a genuine continuation (client trimmed history) and MUST write — count-only would wrongly freeze the snapshot - larger zero-overlap views (real restart on the same session id) still write - fresh sessions, same-size refreshes unchanged
|
Guard upgraded from the message-count threshold to identity overlap (follow-up to review feedback — count was the same class of proxy the issue convicted in the ≤200 budget): if (previous && previousView.length > incoming.length) {
const knownIds = new Set(previousView.map((m) => m.id));
if (!incoming.some((m) => knownIds.has(m.id))) return; // keep the snapshot
}Rationale: a main turn resends the conversation, so it always carries messages the previous snapshot already holds (content-hash ids are stable); an auxiliary prompt shares nothing with it by construction — regardless of its message count or budget. Litmus: a 3+ message few-shot review shape walks through the ≤2 guard but is still refused here; a client that genuinely trims history resends a smaller overlapping view and must (and does) still write.
Pre-flight re-run: typecheck ✅, new tests ✅ (red with the guard removed), 281-file sweep vs pristine master → failure set identical (4 sandbox-environmental, all reproduce on master). CI re-running. |
[bot] 🏷 Round-2 review — identity-overlap guard ( ① Direction. Strictly better than the count threshold: message count was indeed the same class of proxy the issue convicted in the ≤200 budget; ID overlap is causal — a main turn resends the conversation (stable ids), an auxiliary prompt shares nothing by construction regardless of count or budget. This is exactly the conservative variant issue §5 proposed (「把条数换成与已知 ref 的重叠度」), so the fix now holds under the litmus for any future auxiliary shape. Id-stability premise verified in kernel source: Behavior delta (old→new disclosure):
Verification matrix (all run locally by me):
Edge cases walked: fresh session writes ✓; larger view writes (grow direction) ✓; empty incoming refused ( Regression inventory delta vs round 1: only the two behavior items above; all other behaviors from the round-1 inventory are unchanged. Diff vs Small fix pushed directly on the branch (labeled commit, new head 📌 中文摘要:把 #1307 快照守卫从「≤2 条消息」阈值升级为「与既有快照零 id 重叠才拒绝」——用因果判据替代代理指标,堵住 3+ 条辅助请求的残余驱逐、同时解除对真实修剪历史的误冻结;已在 master / 旧守卫 / 新头三个基线上独立复验(红 / 红 / 绿),可以合并(合并仍由人工执行)。 |
[bot] 🏷 重复投递确认:本条(identity-overlap 守卫升级)的完整 review 已在上楼发出(round-2 review,含三基线红/红/绿验证矩阵与行为变更披露),分支上已直接补了标注注释修正提交,当前 PR head = |
|
Scope note (reviewer please read): this PR is a stopgap, not the root fix — tracked in #1314. It blocks exactly one fatal path (auxiliary requests evicting the remembered snapshot) and leaves open: pipeline side-effect isolation (orphan-GC streaks, nudge baseline), a general conversation-identity mechanism (known edges: same-session restart, byte-verbatim echo false-positive), and — likely the bigger cost — the review request's OWN compression economics (flattened ~1.2MB transcript, zero prefix-cache hits, no foldable ranges). #1314 discusses the root directions: prefix-chain identity ( |
…vs-remembered naming (#1431 review) - F1: extractWireTexts treated content:null/absent as unrecognized and abandoned the whole view — but content:null is the canonical agent shape for tool-calling assistant turns (our own e2e fixtures send it), so the anchor was never recorded and auxiliary routing stayed silently inert for exactly the sessions it targets. Null/absent now contributes empty text (mirrors the array branch skipping non-text parts; identity rides role + position). - F2: e2e the true discriminator boundary — a 2-message request carrying a recognized anchor message runs the full pipeline (overlap beats the ≤2 gate), not side-passthrough. - F4: one-line comment distinguishing the anchor view (side-request.ts, routing) from the remembered view (#1312 plugin.ts store, write guard).
Fixes #1307
Root cause
rememberPluginMessages()(src/plugin.ts) rewroteremembered[sessionId]unconditionally after every forward. An auxiliary request riding the main session key with a normal output budget (the host layer stack fills one in — DSH auto-review resolves tomax_tokens=384000) bypasses the #388≤200heuristic, walks the full pipeline with a 1-2 message synthetic view, and evicts the main turn's snapshot. The plugin tool API then anchors compress ranges from a 1-message window → every other ref dangles →Requested range(s) cannot be anchored. The issue's 4 MB production log: 163/163 plugin-path compress failures withctx==1, 62/62 successes withctx>1, zero crossovers — fully deterministic.Fix (Fix A from the issue, write-point guard)
An incoming view of ≤2 messages never evicts a richer remembered snapshot (shrink direction only):
Litmus ("would this hold if the same root cause surfaced in a different shape tomorrow?"): the invariant guarded is the tool API's anchor view must never be replaced by a strictly smaller one — any future auxiliary shape (WebSearch refinement, risk classifiers, new hosts) hitting this write point is caught regardless of its budget/tools/message mix.
Why Fix B (pipeline-entry
isNonSnapshotRequest) is NOT includedIt was implemented and tested on this branch, then deliberately dropped. The proposed signature (no tools + ≤2 messages + zero ref overlap) is ambiguous on the wire:
anthropic-betacontext-1m,anthropic-beta-window.test.ts) rides the same request shape.Scoping the predicate to plugin mode fixed the thin-client class but still broke the window-resolution contract; unscoped it broke 14 existing e2e contracts. Same wire shape, different intent, no reliable structural separator — details in the issue thread. The residual side effects of a pipeline-walking auxiliary request (one ref minted — #1075-bounded; nudge-baseline rewrite; orphan-GC streaks after 3+ consecutive auxiliary requests) are view-layer only, bounded, and self-heal on the next main turn; tracked for follow-up in the issue.
Tests (
tests/issue1307-side-snapshot.test.ts)max_tokens=384000, system+user pair) →POST /__bili/plugin/toolcompress succeeds (Compressed m00001–…, nocannot be anchored).Pre-flight
npm run typecheck✅npm run build✅; full suite deferred to CI as agreed.Merge stays human (wire-path change, AGENTS.md §7.4).