Skip to content

fix(#2601): model-switch lineage — churn-tolerant chain continuity + persona-fork routing follow - #2719

Merged
ranxianglei merged 6 commits into
masterfrom
2026-10-11_2601-model-switch-lineage
Oct 11, 2026
Merged

ranxianglei merged 6 commits into
masterfrom
2026-10-11_2601-model-switch-lineage

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

修复 #2601:模型/供应商切换的会话血统

问题(两层)

A. 重序列化导致链断裂 → 误 fork:模型/供应商切换时,dsh 重放同一段历史但换了一种序列化(thinking 内联 vs 结构化 block、工具 id 重铸、图片占位行增删)。字节级 chainContinues 失配 → resolvePersonaKey 把主线 fork 到 <raw>|sub:<fp>,压缩状态滞留在冻结的父会话上。

B. 管理调用落在陈旧父会话:dsh 原生压缩转发始终盖 RAW id + nativeCaller:true(#2024),fork 后调用仍路由到父会话 → kernel every ref is unknown to this session → stale-ref 熔断。

根因修复

Layer A — 抗扰动链连续性(src/prefix-affinity.ts)

Layer B — persona-fork 血统跟随(src/plugin.ts)

涉及文件

文件 改动
src/prefix-affinity.ts 归一化尾部指纹 + chainContinues 第二次机会 + 快照往返
src/plugin.ts personaDescendantsOf / livePersonaDescendant / personaLineageWitness + 路由两层跟随
src/server/handle.ts note() 传入 fp.normTailHash
src/persona-anchor.ts, src/session-id.ts 注释对齐(#2244 → #2601 语义)
src/fold-reconcile.ts 导出 USER_IMAGE_PLACEHOLDER 供投影过滤
tests/issue2601-persona-fork-lineage.test.ts 4 单元 + 1 e2e

测试

安全边界

Closes #2601

@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-11_2601-model-switch-lineage (ed86e5c)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2972-pr.2719.79f60e7

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

Option B — Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到。这是已完成的 [PR] 工作(2 commits,head 516b83ad),我不重做,按 PR Review 规范走审查:①原 issue #2601 方向核对 → ②回归审查 → ③代码审查 → ④测试有效性。分支落后 master 16 个提交,会先 rebase 到当前 master 再判定可合并性(CI 大部分 job 已绿,test 矩阵还在跑)。审查结论稍后按结构化八问回复。

…persona-fork routing follow

A model/provider switch mid-conversation re-serializes the same history
(thinking inlined vs structured blocks, provider re-minted tool ids,
image placeholder appended/stripped). Byte-exact chainContinues then
fails, resolvePersonaKey forks the main lane onto <raw>|sub:<fp>, and
the host keeps stamping the RAW id on its management calls — compression
state strands on a frozen parent and the kernel's stale-ref circuit
breaker trips (#2601).

Layer A — churn-tolerant continuity (prefix-affinity):
- every noted chain also stores a NORMALIZED tail fingerprint (churn
  keys dropped, role kept as a marker, content-length leaves only,
  sorted so block reordering is invisible, placeholder lines filtered,
  normalizeMessageText fold — the #2636 discipline);
- chainContinues gets a second chance after the exact+depth gates: a
  re-serialized tail with equal normalized fingerprint continues the
  chain, so resolvePersonaKey MIGRATES the anchor on a model switch
  instead of forking. Different content still forks; shorter histories
  never continue (#2668 poison discipline);
- snapshots round-trip normTailHash (restart keeps the second chance).

Layer B — persona-fork lineage follow (plugin routing):
- when a fork still legitimately happens, host-stamped (nativeCaller)
  management calls naming the stale parent follow the live |sub:
  descendant (fresher lastSeen, recent traffic), by their own id or via
  a lineage witness in the conflict branch;
- legacy unflagged callers keep #2016 fail-closed; foreign witnesses
  keep #2024 native-honor; switch-back self-heals (parent live again →
  routing goes home).

Tests: tests/issue2601-persona-fork-lineage.test.ts — 4 unit legs
(second chance, content gating, anchor migration, snapshot round-trip)
+ e2e through the real proxy (fork minted, lineage follow, 409 control,
foreign witness control, switch-back self-heal). Full suite vs base at
the same commit: identical pre-existing local-env failures, zero new.
@ranxianglei
ranxianglei force-pushed the 2026-10-11_2601-model-switch-lineage branch from 988183a to 80eec4f Compare October 11, 2026 03:29
ework-agent and others added 4 commits October 11, 2026 11:51
Review-time supplement: the USER_IMAGE_PLACEHOLDER filter in the normalized tail fingerprint had no test where the placeholder sits on the TAIL message itself (the only position the projection compares). Mutation-checked: removing the filter fails this test.
…nchor

A model switch landing in the same window as an unannounced history
rewrite (dsh local compaction) still satisfies the fork conjunction even
with #2719's churn-tolerant continuity: fp changed AND chain
discontinuous. dsh declares its model target on every request via
x-bili-plugin-model — consume both host declarations: the header model
changed AND the system line-diff is confined to lines naming the old/new
model (folded) => absorb the fp half (migrate-model, raw key). No
host-specific phrasing hardcoded; anything less keeps the fork.
…-absorption

fix(#2601): absorb header-corroborated model-drift into the persona anchor
@ranxianglei
ranxianglei merged commit 6dafceb into master Oct 11, 2026
30 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.255-master.6dafceb (rolling master tag).

npm install -g billion-context@0.0.255-master.6dafceb  # 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.

antclt pushed a commit to antclt/billion-context that referenced this pull request Oct 11, 2026
…lei#2601/ranxianglei#2676)

Scenario A pins the model-switch contract: a dsh model switch (system
model line + x-bili-plugin-model header) landing in the same window as
an unannounced history rewrite is ABSORBED — raw key kept, no |sub:
fork, kernel machinery (compress → decompress) still works on the same
session; the uncorroborated control still forks.

Scenario B pins the fork contract: a fork with context COPIES the
parent's state — inherited blocks (ids + summaries + originals, child
decompress round-trip), seeded raw→ref map equal to the parent's, the
durable-guard lane adoptable (null wire refs, BLOCKED never in byRef),
parent untouched.

A/B teeth: pre-ranxianglei#2719 master mints the fork (scenario A red); master
without ranxianglei#2625 fails scenario B with 409 raw/ref mapping inconsistent —
the ranxianglei#2676 silent degrade.
antclt pushed a commit to antclt/billion-context that referenced this pull request Oct 11, 2026
…ponses wires (ranxianglei#2601/ranxianglei#2676)

The ranxianglei#2729 proof pinned scenario A (model switch = one session) and
scenario B (fork copies state) on the chat wire only, but the persona
wiring is per-call-site in src/server/handle.ts (anthropic :811 /
openai :821 / responses :843,:880) with a different system-text
extractor per lane — correct-in-one-lane is not correct-in-all (ranxianglei#377).

Parameterize the harness over chat/anthropic/responses: per-wire
request builders (system message vs top-level system vs instructions),
per-wire mock upstream responses, identical session-state assertions.
google is deliberately absent (no persona call site, issue ranxianglei#2730).

Teeth (A/B @ 4ecd82f pre-ranxianglei#2719): scenario A mints the |sub: fork on
all three wires; scenario B 409s (ranxianglei#2676); controls still fork on all
three — the persona path is engaged per wire, not vacuous.
ranxianglei pushed a commit that referenced this pull request Oct 11, 2026
…es (#2806 review)

fork-adoption-wires + issue2033-anonymous-anchor drive ANONYMOUS clients whose
identity rides prefix-affinity.json in the shared default state dir. Without
isolation they hydrate foreign chains written by sibling test files running
concurrently in the same CI job and co-write the file underneath each other;
once this stack added four more test files (incl. heavy multi-proxy e2e) the
interference flipped both suites' assertions on all four CI nodes while every
parent tree stayed green. Isolate with the established #2719 idiom.
ranxianglei added a commit that referenced this pull request Oct 13, 2026
v2.1: fragment-tail guard for truncation/reanchor (tail window 8) and
|sub:task:<skel8> keys for tag-less strangers (mixed-traffic probes:
subagent short replay and cross-session key collisions closed).

v2.2: personaTag + declaredModel inputs; wired into all four prepares
through personaConversationOrder (replaces the personaNamespace ladder
call sites; ladder module kept for characterization tests).

- same tag: persona owns the id — ride/continue/reanchor through
  truncation, compaction rewrites, diverged or shorter replays
  (old fp-equal semantics, byte-identical lane keys)
- tag change: migrate on head continuity (#2241/#2250) or on a
  header-corroborated model switch (#2601/#2719/#2817); otherwise
  stable |sub:<fp16(tag)> persona lane (self-recording)
- tag-less: shallow rides the raw key (old non-anchoring path);
  strict |sub:aux only for virgin ids; deep strangers fork to
  |sub:task:<skel8> (#150-class protection)
- empty incoming tag never counts as a persona change

Tests: issue2944 corpus + dsh persona families + 2601/2817 continuity
50/50; crosswire/side-lane/subagent/dsh-native/title 25/25; goldens
10/10.
@ranxianglei
ranxianglei deleted the 2026-10-11_2601-model-switch-lineage branch October 15, 2026 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant