Retry insight persistence with exponential backoff to avoid SQLite lock contention
Add retry_with_backoff utility (100ms base, ±25% jitter, 3 attempts) and replace all 11 direct DAO calls in insight_chat.rs and insight_generator.rs. The Mutex guard drops between retries so the maintenance connection can release its SQLite write lock.
This commit is contained in:
1 parent
4029625dc0
commit
38aaddfd2a
4 files changed
+133
-58
No files matched your search
+15
-10
@@ -26,7 +26,7 @@ use crate::libraries::Library;
|
||||
use crate::memories::extract_date_from_filename;
|
||||
use crate::otel::global_tracer;
|
||||
use crate::tags::TagDao;
|
||||
use crate::utils::{earliest_fs_time, normalize_path};
|
||||
use crate::utils::{earliest_fs_time, normalize_path, retry_with_backoff};
|
||||
|
||||
/// Max location records rendered by `tool_get_location_history`. The DAO
|
||||
/// query is range-bounded, not limited, so the tool caps the rendered list
|
||||
@@ -1539,10 +1539,13 @@ impl InsightGenerator {
|
||||
eval_count: None,
|
||||
};
|
||||
|
||||
let mut dao = self.insight_dao.lock().expect("Unable to lock InsightDao");
|
||||
let result = dao
|
||||
.store_insight(&insight_cx, insight)
|
||||
.map_err(|e| anyhow::anyhow!("Failed to store insight: {:?}", e));
|
||||
let dao = self.insight_dao.clone();
|
||||
let result = retry_with_backoff("store_insight", 3, || {
|
||||
let cx = opentelemetry::Context::new();
|
||||
let mut d = dao.lock().expect("Unable to lock InsightDao");
|
||||
d.store_insight(&cx, insight.clone())
|
||||
})
|
||||
.map_err(|e| anyhow::anyhow!("Failed to store insight: {:?}", e));
|
||||
|
||||
match &result {
|
||||
Ok(_) => {
|
||||
@@ -4465,11 +4468,13 @@ Return ONLY the summary, nothing else."#,
|
||||
eval_count: last_eval_count,
|
||||
};
|
||||
|
||||
let stored = {
|
||||
let mut dao = self.insight_dao.lock().expect("Unable to lock InsightDao");
|
||||
dao.store_insight(&insight_cx, insight)
|
||||
.map_err(|e| anyhow::anyhow!("Failed to store agentic insight: {:?}", e))
|
||||
};
|
||||
let dao = self.insight_dao.clone();
|
||||
let stored = retry_with_backoff("store_insight", 3, || {
|
||||
let cx = opentelemetry::Context::new();
|
||||
let mut d = dao.lock().expect("Unable to lock InsightDao");
|
||||
d.store_insight(&cx, insight.clone())
|
||||
})
|
||||
.map_err(|e| anyhow::anyhow!("Failed to store agentic insight: {:?}", e));
|
||||
|
||||
match &stored {
|
||||
Ok(_) => {
|
||||
|
||||
Reference in new issue
Block a user