[Router] Consolidate ConnectionMode enum to core module#11937
[Router] Consolidate ConnectionMode enum to core module#11937slin1237 merged 1 commit intosgl-project:mainfrom
Conversation
Summary of ChangesHello @YouNeedCryDear, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly refactors the handling of connection modes within the router by consolidating the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This is a great refactoring that consolidates the ConnectionMode enum, removing duplication and improving type safety by embedding the port configuration directly in the enum. The changes are well-executed across the codebase, with all necessary updates to imports and pattern matching. The use of serde attributes ensures backward compatibility for configuration files, which is a thoughtful touch.
I have one suggestion for a potential improvement to make the handling of ConnectionMode even more consistent.
b281f12 to
f9ada2c
Compare
5219380 to
c23f810
Compare
use config clone for grpc worker init
c23f810 to
500b986
Compare
Summary
Consolidates the
ConnectionModeenum definition from the configuration layer (config/types.rs) to the core domain layer (core/worker.rs), eliminating code duplication and improving type safety.Motivation
Addresses #11901
Previously,
ConnectionModeexisted in two separate locations:config/types.rs- Simple enum for configuration serializationcore/worker.rs- Enum with additional fields for worker communicationThis duplication required conversion logic and created a maintenance burden. The consolidation establishes a single source of truth and improves the domain model.
Changes
Core Changes
ConnectionModeenum fromconfig/types.rstocore/worker.rsSerializeandDeserializetraits for configuration interopGrpcvariant from unit to struct:Grpc { port: Option<u16> }convert_connection_mode()function fromworker_manager.rsUpdated Files
sgl-router/src/config/types.rs- Removed ConnectionMode definitionsgl-router/src/core/worker.rs- Added ConnectionMode with serde supportsgl-router/src/config/validation.rs- Updated imports and pattern matchingsgl-router/src/core/worker_manager.rs- Updated imports, removed conversion functionsgl-router/src/lib.rs- Updated imports and return typessgl-router/src/main.rs- Updated importssgl-router/src/routers/factory.rs- Updated imports and pattern matchingsgl-router/src/routers/router_manager.rs- Updated imports and pattern matchingsgl-router/src/server.rs- Updated imports and pattern matchingPattern Matching Updates
All pattern matches updated to handle struct variant:
Benefits
Backward Compatibility
{"type": "grpc"}still deserializes correctly{"type": "grpc", "port": 50051}supported via optional port fieldTesting
tests/directoryAdditional Notes
This change makes it easier to add an explicit
--connection-modeCLI flag in the future if needed, as ConnectionMode now has proper serialization support throughout the codebase.Integration Test Screenshots
4 Llama 3.1 8B with HTTP router and service discovery

1P2D Llama 4 Mav with gRPC router
