scoring: add timeouts, progress feedback, error resilience

- 120s timeout on individual /v1/score HTTP calls
- Activity bar shows "scoring 3/24: memory-key..."
- Info messages at start and completion
- Per-memory timing and importance in debug pane
- Failed individual memories log error but don't abort (zero row)
- Removed duplicate completion message (info from score_memories)

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-03 01:07:47 -04:00
parent e8c3ed3d96
commit beb49ec477
2 changed files with 89 additions and 57 deletions

View file

@ -424,39 +424,39 @@ impl Session {
Command::Handled
}
"/score" => {
{
let agent = self.agent.lock().await;
// Snapshot context+client while we have the lock,
// so the scoring task doesn't need to wait for turns.
let (context, client) = {
let mut agent = self.agent.lock().await;
if agent.scoring_in_flight {
let _ = self.ui_tx.send(UiMessage::Info(
"(scoring already in progress)".into()
));
return Command::Handled;
}
}
self.agent.lock().await.scoring_in_flight = true;
agent.scoring_in_flight = true;
(agent.context.clone(), agent.client_clone())
};
let agent = self.agent.clone();
let ui_tx = self.ui_tx.clone();
let _ = self.ui_tx.send(UiMessage::Debug("[score] task spawning".into()));
tokio::spawn(async move {
let (context, client) = {
let agent = agent.lock().await;
(agent.context.clone(), agent.client_clone())
};
let _ = ui_tx.send(UiMessage::Debug("[score] task started, calling score_memories".into()));
let result = poc_memory::thought::training::score_memories(
&context, &client, &ui_tx,
).await;
let _ = ui_tx.send(UiMessage::Debug("[score] score_memories returned, acquiring lock".into()));
// Store results — brief lock, just setting fields
let mut agent = agent.lock().await;
let _ = ui_tx.send(UiMessage::Debug("[score] lock acquired, storing results".into()));
agent.scoring_in_flight = false;
match result {
Ok(scores) => {
let _ = ui_tx.send(UiMessage::Info(format!(
"[memory scoring complete: {} memories scored]",
scores.memory_keys.len(),
)));
agent.memory_scores = Some(scores);
}
Err(e) => {
let _ = ui_tx.send(UiMessage::Info(format!(
"[memory scoring failed: {:#}]", e,
"[scoring failed: {:#}]", e,
)));
}
}