Compare commits

...
Author SHA1 Message Date
Sharang ParnerkarandClaude Fable 5 617b2df75e fix(llm): chunk embed() requests under the backend batch cap
CI / Check (push) Skipped
CI / Check (pull_request) Successful in 5m42s
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
Found while prepping the C5 live test: the embeddings backend
(bge-multilingual-gemma2 via LiteLLM) caps input arrays at 25 per request
("given batch size overflow maximal one", max: 25), but embed() sent the whole
input in a single request. ControlIndex::build embeds the entire master-controls
corpus (~1.8k texts) in one embed() call, and the RAG pipeline batches docs too —
both 500 at scale. Unit tests passed only because they embed <=3 texts.

Fix: embed() now chunks into EMBED_BATCH_SIZE (16) requests and concatenates in
order; empty input short-circuits. Validated live — 1,784 texts over 112 chunked
requests succeed (~70s, one-time + cached by the index).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-21 17:34:17 +02:00
sharang a7ff36edf3 feat(controls): B3 — categorize the rest of needs_tooling (architectural + RBAC) (#220)
CI / Check (push) Skipped
CI / Detect Changes (push) Successful in 2s
CI / Deploy Dashboard (push) Skipped
CI / Deploy Docs (push) Skipped
CI / Deploy MCP (push) Skipped
CI / Deploy Agent (push) Failing after 4s
2026-07-21 13:15:27 +00:00
4 changed files with 92 additions and 11 deletions
+13 -1
View File
@@ -47,6 +47,17 @@ pub const SURFACES: &[Surface] = &[
"ratelimit",
],
},
Surface {
control_id: "cra-ai-12", // Rollenbasierte Autorisierung (RBAC)
terms: &[
"authorize",
"permission",
"role",
"rbac",
"require_role",
"has_role",
],
},
Surface {
control_id: "cra-ai-24", // Security-Logging
terms: &["login", "authorize", "permission", "role", "admin", "audit"],
@@ -196,10 +207,11 @@ mod tests {
#[test]
fn surfaces_cover_the_absence_based_controls() {
assert_eq!(SURFACES.len(), 7);
assert_eq!(SURFACES.len(), 8);
for id in [
"cra-ai-6",
"cra-ai-11",
"cra-ai-12",
"cra-ai-24",
"cra-ai-27",
"cra-ai-28",
+49 -1
View File
@@ -22,6 +22,11 @@ struct EmbeddingData {
index: usize,
}
/// Max inputs per embedding request. The bge/OpenAI-like backends cap the input
/// array (bge-multilingual-gemma2 rejects >25 with "batch size overflow"), so we
/// chunk larger corpora — a whole control catalog (~1.8k) would otherwise 500.
const EMBED_BATCH_SIZE: usize = 16;
// ── Embedding implementation ───────────────────────────────────
impl LlmClient {
@@ -29,8 +34,21 @@ impl LlmClient {
&self.embed_model
}
/// Generate embeddings for a batch of texts
/// Generate embeddings for a batch of texts, chunking into backend-sized
/// requests and preserving input order across chunks.
pub async fn embed(&self, texts: Vec<String>) -> Result<Vec<Vec<f64>>, AgentError> {
if texts.is_empty() {
return Ok(Vec::new());
}
let mut out = Vec::with_capacity(texts.len());
for chunk in texts.chunks(EMBED_BATCH_SIZE) {
out.extend(self.embed_batch(chunk.to_vec()).await?);
}
Ok(out)
}
/// Embed one backend-sized batch (≤ [`EMBED_BATCH_SIZE`]) in a single request.
async fn embed_batch(&self, texts: Vec<String>) -> Result<Vec<Vec<f64>>, AgentError> {
let url = format!("{}/v1/embeddings", self.base_url.trim_end_matches('/'));
let request_body = EmbeddingRequest {
@@ -72,3 +90,33 @@ impl LlmClient {
Ok(data.into_iter().map(|d| d.embedding).collect())
}
}
#[cfg(test)]
mod tests {
use super::*;
use secrecy::SecretString;
fn client() -> LlmClient {
LlmClient::new(
"http://unused".into(),
SecretString::from(String::new()),
"m".into(),
"e".into(),
)
}
#[tokio::test]
async fn empty_input_makes_no_request() {
// Must short-circuit before any HTTP call (base_url is unroutable).
let out = client().embed(Vec::new()).await.unwrap();
assert!(out.is_empty());
}
#[test]
fn batch_size_is_within_backend_cap() {
assert!(
EMBED_BATCH_SIZE <= 25,
"must stay under the bge 25-input cap"
);
}
}
+9 -9
View File
@@ -25,29 +25,29 @@
"control": "cra-ai-2",
"title": "Minimale Angriffsflaeche",
"scans": [],
"note": "code-checkable but no off-the-shelf tool digs it out — author a detector (custom semgrep rule / check)",
"status": "needs_tooling"
"note": "design property (minimal attack surface) — not derivable from local code patterns; architecture/threat-model review",
"status": "not_code_checkable"
},
{
"control": "cra-ai-3",
"title": "Sichere Systemarchitektur",
"scans": [],
"note": "code-checkable but no off-the-shelf tool digs it out — author a detector (custom semgrep rule / check)",
"status": "needs_tooling"
"note": "design property (secure system architecture) — architecture review, not statically code-checkable",
"status": "not_code_checkable"
},
{
"control": "cra-ai-4",
"title": "Least-Privilege-Prinzip",
"scans": [],
"note": "code-checkable but no off-the-shelf tool digs it out — author a detector (custom semgrep rule / check)",
"status": "needs_tooling"
"note": "design property (least-privilege) — deployment/IAM & architecture review, not a local code pattern",
"status": "not_code_checkable"
},
{
"control": "cra-ai-5",
"title": "Manipulationsschutz",
"scans": [],
"note": "code-checkable but no off-the-shelf tool digs it out — author a detector (custom semgrep rule / check)",
"status": "needs_tooling"
"note": "design property (tamper protection) — hardware/runtime & operational control, not statically code-checkable",
"status": "not_code_checkable"
},
{
"control": "cra-ai-6",
@@ -146,7 +146,7 @@
"control": "cra-ai-12",
"title": "Rollenbasierte Autorisierung",
"scans": [],
"note": "code-checkable but no off-the-shelf tool digs it out — author a detector (custom semgrep rule / check)",
"note": "absence-based — no syntactic pattern; covered by the grounded surface check (retrieve surface + LLM judge), gated (BREAKPILOT_GROUNDED_CHECKS) pending live tuning",
"status": "needs_tooling"
},
{
+21
View File
@@ -214,6 +214,27 @@ mod tests {
assert!(hits.iter().any(|c| c.control == "cra-ai-1"));
}
#[test]
fn coverage_reflects_the_b_track_split() {
let s = ControlMap::cra().unwrap().summary();
// 9 already tool-covered + B1's 4 custom-semgrep controls.
assert_eq!(s.covered, 13);
// The 8 grounded surface controls stay needs_tooling until live-tuned.
assert_eq!(s.needs_tooling, 8);
// B3 marked the 4 pure-architectural controls not code-checkable.
assert_eq!(s.not_code_checkable, 19);
}
#[test]
fn architectural_controls_are_not_code_checkable() {
let map = ControlMap::cra().unwrap();
for id in ["cra-ai-2", "cra-ai-3", "cra-ai-4", "cra-ai-5"] {
let c = map.coverage(id).unwrap();
assert_eq!(c.status, Coverage::NotCodeCheckable, "{id}");
assert!(c.scans.is_empty(), "{id} should carry no scan bindings");
}
}
#[test]
fn custom_rule_controls_do_not_bind_by_broad_cwe() {
let map = ControlMap::cra().unwrap();