Skip to content

fix(schedules): re-examine stranded schedule claims within minutes instead of seven days - #10397

Merged
waleedlatif1 merged 1 commit into
stagingfrom
fix/schedule-stranded-claims
Nov 25, 2026
Merged

waleedlatif1 merged 1 commit into
stagingfrom
fix/schedule-stranded-claims

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • A schedule holding the claim on its current occurrence was only re-claimed once lastQueuedAt was older than the max execution timeout plus buffer (7 days + 5 min), so two cases left schedules silently stuck for a week while still showing active with no failures:
    • an enqueue that failed with an unknown outcome (queue API 5xx/timeout), which deliberately keeps the claim for "the next tick" to reconcile
    • a run that died without releasing its claim
  • Held claims are now re-examined after 10 minutes. The tick already resolves a re-claimed occurrence safely through its carrier's deterministic job id: restores the claim while the run is active, reconciles the outcome once it finished, and re-enqueues under the same idempotency key when the queue never got it
  • updatedAt is the re-check clock, and re-examining a held claim leaves lastQueuedAt untouched (it is the run's identity for the worker's claim-guarded writes), so a re-check never makes a live run look stale, and long runs are re-checked every 10 minutes rather than every tick
  • Moves the claim into lib/workflows/schedules/claim.ts; the remaining 7-day constant in the route is renamed to FALLBACK_SCHEDULE_EXECUTION_LEASE_MS, which is all it still does

Type of Change

  • Bug fix

Testing

  • New lib/workflows/schedules/claim.integration.ts against real Postgres. Red→green verified locally:
    • fails on the pre-fix filter (stranded current-occurrence claim never re-claimed)
    • fails with lastQueuedAt as the re-check clock (re-takes a recently re-examined claim)
    • fails when held claims are overwritten instead of preserved
    • fails when the earlier-occurrence branch is removed
  • app/api/schedules/execute/route.test.ts (37 passing)
  • biome on changed files, check:sql-date-binding, check:file-names, check:comment-hygiene, check:test-patterns, check:source-conventions, check:boundaries; full gate in CI

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Nov 25, 2026 2:53am UTC

Request Review

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@greptile-apps

greptile-apps Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issues were found.

Summary

Held schedule claims are now checked again after ten minutes instead of waiting seven days.

  • The schedule tick re-examines held claims after 10 minutes.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Due schedule] --> B{Claim eligible?}
  B -->|No claim or earlier occurrence| C[Set new claim time]
  B -->|Held and unchecked for ten minutes| D[Keep original claim time]
  C --> E[Update recheck time]
  D --> E
  E --> F[Look up deterministic job ID]
  F --> G{Existing job?}
  G -->|Active| H[Keep claim]
  G -->|Finished| I[Apply recorded outcome]
  G -->|Missing| J[Enqueue with same job ID]
Loading

Reviews (2) · Last reviewed commit: "fix(schedules): re-examine stranded sche..." · Reviewed by Greptile

@waleedlatif1
waleedlatif1 merged commit 84bfe5c into staging Nov 25, 2026
77 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/schedule-stranded-claims branch November 25, 2026 06:34

This branch was previously deployed

1 inactive deployment
Preview — 834e790c Deployed Nov 25, 2026 by vercel[bot]
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