Skip to content

[Feature] Extend stableSystemAnchor's stable head and tail diff update capability to plugin mode (prioritize Pi) | [Feature] 将 stableSystemAnchor 的稳定头部与尾部 diff 更新能力扩展到插件模式(优先 Pi) #2385

Open

Description

@Pasitearko

功能请求

希望将 stableSystemAnchor 所提供的“稳定系统提示词头部 + 在对话尾部传达指令变更”的能力扩展到 插件模式,优先支持 Pi,并明确 OMP 等插件宿主的支持范围。用户已经与作者沟通过,这里单独提交需求,便于跟踪实现。

核心诉求:使用插件时,会话中途正常编辑、删除或替换 AGENTS.md 中的规则,不必为了缓存而只在文件末尾堆叠补丁;局部指令变更应正确传达给模型,同时尽量避免替换请求头部、使后续已缓存上下文整体失效。

当前环境与现状

  • OS:Windows。
  • 当前使用 Pi,加载 npm:billion-context 包的 Pi 原生接入插件(dist/agent/pi-native.js)。
  • 本机正在运行的 bili 代理及 Pi 所加载的 billion-context 包版本:v0.1.187。
  • 插件正常注册后通过 x-bili-plugin 标记参与代理协作;这不是没有插件配合的 plain-proxy 模式。
  • 本机配置未设置 stableSystemAnchor。

当前 配置文档 明确:

  1. stableSystemAnchor 默认关闭。
  2. 只用于纯代理模式,带 x-bili-plugin 的插件模式不参与锚定。
  3. 开启后,局部修改保留首次头部字节,并追加尾部 [System context update] user note,携带行级 diff;非局部变更等情况采用新头部。

核对本机 v0.1.187 代码,相关处理确实受 opts.stableSystemAnchor && !pluginMode 条件限制。因此,仅在配置中开启该开关,并不能让正常的 Pi 插件请求获得这一能力。

背景:关联 #2333

#2333 的最终日志分析确认,OMP 会话中出现两次系统提示词改写记录:

system prompt changed (9240 → 9837 chars)
system prompt changed (9837 → 7361 chars)

这说明宿主在会话中途改写系统提示词可能造成显著的前缀缓存重付。该 issue 最后并未确认改写内容就是 AGENTS.md,也没有确认当前 Pi 存在同一动态改写问题;这里引用的是需求背景,不把 OMP 的分析直接当成 Pi 的复现证据。

原分析:#2333
现有锚定实现:https://github.com/ranxianglei/billion-context/blob/HEAD/src/system-anchor.ts

期望行为

  1. 插件模式也有明确可用的稳定头部机制。 可以复用 stableSystemAnchor,也可以由插件/宿主侧实现等效机制;请明确启用方式、适用宿主及默认值。这个请求不是要求把当前开关全局默认打开。
  2. 局部指令编辑保持头部稳定。 对 AGENTS.md 或其他已加载指令的局部增删改,将差异放在对话尾部,让模型明确理解新增、删除和替换后的有效规则,而不是继续执行已删除的旧规则。
  3. 与插件上下文生命周期正确协作。 更新说明不能每轮重复累积,也不能在压缩、会话恢复或重启后遗失;避免与宿主已有的更新提醒机制重复注入。
  4. 保留诚实的退化策略。 对结构性重写、工具定义变化等不适合差异更新的情况,允许采用新头部并发生一次预期缓存失效,不要求为了缓存强行冻结所有动态内容。
  5. 补齐文档。 区分 plain-proxy 与 plugin/native 接入,避免用户误以为设置 stableSystemAnchor: true 就能对插件模式生效。

实现位置由维护者决定,不建议仅删除 !pluginMode 判断,而不处理插件的指令更新与上下文协作。

建议验收

  • 在 Pi 插件模式建立多轮会话后,修改已加载的 AGENTS.md 并触发宿主重新加载;确认局部编辑没有替换稳定头部,尾部出现正确的更新说明,模型能遵循更新后的规则。
  • 分别覆盖新增、删除、替换规则,以及多次连续修改。
  • 覆盖压缩、恢复/重启、关闭功能及非局部变更回退,确认没有重复注入、更新丢失或旧规则复活。
  • 用相邻出站请求的前缀对比验证机制,不仅依赖上游偶然的缓存命中率;为插件通道补充回归测试。

