-
Notifications
You must be signed in to change notification settings - Fork 0
D3.1 batch sweep handler + clippy -D warnings clean (117/117 tests) #238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,8 +50,9 @@ use crate::wire::{ | |
| WireCalibrateRequest, WireCalibrateResponse, WireCrystal, WireDispatch, WireHealth, | ||
| WireIngest, WirePlanRequest, WirePlanResponse, WireProbeRequest, WireProbeResponse, | ||
| WireQualia, WireRunbookRequest, WireRunbookResponse, WireRunbookStep, | ||
| WireRunbookStepResult, WireStepResult, WireStyleInfo, WireTensorsRequest, | ||
| WireTensorsResponse, WireTokenAgreement, WireTokenAgreementResult, WireUnifiedStep, | ||
| WireRunbookStepResult, WireStepResult, WireStyleInfo, WireSweepRequest, | ||
| WireSweepResponse, WireSweepResult, WireTensorsRequest, WireTensorsResponse, | ||
| WireTokenAgreement, WireTokenAgreementResult, WireUnifiedStep, | ||
| }; | ||
| use lance_graph_contract::cam::CodecParams; | ||
| use std::path::Path as StdPath; | ||
|
|
@@ -96,6 +97,13 @@ pub fn router(driver: ShaderDriver) -> Router { | |
| // `backend:"stub"` so clients cannot confuse Phase 0 stub output | ||
| // for a real measurement (anti-#219 defense, type-level). | ||
| .route("/v1/shader/token-agreement", post(token_agreement_handler)) | ||
| // D3.1 — codec sweep endpoint (batch mode). Client POSTs a | ||
| // WireSweepRequest containing a cross-product grid; handler | ||
| // enumerates grid, validates each candidate, builds stub results, | ||
| // returns WireSweepResponse. SSE streaming + Lance append land in | ||
| // D3.1b; this batch path stays for clients that want all results | ||
| // in one response without streaming. | ||
| .route("/v1/shader/sweep", post(sweep_handler)) | ||
| // Scheduled runbook: one POST runs a list of steps. Test injection | ||
| // lands here — a client script submits its full codec-research | ||
| // protocol as a single DTO, the server executes and returns all | ||
|
|
@@ -284,6 +292,54 @@ async fn token_agreement_handler( | |
| .map_err(|e| (StatusCode::BAD_REQUEST, Json(json!({"error": format!("{e}")})))) | ||
| } | ||
|
|
||
| /// D3.1 — `POST /v1/shader/sweep` handler (batch mode). | ||
| /// | ||
| /// Enumerates the cross-product grid from `WireSweepRequest`, validates | ||
| /// each candidate via TryFrom(CodecParams), computes kernel_signature + | ||
| /// backend per point, and returns all results in one `WireSweepResponse`. | ||
| /// | ||
| /// Stub: per-point calibrate/token_agreement are `None`; Phase 3 real | ||
| /// handler invokes the actual codec_research + token_agreement harness. | ||
| /// SSE streaming variant (D3.1b) replaces the batch return with per-point | ||
| /// Server-Sent Events. | ||
| async fn sweep_handler( | ||
| Json(req): Json<WireSweepRequest>, | ||
| ) -> Result<Json<WireSweepResponse>, (StatusCode, Json<Value>)> { | ||
| let start = std::time::Instant::now(); | ||
| let candidates = req.grid.enumerate(); | ||
| let cardinality = candidates.len() as u32; | ||
|
|
||
| let mut results = Vec::with_capacity(candidates.len()); | ||
| for (idx, wire_params) in candidates.into_iter().enumerate() { | ||
| // Validate each grid point at ingress — surface typed errors early. | ||
| let params: CodecParams = wire_params | ||
| .clone() | ||
| .try_into() | ||
| .map_err(|e: lance_graph_contract::cam::CodecParamsError| { | ||
| (StatusCode::BAD_REQUEST, Json(json!({ | ||
| "error": format!("grid point {idx}: invalid CodecParams: {e}") | ||
| }))) | ||
| })?; | ||
|
|
||
| results.push(WireSweepResult { | ||
| grid_index: idx as u32, | ||
| candidate: wire_params, | ||
| kernel_hash: params.kernel_signature(), | ||
| calibrate: None, | ||
| token_agreement: None, | ||
| stub: true, | ||
| }); | ||
| } | ||
|
|
||
| Ok(Json(WireSweepResponse { | ||
| label: req.label, | ||
| cardinality, | ||
| results, | ||
| elapsed_ms: start.elapsed().as_millis() as u64, | ||
| lance_fragment_path: req.log_to_lance, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed check again |
||
| })) | ||
| } | ||
|
|
||
| async fn route_handler( | ||
| State(_state): State<AppState>, | ||
| Json(wire): Json<WireUnifiedStep>, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
sweep_handler, the request-controlled grid is fully materialized viareq.grid.enumerate()with no cardinality limit, so a small JSON payload containing moderately sized axes can explode into an enormous Cartesian product and exhaust CPU/memory while buildingresults. This creates a straightforward denial-of-service path for the new/v1/shader/sweependpoint; add a hard upper bound (for example a few hundred/thousand points) and return400before callingenumerate().Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed check again