Skip to content

ZCode 宿主 usage 回填未压缩基线:压缩后上下文显示成累加值,非实际转发量(v0.1.88 起;#645 的 ZCode 面) #648

Description

@chenshuangci

ZCode 宿主 usage 回填未压缩基线:压缩后上下文显示成累加值,非实际转发量(v0.1.88 起;#645 的 ZCode 面)

现象

ZCode 以普通代理模式接 bili(anthropic 协议,base-url 指向代理,无插件头)。旧版本(≤0.1.80)里,bili 压缩(折叠)发生后,ZCode UI 的上下文用量会立刻降为实际上下文;某个版本后变成了"累加值"——显示的是未压缩基线(真实折叠值 + 历次压缩节省的回填),只会持续上涨,不再是模型实际收到的量。

  • 用户无法从 UI 判断真实上下文压力(bili 自己的账本显示 9-11%,UI 显示 ~16%+);
  • 数字还会在没有任何压缩的纯追加轮小幅回落(估算漂移),看起来像坏了;
  • 只有翻 bili.log[acp-usage] input= 才能看到真实值。

版本时间线

#645(Codex 面)完全一致:0.1.70–0.1.80 正常,v0.1.88 的 PR #425(#408 host usage backfill)起出现;0.1.95 实测仍存在(证据见下)。

现场证据(0.1.95,2026-09-08 晚,长会话实时抓取)

2026-09-08T11:35:38.077Z [info] [3c6c…] [acp-usage] round 1 input=90023 cached=89792 (cache hit 100%)
2026-09-08T11:35:38.512Z [info] [3c6c…] host usage backfill armed: +63812 tok (forwarded view is folded); host usage will report the uncompressed baseline
2026-09-08T11:45:41.745Z [info] [3c6c…] [acp-usage] round 1 input=101592 cached=99712 (cache hit 98%)
2026-09-08T11:45:44.510Z [info] [3c6c…] host usage backfill armed: +63761 tok (forwarded view is folded); host usage will report the uncompressed baseline

根因(0.1.95 dist/index.js:59340-59347)

function armHostUsageCredit(session, originalMessages, processedMessages, log2) {
  session.hostCreditTokens = 0;
  if (session.metadata.pluginAgent === "pi" || session.metadata.pluginAgent === "omp") return;
  session.hostCreditTokens = ... Math.max(0, estimateCoreMessages(originalMessages) - estimateCoreMessages(processedMessages)) ...;
  // log: host usage backfill armed: +N tok ... host usage will report the uncompressed baseline
}

豁免集目前只有 pluginAgent === "pi"(#591)与 "omp"(#623);#645 在飞的修复按 Codex User-Agent 豁免。ZCode 走普通代理(base-url 直指),pluginAgent 为空、UA 也不是 Codex → 三个豁免都吃不到,hostCreditTokens = est(原始全量) − est(折叠视图) 全额累加进回报宿主的 usage。

与现有 issue 的关系

同一机制的宿主面第四例:#408/#425(起源)→ #590/#591(pi 豁免)→ #623(omp)→ #645(Codex,UA 豁免在飞)→ 本票(ZCode/普通 anthropic 代理客户端)#645 里已论证"回填值是虚数且有漂移,宿主显示 used/window 只有 used=模型实收才自洽"——对 ZCode 同样成立,不重复展开。

修复方向建议

ZCode 与 pi 的论证同构:压缩调度主要由 bili 的 nudge/preflight 负责(读折叠口径),宿主侧的未压缩基线对 ZCode 的价值存疑。两个方向任一均可:

  1. 豁免扩展:普通代理模式提供配置开关(如 hostUsageCredit: "auto"|"off",auto=仅对已知需要未压缩口径的宿主武装),让普通 anthropic 代理客户端默认回报实收值;
  2. UA 识别:若 [Question] Previously, Codex displayed the context window size after compression, but it now appears to show an unexpected/incorrect value. #645 的 Codex UA 豁免落地,把豁免机制做成可扩展宿主集(ZCode 有稳定 UA 的话可加入;普通代理模式下 UA 可能不可靠,建议以配置开关为主)。

若最终裁决 ZCode 需要保留回填(驱动其原生压缩),也请在文档/面板明确「UI 数字=未压缩基线」,并在 /acp 面板或响应头暴露实收值,避免只能翻日志。

验收

Activity

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

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions