refactor: Reduce copying of HTTP headers - #269
Conversation
|
|
@CodeRabbit review |
✅ Action performedReview finished.
|
WalkthroughThe PR adds the shared ChangesTyped header propagation
Estimated code review effort: 4 (Complex) | ~45 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
crates/protocol/src/metadata.rs (1)
196-198: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDocument
Metadata::from_headers.
Metadata::from_headersis a public API. Replace// Create Metadatawith a Rust documentation comment. State that the method parses recognized headers and does not retain the input map for forwarding.As per coding guidelines, “Add concise Rust documentation comments for public structs, enums, methods, and module intent.”
Proposed change
impl Metadata { - // Create Metadata + /// Builds metadata from recognized HTTP headers. + /// + /// The caller can retain `headers` in [`Self::http_headers`] when forwarding is required. pub fn from_headers(headers: &http::HeaderMap) -> Self {🤖 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/metadata.rs` around lines 196 - 198, Replace the `// Create Metadata` comment above `Metadata::from_headers` with a concise Rust documentation comment explaining that the method parses recognized headers and does not retain the input `HeaderMap` for forwarding.Source: Coding guidelines
crates/libsy-llm-client/src/client.rs (1)
1624-1633: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winCover repeated header values.
This fixture only uses
HeaderMap::insert. Add a non-reserved header with twoappendcalls, then assert that both values reach the upstream request. The documentedHeaderMapiterator yields one item for each associated value, andRequestBuilder::headerappends each item. (docs.rs)Suggested regression coverage
headers.insert( "accept-encoding", http::HeaderValue::from_static("gzip, br"), ); + headers.append( + "x-test-multi", + http::HeaderValue::from_static("one"), + ); + headers.append( + "x-test-multi", + http::HeaderValue::from_static("two"), + ); ... assert!(!received.headers.contains_key("accept-encoding")); + assert_eq!( + received.headers.get_all("x-test-multi").iter().count(), + 2 + );🤖 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/libsy-llm-client/src/client.rs` around lines 1624 - 1633, Extend the header fixture around the existing HeaderMap setup with a non-reserved header added via two append calls, then assert the upstream request receives both values. Verify the forwarding path iterates all associated values from the HeaderMap and passes each through RequestBuilder::header rather than retaining only one value.crates/libsy/Cargo.toml (1)
19-19: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMove
http.workspace = trueto[dev-dependencies].All
httpreferences are inside#[cfg(test)]modules. No production source useshttp.🤖 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/libsy/Cargo.toml` at line 19, Move the http dependency declaration from the production dependency section into [dev-dependencies] in Cargo.toml, preserving the workspace-based version setting so test-only references continue to resolve.
🤖 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/switchyard-py/src/interop/subagent.rs`:
- Around line 22-25: The shared Python-header conversion used by
is_subagent_request and PyAlgorithm::run must become fallible and bounded:
return PyResult<bool>, reject invalid names or values, case-insensitive
duplicate names, and capacity overflow, and map every failure to PyValueError
using fallible insertion rather than HeaderMap::extend/append. Update the
PyAlgorithm::run caller to propagate the result and add tests covering each
rejected input.
---
Nitpick comments:
In `@crates/libsy-llm-client/src/client.rs`:
- Around line 1624-1633: Extend the header fixture around the existing HeaderMap
setup with a non-reserved header added via two append calls, then assert the
upstream request receives both values. Verify the forwarding path iterates all
associated values from the HeaderMap and passes each through
RequestBuilder::header rather than retaining only one value.
In `@crates/libsy/Cargo.toml`:
- Line 19: Move the http dependency declaration from the production dependency
section into [dev-dependencies] in Cargo.toml, preserving the workspace-based
version setting so test-only references continue to resolve.
In `@crates/protocol/src/metadata.rs`:
- Around line 196-198: Replace the `// Create Metadata` comment above
`Metadata::from_headers` with a concise Rust documentation comment explaining
that the method parses recognized headers and does not retain the input
`HeaderMap` for forwarding.
🪄 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: eb46242d-b4ad-4874-b15f-632721754934
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock,!Cargo.lock
📒 Files selected for processing (14)
Cargo.tomlcrates/libsy-llm-client/Cargo.tomlcrates/libsy-llm-client/src/client.rscrates/libsy/Cargo.tomlcrates/libsy/src/algorithms/subagent_affinity_tests.rscrates/libsy/src/algorithms/util/subagent.rscrates/protocol/Cargo.tomlcrates/protocol/src/metadata.rscrates/switchyard-py/Cargo.tomlcrates/switchyard-py/src/interop/subagent.rscrates/switchyard-py/src/libsy_bindings.rscrates/switchyard-server/Cargo.tomlcrates/switchyard-server/src/lib.rscrates/switchyard-server/src/routing_log.rs
Use `http::HeaderMap` instead of `BTreeMap`. That means we can use what `axum` gives `switchyard-server` directly. Another benefit is `http` package already normalizes (to lower case) the headers so we don't need that step. In future we will also be able to handle headers with multiple values (`HeaderMap::get_all` vs `get`). Signed-off-by: Graham King <grahamk@nvidia.com>
a649a3f to
05c8528
Compare
Signed-off-by: Graham King <grahamk@nvidia.com>
Signed-off-by: Graham King <grahamk@nvidia.com>
Use
http::HeaderMapinstead ofBTreeMap. That means we can use whataxumgivesswitchyard-serverdirectly.Another benefit is
httppackage already normalizes (to lower case) theheaders so we don't need that step.
In future we will also be able to handle headers with multiple values
(
HeaderMap::get_allvsget).Signed-off-by: Graham King grahamk@nvidia.com
Summary by CodeRabbit