Repository navigation
Description
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-likeThe 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
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsIn review
Activity
shuoYun114 commentedon Sep 19, 2026
Locking this task / bounty.
As an active contributor with merged PRs (#14224, #14546), claiming lock privilege per official Omi Contribution Guidelines:
fix(iq_rating): harden AI score array parsing against malformed eleme…
fix(iq_rating): harden AI score array parsing against malformed eleme…
aryanorastar commentedon Sep 20, 2026
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