Skip to content

[codex] split protocol crate modules#287

Merged
munezaclovis merged 1 commit into
mainfrom
codex/decouple-protocol-crate
Jun 19, 2026
Merged

[codex] split protocol crate modules#287
munezaclovis merged 1 commit into
mainfrom
codex/decouple-protocol-crate

Conversation

@munezaclovis

@munezaclovis munezaclovis commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Splits the protocol crate out of its single large lib.rs into focused private modules while keeping the existing flat public API intact.

The new modules cover requests, responses, events, managed resource update DTOs, transport helpers, errors, and tests. Existing callers can continue using protocol::DaemonResponse, protocol::write_line, and the other current re-exports unchanged.

Validation

  • cargo fmt --all
  • cargo nextest run -p protocol
  • cargo clippy -p protocol --all-targets --all-features --locked -- -D warnings
  • cargo check --workspace --all-targets --locked
  • git diff --check -- crates/protocol/src
  • cargo nextest run --workspace --locked --no-fail-fast

The full local workspace suite ran 881 tests: 880 passed, 1 failed, 3 skipped. The failure was daemon::daemon_foundation::dns_resolver_falls_back_when_preferred_port_is_unavailable; it also failed in isolation because the local PV daemon was already bound to DNS port 35353 (/Users/clovismuneza/.pv/bin/pv daemon:run). This appears local-environment related, so CI should give the clean-run signal.

Summary by CodeRabbit

Release Notes

  • Refactor

    • Reorganized protocol module structure from monolithic to dedicated submodules for improved maintainability and code organization.
  • New Features

    • Added structured daemon protocol support with event streaming, request/response messaging, and asynchronous transport layer.
    • Introduced managed resource update tracking and status reporting capabilities.
    • Added comprehensive protocol error handling.

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The crates/protocol crate is refactored from a single monolithic lib.rs into seven submodules: error, event, request, response, transport, update_check, and tests. All previously inline types and helpers are extracted into their respective modules and re-exported from lib.rs. PROTOCOL_VERSION remains 2.

Changes

Protocol crate modularization

Layer / File(s) Summary
Module declarations, re-exports, and ProtocolError
crates/protocol/src/lib.rs, crates/protocol/src/error.rs
lib.rs declares all submodules and re-exports the public API via pub use; error.rs defines ProtocolError with Json and Frame variants wrapping serde_json::Error and LinesCodecError.
Request, response, and event message types
crates/protocol/src/request.rs, crates/protocol/src/response.rs, crates/protocol/src/event.rs
request.rs adds DaemonRequest and DaemonCommand; response.rs adds DaemonResponse with constructor helpers (ok, accepted, error, ok_update_check), field accessors, and ResponseStatus; event.rs adds the lifetime-parameterized DaemonEvent enum.
Managed resource update check types
crates/protocol/src/update_check.rs
Defines ManagedResourceUpdateCheck, ManagedResourceUpdateCheckTrack, ManagedResourceUpdateRevocation, ManagedResourceUpdateBlocker, and ManagedResourceUpdateStatus, plus From conversions from resources::* counterparts.
Framed transport and write_line
crates/protocol/src/transport.rs
Defines DaemonTransport as a Framed<Stream, LinesCodec> type alias, a transport() constructor, and write_line() which JSON-serializes a value and sends it over the framed stream, returning ProtocolError on failure.
Protocol and transport tests
crates/protocol/src/tests.rs
Covers request serialization, DaemonResponse round-trips for accepted and ok_update_check with nested ManagedResourceUpdateCheck, and an async test verifying write_line framing over an in-memory duplex stream.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • prvious/pv#253: The daemon is refactored to directly import protocol::ProtocolError and use the new request/response/event/transport APIs defined in this PR.
  • prvious/pv#282: Adds DaemonCommand::ManagedResourceUpdateCheck and DaemonResponse.update_check contract, which this PR implements in request.rs, response.rs, and update_check.rs.
  • prvious/pv#284: Uses the DaemonEvent, DaemonRequest/DaemonResponse, ManagedResourceUpdateCheck, and write_line/ProtocolError types defined in this PR for managed-resource update job lifecycle serialization.

Poem

🐇 Hoppity hop through the protocol crate,
One monolith split into modules — how great!
error, event, request, and more,
Each in its own tidy, well-organized drawer.
The frames and the JSON now dance in their place,
All re-exported with elegance and grace! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.18% 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 PR title '[codex] split protocol crate modules' clearly and concisely summarizes the main change: refactoring the protocol crate from a monolithic file into focused modules.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 codex/decouple-protocol-crate

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 and usage tips.

@codspeed-hq

codspeed-hq Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 7 untouched benchmarks


Comparing codex/decouple-protocol-crate (f978dad) with main (ee55e51)

Open in CodSpeed

@munezaclovis munezaclovis marked this pull request as ready for review June 19, 2026 23:02

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes — This PR splits the protocol crate into focused private modules while preserving the flat public API used by daemon and CLI callers.

  • Split protocol definitions by concernProtocolError, request types, response types, events, transport helpers, and managed-resource update DTOs now live in separate private modules.
  • Preserve existing public importssrc/lib.rs re-exports the same protocol::... names, including DaemonResponse, write_line, DaemonTransport, update DTOs, and PROTOCOL_VERSION.
  • Move protocol tests unchanged in intent — the serialization and transport tests moved from inline lib.rs tests into tests.rs.
  • Verified focused behaviorcargo test -p protocol --locked and cargo check -p protocol --all-targets --locked both passed during review.

Pullfrog  | View workflow run | Using GPT𝕏

@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.

🧹 Nitpick comments (1)
crates/protocol/src/update_check.rs (1)

34-42: ⚡ Quick win

Prefer top-level imports over repeated fully-qualified paths.

Lines 34-42 and 54-101 use std::fmt::... and resources::... directly; pull these into use statements to align with repo Rust style and reduce repetition.

Suggested cleanup
 use serde::{Deserialize, Serialize};
+use std::fmt::{self, Display, Formatter};
+use resources::{
+    ManagedResourceUpdateBlocker as ResourcesManagedResourceUpdateBlocker,
+    ManagedResourceUpdateCheckTrack as ResourcesManagedResourceUpdateCheckTrack,
+    ManagedResourceUpdateRevocation as ResourcesManagedResourceUpdateRevocation,
+    ManagedResourceUpdateStatus as ResourcesManagedResourceUpdateStatus,
+};

-impl std::fmt::Display for ManagedResourceUpdateBlocker {
-    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+impl Display for ManagedResourceUpdateBlocker {
+    fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
         write!(
             formatter,
             "requires PV {}, current PV {}",
             self.minimum_pv_version, self.current_pv_version
         )
     }
 }

-impl From<resources::ManagedResourceUpdateStatus> for ManagedResourceUpdateStatus {
-    fn from(status: resources::ManagedResourceUpdateStatus) -> Self {
+impl From<ResourcesManagedResourceUpdateStatus> for ManagedResourceUpdateStatus {
+    fn from(status: ResourcesManagedResourceUpdateStatus) -> Self {
         match status {
-            resources::ManagedResourceUpdateStatus::Current => Self::Current,
-            resources::ManagedResourceUpdateStatus::UpdateAvailable => Self::UpdateAvailable,
-            resources::ManagedResourceUpdateStatus::Blocked => Self::Blocked,
-            resources::ManagedResourceUpdateStatus::Revoked => Self::Revoked,
-            resources::ManagedResourceUpdateStatus::Unavailable => Self::Unavailable,
+            ResourcesManagedResourceUpdateStatus::Current => Self::Current,
+            ResourcesManagedResourceUpdateStatus::UpdateAvailable => Self::UpdateAvailable,
+            ResourcesManagedResourceUpdateStatus::Blocked => Self::Blocked,
+            ResourcesManagedResourceUpdateStatus::Revoked => Self::Revoked,
+            ResourcesManagedResourceUpdateStatus::Unavailable => Self::Unavailable,
         }
     }
 }

As per coding guidelines, "PREFER top-level imports over local imports or fully qualified names in Rust".

Also applies to: 54-101

🤖 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 `@crates/protocol/src/update_check.rs` around lines 34 - 42, The code uses
fully-qualified paths like std::fmt::Display, std::fmt::Formatter, and
std::fmt::Result in the impl block for ManagedResourceUpdateBlocker (lines
34-42) and additional fully-qualified resources:: paths elsewhere (lines
54-101). Add use statements at the top of the file to import these types
(std::fmt::Display, std::fmt::Formatter, std::fmt::Result, and any resources::
types used), then replace all fully-qualified paths throughout the file with the
imported names to reduce repetition and align with the repository's Rust coding
style guidelines.

Source: Coding guidelines

🤖 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 `@crates/protocol/src/update_check.rs`:
- Around line 34-42: The code uses fully-qualified paths like std::fmt::Display,
std::fmt::Formatter, and std::fmt::Result in the impl block for
ManagedResourceUpdateBlocker (lines 34-42) and additional fully-qualified
resources:: paths elsewhere (lines 54-101). Add use statements at the top of the
file to import these types (std::fmt::Display, std::fmt::Formatter,
std::fmt::Result, and any resources:: types used), then replace all
fully-qualified paths throughout the file with the imported names to reduce
repetition and align with the repository's Rust coding style guidelines.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f430921a-4c23-4468-a47a-9b6b0697eada

📥 Commits

Reviewing files that changed from the base of the PR and between ee55e51 and f978dad.

📒 Files selected for processing (8)
  • crates/protocol/src/error.rs
  • crates/protocol/src/event.rs
  • crates/protocol/src/lib.rs
  • crates/protocol/src/request.rs
  • crates/protocol/src/response.rs
  • crates/protocol/src/tests.rs
  • crates/protocol/src/transport.rs
  • crates/protocol/src/update_check.rs

@munezaclovis munezaclovis merged commit 88b3a1a into main Jun 19, 2026
4 checks passed
@munezaclovis munezaclovis deleted the codex/decouple-protocol-crate branch June 19, 2026 23:35
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