Skip to content

[PR] fix(#4778): keep the raw key when a tag change rides on a host-side history rewrite - #4782

Merged
ranxianglei merged 7 commits into
masterfrom
2026-10-26_4778-dsh-goal-subfork
Oct 27, 2026
Merged

ranxianglei merged 7 commits into
masterfrom
2026-10-26_4778-dsh-goal-subfork

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

What / why

#4778: DSH NEXT's goal auto-continuation rewrites the prior per-turn system messages in its own log (cleared to empty content, persisted, resent on every later request) while each turn also ships a fresh leading system prompt. In resolveSessionOrder's tag-changed branch this breaks BOTH existing migration rungs (head-fragment equality, byte-exact prefix-affinity chain), so the entire main conversation was re-keyed onto an empty <id>|sub:<fp> lane. The root lane's fold state (112 active blocks in the reporter's session) became unreachable, every request ran a ~6M-token preflight compression that never finished forwarding, and each restart minted yet another |sub: lane.

A second trigger landed in-thread (mid-session provider switch, e.g. anthropic→openai on dsh desktop): the new wire re-renders the same transcript AND resends per-turn system cells the old wire never carried in-array — same failure domain, same fix.

Fix

A third rung in the tag-changed branch (src/session-resolve.ts): when

  • the incoming history is main-shaped,
  • it extends past the recorded skeleton (no stale-shorter-replay rewind), and
  • the recorded body still sits verbatim inside the incoming — ≥ CONTINUATION_MIN_RUN (8) consecutive same-index content-cell fragment agreements, compared over conversation cells only (harness-state system/developer cells excluded from both sequences before alignment, so host-side insertion/removal/emptying of per-turn system entries cannot shift the alignment),

the anchor migrates to the raw key instead of forking. Exact per-cell sha256 comparison throughout — no fuzzy similarity (MESSAGE-IDENTITY doctrine); an 8-run agreement between distinct conversations is cryptographically impossible.

All four guardrail legs are pinned with negative rows (#3617 gate discipline): self-contained stranger under a reused id (overlap gate), stale shorter replay (length gate), shallow review blob (mainShaped gate), scattered sub-threshold agreement (threshold gate). Existing pinned fork rows in the persona suites all survive unchanged (verified by running them).

Behavior change (old → new)

Tag-changed requests that previously forked onto |sub:<fp> now migrate to the raw key when they carry ≥8 consecutive same-index content-cell agreements with the recorded skeleton AND are not shorter than it. Intended: this is the fix itself — the affected class is "same conversation whose host rewrote part of its own persisted log or re-rendered it on another wire" (dsh goal turns, dsh provider switches). Unaffected: strangers/replays/blobs as above; non-tag-changed paths untouched.

Documented boundary (pinned by a control row): renderer-divergent reasoning text (thinking blocks on one wire, absent on the other) still breaks the per-cell fragments, so such a switch forks until the identity-hash formula question is decided — that is an owner decision, deliberately NOT changed here.

Recovery for already-forked sessions

Self-healing: after upgrading, the first request of a stuck session passes the new rung (its full history still contains the recorded root body) and migrates back onto the raw lane with its existing folds. No data migration needed. Orphaned |sub: lanes remain in storage (harmless; normal GC territory).

Tests

  • New: tests/issue4778-dsh-goal-subfork.test.ts — unit state machine against the issue's exact topology (settle → goal rewrite → steady state) + e2e through the wired dsh openai lane. Verified pre-fix: exactly the two goal rows fail (derived-persona), controls pass.
  • Cross-wire provider switch (the second in-thread trigger): clean anthropic→openai re-render migrates on the PRE-EXISTING head-fragment rung (red/green: green both sides); the dsh-NEXT shape (per-turn system cells resent only on the new wire) is red pre-fix, green post-fix via the new rung; the reasoning-asymmetry row pins the honest boundary (forks either way).
  • Targeted locally on the swept master base: the 9 persona/session-resolution suites (67 tests) green + this suite 10/10; typecheck green. Full suite left to CI per §7.2.

Related (not fixed here): #4686 / PR #4703 (UI read side following a fork — same |sub: family, different symptom), #3149/#3150 (title sidecar ghost lanes), #2944/#3397 (resolver lineage this extends), #4720 (in-thread finding: nudge baseline stamped from an estimate — registered there), #3978 (preflight resumability — already tracked, data point registered there).

Closes #4778

…ost-side history rewrite (#4778)

DSH NEXT's goal auto-continuation rewrites the prior per-turn system messages in its own log (persisted empties resented on every later request) while each turn also ships a fresh leading system prompt. The mid-history rewrite breaks BOTH tag-change migration rungs (head fragments, byte-exact chain), so the whole main conversation was re-keyed onto an empty |sub:<fp> lane — orphaning the root lane's fold state and forcing a multi-million-token preflight on every request until a restart minted yet another lane.

Add a third tag-change rung: when the recorded body still sits verbatim inside the incoming (>= CONTINUATION_MIN_RUN consecutive same-index content-cell fragment agreements, harness-state cells excluded from both sequences before alignment) AND the incoming extends past the recorded, migrate instead of fork. Guardrails preserved by design: self-contained strangers under a reused id share no positional content (overlap gate), stale shorter replays cannot rewind the live skeleton (length gate), shallow aux blobs never qualify (mainShaped gate), scattered sub-threshold agreement still forks (threshold gate).

Regression suite: tests/issue4778-dsh-goal-subfork.test.ts (unit state machine + e2e dsh openai lane; verified to fail pre-fix on exactly the goal rows). Targeted persona/session suites (9 files, 67 tests) + typecheck green locally.
@ranxianglei ranxianglei changed the title fix(#4778): keep the raw key when a tag change rides on a host-side history rewrite [PR] fix(#4778): keep the raw key when a tag change rides on a host-side history rewrite Oct 25, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

查重:不重复。 本 PR 就是 #4778 的修复交付(Closes #4778),无其他在途 PR 触碰 session-resolve 的 tag-changed 分支。PR 正文已正确交叉引用同家族不同症状/机制的相关项(#4686/PR#4703 UI 读侧、#3149/#3150 标题旁路幽灵行、#2944/#3397 resolver 谱系),不并入、不重复立项。

标签:bug, dsh, scope/kernel, p1(主对话永久不回复 = 「不能用」类,按 2026-10-19 owner 规则定 p1;会话核心键判定归 kernel 域)。

以下是对 PR 本身(而非 issue 结论)的独立审核——读了完整 resolver 状态机、handle.ts 五个接线点、affinity-neutral 投影行为、测试文件全文,并本地实跑验证。

结构化八问

  1. 是什么问题:DSH goal 自动续作那一轮之后,整条主对话被会话键判定误当成「派生人格」,重键到空的 |sub:<hash> 分区;根分区已有的全部压缩块变不可达,每次请求在 preflight 现场压缩约 600 万 token 且转发不出去,表现为「会话永远不回复」,重启还会再派生新分区。问题在会话身份判定层(src/session-resolve.ts),不在压缩引擎或 UI。
  2. 什么原因导致的:两个事实叠加——(a) DSH NEXT 每轮系统提示都不同(tag 每轮都变,恒走 tag-changed 分支);(b) goal 那一轮 DSH 自己把之前几轮的系统消息清成空内容并持久化(历史中段被改写)。这同时打断了 tag-changed 分支里两条既有迁移路径:「头部片段相等」(被清空的格片段失配)和「字节级前缀链」(链在中段断裂),于是落进兜底分叉。空内容持久化后每次重发都命中同一分支,所以永远回不来。根因是:tag-changed 分支对「同一对话、宿主改写了部分自己的历史」这一情形没有证据路径。
  3. 影响范围与严重程度:DSH 桌面(NEXT)开了 goal 自动续作的长会话;触发后会话完全不可用(不回复、请求堆在 preflight),数据未丢(根分区完好)但不可达。p1。
  4. 怎么修复的:tag-changed 分支加一级判定(rung)——入站历史是主回合形态、不比已记录骨架短(防旧快照回卷)、且存在 ≥8 个连续同位置内容格 sha256 精确一致(system/developer 这类 harness-state 格从两侧序列剔除后再对齐,宿主增删/清空系统条目不会错位对齐)→ 判为同一对话的宿主侧编辑,anchor 迁回根键而非分叉。全程精确比对、无模糊匹配(MESSAGE-IDENTITY 教义)。没采用 issue 报告者建议的「DSH id 正则 + 主形态无条件认领裸 key」是对的:那会拆掉 dsh 车道现有人格/旁路分流保护(并发同 session-id 流互相覆盖 lastInputTokens 基线:#388 侧请求分类漏掉「整段上下文单消息」形态,#1595 re-anchor 放大覆盖 #1916/[Bug][dsh] 0.1.204: auto-review side request collides with the main session → false native-compaction rebase → aux usage skips #453 clamp → permanent upstream 400 #4438),并把客户端特判写进协议无关的 resolver(违反 会话身份:顺序+自铸id 为认领主判,hash 降级为防漂移护栏(通用规则,取代 persona-fp 阶梯) #2944 规则 4);位置证据路径覆盖 dsh 的同时保留既有分流,也顺带覆盖任何「宿主改写自己日志」的同类问题。已卡住的会话升级后自愈:第一个请求的完整历史仍含已记录主身 → 过新 rung → 迁回根车道,无需数据迁移;孤儿 |sub: 分区留在存储里(无害,GC 范围)。
  5. 是否有回归问题:逐项清点 diff 触碰路径的既有行为——三条既有迁移 rung(头部片段/模型切换佐证/前缀链)位于新 rung 之前,纯追加未重排,结果不变;兜底分叉的 key 格式逐字节不变(持久化的分叉分区跨升级不漂移);非 tag-change 路径、首次 sight claim、持久化 wire 形态(OrderSkeletonEntry)全部未动。高危模式逐项过:除已披露的行为变更外无语义漂移、无吞错、nudge/preflight/缓存参数零改动、输出格式不变。本地验证:11 个 persona/session 相关套件 98/98 全绿(issue4778 新文件 + dsh-persona-fingerprint/continuity + issue2944-neutral-skeleton + issue3397-persona-restart-stability + issue2601-model-drift-absorption/persona-fork-lineage + issue2817-crosswire-persona-fold + subagent-namespace + affinity-neutral + prefix-affinity,比 PR 声称的 9 套件更宽);typecheck 干净。一个理论边缘如实注明:长度门比较的是总格数(含 harness 格),理论上「对话格更少但塞满 system 条目」的旧重放可绕过长度门——真实宿主不会产出这种形状(harness 条目随回合数成比例),且即便发生,结果(re-anchor 到宿主活态)与既有同 tag 短重放语义(line 372「skeleton follows the living end」)一致,不构成拦截理由。
  6. 是否破坏缓存:不影响。只改「请求绑到哪个会话键」(把主对话恢复绑到根键),不动前缀缓存接缝逻辑;迁回后出站前缀反而复用根车道的基线与折叠块,更稳定。
  7. 是否改了设计方向:无架构转向——在既有判定阶梯上加一级,沿用 [[bug] dsh 0.1.185: main lane forks itself on a mid-session model switch, orphaning the persona anchor — every native compress is refused (9/9, not covered by #2157) #2241/[bug] dsh:side request 先到会抢走 persona 锚点,主会话被 fork 到 |sub:<fp>,原生 compress 永久失败 #2156/[Bug] dsh 会话反复 model/provider 切换时主对话迁移到 |sub:<fp> persona fork,宿主盖章的 compress/decompress/acp_status 仍解析在陈旧父 id —— ref 跨空间不可解析直至熔断 #2601 同源模式;消息身份教义(精确相等、禁止模糊相似)不变。
  8. 是否引入了新的配置:无。没有新 env/config/默认值。

测试有效性(单独说)

新测试文件 tests/issue4778-dsh-goal-subfork.test.ts 按 issue 真实拓扑(settle → goal rewrite → steady state)搭了单元状态机 + 走接线的 dsh openai 车道 e2e(真 server、真 header、真 session store 断言,含「不得产生 |sub: 会话」的负向断言)。我本地做了修复前复现:把同一测试文件对着无修复的 master resolver 跑,恰好只有 2 个 goal 行失败(判成 derived-persona)、5 个控制行全过——测试有牙,且控制行钉住了既有分叉行为(修复前就成立,证明 PR 没顺手改掉它们)。四条护栏腿各钉了负向行(#3617 双向往返纪律):陌生会话复用 id(位置零重叠)、旧短重放(长度门)、浅层辅助 blob(mainShaped 门)、散点低命中(<8 照旧分叉)。接线侧核对过:handle.ts 五个 personaConversationOrder 调用点(dsh 四线 + codex/claude instructions 指纹线)传入的 personaTag 构造方式与测试 helper 一致(openaiSystemTextForPersona = 非空 system 文本 \n\n 连接);sideRequestLike 请求根本不进 resolver,mainShaped 门只是第二道防线。

CI 状态与收工判定

写此回复时 PR head(92e9e5a)的全部 CI lane 仍在 queued/运行中,mergeable_state=blocked(等 checks);全量套件判决以远程 CI 为准(§7.2)。本地定向证据已齐:98/98 绿 + 修复前失败复现 + typecheck 干净。

审核结论:通过。 修的是根因(tag-changed 分支缺「宿主改写自身历史」的证据路径)而非堵症状;护栏四腿双向钉死;回归面逐项清点无意外变更;行为变更已在 PR 正文按旧→新披露。CI lane 转绿后即可合并(合并由 owner 执行)。

@ranxianglei ranxianglei added bug Something isn't working dsh p1 scope/kernel labels Oct 25, 2026
@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-26_4778-dsh-goal-subfork (21e6718)

Latest build — install this exact version

npm install -g billion-context@0.0.6263-pr.4782.3558273

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Recent builds (commit → version)

commit version build
21e6718 billion-context@0.0.6263-pr.4782.3558273 build
9bd4f67 billion-context@0.0.6141-pr.4782.96aaed4 build
8694a84 billion-context@0.0.6056-pr.4782.451d4ae build
b0aaeb8 billion-context@0.0.5940-pr.4782.1319eec build
92e9e5a billion-context@0.0.5910-pr.4782.3fd8750 build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr4782.tgz
npm install -g package

Install instructions are refreshed on each push.

ci-check added 5 commits October 26, 2026 10:14
master window commits 293ae65/de5e03659 bumped kernel/package.json to
0.0.165 without regenerating the lockfiles; lock-sync re-resolution then
rewrites the stale recorded versions (root 0.0.163, kernel 0.0.164) and
fails. Pure recorded-version sync via npm install --package-lock-only;
no dependency or semantic change.
…on the #4778 continuation rung

Second #4778 trigger reported in-thread: a mid-session provider switch
re-keys the conversation onto an empty |sub: lane when the new wire resends
per-turn system cells the old wire never carried in-array. Clean re-renders
were already absorbed by the head-fragment rung (#2791 wire-neutral
projection); the dsh-NEXT mid-history-systems shape needs the #4778 rung
(red pre-fix, green post-fix). The reasoning-asymmetry row pins the honest
boundary: thinking text rides the fragment on the wire that carries it, so
a renderer that drops it still forks — making the identity hash think-blind
is an owner decision, not a silent formula change.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

状态:冲突已在本地解决并验证通过,但推送被镜像 502 挡住,尚未落到上游。 这是本轮(自动修复 attempt 1/2)的唯一未完成项——冲突本身不需要任何设计决策,attempt 2 或人工在传输恢复后一条命令即可收尾。

冲突是什么、怎么解的

把 origin/master(当前 341e76c28)merge 进 PR 分支后,唯一冲突是两个 lockfile(无代码冲突):

安全核验后才取 master 侧:

  1. kernel/package.json 已被 git 自动解析为 master 的 0.0.166(PR 分支没动它);
  2. 逐行 diff 两侧 lockfile,除 acp-kernel 版本号外零差异——PR 侧没有引入任何其他依赖,所以整份取 master 侧不会丢东西;
  3. 取 master 侧后两个 lockfile 与 origin/master 逐字节一致,且与 kernel/package.json=0.0.166 内部自洽。

重要:没有覆盖远端新提交。 动手时发现远端 PR 头已从原 head 92e9e5ac7 前进到 f4e1b3326(其间合入了 ci-fixes 锁文件同步 + 一笔新增的「anthropic→openai 跨线 provider 切换」测试钉)。我把 merge 重建在 f4e1b3326 之上而非旧的 92e9e5ac7,保留那笔测试提交。合并提交 6af3f1fe6,双亲 = f4e1b3326 + 341e76c28(= 当前 origin/master)。

本地验证(§7.2 定向)

  • npm run typecheck:干净(kernel/pi-subagents 随 master 的 kernel/src/compress.ts、sync.ts 变更一并重编)。
  • 定向跑 persona/session-resolution 套件 101/101 全绿,含本 PR 的 tests/issue4778-dsh-goal-subfork.test.ts(已含远端新增的那几行跨线用例)及 dsh-persona-fingerprint/continuity、issue2944-neutral-skeleton、issue3397-persona-restart-stability、issue2601 两件套、issue2817-crosswire-persona-fold、subagent-namespace、affinity-neutral、prefix-affinity。
  • 全量套件留给远程 CI 判定(§7.2)。

阻塞点(精确)

git 传输层(本地镜像代理)对 fetch 与 push 持续返回 HTTP 502 Bad Gateway。首次 fetch 成功,随后会话中段起一直 502;我累计重试约 22 次(跨度约 4 分钟)全部同一错误。非命令/参数问题,是基础设施可用性故障。 合并对象已安全落在本地分支(6af3f1fe6),无任何数据丢失;远端 PR 分支仍停在 f4e1b3326 未被改动。

收尾方式(传输恢复后)

  • 在本工作区:git push origin tmp-conflict-4782b:2026-10-26_4778-dsh-goal-subfork(普通 push,fast-forward,非 force)。
  • 若工作区全新:重新 merge origin/master 进 PR 分支,lockfile 两处冲突一律取 master 侧(0.0.166)即可,其余自动合并。

结构化八问

  1. 是什么问题:PR 分支落后 master 93 个提交导致与基线冲突;实际冲突面仅两个 lockfile 的 acp-kernel 记录版本(0.0.165 vs 0.0.166)。
  2. 什么原因导致的:PR 分支上较早的 ci-fixes 同步把锁文件钉在 0.0.165,而 master 期间把内核推进到 0.0.166,两边记录值分叉(CI Control Center: Centralized CI Failure Handling & Status Sync (Comment all CI issues here; do not open new issues) | CI 总控: CI 失败集中处理与状态同步(所有 CI 问题在此评论, 勿开新 issue) #4599 类漂移)。
  3. 影响范围与严重程度:仅阻塞本 PR 合并,不影响运行行为;不解决则 PR 无法合入。属流程性阻塞,非可用性缺陷。
  4. 怎么修复的:merge master 进 PR 分支,lockfile 取 master 侧使记录版本与 kernel/package.json=0.0.166 自洽;先验证两侧 lockfile 除版本号外零差异再整份采纳,避免丢依赖。
  5. 是否有回归问题:无。未改任何源码语义;master 带入的内核/存储变更由 master 自身 CI 背书,本 PR 的 session-resolve 修复在合并后定向套件 101/101 复验通过。
  6. 是否破坏缓存:不涉及(只动了锁文件记录版本与合并历史)。
  7. 是否改了设计方向:不涉及。
  8. 是否引入了新的配置:不涉及。

收工判定:冲突解决+验证已完成,唯一待办是把 6af3f1fe6 push 上去——被镜像 502 卡住,等传输恢复(attempt 2 或人工)一条命令收尾。无需决策立项(纯机械冲突)。

…-goal-subfork

# Conflicts:
#	kernel/package-lock.json
#	package-lock.json
@ranxianglei
ranxianglei merged commit b02370a into master Oct 27, 2026
49 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.879-master.b02370a (rolling master tag).

npm install -g billion-context@0.0.879-master.b02370a  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

ranxianglei pushed a commit that referenced this pull request Oct 27, 2026
Follow-up merge after master advanced past c499b14 mid-resolution (#4969/#4970/#4972/#4971 blog+billing, #4544 event-loop-yield, #4678 mysql-v8-dedup, #4782 dsh-goal-subfork). Conflicts:
- src/server/prepare-responses.ts: import hunk unioned again - kept this branch's fold-reconcile import line (superset of master's: adds noteBiliToolSurface/outboundBiliSurface); master's yieldToEventLoop lines from #4528 landed in all four prepare files untouched.
- tests/golden/storage-render/{anthropic,chat,google,responses}.json: regenerated from the merged tree via scripts/update-storage-render-goldens.ts; output byte-identical to the previous round's regeneration (master's new commits did not change these golden conversations' outbound wire or persisted state) and differing from master only by this branch's image-rescale armed-state latch digests.
Verification: no conflict markers remain; targeted suites green (golden-storage-render + fold-reconcile + issue3400-image-rescale = 109/109); typecheck clean. Full-suite verdict deferred to CI on the pushed head.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working dsh p1 scope/kernel

Projects

None yet

1 participant