Accept null score in hf-inference image-segmentation response#2197
Open
Sanjays2402 wants to merge 1 commit into
Open
Accept null score in hf-inference image-segmentation response#2197Sanjays2402 wants to merge 1 commit into
Sanjays2402 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 2c5934d. Configure here.
The image-segmentation output schema declares score as optional
(packages/tasks/src/tasks/image-segmentation/inference.ts: score?: number),
but the runtime validator in HFInferenceImageSegmentationTask only
accepted undefined or a number, rejecting null with:
API Implementation Error: TypeError: Invalid output: output must be
of type Array<{label:string; score:number; mask: string}>
Several HF-Inference models (e.g. jonathandinu/face-parsing) return
null for score on per-segment masks, which is consistent with the
optional schema field but tripped the strict type guard.
Allow null alongside undefined and number.
Refs huggingface#1430
2c5934d to
ad3b9ca
Compare
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.

Closes #1430.
What
Loosens the
HFInferenceImageSegmentationTask.getResponsetype guard to acceptscore === nullin addition toundefinedandnumber.Why
The image-segmentation output schema in
packages/tasks/src/tasks/image-segmentation/inference.tsdeclaresscoreas optional:…but the runtime validator in
packages/inference/src/providers/hf-inference.tsonly acceptedundefinedor anumber, rejectingnullwith:Several HF-Inference models (e.g.
jonathandinu/face-parsing, the one in the original report) returnnullforscoreon per-segment masks. That's consistent with the optional schema field, but the strict type guard treats it as a malformed response.Diff
(x) => typeof x.label === "string" && typeof x.mask === "string" && - (x.score === undefined || typeof x.score === "number"), + (x.score === undefined || x.score === null || typeof x.score === "number"),Out of scope
inference.tsto makescoreexplicitly nullable — leaving the schema as-is to avoid breaking anyone reading it.hf-inference.tswhose schema declaresscoreas optional, so the samenull-acceptance change isn't symmetric across the file.Note
Low Risk
Single-task response normalization in the HF-Inference provider with no auth, persistence, or API surface changes.
Overview
Fixes HF-Inference image-segmentation responses that were rejected when models return
score: null(e.g.jonathandinu/face-parsing), which previously triggered a malformed-output error despite optionalscorein the task schema.HFInferenceImageSegmentationTask.getResponsenow acceptsnullin its guard and normalizesnullscores toundefinedso returned data matchesscore?: numberand callers usingscore !== undefinedbehave correctly.Reviewed by Cursor Bugbot for commit ad3b9ca. Bugbot is set up for automated code reviews on this repo. Configure here.