Skip to content

fix(stack-overflow-app): guard malformed Stack Exchange payloads - #14334

Closed
xyjk0511 wants to merge 5 commits into
BasedHardware:mainfrom
xyjk0511:fix/stack-overflow-app-hardening
Closed

xyjk0511 wants to merge 5 commits into
BasedHardware:mainfrom
xyjk0511:fix/stack-overflow-app-hardening

Conversation

@xyjk0511

@xyjk0511 xyjk0511 commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

The Stack Exchange tools assumed a dict body whose items were objects with string fields and numeric timestamps. A non-dict body, a non-list items member, an entry that is not an object, a string tags member, or an out-of-range timestamp raised an unhandled error instead of a readable tool message.

Normalize at the parse boundary: _request_json rejects non-dict bodies, callers filter items to objects, _safe_tags_list accepts only a list, and _format_date rejects booleans and unparseable values. Well-formed responses render exactly as before.

Verification: python3 -m pytest plugins/omi-stack-overflow-app/ -q -> 18 passed.

Failure-Class: none

xyjk added 2 commits September 17, 2026 03:11
The tool assumed a dict body whose items were objects with string fields and\nnumeric timestamps. A non-dict body, a non-list items member, an entry that is\nnot an object, a string tags member or an out-of-range timestamp raised an\nunhandled error instead of a readable tool message.
…anifest

Repository rules require deterministic plugin tests to be registered in
.github/checks-manifest.yaml with a local and ci lane, otherwise the suite
never executes in CI. Add a shared hermetic runner for plugin suites that
drive the real FastAPI app.

@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 malformed-payload fix: root cause + tests but diff is 340 lines, exceeds 300-line scope gate = 3/5. Approve only.

@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 from this side, with one blocking issue in the test runner.

