Skip to content

fix(kimi-code): format IPv6 server origins correctly#1402

Open
VectorPeak wants to merge 1 commit into
MoonshotAI:mainfrom
VectorPeak:fix-server-ipv6-origin
Open

fix(kimi-code): format IPv6 server origins correctly#1402
VectorPeak wants to merge 1 commit into
MoonshotAI:mainfrom
VectorPeak:fix-server-ipv6-origin

Conversation

@VectorPeak

Copy link
Copy Markdown

Related Issue

No linked issue; this is a focused, reproducible CLI server URL formatting bug fix.

Problem

serverOrigin(host, port) builds the shared server origin used by multiple kimi server subcommands. It currently interpolates the host directly into a URL string:

`http://${host}:${port}`

That works for IPv4 addresses and hostnames, but it produces an invalid URL for IPv6 literal hosts. IPv6 addresses contain : characters, so a raw value such as ::1 conflicts with the URL's host:port separator:

serverOrigin('::1', 58627)
// before: http://::1:58627
// expected: http://[::1]:58627

This is not just a display issue. serverOrigin() is shared by server lifecycle, daemon, status, kill, and health-check paths, so a malformed origin can be passed into new URL(...) / fetch-style call sites that require bracketed IPv6 host literals.

The behavior should match URL syntax and the existing server access URL formatter: IPv6 literal hosts must be wrapped in brackets, while IPv4 addresses and hostnames should remain unchanged.

What changed

  • Updated serverOrigin() to format IPv6 hosts with the existing formatHostForUrl() helper.
  • Preserved already-bracketed IPv6 hosts so they are not double-wrapped.
  • Preserved IPv4 and hostname output unchanged.
  • Added focused tests for raw IPv6, already-bracketed IPv6, and IPv4 server origins.
  • Added a patch changeset for @moonshot-ai/kimi-code.

Validation run locally:

node -e "for (const u of ['http://::1:58627','http://[::1]:58627']) { try { console.log(u + ' -> ' + new URL(u).href) } catch (e) { console.log(u + ' -> ' + e.name + ': ' + e.message) } }"
corepack pnpm --filter @moonshot-ai/kimi-code exec vitest run test/cli/server/server.test.ts -t "wraps IPv6 hosts when formatting server origins"
corepack pnpm --filter @moonshot-ai/kimi-code exec vitest run test/cli/server/server.test.ts
git diff --check

Observed URL-construction proof:

http://::1:58627 -> TypeError: Invalid URL
http://[::1]:58627 -> http://[::1]:58627/

Note: local validation used ELECTRON_SKIP_BINARY_DOWNLOAD=1 / ELECTRON_SKIP_DOWNLOAD=1; this parser/URL formatting test path does not require the Electron binary.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Jul 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2b1236a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.

1 participant