Repository navigation
fix: resume/branch no longer loses compression — blocks inherit with resumeInheritance + 500ms affinity window (#1834) - #1850
Merged
ranxianglei merged 4 commits intoOct 1, 2026
Conversation
… default (#1834) A client that resumes under a NEW session id while replaying the full transcript (Claude Code --resume, a new branch) inherited the parent's refs and lineage but NOT its compression blocks (forkAdoption default off) — every folded original came back on the wire and the upstream request ballooned (+25% in the live repro on #1834): compression was silently lost on every branch/resume. Blocks now ride along with resumeInheritance itself (default ON); forkAdoption only gates anonymous forks (#629). resumeInheritance:false still opts out of everything. Salt the preflight-multi-range histories per test: their deterministic same-generator content made the 48-message budget test a byte-exact prefix-extension of the regress test's session, so with adoption on it legitimately resume-inherited that session's blocks and tripped the 'no blocks created' assertion.
…ay (#1834) The old flat 5s trailing debounce RESET on every chain mutation, so a busy proxy never wrote prefix-affinity.json until 5s of silence — a SIGKILL under load lost EVERY chain since the last flush and the resumed conversation inherited nothing (#1834 live repro: file ABSENT after the kill, zero inheritance). The write now lands ~500ms after the last mutation, and a 5s max-delay budget guarantees it still lands under sustained traffic.
Contributor
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.1835-pr.1850.db9d4adThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr1850.tgz
npm install -g packageInstall instructions are refreshed on each push. |
The setInterval churn could not keep the event loop alive on every node version (unref'd timers), so on the Node 22 CI lane the test's promise never settled: 'Promise resolution is still pending but the event loop has already resolved' — and the runner cancelled every remaining test in the file. Re-arm the debounce from an awaited loop instead; drop the redundant <6s wall-clock assert (sawFile under churn already proves the budget fired).
Owner
Author
[bot] 🏷 ## PR #1850 复核(独立重验当前 diff)—判定:可合 按你的分工(实现你完成、我负责审),本轮对当前 head df3976c 独立重读了实际 diff,不只沿用上一轮结论。完整七问分析见 #1834 楼 12(同一 head,未再推);这里给自足结论。 本轮独立验证到的关键点
七问速览(逐条详见 #1834 楼 12)
状态(本轮核对)
两个非阻塞小瑕(不影响合并)
分工说明:实现由你完成,我这边只做 review,未改任何代码。合并留给你(系统规则禁止我 merge)。判定:可合。 |
Owner
Author
darkness-A
pushed a commit
to darkness-A/billion-context
that referenced
this pull request
Oct 1, 2026
…oogle wires
fork-adoption's id pass (incomingCoreMessages) only supported
{openai, anthropic}: responses (codex /v1/responses) and google
(gemini native) returned null, so identified resume-forks on those
wires inherited nothing but lineage — every folded original came
back on the wire and had to re-fold (ranxianglei#1834's residual population).
Extend SUPPORTED to all four wires. The new branches mirror each
wire's prepare* pre-projection mutations IN ORDER before converting
with the same converters prepare uses:
- responses: replaceBiliCompactionItems → normalizeResponsesMessageItems
→ sanitizeResponsesInputIds → dropWhitespaceResponsesMessages →
stripAcpPanelResponsesInput → stripAcpStatusMarkers →
stripEmbeddedChainCarriers → responsesToCoreWithToolImages
- google: stripEmbeddedChainCarriers → googleToCore
Id parity with processTurn's input is the whole point: an id this
pass misses drops a parent ref from the inheritance; an id it
invents matches nothing (harmless superset). The plugin-mode
mid-history sys/developer in-place marking (__bili_inplace_sysdev)
is deliberately not replicated — marked or hoisted, those items
contribute no core message either way.
Chain tracking, findResumeParent and the ranxianglei#1850 default block
adoption were already protocol-agnostic; this was the only gap.
tests/resume-adoption-wires.test.ts: responses resume through the
responses⇄chat bridge and a direct gemini-native scenario, both
asserting the full ranxianglei#1486 contract (refs preserved incl outside the
folded block, blocks adopted, lineage, parent untouched, fresh refs
above the parent's space) + the disabled-gate variant. Both
inheritance tests fail on the old SUPPORTED set (teeth verified).
antclt
pushed a commit
to antclt/billion-context
that referenced
this pull request
Oct 6, 2026
…anglei#2188) Claude Code stamps a cache_control breakpoint on its last message + last assistant message and moves them as the conversation grows. The prefix-affinity identity chain hashed those bytes via stableStringify, so a --resume/--fork replay of an earlier history diverged from the parent's stored chain exactly at the breakpoint position and findResumeParent returned null deterministically — every Claude Code resume/fork lost all compression inheritance (ranxianglei#1486/ranxianglei#1834/ranxianglei#1850). Add canonicalForHash: sorted-key JSON with every cache_control field dropped, used by both chainHashes and perItemHashes. The identity chain is now invariant to breakpoint placement while still requiring actual content to match byte-for-byte. Behavior change (one-time): pre-upgrade chains persisted in prefix-affinity.json were hashed WITH cache_control, so they no longer match new-format incoming hashes and fork fresh once; each session converges after its next live request re-notes its chain (self-healing, no persistence-format change).
ranxianglei
deleted the
2026-10-01_issue1834-resume-blocks-affinity-window
branch
October 15, 2026 05:32
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 #1834. ework 选项 B + C(issue 评论里的复现数据即本 PR 的依据)。
B — 已识别 resume-fork 默认继承压缩块(src/server.ts)
maybeAdoptResume的blocksEnabled原来绑定在默认关闭的forkAdoption上:换新 id 的 resume(claude--resume、开分支)继承 refs+lineage 但不继承 blocks → 被折叠原文全部回到线上,复现实测上游请求 +25%(89,759B 折叠 → 112,220B 膨胀),每次分支必丢。现在 blocks 随resumeInheritance(默认开)一并继承;forkAdoption回归只管匿名 fork(#629);resumeInheritance: false仍然全部关闭。复现驱动验证(真 CLI + mock 上游,issue 评论场景):
inherited 23 ref(s) … 1 blockC — prefix-affinity 落盘窗口 5s → 500ms 静默 + 5s 强制上限(src/affinity-persist.ts)
旧防抖是尾随型且每次链变更重置:持续流量下文件永远不写,SIGKILL 丢的是"自上次落盘以来的全部链"(复现实测:杀进程后 prefix-affinity.json ABSENT、继承全灭)。现在最后变更后 ≤500ms 落盘;持续变更下 5s 预算强制落盘一次 —— 丢失窗口从「5s 尾随且负载下无界」收窄为「最后变更后 ≤500ms / 持续流量下 ≤5s」。
测试
tests/resume-ref-inheritance.test.ts新增:默认配置(forkAdoption off / resumeInheritance on)的 resume 必须收养 blocks(/bili/url/重启agent、重启bili、开新会话分支啥的都有概率丢失压缩 #1834 的回归红线)。tests/affinity-persist.test.ts新增 ×2:静默窗口 ~500ms 内落盘;每 100ms 持续 re-arm 不再饿死写入(两条在旧代码上都红)。tests/preflight-multi-range.test.ts:三个测试共用同生成器内容,48 条历史字节级前缀扩展了 24 条那个会话 —— B 生效后合法触发 resume 继承、收养了对方的 blocks,撞上no blocks created断言。按测试加盐隔离(预检预算语义未动)。cc @ework —— 这个我直接改了(issue 评论已说明),你不用接手。
残留(v1 已文档化的边界,非本 PR 引入)
maybeAdoptResume的SUPPORTED = {openai, anthropic}(src/fork-adoption.ts:71)—— responses 线(真 codex)换 id resume 仍只记 lineage,不继承 refs/blocks(其转换管线不同,v1 跳过并打 log-skip;缺失收养只是性能损失,无正确性风险)。已列入 #1834 后续跟进项。