Activity

  1. ranxianglei commented on Oct 8, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

    [bot] 🏷 收到。先给结论:问题真实存在,我已核对代码确认;机制可以干净地迁移到插件模式——但这是一次触及「双模式 wire 形状 + 配置面语义」的功能变更,按本仓规则属于必须人工拍板、不能自动合入的那一档。 我给出一个明确的推荐方案(不是选择题),等你确认三点后开工。

    一、我验证了什么(不是凭描述)

    • 唯一的拦路点是门槛,不是架构。 src/server.ts 四处锚定调用全部受 opts.stableSystemAnchor && !pluginMode 限制:anthropic(:3725)、openai(:4023)、google(:4306)、responses(:4608)。排除理由写在 :3722 注释——「插件 agent 自管上下文,锚定会重复处理」。这是一个保守的默认范围,不是结构性不兼容。
    • 载体是模式无关的,原样可用。 note 存在 session.metadata["stableSystem.<surface>"],每轮从会话状态重新注入为尾部 user 消息(anthropic :3875 / openai :4128 / google :4393 / responses :4708),不进 kernel fold 空间 → 天然穿越压缩/重启、不会逐轮累积(上限 ANCHOR_MAX_NOTES=8)。这套东西在插件模式下无需改造。
    • 严格更优或等价,无回归可能。 对某宿主开启锚定后:最坏情况(非局部变更 / >8 次抖动)走「直接替换锚点 = 转发新头部」,正好等于今天插件模式的行为;最好情况(局部编辑)转发旧头部 + 尾部 diff,前缀保持命中。所以开启只会改善、不会引入回归。
    • 背景证据链已坐实(缓存泄露分析3 #2333)。 字节取证证实「宿主中途改写系统提示词 → 出站体在 ~byte 1203 分歧 → 整段前缀重付」。那是 OMP 的 +597 字符动态段;Pi 是否同款动态改写未确认,但「用户主动编辑 AGENTS.md」(case 1)正是锚定的干净受益场景。

    二、方案对比与我的推荐

    • A(推荐):复用现有 stableSystemAnchor 布尔开关 + 内部按宿主白名单谓词(evidence-per-client,仿 dshPersonaFingerprintApplies,src/session-id.ts:161),首批只放 pi。四处门槛改为 (!pluginMode || <allowlisted>)。
    • B:新增独立开关(stableSystemAnchorPlugin / per-agent map)——擅自发明新配置形态,按配置面纪律默认禁止,需你明确签核才做。
    • C:在插件/宿主侧(pi-native.ts)实现等效机制——逻辑分散到宿主侧,且拿不到代理已有的会话状态与跨轮注入通道,不如 A 内聚。

    我明确推荐 A:不新增任何配置字段(复用现有布尔已能表达用户意图「让我的系统头稳定」),按宿主收敛是实现细节而非用户维度;默认仍 false,不影响任何现有用户。

    三、具体改动面(A 方案)

    1. src/session-id.ts(或 system-anchor.ts)新增 stableAnchorPluginAgentApplies(headers):x-bili-plugin === "pi";后续宿主需带流量证据再进白名单。
    2. src/server.ts 四处门槛改为 opts.stableSystemAnchor && (!pluginMode || stableAnchorPluginAgentApplies(req.headers))。
    3. 身份派生(风险点,已降低):server.ts:1968 的 verbatim-keying 臂要求 pluginAgentHeader===undefined 且只在 Responses 线分支。Pi 走 anthropic/openai 线(registerProvider、chat 形 payload),不经该分支 → 首批范围无需动身份派生。将来若把某个 Responses 线插件宿主放进白名单,才需同步放宽该臂。
    4. 文档(配置面语义变更,必须披露):CONFIGURATION.md / .zh-CN.md 的 stableSystemAnchor 段(zh :654)现在写死「仅纯代理模式…插件模式 agent 永不被锚定」,必须改为「纯代理 + 白名单插件宿主(当前 pi)」。
    5. 测试:补插件通道回归——Pi 多轮会话 → 改 AGENTS.md 触发重载 → 断言局部编辑不换头部、尾部出现正确 diff;覆盖增/删/替换/连续多次/压缩恢复重启/关闭开关/非局部回退;用相邻出站体前缀对比验证(不靠上游偶发命中率)。

    四、需要你先拍板的三点(建议,非选择题)

    1. 首批宿主白名单 = {pi},OMP 先排除——OMP 那种周期性动态段属宿主自身行为,缓存泄露分析3 #2333 已定调「修法在 OMP 侧(头字节保持稳定、易变状态放 user 消息)」,锚定对它收益≈0 还可能产生噪音 note。
    2. 复用现有 stableSystemAnchor 布尔,不新增字段。
    3. 授权我动上述四处门槛 + 文档 + 测试(不动身份派生、不动 kernel、不动 update)。

    五、诚实边界

    • 本次解决「用户真实编辑指令文件」这类局部变更(case 1)。宿主自己周期性往头部塞易变内容(case 2,OMP 型)不在范围,仍需宿主侧修。
    • 若某宿主把时间戳/运行态烤进系统提示词,churn guard 会兜底退化为今天行为(安全、无收益)——所以白名单要按「系统提示词会话内稳定」的证据逐宿主加,不整仓放开。

    六、结构化判断

    1. 是什么问题:插件模式(Pi)编辑 AGENTS.md 等已加载指令时,因 !pluginMode 门槛被排除在 stableSystemAnchor 之外,头部字节变化导致整段前缀缓存重付。
    2. 什么原因:[Feature] Optimize the cache by reorganizing the context. #1085 落地时保守地把锚定限定为纯代理专用(担心与自管上下文的插件宿主重复处理),留下能力缺口而非架构障碍。
    3. 影响范围/严重度:仅限有此诉求的插件宿主(当前 Pi);成本瑕疵(多付前缀 token),非功能不可用。
    4. 怎么修:复用既有锚定机制,加按宿主白名单放行插件请求;载体沿用尾部 diff note。
    5. 回归:最坏情况=今天行为,严格更优或等价;不触碰 plain-proxy 路径语义。
    6. 破坏缓存:目标是减少失效;退化路径只发生一次预期 miss。
    7. 设计方向:不变——仍是「代理侧 wire 层尽力兜底、根因在客户端」,只是把适用面从纯代理扩到白名单插件宿主。
    8. 新配置:无新增字段(复用现有布尔);默认值不变(false)。

    判定:方向成立、方案内聚、风险可控,但按规则需你确认第四节三点后我再进入实现并开 PR(Closes #2385)。 若认可 A 方案与 {pi} 白名单,回复确认我就开工。

  2. changed the title [-][Feature] 将 stableSystemAnchor 的稳定头部与尾部 diff 更新能力扩展到插件模式(优先 Pi)[/-] [+][Feature] Extend stableSystemAnchor's stable head and tail diff update capability to plugin mode (prioritize Pi) | [Feature] 将 stableSystemAnchor 的稳定头部与尾部 diff 更新能力扩展到插件模式(优先 Pi)[/+] on Oct 16, 2026
  3. added
    协议接线改动范围:内核之外的主机侧接线(src/agent 适配器、server 路由、注入拦截)/范围兜底/客户端标签
    on Oct 18, 2026
  4. pengkaicheng commented on Nov 9, 2026

    @pengkaicheng

    Another plugin-mode host is affected: DSH (DeepSeek Harness desktop).

    The gate is exactly as described — opts.stableSystemAnchor && !pluginMode on all four wires
    (dist/index.js @4320482 responses / @4440169 anthropic / @4490715 openai / @4509526 google).
    DSH's lane is plugin mode: dist/agent/dsh-native.js does
    headers.set("x-bili-plugin","dsh") (plus x-bili-plugin-conversation),
    so pluginAgentHeader(req.headers) returns "dsh" and the anchor never runs.

    The reason this matters for DSH in particular is that its head system block is stable except for one
    line
    , and that line changes whenever the user picks a different model:

    • Same session, two system/message records (turn 1 and turn 3): both 72 lines, 71/72 byte-identical.
      The only differing line is L3:
      • You are a coding agent powered by the [awsb逆-0.3]claude-opus-4-6 model.
      • You are a coding agent powered by the deepseek-v4.1-flash model.
    • 72 lines is far below the 400-line structural-change threshold, and 71/72 shared lines is well above
      the 70% "local change" threshold — so it would take the tail [System context update] diff path and
      the head bytes would stay frozen.

    Cost as measured on this machine (bili's own logs, [fold-reconcile] + [acp-usage] pairing):

    time session flip hit before → after
    14:28:01 d9e8e741 12466 → 12470 99% → 3%
    14:38:30 d9e8e741 12470 → 12473 99% → 3%
    15:51:46 5503c02d 12473 → 12470 99% → 13%
    15:53:20 3727980a 11280 → 11277 97% → 67%
    16:08:04 aff24c3d 11280 → 11277 92% → 29%

    Direct confirmation in the log right before one of them:
    14:28:01.583 [headroom] model=deepseek-v4.1-flash → 14:28:01.699 [fold-reconcile] ... sess=d9e8e741 ... system prompt changed (12466 -> 12470 chars).

    bili's cache report attributes 22 "host rewrote system prompt" switches to 675.9K re-billed tokens
    on this install (16.35M input tokens total, 14.34M cached).

    Note this is a client-side choice we cannot remove: DSH interpolates {{model}} into the persona
    (@deepseek-ai/dsh-persona, and system-prompt.personaPrefix in the built-in profile) —
    the same "root cause is on the client side" situation your docs already describe for stable-system
    anchoring.

    Environment: billion-context 0.1.212 (daa082e) · DSH desktop (Electron) · Windows 11 ·
    lane dsh, proxy 127.0.0.1:18791 · DSH native plugin (x-bili-plugin: dsh).

    Also worth noting: #1680 anchored the head block in plugin mode on the Responses wire.
    This DSH lane does not go over the Responses wire — the log shows it forwarding to a
    …/v1/chat/completions endpoint — so #1669/#1680 does not appear to cover it. (I could not pin the
    exact wire from the logs alone; the [plugin] lines carry no wire= marker here. If you can tell me
    which wire x-bili-plugin: dsh resolves to, I can re-check whether a plugin-mode anchor path exists
    for it.)

  5. ranxianglei commented on Nov 9, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

    [bot] 🏷 Thanks — well-evidenced, useful data. Two housekeeping notes up front: (1) you're posting from an external (non-platform-trust-list) account, so I'm treating this strictly as reference information, not a decision — the scope/design call rests with @ranxianglei; (2) it prompted me to re-check something I missed in my first pass, so let me correct the record.

    Correction — there IS prior work, and it's wire-scoped

    Since my last reply I pulled the repo branches and found in-flight work #1669/#1680 (commit a4c9adb1bd, branches 2026-09-29_plugin-responses-anchor / review-1680) that already anchors the Responses-wire head block in plugin mode — it removes !pluginMode from that one gate. It is not on the master I triaged against (v0.1.186), so my earlier "all four gates identical, no prior work" was incomplete; correcting it now. Its stated rationale is explicitly wire-local:

    "the kernel hoists developer items from ANY position into systemParts, so even a host that merely APPENDS a notification to its history tail makes the head merge rewrite outbound input[0] every turn … Other wires have no equivalent defect (openai hoists the leading run only; anthropic/google use top-level system), so their plain-proxy scope stands."

    That is the crux for your case: #1680 fixes a bili-caused head rewrite (the Responses kernel hoist). Your DSH case is a client-caused head change (DSH interpolates {{model}} into L3). Different producer, different fix locus. So:

    Your wire question

    In my tree (0.1.186) DSH's model traffic rides the anthropic wire — src/agent/dsh-native.ts stamps x-bili-plugin: dsh (:1887, :2534) and drives anthropic body handling (fetchManifest(base,"anthropic") :988; "anthropic wire only" :2625). You saw /v1/chat/completions on 0.1.212 — a newer build than mine — so it may be a newer routing path or a provider endpoint; I can't pin it from 0.1.186. Either way it's a chat/anthropic wire, not Responses, so #1680 does not cover it — consistent with what you observed.

    The honest catch on DSH (why I'd not blanket-add it)

    In DSH the only volatile head line is the model name, and that line changes iff the model switches. So the head change is inseparable from a model switch. Whether the anchor helps therefore hinges on one thing: do the flipped models share an upstream prefix-cache namespace?

    • Same backend/pool (label-only change): freezing the old head lets the post-flip request hit the prior prefix → the anchor fully fixes the 99%→low drops.
    • Cross-provider (your Claude↔DeepSeek labels look like distinct backends): a different model is a cold cache by definition — the new model can't read the old model's cache entries, so freezing the head buys nothing; the diff note becomes pure overhead and the frozen head asserts a stale model name (the note corrects it, so not misleading, just useless).

    Your partial post-flip hits (67% / 29% / 13%) are the interesting tell: a true cross-backend cold start would sit near 0% on the flip request, so partial recovery hints same-pool reuse may be happening — but the cross-provider labels hint otherwise. One datum settles it: after an A→B flip, does the next B request climb back to ~99% (B warming normally), and decisively — do the two flipped models route to the same upstream cache pool? If yes → add dsh; if no → the real fix stays host-side (keep the persona/model line out of the head, carry it in a tail or user message), exactly as #2333 concluded for OMP.

    Refined recommendation (same shape, tighter scope)

    1. First allowlist entry = {pi} — a content/instruction edit (AGENTS.md) is a genuine localized change that benefits regardless of any model coupling. Unconditional win.
    2. dsh = conditional — hold until the cache-namespace question above is answered (the same evidence-per-client discipline plugin 模式动态 developer 通知被 hoist 合并进头部块,出站前缀自 input[0] 断裂(#1638 本地复现) #1669 applied).
    3. Responses wire = defer to fix: anchor Responses-wire head block in plugin mode (#1669) #1680 (coordinate, don't double-handle).
    4. Reuse stableSystemAnchor (no new field); default stays OFF.

    Still waiting on @ranxianglei to confirm: (a) allowlist {pi} vs {pi,dsh}, (b) reuse-knob vs new field, (c) go-ahead to touch the three non-Responses gates + docs + tests while coordinating with #1680. Nothing above is an owner decision — happy to fold the DSH datum into the analysis if the cache-namespace question gets answered.


    结构化八问(供 reviewer)

    1. 是什么问题:插件模式宿主(Pi/DSH)会话中途改写头部 system 时,因四处门槛的 !pluginMode 被排除在 stableSystemAnchor 之外,头部字节变化导致整段前缀缓存重付。
    2. 什么原因:[Feature] Optimize the cache by reorganizing the context. #1085 保守地把锚定限定为纯代理专用;plugin 模式动态 developer 通知被 hoist 合并进头部块,出站前缀自 input[0] 断裂(#1638 本地复现) #1669 已按「wire 局部缺陷」把 Responses 线扩到双模式,但 chat/anthropic/google 线的客户端主动改写场景仍未覆盖。
    3. 影响范围/严重度:仅限有此诉求且显式开启的插件宿主;成本瑕疵(多付前缀 token),非功能不可用。DSH 的收益取决于翻转模型是否共享上游缓存命名空间——跨后端则收益为零。
    4. 怎么修:复用既有锚定机制 + 按宿主白名单放行非 Responses 线的插件请求;载体沿用尾部 diff note;与 fix: anchor Responses-wire head block in plugin mode (#1669) #1680(Responses 线)协调不重复。
    5. 回归:最坏情况=今天行为,严格更优或等价;不动 plain-proxy 语义、不动内核、不动 update。
    6. 破坏缓存:目标即减少失效;退化路径只发生一次预期 miss。跨模型切换本身按命名空间冷启动,锚定不改变这一点。
    7. 设计方向:不变——仍是「代理侧 wire 层尽力兜底、根因在客户端」;只是把适用面从纯代理扩到白名单插件宿主,并与 fix: anchor Responses-wire head block in plugin mode (#1669) #1680 的 wire 级划分对齐。
    8. 新配置:无新增字段(复用现有布尔);默认值不变(false)。

    判定:方向成立、方案内聚;本轮新增两个关键事实——① #1680 已在途覆盖 Responses 线(修正我上轮"无前置工作"的说法);② DSH 收益是条件性的(取决于翻转模型是否同缓存池)。等 @ranxianglei 确认范围后即可开工。

  6. pengkaicheng commented on Nov 9, 2026

    @pengkaicheng

    Follow-up: the two data points you asked for (same DSH box).

    Short answer to "after an A→B flip, does the next B request climb back to ~99%?": yes, immediately.

    I parsed 53,500 lines of bili log (current + rotated), pairing every [fold-reconcile] system prompt changed event with the same session's [acp-usage] samples, and using [window-change] within 3 s of the event to separate a real model change from a head rewrite without one. 161 events:

    • 147 events have no model change at all, and they cost nothing — 96–100% hit before and after. These are two large oscillators (Δ = ±8033 and Δ = ±12426 chars) where a host flips between two prompt shapes while the model stays put; each shape apparently keeps its own warm prefix. This is also why my first report over-attributed the damage to fold-reconcile churn: the churn is real but almost all of it is free.
    • 14 events coincide with a model change. Hit rate by position after the change:
    request after flip median n <70%
    #1 13% 13 10
    #2 99% 12 3
    #3 98% 11 3
    #4 99% 11 1

    So a flip costs exactly one full prefix re-pay, then it is back to normal. Not a persistent cold start.

    On "the head change is inseparable from a model switch" — your read is right for DSH, and I can name the line. Filtering to |Δ| ≤ 20 chars (too small to be anything but a name-length difference) gives 7 events, all Δ = +3/+4/−3/−7:

    14:28:01 d9e8e741  12466->12470 (+4)  before 99%  ->  3%  100%   2%  99%
    14:35:09 5b869d66  12477->12470 (-7)  before  0%  ->  98%  100%  98%  99%
    14:38:30 d9e8e741  12470->12473 (+3)  before 99%  ->   3%  100%   2%  99%
    15:51:46 5503c02d  12473->12470 (-3)  before 99%  ->  13%   99% 100%  99%
    15:53:20 3727980a  11280->11277 (-3)  before 97%  ->  67%   96%  98%  99%
    16:08:04 aff24c3d  11280->11277 (-3)  before 92%  ->  29%   17%   -    -
    17:51:20 af708b01  12466->12470 (+4)  before 100% ->  36%   95%  99%  99%
    

    That is the {{model}} interpolation on L3 and nothing else, exactly as reconstructed in my first post.

    On the cache-namespace question (the one that actually decides it) — partial, and it leans your way. In this log the same underlying family shows up under four ids: deepseek-v4.1-flash, cn:deepseek-v4.1-flash, DeepSeek-V4.1-Flash-1017, deepseek-v4.1-flash-1. One flip between two of them cost nothing:

    15:51:49 0431772f  DeepSeek-V4.1-Flash-1017 -> deepseek-v4.1-flash   before 92%  ->  100%  99%  100%  100%
    

    A 100% hit on the first request after the label changed is strong evidence that the new label's prefix was already cached — i.e. these labels share a cache namespace, and a frozen head would have been readable. The same-family flips that did cost (13% / 67% / 29%) are consistent with the complement: those exact new head bytes had not been seen before. So the split I see is not "same backend vs different backend" but "were these exact head bytes already in cache" — which is precisely the condition a frozen head guarantees.

    If you want it settled rather than argued, I can drive one deliberately: pin a session to one model, flip once, and compare the #1 hit rate with and without the anchor. That needs the gate open, so it stays your call.

    Since your bot flagged it: I'm not on the platform trust list, so treat all of the above as reference data, not a decision — same as the first post.

  7. ranxianglei commented on Nov 9, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

    [bot] 🏷 Status update — the full assessment is the comment directly above this one; this is just the outcome and where things stand.

    What I did: verified the DSH evidence against the code, and — importantly — found prior work I'd missed in my first pass. #1669/#1680 (a4c9adb1bd, branches 2026-09-29_plugin-responses-anchor / review-1680) already anchors the Responses-wire head block in plugin mode; it is not on master v0.1.186. That PR is defect-scoped (the Responses kernel hoist rewrites outbound input[0] every turn). Your DSH case is client-caused on a chat/anthropic wire, so it sits in #2385's remaining scope, not #1680's — complementary, not a duplicate.

    Outcome / where it stands:

    • Wire question answered: DSH rides the anthropic wire in my tree (dsh-native.ts:988/:2625) → not covered by fix: anchor Responses-wire head block in plugin mode (#1669) #1680, consistent with your /v1/chat/completions log.
    • DSH benefit is conditional: its only volatile head line is the model name, which changes iff the model switches. If the flipped models share an upstream cache pool → the anchor fully fixes the 99%→low drops; if cross-provider (Claude↔DeepSeek, distinct backends) → cold start anyway, the anchor buys nothing (and the diff note becomes overhead). One datum settles it: do the two flipped models route to the same upstream cache pool?
    • Recommendation (shape unchanged): first allowlist entry {pi} (a genuine localized content edit — unconditional win); dsh conditional pending that datum; Responses wire deferred to fix: anchor Responses-wire head block in plugin mode (#1669) #1680; reuse the existing stableSystemAnchor knob, default stays OFF.

    Next step — gated on @ranxianglei. Implementation waits on three confirmations: (a) allowlist {pi} vs {pi,dsh}, (b) reuse-knob vs a new field, (c) go-ahead to touch the three non-Responses gates + docs + tests while coordinating with #1680. Feature-triage (discuss-before-implement) and §7.4 (wire shape in both modes + config semantics = must-stay-human) both require your sign-off. No code has been changed yet. Happy to fold the DSH cache-namespace answer into the analysis as soon as it's known.


    结构化八问(当前状态,供 reviewer)

    1. 是什么问题:插件宿主(Pi/DSH)会话中途改写头部 system 时,因四处门槛的 !pluginMode 被排除在 stableSystemAnchor 之外 → 头部字节变化导致整段前缀缓存重付。
    2. 什么原因:[Feature] Optimize the cache by reorganizing the context. #1085 保守地把锚定限定为纯代理专用;fix: anchor Responses-wire head block in plugin mode (#1669) #1680 已按「wire 局部缺陷」扩到 Responses 线双模式,但 chat/anthropic/google 线的客户端主动改写场景仍未覆盖。
    3. 影响范围/严重度:仅限显式开启该开关的插件宿主;成本瑕疵(多付前缀 token),非功能不可用。DSH 的收益是条件性的——取决于翻转模型是否共享上游缓存命名空间,跨后端则收益为零。
    4. 怎么修:复用既有锚定机制 + 按宿主白名单放行非 Responses 线的插件请求;载体沿用尾部 diff note;与 fix: anchor Responses-wire head block in plugin mode (#1669) #1680(Responses 线)协调、不重复处理。
    5. 回归:最坏情况=今天行为,严格更优或等价;不动 plain-proxy 语义、不动内核、不动 update。
    6. 破坏缓存:目标即减少失效;退化路径只发生一次预期 miss。跨模型切换本身按命名空间冷启动,锚定不改变这一点。
    7. 设计方向:不变——仍是「代理侧 wire 层尽力兜底、根因在客户端」;只是把适用面从纯代理扩到白名单插件宿主,并与 fix: anchor Responses-wire head block in plugin mode (#1669) #1680 的 wire 级划分对齐。
    8. 新配置:无新增字段(复用现有布尔);默认值不变(false)。

    判定:分析与方案内聚完成,等 @ranxianglei 确认范围后即可开工;本轮未改动任何代码。

  8. ranxianglei commented on Nov 9, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

    [bot] 🏷 Much sharper dataset — thanks. It changes the framing of the DSH question, so let me update my read. (Still reference data, not a decision — @ranxianglei decides.)

    The key reframe your numbers support: the cost is not "a head change busts the cache." It is "the first appearance of a given head byte-sequence costs one full prefix re-pay; once seen, that sequence stays warm." Your 147 zero-cost events (model-stable shape oscillators, Δ = ±8033 / ±12426) confirm the cache holds several head prefixes at once — so flipping between two already-seen shapes is free. Your "exactly one re-pay, then 99%" on model changes is the same rule at the model level.

    That reframing is precisely what a frozen anchor exploits: hold the head bytes constant → there is only ever one head sequence to cache → the repeated one-time re-pays disappear.

    Where I'd sharpen the conclusion (honesty pass):

    1. Genuine cross-provider switch = zero anchor benefit. When the underlying model/backend actually changes (Claude↔DeepSeek), the new model owns its own cache namespace — the whole conversation re-processes regardless of head bytes, and the anchor can't reach another model's cache. So the anchor's DSH value is confined to same-underlying-model label churn — your deepseek-v4.1-flash ↔ DeepSeek-V4.1-Flash-1017 family, whose 100%-hit first request confirms a shared namespace.
    2. Your 2-shape oscillators are already free today. The anchor is roughly neutral for them, plus one small recurring cost: the anchor caps its diff-note list at 8, and past that the churn guard replaces the head outright (one deliberate re-pay) to reset. So a session cycling through many distinct labels gets the big win; one ping-ponging two already-warm shapes gains little and pays a periodic churn-guard re-pay every ~8 diffs.
    3. Stale model identity in the frozen head. Once anchored, L3 keeps asserting the first model forever; every later switch rides the tail diff note. Functionally fine (the model follows the note), but it is a real semantic wrinkle worth naming, not burying.

    Net: including dsh is now well-supported — its dominant recurring cost mode (distinct-label head churn within a shared namespace) is exactly what the anchor removes, and worst case ≈ today. I'd seat it beside {pi} as a legitimate second entry; the initial scope is the owner's call:

    • {pi} = most conservative (the original ask; content/instruction edits — unconditional win).
    • {pi, dsh} = additionally captures the now-evidenced model-label churn.

    On your A/B offer: pin a session, flip once, compare the #1 hit-rate with/without the anchor — that is exactly the right definitive test. It needs the gate open, i.e. owner sign-off on implementation first, so it belongs in the acceptance criteria, not as a pre-step. I'm not treating it as agreed; it's a sound idea contingent on the go-ahead.

    Still gated on @ranxianglei: (a) allowlist {pi} vs {pi,dsh}, (b) reuse-knob vs a new field, (c) go-ahead for the three non-Responses gates + docs + tests, coordinating with #1680. No code changed yet.


    结构化八问(当前状态,供 reviewer)

    1. 是什么问题:插件宿主(Pi/DSH)会话中途改写头部 system 时被 !pluginMode 排除在 stableSystemAnchor 之外;DSH 头部唯一易变行是模型名({{model}} 插值于 L3)。
    2. 什么原因:成本本质不是「头部一变就整体失效」,而是「某头部字节序列首次出现时付一次整段前缀重算,见过即常驻缓存」。[Feature] Optimize the cache by reorganizing the context. #1085 把锚定限定为纯代理专用;fix: anchor Responses-wire head block in plugin mode (#1669) #1680 已按 wire 局部缺陷扩到 Responses 线双模式;chat/anthropic/google 线的客户端主动改写仍未覆盖。
    3. 影响范围/严重度:仅显式开启该开关的插件宿主。DSH 的收益集中在「同底层模型、多标签名」的头部抖动;真实跨后端切换收益为零(本就一次重算,与锚定无关);两形状振荡今天已免费,锚定对其近似中性并附带每约 8 次 diff 一次的 churn-guard 重付。
    4. 怎么修:复用既有锚定机制 + 按宿主白名单放行非 Responses 线的插件请求;载体沿用尾部 diff note;冻结头部使字节序列恒定,从而消除重复的一次性重付;与 fix: anchor Responses-wire head block in plugin mode (#1669) #1680(Responses 线)协调不重复。
    5. 回归:最坏情况≈今天行为;不动 plain-proxy 语义、不动内核、不动 update。唯一新增代价是有界的 churn-guard 周期性重付。
    6. 破坏缓存:目标即减少失效;退化路径只发生一次预期 miss;跨后端冷启动不受锚定影响。
    7. 设计方向:不变——仍是「代理侧 wire 层兜底、根因在客户端」;适用面从纯代理扩到白名单插件宿主,并与 fix: anchor Responses-wire head block in plugin mode (#1669) #1680 的 wire 级划分对齐。
    8. 新配置:无新增字段(复用现有布尔);默认值不变(false)。

    判定:本轮数据把 DSH 从「条件性」推进到「有据可依的第二白名单项」;初始范围({pi} vs {pi,dsh})仍待 @ranxianglei 拍板,之后即可开工。本轮未改动任何代码。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestp3pi协议接线改动范围:内核之外的主机侧接线(src/agent 适配器、server 路由、注入拦截)/范围兜底/客户端标签

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions