fix: improve final image selection in stream processor

When n=1, the stream processor locks onto the first image received
as target. If a different image gets its final version first,
completed >= n breaks the WebSocket loop, but the processor saves
the target's medium-quality data as "final".

Now checks if the target actually has is_final=True before selecting
it. If not, falls back to the highest quality image available.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
chenhuawang-04andClaude Opus 4.6 committed 2026-02-26 16:13:55 +08:00
1 parent 1d29bc44c8
commit 53ab1fd086
1 file changed
+14 -15
+14 -15
View File
@@ -541,22 +541,21 @@ class ImageWSStreamProcessor(ImageWSBaseProcessor):
)
if self.n == 1:
if self._target_id and self._target_id in images:
selected = [(self._target_id, images[self._target_id])]
target_item = images.get(self._target_id) if self._target_id else None
if target_item and target_item.get("is_final", False):
selected = [(self._target_id, target_item)]
elif images:
selected = [
max(
images.items(),
key=lambda x: (
x[1].get("is_final", False),
x[1].get("blob_size", 0),
),
)
]
else:
selected = (
[
max(
images.items(),
key=lambda x: (
x[1].get("is_final", False),
x[1].get("blob_size", 0),
),
)
]
if images
else []
)
selected = []
else:
selected = [
(image_id, images[image_id])