Skip to content

feat(queue): reclaim exact-review leases via worker heartbeats and scheduled reconciliation - #620

Merged
steipete merged 1 commit into
mainfrom
feat/exact-review-lease-heartbeat
Jul 16, 2026
Merged

steipete merged 1 commit into
mainfrom
feat/exact-review-lease-heartbeat

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Why

Jul 14-15 incident: dead exact-review workers pinned all 64 lease slots (oldest pending 15h) because lease release depends on run completion events plus a 130-minute execution-lease expiry. A hung worker holds a slot for the full lease; a missed workflow_run event or a failed event-driven reconcile job (they fail under API rate limits) leaves only that slow expiry path.

What

  • Lease heartbeat: claimed review workers POST a tuple-authenticated heartbeat every 5 minutes (same capability model as /claim and /complete — the Codex-adjacent step never sees the webhook secret). After the first beat, effective lease expiry becomes min(leaseExpiresAt, lastBeat + EXACT_REVIEW_HEARTBEAT_GRACE_MS) (default 20 min, floor 7 min so a misconfigured grace can never reclaim a healthy lease between 5-minute beats). Leases that never heartbeat keep today's 130-minute behavior, so in-flight leases survive the deploy.
  • Scheduled sweep reconciler: every 15 minutes (plus workflow_dispatch), fetch the queue's claimed run tuples (bounded, <=64), check actual run status via the Actions API (actions: read only), and batch-reconcile completed ones. Covers missed workflow_run events and failed event-driven reconciles; partial lookup failures (rate limits, retention-expired runs) log and retry next sweep instead of failing the job.
  • Durable Object alarm wake times now use the heartbeat-aware effective expiry so reclamation fires on time.

Proof

  • node --test test/dashboard-worker.test.ts test/sweep-workflow.test.ts — 181 pass (heartbeat endpoint happy path + tuple mismatch 409, heartbeat-stale lease requeue before execution expiry, legacy no-heartbeat behavior preserved, claimed-runs snapshot -> tuple-safe terminal reconciliation, workflow assertions incl. no-secret-in-review-step).
  • Cron sweep script syntax-verified under node --input-type=module (stdin ESM).
  • pnpm run check:limits green; autoreview (Codex Sol, xhigh) clean after addressing two findings: webhook secret must not enter the Codex process tree (now tuple-auth, no secret in the step), and heartbeat-grace floor must exceed the beat interval (now 7 min).

@steipete
steipete requested a review from a team as a code owner July 16, 2026 04:58

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 688a3bcb9b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +860 to +862
if [ "$heartbeat_status" = "409" ]; then
echo "::notice::Exact-review heartbeat lost its lease tuple."
return

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Stop stale reviews when heartbeat loses the lease

When /heartbeat returns 409, the queue has already reclaimed or superseded this lease, but this branch only stops the background heartbeat and lets the foreground review continue. Because the later publication enqueue is gated on the review step succeeding rather than on the heartbeat still owning the lease, a long-running review that loses its lease can still enqueue and publish an artifact after the item has been requeued to another worker, defeating the heartbeat reclamation and risking duplicate or stale review output.

Useful? React with 👍 / 👎.

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.

1 participant