chore: Upgrade Rust edition to 2024 - #236
Conversation
For if-let chains. Also upgrade `rand` so we have a single version. Signed-off-by: Graham King <grahamk@nvidia.com>
Signed-off-by: Graham King <grahamk@nvidia.com>
WalkthroughThe workspace now uses Rust 2024, resolver 3, and ChangesRust modernization
Estimated code review effort: 3 (Moderate) | ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (3)
crates/switchyard-components/src/stats/accumulator.rs (1)
588-592: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDocument the latency-sampling invariant.
Add a short comment stating that this branch replaces the smallest retained sample so the heap keeps the largest
MAX_LATENCY_SAMPLESvalues.As per coding guidelines, comments are required for non-obvious private helpers and complex logic.
Proposed comment
} else if let Some(smallest_sample) = self.samples.peek() && latency_ms > smallest_sample.0.value() && let Some(mut smallest_sample) = self.samples.peek_mut() { + // Retain the largest samples by replacing the smallest retained value. *smallest_sample = sample; }🤖 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/switchyard-components/src/stats/accumulator.rs` around lines 588 - 592, The replacement branch in the latency sampling logic needs a concise comment documenting its invariant. Add the comment immediately above the branch using self.samples and smallest_sample to state that it replaces the smallest retained sample, keeping the largest MAX_LATENCY_SAMPLES values in the heap.Source: Coding guidelines
crates/switchyard-translation/src/util.rs (1)
425-428: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDocument the stable collision mapping.
mapped_tool_idadds a stable suffix when different raw IDs sanitize to the same candidate. Add a concise comment above the helper so this wire-ID invariant remains explicit.Suggested comment
+// Keeps sanitized tool IDs unique and stable when raw IDs collide. fn mapped_tool_id(As per coding guidelines, add comments for non-obvious private helpers.
🤖 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/switchyard-translation/src/util.rs` around lines 425 - 428, Document the stable collision mapping in the private helper containing the mapped_tool_id logic, immediately above the collision-handling code near used_ids and stable_suffix. Add a concise comment stating that different raw IDs sanitizing to the same candidate receive a stable suffix, preserving the wire-ID invariant.Source: Coding guidelines
crates/switchyard-translation/src/helpers.rs (1)
172-181: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse a let-chain for trailing-frame parsing.
The workspace uses Rust 1.96.1 and edition 2024. Remove
#[allow(clippy::collapsible_if)]and combine the non-empty check with the parser binding.🤖 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/switchyard-translation/src/helpers.rs` around lines 172 - 181, Update the trailing-frame handling around codec.decode_event to remove the #[allow(clippy::collapsible_if)] attribute and combine the frame.trim_end().is_empty() guard with the parse_json_sse_frame binding using a Rust let-chain. Preserve the existing error mapping and event-yielding 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 `@crates/libsy/src/algorithms/rand.rs`:
- Line 82: Replace panicking rand::make_rng() calls at
crates/libsy/src/algorithms/rand.rs:82 and
crates/switchyard-components/src/request_processors/random_routing.rs:118 with
fallible SeedableRng::try_from_rng initialization using SysRng, mapping failures
into each constructor’s existing error type; preserve the current successful
initialization behavior.
In `@crates/switchyard-server/src/config.rs`:
- Around line 736-748: Update the empty API key test around VALID_CONFIG and
error_message so it no longer calls std::env::set_var or std::env::remove_var.
Inject the API-key environment value through the configuration or validation
dependency, or run this case in an isolated subprocess, while preserving the
assertion that an empty API key produces the expected error message.
---
Nitpick comments:
In `@crates/switchyard-components/src/stats/accumulator.rs`:
- Around line 588-592: The replacement branch in the latency sampling logic
needs a concise comment documenting its invariant. Add the comment immediately
above the branch using self.samples and smallest_sample to state that it
replaces the smallest retained sample, keeping the largest MAX_LATENCY_SAMPLES
values in the heap.
In `@crates/switchyard-translation/src/helpers.rs`:
- Around line 172-181: Update the trailing-frame handling around
codec.decode_event to remove the #[allow(clippy::collapsible_if)] attribute and
combine the frame.trim_end().is_empty() guard with the parse_json_sse_frame
binding using a Rust let-chain. Preserve the existing error mapping and
event-yielding behavior.
In `@crates/switchyard-translation/src/util.rs`:
- Around line 425-428: Document the stable collision mapping in the private
helper containing the mapped_tool_id logic, immediately above the
collision-handling code near used_ids and stable_suffix. Add a concise comment
stating that different raw IDs sanitizing to the same candidate receive a stable
suffix, preserving the wire-ID invariant.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: c4eaf03a-2fe1-48cc-94a1-67a5ce3ebf48
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock,!Cargo.lock
📒 Files selected for processing (30)
Cargo.tomlcrates/libsy-llm-client/src/error.rscrates/libsy/src/algorithms/rand.rscrates/libsy/src/algorithms/util/affinity.rscrates/libsy/src/algorithms/util/tool_signals.rscrates/libsy/src/core/algorithm.rscrates/libsy/src/core/driver.rscrates/libsy/src/observability.rscrates/switchyard-components/src/backends/common.rscrates/switchyard-components/src/backends/context_overflow.rscrates/switchyard-components/src/contracts/types.rscrates/switchyard-components/src/intake/client.rscrates/switchyard-components/src/intake/payload.rscrates/switchyard-components/src/request_processors/random_routing.rscrates/switchyard-components/src/response_processors/stats.rscrates/switchyard-components/src/stats/accumulator.rscrates/switchyard-components/tests/support/mod.rscrates/switchyard-py/src/py_serde.rscrates/switchyard-py/src/server_bindings.rscrates/switchyard-server/src/config.rscrates/switchyard-server/src/metrics.rscrates/switchyard-server/src/observability.rscrates/switchyard-translation/src/codecs/anthropic/buffered.rscrates/switchyard-translation/src/codecs/anthropic/stream.rscrates/switchyard-translation/src/codecs/openai_chat/buffered.rscrates/switchyard-translation/src/codecs/openai_chat/stream.rscrates/switchyard-translation/src/codecs/responses/buffered.rscrates/switchyard-translation/src/codecs/responses/stream.rscrates/switchyard-translation/src/helpers.rscrates/switchyard-translation/src/util.rs
This gives us if-let chains.
Also upgrade
randso we have a single version of that dependency.Summary by CodeRabbit
Refactor
Chores