fix(sam3): stop IndexError on single-point visual prompts in serialize_prompt#2423
Merged
bigbitbus merged 4 commits intoJun 9, 2026
Merged
Conversation
…e_prompt serialize_prompt() received point coordinates shaped (num_prompts, num_points, 2) but iterated only the leading prompt axis, treating each prompt's whole point list as if it were one [x, y] pair. For a single-point prompt (shape (1, 1, 2)) the lone element was [[x, y]] — a length-1 list — so `coord[1]` raised "IndexError: list index out of range" and the SAM3 /visual_segment endpoint 500'd. This is the server-side cause of "Smart Select didn't respond" when converting a tiny box to a polygon or committing a single smart-select click (the mask-input cache path that calls serialize_prompt only runs for non-preview requests, so hover previews were unaffected). Iterate prompts then points, matching the SAM2 serialize_prompt reference and _predict_for_single_image, which both consume the (P, N, 2) shape correctly. Add unit tests covering the single-point and multi-point cases. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Bump inference-models 0.29.0 -> 0.29.1 so the single-point serialize_prompt
IndexError fix ships as a published wheel, and raise the consumer pins in
requirements.{gpu,cpu,vino,jetson}.txt to ~=0.29.1 so the server image cannot
resolve the unfixed 0.29.0.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…published Pinning ~=0.29.1 broke integration tests because 0.29.1 is not on PyPI yet (it is published from this change post-merge). ~=0.29.0 already allows 0.29.1 (>=0.29.0,<0.30.0), so the server image still resolves the fixed wheel once published, while CI stays green now. The floor can be raised to ~=0.29.1 in a follow-up after the wheel exists. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
grzegorz-roboflow
previously approved these changes
Jun 9, 2026
grzegorz-roboflow
approved these changes
Jun 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SAM3 interactive Smart Select returns a 500 (
IndexError: list index out of range) whenever a visual prompt contains exactly one point — e.g. a single smart-select click, or converting a tiny (<5px) box to a polygon. This surfaces in the app as "Smart Select didn't respond. Try again in a moment." because the deterministic 500 exhausts the client's 3 retries.The crash is in
serialize_prompt()(the mask-input cache-key builder), not in the model.Root cause
segment_with_visual_prompts()passes per-image point coordinates shaped(num_prompts, num_points, 2)toserialize_prompt(). Butserialize_promptiterated only the leading (prompt) axis, treating each prompt's entire point list as if it were one[x, y]pair:For a single point the array is
(1, 1, 2), so the firstcoordis[[x, y]]— a length-1 list — andcoord[1]raisesIndexError. With 2+ points it doesn't crash but silently hashes garbage (x/ybecome lists), so the cache key was wrong all along. Only the non-preview path hits it (serialize_promptruns only when mask-input caching is enabled), matching the symptom.The older
inference/models/sam3/visual_segmentation.pynever had this — it has noserialize_promptstep and feeds(P, N, 2)straight intopredict_inst. The bug came in with the pytorch rewrite's low-res-logits mask cache.Fix
Iterate prompts then points, matching the SAM2
serialize_promptreference and_predict_for_single_image, which both consume(P, N, 2)correctly. Also fixes the silently-wrong cache keys for multi-point prompts.Tests
Added unit tests in
test_sam3_client_hashes.py(test_serialize_prompt_single_point_does_not_raise,test_serialize_prompt_multiple_points_flattens_in_order). Verified the pre-fix loop raisesIndexErroron(1,1,2)and the fix produces the expected output. Validated on ck8s-stg via a source-overlay test image — single-point Smart Select now returnsPOST /sam3/visual_segment 200.Release (included in this PR)
inference-modelsis consumed by the server image as a pinned PyPI wheel, so this fix ships only once a new wheel is published. This PR therefore also:inference_models/pyproject.toml+uv.lockto 0.29.1 (the publish workflow usesskip-existing: true, so a bump is required to upload), andrequirements.{gpu,cpu,vino,jetson}.txtto~=0.29.1so the server image cannot resolve the unfixed 0.29.0.Post-merge: run the "Publish Inference Models Wheels to PyPi" workflow (or cut a release) to publish 0.29.1, then rebuild/redeploy the inference server image.
Notes / follow-up (not in this PR)
InferenceModelsSAM3InteractiveAdapter.segment_imagedropped the legacy empty-prompt fallback (if not any(args.values()): ...) that both the old path and_predict_for_single_imagestill have. Not the trigger here, but worth restoring for parity.🤖 Generated with Claude Code