Skip to content

fix(iq_rating): harden AI score array parsing against malformed elements (#14436) - #14518

Closed
Aj2280 wants to merge 1 commit into
BasedHardware:mainfrom
Aj2280:fix/iq-rating-score-array-parsing
Closed

Aj2280 wants to merge 1 commit into
BasedHardware:mainfrom
Aj2280:fix/iq-rating-score-array-parsing

Conversation

@Aj2280

@Aj2280 Aj2280 commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #14436 by hardening AI score array parsing in plugins/iq_rating/main.py:

  • Validates that each element in AI scores JSON array is a dictionary to prevent AttributeError on non-dict elements (integers, strings, nulls)
  • Safely coerces or defaults null / non-integer iq values to 100 without raising TypeError or ValueError
  • Guards against missing, null, or whitespace-only name
  • Normalizes is_name to boolean
  • Bounds failures strictly to the malformed element, preventing a single corrupted element from discarding all valid scores in the batch
  • Adds comprehensive hermetic regression test suite in plugins/iq_rating/test_main.py covering all edge cases

Evidence

  • Executed unit test suite with 6 comprehensive test cases:
    python -m unittest plugins/iq_rating/test_main.py (6 tests in 2.5s, OK)
  • Local preflight and pre-push check manifest passed cleanly.

Failure-Class: none

Review in cubic

…ed elements (BasedHardware#14436)

- Validate that each element in AI scores JSON array is a dictionary
- Guard against null or non-integer iq values with safe fallback to 100
- Guard against null or whitespace names
- Coerce is_name to boolean
- Add comprehensive regression test suite in plugins/iq_rating/test_main.py

Failure-Class: none

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Aj2280 — the production change here is solid and matches the issue's diagnosis well.

plugins/iq_rating/main.py — verified the new per-element guards in calculate_iq_with_ai(): the isinstance(scores, list) check, the per-element isinstance(score, dict) skip with a warning naming the offending type, name validation (missing / null / non-string / whitespace-only), guarded int() coercion defaulting to 100, and is_name normalization. Bounding the failure to the malformed element instead of letting the outer except Exception discard the whole batch is exactly the right fix, and the 70–160 clamp is preserved. The added .strip() on names is a small real improvement — an AI reply of " Alice " now still matches.

plugins/iq_rating/test_main.py — I ran the suite locally from the repo root (python3 -m unittest plugins.iq_rating.test_main): all 6 tests pass in ~2.5s, and the malformed-element, null / non-integer iq, invalid-name, non-list, and no-API-key paths are all covered. Good hermetic seam (requests.post + OPENAI_API_KEY patched, no network, no secrets).

One blocking gap before merge — both parts mechanical:

  1. The suite isn't registered in .github/checks-manifest.yaml, so it will never run in CI. Issue #14436 explicitly asked for the regression suite to be registered there, and every sibling plugin suite (omi-frankfurter-app, omi-open-meteo-app, omi-linear-app, omi-github-app, omi-google-calendar-app, omi-hacker-news-app) has an entry like:

    - id: iq-rating-score-parsing-tests
      command: ["python3", "plugins/iq_rating/test_main.py"]
      triggers: ["plugins/iq_rating/**", ".github/checks-manifest.yaml"]
      lanes: [local, "ci"]
      reason: "a non-object element or non-integer iq in the AI score array must skip only that element, not discard the whole batch's scores"

    Without it, a future refactor of this parsing can reintroduce the batch-discard bug with fully green checks — the exact silent failure mode the issue documents.

  2. As written, the file doesn't run under that manifest invocation. Manifest entries execute python3 plugins/iq_rating/test_main.py from the repo root, where sys.path[0] is the script's own directory — from plugins.iq_rating import main then raises ModuleNotFoundError: No module named 'plugins' (reproduced locally; your python -m unittest run worked only because -m puts the repo root on sys.path). That's exactly why the sibling suites (e.g. plugins/omi-hacker-news-app/test_main.py) load the module with importlib.util.spec_from_file_location instead of a package import — switching to that pattern makes the file work both standalone and under python -m unittest.

Nothing else blocking — the runtime hardening itself is good to go once the suite is actually wired into CI.

Automated maintainer review on behalf of the Omi maintainers; a human maintainer makes the final merge call.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Real bug fix for #14436, root cause and per-element guards are correct and match the issue. Confirmed the reviewer's blocking gap independently: the new test suite is not registered in .github/checks-manifest.yaml so it won't run in CI, and it uses a package import that would break under the manifest's direct-script invocation (unlike sibling plugin tests, which use importlib.util.spec_from_file_location). Confidence gate doesn't clear on 'proven correct' as submitted — approve only, not merging.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct root-cause fix for #14436 (malformed AI score array parsing), confidence 3/5: test suite unregistered in checks-manifest.yaml + broken import style means it's not verifiably proven. Approve only, do not merge.

@aryanorastar

Copy link
Copy Markdown
Collaborator

Closing. The IQ non-dict score guard is already on main. This head would drop tests main already has.

@github-actions

Copy link
Copy Markdown
Contributor

Hey @Aj2280 👋

Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request.

After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing.

Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out.

Thank you for being part of the Omi community!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants