Skip to content

Commit 7416a81

Browse files
AssafWooclaude
andcommitted
fix: score_and_compress degrades gracefully when BERT unavailable
Previously embed_batch() errors propagated via `?`, causing the function to return Err when the daemon is not running (e.g. CI). Five unit tests that called score_and_compress().unwrap() then panicked in CI even though they passed locally (daemon was running). Fix: unwrap_or_else to zero embeddings when embed_batch fails. Zero embeddings make all cosine scores 0.0, threshold 0.0, so every section is preserved by rule (imports, typedefs, edit ranges, 50% minimum). This is the correct degraded behavior — no BERT, no scoring, keep all. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 867327c commit 7416a81

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

ccr/src/handlers/focus_compress.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,13 @@ pub fn score_and_compress(
399399
})
400400
.collect();
401401

402-
let embeddings = panda_core::summarizer::embed_batch(&texts)?;
402+
// Embed section texts. If BERT is unavailable (daemon not running), fall back
403+
// to zero embeddings — all cosine scores become 0.0, threshold becomes 0.0,
404+
// so every section is preserved (rule-based only: imports, typedefs, edit ranges,
405+
// 50% minimum). This is the correct degraded behavior and keeps tests passing in
406+
// environments without a running daemon (e.g. CI).
407+
let embeddings = panda_core::summarizer::embed_batch(&texts)
408+
.unwrap_or_else(|_| vec![vec![0.0f32; prompt_emb.len().max(1)]; sections.len()]);
403409

404410
// 2. Compute cosine similarities
405411
let scores: Vec<f32> = embeddings

0 commit comments

Comments
 (0)