[cli] fix: reject malformed rpc error messages - #240
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces validation for JSON-RPC error envelopes in the CLI, ensuring that error.message is a valid string. If the message is missing or malformed, a ServiceResponseError is raised, which prevents the CLI from triggering a daemon rollback. The changes include updates to the CLI implementation in src/keep_gpu/cli.py, comprehensive unit tests in tests/test_cli_service_commands.py, and updated documentation across AGENTS.md, docs/guides/cli.md, and docs/reference/cli.md. A new validation plan has also been added. There are no review comments to evaluate, and the implementation looks solid.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
Warning Review limit reached
Next review available in: 52 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 reviews. How do review 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 refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR tightens JSON-RPC error handling in the CLI's ChangesError message validation
Estimated code review effort: 2 (Simple) | ~15 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/test_cli_service_commands.py (1)
1632-1635: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueEscape regex metacharacters in
pytest.raises(match=...).
.in"error.message must be a string"is an unescaped regex metacharacter. Works today only because the message happens to contain a literal.at that position; usere.escape()for correctness.🔧 Proposed fix
+import re + with pytest.raises( - cli.ServiceResponseError, match="error.message must be a string" + cli.ServiceResponseError, match=re.escape("error.message must be a string") ):🤖 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` around lines 1632 - 1635, The `pytest.raises(..., match=...)` assertion in the `cli._rpc_call` test uses a raw regex string, so the `.` in `error.message` is treated as a metacharacter. Update the test to escape the expected message properly, using `re.escape()` or an equivalent escaped pattern, while keeping the `ServiceResponseError` assertion and the existing `_rpc_call` call unchanged.Source: Linters/SAST tools
🤖 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 `@tests/test_cli_service_commands.py`:
- Around line 1632-1635: The `pytest.raises(..., match=...)` assertion in the
`cli._rpc_call` test uses a raw regex string, so the `.` in `error.message` is
treated as a metacharacter. Update the test to escape the expected message
properly, using `re.escape()` or an equivalent escaped pattern, while keeping
the `ServiceResponseError` assertion and the existing `_rpc_call` call
unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 3812b0d9-bfb2-4752-987f-59c5632338a1
📒 Files selected for processing (6)
AGENTS.mddocs/guides/cli.mddocs/plans/cli-rpc-error-message.mddocs/reference/cli.mdsrc/keep_gpu/cli.pytests/test_cli_service_commands.py
|
Resolved CodeRabbit nit in Final local verification after the follow-up:
Final local subagent delta review also reported no findings. |
Summary
error.messageas malformed service responsesstart_keeperror envelopes from triggering startup-unavailable daemon rollbackVerification
PYTHONPATH=src pytest tests/test_cli_service_commands.py -qPYTHONPATH=src pytest tests -qmkdocs build --strictpre-commit run --all-files --show-diff-on-failuregit diff --checkNotes
Summary by CodeRabbit
Bug Fixes
Documentation
start,status,stop, andlist-gpuswhen responses or records are malformed.