You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
验证:npm run typecheck 干净;npm test 869/870(唯一失败 resolveClientCommand: codex/claude resolve to themselves 在未改动的 master 上同样复现——沙箱装有 /usr/bin/codex 的环境依赖问题,与本改动无关);npm run build 干净。
Trimmed rework of #479 opened as #530, scope per this thread's decisions: sessions are permanent — the retention/size GC is dropped entirely (a session is used for a year and must never be lost); what ships is the single-copy leaf-block dedup + one-pass boot + once-ever migration marker. Real-corpus validation (453 files / 240.2MB copy of the live dir): boot 1.8s→814ms single walk, 518/518 leaf blocks collapse on load (−38.1MB reclaimable = 16% of corpus), 0 files deleted at boot.
For the record, the field-level distribution measured on that corpus (what is actually eating the 240MB):
field
bytes
share
what it is
messages
152.0MB
63%
lastMessages: the client's raw full-conversation snapshot, overwritten every turn. Sole consumer: bili export rendering (src/export.ts:64)
blockContents
77.5MB
32%
original-message cache per compress block; #530 halves the leaf-duplicate 50% of this
state
6.2MB
3%
kernel CompressionState
meta/stats/etc
<0.2MB
<1%
So after #530, the dominant remaining growth driver is messages (63%). Options (need a design call, possibly kernel cooperation since loadAll parses the envelope generically):
gzip the field (text compresses ~5–10×; needs kernel-side or format-level support to parse),
snapshot-on-export (stop persisting every turn; export re-synthesizes or degrades to block-only rendering, which v2 files already do),
accept it as the price of offline-complete export.
Also accepted as future work: lazy boot (stat-only walk + loadSync top-N) once permanence meets a much larger corpus.
#479 is closed as superseded by #530 (its rebase fixes — #404 freshness sort interplay, realistic test timestamps, pfa- guard — are all carried into #530).
诚实的代价:归档会话的 bili export 从"模型所见全量折叠视图"退化为"块摘要视图"(v2 行为),uncompressed tail 不再可导出。如果以后有人需要保真兜底,加一个显式命令(如 bili export --save-snapshot,按需把当前快照落盘一次)是几行代码的事,比默认全量持久化便宜得多——可以作为后续小需求而不是现在的负担。
Activity
ranxianglei commentedon Aug 31, 2026
请处理这个 issue 并回复处理结果
ranxianglei commentedon Aug 31, 2026
[bot] 🏷 收到,正在处理。已确认三个根因(叶块 one/full 重复、零 GC、启动两遍 loadAll + 迁移日志反复),正在按建议的四条修复实现,完成后会开 PR 并回帖链接。
ranxianglei commentedon Sep 3, 2026
worktree 锁验证:请回复 ok
ranxianglei commentedon Sep 3, 2026
[bot] 🏷 ok
ranxianglei commentedon Sep 3, 2026
[bot] 🏷 已处理完毕 → PR #478: #478
审核结论(动手前验证)
三个根因全部在代码层面证实,且都是根本原因而非表面现象:
collectBlockContent(acp-kernel dist:2818)——full:false路径只对 active 子块做 summary 替换;叶块directBlockIds: []时两条路径过滤出完全相同的消息集,文本逐字节相同、count 也相同。bili 侧唯一的缓存点就是src/stream.ts applyRanges,所有压缩路径(loop/core、compress-loop-responses、preflight、stream-openai/responses)都经过它。与你的全库扫描结论一致。.tmp-*清理,无任何保留策略。src/session.ts initSessions()先调migrateLegacyIds()(内部一次store.loadAll())再自己loadAll(),两遍完整递归+逐文件 readFileSync+JSON.parse;且旧日志条件是rekeyed || unlabeled,unlabeled 永远 >0 → 每次启动必打。日志证据与你实测吻合。修复内容(PR #478)
按你建议的四条实现:
cacheBlockContent中 one/full 相同则内存共享同一对象(消费端均为只读,已核实);序列化时(buildRecord)相同只写full、省略one;加载时buildSession用full还原one(独立副本)。旧文件双键格式照常加载,向后兼容。叶块正文落盘只剩一份,文件体积 ≈ 减半。src/session-gc.ts):stat-only 预扫描(readdir+stat+rm,不读不解析任何文件体),在 load 之前运行 → 过期文件零解析成本。保留期BILI_SESSION_RETENTION_DAYS(默认 90d,0=关)+ 字节预算BILI_SESSION_MAX_BYTES(默认 1GiB,0=关),超预算按最旧优先删。规范文件与 spill 兄弟(<base>.fb.json)作为同一单元处理(年龄取最新 mtime),.tmp-*不动。依据:bili state 是派生态,会话本体在客户端(与既有内存 LRU 驱逐同一立场)。migrateLegacyIds()并入新的loadAllMigrated()——一次 walk+parse,会话身份不稳定:credential/upstream 维度导致长会话状态孤儿化(sessions 缺失) #286 rekey 在同一份数据上内存内完成(碰撞/unlabeled 语义不变);迁移日志只在真正发生 rekey 时打印 → 一生只出现一次。测试与 pre-flight
tests/session-gc.test.ts:retention/budget/双关/spill 单元/.tmp-*/缺目录/env 默认值单测 + 验收集成测试(300 个过期 + 5 个新鲜文件:一次启动在读取前清掉过期文件——池大小即读取探针,MAX_SESSIONS 提到 >305,只有 5 个幸存者进内存;二次启动磁盘总量不变)。tests/proxy-persist.test.ts:叶块去重往返(相同视图只存一份、不同视图双存、序列化体积减半、加载还原)、迁移测试迁到loadAllMigrated、迁移日志只出现一次(log capture)。npm run typecheck✅ /npm test877/878(唯一失败launcher.test.ts codex resolve在未改动的 master 上同样失败——本机存在/usr/bin/codex的环境差异,与本改动无关)/npm run build✅合并请人工操作:#478
ranxianglei commentedon Sep 3, 2026
[bot] 🏷 收到 #478。开始按 Triage 流程处理:先逐条核实三个根因(叶块 one/full 逐字节重复、零 GC、启动两遍全量 loadAll + 迁移标记不落地),拿到证据后再动手。修复方向与你的建议一致:①
directBlockIds为空只存full;②启动期保留策略 GC;③迁移完成标记 + 两遍 loadAll 合并;④MAX_SESSIONS改为加载预算。有结论和 PR 后在此更新。ranxianglei commentedon Sep 3, 2026
映射修复验证:请忽略本条,仅验证同步落位
ranxianglei commentedon Sep 3, 2026
已修复,PR: #480
方案(按你建议的 1+2+3 方向实现):
findFreePort。每次 launch spawn 子进程时带一个每次启动唯一的--handshake-file(也可用BILI_HANDSHAKE_FILE设置),子进程 bind 成功后原子发布{origin, pid}(tmp 文件 + rename)。只有自家子进程知道这个路径 → attach 到的 origin 构造上就是自家的,静默挂上陌生实例在机制上不可能;attach 前再做 pid 交叉核对(纵深防御)。完整 instanceId 握手按你的规划在 ACP_PASSTHROUGH one-click silent kill of all compression: no logs / no banners / panel invisible and non-clearable, all sibling env knobs take effect in silence | ACP_PASSTHROUGH 一键静默关死全部压缩:无日志/无横幅/面板不可见且不可清除,同族 env 旋钮全部生效于无声 #403 单独跟踪。bili start撞端口的行为不变(hint + exit 1)。/tmp/bili-proxy-<launchId>.log),不再吃满 20s。debug: true,launch 出的代理日志等级与普通bili start完全一致(--debugflag /ACP_DEBUGenv / 配置文件继承);每次 launch 独立的/tmp/bili-proxy-<launchId>.log重定向保留(422fc6c 的本意是排障可追溯——保留日志文件、移除强制 debug)。验收对照:
startServer+ blocker,断言 handshake 文件带 OS 分配端口与正确 pid、该 origin health 200、blocker 未受影响);另用构建后的 dist 跑了真实子进程全流程:blocker 占端口 → 369ms attach 到自家子进程实际端口,health 200,子进程日志含 fallback warnbili start:强制 debug 已移除,真实 e2e 中子进程启动日志仅 7 行验证:
npm run typecheck干净;npm test869/870(唯一失败resolveClientCommand: codex/claude resolve to themselves在未改动的 master 上同样复现——沙箱装有/usr/bin/codex的环境依赖问题,与本改动无关);npm run build干净。wosnxn123 commentedon Sep 4, 2026
【整合请求 · 双 PR 互撞】本票现有两个同族修复 PR:#478 与 #479(均 dirty;内容同为叶块单副本 + 启动单遍 loadAll + 存储 GC)。请二选一保留(建议留验收覆盖更全者)、关闭另一个,并 rebase 到 master;三条验收不变:叶块 blockContents 只存一份、启动仅一遍目录 walk、legacy 迁移只跑一次。顺带同轮处理:#386 的 #399 与 #387 的 #397 也已 behind/dirty 多日,可一并 rebase 收尾——两票修复内容此前均已通过 bot 自测(871/882 全绿),只差与 master 对齐。
ranxianglei commentedon Sep 4, 2026
[bot] 🏷 整合完成,结果如下(全部已验证,非口头):
1️⃣ #478 / #479 双 PR 互撞 —— 已由 owner 完成整合,我核实无需再动
wt-478-ework-daemon):已在 master tip25e441e上(behind=0、ahead=2,mergeable_state=clean),且有两条独立复审 LGTM("Rebase 干净:merge-base == master tip 25e441e…typecheck ✅;全量测试 1039/1040")。.bili-migration-286.donemarker 文件,fix: bound sessions storage growth (#407) #478 只是日志级别门控)、另有 legacy 文件加载时归一化。结论:留 fix: bound session storage growth — single-copy leaf blocks, boot GC, one-pass startup (#478) #479 正确,无需操作,等人工合并即可。2️⃣ #399(CJK estimator)—— 已 rebase 到 master 并验证
598b687 → d57fe49,无冲突。typecheck ✅ / build ✅ / 全量 1034/1035(唯一失败 = 本沙箱装了/usr/bin/codex导致的路径解析测试,master 上同样失败,与本票无关)。3️⃣ #397(acp_status live ranges)—— 已 rebase,解决 2 处冲突并验证
d498f89 → 48f503b。分叉后 master 在冲突区新增了功能,不能简单取任一侧,逐 hunk 合并:src/loop/core.ts(3 hunks):master 侧新增了 PRE-COMPACTION ARCHIVE 展示段和#422 refreshFoldedhost hook;PR 侧把handleAcpStatus抽到新文件src/acp-status.ts并删除LoopCtx.nudge快照字段。解法:采纳 PR 的 live-recompute 结构,同时把 archive 段迁入src/acp-status.ts(否则该功能丢失),保留refreshFolded,去掉nudge:透传。src/server.ts(1 hunk):LoopCtx 构造点取 PR 侧 + 保留 master 的refreshFolded。typecheck ✅ / build ✅ / 全量 1036/1037(唯一失败同上,沙箱环境性)。新增
tests/acp-status.test.ts+tests/compaction-archive.test.ts定向跑 8/8 ✅。两个 PR 现在都是 against-master-tip、mergeable clean,可以合并了(合并由人工执行)。
4️⃣⚠️ 顺带发现:#401 本体已在 master 被修复,我的 PR #480 已关闭(superseded)
开发期间 master 推进了 145 个 commit,其中包含覆盖 #401 全部三点的实现链:
c2567cc(instance governance,#417):子进程自己 bind,经BILI_LAUNCH_TOKEN把真实 origin/port/pid/instanceId 写回 instance 文件,父进程只在 token 匹配时 attach——明确注释 "#407: no probe-release-rebind"instanceId比对;stale record 不能背书任何 origin;测试tests/launcher.test.ts:694bili start保持 fail-fast--debug大日志proxyStartArgs仅opts.debug时才加--debugf34200e(#446/#526,今日合入):未显式--port时 launcher 直接用 OS ephemeral 端口,私有代理不再蹲 8787验收标准:(a) 竞态下只 attach 自家子进程(token match)✅;(b) 默认等级日志量与
bili start同级 ✅。我基于 v0.1.67 开发的握手文件方案(PR #480)与之重叠且更窄,已在 PR 里贴了对照表并关闭。这些修复尚未打 tag,会随下个 release 发布。建议:#401 可待下个 release 发出后由你验证关闭;另有一个小残留可酌情开新票——子进程启动即死亡时,父进程仍要等满
SPAWN_WAIT_MS(20s)才报错(#480 里有 <5s fast-fail 的实现可参考)。ranxianglei commentedon Sep 4, 2026
Trimmed rework of #479 opened as #530, scope per this thread's decisions: sessions are permanent — the retention/size GC is dropped entirely (a session is used for a year and must never be lost); what ships is the single-copy leaf-block dedup + one-pass boot + once-ever migration marker. Real-corpus validation (453 files / 240.2MB copy of the live dir): boot 1.8s→814ms single walk, 518/518 leaf blocks collapse on load (−38.1MB reclaimable = 16% of corpus), 0 files deleted at boot.
For the record, the field-level distribution measured on that corpus (what is actually eating the 240MB):
messageslastMessages: the client's raw full-conversation snapshot, overwritten every turn. Sole consumer:bili exportrendering (src/export.ts:64)blockContentsstateSo after #530, the dominant remaining growth driver is
messages(63%). Options (need a design call, possibly kernel cooperation since loadAll parses the envelope generically):Also accepted as future work: lazy boot (stat-only walk + loadSync top-N) once permanence meets a much larger corpus.
#479 is closed as superseded by #530 (its rebase fixes — #404 freshness sort interplay, realistic test timestamps, pfa- guard — are all carried into #530).
ranxianglei commentedon Sep 4, 2026
[bot] 🏷 收到,#479→#530 的 supersede 与裁撤 GC 的决定已记录(与之前"留覆盖更全者、验收三条不变"的结论一致)。关于
messages(63%)的设计取舍,我先把代码侧事实核了一遍(master @25e441e),再给明确建议:核实到的关键事实
lastMessages在 src 内的消费者确实只有src/export.ts:64;写入点只有src/persist.ts:344(每轮覆盖),内存赋值src/session.ts:259。src/session.ts:105 lastMessages?: CoreMessage[]),读路径src/persist.ts:391对缺失/非数组直接归一为undefined——v2 文件今天就是没有这个字段在跑的,降级路径不是假设,是既有生产行为。renderHandoff(src/export.ts:64-108)对无快照会话有完整的 v2 fallback:块摘要(+--full时 blockContents 原文),且输出里明确告知用户"这是 v2 文件、离线只能恢复这些"。有测试覆盖(tests/export-uncompressed.test.ts)。messages大小天然被客户端上下文窗口封顶(客户端每轮发什么就存什么,native compaction 后≈窗口大小);语料 152MB/453 文件 ≈ 335KB/文件,与此吻合。也就是说单文件不无限涨,总量增长 = 会话数 × 窗口快照。建议:选 2(停止每轮持久化,保留内存态),理由:
persist.ts:344的写入即可——不需要 kernel 配合(选项 1 才需要,因为 loadAll 通用解析信封,gzip 得动格式层 + acp-kernel 先发版,跨仓库链路长)。诚实的代价:归档会话的
bili export从"模型所见全量折叠视图"退化为"块摘要视图"(v2 行为),uncompressed tail 不再可导出。如果以后有人需要保真兜底,加一个显式命令(如bili export --save-snapshot,按需把当前快照落盘一次)是几行代码的事,比默认全量持久化便宜得多——可以作为后续小需求而不是现在的负担。实施上我建议:#530 合入后开一个独立小 PR(persist.ts 写入移除 + 测试调整 + 可选:借 #530 的 boot 单遍 walk 顺手一次性剥离存量文件里的旧
messages字段,老文件否则要等各自下次写入才瘦身)。范围小、可单独回滚,不和 #530 的验收纠缠。等你拍板,拍板后我直接开工。Merge pull request #530 from ranxianglei/2026-09-04_sessions-storage-…
fix: single-copy leaf blocks + one-pass session boot (ranxianglei#401)
ranxianglei commentedon Sep 6, 2026
#401 修复已提交 — PR #587
方案:盘上不再存全量原始历史,改存有界折叠视图快照:
prune(lastMessages, state)—— 正是bili export默认渲染的折叠视图(摘要替代已折叠原文)BILI_PERSIST_TAIL_TOKENStokens(默认 16384,0=完全关闭消息持久化)效果:
--full仍可从 blockContents 恢复压缩块原文)旧行文件无需迁移:每个会话下次保存时自然改写为新格式。
发现并固化的 kernel 语义:
prune()永远保留第一条 user 消息即使已被覆盖(会话锚点)——测试显式断言。Pre-flight: typecheck ✓ / 1085/1087(2 个已知 plugin-agent 环境失败)/ build ✓ / 新增 tests/persist-tail.test.ts 5/5
请 review 合并。
Merge pull request #587 from ranxianglei/2026-09-06_persist-bounded-f…
fix ranxianglei#401: persist bounded folded-view snapshot instead of …
fix(docs): restore two sections missing from the zh-CN pair; preserve…
test: storage-refactor pins — render goldens (4 wires) + legacy-forma…
test: storage-refactor pins — render goldens (4 wires) + legacy-forma…
fix(launcher): child-reported bind via handshake file kills port TOCT…