Skip to content

core: brain list --limit accepts non-numbers and has no cap while brain_list clamps to 1-100 #1351

Closed

Description

@schlessera

Part of #1341.

Context

CLI: limit: flags.limit ? parseInt(flags.limit as string, 10) : 20 (packages/core/src/cli/commands/list.ts:29). --limit abc yields NaN; --limit 100000 is passed through. MCP: Math.min(Math.max(1, params.limit), MAX_LIST_LIMIT) (packages/core/src/mcp-server.ts:441). The same operation behaves differently per surface.

Approved limit policy

2026-10-09: CLI policy A approved. brain list --limit accepts a whole integer in 1..100, defaults to 20 when omitted, and rejects malformed, fractional, missing-value and out-of-range input as a usage error (exit 1, correcting the original issue's exit-2 proposal). Do not partially parse 10abc or 1.5, silently clamp, or reach SQL with an invalid limit. This deliberately tightens prior CLI behavior, including formerly accepted values above 100.

2026-10-09: MCP policy C approved. Both CLI and brain_list require an integer in 1..100, default 20. MCP rejects fractional/out-of-range values rather than clamping. This explicitly authorizes the breaking tightening of its numeric input schema and behavior. Retain existing successful result shapes and existing MCP error conventions; no new error envelope is selected.

Scope

  • Implement the approved CLI policy with one shared range constant and validation/normalization helper used by both surfaces. Use the same strict integer/range policy for both. CLI parsing must validate the whole supplied string; MCP schema and shared runtime validation enforce the numeric integer/range constraints.

Out of scope

  • Other flags (separate issue).

Acceptance criteria

  • Real CLI tests verify omission defaults to 20; 1 and 100 succeed; abc, 10abc, fractions, missing value, zero, negatives and 101 fail with usage exit 1 in human and JSON modes, without executing a list query. The fix-removed mutation fails the intended behavioral assertion.
  • CLI and MCP share one limit constant and one strict validator. Real MCP registration/transport tests verify default 20 and boundaries 1/100 succeed; fractions, zero, negative and 101 fail through existing error conventions. Schema snapshots record the intentional integer/range constraints; successful documents/warnings shapes remain unchanged. A removed range/integer guard causes the corresponding independent assertion to fail.
  • docs/integration-contract.md states the limit behaviour.

Verification

bun run test packages/core

Contract impact

Yes: CLI input handling is deliberately tightened by the maintainer ruling. Use contract and breaking, a CONTRACT: commit, a same-commit integration-contract update and a changeset describing the before/after CLI limit behavior; follow pre-1.0 breaking version policy. The MCP schema/behavior tightening from numeric clamping to strict 1..100 integers is also explicitly approved. Document both surfaces and update schema snapshots only for that selected change.

Blocked by #1349

2026-10-09: sequenced against the other code-quality issues to avoid overlapping edits; see the epic's planned-order comment.
2026-10-09 decision pass: both limit policies are now settled; remove needs: decision and add agent-ready. Keep blocked while #1349 remains open; ready specification does not permit bypassing the implementation dependency.

Activity

  1. added
    type: fix
    area: core
    area: mcp
    priority: p2
    needs: decision
    contract
    on Oct 9, 2026
  2. added
    blocked
    breaking
    on Oct 9, 2026
  3. schlessera commented on Oct 9, 2026

    @schlessera
    OwnerAuthor

    Decision (maintainer, 2026-10-09): CLI limit policy

    Choose A: brain list --limit requires an integer from 1 through 100, defaulting to 20 when omitted. Reject malformed, fractional, missing-value and out-of-range input with the existing usage-error exit 1. Do not partially parse strings or clamp silently. This is an approved tightening of the previous CLI contract; record it as breaking with the contract update and changeset.

    The body now follows this choice. MCP's published numeric/clamping behavior still needs an explicit preservation-or-tightening choice so shared validation cannot change it accidentally. Keep needs: decision and the dependency on #1349; no readiness yet.

  4. added
    agent-ready
    and removed
    needs: decision
    on Oct 9, 2026
  5. schlessera commented on Oct 9, 2026

    @schlessera
    OwnerAuthor

    Decision (maintainer, 2026-10-09): MCP policy C

    Require integers from 1 through 100 on both CLI and MCP, default 20. MCP rejects fractions and out-of-range values instead of clamping. This explicitly approves the breaking MCP input-schema/behavior tightening alongside the recorded CLI tightening; retain current success shapes and MCP error conventions. Use one constant and strict shared validator, with full-string CLI parsing.

    The body includes boundary/invalid-input tests, deliberate schema snapshot updates, mutation evidence and contract documentation requirements. No decision remains: remove needs: decision and add agent-ready. Keep blocked on open #1349 and retain contract/breaking; implementation must follow that dependency.

  6. removed
    blocked
    on Oct 10, 2026
  7. schlessera commented on Oct 10, 2026

    @schlessera
    OwnerAuthor

    Unblocked: #1349 merged in #1468 (62cf4d6), its only listed blocker.

  8. self-assigned this
    on Oct 10, 2026
  9. schlessera commented on Oct 10, 2026

    @schlessera
    OwnerAuthor

    Claimed (claim token wi-1351-a7). Working on branch fix/1351-list-limit.

  10. added this to the 0.41.0 milestone on Oct 10, 2026
  11. schlessera commented on Oct 10, 2026

    @schlessera
    OwnerAuthor

    PR: #1470 (branch fix/1351-list-limit).

  12. schlessera commented on Oct 10, 2026

    @schlessera
    OwnerAuthor

    Done in #1470, squash-merged as 6cb61cb on main (milestone 0.41.0).

    • brain list --limit and brain_list share DEFAULT_LIST_LIMIT (20), MAX_LIST_LIMIT (100) and listLimitSchema in packages/core/src/lib/ops/read.ts. The CLI requires a full integer literal, validates before opening the database and exits 1 in human and JSON modes. brain_list's schema is integer, 1–100, default 20, and other values are rejected through the SDK's invalid-input convention.
    • The contract doc, the MCP schema snapshot (only brain_list.limit) and the changeset (minor, 0.40.0 → 0.41.0, no major) record the before and after.
    • Failing-first: 21 new tests failed on the old source. Mutations: removing the range guard, removing the integer guard, partial parsing, and validating after the DB open each failed their own assertion. The receipts are in the PR body.
    • CI for head cfa9234 was all green, tested on merge 8d687a7, whose tree matches the squash's. Main-push CI also passed. The website push failure is the known ci: verify the main-push website rebuild after the fixture-source correction #1447 one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agent-readyarea: corearea: mcpbreakingcontractpriority: p2type: fix

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions