Skip to content

fix(relaykit): preserve Gemini text alongside tool calls - #7998

Merged
seefs001 merged 1 commit into
QuantumNous:mainfrom
zxdvd:fix/relay-conversion-regression
Oct 25, 2026
Merged

seefs001 merged 1 commit into
QuantumNous:mainfrom
zxdvd:fix/relay-conversion-regression

Conversation

@zxdvd

@zxdvd zxdvd commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Agent

  • Tool: Codex; AI-assisted code and tests
  • Tool version: CLI 0.163.0; desktop host version unknown
  • Model: gpt-6-astra; snapshot version not provided
  • Host: local desktop execution, macOS arm64
  • Date (UTC): 2026-10-23

Links

Closes #7997

#6604 修调用ID配对;#7458 是反方向;#6593 和 #7933 无本转换器改动;#6615 是Claude→Chat。未发现相同修复。

User request

Public task summary (private wording and local paths omitted): Investigate and fix two reproducible protocol-conversion bugs, with local tests before submission.

Out of scope — refuse

Matched: no;官方协议转换,非透传。

Open gate — do not open unless all are satisfied

  • Out of scope: no
  • Usage / configuration / integration: no
  • Required issue facts present: yes
  • Verification includes actual commands and observed results: yes
  • Body is factual and scoped: yes
  • Open: yes

Kind

  • Bug fix

Issue facts

Gemini model content 同时含 text 和 functionCall 时,出站 assistant.content 变为 null,tool_calls 仍在。

多轮工具调用历史中的解释文本丢失。合成输入每次复现,生产发生率未测。

归因:相同本地假上游及输入,仅替换基线/修复源码。

POST /v1beta/models/gpt-4o:generateContent;OpenAI channel,测试模型名 gpt-4o;Gemini 请求→Chat;非透传。

HTTP对照:本地假上游 POST /v1/chat/completions 返回 HTTP 200;捕获 assistant.content="I will check the weather." 和 call_weather。固定响应为 "Mock acknowledgement."、finish_reason=stop。 真实 OpenAI Adaptor.ConvertGeminiRequest→service/relaykit→ConvertOpenAIRequest→DoRequest。基线及修后均200;基线仅 messages[1].content 为null,修后请求与直连JSON等价。 其他类型不适用。

Change

将工具调用与文本赋值改成两个独立 if,保留同一assistant消息上的 content 和 tool_calls。

Research

Evidence comes from current source code, the official protocol references below, and deterministic regression tests.

Duplicate / prior art

2026-10-23 UTC(发布前已刷新),范围限定 QuantumNous/new-api。Issues/PRs 全状态、各上限100:Gemini functionCall text、Gemini tool_calls text;Discussions:Gemini functionCall、Gemini text tool,均0条且无下一页。

#6604 修调用ID配对;#7458 是反方向;#6593 和 #7933 无本转换器改动;#6615 是Claude→Chat。未发现相同修复。

Docs and code

New API、README:确认协议转换入口;具体行为以源码为准。

Gemini 的 Content 包含多个有序 Part,类型互斥仅限单个 Part;OpenAI assistant 支持 content 与 tool_calls 共存。

relaykit/relayconvert/internal/gemini_chat/to_oai_chat_req.go 定位根因。

Alternatives considered

另建assistant消息会改变历史结构;复用原消息的content和tool_calls更小且符合目标协议。

Files

relaykit/relayconvert/internal/gemini_chat/to_oai_chat_req.go:拆开赋值分支。

relaykit/relayconvert/request_registry_test.go:四个回归/控制案例。

Behavior

Before: Gemini model content 同时含 text 和 functionCall 时,出站 assistant.content 变为 null,tool_calls 仍在。

After: 同一消息中的文本和工具均保留,文本间顺序及仅文本/仅工具行为不变。

非目标:未调用真实 Gemini/OpenAI,未测试完整网关鉴权/路由/计费及响应格式转换;不承诺跨协议文本和工具的完整交错顺序。#6604改同文件,可能有合并冲突。

Verification

cd relaykit && GOWORK=off go test ./relayconvert -run '^TestGeminiToOpenAIChatPreservesTextAlongsideToolCalls$' -count=1:基线两个混合案例失败,修后四例通过。GOWORK=off go test ./... -count=1、GOWORK=off go build ./...、git diff --check 通过。

Local HTTP experiment: a localhost fake upstream was exercised through the real adaptor/handler path described above. The direct and converted requests/responses were captured and compared before and after the patch. This is supplemental local evidence, not a live-provider or full-gateway test.

