feat(guardrail): apply to request by policy#112
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughThis PR removes model-level ChangesGuardrail resolution migration from model-based to policy-driven
Estimated code review effort🎯 4 (Complex) | ⏱️ ~75 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/proxy/handlers/format_handler.rs (1)
345-348: 💤 Low valueOptional: Simplify error conversion.
The
Ok(expr?)pattern is redundant here. SinceA::Error: From<GatewayError>, the?operator handles the conversion.♻️ Suggested simplification
- let input = input_payload_from_check_payload(payload).map_err(guardrail_bridge_error)?; - Ok(input_payload_to_chat_messages(&input).map_err(guardrail_bridge_error)?) + let input = input_payload_from_check_payload(payload).map_err(guardrail_bridge_error)?; + input_payload_to_chat_messages(&input).map_err(guardrail_bridge_error).map_err(Into::into)Or, keeping the current style consistently:
- Ok(input_payload_to_chat_messages(&input).map_err(guardrail_bridge_error)?) + input_payload_to_chat_messages(&input).map_err(guardrail_bridge_error).map_err(A::Error::from)🤖 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 `@src/proxy/handlers/format_handler.rs` around lines 345 - 348, The return uses the redundant Ok(expr?) pattern: in format_handler.rs replace the final line returning Ok(input_payload_to_chat_messages(&input).map_err(guardrail_bridge_error)?) with a direct propagated result using the ? operator so that input_payload_from_check_payload(...).map_err(guardrail_bridge_error)? is used and then return input_payload_to_chat_messages(&input).map_err(guardrail_bridge_error)? (i.e., drop the outer Ok(...) and rely on ? to convert GatewayError into A::Error); update the function that calls input_payload_from_check_payload and input_payload_to_chat_messages and remove the unnecessary wrapping to keep error handling consistent.
🤖 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 `@src/proxy/guardrails.rs`:
- Around line 257-273: Add the #[fastrace::trace] attribute directly above the
pub(crate) function build_resolved_guardrail_for_stage to enable distributed
tracing for this public request-path function; ensure the fastrace attribute
macro is available in scope (use the #[fastrace::trace] path as specified) and
place it immediately above the function signature so tracing covers the entire
function body.
In `@src/proxy/policies.rs`:
- Around line 20-27: The new public(crate) functions need distributed-tracing
annotations: add #[fastrace::trace] above the stable_route_format function and
likewise annotate any other public(crate) functions introduced in this file (the
ones between the stable_route_format declaration and the block covering lines
~29-137) so they are instrumented for fastrace-based request-path observability;
locate functions by name (e.g., stable_route_format and the other public(crate)
function names in src/proxy/policies.rs) and place the attribute directly above
each function signature.
---
Nitpick comments:
In `@src/proxy/handlers/format_handler.rs`:
- Around line 345-348: The return uses the redundant Ok(expr?) pattern: in
format_handler.rs replace the final line returning
Ok(input_payload_to_chat_messages(&input).map_err(guardrail_bridge_error)?) with
a direct propagated result using the ? operator so that
input_payload_from_check_payload(...).map_err(guardrail_bridge_error)? is used
and then return
input_payload_to_chat_messages(&input).map_err(guardrail_bridge_error)? (i.e.,
drop the outer Ok(...) and rely on ? to convert GatewayError into A::Error);
update the function that calls input_payload_from_check_payload and
input_payload_to_chat_messages and remove the unnecessary wrapping to keep error
handling consistent.
🪄 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: CHILL
Plan: Pro
Run ID: 3c24ee1c-8a63-485f-a29d-99762ba72043
📒 Files selected for processing (10)
src/config/entities/models-schema.jsonsrc/config/entities/models.rssrc/proxy/guardrails.rssrc/proxy/handlers/format_handler.rssrc/proxy/hooks/context.rssrc/proxy/hooks/mod.rssrc/proxy/mod.rssrc/proxy/policies.rstests/admin/models.test.tstests/proxy/guardrail/shared.ts
💤 Files with no reviewable changes (1)
- src/config/entities/models-schema.json
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@src/proxy/policies.rs`:
- Around line 71-75: The PolicyRouteContext is being constructed with the raw
request.route_format which can vary by provider; call
stable_route_format(request.route_format) and assign that result to the
PolicyRouteContext.format so policies see a normalized, provider-agnostic key.
Update the construction of PolicyRouteContext (where route: PolicyRouteContext {
method: &route.method, path: &route.path, format: request.route_format, }) to
use stable_route_format(...) instead of the raw request.route_format so matching
uses the normalized format.
🪄 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: CHILL
Plan: Pro
Run ID: ff3f4cde-a844-4aa2-94ad-3b55a8a3a579
📒 Files selected for processing (2)
src/proxy/handlers/format_handler.rssrc/proxy/policies.rs
🚧 Files skipped from review as they are similar to previous changes (1)
- src/proxy/handlers/format_handler.rs
Summary by CodeRabbit
Breaking Changes
New Features
Tests