Repository navigation
Description
v0.1.197 Windows / Responses 补充证据:bounded cold load 按 host 查找,丢失同一 native conversation 的压缩连续性
补充到已有 #2960,关联 #2671 defect-1、#2847、#2803;关联 #2960。本地先做了一个保守热补丁,以下把生产证据、隔离复现和推断分开。
版本/运行条件
- npm
billion-context@0.1.197,对应3aeddc160864ca774e54817559d6984310e2a9ab。 - Windows npm daemon,Codex 原生稳定 conversation ID,
responses协议,切换 upstream host。 - 实际运行
storage.unified=shadow,bounded boot 只预热少量状态。legacy 模式隔离控制也复现;full/unified-first 命中路径不作同样故障断言。 - 当前 master
83197e913a9229b765bc0a144cb777ee49560430的loadEnvelope候选筛选仍相同。
1. 生产启动日志(真实摘录)
2026-10-16T10:02:26.661Z [info] [v=0.1.197] [storage] unified shadow mode ENABLED (storage.unified=shadow or BILI_STORAGE_UNIFIED): every session write is double-ingested into index.db and digest-reconciled [engine: node:sqlite/builtin]
2026-10-16T10:02:29.802Z [info] [v=0.1.197] [persist] indexed 248 state files; warmed 8 sessions within 67108864 decoded bytes; older states load on demand
2026-10-16T10:02:30.127Z [info] [v=0.1.197] acp-proxy v0.1.197 (pid 2772) listening on http://127.0.0.1:8787 [nonessential listener/banner fields omitted]
同一原生 ID 的两个有效 envelope(version 3;以下字段取自 payload,不是 envelope 顶层):
| 字段 | 旧 provider-A 快照 | 新 provider-B 快照 |
|---|---|---|
| createdAt (UTC) | 2026-10-11T23:49:04.580Z | 2026-10-16T06:36:11.780Z |
| savedAt (UTC) | 2026-10-16T02:36:48.637Z | 2026-10-16T08:28:22.420Z |
| 文件字节 | 31,148,251 | 23,744,791 |
| requests | 3,697 | 2 |
| 历史 blocks / active blocks | 274 / 25 | 91 / 91 |
| active summary UTF-8 字节 | 62,099 | 806,302 |
| compressionCount | 276 | 91 |
| lastInputTokens | 72,613 | 777,767 |
| lastInputTokensSource | usage | estimate |
两份快照有 50 个相同 message ID,但没有完全相同的 block summary。新文件的 91 个块全部 tier-1,创建集中在 06:36:21.523–06:38:05.513Z。这支持“同会话重新建了一套折叠账本”的判断;不会把 estimate 当上游实际计费 token。
413 证据边界:用户截图显示 payload core text alone is ~2949521 bytes、NOT forwarded even for evidence。v0.1.197 的 doomed-probe gate 在正常 preflightCompress 之前,用 coreTextBytes > max(2_000_000, limit * 7.5) 拒绝当前请求。这里 7.5 bytes/token 是启发式,不是真 tokenizer;UI 的 72,613 来自上一笔成功 usage。没有找到该次目标请求的完整可关联服务日志,因此不声称重放了那一条 2,949,521-byte 请求,也不拿其他会话的日志补洞。#2928 处理另一层 guard 恢复问题,本补丁不改变 guard 或其拒绝契约。
2. 已确认的代码路径
src/persist.ts:
const expected = path.basename(relPathFor(id, meta?.protocol, meta?.upstreamOrigin));
const candidates = this.diskFiles.filter(file => fileNameMatchesId(path.basename(file), id, meta?.protocol, meta?.upstreamOrigin)
|| (!meta?.protocol && path.basename(file).endsWith(`_${expected}`)));- namespaced 文件名是
<protocol>/<host>_<sha256(id)[:24]>.json。 - 请求已有
meta.protocol,所以无法命中其他 host 的有效同-ID 文件。 - bounded boot 建立
diskFiles,不预热所有 Session,也不为所有冷文件填 kernel discovered-path map。 - native
id === label不会保留为 legacy alias。 - 最后的 kernel
loadSync(id, new-route-hint)仍找不到旧 host 文件,随后getSession创建 requests=0 / blocks=0 的会话。 - 对照:先把旧 Session 放进 resident map 后切供应商,同一对象保留 274 blocks。内存按 id、冷盘查找按 host,行为不一致。
3. 隔离真实快照复现(只操作临时目录副本)
仅复制 provider-A 文件到全新临时目录,new SessionStore,boot({maxSessions: 0, maxBytes: 0}),使用同 native ID + provider-B metadata。不能在同一个写入对象上测试:writeNow 会填充 kernel discovered map,掩盖故障。
补丁前(legacy 和实际 shadow 两种模式均复现):
{"case":"cold new route, only old route snapshot","warmed":0,"newRouteLoad":null,"newRouteRequests":0,"newRouteBlocks":0,"oldRouteRequests":3697,"oldRouteBlocks":274}
{"case":"resident route switch","sameObject":true,"blocks":274,"requests":3697}补丁后(shadow;生产 bundle 的实际替换方法也跑过同样副本):
2026-10-16T11:57:06.582Z [info] [v=0.1.197] [storage] unified shadow mode ENABLED (storage.unified=shadow or BILI_STORAGE_UNIFIED): every session write is double-ingested into index.db and digest-reconciled [engine: node:sqlite/builtin]
{"case":"cold new route, only old route snapshot","warmed":0,"newRouteLoadFound":true,"newRouteRequests":3697,"newRouteBlocks":274,"oldRouteRequests":3697,"oldRouteBlocks":274}
2026-10-16T11:57:08.576Z [info] [v=0.1.197] [storage] unified shadow mode ENABLED (storage.unified=shadow or BILI_STORAGE_UNIFIED): every session write is double-ingested into index.db and digest-reconciled [engine: node:sqlite/builtin]
{"case":"resident route switch","sameObject":true,"blocks":274,"requests":3697}
installed-bundle method: real snapshot cold reload, old four patches, idempotence and changed-anchor refusal PASS
4. 保守本地补丁与边界
在 exact/current-route 探测失配后、legacy alias/kernel fallback 前,只查找同协议目录下同 ID digest 候选;解码后再次验证 envelope/body ID、持久化 protocol 和 canonical filename。live 优先于 cold;同级多个旧 route 选最新 savedAt,平局按稳定文件顺序。记录 sourceFiles,保留伴随 CCR originals 的查找路径。
- 不重写已存在的 wire history、opaque reasoning 或 tool 参数,不迁移格式、不碰 kernel、不增加配置。
- 当前路由已有快照时维持原有优先级,不自动合并/覆盖已分叉的新旧 ledger。这是避免回滚的临时补丁,不替代 Identity pipeline: key sessions by (agent, conversation id) in the unified store — decouple fold ledgers from protocol/host origin (#2938 / #2847 / #2671 defect-1) #2960 的完整身份设计。
- 匹配文件损坏仍 fail closed;不能在不可解码时静默创建空 ledger。
- 旧 usage 的 origin/provenance 不伪装为新供应商的 usage,baseline 路由安全检查不放宽。
- 这条用户会话现在已经有两份分叉快照;没有自动覆盖它们,也没有声称其后续真实 413 已消失。
补丁源码:
diff --git a/src/persist.ts b/src/persist.ts
index 31864c61..a6267ede 100644
--- a/src/persist.ts
+++ b/src/persist.ts
@@ -875,6 +875,33 @@ export class SessionStore {
return envelope;
}
}
+ // Provider host is mutable metadata, not conversation identity. A
+ // cold bounded boot has no kernel discovered-path entry for the old
+ // route. Recover only on an exact-route miss; never merge or overwrite
+ // an existing route's branch. Keep protocol/body/filename ownership.
+ if (meta?.protocol) {
+ const protocol = meta.protocol;
+ const suffix = `_${path.basename(relPathFor(id))}`;
+ for (const root of [this.sessionsDir, `${this.sessionsDir}-cold`]) {
+ let recovered: { file: string; envelope: PersistedEnvelope<PersistedSession> } | undefined;
+ const routeFiles = this.diskFiles.filter(file => path.dirname(file) === path.join(root, protocol)
+ && path.basename(file).replace(/\.fb\.json$/, ".json").endsWith(suffix)).sort();
+ for (const file of routeFiles) {
+ if (!existsSync(file)) continue;
+ const envelope = this.readEnvelopeFile(file, id);
+ if (!envelope) continue;
+ const savedMeta = envelope.payload.meta ?? envelope.payload;
+ if (savedMeta.protocol !== meta.protocol
+ || !fileNameMatchesId(path.basename(file), id, savedMeta.protocol, savedMeta.upstreamOrigin)) continue;
+ if (!recovered || envelope.savedAt > recovered.envelope.savedAt) recovered = { file, envelope };
+ }
+ if (recovered) {
+ this.sourceFiles.set(id, recovered.file);
+ this.log("info", `[persist] restored ${id} from another upstream route (same protocol, exact body id)`);
+ return recovered.envelope;
+ }
+ }
+ }
const alias = this.legacyAliases.get(id);
if (alias) {
const envelope = this.readEnvelopeFile(alias.file, alias.id);5. 回归与安装验证
本地 v0.1.197:
node --import ./tests/preload-storage-baseline.mjs --import tsx --test tests/bounded-storage.test.ts tests/storage-ccr.test.ts
npx tsc --noEmit --project tsconfig.json
npm run build- 新增 4 个测试组:真正 fresh reader 的跨供应商冷恢复及 messageRefs/block originals/CCR sidecar 精确保留;多 route 最新选择与 exact-route 优先级;协议/body-ID/改名隔离;cold archive 和损坏匹配 fail-closed。
- 补丁前新增组 3 失败、1 通过;补丁后 targeted 18/18 通过(15 bounded + 3 CCR),typecheck/build 退出 0。未运行全套本地测试,也不把 targeted 当完整 CI verdict。
- Windows npm dist 仅作 scoped 方法替换;
node --check通过,五补丁可共存、重复执行不改变文件,anchor 漂移会拒绝写入。升级 watcher 已接入第五补丁。 - 安装使用 NoRestart;安装前后 8787 listener 都是 PID 2772。watcher 自身已重新加载,Bili/Node/app-server 未重启。写入磁盘不等于当前进程已经加载新方法。
测试末尾原文:
✔ ccr: legacy mode keeps the file as the read of record (#2960 ③ control) (8.769862ms)
ℹ tests 18
ℹ suites 0
ℹ pass 18
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 4068.931379
当前 master 复核补充
已在独立 worktree、当前 master 83197e913a9229b765bc0a144cb777ee49560430 应用同一源码修复;npm run build、npx tsc --noEmit --project tsconfig.json 均退出 0,bounded-storage + storage-ccr targeted 18/18 通过。
版本差异已保留:master 的 readEnvelopeFile 已增加损坏状态 quarantine-and-fresh 行为,master 回归对应断言隔离文件保留原始损坏字节;v0.1.197 Windows 热补丁保留旧版 fail-closed 异常契约。没有把一个版本的损坏处理假设强加给另一个版本。
安装后 Windows 核验原文:
PASS: installed bundle syntax; five patch markers; Bili listener PID 2772 unchanged; one reloaded watcher PID 6704
Activity
[-][Bug][v0.1.197] 冷启动后切换供应商漏载同一会话的压缩账本,重新折叠后触发本地 413[/-][+]Cold start after provider switch loses the session's compression ledger; refold hits local 413 | [Bug][v0.1.197] 冷启动后切换供应商漏载同一会话的压缩账本,重新折叠后触发本地 413[/+]ranxianglei commentedon Oct 16, 2026
(ai: vllm-qwen/qwen3.8-27b)
查重结论:非完全重复,同家族保留打开。 与以下条目同机制/症状家族,已互相关联:
本案带来三个此前任何 open 条目都没记录的新事实(见下③),故不按 duplicate 关闭,保持打开到止血 PR 或决策收口。in-flight PR 也查过:无 PR 触碰本机制([PR] refactor(storage): extract StorageBackend contract behind UnifiedStore (#3388 Phase A) #3432 是另一条 storage 重构线,不冲突本修复点)。
① 独立验证(未采信楼主结论,全部重做)
3aeddc160(release PR release v0.1.197 #3130),与楼主声明一致;该 tag 的loadEnvelope四段探测结构与当前 master 逐行一致 ✅ce9bc90a3,三腿全过):同 conversation id 在responses/<hostA>_<hash>.json落盘(requests=3697 + fold 块)→ 新 store 实例 + 生产同款 bounded boot(maxSessions=8, maxBytes=64MB)→loadSync(id, {protocol:"responses", upstreamOrigin:<hostB>}):复现成立,机制与楼主分析一致。空会话 ⇒ 宿主全量重发 ⇒ 要么重建第二套折叠账本(楼主现场的 91 块 B 快照),要么裸文本 > max(2MB, limit×7.5) 被本地 doomed-probe 门拒 413(fix: doomed preflight rejection answers 413, not 502 (#2847) #2921 起的语义)。
boot()是全量store.loadAll()——kerneldiscovered映射按 body id 索引全部文件,跨路由冷加载能自愈([Evidence] pi 车道切供应商(同 modelId)后 fold 不随会话迁移:裸上下文 2.23MB(≥298K est tokens)被 preflight 10 秒拒 3 次;账面 ≤157K 与裸水位背离 10.5h #2847 floor 3「文件存在后启动的新实例会被 boot walk 自愈」只在那个时代成立);c3b212b(v0.1.196 起)改 bounded boot,discovered 不再于启动填充 ⇒ 「切供应商 + 重启」从特殊拓扑问题变成确定性触发。楼主跑 v0.1.197 正落在这个窗口内。loadEnvelope(src/persist.ts:1083-1122)四段探测集全部由 f(id, protocol, origin) 派生——stage 1 三条活路径(当前 host /_unknown// flat)、stage 2 diskFiles 过滤在 meta.protocol 存在时要求 host 精确匹配(:1101)、stage 3 label alias、stage 4 kernel discovered(bounded boot 下为空)→ 全 miss →loadSync返回 null(:1137/:1153)→getSession建空会话。恢复窗口还会自我关闭:空/降级孪生一旦向新路由落盘一次,kernel loadAll 的 savedAt 择优(kernel/src/persist/store.ts:393-397)永久旁路完好旧文件——楼主现场 A(3697 req, 02:36) vs B(2 req, 08:28) 就是孪生已落盘后的形态。readsUnifiedgate 仅 full 生效)⇒ 默认用户全体暴露,不是 opt-in 少数派。② 层次判断(楼主判层正确,我补一层时间线归因)
③ 方案评估与处置请求(等拍板,三个选项)
楼主补丁方向与边界我核过:严格校验、fail-closed(#3157 隔离语义保留)、不合并/覆盖、sourceFiles 保 CCR sidecar——都对。两处需要修正后再进 PR:
staleDiskPayload比较器,src/persist.ts:1536-1551),不能用 savedAt——楼主补丁取 newest-savedAt,在本案数据上恰好选中降级的 B 账本(2 req 赢 3697 req),止血变帮凶;loadEnvelope精确路由 miss 后加「同协议目录 + 同 24-hex id 后缀」兄弟探测,body id + protocol 严格复核,多候选按 staleDiskPayload 比较器仲裁,sourceFiles 保 sidecar。纯读路径、无配置、无 wire 变更;full-default 翻转后此路径自然休眠为什么先请示而不是直接动手:此改动改变全体默认用户的会话加载语义(§7.4 identity/session-binding 人工门禁区);你在 #2847 对同一个止血提议留了未决(当时以统一存储收口);persist.ts 正在你的 R3(#3050 lazy-load)和 #3432(StorageBackend 抽取)重构区内,并行改动有冲突成本。点头即开工(楼主测试 + 上述两处修正 + red/green 回归钉住),并与 #3432 协调合入顺序。
结构化八问(决策请求体例,第 3/5 问按选项分列)
_unknown//flat 探测顺序不变、alias 路径不变、坏文件处置保持 [bug] 会话状态写入缺 fsync:内核崩溃后留下 size 正常但 VDL=0 的全零状态文件,loadSync 永久抛错 → 502 acp-proxy failure 且不自愈(含 7 处 tmp+rename 写路径盘点) #3157 隔离语义、多实例共享目录沿用既有 staleDiskPayload 咨询式计数器边界(无新增风险维度)、full 模式不受影响(readsUnified 先行短路);主要残余风险是与 [PR] refactor(storage): extract StorageBackend contract behind UnifiedStore (#3388 Phase A) #3432/R3 的 hot-file 时序冲突(用 rebase+CI 兜)。B/C——零代码改动,零回归,代价是暴露面延续。收工判定:triage 完成、机制坐实(hermetic 复现红/绿对照)、恢复路径与止血方案就绪,等你拍板 A/B/C。另:标题已按规范改为「English | 原文」格式,正文未动。
nsdbjh commentedon Oct 17, 2026
补充现场恢复结果:安装本地 v2 补丁并重启 Bili 后,原故障会话的 413 已消失,可以继续正常对话。
认可您指出的 v1 仲裁问题:按最新 savedAt 选择可能误选退化账本。v2 没有继续采用该规则,而是仅针对这条已取证的会话,通过原始快照完整文件 SHA256、身份及成功 usage 等校验,恢复完整旧账本;不合并两套 messageRefs/blocks,不改写历史内容。这是定向恢复,不代表通用修复已经完成。
另请在方案 A 的回归测试中覆盖:当前路由已经存在退化快照,同时旧路由仍有完整账本。若兄弟探测只在精确路由 miss 后执行,此场景仍会先命中退化快照,无法恢复。本次现场正是这种情况。
当前保留本地补丁,等待正式修复;请确认最终方案是否覆盖上述已有分叉场景。
ranxianglei commentedon Oct 17, 2026
(ai: vllm-qwen/qwen3.8-27b)
收到现场恢复结果(413 消失、会话可继续对话),记下。你的两点我逐一回应:
① 直接确认:方案 A 的最终形态覆盖「当前路由已有退化快照 + 旧路由仍有完整账本」的分叉场景——你指出的问题成立,我原表述要修正。 「兄弟探测只在精确路由 miss 后执行」这个说法不对:你现场两个文件都在,精确路由会先命中文法正确的退化快照,永远走不到兄弟探测。修正后的规格:
stats.requests → state.nextBlockId比较器择优(复用既有staleDiskPayload比较器,src/persist.ts:1536-1551),精确路由文件不再短路;② 一个配套细节一并说清:跨路由恢复后,加载出的会话要采纳当前请求的路由 meta(而不是沿用旧账本里记录的 origin)——否则下次保存还会写回旧路由路径,孪生永不收敛;采纳后下一次保存会用完整内容重写当前路由文件,退化快照被自然覆盖,最终收敛为单文件。这也是为什么仲裁必须用计数器而非 savedAt:savedAt 只反映「谁最后动过磁盘」,计数器才反映「谁携带的折叠进度更多」。
③ 你的 v2 定向恢复(原始快照全文件 SHA256 + 身份 + usage 校验、单会话定向、不合并两套 refs/blocks)作为该会话的止血是合理的,保留本地补丁等正式修复没问题;逐会话哈希钉死不可泛化,不需要也不适合并入主线。
状态不变:A/B/C 决策请求已在楼上回帖中呈给 owner(八问按选项分列),拍板后按上面修正后的规格开 PR(diff <100 行 + 五腿回归测试)。
nsdbjh commentedon Oct 19, 2026
确认,修订后的方案 A 已覆盖本次双文件并存、当前路由退化的现场。请推进实现并提供 PR,保留上述五项回归测试,同时明确已成功延续的新分支如何避免被旧账本回退。当前继续保留本地 v2,待正式版本通过真实快照冷加载、保存及再次重启验证后再撤除。
ranxianglei commentedon Oct 19, 2026
(ai: vllm-qwen/qwen3.8-27b)
实现完成,PR 已开:#3765 — https://github.comranxianglei/billion-context/pull/3765 (Closes #3399,等 CI + 你 review/merge)。按修订方案 A 落地,只动
src/persist.ts。修法(两层)
loadEnvelope先把同一 id 的全部同协议文件收进一个候选池(精确路由名 ∪ 目录扫描到的兄弟文件;.fb.jsonspill 按 savedAt 归并到 canonical,沿用 kernel loadAll 约定)。每个候选重验 body id + protocol(跨协议隔离),坏文件按 [bug] 会话状态写入缺 fsync:内核崩溃后留下 size 正常但 VDL=0 的全零状态文件,loadSync 永久抛错 → 502 acp-proxy failure 且不自愈(含 7 处 tmp+rename 写路径盘点) #3157 隔离。胜者按折叠进度选:requests → nextBlockId → 平手取精确路由 → 最后才看 savedAt——不按探测顺序、也不单看文件新鲜度。你问的「已成功延续的新分支如何避免被旧账本回退」:仲裁量是折叠进度(副本承载了多少已折叠历史),不是写入时间——requests=3697 的新分支必然压过 requests=2 的旧账本;只有两边计数完全相同时才确定性地取当前路由。测试第 3 腿专门钉住这个方向(新分支延续中不被回退),第 1 腿钉反向(空新分支不吞旧账本)。
测试:新增
tests/issue3399-cross-route-load.test.ts共 11 腿——双文件双向仲裁 / 保存收敛到请求路由 / 纯丢失恢复 / 同路由对照 / 坏文件隔离+降级回退 / 全坏→诚实 fresh start / 计数平手 / 跨协议隔离 / CCR sidecar 跟随 / legacy 模式通道——本地 11/11 绿;storage/persist 定向套件 16 个文件 0 失败;typecheck/build 干净。全量回归在远程 CI(PR check runs)。行为变更披露(有意修复,明细表在 PR 正文):
关于你的本地 v2 热补丁:按你说的保留即可,待正式版通过真实快照冷加载/保存/再重启验证后撤除。注意一处与本地补丁的行为差异:双方计数相等但新鲜度不同时,本版优先当前路由(savedAt 只做最后 tie-break);另外本 PR 只修读侧查找路径,写侧仍按当前路由命名(#2671 defect-1 的写侧 facet,另行跟踪)。
结构化八问
标签:bug / codex / scope/storage / p1(换供应商+重启后会话完全不可用、413 硬失败,按 p1 判)。
判定:修复闭环(PR #3765 待 CI 绿 + owner merge);merge 后建议用你的真实快照走一遍冷加载/保存/再重启验收,通过即撤本地 v2。
ranxianglei commentedon Oct 19, 2026
(ai: vllm-qwen/qwen3.8-27b)
更正上一条的笔误:PR 链接应为 #3765 (#3765)。其余内容不变。
ranxianglei commentedon Oct 19, 2026
(ai: vllm-qwen/qwen3.8-27b)
收工更新:PR #3765 已 rebase 到最新 master,全量 CI 绿。
期间 master 前进了数笔(含 #3623 诊断增强给冷加载加了
logColdLoad日志行、#3759 snapshot-render 等),与我的改动在loadSync两个返回点发生文本冲突。冲突解法 = 意图并集:保留 master 的logColdLoad观测行 + 我的adoptRequestedRoute路由采纳调用(两者无交互,顺序为日志在前)。rebase 后定向复验:typecheck 干净、tests/issue3399-cross-route-load.test.ts11/11 通过,随后推送。CI(eac33b5a0)18 项检查全部通过:build / typecheck / kernel-guard / pi-subagents-guard / pr-labels / update-wire-contract / config-doc-consistency / test ubuntu+windows × node22+24 × 3 shards。
八问结论与此前最终回复一致,无变化(rebase 未引入任何行为变更;唯一新增交互是与 #3623 日志行的共存,属叠加不属修改)。
PR 可合并:#3765 (Closes #3399)。您的本地 v2 热补丁按原计划待该版本经真实快照冷加载验证后再撤除。
fix(persist): recover cross-route fold ledger on cold load after prov…
ranxianglei commentedon Oct 19, 2026
拉最新 master 看 snapshot 方案是否可解决
darkness-A commentedon Oct 19, 2026
独立确认:OpenCode + 0.1.199/shadow;局部回移后生产冷加载恢复成功
补充一个与原报告不同的运行环境:Ubuntu、OpenCode 自定义桥接、官方 npm
billion-context@0.1.199(commit5cdb28d8)、Responses 协议、默认 shadow 存储。不是原报告的 Windows/Codex 环境,也不是 #3765 的作者。这里固定了现有版本做临时修复;已看到维护者关于最新 master snapshot 方案的建议,但未测试最新 master/snapshot 路径,不据此声称最新主干仍有这个问题。本次回移参考 #3765 head
7b825c800198764b6b17c0c709535c07c8ea7048,没有安装整份 PR 测试包。脱敏证据与根因
桥接在 HTTP 请求中确实传递真实执行会话 ID;未发现桥接删除块。相同 ID 在同一个
responses/目录有两份 V3 账本:旧 JSON 的
meta.upstreamOrigin仍指 provider-A,但lastInputTokensOrigin已指 provider-B,说明热内存曾按真实 ID 跨路由复用。重启日志显示 bounded bootwarmed 0;此后带 provider-B meta 的冷加载未找到旧账本,生成较新的退化文件。旧 156 个块并未从磁盘删除。原包
getSession()的内存键是 ID,持久层 legacy/shadow 冷加载却依赖协议 + host + ID 摘要。未修复的真实 bundle 在零预热隔离测试中重现:只有 A 的文件、带 B 的 meta 加载,返回 null。两份文件并存时,仅在 exact miss 后 fallback 也不够,因为 B 的退化文件已经存在。退化后原始上下文估计 2,452,186 tokens,对有效窗口 285,000 触发 preflight;救援压缩仍被本地
preflight fail-fast 413 (retryable=false)拒绝。这不是“上游正常接收过请求”的证据。修复没有关闭 413 检查、扩大窗口或绕过安全门。实施的局部修复
requests → nextBlockId → exact route → savedAt;不以最新时间作为主标准,不合并两个账本。sourceFiles,采纳请求路由后通过官方writeNow/保存链和 shadow 双写收敛,不手工改 SQLite。loadContentStore()会先读新路由路径;若新路由已有不完整原件,它可遮蔽胜出旧账本的原件。本地补丁在改 origin 前先读源侧 CCR,置contentStoreDirty,由官方顺序先保存原件再保存状态;spill 账本使用 canonical CCR 文件名。源侧原件缺失而新路由另有原件时 fail closed,不静默拼接。具体两项回归已包含在下面代码。该进度仲裁沿用现有防陈旧覆盖规则,是受约束的恢复启发式,不声称是任意独立分叉的通用合并算法。主干的 snapshot/统一存储方案仍需独立验收。
验证边界与结果
boot({maxSessions: 0, maxBytes: 0})并等待 remainder scan,不能先用writeNow()给同一个 reader 种 discovered 命中来掩盖缺陷。inFlight=0连续三秒后正常停机、补充账本/SQLite 备份,恢复后重启该独立代理;未重启 OpenCode。新进程实际代码指纹、watchdog、精确 ID 状态均复验通过:156 块、85 活跃块,旧源未动,shadow 视图一致,无 DIGEST DRIFT。可审阅的固定版本补丁
下面是本地使用的方法实现、指纹保护应用器与合成测试部分,不含私有账本/数据库/对话/配置/地址/真实会话 ID。方法是插入现有 SessionStore 的 JS 回移,不是已在最新 master 上 typecheck 的 TypeScript PR。应用器只接受这一份官方 bundle,拒绝未知版本/指纹,重复执行幂等;方法级 diff 可由原方法和下列实现生成。
原 SHA256:
0bda86e4af6bb363ec3e644ab341f9ed079a7dcefab6631c63e1e8418067cd1c。补丁 SHA256:
a0304700dbb614b58acc36b13a2333bfdca5dde068bed09828c9c51b565ae375。依赖升级可能覆盖此热补丁;不能无校验地重放到新版本。建议正式发布时纳入上述 cold-zero-warm、退化 twin、源侧 CCR/spill 与父子/协议隔离回归。
patches/bili-0.1.199-cross-route.methods.js
scripts/apply-bili-cross-route-hotfix.mjs
tests/bili-cross-route-hotfix.test.mjs(仅合成部分,22 项)
pkuqiuning commentedon Oct 19, 2026
Supplementary evidence for the route-rekey / state-identity family, from an independent occurrence on v0.1.201 (proxy instance managed by the client plugin, OpenCode client, legacy/shadow file mode). It reaches the same end state as #3399 (rich old-route ledger orphaned, empty twin under the new route, full-history resend) via a different observed trigger, and adds three details not covered there.
Occurrence. A 780+ request session holding 121 fold blocks (55 active) was persisted under
<protocol>/<relay-host>_<sha24>.json(<protocol>= the per-protocol state directory). During routine state maintenance the proxy was killed; it was respawned by its plugin. On the next save, the session was persisted under a different filename —<protocol>/api.anthropic.com_<sha24>.json— while every actual request still routes to the relay origin. The pre-existing rich ledger under the relay-host filename was never probed at load (no cold-load log line resolves the old file; this is inferred from the empty load result); the session came back empty (0 blocks, compression counter 0, request counter restarted and observed at 3), and the next request resent the full unfolded history: 1292 messages / ~2.0M chars of token-dense code/JSON, tripping the input limit declared to the proxy as 1,000,000 tokens with an HTTP 400 (surfaced by the relay asContextWindowExceeded).Detail 1 — where the wrong origin comes from. The state filename's host label derives from
session.meta.upstreamOrigin, whose resolution chain ends in a hardcoded default:env.ACP_UPSTREAM ?? fileConfig.upstream ?? "https://api.anthropic.com". In plugin deployments where the real upstream is a relay, a restart that loses per-request route context can silently substitute that default — and the default then becomes the session's route identity. Our config sets noupstream, so the default was always live and only needed one context-loss to win. (The "respawn → lost route context → default origin" step is inference: the re-key itself emitted no log line.)Detail 2 — the shadow path can precede the re-key. Three seconds before the drifted save (respawn at T, digest-drift line at T+3s by log timestamps), the log printed:
In this occurrence the legacy file had been hand-edited (state surgery to prune dead ids), so the digest mismatch was expected — but it demonstrates a second path to the same end state: any legacy/shadow disagreement drops the watermark, and the following save can land under a different (default) route.
Detail 3 — silence + the gate. The re-key itself produced no warning line (no drift entry, no banner); the only symptoms were the empty session report and then the upstream 4xx. And at the exact overflow moment, the model's own
compresstool call was refused by the proxy withgate:no-visible-context(receipt text begins"no visible context — the proxy holds"; remainder elided) — the anti-loop gate closed the only in-band recovery path precisely when compression was most needed, and the next request 400'd. Both feel worth addressing alongside #3765's restore fix: the route label is treated as display metadata, yet it determines which state file a cold load resolves — and therefore whether a 121-block ledger exists at all.Recovery in this occurrence: copying the rich old-route file over the new-route filename restored the session immediately — consistent with #3765's "fold-progress winner" arbitration order (
requests → nextBlockId → exact-route → savedAt).Merge pull request #3765 from ranxianglei/2026-10-19_issue-3399-cross…