Skip to content

fix(rpc): handle notifications and empty batches - #183

Open
Muneerali199 wants to merge 1 commit into
StabilityNexus:mainfrom
Muneerali199:fix/json-rpc-notifications
Open

Muneerali199 wants to merge 1 commit into
StabilityNexus:mainfrom
Muneerali199:fix/json-rpc-notifications

Conversation

@Muneerali199

@Muneerali199 Muneerali199 commented Nov 11, 2026 •

Copy link
Copy Markdown

Summary

Bring the HTTP JSON-RPC handler in line with JSON-RPC 2.0 notification and batch semantics.

  • execute requests with an absent id without returning a JSON-RPC response
  • return HTTP 204 for single notifications and notification-only batches
  • omit notification responses from mixed batches
  • return one -32600 Invalid Request object for an empty batch
  • preserve responses for an explicit id: null

Fixes #177

Testing

  • python -m pytest tests/test_rpc.py -q (20 passed)
  • python -m pytest --cov=minichain --cov-report=term-missing -q (237 passed, 81% total coverage)

Verified with Python 3.11.15, matching the PR workflow. The commit is DCO signed.

AI Usage

This PR contains AI-assisted code and tests. I used OpenCode (GPT-5.6) to help inspect JSON-RPC edge cases and draft the focused coverage. I reviewed the implementation and ran both the RPC and complete project suites locally.

Summary by CodeRabbit

  • Bug Fixes
    • JSON-RPC notifications now execute without returning a response, including when the method is unknown or fails.
    • Batch responses omit notification results; batches with no responses return HTTP 204. Empty batches now return an invalid-request error.
    • Single requests that produce no result now return HTTP 204. An explicit null request ID continues to receive a response.

Signed-off-by: Muneerali199 <alimuneerali245@gmail.com>
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The RPC handler now treats requests without an id as notifications and omits their responses. It rejects empty batches with an invalid-request error and returns HTTP 204 when a single notification or notification-only batch produces no response.

Changes

JSON-RPC request handling

Layer / File(s) Summary
Notification response handling
minichain/rpc.py, tests/test_rpc.py
The handler suppresses responses for requests without an id. Tests cover a transaction notification and confirm that an explicit id: null receives a response.
Batch response handling
minichain/rpc.py, tests/test_rpc.py
The handler omits notification results from batch responses and returns an invalid-request error for an empty batch. Tests cover mixed batches, notification-only batches, and empty batches.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested labels: Python Lang

Suggested reviewers: siddhantcookie

Merge Risk: Minimal · up to 3b3d1

The change makes JSON-RPC notification and empty-batch handling follow the spec and adds tests for those cases. No actionable merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main changes: RPC notification handling and empty batch handling.
Linked Issues check Passed Issue #177 requires notification requests to execute without a response and empty batches to return one -32600 Invalid Request response. minichain/rpc.py now suppresses responses for notification …
Out of Scope Changes check Passed The changes are limited to JSON-RPC notification and batch handling in minichain/rpc.py and focused tests in tests/test_rpc.py. The implementation and tests directly support issue #177. No unrelat…
Full details: Linked Issues check

Explanation

Issue #177 requires notification requests to execute without a response and empty batches to return one -32600 Invalid Request response. minichain/rpc.py now suppresses responses for notification success, errors, and unknown methods; returns HTTP 204 when no response exists; omits notification results from mixed batches; and returns the required error for []. Requests with an explicit id: null remain response-producing. tests/test_rpc.py covers these cases and the reported test suites passed.

Full details: Out of Scope Changes check

Explanation

The changes are limited to JSON-RPC notification and batch handling in minichain/rpc.py and focused tests in tests/test_rpc.py. The implementation and tests directly support issue #177. No unrelated functional changes are shown.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

A rabbit sends a call with no ID,
The server keeps its answer inside.
A batch finds its replies,
Empty brackets get a code,
And the tests hop along beside.

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between e16ae98 and 3b3d1ce.

Files selected for processing: 2

  • minichain/rpc.py
  • tests/test_rpc.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@Muneerali199

Copy link
Copy Markdown
Author

@SIDDHANTCOOKIE this is ready for maintainer review. CodeRabbit approved with no actionable findings. GitHub is holding PR Tests & Coverage for first-time-contributor approval; the identical Python 3.11 coverage command passes locally with 237 tests.

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.

[BUG]: Handle JSON-RPC notifications and empty batches correctly

1 participant