Skip to content

Google Gemini is untracked: no conversation id, so nothing is folded or compressed #866

Closed

Description

@joshwapohlmann

bili terminates TLS for generativelanguage.googleapis.com and forwards the POSTs, but a Gemini conversation is invisible to everything downstream of detection. Every turn is logged as an anonymous forward while the other wires log a session-scoped processTurn:

[01a0a0cb-…] processTurn: 158 msgs …        (deepseek)
[unknown] forward POST → https://generativelanguage.googleapis.com/v1beta/models/gemini-3.8-flash:streamGenerateContent?alt=sse

Consequences observed on a live session: no conversation id is minted, prefix affinity never links the turns into one session, the nudge never computes growth, ACP compression never fires, and usage is not accounted. The client's own compaction is cancelled by the plugin by design (session_before_compact returns {cancel:true} for reason threshold or overflow), so with the proxy also unable to compact, nothing compacted and the context reached 339k tokens, holding large tool results (135 KB DOM dumps) verbatim.

Cause: protocol detection matched only /chat/completions, /v1/messages and /responses. Gemini's /v1beta/models/<model>:streamGenerateContent matched none of them, so protocol came back null, the kernel path was skipped, and the request was forwarded byte for byte. Client identity cannot be taken from a header here either: the client stamps a session header only for the anthropic and openai wires, so a Gemini session has to be recognised by prefix affinity over contents.

What has to be supported for this wire to behave like the others:

  • Detection and model resolution from the path (:generateContent, :streamGenerateContent, :countTokens), and a window entry for the Gemini 3 line.
  • A conversation identity for anonymous Gemini traffic, by prefix affinity over contents.
  • Folding and re-emission on that wire, keeping systemInstruction, the alternating roles, thoughtSignature round-trips and named functionResponse pairing valid, plus tool declarations in the flat {name, description, parameters} shape.
  • Usage accounting from usageMetadata (input = promptTokenCount minus cachedContentTokenCount, output = candidatesTokenCount plus thoughtsTokenCount), and the output budget mapped to generationConfig.maxOutputTokens.
  • The auxiliary paths: tag stripping, image estimation, in-band truncation, the fake-completion hint, countTokens, and the preflight summary call.

Expected: a Gemini session shows up in /acp panel with a conversation id, gets nudged and folded like the other wires, and reports usage instead of staying anonymous.

Fixed by PR #867.

Activity

  1. joshwapohlmann commented on Sep 16, 2026

    @joshwapohlmann
    ContributorAuthor

    The fix is already filed as PR #867 (branch 2026-09-16_866-google-wire). Please review there rather than implementing a parallel change. Note its CI fails at npm run typecheck with TS2305: Module 'acp-kernel/wire' has no exported member 'GoogleRequestBody' because acp-kernel is pinned at 0.0.74: it needs a kernel release carrying the codec (kernel PR #318) plus the deps: bump acp-kernel commit this repository makes after each release.

  2. ranxianglei commented on Sep 16, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

    [bot] 🏷 Review of PR #867 — verdict + what is actually blocking CI

    Reviewed PR #867 head e377eb9 (5 commits, 23 files, +2425/−103) against current master. No parallel implementation touched.

    Code verdict: solid. The diff mirrors the other wires' architecture faithfully and covers every item in the OP spec:

    • detection + model-from-path (googlePathKind / googleModelFromPath, requestModel = body ?? path at every model-keyed site);
    • identity via conversationSignalGoogle with the anonymous prefix-affinity fallback over contents;
    • folding in prepareGoogle: systemInstruction hoisted out of the fold space, coreToGoogle re-emission under role alternation, thoughtSignature round-trip through ToolCallEmit/reasoning replay, name-based functionResponse pairing (the live 400 fix), flat functionDeclarations injection, nudge merged into the trailing non-model content;
    • accounting exactly as specified (input = promptTokenCount, which already includes cachedContentTokenCount; output = candidatesTokenCount + thoughtsTokenCount), Gemini 3 window row, budget mapped to generationConfig.maxOutputTokens;
    • aux paths: tag stripping (SSE and JSON-array streaming forms), inlineData/fileData image estimates, in-band error/truncation frames, fake-completion hint, countTokens pruning, and the preflight summary call incl. the response-shape-driven SSE parse fix ([preflight] responses 协议 overhead 估算漏计 input[] 内的 developer/system 消息:codex 请求被系统性低估整个 system prompt #829 mirror case).

    Two review findings:

    1. Latent edge case in src/loop/adapter-google.ts (parseStream): the guard that keeps a text event from forwarding a chunk which also carries a functionCall part only counts calls seen before the text part in iteration order. If one chunk holds [text, functionCall] (text first), the text event forwards the whole chunk and the settle-time replay forwards it again → the client sees the text/call twice. The tag-filtered-text branch is worse: its raw keeps every sibling part, so a proxy tool call could leak to the client even when settle drops the chunk. Real Gemini streams usually isolate functionCall parts in their own chunk, so severity is low-medium, but it is a wire-fidelity hazard. Suggested fix: precompute hasCallPart over the chunk's parts and suppress raw on both branches when it is set (the core then synthesizes the frame via emitText). I can push this as a commit on the PR branch alongside the dep bump below.
    2. Cosmetic: cloneChunk yields a content without role for finish-only chunks (harmless in practice).

    CI failure — confirmed locally, and the blocker sits one step further upstream than stated. Reproduced on the PR head with acp-kernel 0.0.74: typecheck fails with ~22 errors. GoogleRequestBody is only one of them — the missing exports are also coreToGoogle, googleToCore, googleSystemText, injectGoogleSystem, conversationSignalGoogle, GoogleContent, GoogleFunctionDeclaration, GoogleSystemInstruction, GoogleTool, GooglePart (from acp-kernel/wire) and COMPRESS_TOOL_GOOGLE / DECOMPRESS_TOOL_GOOGLE / SEARCH_CONTEXT_TOOL_GOOGLE / ACP_STATUS_TOOL_GOOGLE / ACP_TOOLS_GOOGLE / ABSORB_TOOL_GOOGLE (from the acp-kernel root), plus one cascading TS7006 at src/server.ts:2269. Single root cause: the pinned kernel predates the codec.

    The key point: there is no kernel release to bump to yet. Verified just now:

    So the sequence is: merge kernel PR #318 (human-only) → kernel release published by CI → then the deps: bump acp-kernel commit lands on this PR. PR #867 has allow edits by maintainers enabled, so as soon as the version is live on npm I can push the bump commit (exact pin + lockfile refresh, per repo convention) to joshwapohlmann:2026-09-16_866-google-wire and re-run the checks myself.

    Bottom line: code approved pending the kernel release; nothing in this PR blocks that step. Ping me once #318 is merged/released and I'll land the bump.


    中文摘要:PR #867 代码审查通过(实现完整、与其他 wire 架构一致;另发现一个低概率的“同一 chunk 混合 text+functionCall 时双重转发”边界问题,已给出修法,可随依赖升级一并提交)。CI 红的原因已在本地复现并确认:acp-kernel 0.0.74 缺少 Gemini codec(缺失导出远不止 GoogleRequestBody 一个)。更关键的是——目前连可升级的版本都不存在:kernel PR #318 尚未合并,npm 最新的 0.0.75 经解包验证也不含该 codec。等 #318 合并并发布后,我可以直接把 deps: bump acp-kernel commit 推到 PR 分支并复跑 CI,届时即可合并。

  3. ranxianglei commented on Sep 16, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

    [bot] 🏷 Review of PR #867 — verdict + what is actually blocking CI

    Reviewed PR #867 head e377eb9 (5 commits, 23 files, +2425/−103) against current master. No parallel implementation touched.

    Code verdict: solid. The diff mirrors the other wires' architecture faithfully and covers every item in the OP spec: detection + model-from-path (googlePathKind / googleModelFromPath, requestModel = body ?? path); identity via conversationSignalGoogle with the anonymous prefix-affinity fallback over contents; folding in prepareGoogle (systemInstruction hoisted out of the fold space, coreToGoogle re-emission under role alternation, thoughtSignature round-trip through ToolCallEmit/reasoning replay, name-based functionResponse pairing, flat functionDeclarations injection, nudge merged into the trailing non-model content); accounting exactly as specified (input = promptTokenCount, which already includes cachedContentTokenCount; output = candidatesTokenCount + thoughtsTokenCount), Gemini 3 window row, budget mapped to generationConfig.maxOutputTokens; aux paths: tag stripping (SSE and JSON-array streaming forms), inlineData/fileData image estimates, historical image stripping, in-band error/truncation frames, fake-completion hint, countTokens pruning, and the preflight summary call incl. the response-shape-driven SSE parse fix (#829 mirror case).

    Two review findings:

    1. Latent edge case in src/loop/adapter-google.ts (parseStream): the guard that keeps a text event from forwarding a chunk which also carries a functionCall part only counts calls seen before the text part in iteration order. If one chunk holds [text, functionCall] (text first), the text event forwards the whole chunk and the settle-time replay forwards it again → the client sees the text/call twice. The tag-filtered-text branch is worse: its raw keeps every sibling part, so a proxy tool call could leak to the client even when settle drops the chunk. Real Gemini streams usually isolate functionCall parts in their own chunk, so severity is low-medium, but it is a wire-fidelity hazard. Suggested fix: precompute hasCallPart over the chunk's parts and suppress raw on both branches when it is set (the core then synthesizes the frame via emitText). I can push this as a commit on the PR branch alongside the dep bump below.
    2. Cosmetic: cloneChunk yields a content without role for finish-only chunks (harmless in practice).

    CI failure — confirmed locally, and the blocker sits one step further upstream than stated. Reproduced on the PR head with acp-kernel 0.0.74: typecheck fails with ~22 errors. GoogleRequestBody is only one of them — the missing exports are also coreToGoogle, googleToCore, googleSystemText, injectGoogleSystem, conversationSignalGoogle, GoogleContent, GoogleFunctionDeclaration, GoogleSystemInstruction, GoogleTool, GooglePart (from acp-kernel/wire) and COMPRESS_TOOL_GOOGLE / DECOMPRESS_TOOL_GOOGLE / SEARCH_CONTEXT_TOOL_GOOGLE / ACP_STATUS_TOOL_GOOGLE / ACP_TOOLS_GOOGLE / ABSORB_TOOL_GOOGLE (from the acp-kernel root), plus one cascading TS7006 at src/server.ts:2269. Single root cause: the pinned kernel predates the codec.

    The key point: there is no kernel release to bump to yet. Verified just now:

    So the sequence is: merge kernel PR #318 (human-only) → kernel release published by CI → then the deps: bump acp-kernel commit lands on this PR. PR #867 has allow edits by maintainers enabled, so as soon as the version is live on npm I can push the bump commit (exact pin + lockfile refresh, per repo convention) to joshwapohlmann:2026-09-16_866-google-wire and re-run the checks myself.

    Bottom line: code approved pending the kernel release; nothing in this PR blocks that step. Ping me once #318 is merged/released and I'll land the bump.


    中文摘要:PR #867 代码审查通过(实现完整、与其他 wire 架构一致,覆盖 OP 全部要求;另发现一个低概率的"同一 chunk 混合 text+functionCall 时双重转发"边界问题,已给出修法,可随依赖升级一并提交)。CI 红的原因已在本地复现并确认:acp-kernel 0.0.74 缺少 Gemini codec(缺失导出远不止 GoogleRequestBody 一个)。更关键的是——目前连可升级的版本都不存在:kernel PR #318 尚未合并,npm 最新的 0.0.75 经解包验证也不含该 codec。等 #318 合并并发布后,我可以直接把 deps: bump acp-kernel commit 推到 PR 分支并复跑 CI,届时即可合并。

  4. ranxianglei commented on Sep 17, 2026

    @ranxianglei
    Owner

    继续

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions