fix(correctness): pagination tiebreakers, dedup race, duration gating (0.87.6)
Three medium correctness fixes: 1. **Pagination ORDER BY missing tiebreakers** — four admin list queries sorted by a timestamp or `chapters.number` with no stable secondary sort. Add `id` tiebreakers across `repo::admin_view`, `repo::admin_audit`, `repo::bookmark`. 2. **`enqueue_pages` NOT EXISTS read-then-insert race** — concurrent admin clicks could land duplicate analyze_page jobs. Migration 0031 adds a partial unique index mirroring 0014; query relies on `ON CONFLICT DO NOTHING`. 3. **`record_duration` overwrote a prior done row's duration on a non-terminal failed retry of a force-re-analyze.** Gate the call on "did this attempt actually write a row?". Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -313,6 +313,17 @@ impl WorkerContext {
|
||||
self.events.publish(event);
|
||||
}
|
||||
|
||||
// Stamp how long the vision dispatch took — but ONLY when a row
|
||||
// was actually written this attempt. Otherwise a non-terminal
|
||||
// failure on a force-re-analyze (page already has a `done` row)
|
||||
// would overwrite the prior duration with the duration of a
|
||||
// failed retry that wrote nothing new.
|
||||
let wrote_row = match &result {
|
||||
Ok(()) => true,
|
||||
Err(_) if lease.attempts >= lease.max_attempts => true, // mark_failed wrote below
|
||||
Err(_) => false,
|
||||
};
|
||||
|
||||
match result {
|
||||
Ok(()) => {
|
||||
let _ = jobs::ack_done(&self.pool, lease.id).await;
|
||||
@@ -341,10 +352,9 @@ impl WorkerContext {
|
||||
}
|
||||
}
|
||||
|
||||
// Stamp how long the vision dispatch took. Best-effort and ordered
|
||||
// after the row is written (persist on success / mark_failed on
|
||||
// terminal failure); a transient failure with no row updates nothing.
|
||||
let _ = repo::page_analysis::record_duration(&self.pool, page_id, elapsed_ms).await;
|
||||
if wrote_row {
|
||||
let _ = repo::page_analysis::record_duration(&self.pool, page_id, elapsed_ms).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user