Skip to content

【BugFix】Fix the support issue for IPv6#186

Merged
SJTUyh merged 3 commits intoAISBench:masterfrom
GaoHuaZhang:bugfix
Mar 13, 2026
Merged

【BugFix】Fix the support issue for IPv6#186
SJTUyh merged 3 commits intoAISBench:masterfrom
GaoHuaZhang:bugfix

Conversation

@GaoHuaZhang
Copy link
Collaborator

@GaoHuaZhang GaoHuaZhang commented Mar 12, 2026

Thanks for your contribution; we appreciate it a lot. The following instructions will make your pull request healthier and help you get feedback more easily. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.
感谢您的贡献,我们非常重视。以下说明将使您的拉取请求更健康,更易于获得反馈。如果您不理解某些项目,请不要担心,只需提交拉取请求并从维护人员那里寻求帮助即可。

PR Type / PR类型

  • Feature(功能新增)
  • Bugfix(Bug 修复)
  • Docs(文档更新)
  • CI/CD(持续集成/持续部署)
  • Refactor(代码重构)
  • Perf(性能优化)
  • Dependency(依赖项更新)
  • Test-Cases(测试用例更新)
  • Other(其他)

Related Issue | 关联 Issue
Fixes #(issue ID / issue 编号) / Relates to #(issue ID / issue 编号)

🔍 Motivation / 变更动机

This PR aims to make service-based model backends work reliably with IPv4, IPv6 literals and hostnames when configuring host_ip. Previously, BaseAPIModel only handled IPv4 literals correctly and could generate invalid URLs or even raise exceptions when using IPv6 literals or localhost. With this change, users can configure IPv4/IPv6/hostnames in a more intuitive and consistent way, with proper URL construction and clearer documentation.

本 PR 旨在让服务化模型后端在配置 host_ip 时能够稳定支持 IPv4、IPv6 字面量以及主机名。此前 BaseAPIModel 只在 IPv4 字面量场景下工作正常,使用 IPv6 字面量或 localhost 时可能会生成非法 URL,甚至抛出异常。本次修改希望通过修正 URL 构造逻辑并补充文档说明,使用户在配置 IPv4/IPv6/主机名时行为更加直观、一致。

📝 Modification / 修改内容

Code changes / 代码修改

  • Update [ais_bench/benchmark/models/api_models/base_api.py] to build base_url based on host_ip in a protocol-agnostic and IP-version-aware way:
    • Use ipaddress.ip_address(self.host_ip) to detect whether host_ip is a valid IPv4 or IPv6 literal.
    • Automatically wrap IPv6 literals in brackets when constructing URLs (e.g. http://[::1]:8080/), while keeping IPv4 literals unchanged.
    • For non-literal hostnames (such as localhost or custom domains), keep the original string without modification to remain compatible with existing deployments.

文档与测试 / Docs & Tests

  • In [docs/source_zh_cn/base_tutorials/all_params/models.md] and [docs/source_en/base_tutorials/all_params/models.md], clarify that host_ip supports both IPv4 and IPv6 literals, add examples like ::1, and explicitly document that IPv6 literals will be automatically wrapped in brackets in the generated URLs.
  • In [tests/UT/models/api_models/test_base_api.py], add unit tests to cover:
    • Initialization and _get_base_url behavior with an IPv6 literal host_ip (e.g. ::1);
    • _get_base_url behavior with a hostname host_ip (e.g. localhost) to ensure backward compatibility.
      smoke test:
image

📐 Associated Test Results / 关联测试结果

Local unit tests have been added/updated and executed for the affected modules, focusing on IPv6 and hostname handling in BaseAPIModel:

  • tests/UT/models/api_models/test_base_api.py

相关模块的本地单元测试已补充/更新并执行,重点覆盖 BaseAPIModel 中 IPv6 与主机名场景的行为:

  • tests/UT/models/api_models/test_base_api.py

测试结果:

⚠️ BC-breaking (Optional) / 向后不兼容变更(可选)

This change is not expected to be BC-breaking. It keeps the behavior for IPv4 literals and hostnames unchanged at the configuration level, while making URL construction for IPv6 literals more correct (adding brackets automatically). Existing configurations using 127.0.0.1 or localhost should continue to work as before.

本次修改预期不会引入向后不兼容变更:对 IPv4 字面量和主机名的配置行为保持不变,仅在内部对 IPv6 字面量的 URL 构造进行了更规范的处理(自动添加方括号)。已使用 127.0.0.1localhost 的现有配置应能继续按原有方式工作。

⚠️ Performance degradation (Optional) / 性能下降(可选)

If the modification introduces performance degradation, please describe the impact of the performance degradation and the expected performance improvement.
如果引入了性能下降,请描述性能下降的影响和预期的性能改进。

🌟 Use cases (Optional) / 使用案例(可选)

If this PR introduces a new feature, it is better to list some use cases here and update the documentation.
如果此拉取请求引入了新功能,最好在此处列出一些用例并更新文档。

✅ Checklist / 检查列表

Before PR:

  • Pre-commit or other linting tools are used to fix the potential lint issues. / 使用预提交或其他 linting 工具来修复潜在的 lint 问题。
  • Bug fixes are fully covered by unit tests, the case that causes the bug should be added in the unit tests. / 修复的 Bug 已完全由单元测试覆盖,导致 Bug 的情况应在单元测试中添加。
  • The modification is covered by complete unit tests. If not, please add more unit tests to ensure the correctness. / 此拉取请求中的修改已完全由单元测试覆盖。如果不是,请添加更多单元测试以确保正确性。
  • All relevant documentation (API docs, docstrings, example tutorials) has been updated to reflect these changes. / 所有相关文档(API 文档、文档字符串、示例教程)已更新以反映这些更改。

After PR:

  • If the modification has potential influence on downstream or other related projects, this PR should be tested with those projects. / 如果此拉取请求对下游或其他相关项目有潜在影响,应在那些项目中测试此 PR。
  • CLA has been signed and all committers have signed the CLA in this PR. / CLA 已签署,且本 PR 中的所有提交者均已签署 CLA。

👥 Collaboration Info / 协作信息

  • Suggested Reviewers / 建议审核人: @xxx
  • Relevant Module Owners / 相关模块负责人: @xxx
  • Other Collaboration Notes / 其他协作说明:

🌟 Useful CI Command / 实用的CI命令

Command / 命令 Introduction / 介绍
/gemini review Performs a code review for the current pull request in its current state by Gemini. / 对当前拉取请求在当前状态下由 Gemini 执行代码审核。
/gemini summary Provides a summary of the current pull request in its current state by Gemini. / 对当前拉取请求在当前状态下由 Gemini 提供摘要。
/gemini help Displays a list of available commands of Gemini. / 显示 Gemini 可用命令的列表。
/readthedocs build Triggers a build of the documentation for the current pull request in its current state by Read the Docs. / 触发当前拉取请求在当前状态下由 Read the Docs 构建文档。

@gemini-code-assist
Copy link
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!

This pull request addresses a bug where BaseAPIModel in service-based model backends did not correctly handle IPv6 literals or hostnames for host_ip, potentially leading to invalid URLs or exceptions. The changes ensure that host_ip configurations reliably support IPv4, IPv6 literals, and hostnames, providing a more intuitive and consistent experience for users by correctly constructing URLs and offering clearer documentation.

Highlights

  • IPv6 Support: Enabled reliable handling of IPv6 literals in host_ip configurations for service-based model backends, resolving previous issues with invalid URLs or exceptions.
  • URL Construction Logic: Modified BaseAPIModel to automatically wrap IPv6 literals in square brackets (e.g., http://[::1]:8080/) when constructing URLs, while maintaining correct behavior for IPv4 literals and hostnames.
  • Documentation Updates: Updated both English and Chinese documentation to clearly state host_ip support for IPv6 and explain the automatic bracket wrapping mechanism in generated URLs.
  • Enhanced Unit Tests: Added new unit tests to comprehensively cover the initialization and URL generation behavior of BaseAPIModel with IPv6 literals and hostnames.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • ais_bench/benchmark/models/api_models/base_api.py
    • Imported the ipaddress module to facilitate IP address parsing.
    • Modified the _get_base_url method to parse host_ip using ipaddress.ip_address and automatically wrap IPv6 literals in square brackets for URL construction.
    • Ensured localhost is handled correctly without modification.
  • docs/source_en/base_tutorials/all_params/models.md
    • Updated the description for host_ip to explicitly mention IPv6 support (e.g., ::1).
    • Added a note explaining that IPv6 literals will be automatically wrapped in brackets in generated URLs.
  • docs/source_zh_cn/base_tutorials/all_params/models.md
    • Updated the description for host_ip in Chinese to explicitly mention IPv6 support (e.g., ::1).
    • Added a note in Chinese explaining that IPv6 literals will be automatically wrapped in brackets in generated URLs.
  • tests/UT/models/api_models/test_base_api.py
    • Added ipv6_kwargs to the setUp method for IPv6 test cases.
    • Introduced test_init_with_ipv6_host_ip to verify BaseAPIModel initialization with an IPv6 host_ip.
    • Added test_get_base_url_with_ipv6_host_ip to test URL construction for IPv6.
    • Included test_get_base_url_with_hostname to ensure correct URL construction for hostnames like localhost.
Activity
  • The pull request was created by GaoHuaZhang to fix an issue with IPv6 support.
  • The author has provided a detailed description covering motivation, modifications, associated test results, and a checklist.
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
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

This pull request correctly adds support for IPv6 addresses in host_ip and updates the documentation accordingly. However, the implementation has a critical bug where it fails to handle hostnames other than localhost, which will cause a ValueError. I've provided a code suggestion to fix this by using a try-except block to gracefully handle hostnames. I've also recommended adding a unit test for generic hostnames to improve test coverage and prevent future regressions.

kwargs = self.default_kwargs.copy()
kwargs["host_ip"] = "localhost"
model = self.model_class(**kwargs)
self.assertEqual(model._get_base_url(), "http://localhost:8000/")
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The new tests cover localhost, but they don't cover other hostnames (e.g., example.com). The current implementation in base_api.py would fail for such hostnames. It's good practice to add a test case for this scenario to prevent future regressions.

I recommend adding another test case for a generic hostname:

    def test_get_base_url_with_generic_hostname(self):
        kwargs = self.default_kwargs.copy()
        kwargs["host_ip"] = "my-service.local"
        model = self.model_class(**kwargs)
        self.assertEqual(model._get_base_url(), "http://my-service.local:8000/")

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
if isinstance(ip, ipaddress.IPv6Address):
host = f"[{ip}]"
except ValueError:
# Not an IP address, so it's a hostname. Use it as is.
Copy link
Collaborator

Choose a reason for hiding this comment

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

[review] we should add warning to user

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The IP address format issue is verified and a message is displayed during model building. The value error here is caused only by the "localhost" address, and no additional log message is required.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes URL construction for service-based API model backends so host_ip works correctly with IPv6 literals (bracketed in URLs), and updates docs/tests accordingly.

Changes:

  • Update BaseAPIModel._get_base_url() to detect IPv6 literals via ipaddress.ip_address() and wrap them in [] when building base_url.
  • Add unit tests covering IPv6 (::1) and hostname (localhost) host_ip behaviors.
  • Update EN/ZH docs to clarify IPv6 host_ip support and bracketed URL generation.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
ais_bench/benchmark/models/api_models/base_api.py Make base URL building IPv6-aware by bracket-wrapping IPv6 literals.
tests/UT/models/api_models/test_base_api.py Add tests for IPv6 base URL construction and hostname compatibility.
docs/source_zh_cn/base_tutorials/all_params/models.md Document IPv6 host_ip support and bracket behavior (ZH).
docs/source_en/base_tutorials/all_params/models.md Document IPv6 host_ip support and bracket behavior (EN).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

| `retry` | Int | Maximum number of retries after failing to connect to the server. Valid range: [0, 1000] |
| `api_key` | String | Custom API key, default is an empty string. Only supports the `VLLMCustomAPI` and `VLLMCustomAPIChat` model type. |
| `host_ip` | String | Server IP address, supporting valid IPv4 or IPv6, e.g., `127.0.0.1` |
| `host_ip` | String | Server IP address, supporting valid IPv4 or IPv6, e.g., `127.0.0.1`, `::1`. When using an IPv6 literal, the tool automatically wraps it in brackets when building URLs, for example: `http://[::1]:8080/` |
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

This parameter description now says “Server IP address” and only mentions IPv4/IPv6 literals, but the tool also supports hostname values (at least localhost, and the implementation falls back to treating any non-IP string as a hostname). Consider updating the wording to “host/IP” and explicitly stating which hostname forms are supported, so users don’t assume hostnames are invalid.

Suggested change
| `host_ip` | String | Server IP address, supporting valid IPv4 or IPv6, e.g., `127.0.0.1`, `::1`. When using an IPv6 literal, the tool automatically wraps it in brackets when building URLs, for example: `http://[::1]:8080/` |
| `host_ip` | String | Server host/IP address. Supports hostnames such as `localhost` and other DNS-resolvable hostnames, as well as valid IPv4 or IPv6 literals, e.g., `127.0.0.1`, `::1`. When using an IPv6 literal, the tool automatically wraps it in brackets when building URLs, for example: `http://[::1]:8080/` |

Copilot uses AI. Check for mistakes.
| `retry` | Int | 连接服务端失败后的最大重试次数。合法范围:[0, 1000] |
| `api_key` | String | 自定义API key,默认是空字符串。仅支持 `VLLMCustomAPI``VLLMCustomAPIChat` 模型类型。 |
| `host_ip` | String | 服务端 IP 地址,支持合法 IPv4 或 IPv6,例如:`127.0.0.1` |
| `host_ip` | String | 服务端 IP 地址,支持合法 IPv4 或 IPv6,例如:`127.0.0.1``::1`。当使用 IPv6 字面量时,访问 URL 中会自动转换为带方括号的形式,例如:`http://[::1]:8080/` |
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

这里将 host_ip 描述为“IP 地址”且仅强调 IPv4/IPv6 字面量,但实际使用中也支持主机名(至少 localhost,实现也会把非 IP 字符串按 hostname 处理)。建议将描述改为“主机名或 IP”,并明确哪些 hostname 形式被支持,避免用户误解。

Suggested change
| `host_ip` | String | 服务端 IP 地址,支持合法 IPv4 IPv6,例如:`127.0.0.1``::1`。当使用 IPv6 字面量时,访问 URL 中会自动转换为带方括号的形式,例如:`http://[::1]:8080/` |
| `host_ip` | String | 服务端主机名或 IP 地址,支持主机名(如 `localhost`)以及合法 IPv4 / IPv6 字面量,例如:`127.0.0.1``::1`。非 IP 字符串将按主机名解析。当使用 IPv6 字面量时,访问 URL 中会自动转换为带方括号的形式,例如:`http://[::1]:8080/` |

Copilot uses AI. Check for mistakes.
Comment on lines +118 to +126
# For IPv6 literals, wrap in brackets when constructing the URL.
host = self.host_ip
try:
ip = ipaddress.ip_address(host)
if isinstance(ip, ipaddress.IPv6Address):
host = f"[{ip}]"
except ValueError:
# Not an IP address, so it's a hostname. Use it as is.
pass
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

The new hostname fallback (treating non-IP host_ip as a hostname) doesn’t fully deliver the PR’s stated goal of supporting arbitrary hostnames in configs: _validate_model_cfg currently only allows host_ip == "localhost" or a valid IP literal, and rejects other hostnames/domains. Either widen config validation to accept hostnames (and document it), or tighten this logic/doc/PR description to only support localhost + IP literals so behavior is consistent end-to-end.

Copilot uses AI. Check for mistakes.
@GaoHuaZhang GaoHuaZhang temporarily deployed to smoke-test-approval March 13, 2026 06:32 — with GitHub Actions Inactive
@SJTUyh SJTUyh merged commit 76105e9 into AISBench:master Mar 13, 2026
10 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 在model配置中设置host_ip(ipv6的地址)、host_port,工具拉起报错

4 participants