Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
fix(storage): surface LevelDB exec_op failures (#6716)
Lusen Dongf3660180d642
diff --git a/src/store/persist_store.cpp b/src/store/persist_store.cppindex 6bf28abf5..e5a3dd257 100644--- a/src/store/persist_store.cpp+++ b/src/store/persist_store.cpp@@ -8,6 +8,26 @@#include "leveldb/write_batch.h"namespace vectordb {+namespace {++std::string summarize_leveldb_status(const leveldb::Status& status) {+ // POSIX errors are formatted as "type: file context: system reason".+ // Keep the actionable ends while leaving the full context in server logs.+ const std::string message = status.ToString();+ const size_t type_separator = message.find(": ");+ if (type_separator == std::string::npos) {+ return "LevelDB error";+ }++ const size_t reason_separator = message.rfind(": ");+ if (reason_separator == type_separator) {+ return message.substr(0, type_separator);+ }+ return message.substr(0, type_separator + 2) ++ message.substr(reason_separator + 2);+}++} // namespacePersistStore::PersistStore(const std::string& path) {leveldb::Options options;@@ -167,7 +187,8 @@ int PersistStore::exec_op(const std::vector<StorageOp>& ops) {auto status = db_->Write(write_options, &batch);if (!status.ok()) {SPDLOG_WARN("Failed to exec op data db: {}", status.ToString());- return -1;+ throw std::runtime_error("PersistStore::exec_op failed: " ++ summarize_leveldb_status(status));}return 0;}diff --git a/tests/engine/test_index_engine.cpp b/tests/engine/test_index_engine.cppindex db666d6b2..4fffd81c7 100644--- a/tests/engine/test_index_engine.cpp+++ b/tests/engine/test_index_engine.cpp@@ -615,11 +615,60 @@ void test_paged_store_scan() {SPDLOG_INFO("[Passed] test_paged_store_scan");}+void test_persist_store_write_error_is_actionable_and_path_safe() {+ SPDLOG_INFO(+ "[Running] test_persist_store_write_error_is_actionable_and_path_safe...");++#if defined(_WIN32)+ SPDLOG_INFO(+ "[Skipped] open LevelDB files cannot be removed reliably on Windows");+ return;+#endif++ const std::string db_path = "test_data_cpp/persist_store_write_failure";+ std::filesystem::remove_all(db_path);+ std::filesystem::create_directories(db_path);++ std::string error_message;+ {+ PersistStore store(db_path);+ StorageOp fill_memtable;+ fill_memtable.key = "large-value";+ fill_memtable.value = std::string(5 * 1024 * 1024, 'x');+ if (store.exec_op({fill_memtable}) != 0) {+ SPDLOG_ERROR("Failed to prepare the persistent store write failure");+ exit(1);+ }++ // The next write rotates the oversized memtable's log. Removing the store+ // directory makes that rotation fail through LevelDB's real write path.+ std::filesystem::remove_all(db_path);+ StorageOp trigger_rotation;+ trigger_rotation.key = "trigger-rotation";+ trigger_rotation.value = "value";+ try {+ store.exec_op({trigger_rotation});+ } catch (const std::runtime_error& error) {+ error_message = error.what();+ }+ }++ if (error_message.find("PersistStore::exec_op failed: NotFound: ") != 0 ||+ error_message.find(db_path) != std::string::npos) {+ SPDLOG_ERROR("Unexpected public persistent store error: {}", error_message);+ exit(1);+ }+ std::filesystem::remove_all(db_path);+ SPDLOG_INFO(+ "[Passed] test_persist_store_write_error_is_actionable_and_path_safe");+}+int main() {init_logging("INFO", "stdout", "[%Y-%m-%d %H:%M:%S.%e] [%l] %v");test_basic_workflow();test_routed_filter_projection_edge_cases();test_path_bitmap_lifecycle_and_reload();test_paged_store_scan();+ test_persist_store_write_error_is_actionable_and_path_safe();return 0;}