Wire database Store into agent loop

Persist jobs and actions to PostgreSQL using fire-and-forget pattern:
- Scheduler passes store to Worker, persists cancellations
- Worker persists job status changes and tool execution actions
- Agent persists new jobs on creation
- All DB writes use tokio::spawn to avoid blocking execution

Store remains optional to preserve --no-db mode.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
This commit is contained in:
Illia Polosukhin
2026-02-02 22:53:12 -08:00
co-authored by Claude Opus 4.5
parent aea3f47f8b
commit 45bbfa026d
4 changed files with 137 additions and 17 deletions
+13
View File
@@ -47,6 +47,7 @@ impl Agent {
llm.clone(),
safety.clone(),
tools.clone(),
store.clone(),
));
Self {
@@ -171,6 +172,18 @@ impl Agent {
.await?;
}
// Persist new job to database (fire-and-forget)
if let Some(ref store) = self.store {
if let Ok(ctx) = self.context_manager.get_context(job_id).await {
let store = store.clone();
tokio::spawn(async move {
if let Err(e) = store.save_job(&ctx).await {
tracing::warn!("Failed to persist new job {}: {}", job_id, e);
}
});
}
}
// Schedule for execution
self.scheduler.schedule(job_id).await?;