Skip to content

fix(code-reviews): drain stuck pending queues#3357

Merged
alex-alecu merged 13 commits into
mainfrom
feat/queue-recovery
May 21, 2026
Merged

fix(code-reviews): drain stuck pending queues#3357
alex-alecu merged 13 commits into
mainfrom
feat/queue-recovery

Conversation

@alex-alecu
Copy link
Copy Markdown
Contributor

Why

Pending code reviews could wait a long time after a slot opened. They only woke up when another event arrived, so some reviews stayed parked even though work could continue.

What changed

This adds a scheduled queue sweep that wakes owners with reviews ready to try again. It reserves capacity safely before the slow work starts, so overlapping events do not take more slots than allowed. Old queued claims can recover again, and old running reviews are only shown as a warning signal, not failed automatically. The admin code review page now shows a live queue health card so support can see waiting work right away.

How to test

  1. Open /admin/code-reviews as an admin and confirm Current queue health appears above the older telemetry cards.
  2. Create or seed a pending review for an owner with free review capacity, then call the cron endpoint with the configured bearer secret and confirm the review moves toward dispatch.
  3. Seed a queued review older than five minutes and confirm the scheduled drain can pick it up again.
  4. Seed a running review older than ninety minutes and confirm it is shown in queue health but is not marked failed by the drain.

Comment thread apps/web/src/lib/code-reviews/dispatch/dispatch-pending-reviews.ts Outdated
Comment thread apps/web/src/lib/code-reviews/dispatch/dispatch-pending-code-review-owners.ts Outdated
@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented May 20, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

All previously flagged issues have been addressed; the only new change since the last review is a vercel.json cron schedule fix (every-minute → every-10-minutes for dispatch-pending-code-reviews).

Previous Issues (all resolved)
File Issue Status
apps/web/src/lib/code-reviews/dispatch/dispatch-pending-reviews.ts pending count misreported error-thrown dispatches as pending Fixed in abb6338c2
apps/web/src/lib/code-reviews/dispatch/dispatch-pending-code-review-owners.ts Redundant async/await wrapper in pLimit call Fixed in 395834f36
apps/web/src/lib/code-reviews/dispatch/dispatch-pending-code-review-owners.ts Recovery path when bot creation failed during config Fixed in a9cf55d62
apps/web/src/routers/admin-code-reviews-router.ts:216 Aggregate query could restrict base scan to live queue Fixed in 134c66820
apps/web/src/lib/code-reviews/db/code-reviews.ts:253 Minute cron avoiding grouping/sorting whole table Fixed in fee6591f4
apps/web/src/lib/code-reviews/db/code-reviews.ts:223 active_work CTE encoding duplicated condition Fixed in e70fbf8a4
apps/web/src/routers/admin-code-reviews-router.ts:183 waitingOwnerCondition shared filter Fixed in 262bea245
Files Reviewed (19 files)
  • apps/web/src/app/admin/api/code-reviews/hooks.ts
  • apps/web/src/app/admin/code-reviews/page.tsx
  • apps/web/src/app/admin/components/CodeReviewQueueHealthSummary.test.ts
  • apps/web/src/app/admin/components/CodeReviewQueueHealthSummary.tsx
  • apps/web/src/app/api/cron/dispatch-pending-code-reviews/route.test.ts
  • apps/web/src/app/api/cron/dispatch-pending-code-reviews/route.ts
  • apps/web/src/lib/code-reviews/db/code-reviews.ts
  • apps/web/src/lib/code-reviews/dispatch/dispatch-constants.ts
  • apps/web/src/lib/code-reviews/dispatch/dispatch-pending-code-review-owners.test.ts
  • apps/web/src/lib/code-reviews/dispatch/dispatch-pending-code-review-owners.ts
  • apps/web/src/lib/code-reviews/dispatch/dispatch-pending-reviews.test.ts
  • apps/web/src/lib/code-reviews/dispatch/dispatch-pending-reviews.ts
  • apps/web/src/routers/admin-code-reviews-router.test.ts
  • apps/web/src/routers/admin-code-reviews-router.ts
  • apps/web/vercel.json
  • packages/db/src/migrations/0136_neat_lady_deathstrike.sql
  • packages/db/src/migrations/0137_redundant_doctor_spectrum.sql
  • packages/db/src/migrations/0138_dry_korath.sql
  • packages/db/src/schema.ts

Reviewed by claude-4.6-sonnet-20260217 · 904,209 tokens

Review guidance: REVIEW.md from base branch main

Comment thread apps/web/src/lib/code-reviews/dispatch/dispatch-pending-code-review-owners.ts Outdated
Comment thread apps/web/src/routers/admin-code-reviews-router.ts
Comment thread apps/web/src/lib/code-reviews/db/code-reviews.ts
Comment thread apps/web/src/lib/code-reviews/db/code-reviews.ts
Comment thread apps/web/src/routers/admin-code-reviews-router.ts
@alex-alecu
Copy link
Copy Markdown
Contributor Author

Manual test passed.

Tested:

  • Opened /admin/code-reviews as a local admin; the Current queue health card rendered and reflected seeded pending, stale queued, and stale-running queue state before and after refresh.
  • Called /api/cron/dispatch-pending-code-reviews without auth (401) and with the configured bearer secret (200); the authorized drain considered 2 owners and dispatched 2 reviews.

Verified:

  • A pending review and a queued claim older than five minutes were re-reserved and handed to the local code-review worker, which accepted both dispatches.
  • Persisted queue state recorded replacement reservation IDs and attempt rows, while a running review older than ninety minutes stayed running; queue-health counts dropped pending/stale queued to zero while retaining the stale-running diagnostic.

@alex-alecu alex-alecu changed the title fix(code-reviews): drain pending queues fix(code-reviews): drain stuck pending queues May 20, 2026
@alex-alecu alex-alecu merged commit 17baaa0 into main May 21, 2026
50 checks passed
@alex-alecu alex-alecu deleted the feat/queue-recovery branch May 21, 2026 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants