Admin: list and restart running generations with the models set now
CI / test (push) Successful in 1m17s
CI / build (push) Successful in 5m43s
CI / deploy (push) Skipped

- Modellek page: analyses and answers being written or waiting, with their model
  and the one a restart would use; restart one or all
- Each attempt's started_at is its token: a restarted attempt still running in the
  worker cannot write its result and is dropped within 10 seconds

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-18 21:31:09 +00:00
co-authored by Claude Opus 5.5
parent 769b4791ae
commit b5743ec7d1
13 changed files with 492 additions and 51 deletions
+24
View File
@@ -781,4 +781,28 @@ mod analyses {
fake.requests.lock().unwrap().iter().map(|b| b["model"].as_str().unwrap().to_string()).collect();
assert_eq!(models, ["cheap/model", "cheap/model", "test/model"]);
}
#[sqlx::test(migrator = "db::MIGRATOR")]
async fn a_restarted_attempt_does_not_write_its_result(db: PgPool) {
let s = setup(&db).await;
let id = request_analysis(&db, &s).await;
let (_, url) = fake_openrouter(vec![reply(&content(Kind::Natal))]).await;
let a = analyzer(&db, &url);
let job = a.claim().await.unwrap().expect("a job");
// an admin restarts it while the worker is still writing it
sqlx::query("UPDATE analyses SET status = 'pending', started_at = NULL, attempts = 0 WHERE id = $1")
.bind(id)
.execute(&db)
.await
.unwrap();
a.handle(job).await;
let (status, content): (String, Option<Value>) =
sqlx::query_as("SELECT status, content FROM analyses WHERE id = $1").bind(id).fetch_one(&db).await.unwrap();
assert_eq!((status.as_str(), content), ("pending", None));
// the new attempt writes it
assert!(run_once(&a).await);
let status: String =
sqlx::query_scalar("SELECT status FROM analyses WHERE id = $1").bind(id).fetch_one(&db).await.unwrap();
assert_eq!(status, "done");
}
}