Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
73a34ba
fix: strip refs-only residue adjacent to render tags in the echo filt…
Oct 4, 2026
27ba88a
fix: classify released refs-run tails as prose in degenerate-turn acc…
Oct 4, 2026
61957c5
fix: drop model-emitted ACP tool-call emissions from the prose channel
yukhymenko-yurii Oct 4, 2026
5d1e688
fix: keep signed thinking/thought byte-for-byte across non-streaming …
Oct 4, 2026
cb40206
fix(#2190): strip model-emitted degenerate-close echo residue
Oct 5, 2026
dbf4f1b
fix: degenCloseAfterRef off standalone SINGLE_REF_BODY const (#2229 s…
Oct 6, 2026
10b978b
fix(#2190): extend acplike name set with field-attested drift names; …
Oct 6, 2026
83fb43f
chore: untrack .tmp scratch swept into branch by #2229 compat commit;…
Oct 6, 2026
7977aeb
fix(#2248): extend raw-forward exit audit to anthropic/google/respons…
Oct 6, 2026
46dc831
fix(#2190): drop acpx from attested drift names after evidence decont…
Oct 6, 2026
f5e9eb4
test(#2190): pin H2-exclusion invariant — touching a well-formed pair…
Oct 6, 2026
e4e0f96
test(#2190): pin field replay seq=22409 — degenerate close </ak> stri…
Oct 6, 2026
58b064e
merge: PR #2025 (tag-echo refs-run generalization, #2023)
Oct 6, 2026
3a029f0
merge: PR #2211 (degen-close strip + egress audit net, #2190/#2248)
Oct 6, 2026
9ebe2e2
merge: PR #2067 (emission drop + signed-thinking verbatim, #2066)
Oct 6, 2026
0e8fd36
fix: absorb-emission tests to unified createTagEchoFilter(onDrop, onR…
Oct 6, 2026
d10fc01
unify ACP tag-echo remediation under four invariants (#2023 #2066 #21…
Oct 6, 2026
b291d44
fix: #1039 responses pin flipped to unified invariant (reasoning summ…
Oct 6, 2026
000dfe8
fix: clear tcHold buffer before processing so a stashed partial tail …
Oct 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ dist/
.bili-coop-build-stamp
tmp/
tests/.pp-stamp-state-*/
.tmp/
6 changes: 6 additions & 0 deletions CLIENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ two small node scripts that do the work around the client:
against the live proxy manifest, the routed entries gain
`headers["x-bili-plugin"] = "zcode"` — until then traffic rides wire mode.
Tool calls bind via the per-call `conversation_id` argument (#760).
- **What gets cleaned vs. never touched (unified ACP invariants):** model
prose may have bili render-tag echoes / marker lines / degenerate residue
stripped in transit; the **thinking channel** (anthropic `thinking`, google
`thought`, openai `reasoning_content`/`reasoning`, responses reasoning
summaries), **tool-call arguments** (model-written file content) and
**user messages** are byte-for-byte untouched.
- **Routing scope (#1622):** native mode wraps **every** provider entry with
a usable http(s) `baseURL` — the same "all providers ride compression"
semantics as the in-process natives (pi/dsh) — not just the bigmodel
Expand Down
1 change: 1 addition & 0 deletions CLIENTS.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ fork 继承同一面;Antigravity 自带用户插件系统 —— `plugins/<name>
- **卸载后的已开会话(#2155):**`bili plugin remove zcode` 无法触及已开着的客户端窗口 —— 它们的 MCP 子进程已死,但代理侧的会话绑定(session metadata)仍在。这类僵尸会话在连续 5 轮“有 nudge、无插件头、线上无 bili 工具、零压缩”后被检测到,随即**自愈降级为代理模式** —— ACP 工具改由代理线上回注、压缩重新由代理接管(nudge 保留)。若线上注入不可用(`compress.injectTool=false`)则改为静默 nudge,直到出现一次压缩缩减自动解除。插件头重现(客户端重启/重装)即在同一请求内恢复 plugin 模式。remove 命令在近 10 分钟内见过活跃会话时会打印提示;web UI 会为这类会话挂“自愈”徽标。
- **每会话自举:** 每个 ZCode 会话把 MCP 子进程作为直接子进程拉起;启动时附着到健康代理(`BILLION_CONTEXT_PROXY`)或在临时端口自拉起,然后在 mkdir 锁文件下对生效的 provider store 做幂等 JSON 手术:每个可路由 provider 条目的 `baseURL` 变为 `http://127.0.0.1:<port>/bili/<上游>`(你设的自定义 baseURL 原样保留在包装之内)。两代 store 都处理:legacy `~/.zcode/v2/config.json`(`provider.<id>.options.baseURL`)与 v3.14+ personal store `~/.zcode/v2/provider_config.json`(`config.providerConfigRules.providerRules[].config.api.baseUrl`)—— 两者并存时以新 store 为准(其中哪些条目路由、哪些被跳过见下方路由范围)。原始文件按每次用户编辑快照到 `<file>.bili-bak`(快照永远反映你最后一次真实状态,绝不记录 bili 自己的写入);其余所有键逐字节保留。旧世代客户端在启动时加载 provider 配置 —— 安装后重启一次 ZCode;新版构建可在会话中途感知路由变化(约 1 s 轮询)。`SessionStart` hook 机会性地跑同一套自举(仅附着 —— 绝不 spawn);它的非阻塞竞态被设计为可容忍:第一轮可以走 wire 模式,不变量是 `baseURL` 永不指向死端口。
- **Plugin 模式盖章:** MCP 子进程对着存活代理清单核验 ACP 工具列表之后,才给路由条目加 `headers["x-bili-plugin"] = "zcode"` —— 此前流量走 wire 模式。工具调用经每次调用的 `conversation_id` 参数绑定(#760)。
- **清洗什么、绝不动什么(统一 ACP 不变量):** 模型正文中 bili 渲染标签回声 / marker 行 / 退化残骸可在传输中被剥离;**思考通道**(anthropic `thinking`、google `thought`、openai `reasoning_content`/`reasoning`、responses reasoning summaries)、**工具调用参数**(模型写往文件的内容)与**用户消息**逐字节原样透传。
- **路由范围(#1622):** 原生模式包装**每一个**有可用 http(s) `baseURL` 的 provider 条目 —— 与进程内原生(pi/dsh)的「所有 provider 都吃压缩」语义一致 —— 而不是只包 bigmodel coding-plan 账号。无法安全包装的条目会被跳过并记录原因,而非静默丢弃:
- **客户端签名账号(#1621):** v3.14+ personal store 上的 coding-plan 账号保持直连(见已知局限);其余 provider 照常路由。
- **环回目标(#809):** http 环回 `baseURL`(localhost / 127.x.x.x / ::1)永不二次代理 —— 包装它会把 bili 叠在自己或你自己的本地中继上。
Expand Down
33 changes: 33 additions & 0 deletions TECHNICAL-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,36 @@ transition logs one `[self-heal]` line (detect + recovery). `bili plugin
remove <client>` best-effort queries the live proxy (instance file →
`GET /__bili/sessions`, 2.5 s timeout, silent on failure) and prints a note
when sessions of that client were active within the last **10 minutes**.

## Unified ACP tag-echo remediation — the four invariants (#2023/#2066/#2190/#2248)

One PR folds the three remediation legs together (refs-run residue #2023,
degenerate-close stripping + egress audit net #2190, emission drop +
signed-thinking verbatim #2066) under a single set of hard rules that govern
EVERY text-rewriting surface (loop adapters, plugin passthrough, JSON strip
functions, exit audits):

1. **The thinking channel is byte-verbatim.** Anthropic `thinking`, Google
`thought`, OpenAI `reasoning_content`/`reasoning`, and Responses reasoning
summaries ride as-is — echo-shaped reasoning included. Rationale: reasoning
replay (DeepSeek-style) and signature verification validate these bytes;
any rewrite desyncs them and bricks the session (#1960/KDD#10). The
adapters route these fields through `createIdentityStreamFilter`, and the
strip functions (`stripOpenaiChatText`, `stripResponsesText`) leave them
untouched (defense in depth). NOTE: this REVERSES the pre-#1881-era
reasoning-echo strip — the thinking channel is no longer cleaned.
2. **Model prose is manageable.** Render-tag echoes, marker lines,
bili-internal text, degenerate open/close residue, and (when
absorb-instructed) whole tool-call emissions are stripped from the visible
text channel only.
3. **Model output bound for files is byte-identical (#1039).** Tool-call
arguments never enter any filter, whatever bytes they carry.
4. **User-sent bytes are never rewritten.** A verbatim echo of the user's own
fragment survives even when stripping is armed (#463 exemption, keyed on
the request text, not shape).

The egress audit net (#2248) stays log-only: raw exits (unrecognized frames,
parse failures) forward as-is and log `[tag-echo] raw exit` so new leak shapes
become visible without changing the wire. Pinned by
`tests/unified-acp-invariants.test.ts` (eight tests, both lanes).

12 changes: 12 additions & 0 deletions TECHNICAL-NOTES.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,15 @@ bili 永不拥有用户数据:每个被启动的客户端都跑在**真实 home*
- **D3 网关杀摘要** —— **非流式** preflight 摘要以 HTTP 524/504(Cloudflare 类)死亡时不再原地重试(旧的 transient 重试对着死网关每次烧 ~100 秒);会话在**首次**命中即学习 `metadata.preflightStreamSummary = true` 并改用 SSE 重取摘要 —— 与手动 `compress.streamSummary` 旋钮(#2133)同一学习存储,自动武装。级联双向被尊重:任一级显式 `streamSummary: false`(global → provider → model)即操作员 opt-out —— 两条学习路径都不武装、已学习的旧标志被忽略(`PreflightDeps.streamSummaryOff`)。

可观测:`session.metadata.selfHeal = { detected, action, since }` 进 `/__bili/sessions`、web UI 挂"自愈"徽标、每次转换一行 `[self-heal]` 日志(检测+恢复)。`bili plugin remove <client>` 尽力查询活代理(instance 文件 → `GET /__bili/sessions`,2.5 秒超时,失败静默),该客户端近 **10 分钟**内有活跃会话时打印提示。

## ACP 标签回声统一整治 —— 四条不变量(#2023/#2066/#2190/#2248)

一个 PR 把三条整治腿合并(refs-run 残留 #2023、退化闭名剥离+出口审计网 #2190、emission 整段丢弃+签名思考 verbatim #2066),并统一受四条硬规则约束 —— 覆盖**所有**文本改写面(loop 适配器、插件直通、JSON strip 函数、出口审计):

1. **思考通道逐字节不动。** Anthropic `thinking`、Google `thought`、OpenAI `reasoning_content`/`reasoning`、Responses reasoning summaries 原样透传 —— 哪怕长得像标签回声。理由:reasoning 回放(DeepSeek 式)与签名校验验证的就是这些字节,任何改写都会让它们失步并卡死会话(#1960/KDD#10)。适配器侧走 `createIdentityStreamFilter`,strip 函数(`stripOpenaiChatText`、`stripResponsesText`)同样不动它们(纵深防御)。**注意:这翻转了 #1881 时代的 reasoning 回声剥离 —— 思考通道不再清洗。**
2. **模型的正文输出可以治理。** 渲染标签回声、marker 行、bili 内部文本、退化开/闭名残骸,以及(absorb 受指令时)整段工具调用 emission,只在可见文本通道剥离。
3. **模型写入文件的内容逐字节不变(#1039)。** 工具调用 arguments 无论携带什么字节都不进任何过滤器。
4. **用户发送的消息永不被改写。** 用户自己片段的逐字回声在武装清洗下也保留(#463 豁免,按请求文本匹配,不按形状)。

出口审计网(#2248)保持仅记日志:裸出口(未识别帧、解析失败)原样转发并打 `[tag-echo] raw exit` 日志,新泄漏形状可见而不改线上行为。由 `tests/unified-acp-invariants.test.ts` 钉住(8 个测试,两条 lane)。

13 changes: 11 additions & 2 deletions src/loop/adapter-anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function buildTextDeltaEvent(index: number, text: string): Buffer {
);
}

export function createAnthropicAdapter(requestBody: Record<string, unknown>, originalSystem?: AnthropicRequestBody["system"], notes?: string[], errorShape: "protocol" | "completion" = "protocol", cacheMarks?: Map<string, { type: "ephemeral" }>): CompressLoopAdapter {
export function createAnthropicAdapter(requestBody: Record<string, unknown>, originalSystem?: AnthropicRequestBody["system"], notes?: string[], errorShape: "protocol" | "completion" = "protocol", cacheMarks?: Map<string, { type: "ephemeral" }>, absorbArmed?: boolean): CompressLoopAdapter {
const model = (requestBody.model as string) ?? undefined;
let messageId: string | undefined;
let clientIndex = 0;
Expand Down Expand Up @@ -284,11 +284,20 @@ export function createAnthropicAdapter(requestBody: Record<string, unknown>, ori
// per prose field — text and thinking deltas interleave across one
// stream, so a shared instance would hold a tag-shaped tail against
// the wrong field's bytes.
// m00885: whole-field absorb-emission drop is armed only when this
// request instructed the model about absorb (server-side provenance).
const absorbArmedLocal = absorbArmed === true;
// m00885: the shipped request text lets the filter keep an
// emission-shaped span the user asked to be output verbatim.
const requestText = JSON.stringify(requestBody);
const makeFilter = () => composeStreamFilters(
composeStreamFilters(
createTagEchoFilter((snippet) => {
loggerLog("warn", `[tag-echo] stripped model-emitted render tag: ${snippet.slice(0, 80).replace(/\n/g, " ")}`);
}),
}, (snippet) => {
// #2190: residue audit — log-only, see plugin.ts twins.
loggerLog("warn", `[tag-echo] filter released echo-residue-shaped bytes (#2190): ${snippet.slice(0, 80).replace(/\n/g, " ")}`);
}, absorbArmedLocal, requestText),
createMarkerLineFilter((snippet) => {
loggerLog("warn", `[marker-echo] stripped model-emitted ACP confirmation marker: ${snippet.slice(0, 80).replace(/\n/g, " ")}`);
}),
Expand Down
13 changes: 12 additions & 1 deletion src/loop/adapter-google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,22 @@ export function createGoogleAdapter(
// text from signature and bricks the session. Thought echoes are
// forwarded verbatim; cosmetic leaks inside a thought pane are
// accepted (#1960 verdict).
// m00885: whole-field absorb-emission drop is armed only when this
// request instructed the model about absorb (server-side provenance
// — the absorb section exists on this request's wire iff absorbName
// was resolved for it).
const absorbArmedLocal = absorbName !== undefined;
// m00885: the shipped request text lets the filter keep an
// emission-shaped span the user asked to be output verbatim.
const requestText = JSON.stringify(requestBody);
const makeFilter = () => composeStreamFilters(
composeStreamFilters(
createTagEchoFilter((snippet) => {
loggerLog("warn", `[tag-echo] stripped model-emitted render tag: ${snippet.slice(0, 80).replace(/\n/g, " ")}`);
}),
}, (snippet) => {
// #2190: residue audit — log-only, see plugin.ts twins.
loggerLog("warn", `[tag-echo] filter released echo-residue-shaped bytes (#2190): ${snippet.slice(0, 80).replace(/\n/g, " ")}`);
}, absorbArmedLocal, requestText),
createMarkerLineFilter((snippet) => {
loggerLog("warn", `[marker-echo] stripped model-emitted ACP confirmation marker: ${snippet.slice(0, 80).replace(/\n/g, " ")}`);
}),
Expand Down
20 changes: 17 additions & 3 deletions src/loop/adapter-openai.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { CoreMessage } from "acp-kernel";
import { coreToOpenai, injectOpenaiSystem } from "acp-kernel/wire";
import { buildVisibilityMarker } from "./core.js";
import { composeStreamFilters, createBiliArtifactFilter, createMarkerLineFilter, createTagEchoFilter } from "./tag-echo-filter.js";
import { composeStreamFilters, createBiliArtifactFilter, createIdentityStreamFilter, createMarkerLineFilter, createTagEchoFilter } from "./tag-echo-filter.js";
import { degenerateTurnWarning } from "../degenerate-turn.js";
import { log as loggerLog } from "../logger.js";
import { hardenOpenaiAssistantContent, systemToUser } from "../util.js";
Expand Down Expand Up @@ -249,11 +249,25 @@ export function createOpenaiAdapter(requestBody: Record<string, unknown>, client
// shared instance would hold a tag-shaped tail against the wrong
// field's bytes (residue leak or content loss). Tool-call
// arguments never enter any filter (#1039 invariant).
// Unified ACP invariant: the reasoning channel rides an IDENTITY
// filter — thinking is never rewritten (matches signed-thinking
// treatment in the anthropic/google adapters, #1960/KDD#10).
// m00885: whole-field absorb-emission drop is armed only when this
// request instructed the model about absorb (server-side provenance
// — the absorb section exists on this request's wire iff absorbName
// was resolved for it).
const absorbArmedLocal = absorbName !== undefined;
// m00885: the shipped request text lets the filter keep an
// emission-shaped span the user asked to be output verbatim.
const requestText = JSON.stringify(requestBody);
const makeFieldFilter = () => composeStreamFilters(
composeStreamFilters(
createTagEchoFilter((snippet) => {
loggerLog("warn", `[tag-echo] stripped model-emitted render tag: ${snippet.slice(0, 80).replace(/\n/g, " ")}`);
}),
}, (snippet) => {
// #2190: residue audit — log-only, see plugin.ts twins.
loggerLog("warn", `[tag-echo] filter released echo-residue-shaped bytes (#2190): ${snippet.slice(0, 80).replace(/\n/g, " ")}`);
}, absorbArmedLocal, requestText),
createMarkerLineFilter((snippet) => {
loggerLog("warn", `[marker-echo] stripped model-emitted ACP confirmation marker: ${snippet.slice(0, 80).replace(/\n/g, " ")}`);
}),
Expand All @@ -267,7 +281,7 @@ export function createOpenaiAdapter(requestBody: Record<string, unknown>, client
// only turn must still report an empty text channel, not a missing
// one. Thinking/reasoning presence reaches the gate via sawReasoning.
const contentFilter = makeFieldFilter();
const reasoningFilter = makeFieldFilter();
const reasoningFilter = createIdentityStreamFilter();
const flushFilter = function* (): Generator<ParsedStreamEvent> {
const ct = contentFilter.flush();
if (ct.length > 0) yield { kind: "text", delta: ct, raw: buildContent(ct) } as ParsedStreamEvent;
Expand Down
Loading
Loading