Skip to content

[validation,mcp] fix: reject oversized numeric session inputs - #105

Merged
Wangmerlyn merged 2 commits into
mainfrom
codex/mcp-finite-numeric-validation
Jun 28, 2026
Merged

[validation,mcp] fix: reject oversized numeric session inputs#105
Wangmerlyn merged 2 commits into
mainfrom
codex/mcp-finite-numeric-validation

Conversation

@Wangmerlyn

@Wangmerlyn Wangmerlyn commented Jun 28, 2026

Copy link
Copy Markdown
Owner

Summary

  • Reject oversized public interval and VRAM values as validation errors instead of overflow/internal failures.
  • Validate blocking CLI VRAM before torch import/probing, widen MCP vram schema to string or integer bytes, and keep REST/JSON-RPC/MCP/Python behavior aligned.
  • Document the bounded public contract and add plan/test coverage for huge ints, digit strings, decimal caps, and service boundary behavior.

Verification

  • PYTHONPATH=$PWD/src pytest tests/utilities/test_session_config.py tests/utilities/test_humanized_input.py tests/mcp/test_server.py tests/mcp/test_http_api.py tests/test_cli_service_commands.py tests/global_controller/test_contract.py -q -> 259 passed
  • PYTHONPATH=$PWD/src pytest tests -q -> 360 passed, 11 skipped
  • PYTHONPATH=$PWD/src mkdocs build -> passed with known Material/MkDocs and unlisted-plan warnings
  • pre-commit run --all-files -> passed
  • git diff --check -> passed

Local Review

  • Local spec review and code-quality re-review completed with no remaining issues.

Summary by CodeRabbit

  • New Features

    • Added clearer limits for public numeric inputs across the CLI, service API, and MCP interfaces.
    • --interval values now have an explicit maximum, and VRAM values are capped at 1 PiB equivalent.
  • Bug Fixes

    • Oversized or invalid numeric inputs are now rejected with user-friendly validation errors instead of runtime overflow failures.
    • Validation is applied earlier in request handling, reducing the chance of partial session setup.
  • Documentation

    • Updated guides and reference docs to reflect the new input limits and response behavior.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@Wangmerlyn, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 51 minutes and 11 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 860e3d47-e662-42dd-8758-0412b164cb28

📥 Commits

Reviewing files that changed from the base of the PR and between 6c2b340 and 7b4f904.

📒 Files selected for processing (3)
  • docs/plans/mcp-finite-numeric-validation.md
  • tests/mcp/test_server.py
  • tests/test_cli_service_commands.py
📝 Walkthrough

Walkthrough

Adds PUBLIC_INTERVAL_MAX_SECONDS (from threading.TIMEOUT_MAX) and PUBLIC_VRAM_MAX_BYTES (1 PiB) as explicit upper bounds. validate_interval and humanized_input parsing enforce these caps using Decimal arithmetic. CLI, MCP server schema, and HTTP API surfaces wire the new constants. Tests and documentation are updated across all layers.

Changes

Finite Numeric Validation for Interval and VRAM

