fix(proxy): strip unsupported IPv6 CIDRs from NO_PROXY#2000
Open
pi-dal wants to merge 2 commits intoMoonshotAI:mainfrom
Open
fix(proxy): strip unsupported IPv6 CIDRs from NO_PROXY#2000pi-dal wants to merge 2 commits intoMoonshotAI:mainfrom
pi-dal wants to merge 2 commits intoMoonshotAI:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a startup crash in environments where NO_PROXY/no_proxy contains IPv6 CIDR blocks by normalizing the proxy environment before httpx client initialization.
Changes:
- Strip unsupported IPv6 CIDR entries from
NO_PROXY/no_proxyduringnormalize_proxy_env(). - Add a regression test that reproduces the
httpx.Client()initialization failure with IPv6 CIDR values inNO_PROXY.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/kimi_cli/utils/proxy.py |
Adds IPv6 CIDR detection/filtering for NO_PROXY/no_proxy to prevent httpx.InvalidURL during startup. |
tests/utils/test_proxy.py |
Adds a regression test ensuring httpx.Client() initializes successfully after proxy env normalization. |
Comments suppressed due to low confidence (1)
src/kimi_cli/utils/proxy.py:41
- The
normalize_proxy_envdocstring only describes thesocks://→socks5://rewrite, but the function now also mutatesNO_PROXY/no_proxyto strip unsupported IPv6 CIDRs. Please update the docstring to reflect the additional behavior and why it’s needed (httpx startup crash with IPv6 CIDR patterns).
def normalize_proxy_env() -> None:
"""Rewrite ``socks://`` to ``socks5://`` in proxy environment variables.
Many proxy tools (V2RayN, Clash, etc.) set ``ALL_PROXY=socks://...``, but
httpx and aiohttp only recognise ``socks5://``. Since ``socks://`` is
effectively an alias for ``socks5://``, this function performs a safe
in-place replacement so that downstream HTTP clients work correctly.
"""
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+99
to
+100
| client = httpx.Client() | ||
| client.close() |
There was a problem hiding this comment.
Prefer using with httpx.Client() as client: here so the client is always closed even if an assertion is added later or an exception occurs after construction. This avoids leaking resources in the test process.
Suggested change
| client = httpx.Client() | |
| client.close() | |
| with httpx.Client() as client: | |
| assert client is not None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issue
Resolve #1959
Description
NO_PROXY/no_proxybeforehttpxclient initialization.localhost,127.0.0.1, and::1.Verification
uv run pytest tests/utils/test_proxy.pyuv run ruff check src/kimi_cli/utils/proxy.py tests/utils/test_proxy.pyHTTP_PROXY=http://127.0.0.1:7890andNO_PROXY=localhost,127.0.0.1,::1,fd00::/8,fe80::/10;httpx.Client()now initializes successfully after normalization.make testNotes
make ai-testcurrently fails on the existingtests_ai/scripts/main.yamlreference tokimi_cli.tools.multiagent:Task, which is unrelated to this change.make checkstill reports existing non-blockingtydiagnostics and fails on pre-existing web Biome lint errors inweb/src/features/chat/components/approval-dialog.tsxandweb/src/features/chat/components/session-files-panel.tsx.Checklist
make gen-changelogto update the changelog.make gen-docsto update the user documentation.