Repository navigation
serve: a key file line sets its key's scope and its in-flight and rate limits (403, 429 with Retry-After) - #1003
Conversation
There was a problem hiding this comment.
Verdict: MUST_FIX: the new socket test duplicates an existing HTTP response reader.
Must fix
1. Reuse the HTTP test-response reader
crates/serve/src/api.rs:6935 adds HTTP head/body separation and status parsing already owned by crates/serve/src/http.rs:469. This is a kind B duplication defect under R14.
Reusing that owner removes the second parser without adding an abstraction. Replace lines 6935–6943 with the following; the socket timeout remains, and the EOF assertion preserves the connection-close check:
let mut read = BufReader::new(&mut s);
let (status, head, body) = crate::http::read_test_response(&mut read);
assert_eq!(read.read(&mut [0]).expect("the connection closes"), 0);
(status, head, String::from_utf8(body).expect("a UTF-8 response"))Checked
Duplication: both cited readers were inspected; the new parser is on added lines. Dryer reported no pairs.
Fix: BufReader and Read are already in scope. The requests use HTTP/1.0, and the response writer declares Content-Length. The existing helper reads that body; the final read checks EOF with the original timeout.
Diagnostics: Limits::parse is new at complexity 17; ApiKeys::add rose 7→12; keep_alive rose 20→24. These measurements do not establish a separate finding.
Scope: this is a full review, not a revert or a no-merge mirror. No ledger lessons apply.
Notes
Tests were not executed during validation. The PR's card report lacks the nvidia-smi line, both commit hashes and just gate-* commands with output, so GPU evidence is incomplete.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
…e limits (403, 429 with Retry-After) A key file line may carry fields after its key: scope=inference|read|admin limits the routes the key reaches (a route outside them is a 403 permission_error), inflight=N caps the key's requests answered at once, and rate=N/s or N/m with burst=B is a bucket each request takes one from. A request past a limit is a 429 rate_limit_error with Retry-After in whole seconds, and the connection carries the next request. Each key counts apart; a background response holds its key's place until its generation ends. A key with no fields reaches every route unlimited, as before, and a field the line does not take refuses the start by line and place, never echoing the key.
7a14f5f to
b2e4bef
Compare
There was a problem hiding this comment.
Since the last review: the response-parser duplication is fixed at crates/serve/src/api.rs:6935. The decision-server test also reuses its existing response reader.
Verdict: CLEAN: the interdiff resolves the previous finding and introduces no proven defect.
Checked
Duplicates: 0 new definitions in the interdiff; both replacements reuse existing owners. Dryer reported 0 pairs.
Complexity: full-PR diagnostics report new Limits::parse (17), and branch growth in ApiKeys::add (7→12) and keep_alive (20→24). These functions are unchanged by the interdiff.
Silent failure: 0 added suppression sites. Unparseable status codes, invalid UTF-8 bodies and truncated bodies still fail the tests.
Tests: static inspection of flag.rs:274 and api.rs:1495 confirms that bypassing scope refusal contradicts the 403 assertion, and dropping the seated-route condition sends the second request into the held decider instead of returning 429. The revised readers preserve these checks.
Gates: no thresholds or explicit gate assertions removed or relaxed in the interdiff.
Adversarial checks: truncated bodies fail read_exact; a missing API connection close fails the bounded EOF check. The tested HTTP/1.0 responses declare Content-Length and Connection: close, as the reused readers require.
Escape catalog: no patterns match. No production hot path changes in the interdiff.
Notes
Tests were not executed during review or validation. The PR report lacks the nvidia-smi line, both commit hashes and just gate-* commands with output; GPU evidence is incomplete.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
|
The review is done and the contribution check passed, so I'm merging this. |
API 키 파일의 한 줄에서 키별 접근 범위(scope)와 동시 요청 수, 요청 속도 제한을 정할 수 있게 했습니다.
What and why
--api-key-filekeys all reach every route and run unlimited. A key file line can now narrow its key with fields after it:sk-app scope=inference inflight=2 rate=30/m burst=5.scope=takesinference,readoradmin(comma-separated). A route outside the key's scope answers 403 (permission_error).inflight=Ncaps the requests the key has answered at once. A request keeps its place until its answer is fully written and the engine has left its generation, also after a cancel or a disconnect.rate=N/sorrate=N/mwithburst=Bis a per-key request bucket.rate_limit_error) withRetry-Afterin whole seconds and starts nothing.A key with no fields behaves as before.
docs/serving.mddocuments the fields.Release notes: Added: a key file line can set a key's scope and its in-flight and rate limits; a request past a limit answers 429 with Retry-After, and a route outside the scope answers 403.
Code shape
crates/serve/src/admit.rs; the HTTP writer, the SSE stream and the background path share one lease on it instead of counting separately.cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up.Duplication found or removed (
path:line): none.What I ran
On a DGX Spark (GB10), a real
bloomery-servebuilt withcargo oxide build --arch sm_121a -- -p bloomery-gpu-gates --release --bin bloomery-serveservednvidia/Qwen3.8-Flash-Next-FP4-Localwith a key file that setsscope=,inflight=andrate=on separate keys:A key file with a field the line does not take exits with a usage error that names the line and the field. The
scope=readkey readsGET /props(200) and thescope=inferencekey gets 403 there and onPOST /shutdown.The whole serve library passes:
With the fix reverted, a route the decision server seats never answered 429:
AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.