Skip to content

fix(kimi-code): reject malformed server CLI numbers#1401

Open
VectorPeak wants to merge 1 commit into
MoonshotAI:mainfrom
VectorPeak:fix-server-cli-numbers
Open

fix(kimi-code): reject malformed server CLI numbers#1401
VectorPeak wants to merge 1 commit into
MoonshotAI:mainfrom
VectorPeak:fix-server-cli-numbers

Conversation

@VectorPeak

@VectorPeak VectorPeak commented Jul 5, 2026

Copy link
Copy Markdown

Related Issue

No linked issue; this is a focused, reproducible CLI parser bug fix.

Problem

kimi server run --port <port> and the shared internal server option parser accepted numeric values through Number.parseInt(raw, 10). That is a poor fit for CLI option validation because parseInt is a prefix parser, not a strict decimal-integer validator: once it has read a valid numeric prefix, it stops at the first non-digit character and returns the prefix instead of rejecting the whole input.

As a result, malformed values could be silently accepted:

123abc -> 123
1.5    -> 1
10ms   -> 10

For server options, that behavior is surprising and potentially risky. A user who mistypes a port or idle grace value would not get feedback that the input is invalid; the server could instead start with a different value than the one the user intended. This is especially visible for --port, where a malformed value can still pass the later port-range check after being truncated, and for --idle-grace-ms, where a time-like suffix such as 10ms looks readable but is reduced to 10.

The shared parser is also used below the direct CLI entry point, so this is not only a display or help-text issue. The loose conversion happens before the rest of the server option object is built, which means downstream server lifecycle code receives a normalized number and cannot distinguish a genuinely valid integer from a partially parsed malformed string.

The expected behavior for these server numeric options is stricter: either the entire input is a decimal integer, or the option should be rejected. That keeps CLI typos visible, preserves the existing valid cases such as 8080 and 1000, and avoids treating unit suffixes, decimals, or mixed strings as valid configuration.

What changed

  • Added a shared complete-decimal-integer parser for server CLI numeric options.
  • Updated parsePort and parseIdleGraceMs to reject values unless the entire input is decimal digits and fits a safe integer.
  • Preserved existing defaults, valid integer inputs, and the --port range check.
  • Added focused parser tests for malformed --port and --idle-grace-ms values.

Validation run locally:

corepack pnpm --filter @moonshot-ai/kimi-code exec vitest run test/cli/server/server.test.ts -t "shared parsers stay strict"
corepack pnpm --filter @moonshot-ai/kimi-code exec vitest run test/cli/server/server.test.ts
git diff --check

Note: local install used ELECTRON_SKIP_BINARY_DOWNLOAD=1 / ELECTRON_SKIP_DOWNLOAD=1 because the unrelated Electron postinstall binary download hit ECONNRESET; this parser 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: 1c5e27d

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

@VectorPeak VectorPeak marked this pull request as ready for review July 5, 2026 16:45
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