Error log, retry notice, a waiting counter that keeps counting
CI / test (push) Successful in 1m8s
CI / build (push) Successful in 5m13s
CI / deploy (push) Skipped

- generation_errors: every failed attempt (model, attempt, outcome, duration); admin
  Hibanapló page and GET /v1/admin/errors; kept 90 days
- The waiting page counts from when the text was asked for (requested_at), not from
  the page load, so a reload no longer restarts it
- It says when an attempt failed and is retried, and when a failed text's unit was
  given back; admins see the error

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:47:37 +00:00
co-authored by Claude Opus 5.5
parent cf2fb9d454
commit 02e4e225f0
22 changed files with 569 additions and 25 deletions
+52 -1
View File
@@ -253,6 +253,8 @@ impl Analyzer {
.await
}
Err(e) => {
self.log_error("preview", job.id, &job.kind, &job.model, 1, "failed", e.message(), started.elapsed())
.await;
sqlx::query(
"UPDATE prompt_previews SET status = 'failed', error = $2, completed_at = now() \
WHERE id = $1 AND status = 'running'",
@@ -322,7 +324,24 @@ impl Analyzer {
}
Err(e) => {
let can_fall_back = !job.on_fallback && job.fallback_model.is_some();
match next_step(&e, job.attempts, self.max_attempts, can_fall_back) {
let next = next_step(&e, job.attempts, self.max_attempts, can_fall_back);
let outcome = match next {
Next::Retry(_) => "retry",
Next::Fallback => "fallback",
Next::Fail => "failed",
};
self.log_error(
"analysis",
job.id,
&job.kind,
job.active_model(),
job.attempts,
outcome,
e.message(),
took,
)
.await;
match next {
Next::Retry(wait) => {
sqlx::query(
"UPDATE analyses SET status = 'pending', error = $2, \
@@ -424,6 +443,38 @@ impl Analyzer {
Ok(result.rows_affected())
}
/// Records a failed attempt in the admin error log (a failure here is only logged).
#[allow(clippy::too_many_arguments)]
pub(crate) async fn log_error(
&self,
source: &str,
item_id: Uuid,
kind: &str,
model: &str,
attempt: i32,
outcome: &str,
error: &str,
took: Duration,
) {
let result = sqlx::query(
"INSERT INTO generation_errors (source, item_id, kind, model, attempt, outcome, error, seconds) \
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)",
)
.bind(source)
.bind(item_id)
.bind(kind)
.bind(model)
.bind(attempt)
.bind(outcome)
.bind(error.chars().take(2000).collect::<String>())
.bind(i32::try_from(took.as_secs()).unwrap_or(i32::MAX))
.execute(&self.db)
.await;
if let Err(e) = result {
tracing::error!(error = %e, "writing the error log");
}
}
/// Resolves when this attempt is no longer the current one (an admin
/// restarted it); checked every 10 seconds, never on a database error.
async fn superseded(&self, table: &str, id: Uuid, started_at: time::OffsetDateTime) {