Skip to content

fix(#459): stabilize fork-host live-tail refs - #466

Merged
ranxianglei merged 1 commit into
masterfrom
2026-09-16_fork-ref-stability
Sep 21, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-09-16_fork-ref-stability

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Fixes #459

背景

#452「循环压缩」的 L1 根因:fork host(PI_ACP_FORK_HOST=1,无 buildContextEntries)路径上 live 尾部消息用数组下标 live-N 当 id——宿主每轮 append/evict 都会让同一内容换 id,nudge 引用的 ref 下一轮就失效(does not exist in this session),compress 永远失败、emergency-inject 死循环。这正是 OMP 默认被拒的原因(src/index.ts 的 refusal 注释)。

改动(4+1)

  1. 内容寻址 id(src/runtime.ts mergeLiveEntries):unmatched 尾部消息的 id = live-<sha256(identity + rank)[:16]>。identity 来自 messageIdentity(去时间戳/排序键/剥 ref 标签)。rank 用望远镜不变量 seq(M) = count_P(X) + unmatched-X-before-M:尾部消息落盘时 U−1/P+1,存活重复项 rank 守恒 → 跨 fire 同内容同 id;新消息只追加在尾部,不影响前序 rank。
  2. 确定性对齐兜底(src/sequence-match.ts findPositionalPrefixRun):findUniqueLongestRun 因歧义拒绝时,按「persisted 只在尾部增长」的性质做尾锚定逐长度匹配,返回唯一确定解。行为变化:等长歧义 run(如 [e1,gap,e2] 对 live [e2])以前整段拒绝,现在对齐到最近一次出现——保持身份稳定,严格更优(integration.test.ts T2 已改名锁定该契约)。
  3. 孤儿 ref 剪枝覆盖非 pi 视图(src/runtime.ts stateFor):merged 视图也跑 pruneOrphanRefs,强制 byRaw ⊆ 当前视图 id ∪ block id,清掉 Cyclic compression | 循环压缩 #452 里跨代残留 ref(m00190.. vs m05395.. 并存那类)。
  4. 工具路径视图对齐(src/runtime.ts lastLiveBySession):架构级发现——工具调用走 stateFor(ctx) 只看 getBranch()(滞后于 in-flight 视图),而 nudge 渲染的是 merged 视图。master 上 fork host 的 compress 结构性地解析不到 live 尾部 ref(本分支 A/B 探针验证)。现在 context fire 缓存最后已知 live 尾部,工具路径回放同一视图;pi host 与无缓存场景行为完全不变。
  5. 警告软化(src/omp.ts / src/index.ts):加固已落地,FORK_HOST_WARNING_MESSAGE 改为「refs 已内容稳定(Fork host (PI_ACP_FORK_HOST) live-entries ref 漂移根治:live 尾部 id/ref 不稳定导致 compress 区间构造失败 #459);若仍见 does-not-exist 说明宿主改写 in-flight 视图,长会话建议走 billion-context proxy」;admission 日志字段更新为 hardening:Fork host (PI_ACP_FORK_HOST) live-entries ref 漂移根治:live 尾部 id/ref 不稳定导致 compress 区间构造失败 #459/proxy:billion-context。常量名与 notify-once 机制不变(stopgap 测试零改动通过)。

验证

备注

@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Extension Artifact

Branch: 2026-09-16_fork-ref-stability (dc923a8)

Option A — Install from npm PR tag (recommended)

pi install npm:billion-context-pi@pr-466

Each push to this PR publishes a new version under the pr-466 npm tag.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pi-pr466.tgz
pi install ./package

This comment is automatically updated on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到。正在拉取分支 2026-09-16_fork-ref-stability(be991f6)做完整 review:核对 diff、本地跑 typecheck/test/build、检查与最新 master 的同步状态。CI 目前除 windows test(22) 还在跑之外全部绿。稍后给出结论。

@ranxianglei
ranxianglei force-pushed the 2026-09-16_fork-ref-stability branch from be991f6 to 90147e1 Compare September 16, 2026 06:13
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review 完成,结论:可以合并(合并动作留给你)。

逐条核对(5/5 与代码一致)

  1. 内容寻址 id(src/runtime.ts mergeLiveEntries/stableLiveId):live-<sha256(identity\0rank)[:16]>;rank = persisted 中该 identity 出现次数 + 前序 unmatched live 同 identity 数,望远镜不变量实现正确。usedIds 防碰撞逻辑删除是有意的——同内容同 rank 复用同一 id 正是本 PR 的目标。
  2. 尾锚定兜底(src/sequence-match.ts findPositionalPrefixRun):仅在 findUniqueLongestRun 返回 undefined(歧义放弃)时启用,取最长 k 使 live[0..k) === persisted[len-k..len),构造上确定唯一。integration.test.ts T2 改名后的断言锁住了新契约(歧义 run 对齐到最近一次出现、不再整段拒绝)。
  3. merged 视图剪枝(stateFor):确认 pruneOrphanRefs 保留集 = 当前视图 id ∪ block direct+effective id(src/runtime.ts:313-326),块引用的 ref 不会被误删,decompress/search 不受影响。
  4. 工具路径视图对齐(lastLiveBySession):pi host 恒走 live=undefined 分支、无缓存场景行为与 master 完全一致,只影响 fork host 工具路径——与声明相符。这是本次最有价值的架构级修复。
  5. 警告软化:常量名 FORK_HOST_WARNING_MESSAGE 与 notify-once(forkWarned)机制未动,仅文案与日志字段更新,stopgap 测试零改动通过——已验证。

本地验证(原 head be991f6)

我做了一个操作:rebase 到最新 master

分支基于 457df15,落后 master 3 个提交(release v0.1.71 + #461/#462 proxy stand-down)。已在本地 rebase 并验证 patch 零漂移(range-diff 显示 be991f6 = 90147e1),rebase 后重跑全量:typecheck ✓ · build ✓ · 834 / 831 pass / 0 fail / 3 skipped(+2 来自 master 新加的 proxy-standdown 测试)。已推回分支,新 head 90147e1。CI 在 90147e1 上重跑中:pr-validation/build-artifact/docker/e2e(ubuntu) 已绿,test 矩阵进行中。

非阻塞观察(记录在案,不要求改)

  • findPositionalPrefixRun 最坏 O(n²)(内容高度重复时每个长度都要扫一遍);只在 unique matcher 放弃时才触发,常规会话无感,马拉松会话若遇到重复刷屏可留意延迟。
  • lastLiveBySession 缓存的 staleness 窗口:两次 context fire 之间宿主若改写/收缩视图,工具路径会回放上一轮的尾部直到下一次 fire 刷新——这正是软化后警告文案指向的残余风险,属设计内取舍。
  • 内容寻址的别名边界:消息离屏后同内容在同 rank 复现会共享坐标,旧 ref 若非块引用会被剪枝收敛,有界且为设计固有。

📌 中文摘要:修复了 fork host 下 live 尾部 ref 随宿主视图漂移导致 compress 死循环的问题(#459/#452 L1 根因),内容寻址 id + 尾锚定对齐 + merged 视图剪枝 + 工具/nudge 视图对齐四项加固均已逐条核对属实、本地全量验证通过;我已把分支 rebase 到最新 master(patch 零漂移,新 head 90147e1),CI 重跑中,可以合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 CI 更新:rebase 后的新 head 90147e1 上 9/9 checks 全绿(pr-validation、build-artifact、docker、e2e ubuntu+windows、test ubuntu/windows × node 22/24)。分支与 master 已完全同步,无冲突,随时可以合并。

📌 中文摘要:CI 已全部通过,PR 处于可合并状态,等你点合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

继续

…fix alignment + orphan pruning + tool-view parity)

- live-tail ids are now content-addressed (sha256-16 of message identity +
  duplicate rank) instead of array-index live-N: identical content keeps the
  same id across context fires while the host appends or evicts elsewhere.
  Rank uses the telescoping invariant seq(M)=count_P(X)+unmatched-X-before-M,
  so persisting tail messages never renumbers surviving duplicates.
- findPositionalPrefixRun (sequence-match.ts): deterministic tail-anchored
  fallback when findUniqueLongestRun rejects an ambiguous match; persisted
  branches only grow at the tail, so tail alignment is unambiguous.
- pruneOrphanRefs now also runs on the merged non-pi view, enforcing
  byRaw ⊆ current-view ids ∪ block ids (kills cross-generation stale refs).
- Tool path now sees the same view as the context path: lastLiveBySession
  cache replays the last known live tail into stateFor() for tool calls on
  fork hosts (getBranch() lags the in-flight view; this asymmetry is why
  compress from nudge-cited refs always failed there).
- FORK_HOST_WARNING_MESSAGE softened: hardening shipped, proxy still
  recommended for long sessions; admission log fields updated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fork host (PI_ACP_FORK_HOST) live-entries ref 漂移根治:live 尾部 id/ref 不稳定导致 compress 区间构造失败

1 participant