Skip to content

feat(tasks): task claims are leases — ADR-018 D4 backfill - #901

Merged
lilyshen0722 merged 2 commits into
mainfrom
feat/task-claim-lease
Aug 12, 2026
Merged

lilyshen0722 merged 2 commits into
mainfrom
feat/task-claim-lease

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

What

D4's backfill: task claims get the same liveness rule as message claims. claimedBy previously had no deadline — a dead claimant held a task forever, invisibly.

  • Task.claimExpiresAt (new, default null) + a 30-minute lease stamped at claim time (matches the pod's claim-the-orphan ~30-min convention).
  • One CAS, four ways to win: unclaimed / the holder itself (renewal — same-call semantics as messageClaimService) / lapsed lease / legacy claim whose claimedAt is older than one lease. Legacy rows derive effective expiry from claimedAt — no migration, and no instant steal of work claimed minutes ago.
  • The 409 now names the holder and claimExpiresAt, so a loser stands down informed (D3), knowing when racing again is legitimate.
  • Reopen path clears the lease alongside claimedAt.
  • commonly_claim_task's description (unpublished 0.3.0) now carries the lease contract.

Tests

6 service-tier tests through the real route (fresh lease, live-lease refusal with holder+expiry, self-renewal extends, lapsed-lease reclaim, recent-legacy protected, stale-legacy reclaimable).

Not verified locally (rule: say what you didn't verify): Node 26 removed SlowBuffer, which breaks jsonwebtoken's dep chain for every service-tier suite on this machine — the pre-existing sibling suite (tasks.source-ref-idempotency) fails identically before any assertion runs. CI's Service Tests job (older Node) is the verification tier; treat a red there as a real finding, not flake.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XeUH4HVDsDHYPsHJthXjB8

claimedBy had no deadline: a dead claimant (closed laptop, killed wrapper)
held a task forever, invisibly. Message claims shipped with a lease (#892)
precisely to avoid this, which left two claim primitives with different
liveness rules — the gap D4 names.

The claim route now stamps claimExpiresAt (30 min — matches the pod's
claim-the-orphan convention of racing on work stalled ~30 min) and the CAS
admits four winners: unclaimed, the holder itself (renewal, same-call
semantics as messageClaimService), a lapsed lease, or a LEGACY claim
(claimExpiresAt null) whose claimedAt is older than one lease — legacy
rows derive their effective expiry from claimedAt, so there is no
migration and no instant steal of recently-claimed work. The 409 now
names the holder AND when the lease frees (D3: losers stand down
informed, not blind).

commonly_claim_task's description (unpublished 0.3.0) carries the lease
contract in the same falsifiable style as the tone contract.

Service-tier tests cover all six behaviors. NOT verified locally: Node 26
removed SlowBuffer, which breaks jsonwebtoken's dep chain for every
service-tier suite on this machine (the pre-existing sibling suite fails
identically) — CI's Service Tests job is the verification tier.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XeUH4HVDsDHYPsHJthXjB8
Comment thread backend/routes/tasksApi.ts Fixed
Same limiter shape as task-create in this file (token-hash keyed), at 30/60s:
renewals are re-claims, so the ceiling leaves room for a busy agent racing
several tasks while a runaway loop still hits the wall inside one lease
window. The gap predates this PR, but touching the handler makes it new
code — and the route did gain a reason to be called more often (renewal).

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XeUH4HVDsDHYPsHJthXjB8
@lilyshen0722
lilyshen0722 merged commit 9a6fce7 into main Aug 12, 2026
11 checks passed
@lilyshen0722
lilyshen0722 deleted the feat/task-claim-lease branch August 12, 2026 09:46
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