Repository navigation
fix: detect silent fold loss when resent history ids drift from compressed blocks (#1195) - #1247
Conversation
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-1247Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr1247.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 Review of #1247 (log-only fold-drift diagnostics for #1195) — reviewed code against both the PR head ( ① Original issue / direction. #1195's incident analysis identified id-drift silent fold loss as the leading suspect mechanism: content-hash ids drift when a client resends mutated bytes, covered ids stop matching active blocks, those messages silently re-enter the wire unfolded while their savings were already booked into ② Regression inventory. Touched paths: the four main prepares in
③ Code. ④ Tests. ⑤ Diff. 3 files, +165/−2, single commit, every line on-purpose; no whitespace churn, no lockfile/generated noise. Clean. Pre-flight (run by me, not just CI):
The 3 failures are the Duplicate screening: no other open/closed issue or PR covers drift/fold-coverage detection. Two housekeeping notes, neither blocking:
中文摘要: 这是 #1195 的可观测性半边——在折叠覆盖检查处加了纯日志的 id 漂移检测(不动任何线协议/配置/持久化/阈值);我逐条核对了四个 prepare 路径的既有行为无回归、测试有牙且能钉住本功能、diff 干净,并亲自验证了 PR 头与 rebase 到当前 master 后的双份预检全绿(claude-native 3 个失败在裸 master 上同样复现,属 #1248 已立案的沙盒 flake),CI 8/8 通过——建议作者 rebase 到最新 master 后即可合并。 |
0d1d496 to
c1ea178
Compare
…essed blocks (#1195) Message ids are content hashes (deriveMessageId). When a client resends history whose bytes changed (resume/re-serialization, edit, duplicate-cluster shift), compressed-range ids no longer match the block's covered set and those messages silently re-enter the wire unfolded - while the compress result already booked their savings into lastInputTokens, blinding preflight/nudge decisions for subsequent turns. Add foldCoverage() in src/session.ts and a materialization check in all four main prepares (anthropic/openai/google/responses): when the previous turn ended with a pending fold (stats.pendingFoldUsage), snapshot the active blocks' covered ids before processTurn, then compare against the resent message ids after state adoption. A mismatch logs one warn line: [acp-drift] fold coverage mismatch: matched/expected ... Log-only: no behavior change, no wire change. Guards: side requests skipped (msgs < REWRITE_MIN_INCOMING_TOTAL), title generation (!isTitleGen), compaction triggers (!isCompactionTrigger).
c1ea178 to
6bb6056
Compare
|
#1417 批次深审 + rebase/修复合并交付 判定:✅ 可合(修后,已修)干什么/动机:输入侧 fold-drift 归因—— 定位澄清(重要):#1195 已被 #1328(响应侧 rescue+refold)修复关闭;本 PR 是 #1328 的观测补充(400 发生前归因/反复 rescue 的根因可见),PR body 已加注记重构叙事。与 #1351(传输层失败分类)不同层零重叠。 四轴:纯观测——零 wire 改动、零注入、零节奏影响、无配置。压缩行为/cache/推荐列表/质量全部零触碰。 rebase + 修复(新 head
|
[bot] 🏷 Round-2 verification at rebased head I did not take the pre-flight claims on faith; ran them myself at the new head (worktree detached at
Wording fix verified in code (all four prepares, Union conflict resolution verified: snapshot still immediately before Your non-blocking note stands as-is: the #1328-rescue double-warn is pure log noise on an already-diagnostic path; not worth a pre-merge change. Regression posture unchanged from round 1: pure observation — zero wire/config/persistence/threshold/timing impact, both compression modes unaffected. Nothing new introduced by the rebase or the wording commit. Verdict: 可合. CI green, local pre-flight green, diff clean, my round-1 observation fixed. Merge is human-only per system rules — whenever you're ready: #1247 中文摘要: 我在 rebase 后的新 head |
Context
From #1195: after a successful pi compression (2 blocks, ~51K tokens saved), the very next request fails with
Prompt is too long.While tracing that report I found a silent failure path worth instrumenting regardless of which mechanism fired in that specific incident (see #1148/#1102 for the fork-class cousins already fixed in v0.1.148):
Message ids are content hashes (
deriveMessageId). When a client resends history whose bytes changed (resume/re-serialization, edit, duplicate-cluster shift), compressed-range ids no longer match the block's covered set, and those messages silently re-enter the wire unfolded — while the compress result already booked their savings intolastInputTokens, blinding preflight/nudge decisions for subsequent turns. Today this path produces zero log output.What this PR does (log-only diagnostics)
src/session.ts: newfoldCoverage(coveredBefore, liveRawIds)— returns{expected, matched}when some covered ids are missing from the resent history,nullon full coverage.src/server.ts: all four main prepares (anthropic/openai/google/responses) now snapshot the active blocks' covered ids beforeprocessTurnwhen the previous turn ended with a pending fold (stats.pendingFoldUsage === true), then compare against the resent message ids after state adoption. A mismatch logs one line:[acp-drift] fold coverage mismatch: matched/expected covered message id(s) present in resent history — N message(s) from the just-compressed range did not fold out of the wire ...msgs.length >= REWRITE_MIN_INCOMING_TOTAL,!isTitleGen,!isCompactionTrigger).tests/fold-drift.test.ts: 4 regression tests (pure helper semantics + a server-mirroring materialization check: stable resend silent, drifted resend fires).Behavior change disclosure
None. No wire change, no config change, no persistence change, no threshold/default/timing change. The only observable difference is a new
warnlog line in sessions where a completed compress fold demonstrably did not materialize. Both compression modes unaffected (the check is mode-agnostic; plugin-mode warnings already flow through the same logger).Verification (rebased head c1ea178 on master 570a2ea / v0.1.148)
npm run typecheck✅npm run build✅node --import tsx --test tests/fold-drift.test.ts→ 4/4 ✅npm test→ 2547/2557 pass, 0 fail, 10 skipped ✅ (green on the rebased head)Scope note
This is the observability half of #1195. It makes the drift mechanism self-diagnosing in production logs. If the reporter's evidence (upstream error body token counts + bili.log around the failure) confirms this mechanism as the actual cause, the targeted mitigation will land on this branch before merge; if a different mechanism is confirmed, this PR still ships as a pure win (it closes a real silent blind spot).