Repository navigation
fix(coingecko-app): guard malformed payloads and coerce numeric fields - #14332
Conversation
The CoinGecko parsers assumed every response was the documented shape: a dict body, a list of dicts, and JSON numbers. An upstream edge or error page that returns a JSON list, a bare string body, or numeric fields encoded as strings raised an unhandled AttributeError/TypeError, so the tool answered with an internal failure instead of a readable error. Normalize at the parse boundary: _as_dict/_as_list validate container types, _coerce_number converts numeric or numeric-string fields, and entry lists are filtered to dicts. Well-formed responses render exactly as before.
…odies The shared client already carries a timeout, but the tool call did not pass one\nand a CDN edge can answer with HTML. Both paths ended as an unhandled error\ninstead of a readable tool message.
|
The workflow runs for this PR are sitting in |
…check The registered coingecko check only executed test_null_optionals.py, so the new response-parsing guards had no CI coverage. Run both suites instead.
kodjima33
left a comment
There was a problem hiding this comment.
CoinGecko malformed-payload fix: root cause, scoped (185 lines/3 files), test regression proof = 4-5/5. mergeStateStatus UNKNOWN after refetch -- approve only per override b.
Git-on-my-level
left a comment
There was a problem hiding this comment.
Thanks @xyjk0511 — the parsing-boundary hardening in main.py is well done, and the regression suite is genuinely load-bearing (4 of the 9 new cases fail on the parent revision; all 9 pass here, and test_null_optionals.py still passes unchanged). One blocker before this can merge:
scripts/run-plugin-coingecko-tests.sh now runs python -m pytest (both the uv and venv paths) but pinned_deps doesn't include pytest. In a clean environment the pinned set (fastapi/httpx/pydantic/starlette) has no pytest, so the script fails with No module named pytest. This script is the coingecko-null-optionals-tests lane in .github/checks-manifest.yaml and runs on every change under plugins/omi-coingecko-crypto-app/**, so this PR breaks the very checks that validate it. The old python "$test_file" form didn't need pytest — the switch to pytest requires adding it to pinned_deps (e.g. a pinned pytest==8.x). One-line fix.
Two non-blocking notes:
- The PR description says the old code "returned a 500" — the parent revision already returned 200 with an
errorfield viaexcept Exception. The actual improvement (specific errors, partial results instead ofUnexpected error ... 'list' object has no attribute 'get', numeric-string coercion) is real and worth describing accurately. - The per-request
timeout=REQUEST_TIMEOUT_SECONDSin_fetch_coingeckois redundant — the sharedAsyncClientis already constructed with it — but harmless.
With pytest pinned and the lane green, this looks good. Leaving for human maintainer review before merge (CI runner change from a first-time contributor needs maintainer sign-off).
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
…undant timeout Review feedback: the runner switched to `python -m pytest` but pinned_deps never gained pytest, so a clean environment failed with "No module named pytest" and broke the very lane that validates this plugin. Pin pytest==8.4.1 (matching the version already used elsewhere in the repo). The shared AsyncClient already carries REQUEST_TIMEOUT_SECONDS, so the per-request timeout argument was redundant; drop it.
|
Thanks for the careful review. All three points are addressed in
Understood on maintainer sign-off for a CI runner change from a first-time contributor. |
|
@Git-on-my-level The blocking item from your review is fixed in the latest commit.
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? |
Reviewer's blocker on BasedHardware#14332 was that run-plugin-coingecko-tests.sh invokes python -m pytest without pytest in the pinned set. The uv path was fixed, but the venv fallback still probed only fastapi/httpx, so a clean venv that has those two would still die with 'No module named pytest' before running a test. Constraint: .github/checks-manifest.yaml routes coingecko-null-optionals-tests through this script, and the Hygiene lane runs manifest checks on main pushes, so a gap here goes red after merge. Rejected: Leaving the venv path as-is because CI prefers uv | the fallback is reachable whenever uv is absent, which is exactly the clean-environment case the reviewer reproduced. Confidence: high Scope-risk: narrow Directive: Keep this probe in sync with pinned_deps; it exists to fail loudly rather than vacuously. Tested: python -c 'import fastapi, httpx, pytest' -> deps ok; python -m pytest on test_malformed_payloads.py + test_null_optionals.py -> 14 passed. Not-tested: The uv path, which the same PR already pinned pytest for.
|
@Git-on-my-level The venv-path gap is closed in You were right that the earlier fix only covered half the script. The uv path pinned Verified through the venv shape the fallback uses: So both paths now fail loudly if a dep is missing rather than dying at import time. Ready for a re-run on the current head when you have a moment. |
kodjima33
left a comment
There was a problem hiding this comment.
Confidence gate 5/5: root cause clear (parsing-boundary type guards for malformed CoinGecko payloads), test regression proof (4/9 new cases fail on parent revision), the pytest-pinning blocker from the earlier CHANGES_REQUESTED review (missing pytest in pinned_deps) was fixed in commit 2f1f55a and the venv-fallback gap in 3500cc8; CI is fully green on the current head commit (Hygiene lane, which runs the manifest-registered check, passes). Re-approving to supersede the now-stale CHANGES_REQUESTED.
What changed
The CoinGecko tool parsers assumed every response matched the documented shape: an object body, a list of objects, and JSON numbers. When the API answers with a JSON list where an object was documented, a bare string body (edge cache or an error page), a list containing non-object entries, or numeric fields encoded as strings, the parsing raised an unhandled
AttributeError/TypeErrorthat was caught by the handler and surfaced as a single genericUnexpected error ...message with no results at all.Normalizing at the parse boundary keeps the rendering code unchanged:
_as_dict/_as_listvalidate container types before.get()or iteration._coerce_numberconverts numeric fields, including numeric strings, and returnsNonefor anything unusable, so_format_currency/_format_compactkeep printingN/A.coins, trending wrappers,/coins/markets) are filtered to objects, so a stray non-object entry no longer aborts the whole response.itemwrappers that are not objects are treated as empty rather than fatal.The practical improvement is specific, per-item errors and partial results instead of one generic failure for the entire response. Well-formed responses render exactly as before.
Verification
python3 -m pytest plugins/omi-coingecko-crypto-app/test_malformed_payloads.py plugins/omi-coingecko-crypto-app/test_null_optionals.py -q-> 14 passed.Reverting only
main.pyto the parent revision makes 4 of the 9 new cases fail, which is the regression this change closes.test_null_optionals.pystill passes unchanged.scripts/run-plugin-coingecko-tests.shnow runs both suites throughpython -m pytest, withpytest==8.4.1added topinned_depsso the lane works in a clean environment.Failure-Class: none