Skip to content

revert: restore the RPC layer (pkg/rpc)#207

Merged
rustatian merged 3 commits into
masterfrom
revert/connectrpc
Jul 15, 2026
Merged

revert: restore the RPC layer (pkg/rpc)#207
rustatian merged 3 commits into
masterfrom
revert/connectrpc

Conversation

@rustatian

@rustatian rustatian commented Jul 14, 2026

Copy link
Copy Markdown
Member

Reverts #203. Connect-RPC is being reverted across the org: the rpc plugin serves goridge/net-rpc again, so the codec, client and their tests return. Also restores the protobuf dependency and keeps errors at v1.5.0.

Summary by CodeRabbit

  • New Features
    • Added Goridge-backed net/rpc codec support for Proto, JSON, Gob, and raw byte payloads.
    • Introduced a new RPC benchmark with a local TCP server and profiling endpoint.
  • Documentation
    • Updated README to describe the project as a high-performance PHP-to-Golang codec library.
    • Added rpc package documentation.
  • Tests
    • Expanded cross-platform RPC tests for correctness, error handling, concurrency, binary payloads, and codec edge cases, plus a new PHP interop test.
  • Chores
    • Extended CI and the test target to run additional ./pkg/rpc tests with coverage output.

Copilot AI review requested due to automatic review settings July 14, 2026 20:09
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1bee99c0-339c-4482-b800-0354f424e308

📥 Commits

Reviewing files that changed from the base of the PR and between bc874c8 and fce398c.

📒 Files selected for processing (3)
  • pkg/rpc/codec.go
  • tests/message.proto
  • tests/php_test_files/issue_185.php
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/message.proto
  • pkg/rpc/codec.go

📝 Walkthrough

Walkthrough

Adds Goridge-backed net/rpc client and server codecs with protobuf, JSON, Gob, and raw payload support. It adds integration and edge-case tests, PHP interoperability coverage, a benchmark, updated documentation, and RPC test execution across local and platform CI workflows.

Changes

RPC codec integration

Layer / File(s) Summary
Server codec and frame serialization
pkg/rpc/codec.go, pkg/rpc/doc.go, go.mod
Implements Goridge-backed request decoding, response encoding, codec selection, error handling, pooling, and closure behavior.
Client codec request and response handling
pkg/rpc/client.go
Adds client frame writing, response parsing, protobuf/JSON/Gob/raw decoding, pooling, and idempotent closure.
RPC format and integration validation
tests/message.proto, pkg/rpc/*_test.go, tests/issues/*, tests/php_test_files/*
Tests serialization formats, errors, concurrency, edge cases, protobuf contracts, and PHP RPC interoperability.
Benchmark, documentation, and test commands
benchmarks/main.go, README.md, Makefile, .github/workflows/*
Adds an RPC benchmark and pprof server, documents net/rpc usage, and runs ./pkg/rpc tests locally and in CI.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant ClientCodec
  participant Relay
  participant ServerCodec
  participant GoService
  Client->>ClientCodec: Write RPC request
  ClientCodec->>Relay: Send encoded Goridge frame
  Relay->>ServerCodec: Receive request frame
  ServerCodec->>GoService: Decode and dispatch method
  GoService-->>ServerCodec: Return response
  ServerCodec->>Relay: Send encoded response frame
  Relay-->>ClientCodec: Receive response
  ClientCodec-->>Client: Decode response body
Loading

Possibly related PRs

Suggested labels: C-enhancement

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description states the revert reason and main changes, but it omits the required template sections and checklist details. Add the required headings for Reason, Description, License Acceptance, and PR Checklist, and fill in the checklist items.
Docstring Coverage ⚠️ Warning Docstring coverage is 17.65% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: restoring the RPC layer and related pkg/rpc code.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch revert/connectrpc

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.

@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 55.26316% with 204 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.37%. Comparing base (c33a954) to head (fce398c).

Files with missing lines Patch % Lines
tests/message.pb.go 33.81% 90 Missing and 2 partials ⚠️
pkg/rpc/codec.go 61.27% 70 Missing and 9 partials ⚠️
pkg/rpc/client.go 70.79% 22 Missing and 11 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master     #207       +/-   ##
===========================================
- Coverage   90.59%   71.37%   -19.22%     
===========================================
  Files           5        8        +3     
  Lines         372      828      +456     
===========================================
+ Hits          337      591      +254     
- Misses         21      201      +180     
- Partials       14       36       +22     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Reverts the prior removal of the pkg/rpc layer by restoring the Goridge-backed net/rpc ServerCodec/ClientCodec, reintroducing protobuf support used by RPC tests/benchmarks, and updating CI/docs to reflect the restored RPC workflow.

Changes:

  • Re-adds pkg/rpc codecs and their unit/integration tests.
  • Restores protobuf-based test fixtures and benchmark harnesses.
  • Updates README, Makefile, and CI workflows to include ./pkg/rpc tests and the protobuf dependency.

Reviewed changes

Copilot reviewed 16 out of 19 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
tests/php_test_files/issue_185.php PHP-side RPC call fixture used by an issue regression test.
tests/php_test_files/composer.json Adds Composer requirement for the PHP Goridge package.
tests/php_test_files/composer.lock Locks PHP dependencies for the PHP test fixtures.
tests/message.proto Reintroduces protobuf schema used by Go RPC tests.
tests/message.pb.go Generated Go types from tests/message.proto.
tests/issues/issue_185_test.go Adds Go test exercising PHP↔Go RPC interoperability for Issue #185.
README.md Reframes docs and sample usage around net/rpc + Goridge codec.
pkg/rpc/doc.go Package documentation for the restored RPC layer.
pkg/rpc/codec.go Restored server-side net/rpc codec implementation.
pkg/rpc/codec_edge_test.go Edge/regression tests for codec safety and close behavior.
pkg/rpc/client.go Restored client-side net/rpc codec implementation.
pkg/rpc/client_server_test.go End-to-end codec tests across proto/json/raw/error/concurrency.
Makefile Adds go test invocation for ./pkg/rpc.
go.mod Restores google.golang.org/protobuf dependency.
go.sum Updates checksums for restored Go deps.
benchmarks/main.go Restores benchmark harness for RPC codec and pprof server.
.github/workflows/linux.yml Adds ./pkg/rpc to Linux CI test matrix/coverage.
.github/workflows/macos.yml Adds ./pkg/rpc to macOS CI test matrix/coverage.
.github/workflows/windows.yml Adds ./pkg/rpc to Windows CI test matrix.
Files not reviewed (1)
  • tests/message.pb.go: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/rpc/codec.go
Comment thread pkg/rpc/codec.go
Comment thread pkg/rpc/codec.go
Comment thread pkg/rpc/codec.go
Comment thread tests/php_test_files/issue_185.php Outdated
Comment thread tests/issues/issue_185_test.go
Comment thread tests/issues/issue_185_test.go
Comment thread tests/issues/issue_185_test.go
Comment thread README.md

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🧹 Nitpick comments (4)
benchmarks/main.go (1)

122-124: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

Set timeouts on http.Server.

The http.Server for debugging is constructed without timeouts (e.g., ReadHeaderTimeout, ReadTimeout). Even though this is a local benchmark server, setting timeouts is a good practice to prevent resource exhaustion and connection leaks.

♻️ Proposed refactor
-	return Server{srv: &http.Server{Handler: mux}}
+	return Server{srv: &http.Server{
+		Handler:           mux,
+		ReadHeaderTimeout: 5 * time.Second,
+		ReadTimeout:       10 * time.Second,
+	}}
🤖 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 `@benchmarks/main.go` around lines 122 - 124, Update the http.Server
construction in the Server initializer to configure appropriate request
timeouts, including ReadHeaderTimeout and ReadTimeout, while preserving the
existing Handler mux assignment.

Source: Linters/SAST tools

README.md (1)

72-79: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove unnecessary blank identifier assignment.

The _ = conn assignment is unnecessary since conn is already used in the following rpc.ServeCodec call.

♻️ Proposed refactor
 	for {
 		conn, err := ln.Accept()
 		if err != nil {
 			continue
 		}
-		_ = conn
 		go rpc.ServeCodec(goridgeRpc.NewCodec(conn))
 	}
🤖 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 `@README.md` around lines 72 - 79, Remove the unnecessary `_ = conn` assignment
from the listener loop; retain the existing `conn` usage in the subsequent
`rpc.ServeCodec` call.
pkg/rpc/codec.go (1)

89-89: 📐 Maintainability & Code Quality | 🔵 Trivial

Repeated codec.(byte) assertions.

codec.(byte) is re-asserted independently at each case after the codec == nil guard. Extracting it once into a local byte variable after Line 100 would avoid the repetition without behavior change.

Also applies to: 103-103, 124-124, 154-154, 176-176, 179-179

🤖 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 `@pkg/rpc/codec.go` at line 89, In the codec handling function, extract the
guarded codec value from the repeated codec.(byte) assertions into one local
byte variable after the codec == nil check, then reuse that variable in the
affected WriteFlags and related case branches without changing behavior.
pkg/rpc/client.go (1)

116-140: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Frame not returned to pool on early-return error paths.

None of the four error returns in ReadResponseHeader (Receive failure, CRC failure, bad options count, offset-out-of-bounds) call c.putFrame/release the fetched frame, unlike codec.go's ReadRequestHeader, which explicitly frees the frame before every error return. Impact is muted here because net/rpc.Client.input() closes the whole client on a header-read error, but it's worth aligning for consistency and to avoid holding onto the pool object longer than necessary.

🤖 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 `@pkg/rpc/client.go` around lines 116 - 140, Update
ClientCodec.ReadResponseHeader to return the frame obtained by getFrame through
c.putFrame before each error return: Receive failure, CRC verification failure,
invalid options count, and payload offset out of bounds. Keep the successful
path assigning c.frame unchanged, matching ReadRequestHeader’s frame-release
behavior.
🤖 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.

Inline comments:
In `@pkg/rpc/codec_edge_test.go`:
- Around line 95-104: Update ReadResponseBody to guard c.frame before the
deferred putFrame reset, so calling ReadResponseBody(nil) before a successful
ReadResponseHeader cannot panic. Preserve the existing frame cleanup behavior
when c.frame is non-nil.

In `@pkg/rpc/codec.go`:
- Around line 282-289: Move the defer registering c.putFrame(c.frame) in
Codec.ReadRequestBody before the out == nil check, preserving the existing nil
return while ensuring the frame is returned to the pool for unresolved or
malformed requests.
- Around line 102-108: Update the Proto branch in the response encoding logic
around proto.Marshal to use a safe two-value assertion for body as
proto.Message. On mismatch, return through c.handleError with an appropriate
error instead of panicking, while preserving the existing marshal-error handling
for valid protobuf replies.

In `@tests/issues/issue_185_test.go`:
- Around line 34-42: Update the goroutine in the issue_185 test to create a
context with a finite timeout and pass it to exec.CommandContext instead of
context.Background(). Ensure the context is canceled after use, while preserving
the existing PHP command and assertions.

In `@tests/message.proto`:
- Line 4: Update the go_package option in message.proto so its package-name
segment is tests, matching the generated code and existing tests.* callers;
preserve the current local import path segment.

In `@tests/php_test_files/issue_185.php`:
- Around line 3-4: Update the autoload require in the PHP test script to resolve
vendor/autoload.php relative to the script’s own directory rather than the
process working directory, preserving the existing Composer vendor location used
by issue_185_test.go.

---

Nitpick comments:
In `@benchmarks/main.go`:
- Around line 122-124: Update the http.Server construction in the Server
initializer to configure appropriate request timeouts, including
ReadHeaderTimeout and ReadTimeout, while preserving the existing Handler mux
assignment.

In `@pkg/rpc/client.go`:
- Around line 116-140: Update ClientCodec.ReadResponseHeader to return the frame
obtained by getFrame through c.putFrame before each error return: Receive
failure, CRC verification failure, invalid options count, and payload offset out
of bounds. Keep the successful path assigning c.frame unchanged, matching
ReadRequestHeader’s frame-release behavior.

In `@pkg/rpc/codec.go`:
- Line 89: In the codec handling function, extract the guarded codec value from
the repeated codec.(byte) assertions into one local byte variable after the
codec == nil check, then reuse that variable in the affected WriteFlags and
related case branches without changing behavior.

In `@README.md`:
- Around line 72-79: Remove the unnecessary `_ = conn` assignment from the
listener loop; retain the existing `conn` usage in the subsequent
`rpc.ServeCodec` call.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 804be455-edc7-4502-8ea9-0a0092e617d8

📥 Commits

Reviewing files that changed from the base of the PR and between c33a954 and 75e9ece.

⛔ Files ignored due to path filters (3)
  • go.sum is excluded by !**/*.sum
  • tests/message.pb.go is excluded by !**/*.pb.go
  • tests/php_test_files/composer.lock is excluded by !**/*.lock