Layer / File(s) Summary
Public bound constants and validate_interval cap
src/keep_gpu/utilities/session_config.py, src/keep_gpu/utilities/humanized_input.py
Adds PUBLIC_INTERVAL_MAX_SECONDS from threading.TIMEOUT_MAX and PUBLIC_VRAM_MAX_BYTES (1 PiB) with label constants. validate_interval gains a new upper-bound check raising ValueError for oversized values.
Decimal-based VRAM parsing with 1 PiB cap
src/keep_gpu/utilities/humanized_input.py
Refactors _bytes_to_float32_elements to accept int/float/Decimal, adds _vram_too_large_message() and public-numeric-string helpers, updates parse_size to distinguish digit-only vs. decimal inputs using Decimal arithmetic, and routes integer inputs in parse_vram_to_elements directly without float() conversion.
CLI _validate_cli_vram helper and usage
src/keep_gpu/cli.py
Introduces _validate_cli_vram that calls parse_vram_to_elements and raises typer.BadParameter on failure. Wires it into _run_blocking and start, replacing prior inline validation.
MCP tool schema bounds and OverflowError handling
src/keep_gpu/mcp/server.py
Imports PUBLIC_VRAM_MAX_BYTES and PUBLIC_INTERVAL_MAX_SECONDS; updates start_keep input schema to add maximum constraints on vram (integer type support) and interval. Catches OverflowError as SessionInputError.
Tests
tests/utilities/test_session_config.py, tests/utilities/test_humanized_input.py, tests/global_controller/test_contract.py, tests/mcp/test_server.py, tests/mcp/test_http_api.py, tests/test_cli_service_commands.py
Adds boundary and rejection tests for validate_interval, parse_size/parse_vram_to_elements, GlobalGPUController contract, JSON-RPC and HTTP API oversized inputs, MCP tools/call oversized vram, and CLI start/blocking mode oversized inputs.
Documentation
AGENTS.md, README.md, docs/concepts/architecture.md, docs/getting-started.md, docs/guides/*, docs/reference/*, docs/plans/mcp-finite-numeric-validation.md
Updates all user-facing and internal docs to reflect the new interval and VRAM caps, and adds a new implementation plan document.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Wangmerlyn/KeepGPU#66: Introduced the start/session-start surfaces and schemas (start_keep, /api/sessions) that this PR now hardens with numeric upper-bound validation.

Poem

🐇 A rabbit checked the numbers one fine day,
Found intervals too big could go astray.
One PiB for VRAM, runtime wait the cap —
No overflow sneaks past this careful chap!
NaN and Infinity? Rejected! Shoo!
Decimal arithmetic sees the whole thing through. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.51% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: rejecting oversized numeric session inputs, including validation and MCP-related paths.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/mcp-finite-numeric-validation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (3)
docs/plans/mcp-finite-numeric-validation.md (1)

109-119: 📐 Maintainability & Code Quality | 🔵 Trivial

Task 4 file list omits docs/guides/python.md.

The plan's Task 4 lists documentation files to modify but does not include docs/guides/python.md, which was updated with the new interval and vram_to_keep bounds documentation. Add it to the file list so the plan accurately reflects all touched docs.

   - Modify: `docs/guides/cli.md`
   - Modify: `docs/guides/mcp.md`
+  - Modify: `docs/guides/python.md`
   - Modify: `docs/reference/cli.md`
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/plans/mcp-finite-numeric-validation.md` around lines 109 - 119, The Task
4 documentation file list in the plan is missing docs/guides/python.md, which
was also updated with the new interval and vram_to_keep bounds details. Update
the file list in the plan’s Task 4 section to include docs/guides/python.md
alongside the other documentation files, keeping the list aligned with the
touched docs.
tests/mcp/test_server.py (1)

528-528: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Make the schema type assertion order-insensitive.

This locks the test to one JSON Schema serialization order even though ["string", "integer"] and ["integer", "string"] are equivalent. Prefer asserting the set so harmless schema construction changes do not fail the test.

♻️ Proposed fix
-    assert start_schema["properties"]["vram"]["type"] == ["string", "integer"]
+    assert set(start_schema["properties"]["vram"]["type"]) == {"string", "integer"}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/mcp/test_server.py` at line 528, The schema assertion in the test for
start_schema["properties"]["vram"]["type"] is too order-dependent; update the
check to be order-insensitive so equivalent JSON Schema arrays in any
serialization order pass. Locate the assertion in the test around the
start_schema validation and compare the type values as an unordered collection
rather than a fixed list.
tests/test_cli_service_commands.py (1)

550-550: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Drop the result.exception assertion from this test.

The observable CLI contract here is the exit code and rendered message. Asserting on CliRunner.invoke()'s captured exception couples the test to Click/Typer internals and can fail on harmless error-handling refactors.

♻️ Proposed fix
     assert result.exit_code == 1
-    assert result.exception is not None
     assert message in result.output
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_cli_service_commands.py` at line 550, The test is too tightly
coupled to Click/Typer internals by asserting on result.exception; remove that
assertion and keep the test focused on the observable CLI contract. Update the
relevant CLI test in the test case around CliRunner.invoke() so it only checks
the exit code and the rendered output/message, without relying on exception
capture.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@docs/plans/mcp-finite-numeric-validation.md`:
- Around line 109-119: The Task 4 documentation file list in the plan is missing
docs/guides/python.md, which was also updated with the new interval and
vram_to_keep bounds details. Update the file list in the plan’s Task 4 section
to include docs/guides/python.md alongside the other documentation files,
keeping the list aligned with the touched docs.

In `@tests/mcp/test_server.py`:
- Line 528: The schema assertion in the test for
start_schema["properties"]["vram"]["type"] is too order-dependent; update the
check to be order-insensitive so equivalent JSON Schema arrays in any
serialization order pass. Locate the assertion in the test around the
start_schema validation and compare the type values as an unordered collection
rather than a fixed list.

In `@tests/test_cli_service_commands.py`:
- Line 550: The test is too tightly coupled to Click/Typer internals by
asserting on result.exception; remove that assertion and keep the test focused
on the observable CLI contract. Update the relevant CLI test in the test case
around CliRunner.invoke() so it only checks the exit code and the rendered
output/message, without relying on exception capture.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 835af7a1-831b-467c-a345-c0bd9777602e

📥 Commits

Reviewing files that changed from the base of the PR and between 54d2a12 and 6c2b340.

📒 Files selected for processing (20)
  • AGENTS.md
  • README.md
  • docs/concepts/architecture.md
  • docs/getting-started.md
  • docs/guides/cli.md
  • docs/guides/mcp.md
  • docs/guides/python.md
  • docs/plans/mcp-finite-numeric-validation.md
  • docs/reference/api.md
  • docs/reference/cli.md
  • src/keep_gpu/cli.py
  • src/keep_gpu/mcp/server.py
  • src/keep_gpu/utilities/humanized_input.py
  • src/keep_gpu/utilities/session_config.py
  • tests/global_controller/test_contract.py
  • tests/mcp/test_http_api.py
  • tests/mcp/test_server.py
  • tests/test_cli_service_commands.py
  • tests/utilities/test_humanized_input.py
  • tests/utilities/test_session_config.py

@Wangmerlyn

Copy link
Copy Markdown
Owner Author

Resolved CodeRabbit nitpicks in 7b4f904:

  • Added docs/guides/python.md to the plan file list.
  • Made the MCP vram schema type assertion order-insensitive.
  • Removed the CliRunner.result.exception assertion and kept the test focused on exit code/output.

Post-fix verification:

  • PYTHONPATH=$PWD/src pytest tests -q -> 360 passed, 11 skipped
  • PYTHONPATH=$PWD/src mkdocs build -> passed with known warnings
  • pre-commit run --all-files -> passed
  • git diff --check -> passed

@Wangmerlyn
Wangmerlyn merged commit 2211fc6 into main Jun 28, 2026
5 checks passed
@Wangmerlyn
Wangmerlyn deleted the codex/mcp-finite-numeric-validation branch June 28, 2026 07:01
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