Conversation
📝 WalkthroughWalkthroughRequest body extraction refactored from a custom middleware pattern to Axum's built-in Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/proxy/handlers/chat_completions/mod.rs (1)
35-41: Clean migration toJsonextractor.The
Json<ChatCompletionRequest>extractor provides built-in deserialization with appropriate error responses (HTTP 422 for validation failures).The
Request::new(Body::empty())workaround is acceptable given that all current hook implementations ignore the_reqparameter (confirmed invalidate_model.rs,metric.rs,rate_limit/mod.rs). The TODO appropriately flags this for future cleanup.When addressing the TODO, consider refactoring the
ProxyHook::pre_calltrait method to make theRequestparameter optional or remove it entirely if no hooks actually need it. This would eliminate the need for dummy request construction.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/proxy/handlers/chat_completions/mod.rs` around lines 35 - 41, The handler now uses the Json<ChatCompletionRequest> extractor but still constructs a dummy HTTP Request via Request::new(Body::empty()) before calling HOOK_MANAGER.pre_call; keep the Json extractor, remove the TODO by either (A) keeping the temporary Request but add a clear comment referencing that all current hooks (validate_model.rs, metric.rs, rate_limit/mod.rs) ignore the request and why the dummy is safe, or (B) refactor the hook trait ProxyHook::pre_call to accept an Option<Request<Body>> (or remove the Request parameter) and update HOOK_MANAGER.pre_call and its implementations (validate_model, metric, rate_limit) to accept None so the dummy Request creation can be eliminated—update hook_ctx usage and signatures accordingly to ensure compile-time consistency.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/proxy/handlers/embeddings/mod.rs`:
- Around line 25-36: The embeddings handler is missing the #[fastrace::trace]
decorator required for public handlers; add the #[fastrace::trace] attribute
immediately above the pub async fn embeddings signature to match the
chat_completions handler's tracing setup so this function is instrumented for
distributed tracing (ensure the attribute is imported/available in the module if
needed).
---
Nitpick comments:
In `@src/proxy/handlers/chat_completions/mod.rs`:
- Around line 35-41: The handler now uses the Json<ChatCompletionRequest>
extractor but still constructs a dummy HTTP Request via
Request::new(Body::empty()) before calling HOOK_MANAGER.pre_call; keep the Json
extractor, remove the TODO by either (A) keeping the temporary Request but add a
clear comment referencing that all current hooks (validate_model.rs, metric.rs,
rate_limit/mod.rs) ignore the request and why the dummy is safe, or (B) refactor
the hook trait ProxyHook::pre_call to accept an Option<Request<Body>> (or remove
the Request parameter) and update HOOK_MANAGER.pre_call and its implementations
(validate_model, metric, rate_limit) to accept None so the dummy Request
creation can be eliminated—update hook_ctx usage and signatures accordingly to
ensure compile-time consistency.
🪄 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: 2374f894-9db4-409b-8576-7e3c77ec6dab
📒 Files selected for processing (8)
src/proxy/handlers/chat_completions/mod.rssrc/proxy/handlers/embeddings/mod.rssrc/proxy/middlewares/mod.rssrc/proxy/middlewares/parse_body.rssrc/proxy/mod.rstests/proxy/chat-completions-sim.test.tstests/proxy/chat-completions.test.tstests/proxy/embeddings.test.ts
💤 Files with no reviewable changes (1)
- src/proxy/middlewares/parse_body.rs
| pub async fn embeddings( | ||
| State(_state): State<AppState>, | ||
| Extension(mut request_data): Extension<EmbeddingRequest>, | ||
| mut hook_ctx: HookContext, | ||
| mut request: Request, | ||
| Json(mut request_data): Json<EmbeddingRequest>, | ||
| ) -> Result<Response, EmbeddingError> { | ||
| // PRE CALL HOOKS START | ||
| hook_ctx.insert(RequestModel(request_data.model)); | ||
|
|
||
| let mut request = Request::new(Body::empty()); //TODO | ||
| HOOK_MANAGER | ||
| .pre_call(&mut hook_ctx, &mut request, HOOK_FILTER_ALL) | ||
| .await?; |
There was a problem hiding this comment.
Consistent refactor with chat_completions handler, but missing #[fastrace::trace] decorator.
The Json<EmbeddingRequest> extractor and empty request pattern match the chat_completions handler, which is good for consistency.
However, the embeddings function is missing the #[fastrace::trace] decorator that's present on chat_completions (line 30 in that file). As per coding guidelines, public functions in src/**/*.rs should use this decorator for distributed tracing.
🔧 Proposed fix to add tracing decorator
+#[fastrace::trace]
pub async fn embeddings(
State(_state): State<AppState>,
mut hook_ctx: HookContext,📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| pub async fn embeddings( | |
| State(_state): State<AppState>, | |
| Extension(mut request_data): Extension<EmbeddingRequest>, | |
| mut hook_ctx: HookContext, | |
| mut request: Request, | |
| Json(mut request_data): Json<EmbeddingRequest>, | |
| ) -> Result<Response, EmbeddingError> { | |
| // PRE CALL HOOKS START | |
| hook_ctx.insert(RequestModel(request_data.model)); | |
| let mut request = Request::new(Body::empty()); //TODO | |
| HOOK_MANAGER | |
| .pre_call(&mut hook_ctx, &mut request, HOOK_FILTER_ALL) | |
| .await?; | |
| #[fastrace::trace] | |
| pub async fn embeddings( | |
| State(_state): State<AppState>, | |
| mut hook_ctx: HookContext, | |
| Json(mut request_data): Json<EmbeddingRequest>, | |
| ) -> Result<Response, EmbeddingError> { | |
| // PRE CALL HOOKS START | |
| hook_ctx.insert(RequestModel(request_data.model)); | |
| let mut request = Request::new(Body::empty()); //TODO | |
| HOOK_MANAGER | |
| .pre_call(&mut hook_ctx, &mut request, HOOK_FILTER_ALL) | |
| .await?; |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/proxy/handlers/embeddings/mod.rs` around lines 25 - 36, The embeddings
handler is missing the #[fastrace::trace] decorator required for public
handlers; add the #[fastrace::trace] attribute immediately above the pub async
fn embeddings signature to match the chat_completions handler's tracing setup so
this function is instrumented for distributed tracing (ensure the attribute is
imported/available in the module if needed).
There was a problem hiding this comment.
just ignore it for now
There was a problem hiding this comment.
@bzp2010, understood — I'll skip this for now.
🧠 Learnings used
Learnt from: CR
Repo: api7/aisix PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-08T12:40:09.587Z
Learning: Applies to src/**/*.rs : Use #[fastrace::trace] decorator for distributed tracing on public functions
Summary by CodeRabbit
New Features
Bug Fixes