Skip to content

fix: gemini 转换中 lastPart 为 nil 时避免 panic#1051

Merged
looplj merged 1 commit intolooplj:release/v0.9.xfrom
MomentDerek:fix/v0.9.x-gemini-panic
Mar 13, 2026
Merged

fix: gemini 转换中 lastPart 为 nil 时避免 panic#1051
looplj merged 1 commit intolooplj:release/v0.9.xfrom
MomentDerek:fix/v0.9.x-gemini-panic

Conversation

@MomentDerek
Copy link
Copy Markdown
Contributor

No description provided.

@MomentDerek MomentDerek marked this pull request as ready for review March 13, 2026 09:06
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在增强 Gemini 转换逻辑的健壮性,通过在处理 ReasoningSignature 时添加必要的空值检查,避免了在特定边缘情况下可能发生的 panic。同时,通过新增全面的单元测试和流式转换测试,确保了修复的有效性并提高了代码的稳定性。

Highlights

  • 修复潜在的 panic: 在 Gemini 转换逻辑中,为 lastPart 变量添加了空值检查,以防止在 lastPartnil 时发生 panic。
  • 新增单元测试: 增加了新的测试用例,以验证在 ReasoningSignature 存在但 Content.Parts 为空的情况下,转换函数不会引发 panic。
  • 新增流式转换测试: 引入了一个新的流式转换测试,确保仅包含 ReasoningSignature 的完成块能够被正确处理。
Changelog
  • llm/transformer/gemini/inbound_convert.go
    • 在将 ReasoningSignature 赋值给 lastPart.ThoughtSignature 之前,添加了 lastPart != nil 的条件检查。
  • llm/transformer/gemini/inbound_convert_test.go
    • 新增了一个名为 "reasoning signature without parts does not panic" 的测试用例,验证在没有 Content.Parts 的情况下,ReasoningSignature 的处理不会导致 panic。
  • llm/transformer/gemini/inbound_stream_test.go
    • 导入了 github.com/looplj/axonhub/llm/transformer/shared 包。
    • 新增了一个名为 "TestInboundTransformer_TransformStream_FinishOnlyChunkWithReasoningSignature" 的测试用例,用于验证流式转换器在接收到仅包含 ReasoningSignature 的完成块时,能够正确处理。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

本次 PR 修复了在 Gemini 转换逻辑中,当 lastPartnil 时可能引发的 panic。该问题发生在处理一个包含 ReasoningSignature 但没有任何内容部分(parts)的消息时,会导致对空指针的解引用。通过在赋值前添加对 lastPart 的空指针检查,此更改避免了潜在的 panic。PR 中还包含了针对非流式和流式场景的单元测试,以验证此修复并防止回归。

@looplj looplj merged commit 60f0dd5 into looplj:release/v0.9.x Mar 13, 2026
2 checks passed
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.

2 participants