Repository navigation
[PR] fix: cold load after provider switch recovers the session fold ledger across routes (#3399) - #3765
Conversation
…ider switch (#3399) A provider switch mid-conversation leaves the fold ledger under its old route name (<protocol>/<oldHost>_<sha>.json); the cold load after restart probed only the requested route, so the session came back empty (requests=0, blocks=0) and the client re-sent the full unfolded history - refolded from scratch or rejected with a local 413 at the doomed-probe gate. - loadEnvelope resolves same-protocol namespaced files for a conversation id as ONE candidate pool when the request carries protocol meta: the computed exact-route name plus walked siblings sharing the id's sha suffix (.fb.json spills reconciled to their canonical copy by savedAt), each re-verified for body id and protocol (cross-protocol isolation), corrupt members quarantined per #3157. Winner by fold progress - requests, then nextBlockId (staleDiskPayload discipline), exact route on ties - never by probe order or savedAt, so a fresh-but-empty current-route twin loses to the richer old-route ledger and a successfully continued branch is never rolled back by a stale one. - A session restored from an off-route file adopts the requesting upstream origin (getSession fill-if-absent cannot override a stale-but-present one), so the next save converges under the live route instead of re-forking. Label/title are identity and stay put; no-meta callers keep byte-identical probe behavior. Tests: tests/issue3399-cross-route-load.test.ts (11 legs incl. both-twin arbitration, convergence, no-rollback, pure miss, corrupt fail-closed, tie-break, cross-protocol isolation, CCR sidecar, legacy lane). Closes #3399
(ai: vllm-qwen/qwen3.8-27b) 查重: 不重复。 检索了 open+closed 的 issue 和 PR(按失败机制匹配,不只标题):只有本 PR 触碰「冷启动跨路由恢复折叠账本」这个机制;#3399 是它的跟踪 issue(本 PR 进入完整 review。先报两个硬状态:
代码方向先给初步判断:根因定位准确—— |
5d139d1 to
7b825c8
Compare
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.4486-pr.3765.cb79e65This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr3765.tgz
npm install -g packageInstall instructions are refreshed on each push. |
(ai: vllm-qwen/qwen3.8-27b) 冲突已解决并推送。 PR #3765(head 分支 过程:master 自该 PR 分叉点( 验证:typecheck 全绿(kernel + pi-subagents 构建 + 结构化八问:
判定:冲突已清除,PR 恢复可合并状态(当前 |
(ai: vllm-qwen/qwen3.8-27b) PR #3765 review(#3399 跨路由冷加载折叠台账恢复)— 结论:代码可合;当前 CI 红与本次改动无关 先给判定:代码审查通过。根因修复、逻辑自洽、测试有牙、diff 收敛到两个文件(
CI 状态(诚实说明):head 判定:代码可合,无需返工。唯一挡路的是 red base(snapshot-render.test.ts D-on + #3044 zone),与 #3399 无关;base 转绿即可合入。待运行分片落地后我可再确认 #3399 用例结果。 |
|
感谢这个修复方向。补充一个独立的 OpenCode + 建议合并前额外覆盖 source-side CCR 采纳,而不只测试块数恢复:
本地新增并通过的合成腿:
这些是本地 0.1.199 局部回移的测试和源码顺序审阅,没有把它表述为整份本 PR 或最新 master 的端到端实测。最新主干 snapshot 方案尚未评估;也没有主动对真实目标会话发送模型请求,故“真实上游成功 / 413 已消失”仍未验证。无私有账本、对话、配置或真实 ID 上传。 |
…3765 review) readContentStoreRels probed the request's current-route sidecar before the winning ledger's own content-store. adoptRequestedRoute rewrites session.meta.upstreamOrigin to the requesting route during loadSync, so that current-route path targeted a degraded twin whose valid-but-incomplete CCR shadowed the richer recovered ledger's originals (missing refs -> DIGEST DRIFT) on the legacy lane. Probe the sourceFiles-derived CCR first so originals always follow the same file the fold ledger was loaded from; derive its canonical <base>.content-store.json name for .fb.json fallback sources (CCRs are never .fb-named). Adds two regression legs (shadowing; .fb.json->canonical) to tests/issue3399-cross-route-load.test.ts; both fail on the pre-fix code. Pre-merge coverage from the #3765 review.
(ai: vllm-qwen/qwen3.8-27b) @darkness-A 感谢这份源码顺序审阅。我独立在当前 rebase 后的 head( 已确认并修复(无决策依赖的部分)
新增两条回归腿到 需 owner 拍板(有决策依赖的部分,暂未实现) 你给的腿 3 / 第 4 点:胜出源根本没有 CCR、但另一路由有一份时怎么办。reorder 后的现状是 fall-through 到另一路由的 CCR = 静默混账(A 的 ref 配 B 的原件)。这是数据丢失语义的产品决策,不是机械 bug,我不擅自定:
倾向 A/C,请 owner 定夺后再补腿 3 与实现。 结构化八问
范围说明:单元级验证(定向测试);全量回归交 push 后 CI。与你一致的边界——我也未对真实上游会话发模型请求,「真实上游成功 / 413 消失」仍未实测;无私有账本/对话/配置/真实 ID 上传。 判定:核心遮蔽缺陷已在本 PR 内修复并加锁(腿 1/2);腿 3 的 fail-closed 语义作为决策项提请 owner 拍板。我不会自行合并。 |
|
这个要看看新存储是否解决了这个问题?看起来是遗漏问题 |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.624-master.48d45e7 # this exact build
npm install -g billion-context@master # always the newest merged build
|
Problem
A mid-conversation provider switch leaves the fold ledger under its OLD route filename (
<protocol>/<oldHost>_<sha24>.json). After a daemon restart (or LRU eviction), the cold load for the same native conversation id probes only the NEW route → empty session (requests=0, blocks=0) → the client re-sends the full unfolded history → refold from scratch, or a local 413 at the doomed-probe gate when the core text exceedsmax(2MB, limit*7.5). Production evidence in #3399: a 3697-request ledger orphaned under the old host while a degraded 2-request twin accumulated under the new one, then a 413 on the refold attempt.Root cause
SessionStore.loadEnvelope's candidate filters require an exact (id, protocol, upstreamOrigin) filename match whenever the request carries protocol meta — but the host prefix is display metadata derived from the request origin, not identity (#280/#286 contract: the conversation id IS the identity). The old-host file therefore never matches; bounded boot fillsdiskFilesbut never the kerneldiscoveredmap, so all four probe stages miss and the session comes back empty. In-memory keying is id-only, which is why LIVE switches work but cold loads do not. Full-mode users are protected by the R2 unified index (row keyed (agent, conv_id), #2960); the legacy/shadow file-walk modes (the default) were not.Fix (src/persist.ts only)
loadEnvelopefirst resolves every same-protocol file naming this id: the computed exact-route name (covers files created after boot) ∪ walked siblings sharing the id's sha suffix (.fb.jsonspills reconciled to their canonical copy by savedAt, kernel loadAll convention). Each candidate is re-verified for body id and protocol (cross-protocol isolation); corrupt members quarantine per [bug] 会话状态写入缺 fsync:内核崩溃后留下 size 正常但 VDL=0 的全零状态文件,loadSync 永久抛错 → 502 acp-proxy failure 且不自愈(含 7 处 tmp+rename 写路径盘点) #3157. Winner by fold progress: requests → nextBlockId (the staleDiskPayload clobber-guard discipline) → exact-route preference → savedAt. Never probe order or savedAt alone — a fresh-but-empty current-route twin loses to the richer old-route ledger, and a successfully continued branch is never rolled back by a stale one (arbitration per the revised plan A agreed in-thread).sourceFiles, so CCR sidecar resolution follows the restored source unchanged.No-meta callers keep byte-identical probe behavior: the pool only engages with protocol meta, and on pool miss the original four probe stages run unchanged.
Behavior changes (disclosed)
[persist] restored … from another upstream route (…),[persist] adopted route …No config surface added. No persistence format/version change. No
kernel/change. No wire/message-shape change.Tests
tests/issue3399-cross-route-load.test.ts— 11 legs: both-twin arbitration (richer-old wins; continued-branch wins), convergence (save lands under the requested route with full content), pure miss, same-route control, corrupt-sibling quarantine + degraded fallback ([bug] 会话状态写入缺 fsync:内核崩溃后留下 size 正常但 VDL=0 的全零状态文件,loadSync 永久抛错 → 502 acp-proxy failure 且不自愈(含 7 处 tmp+rename 写路径盘点) #3157), all-corrupt → honest null, counter tie → requested route, cross-protocol isolation, CCR sidecar follow, explicit legacy lane. 11/11 green.npm run typecheckclean,npm run buildOK. Full-suite verdict = CI on this head.Related: #2671 defect-1 (write-side filename coupling — separate facet of the same disease), #2960 (root-disease roadmap; R2 index already protects full mode).
Closes #3399