Skip to content

fix(fleet-queue): claim by explicit id; pin claim lease + lane storage (#7617) - #7882

Merged
developing-today[bot] merged 2 commits into
mainfrom
queue/14226-7617-claim-lease-lane
Nov 9, 2026
Merged

developing-today[bot] merged 2 commits into
mainfrom
queue/14226-7617-claim-lease-lane

Conversation

@developing-today

@developing-today developing-today Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Closes #7617

What was wrong

verb_claim (Turso queue broker) claimed a task via a subquery, then re-read the result as "the newest claimed row for (queue, worker_id)". Every lane shares worker_id = repo-worker-code, so under concurrent claims that re-read can return another lane's just-claimed task:

The lease contract was also one literal away from the same class of bug: 2700 (claim default) and 900 (heartbeat extension default) were bare literals in different verbs.

Fix

  • Pick the candidate id first, claim THAT row with a conditional UPDATE ... WHERE id = ? AND status IN ('queued','parked') (status re-check keeps the claim atomic; a lost race re-picks), read the claimed row back by id. The leases row insert now provably names the same task the caller is handed.
  • Named constants CLAIM_DEFAULT_LEASE_SECONDS = 2700 and HEARTBEAT_DEFAULT_EXTEND_SECONDS = 900; claim_lease_until() is the single source for the stored lease_until (tasks row and leases row), computed from one clock read with claimed_at.

Regression tests (oracle: #7617 acceptance)

  • claim_lease_is_the_requested_lease_not_the_heartbeat_default — stored lease is claimed_at + requested lease (2700), never + the 900 s heartbeat default; the two defaults are pinned distinct.
  • claim_lane_argument_is_stored_verbatim — the lane passed at claim reaches the UPDATE verbatim; a lane-less claim stores NULL, never another lane's id.

Verified on the laptop: cargo test -p fleet-queue --features queue-broker --lib claim_ → 10 passed incl. both new tests; full turso_queue suite 20 passed. Queue task 14226.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

#7617)

verb_claim claimed via a subquery and re-read the result as the newest claimed row for (queue, worker_id). Every lane shares worker_id repo-worker-code, so under concurrent claims that re-read could return another lane's just-claimed task: the caller was handed a row stamped with a foreign lane_id (live repro 2026-11-08: lane code-u claims returned tasks stamped code-e and code-t), worked a task it did not own, and the claim guard could quarantine a live foreign claim. This is the writer that can release/displace a live claim named in #7617, alongside the lease contract confusion.

- Pick the candidate id first, claim THAT row with a conditional UPDATE by id (status re-check keeps it atomic; a lost race re-picks), and read the claimed row back by id.
- Split the lease defaults into named constants: CLAIM_DEFAULT_LEASE_SECONDS=2700 for claims, HEARTBEAT_DEFAULT_EXTEND_SECONDS=900 for heartbeats, with claim_lease_until() as the single source for the stored lease_until on both the tasks and leases rows.
- Regression tests (oracle: #7617 acceptance): claim_lease_is_the_requested_lease_not_the_heartbeat_default and claim_lane_argument_is_stored_verbatim.

Tests: cargo test -p fleet-queue --features queue-broker --lib claim_ -> 10 passed incl. both new tests; turso_queue suite 20 passed.
@developing-today
developing-today Bot requested review from a team and dezren39 as code owners November 9, 2026 00:44
@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e33b74e6-481d-4b23-966c-4e0252c438c7

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

…stant (#7617)

Review catch on PR #7882: between the pick SELECT and the claim UPDATE, the picked row could be parked into the future (or hit its attempts cap); the UPDATE must re-verify status/attempts/not_before for the picked id, not just status membership.
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.

repo-queue: claim lease dies ~15 min after a 45 min claim; claimed task leaves claim state without a heartbeat/park

0 participants