Skip to content

fix(stack-overflow-app): guard null payloads + typed request models (#14126) - #14133

Closed
t3ratech wants to merge 3 commits into
BasedHardware:mainfrom
t3ratech:fix/stack-overflow-14126
Closed

t3ratech wants to merge 3 commits into
BasedHardware:mainfrom
t3ratech:fix/stack-overflow-14126

Conversation

@t3ratech

@t3ratech t3ratech commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Closes #14126

Root cause

Stack Exchange returns "owner": null for deleted/anonymized users and "tags": null for untagged questions. dict.get(key, default) returns the stored None, not the default — so owner.get("display_name") and ", ".join(tags) crashed at the format layer. All three tool endpoints also took untyped dict payloads, so a malformed request produced a raw 422 — which crashes the Omi chat agent (tool responses must be HTTP 200 + ChatToolResponse).

Changes

  • models.py (new): SearchQuestionsRequest, GetQuestionRequest, GetTopAnswersRequest, ChatToolResponse — validators coerce Omi's null-means-default contract (site, limit, question_id)
  • main.py: RequestValidationError handler returns HTTP 200 ChatToolResponse(error=...) (same envelope as omi-coingecko-crypto-app); (item.get("owner") or {}) guard; _safe_tags_list for null/non-list/non-string tags; _safe_count for score/answers/views; non-dict payload + non-dict item guards in _request_json and all handlers
  • test_main.py (new): 23 hermetic regressions — framework-stubbed, stdlib-only
  • checks-manifest.yaml: stack-overflow-app-tests, local+ci lanes

Verification

  • python3 plugins/omi-stack-overflow-app/test_main.py → 23/23 pass on this head
  • Same suite against the unpatched module → 16 errors + 2 assertion failures (red→green)
  • Handler paths exercised through stubbed request models matching the coingecko envelope contract

/claim #14126 PayPal: [email removed]

Review in cubic

Failure-Class: none

@t3ratech

t3ratech commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor Author

/claim #14126 PayPal: [email removed]

@Git-on-my-level

Copy link
Copy Markdown
Member

Verified end to end - this is a careful fix. What I checked on 28f1196:

  • plugins/omi-stack-overflow-app/main.py - (item.get("owner") or {}) correctly fixes the reported crash (dict.get(key, default) returns the stored None, so the old owner.get("display_name") raised AttributeError on "owner": null); _safe_tags_list handles null/non-list tags and non-string members; _safe_count renders null score/answer/view as 0; non-dict guards in _request_json, _format_question, _format_answer, and per-item isinstance filters in all three handlers.
  • plugins/omi-stack-overflow-app/models.py - ChatToolResponse now enforces exactly-one-of result/error, and the request models coerce Omi's {"site": null, "limit": null} payload to documented defaults (limits clamped 1..10, question_id coerced/validated positive).
  • plugins/omi-stack-overflow-app/test_main.py - 23 hermetic tests; ran them in a clean container with no network and stdlib only: 23/23 pass, including from a repo root as the manifest invokes the command. I also drove the real app with the plugin's pinned fastapi 0.115.6 / pydantic 2.10.4 / httpx 0.28.1: empty body, null optionals, limit: "abc", and bad/null question_id all come back HTTP 200 with the ChatToolResponse(error=...) envelope - no 422s escape to the chat agent. The pre-existing test_format_question.py still passes against the new module.
  • .github/checks-manifest.yaml - the new stack-overflow-app-tests entry follows the existing entries and is green locally.

The RequestValidationError -> HTTP 200 handler mirrors the coingecko app's established envelope contract, which is the right call for chat-tool endpoints.

One merge note: .github/checks-manifest.yaml currently conflicts with main - several sibling plugin entries landed in the same region after this branch's merge base. The plugin files themselves merge clean, so a rebase onto latest main should be a trivial resolution. Happy to re-verify after the rebase.


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.

stack-overflow-app null-owner/tags fix for #14126, confirmed not yet fixed on main, scores 4/5 on confidence gate, but Hygiene required check just turned red and mergeStateStatus is UNKNOWN — approve only for now, re-check for merge once CI stabilizes. Duplicate of #14127 for the same issue.

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

Verified fix for #14126 — thank you for the clean, well-tested change.

Code review on aa8956d:

  • models.py — the null-means-default validators (null_site_means_default, null_limit_means_default, coerce_question_id) handle Omi's {"site": null, "limit": null} envelope correctly, and question_id coercion preserves the legacy int() behavior (numeric strings still accepted).
  • main.py — the RequestValidationError handler returning HTTP 200 ChatToolResponse matches the established pattern in plugins/omi-coingecko-crypto-app/main.py; (item.get("owner") or {}) fixes the null-owner AttributeError; _safe_tags_list/_safe_count guard the format layer; the non-dict guard in _request_json covers list/None payloads.
  • test_main.py — 23/23 pass; I confirmed red→green by running the same suite against the pre-fix module (16 errors + 2 failures reproduce the reported crashes).
  • checks-manifest.yaml — the stack-overflow-app-tests entry (local+ci lanes) registers cleanly, and the upstream-merge conflict resolution drops no existing entries.

I also exercised the app under the pinned real fastapi 0.115.6 / pydantic 2.10.4 (the committed suite stubs pydantic with a permissive fake, so those paths aren't pinned by it): null optionals coerce to defaults, missing/invalid fields return HTTP 200 error envelopes naming the field, numeric-string question_id coerces, limits clamp to 1..10, comma/semicolon string tags keep working, and the tools manifest serves. All green.

One blocking item (PR description only — no code change needed):
The Hygiene check fails on failure-class-protocol: a commit subject beginning with fix: requires a Failure-Class: declaration in the PR body, and the body currently has none (the commit message carries Failure-Class: none, but the protocol reads the PR description). Adding exactly one accepted form on its own line — e.g. Failure-Class: none — to the PR body will turn Hygiene green.

Non-blocking suggestion for a follow-up: because the hermetic suite stubs pydantic/fastapi, the null-coercion and 422→200 envelope paths aren't locked in by the registered check; a small real-framework variant would pin that contract in CI.

The earlier maintainer approval covers byte-identical plugin code (the head only adds an upstream merge), so once the body trailer is added this should be ready to merge. Changing this review to an approval is deliberately left to the human maintainers.


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

…asedHardware#14126)

Stack Exchange returns "owner": null for deleted users and "tags": null
for untagged questions; both crashed formatters via .get-on-None and
join-on-None. Untyped dict payloads skipped schema validation entirely,
and a raw 422 crashes the Omi chat agent.

- models.py: typed request models, null-means-default coercion
- main.py: RequestValidationError -> HTTP 200 ChatToolResponse envelope,
  null-owner/null-tags/non-dict-item guards, _safe_count for counters
- test_main.py: 23 hermetic regressions (18 fail on unpatched code)
- checks-manifest: stack-overflow-app-tests, local+ci lanes

Verification: python3 plugins/omi-stack-overflow-app/test_main.py — 23/23
green on this head; same suite reports 16 errors + 2 failures against
the unpatched module.

Failure-Class: none
@t3ratech
t3ratech force-pushed the fix/stack-overflow-14126 branch from aa8956d to c8ec3c6 Compare September 17, 2026 05:46
@t3ratech

Copy link
Copy Markdown
Contributor Author

Status update — the one blocking item from the review is already satisfied, and the remaining red check is an unrelated flake.

1. Failure-Class trailer — done. The PR body carries Failure-Class: none on its own line (line 25), and Hygiene is now green on this head. That was the only blocking item called out, so the review can move to approval whenever you get a chance, @Git-on-my-level.

2. Dart Analyze & Tests (FAILURE) is unrelated to this PR. Evidence:

That points at a timing/temp-file flake in the WAL reconstruction test rather than anything on these branches. A re-run of the Dart job should clear it; I don't have re-run rights on the upstream repo. Happy to open a separate issue for the flaky test if that's useful — say the word and I'll take it with a PR rather than just filing it.

@Git-on-my-level
Git-on-my-level dismissed their stale review September 18, 2026 16:18

Resolved on current head b9decc8: the PR body now carries 'Failure-Class: none' on its own line and the Hygiene failure-class-protocol check is green. Plugin code is unchanged from the reviewed commit; the only open items are the rebase onto main after #14546 and manifest id reconciliation, which are tracked in the discussion.

@Git-on-my-level

Copy link
Copy Markdown
Member

Status update on b9decc8 — the ground under this PR shifted today, so here is where things stand.

Resolved since the last review:

  • The one blocking item is fixed: the PR body now carries Failure-Class: none on its own line, and the Hygiene failure-class-protocol check is green on this head. The plugin files themselves are byte-identical to the previously reviewed aa8956d (the new commit only dedups the manifest entry), so the earlier code verification carries over — I also re-ran the hermetic suite from the head's files: 23/23 pass, stdlib-only, no network.
  • The red Dart Analyze & Tests check is not from this PR: the only failure is app/test/unit/capture_recovery_replay_scenarios_test.dart (a Flutter capture/WAL replay test). This PR touches no Dart files, so that is treated as an unrelated flake.

New situation — main has moved:

What this PR still uniquely adds over main:

  • models.py typed request models with null-means-default coercion, the global RequestValidationError → HTTP 200 ChatToolResponse envelope (main's payload: dict[str, Any] handlers can still return a raw 422 for non-object JSON bodies, which is exactly the chat-agent crash class this PR closes), the exactly-one-of result/error contract on ChatToolResponse, and the 23-test regression suite.

Suggested path forward:

  1. Rebase onto latest main. In main.py, keep fix(plugins): harden Stack Overflow question URL parsing and owner NoneType defense #14546's parsing/owner guards and layer the typed models + validation envelope on top rather than re-applying the old formatter code.
  2. Reconcile the manifest: main now registers omi-stack-overflow-tests with a plugins/omi-stack-overflow-app/** trigger; keeping this branch's stack-overflow-app-tests id as-is would double-register the suite. Either fold the new contract tests into main's test_main.py under the existing id, or replace the id in this branch's entry so exactly one check owns the trigger.

Maintainer note: with #14546 already merged and #14127 also open on this plugin, a human call is needed on which track lands the typed-models layer — flagging for maintainer review rather than blocking, since the remaining delta is additive robustness rather than a bug main still carries.


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

@Git-on-my-level Git-on-my-level added the needs-maintainer-review Needs a human maintainer to sign off before merge label Sep 18, 2026
@aryanorastar

Copy link
Copy Markdown
Collaborator

Closing as a later duplicate of #14127, opened earlier for the same file class.

Both PRs still change overlapping production files (plugins/omi-stack-overflow-app/main.py, plugins/omi-stack-overflow-app/models.py, plugins/omi-stack-overflow-app/test_main.py). This later head is b9decc889146. MERGEABLE or extra tests on this tip do not replace the earlier vehicle. Continue on #14127.

@github-actions

Copy link
Copy Markdown
Contributor

Hey @t3ratech 👋

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

needs-maintainer-review Needs a human maintainer to sign off before merge positive-signal Automation verified a genuine fix/quality contribution python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Plugin] Fix uncaught crashes on null owner and unhandled validation in omi-stack-overflow-app

4 participants