Skip to content

iq_rating: a non-object element in the AI score array discards the whole batch's scores #14436

Closed

Description

@sayed1145

Symptom

plugins/iq_rating/main.py -> calculate_iq_with_ai() reads every element of the model's JSON
score array as a mapping and coerces iq with int():

for score in scores:
    name = score.get("name", "").lower()   # assumes every element is a mapping
    iq = score.get("iq", 100)
    is_name = score.get("is_name", True)
    ...
    "iq": max(70, min(160, int(iq))),      # assumes iq is number-like

The prompt asks the model for a JSON array and nothing validates its shape, so a single element
that is not an object (1, "alice", null) or an iq that is not number-like (null) raises.
The surrounding except Exception catches it, logs it, and moves on — which discards every
valid score in that batch
:

[1, {"name": "alice", "iq": 120}]  ->  alice is scored from the random fallback, not 120

Why it is silent

calculate_iq_with_ai() fills every person missing from iq_scores with
calculate_iq_score_random(), so after the discard the caller cannot tell "the model returned
nothing for this batch" from "one entry in this batch was malformed". A stray element costs the
whole batch its real scores and nobody sees a failure.

Evidence

On current main, driving the real function through a patched requests.post seam
(plugins/iq_rating/test_score_array_parsing.py, stubbed FastAPI/requests imports):

FAIL test_leading_non_object_element_keeps_the_valid_scores: alice fell back to {'iq': -1, 'is_name': True}
FAIL test_null_element_keeps_the_valid_scores: alice fell back to {'iq': -1, 'is_name': True}
FAIL test_string_element_keeps_the_valid_scores: alice fell back to {'iq': -1, 'is_name': True}
FAIL test_null_iq_falls_back_without_losing_its_siblings: bob fell back to {'iq': -1, 'is_name': True}
4/8 passed

and the swallowed exceptions appear in the runtime log:

ERROR - Error parsing AI response: 'int' object has no attribute 'get'
ERROR - Error parsing AI response: 'NoneType' object has no attribute 'get'
ERROR - Error parsing AI response: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'
ERROR - Error parsing AI response: 'str' object has no attribute 'get'

Related but distinct

The guards already landed for choices[0] indexing (e.g. the check at main.py:1089) cover the
envelope around the reply, not the shape of the array inside it. This is the inner loop, one level
down, and it is still unguarded — same class of defect, different position.

Suggested fix

Validate per element and bound the damage to the element that is wrong: require a mapping, require
a non-empty string name, coerce iq with a guarded int() defaulting to 100, normalise is_name
to a bool, and skip only the offending element with a warning that names its type. A PR doing
exactly that, with the regression suite above registered in .github/checks-manifest.yaml, follows.

Per the Contribution guide ("No bounties available? ... suggest your own"), proposing a US$25
bounty for this fix + regression test. cc @josancamon19 @kodjima33

Activity

  1. moved this from Someday to In progress in omi TODO / bountieson Sep 17, 2026
  2. shuoYun114 commented on Sep 19, 2026

    @shuoYun114
    Contributor

    Locking this task / bounty.

    As an active contributor with merged PRs (#14224, #14546), claiming lock privilege per official Omi Contribution Guidelines:

  3. aryanorastar commented on Sep 20, 2026

    @aryanorastar
    Collaborator

    Closing as already fixed on current main.

    Merged #14682; current main calculate_iq_with_ai skips non-dict score elements instead of discarding the batch

  4. moved this from In progress to In review in omi TODO / bountieson Sep 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions