feat(protocols): add serde(flatten) to ChatCompletionRequest for engine-specific fields#1119
Conversation
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 55 minutes and 32 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
Hi @DavidBellamy, the DCO sign-off check has failed. All commits must include a To fix existing commits: # Sign off the last N commits (replace N with the number of unsigned commits)
git rebase HEAD~N --signoff
git push --force-with-leaseTo sign off future commits automatically:
|
There was a problem hiding this comment.
Code Review
This pull request updates the ChatCompletionRequest struct in crates/protocols/src/chat.rs to include an other field of type Map<String, Value> with the #[serde(flatten)] attribute. This change allows the struct to capture additional, non-explicitly defined fields from incoming JSON requests. I have no feedback to provide as there were no review comments.
|
thanks for the fix, lgtm |
…uest Adds a [patch.crates-io] override pointing openai-protocol at a fork that adds serde(flatten) to ChatCompletionRequest, matching the existing pattern on CompletionRequest. This allows engine-specific parameters like return_routed_experts to pass through the gateway to workers. Upstream PR: lightseekorg/smg#1119 Remove this patch once the upstream crate publishes with the fix.
|
@slin1237 Thanks for the review! I've addressed the CI failures:
The new workflow runs need maintainer approval to execute (fork PR after force push). Could you approve them? Re: the |
ed64c29 to
46fa164
Compare
…ne-specific fields ChatCompletionRequest silently drops any request fields not explicitly defined in the struct. This prevents engine-specific parameters (e.g. sglang's return_routed_experts for MoE routing replay) from passing through the gateway to backend workers. CompletionRequest already has this flatten catch-all (via its `other` field). This commit makes ChatCompletionRequest consistent by adding the same pattern. Signed-off-by: David <12414531+DavidBellamy@users.noreply.github.com>
46fa164 to
8ac5695
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@crates/protocols/src/chat.rs`:
- Around line 320-322: Add a unit test that verifies serde(flatten) preserves
unknown fields: create a JSON string for the chat request that includes an extra
key like "return_routed_experts": true, deserialize it with serde_json::from_str
into the struct that defines the #[serde(flatten)] pub other: Map<String,
Value>, assert that request.other.get("return_routed_experts") exists and equals
Value::Bool(true), then re-serialize the struct with serde_json::to_string and
assert the resulting JSON contains the "return_routed_experts" key (or that
serde_json::from_str of the re-serialized JSON still yields the same other
entry). Use the struct with the other field and serde_json utilities to
implement the test.
🪄 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: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 19466c72-c51d-4bb7-8982-e8ac869383e1
📒 Files selected for processing (1)
crates/protocols/src/chat.rs
| /// Additional fields not explicitly defined above (e.g. engine-specific parameters) | ||
| #[serde(flatten)] | ||
| pub other: Map<String, Value>, |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Add a round-trip regression test for unknown-field preservation.
Please add a test that deserializes a request with an extra key (e.g., return_routed_experts), asserts it lands in other, and verifies it is present after re-serialization.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@crates/protocols/src/chat.rs` around lines 320 - 322, Add a unit test that
verifies serde(flatten) preserves unknown fields: create a JSON string for the
chat request that includes an extra key like "return_routed_experts": true,
deserialize it with serde_json::from_str into the struct that defines the
#[serde(flatten)] pub other: Map<String, Value>, assert that
request.other.get("return_routed_experts") exists and equals Value::Bool(true),
then re-serialize the struct with serde_json::to_string and assert the resulting
JSON contains the "return_routed_experts" key (or that serde_json::from_str of
the re-serialized JSON still yields the same other entry). Use the struct with
the other field and serde_json utilities to implement the test.
|
Replaced by #1130 (branch renamed to conform to Mergify naming convention). |
Summary
ChatCompletionRequestsilently drops request fields not explicitly defined in the struct. This prevents engine-specific parameters (e.g. sglang'sreturn_routed_expertsfor MoE routing replay) from passing through the gateway to backend workers.CompletionRequestalready has a#[serde(flatten)] pub other: Map<String, Value>catch-all. This PR makesChatCompletionRequestconsistent by adding the same pattern...Default::default(), so the new field is automatically initialized to an empty map with no code changes needed elsewhere.Fixes: sgl-project/sglang#22740
Summary by CodeRabbit