Repository navigation
[PR] fix: strip ACP panels and status markers on the google lane before projection (#2798) - #2805
ranxianglei wants to merge 7 commits into
Conversation
…ojection (#2798) prepare-google.ts imported stripAcpPanelMessages/stripAcpStatusMarkers but never called them, so ACP panel user messages (#359) and ephemeral [ACP] status marker lines (#717/#1029, incl. multi-line acp_status reports #2789/#2797) rode unstripped into the compression state on every /v1beta turn and were billed/replayed forever while the openai/anthropic/responses lanes stripped them. The existing strippers only understand {role, content} arrays — google contents are {role, parts} — so passing parsed.contents would have been a silent no-op. Add parts-aware variants to acp-panel.ts: stripAcpPanelGoogleContents (whole panel user contents removed; any non-text/signatured part makes a content ineligible) and stripAcpStatusMarkersGoogleContents (per-part marker-line stripping that skips thought/thoughtSignature parts per KDD #10). Call both in prepareGoogle and prepareGoogleCountTokens before the chain-carrier strip, with the same log lines as the siblings. Mirror the same two passes in fork-adoption's incomingCoreMessages google branch so adoption id derivation stays in parity with prepareGoogle (maybeAdoptForkBlocks runs pre-prepare on the raw body). Behavior change (old->new): /v1beta generateContent/streamGenerateContent/countTokens previously forwarded and measured ACP panel messages + [ACP] marker lines verbatim; they are now stripped before projection/measurement, matching the other three lanes. No config surface change, no kernel change.
…s preview too (in-passing, #2798) Found while working #2798: prepareCountTokens (/v1/messages/count_tokens) forwarded the raw body to upstream for measurement while prepareAnthropic strips panels (#359) and [ACP] marker lines (#717/#1029) before projection — so the preview measured a payload that is never what the proxy sends. Same mechanism family as the google gap, trivially fixable in passing: run the same two strip passes at the top of the preview, same log lines, still read-only. OpenAI/Responses have no count_tokens endpoint, so this twin completes the set. Also drops the unused stripAcpPanelResponsesInput import from server.ts (vestigial; tsc does not flag it — noUnusedLocals is off). Behavior change (old->new): /v1/messages/count_tokens previously measured panel messages + marker lines verbatim; they are now excluded from the measured payload, matching what /v1/messages forwards.
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.3343-pr.2805.513d976This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2805.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 Reviewing #2805 now. Pulled the branch ( Quick preview of what I verified so far:
No new config/env/CLI surface, no kernel change, no persistence change. Awaiting the last 4 green checks before the formal verdict. |
[bot] 🏷 PR review 结论 — 方向对、代码 sound,但 CI 红:拦下(待一次性 golden 重生成 + PR body 理由) 代码我逐段读过(diff 全量 + 相关既有行为),修复本身正确、定位准、测试有牙。唯一阻塞项不在代码逻辑,而在漏了一次 golden 快照重生成。下面按八问给结论。 1. 是什么问题:Google(Gemini 原生)lane 在投影前从没跑过 ACP panel / status-marker 剥离 —— 2. 什么原因导致:(a) 抽取时共享 import 列表被照搬,google 分支却没接调用;(b) 不是能一行修的原因 —— 那两个 stripper 吃 3. 影响范围与严重程度:所有走 4. 怎么修复的:新增两个 parts-aware 剥离器 5. 回归问题 — 这里有问题(CI 红):
6. 是否破坏缓存:不破坏,反而让出站前缀更稳(去掉代理注入的临时 artifact)。session identity / persistence 不动。 7. 是否改设计方向:不改架构/边界/数据流,只是把 google lane 补齐到与其它三 lane 一致的既有机制(parts-aware 变体)。 8. 是否引入新配置:无新 env/config/CLI。 处置(合并前必办)
修复质量我给好评:root cause 找得准、KDD#10 守卫到位、11 个新单测(含 KDD#10 字节精确性、fork parity、full-server proof)都有牙且在 CI 里全绿。只差这一次 golden 重生成 + 理由说明即可合。 判定:拦下(block) —— 待上述 golden 重生成合入并 CI 转绿后放行。 |
…tentional drift) The golden-google drive runs compress.injectTool+injectNudge, so after the fold at body #9 the proxy injects its ephemeral [ACP] status-marker line into the next request's history (#717/#1029). Pre-fix that line rode into the google lane's projection on every subsequent turn; post-fix prepareGoogle strips it before projection — which is exactly what #2798 changes, now observable in the pin set. Delta is exactly the strip effect and nothing else: outbound bodies #10-#14 each shrink by a constant 268 bytes (the fixed marker content removed from contents); stateDigest/sectionDigests(state,stats,metadata)/stateKeyDigests(messageRefs,tokenSnapshot,lastPassIds) move accordingly; blockContents digest, blocks/nudge/deadRefs/hiddenOrphanRefs/terminalStreak digests, foldAt/editedAt/summaryFrom and stateShape (incl. refs count) are unchanged. The other three wires' goldens regenerate byte-identical (no git diff for chat/anthropic/responses), confirming no cross-lane effect. Regenerated with node --import tsx scripts/update-storage-render-goldens.ts (#2798, Closes via PR #2805).
…k semantics The merged master changed marker stripping from line-granular (stripMarkerLines) to block-granular (stripAcpStatusBlocks): an acp_status head now consumes its wrapped [acp-status]/[/acp-status] body or legacy report grammar, and end-of-part markers no longer leave a trailing newline. The google lane shares stripAcpStatusBlocks verbatim with the siblings (adapted in the merge commit), so this suite now pins the same shapes tests/acp-status-marker-block.test.ts does: wrapped whole-block removal, legacy grammar stop-at-prose, cut-mid-report consume-to-end, plus a signed-part-with-full-block byte-exact case (KDD #10).
|
(ai: zhipuai-lb/glm-5.3) 陈旧票清理(第三批动作①):目标 issue #2798 已关。为避免重复劳动关闭本 PR;如判断有误请直接 reopen 并留言。 |
(ai: vllm-qwen/qwen3.8-27b) 结论:同意关闭,不 reopen。我回到当前 master 核对了代码 —— #2798 已被更新的统一机制修掉,本 PR 的方案被整体取代。 没有直接照单全收「目标 issue 已关」,而是查了当前 master: 1) #2798 的缺口确实已修(用的是另一套机制) 该引擎来自更新的 PR #2815(marker-declarative)(
2) 时间线对得上:本 PR 基于 2026-10-11 的旧 master(那时还没有这个引擎,所以走了「acp-panel.ts 加两个 parts-aware 变体」的老路子);issue #2798 于 2026-10-13 标 completed(对应 #2815 合入);master 此后大幅重构,本 PR 的 diff 现在也套不上去 —— 硬合会引入一条与引擎并行的重复/冲突剥离路径。 所以我上一轮「block、待 golden 重生成」是针对当时基线的评审,现在整个方案已被 #2815 取代,该结论作废。关闭是对的,我不 reopen、不动它。 顺带一个小的观察(不构成重开理由,单独留意即可):master 的 google 判定:维持关闭,不 reopen。 |
Closes #2798
What this fixes
The Google (Gemini native) lane never ran the incoming ACP strip passes:
src/server/prepare-google.ts:23importedstripAcpPanelMessages+stripAcpStatusMarkersbut never called either — not inprepareGoogle, not inprepareGoogleCountTokens. All three sibling lanes strip before projection (prepare-openai.ts:82,86,prepare-anthropic.ts:124,128,prepare-responses.ts:114). Consequence: ACP panel user messages (#359) and ephemeral[ACP]status marker lines (#717/#1029, incl. the multi-line acp_status reports fixed in #2789/#2797) rode unstripped into the compression state on every/v1betaturn — billed and replayed forever.Not a regression from the #1440 extraction (per the issue's provenance): pre-extraction
src/server.tshad exactly the same three call sites; the google branch never called them. The extraction carried over the shared import list, leaving the vestigial import.Why it is not a one-line fix
stripAcpPanelMessages/stripAcpStatusMarkersoperate on{role, content}arrays; google contents are{role, parts}— passingparsed.contentswould be a silent no-op. This PR adds parts-aware variants instead.Changes
Commit 1 — main fix (#2798)
src/acp-panel.ts: two new exported strippers mirroring sibling semantics:stripAcpPanelGoogleContents(contents)— removes whole user-role contents whose plain-text join is an ACP panel (box / fallback / cache-report / rule-report signatures, same as the messages variant). Any non-text or signatured part makes a content ineligible → preserved. Never deletes non-panel contents.stripAcpStatusMarkersGoogleContents(contents)— strips MARKER_LINE lines from text parts ofuser/model/role-less contents. Skipsthought: trueparts and parts carryingthoughtSignature(KDD release v0.1.3 #10: thinking-family blocks are signature-verified and must stay byte-exact — unlike anthropic, where the signature sits on a separate field name, so google needs an explicit guard). Marker-only parts degrade to" "; never deleted.src/server/prepare-google.ts: both passes added toprepareGoogle(before the chain-carrier strip — order panels → markers → carriers matches the openai lane) and toprepareGoogleCountTokens, with the same log lines as the siblings so the lane is observable identically.src/fork-adoption.ts: the same two passes mirrored inincomingCoreMessages's google branch. Required becausemaybeAdoptForkBlocksruns before prepare* on the raw body (first request of a fresh session); without the mirror, id derivation would diverge for marker/panel-bearing messages after this fix and silently drop ref inheritance.tests/issue2798-google-acp-strip.test.ts(new, 11 tests): stripper units (panel signatures, multi-part join, non-text/signatured part preservation, KDD release v0.1.3 #10 byte-exactness, multi-line acp_status report shape), fork-adoption google parity,prepareGoogleCountTokensread-only measurement, and a full-server proof that upstream/v1betatraffic arrives stripped while still answering.Commit 2 — in-passing fix (same mechanism family, labeled)
src/server.tsprepareCountTokens(the anthropic/v1/messages/count_tokenstwin): forwarded the raw body for measurement whileprepareAnthropicstrips panels/markers before projection — the preview measured a payload the proxy never sends. Now runs the same two passes at the top of the preview (still read-only, same log lines). OpenAI/Responses have no count_tokens endpoint (existingisCountTokensRequesttests pin that), so this twin completes the set.stripAcpPanelResponsesInputimport fromserver.ts(vestigial; tsc does not flag it becausenoUnusedLocalsis off).tests/count-tokens.test.ts(natural home; keeps commit 2 self-contained).Behavior changes (old → new)
/v1beta …:generateContent/:streamGenerateContent[ACP]marker lines forwarded verbatim into compression state every turn (billed/replayed forever)/v1beta …:countTokens/v1/messages/count_tokens(in-passing)/v1/messagesforwardsNo new config/env/CLI surface. No kernel change (
kernel-change:not applicable — host-side only). No persistence format change.Regression review (existing behaviors audited)
thought:trueandthoughtSignatureparts; pinned by a byte-exactness test.buildIncomingImageIndexruns pre-prepare on the raw body by design, butrefreshIncomingImageIndexre-runs post-prepare within the same request — self-heals exactly like all four lanes today. No change.chatBodyToCorereturns null for google bodies by design ([Bug][pi] fork adoption masks the root cause of snapshot 409; lineage-only subtask falsely triggered and Responses clien | [Bug][pi] fork adoption 隐藏 snapshot 409 原因,lineage-only 子任务误触发且 Responses 客户端未支持 #2469) — nothing to mirror client-side.Verification
Local targeted runs (full suite via CI): typecheck clean;
tests/issue2798-google-acp-strip.test.ts11/11,tests/acp-panel.test.ts,tests/count-tokens.test.ts9/9 (incl. new),tests/issue1029-acp-marker-stale-refs.test.ts,tests/fork-adoption-wires.test.ts,tests/pi-omp-fork-adopt.test.ts,tests/dsh-fork-adopt.test.ts,tests/issue1204-rules-google-plugin.test.ts— 99/99 pass.Golden regeneration (commit 3) — intentional drift, justified
First CI run was red on exactly two tests, both asserting against the shared
golden-googlepin set (tests/golden/storage-render/google.json):storage-render golden (google): wire bodies + persisted state match committed snapshotstorage engine: full-mode restart is invisible on the google wire (== legacy restart, wire == committed goldens)Why the pins moved: the golden drive runs with
compress: { injectTool: true, injectNudge: true }, so once the fold fires at body #9 the proxy injects its ephemeral[ACP]status-marker line (#717/#1029) into the next request's incoming history. Pre-fix that line rode unstripped into the google lane's projection on every subsequent turn — i.e. the pin set had codified the exact defect #2798 removes. Post-fixprepareGooglestrips it before projection, so bodies #10+ and the final persisted state legitimately differ. This is the fix working as designed, made visible by the pin set; per the gate's own instruction the goldens were regenerated withnode --import tsx scripts/update-storage-render-goldens.ts.The delta is exactly the strip effect and nothing else (reviewed field-by-field):
contents; constant across all five bodies rules out nondeterministic drift);stateDigest,sectionDigests.{state,stats,metadata},stateKeyDigests.{messageRefs,tokenSnapshot,lastPassIds};blockContentsdigest,blocks/nudge/nextBlockId/nextRunId/deadRefs/hiddenOrphanRefs/terminalStreakdigests,foldAt=9/editedAt=12/summaryFrom=9, andstateShapeincl. the refs count (the marker rides inside an existing message as a line, so no ref is minted/freed);Rebase onto current master + #2797 block-semantics adaptation (commits
1cf37f907→a48d5e099)Conflict wake-up arrived while master had merged #2797 (
3185aee4a, acp_status marker = BLOCK not line): the platform sync had merged a stale master missing it, so the google stripper was adapted in the resolution — it now calls the sharedstripAcpStatusBlocksverbatim, exactly like the three sibling lanes.[ACP]head line of an acp_status report (pre-fix(#2789): strip the whole acp_status marker block from incoming history #2797 semantics); it now consumes the whole block — the sentinel-wrapped[acp-status]…[/acp-status]body exactly, or the legacy unwrapped report grammar up to the first prose line, or to end-of-message when cut mid-report — identical to openai/anthropic/responses post-fix(#2789): strip the whole acp_status marker block from incoming history #2797. Also: a marker at end of part leaves no trailing newline (shared split/join semantics).src/server.tsimport line (kept — used by the in-passing count_tokens fix);tests/golden/storage-render/google.json(took master's, regenerated — same strip-only diff as before,stateDigest bafa686948387cd7…, chat/anthropic/responses byte-identical).a48d5e099): mirrorstests/acp-status-marker-block.test.tsfixtures for the google parts shape — wrapped whole-block removal, legacy stop-at-prose, cut-mid-report consume-to-end, plus a signed-part-with-full-block byte-exact case (KDD release v0.1.3 #10).