📒 Files selected for processing (16)
  • .github/workflows/linux.yml
  • .github/workflows/macos.yml
  • .github/workflows/windows.yml
  • Makefile
  • README.md
  • benchmarks/main.go
  • go.mod
  • pkg/rpc/client.go
  • pkg/rpc/client_server_test.go
  • pkg/rpc/codec.go
  • pkg/rpc/codec_edge_test.go
  • pkg/rpc/doc.go
  • tests/issues/issue_185_test.go
  • tests/message.proto
  • tests/php_test_files/composer.json
  • tests/php_test_files/issue_185.php

Comment thread pkg/rpc/codec_edge_test.go
Comment thread pkg/rpc/codec.go
Comment thread pkg/rpc/codec.go
Comment thread tests/issues/issue_185_test.go
Comment thread tests/message.proto Outdated
Comment thread tests/php_test_files/issue_185.php Outdated
Use the two-value type assertion for the reply body in the CodecProto
branch and return an error response instead of an unrecovered panic when
the body is not a proto.Message, matching the safe pattern already used
in ReadRequestBody/ReadResponseBody.

Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
@rustatian rustatian self-assigned this Jul 15, 2026
…hRelay

- ReadRequestBody: return the frame stored by ReadRequestHeader when
  net/rpc drains an unresolvable request with a nil out, instead of
  leaking it from the pool (guard the nil frame to keep the direct-call
  path panic-free).
- NewCodecWithRelay: initialize bPool/fPool so get()/getFrame() no longer
  panic on a zero-value sync.Pool.
- tests: resolve issue_185.php autoload relative to __DIR__ and align
  message.proto go_package name with the generated `tests` package.

Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
@rustatian
rustatian merged commit 5dab214 into master Jul 15, 2026
15 checks passed
@rustatian
rustatian deleted the revert/connectrpc branch July 15, 2026 17:15
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.

2 participants