Skip to content

fix(cli): reject malformed numeric options - #3596

Open
GautamSharma99 wants to merge 1 commit into
letta-ai:mainfrom
GautamSharma99:fix/strict-cli-numeric-options
Open

fix(cli): reject malformed numeric options#3596
GautamSharma99 wants to merge 1 commit into
letta-ai:mainfrom
GautamSharma99:fix/strict-cli-numeric-options

Conversation

@GautamSharma99

Copy link
Copy Markdown

Summary

Fixes the CLI numeric-option parsing paths described in #3586.

The agents, environments, and messages subcommands previously used three copies of a parseInt()-based helper. That accepted numeric prefixes such as 10junk, allowed zero and negative pagination values, and silently replaced fully nonnumeric user input with a default. The dream timeout performed a separate partial validation and therefore accepted values such as 30seconds.

This PR routes those options through the existing shared CLI integer-flag owner and makes its parsing strict:

  • require the entire trimmed value to contain decimal digits;
  • require a JavaScript safe integer greater than zero;
  • enforce explicit command bounds;
  • use defaults only when an option is omitted;
  • return an actionable error and exit code 1 for supplied invalid values.

Bounds

  • pagination page sizes (--limit): 1 through 1,000;
  • transcript pagination (--max-pages): 1 through 1,000;
  • dream reflection timeout (--timeout): 1 through 86,400 seconds.

The CLI help now documents these ranges next to each option.

Implementation details

  • Strengthens parsePositiveIntFlag() instead of introducing another numeric parser. Existing callers retain undefined for an omitted flag, while malformed prefixes, fractions, unsafe integers, and out-of-range values now throw a consistent validation error.
  • Removes the duplicated parseLimit() implementations from agents, environments, and messages.
  • Parses numeric values before settings initialization and backend construction. Invalid input therefore cannot authenticate, initialize settings, or issue an API request.
  • Keeps each command's existing omitted-value defaults: agents 20, environments 50, message search 10, message list 20, transcript page size 100, transcript max pages 200, and dream timeout 1,500 seconds.

Tests

Added table-driven coverage for:

  • valid complete integers, surrounding whitespace, omitted values, and upper boundaries;
  • zero and negative values;
  • decimals;
  • trailing junk;
  • whitespace-only and NaN input;
  • integers beyond Number.MAX_SAFE_INTEGER;
  • values above each explicit command limit;
  • early failure before settings initialization or message/environment backend calls.

Validation performed:

  • bun test src/cli/flag-utils.test.ts src/cli/subcommands/agents.test.ts src/cli/subcommands/environments.test.ts src/cli/subcommands/messages.test.ts src/cli/subcommands/dream.test.ts (52 passed)
  • bun run check (all 12 checks passed)

Closes #3586

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.

CLI numeric options accept negative values and trailing junk

2 participants