[Router] Parse the request body once per request #1230
All Vouch review confidence checks passed
Residual risk 0.23 = Change Risk (0.40) × (1 − Review Confidence (0.43)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 290 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth
shallow_review_depth
0.344
Diff Size
diff_size
0.339
Real PR Conversation Timeline
1 comments
"Review active on #1230"
general
weight: 0.35
chrikrah
Hi Team,
route_general_request parses the request body intorequest_jsonto route it, then callsprocess_request, which runsjson.loads(body)again just to readstreamandmodel. That second parse runs once per attempt, so it repeats on every failover retry.This PR passes the already parsed request_json
intoprocess_request. The new argument is optional: direct callers that don't pass it get the same parse and the same 400 for an unparsable body as before.request_json
always matches the bytes sent to the backend: the alias path updates it in place, the request rewriter re-parses it, andPriorityRouterre-serialises the body from it.Related to #707. The memray profile there lists json.loads
/raw_decodeas the largest source of allocation churn in the router. This change removes one of the two body parses per request. It does not claim to fix the RSS growth reported there.This touches the same parse block in process_request
as #1067, so whichever lands second needs a small rebase.Measurements
process_request
called in-process against a fake backend, with a 10-turn chat body of each size. Time is the mean of 2000 requests; memory is the median peak traced allocation per request over 200 requests (tracemalloc).| body | bytes | before µs | after µs | before KiB | after KiB |
|---|---:|---:|---:|---:|---:|
| tiny chat | 547 | 10.6 | 8.5 | 4.7 | 3.3 |
| 2 KB prompt | 2467 | 11.8 | 8.3 | 7.9 | 3.3 |
| 16 KB prompt | 16507 | 18.1 | 8.5 | 35.3 | 3.3 |
| 64 KB prompt | 64507 | 41.2 | 9.8 | 129.0 | 3.3 |
| 256 KB prompt | 256507 | 120.7 | 8.7 | 504.0 | 3.3 |
The cost removed grows with the prompt size, while process_request
itself stays flat. Across the whole request, the body is now parsed once instead of twice.Tests
checks that the body isn't parsed again whenrequest_jsonis passed. It fails onmain.: 284 passed.---
,[Feat], and[CI]`.