Skip to content

[PR] Guard the google lane against inert-frame tail drains - #6535

Merged
ranxianglei merged 1 commit into
ranxianglei:masterfrom
tinysunspot:2026-11-13_google-lane-inert-frame-guard
Nov 15, 2026
Merged

ranxianglei merged 1 commit into
ranxianglei:masterfrom
tinysunspot:2026-11-13_google-lane-inert-frame-guard

Conversation

@tinysunspot

Copy link
Copy Markdown
Contributor

What this changes

Ports the #5848 inert-frame guard to the Google (Gemini) lane, which still drained the tag-echo filter on any text-less frame. src/plugin.ts:3748 (inside processGoogle, :3582) was the exact twin of the line #5849 fixed for chat:

-        if (!hadText && anyPending()) return flushTails() + rawEvent + "\n\n";
+        if (!hadText && anyPending() && googleFrameHasNonText(ev)) return flushTails() + rawEvent + "\n\n";

googleFrameHasNonText is the Gemini counterpart of hadTextOtherThanTextFields and already existed in the file (it gates the rebuilt branch three lines above at :3740). No new helper, no config surface, no wire change.

Why

PR #5849 shipped the guard on the chat lane only, justified in its description with "no mid-stream text-less frames observed there" for the Google lane — an absence of observation, not a property of the lane. When a text-less frame reaches the unguarded exit:

  1. anyPending() is true because the tag-echo filter is holding a split render tag (<acp tokens="3);
  2. flushTails() drains it, and createTagEchoFilter.flush() drops the open-tag prefix it cannot complete (TRUNC_OPEN → drop(t[0]));
  3. the rest of the tag (1" type="text" …>m00039) never started with <, so it is forwarded as prose.

That is exactly the persisted shape in #5192 ( type="text">mNNNNN as assistant text), reached through a different lane.

Reproduction (red before the fix)

tests/plugin-passthrough-progress-frame-google.test.ts — the Gemini twin of tests/plugin-passthrough-progress-frame.test.ts, using a progress frame in Gemini's own dialect (a candidate whose only part is { text: "" }).

Against the unpatched tree, 3 of the 5 tests fail, e.g.:

✖ google: a text-less progress frame inside a paired render tag does not leak the tag's tail
  + '前の文章。1" type="text" time="2026-11-06 15:30:10">m00039後の文章'
  - '前の文章。後の文章'

With the fix: 19/19 pass across the three in-family suites (plugin-passthrough-progress-frame-google, plugin-passthrough-progress-frame, plugin-passthrough-finish-tail).

Both directions are asserted, per §3 Gate Test Discipline: the guard must not hold on a frame that legitimately carries something (usageMetadata still drains the held tail, and the result equals the no-extra-frame control run), and ordinary streams with no held tail are byte-identical.

Verification

  • npx tsc --noEmit --project tsconfig.json → exit 0
  • Targeted suites: 19/19 pass (3 in-family files)
  • Local full-suite verdict left to remote CI per §7.2

Scope

Single-module fix (src/plugin.ts + one new test file). No config schema, no persistence, no wire shape, no kernel/ change, no version bump. Fixes #5192 is deliberately not claimed — that issue keeps several open facets (live-streaming matcher policy, injection-side root cause) per the owner's "keep all facets under this issue" ruling; this PR closes only the Google-lane half of the #5848 mechanism.

Related

ranxianglei#5849 added hadTextOtherThanTextFields to the chat lane after a text-less
frame drained a held render-tag head, letting the rest of the tag reach the
host as prose. The google lane kept the unconditional drain, on the
assumption that it never sees such frames -- an absence of observation, not
a property of the lane.

A Gemini progress frame whose only part is {text:""} reproduces the same
split here, so gate that exit on googleFrameHasNonText, the predicate the
rebuilt branch three lines above already uses.
@ranxianglei ranxianglei changed the title Guard the google lane against inert-frame tail drains [PR] Guard the google lane against inert-frame tail drains Nov 13, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷
(ai: opencode/qwen3.8-27b)

Duplicate screen: not a duplicate. This is the Google-lane half of the #5848 mechanism; the chat-lane half (#5849) is already merged on master. I searched open PRs — #6535 is the only in-flight PR doing the Google-lane inert-frame guard. #6537 is in the same #5192 family but a different mechanism (making a dropped head auditable, not the guard itself), so related but not a duplicate.

Labels applied: bug / gemini / scope/wiring / p2 — defect on the Google/Gemini wire lane; output-visible tag residue under a specific frame shape; not a session brick or cost explosion.

Verdict: APPROVE / 可合 — pending CI (head 2a355a62bb has 0 check runs yet = Actions queue congestion, not red; master is green at 259cd87674 per #4599). Human merge tier (external contributor PR + touches plugin passthrough wire behavior, so not auto-merge).

Review method: I read the full diff independently (not the PR body's claims), pulled the authoritative source at the PR head, verified the mechanism against the tag-echo filter, and ran the in-family suites locally (RED before the fix, GREEN after).

结构化八问

  1. 是什么问题:Google/Gemini 车道的插件透传,在流中出现「无文本帧」(inert frame,parts 只有空串)时,会把 tag-echo filter 里暂存的未闭合标签前缀冲掉,残段(没有前导 <)作为正文转发出去,客户端看到的就是 [Pi/OpenAI] 0.1.209 leaks render-tag suffix type="text">mNNNNN into assistant text #5192 那种「 type="text">mNNNNN 漏进 assistant 文本」的持久化形状。

  2. 什么原因导致的:根因在排水决策点——master 上 src/plugin.ts:3748 的 raw exit if (!hadText && anyPending()) 对任何无文本帧都调 flushTails(),不区分该帧是否携带真正需要标签前置的内容。flushTails() 对 TRUNC_OPEN(未闭合开标签)执行 drop(src/loop/tag-echo-filter.ts:1359),于是暂存的前缀被丢、残段无 < 前缀直接当正文转发。chat 车道([pi/OpenAI] text-less mid-stream frames (delta:{}) drain the tag-echo filter → opener-less render-tag residue (one mechanism of #5192) #5848)早就是同一机制,已由 [PR] fix(plugin): don't drain held tags on inert mid-stream frames (#5848) #5849 在 src/plugin.ts:3449 修掉;Google 车道是同一缺陷的第二条产线,本 PR 把同一守卫移植过来。

  3. 影响范围与严重程度:所有走 Google/Gemini 插件透传、且流里出现无文本 inert 帧的用户面。严重度 p2:功能可用、有绕行(不触发该帧形状即不受影响),但一旦触发就会产生输出可见的标签残段(数据完整性瑕疵),非会话砖、非成本爆炸、非不可用。

  4. 怎么修复的(机制层):在排水决策点加一个谓词,让「无文本帧」只有在真正携带非文本内容时才排水。新增守卫 googleFrameHasNonText(ev)(Gemini 方言的 hadTextOtherThanTextFields 对应物):当帧含 usageMetadata / promptFeedback、candidates 非数组(fail-open→排水)、finishReason 非空、或任一 part 的 key 不是 text/thought/thoughtSignature 时返回 true。守卫后的行:if (!hadText && anyPending() && googleFrameHasNonText(ev))。这是打在根因(决策点)上的疏,不是在中途过滤字节的堵。

  5. 是否有回归问题——既有行为逐项过:

    • 终态排水([bug] plugin passthrough: content after finish_reason when an empty-string text delta skips the held-tail flush #1546):drain 在守卫行之前计算且优先返回——保持。
    • 非 candidates 帧的 raw exit:保持(在守卫行之前,未触碰)。
    • rebuilt 路径:保持。
    • 带文本的帧:hadText 为 true → 守卫行为 false——保持。
    • 无文本但携带非文本内容(functionCall/functionResponse/usageMetadata/promptFeedback/非空 finishReason)的帧:googleFrameHasNonText 为 true → 仍排水——保持。
    • 无文本 inert 帧(仅空 parts):有意变更——不再排水,原样转发,暂存尾巴保持 pending,直到下一个真实帧/终态/[DONE]/EOF 合成尾才排水。无数据丢失。
    • 高危模式:无语义漂移、无 fail-fast 变吞错、无既有阈值/时序/输出格式漂移。
    • 顺带:此改动触碰插件透传 wire 行为 + 外部贡献者 PR,不满足自动合并门槛,须 owner 人工合并。
  6. 是否破坏缓存:不涉及。本 PR 只改「无文本帧是否触发 tag-echo 尾巴排水」这一决策,不改压缩内容、不改前缀缓存、不改消息重建字节。

  7. 是否改了设计方向:不转向。是 [PR] fix(plugin): don't drain held tags on inert mid-stream frames (#5848) #5849(chat 车道)同一守卫在 Google 车道的对称移植;数据流/边界/两压缩模式语义不变。

  8. 是否引入新的配置:无。纯代码守卫 + 测试,未新增 env/config/默认值,无需迁移。

验证(本地,PR head 2a355a62bb)

  • RED 对照:把 src/plugin.ts 回退到 master(保留测试文件)→ google 套件 3/5 失败(配对标签泄漏、未闭合标签、每个边界),测试 4-5(usageMetadata 仍排水、普通流不变)通过——证明测试真钉住新行为而非空转。
  • GREEN:PR head 上 3 个同族套件 19/19 通过;npx tsc --noEmit exit 0。
  • CI:head 2a355a62bb 0 check runs(队列拥塞,非红);master 在 259cd87674 绿。

diff 整洁度 & 代码质量

2 文件 +233/-1,每一行都和本 PR 目的相关,无跑题文件/空白噪音/lockfile churn。命名达意(gframe/gprogress/visibleText),注释讲 why(引 #5848/#5192),无死代码、无魔法数字。达标。

判定:可合 / APPROVE(owner 人工合并;CI 队列拥塞待跑,非红)。

@ranxianglei

Copy link
Copy Markdown
Owner

Superseded by #6765 (merged to master as 7c17438).

Your commit 2a355a6 is in master verbatim — same content, same authorship, only the object ID changed (the batch used a real git merge, no rebase or cherry-pick rewrite). Merged under a different branch name, so GitHub does not flip this PR by itself.

Thanks for the fix — it is live in master from 7c17438 onward.

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

Labels

bug Something isn't working gemini p2 scope/wiring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants