Skip to content

fix(reranker): stop a cancelled in-process rerank from starting more batches - #5795

Merged
nicoloboschi merged 2 commits into
mainfrom
fix/local-reranker-cancel-batches
Oct 19, 2026
Merged

nicoloboschi merged 2 commits into
mainfrom
fix/local-reranker-cancel-batches

Conversation

@nicoloboschi

@nicoloboschi nicoloboschi commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #5722.

When a caller cancels an in-process rerank (local SentenceTransformers, FlashRank, ONNX), the batch already running in the worker thread still finishes, but the remaining batches used to run too, holding the worker and making the next request wait.

Now each provider's _predict goes through _run_batches_in_executor, which hands the worker a per-call stop flag and sets it on cancellation. The batch loop checks it before each batch, next to the existing timeout check. Timeout / partial-score behaviour is unchanged, and a cancelled call still surfaces as CancelledError (no retry, no partial result).

Tests:

  • test_cancel_skips_batches_not_yet_started (bucketed and original order): cancels one request mid-first-batch and one while queued, then checks only the successor runs after. Fails on main (['a1', 'a2', 'successor']), passes with the fix.
  • test_set_cancel_flag_starts_no_batch_in_any_provider: local, FlashRank, ONNX start no batch once the flag is set.
  • test_every_batching_reranker_takes_a_cancel_flag: family guard so a new in-process reranker can't skip it (JinaMLX exempt: one call per query, no batch loop).

@nicoloboschi nicoloboschi changed the title fix(reranker): stop a cancelled local rerank from starting more batches fix(reranker): stop a cancelled in-process rerank from starting more batches Oct 19, 2026
Review fixes:
- sibling parity: FlashRank and ONNX had the same between-batch loop; all three now
  share _run_batches_in_executor, which sets a per-call stop flag on cancel
- family guard test: every in-process reranker with a _predict_sync takes the flag
  (JinaMLX exempt: one call per query, no batch loop)
@nicoloboschi
nicoloboschi force-pushed the fix/local-reranker-cancel-batches branch from eca1420 to 5caef46 Compare October 19, 2026 16:47
@nicoloboschi
nicoloboschi merged commit 72765d7 into main Oct 19, 2026
116 of 117 checks passed
@nicoloboschi
nicoloboschi deleted the fix/local-reranker-cancel-batches branch October 19, 2026 17:08
@nicoloboschi nicoloboschi mentioned this pull request Nov 3, 2026
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.

Local reranker cancellation leaves later abandoned scoring batches in the executor

1 participant