Skip to content

fix(plugins): harden Stack Overflow question URL parsing and owner NoneType defense - #14546

Merged
kodjima33 merged 1 commit into
BasedHardware:mainfrom
shuoYun114:fix/stackoverflow-url-parsing-and-owner-none-guard
Sep 18, 2026
Merged

kodjima33 merged 1 commit into
BasedHardware:mainfrom
shuoYun114:fix/stackoverflow-url-parsing-and-owner-none-guard

Conversation

@shuoYun114

@shuoYun114 shuoYun114 commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Failure class (fixes)

Failure-Class: none

Fixes #14545

Summary of Changes

This pull request hardens the omi-stack-overflow-app plugin against unhandled NoneType crashes, adds flexible URL / identifier target parsing across Stack Exchange sites, cleans dirty inputs, and introduces a hermetic test suite with CI contract enforcement:

  1. Defensive Guard Against Deleted/Anonymous Owner (AttributeError):

    • In _format_answer, safely verify isinstance(owner, dict)" before extracting display_name.
    • When owner is bull, defaults cleanly to "unknown" instead of raising AttributeError: 'NoneType' object has no attribute 'get' and crashing with 500.
  2. Full Question URL & Site Domain Extraction:

    • Introduced _parse_question_target in get_question and get_top_answers.
    • Supports raw integer IDs (11227809), prefixed formats (#11227809, question: 11227809), full URLs (https://stackoverflow.com/questions/11227809/...), short URLs (https://superuser.com/q/12345), and automatically infers network sites (stackoverflow, superuser, serverfault, askubuntu,smathoverflow, etc.) when site` is not explicitly passed.
  3. Dirty Input Sanitization & HTML Unescape Ordering:

    • Defensively coerced limits against bool, Inf, NaN, and float strings.
    • Guarded _clean_text against invisible unicode formatting and adjusted unescape ordering so code tags inside HTML-escaped text (e.g. <div>>) are not stripped as HTML markup.
  4. Hermetic Test Suite (26 Tests):

    • Added plugins/omi-stack-overflow-app/test_main.py containing 26 hermetic unit tests.
    • Includes lightweight standard-library test stubs so the suite runs cleanly in any bare Python environment without external network calls.
  5. CI Contract Registration:

    • Registered omi-stack-overflow-tests under .github/checks-manifest.yaml in both local and ci lanes.

Verification

All 26 hermetic tests and repository checks pass cleanly:
``@bash
python plugins/omi-stack-overflow-app/test_main.py

Ran 26 tests in 0.010s -> OK

python .github/scripts/run_checks.py --lane local --base 27ef82c

Manifest checks passed: 15 check(s).


### Bounty Claim

- Preferred: USDT (TRC20): `TGKmfSUmt2dggErAo8bicaCoXhkMwLetxV`
- Alternative: Bitcoin (BTC): `1NkUnv2365ZYJn64pseAcWRA6sJitxh2f`
- Contact Email: `[email protected]`


<!-- This is an auto-generated description by cubic. -->
<a href="https://cubic.dev/pr/BasedHardware/omi/pull/14546?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->

…neType defense

- Support question URL parsing and domain site extraction in get_question and get_top_answers

- Guard against NoneType in answer owner object to prevent 500 AttributeErrors on deleted accounts

- Defensively sanitize question queries, limits, and tags against non-finite values and malformed payloads

- Add hermetic test suite covering URL extraction, sanitization, and API error handling

- Register omi-stack-overflow-tests in checks-manifest.yaml

Failure-Class: none
@shuoYun114

Copy link
Copy Markdown
Contributor Author

Hi @kodjima33 @aaravgarg, quick 10-second review summary for ready-to-merge:

  • What changed: Regex question ID extraction from full Stack Overflow URLs and deep NoneType defense for unauthenticated/anonymous owners.
  • Zero breaking change: Fully preserves tool output format and gracefully displays missing owner details.
  • Verification: 25 hermetic unit tests passing, all core and mobile preflights green. Ready for one-click merge!

@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.

Confirmed still-broken on main (_format_answer does item.get('owner', {}).get('display_name') which raises AttributeError when owner is explicit None, not just absent). Fixes #14545, scoped root cause, green CI, 26 new hermetic tests: 4/5 (diff size is the only miss). Merging.

@kodjima33
kodjima33 merged commit 07203f0 into BasedHardware:main Sep 18, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(plugins/omi-stack-overflow-app): handle NoneType in answer owner, support URL question targets, and add test suite

3 participants