Skip to content

fix(core): no panics on embedder-less or missing-RRF recall paths; no retry of validation errors - #1443

Merged
ajianaz merged 6 commits into
developfrom
fix/embed-panics-and-retry
Oct 13, 2026
Merged

ajianaz merged 6 commits into
developfrom
fix/embed-panics-and-retry

Conversation

@ajianaz

@ajianaz ajianaz commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

What

Defensive hardening in crates/uteke-core/src/operations.rs, from the #1439 audit:

  • retry_embed, empty embedder slot. It returns Error::Embedding ("No embedder configured; the memory was not embedded") instead of panicking on expect("embedder ensured above").
  • retry_embed, validation errors. Error::Validation is returned at once instead of being retried three times (about 600 ms of sleeps). This matches the existing rule in index_sync.rs (!matches!(e, Error::Validation(_))).
  • recall_inner. The same expect becomes Error::embed_msg("No embedder configured; semantic recall is unavailable").
  • recall_rrf. A scored id missing from the fused memory map is skipped with a warn! instead of panicking. .take(limit) stays before the filter.

Why

The audit flagged these expects as panics on user-reachable paths. Investigation showed none of them is reachable in the current code:

  • ensure_embedder returning Ok always leaves the slot Some.
  • recall_rrf fills its score map and its memory map in the same loops.
  • No production embedder returns Validation from embed(); that only happens at construction.

So this PR changes nothing on any reachable path. It turns invariants that live in comments and callers' heads into errors, so a future change that breaks them degrades instead of crashing the server.

Benchmark safety. The normal recall/remember paths are unchanged:

  • take comes before filter_map, which yields the same items when every lookup succeeds.
  • Score normalization and ordering are untouched.
  • The success arm of retry_embed is unchanged.

Testing

  • cargo test --workspace: all green (uteke-core 728 passed, 33 ignored ONNX-only).
  • cargo fmt --all -- --check and cargo clippy --workspace --all-targets -- -D warnings: clean.
  • New retry_embed_tests:
    • an empty slot gives Error::Embedding and no panic
    • Validation is called exactly once
    • a transient embed_msg error is retried and then succeeds (2 calls)
  • New recall_no_embedder_tests::recall_without_embedder_returns_error: recall() on a custom backend with no embedder returns an error, not a panic.
  • The new ok_or_else arm in recall_inner and the RRF skip arm are unreachable today, so they have no tests by design.
  • Two existing fakes in remember_embedding_status_tests now return embed_msg instead of Validation. They simulate transient and outage failures, which must stay retryable.

ensure_embedder only returns Ok once the slot holds an embedder and nothing
resets it to None, so the expect was unreachable today. Return an Embedding
error instead so a future change cannot turn it into a panic. Adds a test that
vector recall on a store with no usable embedder errors rather than panics.
recall_rrf fills rrf_scores and memories in the same loops, so the expect
could not fire today. Use filter_map and skip a missing id with a warning
instead of panicking if that invariant ever breaks. take(limit) stays before
the filter, so the normal path is unchanged.
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit 0a62384 into develop Oct 13, 2026
15 checks passed
@ajianaz
ajianaz deleted the fix/embed-panics-and-retry branch October 13, 2026 04:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant