Skip to content

Enhance error handling#28

Merged
anaslimem merged 2 commits intomainfrom
enhance_error_handling
Mar 17, 2026
Merged

Enhance error handling#28
anaslimem merged 2 commits intomainfrom
enhance_error_handling

Conversation

@anaslimem
Copy link
Owner

Description

This PR focuses on improving system resilience, fixing build/compilation issues on modern Python versions, and addressing all compiler & linter warnings.

The most significant change is the removal of cascading panics during lock poisoning. Instead of crashing the entire application with .expect("lock poisoned") when a shared resource lock is compromised, the cortexadb-core engine now propagates these errors gracefully so they can be handled or recovered from.

Copilot AI review requested due to automatic review settings March 17, 2026 00:03
@vercel
Copy link

vercel bot commented Mar 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cortexa-db Ready Ready Preview, Comment Mar 17, 2026 0:03am

@anaslimem anaslimem merged commit 0fe0226 into main Mar 17, 2026
5 checks passed
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves resilience by replacing lock-poisoning panics with recoverable errors (or logged warnings), and updates Rust + Python surfaces accordingly. It also standardizes import formatting to address compiler/linter warnings and modernize formatting config.

Changes:

  • Replace several expect("...lock poisoned") patterns with Result-based error propagation and/or logging in cortexadb-core.
  • Make CortexaDB::stats() (Rust) and CortexaDB.stats() (PyO3 wrapper) handle fallible stat retrieval, updating tests accordingly.
  • Update rustfmt configuration and refactor imports across multiple modules.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
rustfmt.toml Switch to imports_granularity to replace deprecated import-merge setting.
crates/cortexadb-py/src/lib.rs Update Python bindings for fallible stats + adjust exceptions/__repr__/__len__.
crates/cortexadb-core/tests/integration.rs Update integration tests to handle fallible stats().
crates/cortexadb-core/src/store.rs Propagate lock poisoning via new error variant; make some methods fallible; adjust background threads.
crates/cortexadb-core/src/storage/wal.rs Import organization / lint cleanup.
crates/cortexadb-core/src/storage/segment.rs Import organization / lint cleanup.
crates/cortexadb-core/src/storage/compaction.rs Import organization / lint cleanup.
crates/cortexadb-core/src/storage/checkpoint.rs Import organization / lint cleanup.
crates/cortexadb-core/src/query/intent.rs Replace lock-poison panics with warning logs + fallback behavior.
crates/cortexadb-core/src/query/hybrid.rs Import organization / lint cleanup.
crates/cortexadb-core/src/query/executor.rs Replace lock-poison panics in cache handling with logging + best-effort behavior.
crates/cortexadb-core/src/index/vector.rs Import organization / lint cleanup.
crates/cortexadb-core/src/index/temporal.rs Import organization / lint cleanup.
crates/cortexadb-core/src/index/hnsw.rs Import organization / lint cleanup.
crates/cortexadb-core/src/index/graph.rs Import organization / lint cleanup.
crates/cortexadb-core/src/index/combined.rs Import organization / lint cleanup.
crates/cortexadb-core/src/facade.rs Make stats() fallible; update internal tests accordingly.
crates/cortexadb-core/src/engine.rs Add error variant + import organization / lint cleanup.
crates/cortexadb-core/src/core/state_machine.rs Import organization / lint cleanup.
crates/cortexadb-core/src/core/memory_entry.rs Import organization / lint cleanup.
crates/cortexadb-core/src/core/command.rs Import organization / lint cleanup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +700 to +704
pub fn set_vector_backend_mode(&self, mode: VectorBackendMode) -> Result<()> {
let mut writer = writer_lock(&self.writer)?;
writer.indexes.set_vector_backend_mode(mode);
self.publish_snapshot_from_write_state(&writer);
Ok(())
Comment on lines +856 to +857
pub fn wal_len(&self) -> Result<u64> {
Ok(writer_lock(&self.writer)?.engine.wal_len())
Comment on lines 498 to +506
/// Get database statistics.
pub fn stats(&self) -> Stats {
Stats {
pub fn stats(&self) -> Result<Stats> {
Ok(Stats {
entries: self.inner.state_machine().len(),
indexed_embeddings: self.inner.indexed_embeddings(),
wal_length: self.inner.wal_len(),
wal_length: self.inner.wal_len()?,
vector_dimension: self.inner.vector_dimension(),
storage_version: 1,
}
})
if stats.entries > 0 && stats.vector_dimension != dimension {
return Err(CortexaDBConfigError::new_err(format!(
"dimension mismatch: database has dimension={}, but open() was called with dimension={}",
return Err(PyValueError::new_err(format!(
Comment on lines 650 to +651
fn __len__(&self) -> usize {
self.inner.stats().entries
self.inner.stats().map(|s| s.entries).unwrap_or(0)
Comment on lines +34 to +38
if let Ok(mut guard) = policy_cell().write() {
*guard = policy;
crate::query::executor::clear_intent_anchor_cache();
} else {
log::warn!("intent policy write lock poisoned");
Comment on lines 42 to +48
pub fn get_intent_policy() -> IntentPolicy {
policy_cell().read().expect("intent policy read lock poisoned").clone()
if let Ok(guard) = policy_cell().read() {
guard.clone()
} else {
log::warn!("intent policy read lock poisoned, falling back to default");
IntentPolicy::default()
}
Comment on lines +448 to 453
log::error!("cortexadb sync manager flush error (lock poisoned): {e}");
continue;
}
};
if let Err(err) = write_state.engine.flush_buffers() {
log::error!("cortexadb sync manager flush_buffers error: {err}");
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.

2 participants