Skip to content

refactor: Extract shared patterns from IPC server handlers#132

Merged
2witstudios merged 1 commit intomainfrom
pu/refactor-ipc-server
Mar 10, 2026
Merged

refactor: Extract shared patterns from IPC server handlers#132
2witstudios merged 1 commit intomainfrom
pu/refactor-ipc-server

Conversation

@2witstudios
Copy link
Owner

@2witstudios 2witstudios commented Mar 10, 2026

Summary

  • Introduce StreamMode enum and parse_stream_request helper to consolidate duplicated read-parse-dispatch logic across attach, grid, and status streaming handlers
  • Extract dispatch_request method to flatten the connection loop from nested match to single dispatch
  • Net: +129/-150 lines, reducing Cx 55 and improving 17% density

Baseline (from churn analysis)

Metric Before
Cx 55
Density 17%
Churn 14

Test plan

  • Build and run cargo test to verify compilation
  • Verify IPC attach, grid subscribe, and status subscribe still work
  • Run npx aidd churn to compare metrics

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Improved internal code organization and consistency of streaming request handling to enhance maintainability and reduce code duplication.

Introduce StreamMode enum and parse_stream_request helper to consolidate
duplicated read-parse-dispatch logic across attach, grid, and status
streaming handlers. Extract dispatch_request method to flatten the
connection loop. Reduces cyclomatic complexity and improves code density.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai
Copy link

coderabbitai bot commented Mar 10, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a985255a-730b-4fcd-b13b-06d36d492818

📥 Commits

Reviewing files that changed from the base of the PR and between 9bbaf05 and 4095e21.

📒 Files selected for processing (1)
  • crates/pu-engine/src/ipc_server.rs

📝 Walkthrough

Walkthrough

Refactors the IPC server request handling to introduce streaming mode abstractions and centralized dispatch logic. Replaces inline request handling with a generic dispatch_request function that routes requests through appropriate streaming handlers (attach, grid, status) based on request type classification.

Changes

Cohort / File(s) Summary
IPC Server Streaming Refactoring
crates/pu-engine/src/ipc_server.rs
Introduces StreamMode enum and from_request helper to classify request types. Adds centralized dispatch_request function replacing inline handling. Implements dedicated streaming handlers (handle_attach_stream, handle_grid_stream, handle_status_stream) with parse_stream_request for message parsing. Standardizes write operations (write_output_chunks, write_response) on unified IpcWriter type. Consolidates status snapshot generation via send_status helper. Restructures request parsing, error handling, streaming mode derivation, and loop termination logic.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 Hop, hop! The dispatch now flows so clean,
Streaming modes dance in between,
Old handlers scattered, now unified streams,
Refactored logic fulfills our dreams! 🌟

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch pu/refactor-ipc-server

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.

@2witstudios 2witstudios merged commit a1fb1d1 into main Mar 10, 2026
4 of 5 checks passed
@2witstudios 2witstudios deleted the pu/refactor-ipc-server branch March 10, 2026 15: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.

1 participant