···118118119119 let permit = match self.semaphore.clone().try_acquire_owned() {
120120 Ok(p) => p,
121121- Err(_) => break,
121121+ Err(_) => {
122122+ // remove before breaking so the DID isn't permanently stuck in
123123+ // in_flight with no task to clean it up
124124+ self.in_flight.remove_sync(&did);
125125+ break;
126126+ }
122127 };
123128124129 let guard = InFlightGuard {
···445450 error!(err = %e, "failed to wipe repo during backfill");
446451 }
447452 batch.commit().into_diagnostic()?;
448448- return Ok(Some(previous_state)); // stop backfill
453453+ // return None so did_task handles the repos/pending count decrements
454454+ // and skips sending BackfillFinished (nothing to drain for a deleted repo)
455455+ return Ok(None);
449456 }
450457451458 let inactive_status = match e {
+24-2
src/db/mod.rs
···593593 if delta >= 0 {
594594 *entry = entry.saturating_add(delta as u64);
595595 } else {
596596- *entry = entry.saturating_sub(delta.unsigned_abs());
596596+ let decrement = delta.unsigned_abs();
597597+ if *entry < decrement {
598598+ error!(
599599+ key,
600600+ current = *entry,
601601+ decrement,
602602+ "count underflow !!! this is a bug"
603603+ );
604604+ *entry = 0;
605605+ } else {
606606+ *entry -= decrement;
607607+ }
597608 }
598609 }
599610···606617 if delta >= 0 {
607618 *entry = entry.saturating_add(delta as u64);
608619 } else {
609609- *entry = entry.saturating_sub(delta.unsigned_abs());
620620+ let decrement = delta.unsigned_abs();
621621+ if *entry < decrement {
622622+ error!(
623623+ key,
624624+ current = *entry,
625625+ decrement,
626626+ "count underflow !!! this is a bug"
627627+ );
628628+ *entry = 0;
629629+ } else {
630630+ *entry -= decrement;
631631+ }
610632 }
611633 }
612634