独立review重跑focused测试通过,无阻塞发现。仅macOS、本地fake upstream;未访问数据库、无UI。未验证范围见Behavior。

Risks

未调用真实 Gemini/OpenAI,未测试完整网关鉴权/路由/计费及响应格式转换;不承诺跨协议文本和工具的完整交错顺序。#6604改同文件,可能有合并冲突。 不改鉴权、quota或usage逻辑。

Scope check

  • Single focused change: yes
  • Secrets included: no
  • Out of scope: no

Summary by CodeRabbit

  • Bug Fixes
    • Assistant responses now preserve text when they include tool calls, so users can see both the message content and the results of the requested actions.

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4b3f8afe-685e-4a37-ae94-8fa4628b92f2
📥 Commits

Reviewing files that changed from the base of the PR and between 33c61a2 and fb01914.

📒 Files selected for processing: 2
  • relaykit/relayconvert/internal/gemini_chat/to_oai_chat_req.go
  • relaykit/relayconvert/request_registry_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Walkthrough

Gemini-to-OpenAI chat conversion now retains text content when an assistant message also contains tool calls. New tests cover mixed, call-only, and text-only inputs, including a JSON round-trip of the converted request.

Changes

Gemini chat conversion

Layer / File(s) Summary
Preserve text with tool calls
relaykit/relayconvert/internal/gemini_chat/to_oai_chat_req.go, relaykit/relayconvert/request_registry_test.go
The converter checks the single-text content condition independently of tool calls. Tests verify text and tool-call fields for mixed, call-only, and text-only inputs, including after JSON serialization and decoding.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: calcium-ion

Merge Risk: ⚪ Minimal · up to fb019

No confirmed issue remains that should block merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: preserving Gemini text alongside tool calls during relaykit conversion.
Linked Issues check Passed No active directly linked issue remains. Issue #7997 is closed and supplies historical context only. Therefore, this pull request has no active linked-issue coding requirement. The diff is consistent …
Out of Scope Changes check Passed The changes stay within the stated Gemini-to-OpenAI Chat conversion fix. The source change is limited to relaykit/relayconvert/internal/gemini_chat/to_oai_chat_req.go. The added test covers mixed te…
Full details: Linked Issues check

Explanation

No active directly linked issue remains. Issue #7997 is closed and supplies historical context only. Therefore, this pull request has no active linked-issue coding requirement. The diff is consistent with the historical bug description: it assigns tool calls and text in separate conditions and adds focused regression coverage.

Full details: Out of Scope Changes check

Explanation

The changes stay within the stated Gemini-to-OpenAI Chat conversion fix. The source change is limited to relaykit/relayconvert/internal/gemini_chat/to_oai_chat_req.go. The added test covers mixed text and function calls, call-only input, and text-only input. These tests support the conversion fix and are not unrelated changes.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

⚠️ This pull request shows signs of AI-generated slop (ai_padded_prose). It has been flagged by CodeRabbit slop detection and should be reviewed carefully.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit taps the message trail,
Text and tool calls both prevail.
Through JSON fields, the words stay clear,
Call names and IDs reappear.
The rabbit hops, content intact.

Comment @coderabbitai help to get the list of available commands.

@zxdvd
zxdvd marked this pull request as ready for review October 23, 2026 16:45
@seefs001
seefs001 merged commit 0165fef into QuantumNous:main Oct 25, 2026
1 check passed
hydraxman pushed a commit to MindxMotion/MEM-AI that referenced this pull request Oct 28, 2026
Select nine upstream fixes from QuantumNous/new-api main at 49271d2. Preserve OIDC, root-managed integration clients, bounded diagnostics, canonical mem-ai routes, and existing dependencies. Do not include pricing, schema, frontend, or deployment changes.

Keep the AWS safeguards regression without importing unrelated thinking-binding tests from three-way context. Add canceled-context stream coverage alongside the upstream non-stream regression.

Upstream sources:
bc795cc fix:修复stop为非字符串和[]string的协议转换问题 (QuantumNous#7935)
4d962e4 fix(relaykit): preserve tool argument numbers in Claude responses (QuantumNous#7996)
0165fef fix(relaykit): preserve Gemini text alongside tool calls (QuantumNous#7998)
34003e9 test: stabilize channel affinity cache keys (QuantumNous#8009)
01da3a5 perf(relay): stop recompiling param override regexes on every request (QuantumNous#8061)
ad56112 fix(relay): apply GPT-6 chat parameter rules to gpt-6.1-sol and gpt-6.1-terra (QuantumNous#8064)
3f926c3 fix(metrics): count completed streams after context cancellation (QuantumNous#7638)
5478811 fix: count completed non-stream relays after context cancellation (QuantumNous#7844)
49271d2 fix(aws): preserve safeguards in Bedrock Invoke requests (QuantumNous#8071)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
kyuhwi-choi pushed a commit to attodev/new-api that referenced this pull request Oct 30, 2026
woncc added a commit to 86669666/new-api that referenced this pull request Nov 5, 2026
Port upstream 0165fef (QuantumNous#7998).

Co-authored-by: woncc <3104616+woncc@users.noreply.github.com>
Co-authored-by: Xudong Zhang <zxdvd_zhang@163.com>
shirosoralumie648 added a commit to shirosoralumie648/newapi-rev that referenced this pull request Nov 5, 2026
Sync 75 upstream commit(s) via merge (fork history preserved).

Upstream commits:
- 7061447 fix(auth): 校验 Redis 鉴权缓存完整性 (QuantumNous#8200)
- ba5f736 fix(gemini): bill embeddings from upstream usageMetadata (QuantumNous#8182)
- 94b5216 feat(vertex): add per-channel v1beta1 endpoint switch (QuantumNous#8179)
- 83b18fe feat(channel): return created IDs with input mappings (QuantumNous#8164)
- 52c1730 feat(gemini): add Argon fields and reasoning mappings (QuantumNous#8177)
- 9b473a3 fix(twofa): restart the failure count after a lockout expires (QuantumNous#8172)
- 45746ee feat(relay): add opt-in HTTP/2 health checks (QuantumNous#8059)
- c046559 feat(plugins): bill gemini omni by the tokens vertex reports (QuantumNous#8153)
- 651d5a2 fix(xai): preserve token details in stream usage conversion (QuantumNous#6420)
- 70e6af6 perf: read and edit request JSON and base64 with moego (QuantumNous#8148)
- d0abbf6 feat(plugins): generate video with Gemini Omni on Vertex AI channels (QuantumNous#8142)
- ea343c4 fix(plugins): charge relayed streams even when the reserve or task insert fails (QuantumNous#8121)
- fe57cba fix(plugins): prefer Kling's returned price (list_price) for Kling 4.0 cash billing (QuantumNous#8125)
- 1424ffd fix(plugins): load plugins that declare their own /{key} address (QuantumNous#8119)
- 8b253de fix(plugins): keep Kling 4.0 durations in range and map every video size (QuantumNous#8118)
- c59f6fd feat(plugins): serve task plugins at the vendors' own paths and answer as the vendors do (QuantumNous#8117)
- 37d23dc fix(profile): honor global sidebar visibility (QuantumNous#7429)
- 7743627 fix(deps): upgrade DOMPurify to 3.4.17 (QuantumNous#8116)
- 883eeb8 feat(plugins): warn about task models a plugin cannot charge
- 1e8c707 chore(deps): bump @codemirror/language from 6.12.4 to 6.13.1 in /web (QuantumNous#8102)
- 6e78cb3 chore(deps): bump marked from 18.0.6 to 18.1.2 in /web (QuantumNous#8103)
- 9fc70bb chore(deps-dev): bump @tanstack/react-query-devtools in /web (QuantumNous#8104)
- cef7820 chore(deps-dev): bump knip from 6.27.0 to 6.43.0 in /web (QuantumNous#8105)
- 1695171 chore(deps): bump tailwind-merge from 3.6.0 to 3.7.0 in /web (QuantumNous#8106)
- 7fa815e chore(deps-dev): bump fast-uri from 3.1.7 to 3.1.9 in /electron (QuantumNous#8007)
- ee0f0ac chore(deps-dev): bump electron from 41.10.6 to 42.11.16 in /electron (QuantumNous#8008)
- 837b814 chore(deps): bump undici in /electron (QuantumNous#8006)
- 3150dfe chore(deps): bump github.com/go-jose/go-jose/v4 from 4.1.4 to 4.1.6 (QuantumNous#8112)
- a3851c2 fix: save Turnstile keys before enabling (QuantumNous#7960)
- 4193734 fix(logger): keep gin access and recovery logs on the current log file after rotation (QuantumNous#8098)
- f366017 Merge commit from fork
- 829f082 fix: unmount authenticated layout on sign-out to stop credential-less refetches (QuantumNous#8110)
- 9eda50a Merge commit from fork
- a2defd2 Merge commit from fork
- e449cc7 feat: sample immediate task successes in model performance metrics (QuantumNous#8067)
- fcc241c fix: start affinity fallback at the highest channel priority (QuantumNous#8078)
- b08ee86 fix(cloudflare): preserve embedding response data (QuantumNous#8041)
- 26c488c fix(relay): allow Azure channels to opt in to Responses WebSocket (QuantumNous#8047) (QuantumNous#8075)
- 55515db fix(relay): terminate streams on exact bare done markers (QuantumNous#8074)
- 49271d2 fix(aws): preserve safeguards in Bedrock Invoke requests (QuantumNous#8071)
- 5478811 fix: count completed non-stream relays after context cancellation (QuantumNous#7844)
- ad56112 fix(relay): apply GPT-6 chat parameter rules to gpt-6.1-sol and gpt-6.1-terra (QuantumNous#8064)
- 01da3a5 perf(relay): stop recompiling param override regexes on every request (QuantumNous#8061)
- 34003e9 test: stabilize channel affinity cache keys (QuantumNous#8009)
- 0165fef fix(relaykit): preserve Gemini text alongside tool calls (QuantumNous#7998)
- 4d962e4 fix(relaykit): preserve tool argument numbers in Claude responses (QuantumNous#7996)
- f1569d1 fix(pricing): classify dynamic per-request billing correctly (QuantumNous#8010)
- bc795cc fix:修复stop为非字符串和[]string的协议转换问题 (QuantumNous#7935)
- 9823ebc fix(billing): bill cache_creation_input_tokens reported in prompt_tokens_details (QuantumNous#7909)
- e835b1b chore(deps): bump axios from 1.18.1 to 1.20.0 in /web (QuantumNous#7835)
- 5c8032d chore(deps): bump react-i18next from 17.0.10 to 17.1.0 in /web (QuantumNous#7981)
- 0b667ca chore(deps): bump i18next from 26.3.6 to 26.5.3 in /web (QuantumNous#7979)
- 4105bd0 chore(deps): bump input-otp from 1.4.2 to 1.5.0 in /web (QuantumNous#7980)
- b6b85ca chore(deps): bump react-resizable-panels from 4.12.2 to 4.14.6 in /web (QuantumNous#7982)
- 1dafb19 fix(gemini): preserve top-level imageConfig in chat conversion
- 0034b24 fix(task): wait up to 72 hours before timing out tasks
- a404460 chore(web): upgrade Bun to 1.4.4 and use bun check
- 33c61a2 fix: prevent stale values when switching edit drawer records (QuantumNous#7989)
- 30748c6 fix(logging): 隐藏访问日志中的查询凭据 (QuantumNous#7972)
- 7fb6e57 fix(channels): preserve advanced custom body passthrough settings (QuantumNous#7971)
- e9d4d63 feat(billing): bill OpenAI 12-hour prompt cache writes at their own price (QuantumNous#7965)
- d0b840e fix(relay): keep the client's JSON Schema property order
- d8e6561 feat(web): copy model names from usage log details
- 8802113 feat(task): let ordinary channels compete on shared plugin endpoints
- eb169e7 feat(pricing): adjust synced upstream prices by the site exchange rate
- e2321a5 chore(web): sort locale keys
- db80ac8 fix(task): let task plugins validate their own requests
- dbe97be feat(task): pass client request headers to task plugin drivers
- 556517f feat(task): accept multipart bodies on native plugin routes
- 94cc3ff fix(billing): bill Claude cache writes that arrive without a 5m/1h split
- 7e65967 fix(relay): stop cutting off slow clients during large stream events
- 0c2af97 fix(relay): finish delivered Responses streams without false disconnect errors (QuantumNous#7956)
- 7d8b912 fix: upgrade Go to 1.26.10 for CVE-2026-111943 (QuantumNous#7942)
- 4d36f2c chore(deps-dev): bump vitest from 4.1.10 to 5.0.4 in /web (QuantumNous#7838)
- eea05e0 chore(deps): bump github.com/klauspost/compress from 1.18.3 to 1.18.7 (QuantumNous#7931)

Local tests not run (CI-only).
timwenx pushed a commit to timwenx/new-api that referenced this pull request Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Gemini→Chat conversion drops text alongside function calls

2 participants