Shared helpers for concurrent per-tile dispatch failure handling.
These utilities are transport-agnostic and shared by every code path that fans a batch of tile requests out concurrently (the whole-slide inference pipeline and the standalone PyTorch adapter). They centralize how a batch summarizes and surfaces the tiles that failed after their per-request retry budget was exhausted, so the failure policy stays consistent and is defined in exactly one place.
summarize_indices
Formats a possibly-long list of tile indices for error messages.
The tile indices to format.
Maximum number of indices to list before truncating.
Returns:
A comma-separated string, truncated with a count if too long.
dispatch_failure_error
Builds a typed error summarizing per-tile dispatch failures.
Constructs (but does not raise) a BioptimusRuntimeError tagged with DISPATCH_FAILED, chaining the lowest-indexed failure as the cause. Callers raise the returned error with raise dispatch_failure_error(...) from ... or simply raise; the cause is already attached.
(tile_index, exception) pairs for each failed tile.
Total number of tiles in the batch.
Verb describing the operation for the message, for example "Dispatch" or "Prediction".
Optional extra clause inserted before the first error, for example "No output written.".
Returns:
The constructed error, with the first failure set as its cause.