Skip to content

fix(proxy): strip unsupported IPv6 CIDRs from NO_PROXY#2000

Open
pi-dal wants to merge 2 commits intoMoonshotAI:mainfrom
pi-dal:issue-1959-no-proxy-ipv6-cidr
Open

fix(proxy): strip unsupported IPv6 CIDRs from NO_PROXY#2000
pi-dal wants to merge 2 commits intoMoonshotAI:mainfrom
pi-dal:issue-1959-no-proxy-ipv6-cidr

Conversation

@pi-dal
Copy link
Copy Markdown

@pi-dal pi-dal commented Apr 22, 2026

Related Issue

Resolve #1959

Description

  • Strip unsupported IPv6 CIDR entries from NO_PROXY / no_proxy before httpx client initialization.
  • Preserve valid non-CIDR entries such as localhost, 127.0.0.1, and ::1.
  • Add a regression test that reproduces the proxy + IPv6 CIDR startup crash path.

Verification

  • uv run pytest tests/utils/test_proxy.py
  • uv run ruff check src/kimi_cli/utils/proxy.py tests/utils/test_proxy.py
  • Reproduced the original environment shape with HTTP_PROXY=http://127.0.0.1:7890 and NO_PROXY=localhost,127.0.0.1,::1,fd00::/8,fe80::/10; httpx.Client() now initializes successfully after normalization.
  • make test

Notes

  • make ai-test currently fails on the existing tests_ai/scripts/main.yaml reference to kimi_cli.tools.multiagent:Task, which is unrelated to this change.
  • make check still reports existing non-blocking ty diagnostics and fails on pre-existing web Biome lint errors in web/src/features/chat/components/approval-dialog.tsx and web/src/features/chat/components/session-files-panel.tsx.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked the related issue, if any.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have run make gen-changelog to update the changelog.
  • I have run make gen-docs to update the user documentation.

Open in Devin Review

Copilot AI review requested due to automatic review settings April 22, 2026 10:56
Copy link
Copy Markdown
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

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_proxy during normalize_proxy_env().
  • Add a regression test that reproduces the httpx.Client() initialization failure with IPv6 CIDR values in NO_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_env docstring only describes the socks://socks5:// rewrite, but the function now also mutates NO_PROXY/no_proxy to 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 thread tests/utils/test_proxy.py Outdated
Comment on lines +99 to +100
client = httpx.Client()
client.close()
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

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

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

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.

Crash on startup: IPv6 CIDR in NO_PROXY triggers "Invalid port: ':'" in httpx

2 participants