Parser hardening — verified correct. I ran your suite against the pre-fix main.py: 13 malformed-payload tests crash there ('str' object has no attribute 'get' from _request_json's old contract and non-dict owner, TypeError from datetime.fromtimestamp("not-a-timestamp"), and a string tags value iterated per-character into Tags: p, y, t, h, o, n). On this head all 16 pass, and the well-formed outputs are identical before/after — the happy path is preserved as described. _format_date's bool/out-of-range handling, _safe_tags_list, and the non-dict fallbacks in _format_question/_format_answer all check out on read-through as well.

Blocking: scripts/run-plugin-hermetic-tests.sh fails before running a single test. The uv path pins fastapi/httpx/pydantic/starlette but then invokes python -m pytest:

$ bash scripts/run-plugin-hermetic-tests.sh plugins/omi-stack-overflow-app
No module named pytest        # exit 1, zero tests executed

(reproduced in a clean layout with exactly the script's pinned wheels — pytest is simply not in pinned_deps; the venv fallback has the same gap since it only checks for fastapi/httpx.)

This matters because .github/checks-manifest.yaml routes the new stack-overflow-app-tests check through this script, and the Hygiene lane executes manifest checks on main pushes — the PR's checks are empty right now, so the lane would go red on the first push to main after merge. The verification line in the description ("pytest ... -> 18 passed", also 16 tests in the file) was evidently run directly with pytest rather than through the shipped script.

Two one-step fixes, either works:

  • add a pinned pytest entry to pinned_deps, or
  • follow the existing scripts/run-plugin-coingecko-tests.sh pattern: a unittest.main() test file driven with plain python, no pytest dependency.

Seeing @kodjima33's approval on this head — the request above is scoped only to the runner script; the app code changes are good to go from my side.

Automated maintainer-assistant feedback; final merge decisions rest with 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.

@Git-on-my-level Git-on-my-level added workflow-review Needs maintainer review for workflow, automation, hooks, or CI behavior python labels Sep 17, 2026
Review feedback: the runner switched to `python -m pytest` but pinned_deps
never gained pytest, so the uv path exited 1 with "No module named pytest"
before running a single test; the venv fallback had the same gap because it
only probed for fastapi/httpx. Pin pytest==8.4.1 (matching the repo-wide
version) and probe for it in the venv path.
@xyjk0511

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough verification. Fixed in e8705d57.

  • pytest==8.4.1 is now pinned in pinned_deps (the version the repo already pins elsewhere), and the venv fallback probes for fastapi, httpx, pytest instead of only fastapi/httpx.
  • Re-verified through the shipped shape: uv run --no-project --python 3.12 --with fastapi==0.121.0 --with httpx==0.28.1 --with pydantic==2.13.4 --with starlette==0.49.1 --with pytest==8.4.1 -- python -m pytest plugins/omi-stack-overflow-app -q -> 18 passed. You are right that the earlier number came from running pytest directly rather than through the script; that gap is closed now.

Good catch on the Hygiene lane going red on the first main push, that is exactly the failure this removes.

@xyjk0511

Copy link
Copy Markdown
Contributor Author

@Git-on-my-level The blocking item from your review is fixed in the latest commit.

pytest==8.4.1 is now pinned in pinned_deps, so the runner resolves pytest in a clean environment instead of failing with No module named pytest. Verified through the shipped script shape with uv run --no-project --python 3.12 --with fastapi==0.121.0 --with httpx==0.28.1 --with pydantic==2.13.4 --with starlette==0.49.1 --with pytest==8.4.1 -- python -m pytest <suites> -q -> all pass.

The non-blocking notes are covered too: the description no longer claims a 500 (the parent returned 200 with a generic error), and the redundant per-request timeout was dropped since the shared client already sets it.

Could you re-run the check on the current head?

Resolves the CONFLICTING state on BasedHardware#14334. The only conflict was
.github/checks-manifest.yaml, where main added mobile-event-registry and this
branch added stack-overflow-app-tests at the same position. The file is an
append-only registry, so both entries are kept; YAML parses and both ids are
present.

Constraint: the manifest is a shared registry every PR appends to, so the resolution must retain main's new entry rather than take either side wholesale.
Rejected: Taking the branch side of the manifest hunk | it would silently drop main's mobile-event-registry check from the registry.
Confidence: high
Scope-risk: narrow
Directive: If this file conflicts again, keep both hunks; the entries are independent and order is not significant.
Tested: yaml.safe_load parses (228 checks); both stack-overflow-app-tests and mobile-event-registry present; python -m pytest plugins/omi-stack-overflow-app/test_main.py -q -> 16 passed.
Not-tested: The full CI matrix, which the PR's own checks will exercise.
@xyjk0511

Copy link
Copy Markdown
Contributor Author

@Git-on-my-level The merge conflict that had this PR at CONFLICTING is resolved in 46c9794297; the PR is back to MERGEABLE.

The only conflicted file was .github/checks-manifest.yaml, and it was a pure both-sides-add at the same position: main added mobile-event-registry, this branch added stack-overflow-app-tests. Since the file is an append-only registry, both entries are kept rather than picking a side.

Verified after resolving:

  • yaml.safe_load parses the manifest (228 checks) and both stack-overflow-app-tests and mobile-event-registry are present
  • python -m pytest plugins/omi-stack-overflow-app/test_main.py -q -> 16 passed on the merged tree

The blocking item from your earlier review (pytest==8.4.1 missing from pinned_deps, plus the venv probe) is unchanged and still in place on the head. Ready for a re-run when convenient.

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

Resolved on current head 46c9794 and verified by execution: pytest==8.4.1 is now pinned in the runner's pinned_deps and the venv fallback probes for it; running the shipped entry point end-to-end passes 18 tests with exit 0. The original concern was the runner exiting with 'No module named pytest' before executing any test.

@Git-on-my-level

Copy link
Copy Markdown
Member

Follow-up verification on 46c9794 — the blocking runner issue from my earlier review is resolved, and this time I confirmed it by execution rather than read-through.

Runner fix verified. e8705d57 pins pytest==8.4.1 in pinned_deps and extends the venv fallback probe to import fastapi, httpx, pytest. Running the shipped entry point exactly as the manifest will (bash scripts/run-plugin-hermetic-tests.sh plugins/omi-stack-overflow-app, clean container, uv path): 18 passed, exit 0 — the 16 new tests in test_main.py plus the 2 pre-existing ones in test_format_question.py that the plugin-dir target also picks up (this also explains the 16-vs-18 count noted earlier). Re-running the suite against the pre-fix main.py fails 8 of the malformed-payload tests, so the suite is not vacuous.

Merge resolution verified. 46c9794 adds only the stack-overflow-app-tests entry to .github/checks-manifest.yaml: the diff against main's merge parent is exactly the +5 lines, main's mobile-event-registry entry is retained, YAML parses, and all 228 check ids are unique. One thing worth knowing: the new check first executes on the first push to main after this merges (the manifest lane runs on main pushes, not PRs) — it is green on this head, so no post-merge surprise.

Two non-blocking nits, take or leave:

  • scripts/run-plugin-hermetic-tests.sh: the final fallback message (line 44) still says "fastapi/httpx" without pytest.
  • _request_json now passes timeout= per request while _new_stack_client() already sets a client-wide timeout — harmless redundancy; being explicit is fine.

The parser hardening in plugins/omi-stack-overflow-app/main.py is unchanged since my earlier verified review (the merge didn't touch the plugin or the runner). With @kodjima33's approval on the parser code and this verification, the remaining step is maintainer sign-off on the CI-surface addition (the new manifest check + runner), which the workflow-review label tracks.

Automated maintainer-assistant feedback; final merge decisions rest with 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.

@Git-on-my-level Git-on-my-level added the positive-signal Automation verified a genuine fix/quality contribution label Sep 18, 2026
@xyjk0511

Copy link
Copy Markdown
Contributor Author

Withdrawing this one — it is superseded by #14546, which landed on main today.

I re-fetched main after noticing the PR had gone back to CONFLICTING, and the conflicts explain why:

  • plugins/omi-stack-overflow-app/main.py now carries the same payload-hardening at the same boundary. _request_json on main already does if not isinstance(data, dict): return {}, and _format_answer already guards a non-dict owner, which was the core of my change. Main's version is broader than mine (it also adds _parse_question_target, site inference, and flexible ID parsing).
  • plugins/omi-stack-overflow-app/test_main.py on main has 26 tests to my 16, covering the same malformed-payload cases.
  • .github/checks-manifest.yaml on main already registers omi-stack-overflow-tests, so the CI wiring I proposed is also covered.

That leaves no unique contribution here, so keeping it open would only produce a redundant merge and a needless conflict for whoever reviews it. Closing it is the honest outcome rather than re-pushing a conflict resolution for work that already landed by another route.

What still stands from this branch and is not on main: the pytest==8.4.1 pin plus the import fastapi, httpx, pytest probe in scripts/run-plugin-hermetic-tests.sh. Main does not have that script at all — it took the "run the file directly with python3" route instead, which sidesteps the dependency problem entirely. So that part is moot too.

Thanks to whoever reviewed it earlier; the two reviews were accurate, and the upstream fix is the better one.

@xyjk0511 xyjk0511 closed this Sep 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hey @xyjk0511 👋

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

positive-signal Automation verified a genuine fix/quality contribution python workflow-review Needs maintainer review for workflow, automation, hooks, or CI behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants