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:
MechaCat02
2026-06-22 21:34:39 +02:00
parent 80f4819fad
commit b9dd75684e
9 changed files with 64 additions and 16 deletions

View File

@@ -60,7 +60,11 @@ pub async fn list(
AND ($2::text IS NULL OR a.target_kind = $2)
AND ($3::uuid IS NULL OR a.actor_user_id = $3)
AND ($4::timestamptz IS NULL OR a.at >= $4)
ORDER BY a.at DESC
-- `id` tiebreaker for stable pagination: a single admin action
-- can write multiple audit rows in the same statement_timestamp
-- (e.g. bulk requeue) and ties on the timestamp would otherwise
-- skip or repeat rows across pages.
ORDER BY a.at DESC, a.id DESC
LIMIT $5 OFFSET $6
"#,
)