Skip to content

fix(uber-call): reject non-scalar geolocation coordinates with 400, not 500 - #17108

Merged
kodjima33 merged 1 commit into
BasedHardware:mainfrom
optimus-fulcria:fix/uber-call-geolocation-type-500
Sep 23, 2026
Merged

kodjima33 merged 1 commit into
BasedHardware:mainfrom
optimus-fulcria:fix/uber-call-geolocation-type-500

Conversation

@optimus-fulcria

@optimus-fulcria optimus-fulcria commented Sep 23, 2026 •

Copy link
Copy Markdown

What changed and why

POST /api/call_uber returned HTTP 500 when a geolocation coordinate arrived as a list or an object; it now returns the 400 the app already documents for a bad geolocation.

The backend forwards geolocation as free-form JSON and the field is typed dict[str, Any], so pydantic does not coerce the values inside it — unlike the top-level pickup_latitude / dropoff_latitude floats, which pydantic rejects with a 422. A non-scalar value therefore reached float() in uber_links._normalize_float, which raises TypeError, while call_uber only catches ValueError — so it escaped as an unhandled 500. test_main.test_bad_geolocation_returns_400 pins this contract for the string case only, which is why the gap survived.

The fix converts that TypeError into a ValueError naming the offending type, at the single helper every coordinate is normalised through. No behaviour change for numbers, numeric strings, None, or "".

Product invariants affected

none

How it was verified

Reproduced against the real endpoint on main before the fix, via TestClient(app, raise_server_exceptions=False):

POST /api/call_uber {"destination":"SFO Airport","geolocation":{"latitude":<v>,"longitude":-122.418028}}
  v = [37.7749, 1]   -> 500      <- unhandled TypeError
  v = {"lat":37.7749} -> 500      <- unhandled TypeError
  v = "nearby"        -> 400      <- the case the existing test covers

After the fix the same three requests return 400/400/400, and a valid {"latitude":37.7749,"longitude":-122.4194} still returns 200 with an m.uber.com link.

  • make preflight — passed, 15 checks, with uber-call-geolocation-type-tests selected.
  • scripts/pr-preflight --pr-body-file with this body — passed, 15 checks.
  • No regressions in the app's existing suites: test_coord_bounds.py 3/3, test_uber_links.py 4/4, test_main.py 2/2.

Tests

New plugins/uber_call/test_geolocation_types.py — the regression test that would have caught this bug:

  • 5 stdlib-only tests pin the ValueError contract for list/dict/tuple latitude and longitude, and that numeric strings, numbers, "" and None behave exactly as before.
  • 2 skipIf(TestClient is None) tests drive the real endpoint for the 400 and the 200 path, matching the existing test_main.py harness style.

CI has no plugin dependencies installed, so I checked the suite with fastapi, httpx, pydantic and starlette made unimportable through a MetaPathFinder: 5 run / 2 skipped / 0 failures. The defect contract stays pinned in CI rather than silently skipping in full.

Failure class (fixes)

Failure-Class: FC-chat-tool-input-assumed-typed-and-complete

Loosely-typed, human-shaped chat-tool input crashing a handler with TypeError instead of returning a clean tool error is squarely this class's violated contract. The fix follows its canonical prevention: validate in one shared normalisation helper, pinned by a manifest-registered hermetic suite that drives the real handler through dirty inputs.

New guards (only when adding a check or ratchet)

uber-call-geolocation-type-tests is the manifest entry for the suite above. The incident it would have caught is this one: plugins/uber_call has no checks-manifest entry today, so none of its three existing suites run in CI, and the 500 was reachable from an ordinary chat-tool call.

It is not a shared primitive because the coercion is per-app: each plugin reads geolocation with its own helper and its own accepted key spellings (latitude/lat, longitude/lng/lon here), so the guard has to drive this app's normaliser. The registered class-level prevention for the shared half already exists as FC-chat-tool-input-assumed-typed-and-complete's canonical artifact.

Scoped cleanups (optional)

None included. One adjacent gap I deliberately left out, happy to take it if you would rather: plugins/uber_call's three pre-existing suites (test_coord_bounds, test_uber_links, test_main) also have no checks-manifest entries, so they still will not run in CI after this PR. I registered only the new suite to keep this scoped — say the word and I will add the other three.

🤖 Generated with Claude Code

Review in cubic

…ot 500

The Omi backend forwards `geolocation` to this app as free-form JSON, and
the field is typed `dict[str, Any]`, so pydantic does not coerce the values
inside it. A coordinate that arrives as a list or an object therefore reached
`float()` in `_normalize_float`, which raises TypeError. `call_uber` only
handles ValueError, so the request failed with an unhandled 500 instead of
the 400 the app already documents for a bad geolocation
(`test_main.test_bad_geolocation_returns_400` covers only the string case).

`_normalize_float` now converts that TypeError into a ValueError naming the
offending type, which is the contract `call_uber` already maps to a 400.

Adds `test_geolocation_types.py`: five stdlib-only tests pin the ValueError
contract and the accepted inputs, and two skip-if-absent TestClient tests
assert the endpoint returns 400 for list/dict/tuple coordinates and still
builds links for a valid geolocation. Registered in the checks manifest so
CI runs it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@aryanorastar

Copy link
Copy Markdown
Collaborator

Keeping this open on 11077c0.

Uber link parsing on main still returns float(value) with no guard. This head turns TypeError into ValueError, and the tests import build_location. The only check is cubic, so this is not an approval.

Not approving this SHA.

— Astar, on behalf of @aryanorastar

@Git-on-my-level

Copy link
Copy Markdown
Member

Verified the bug and the fix against this head.

plugins/uber_call/uber_links.py — the try/except TypeError -> ValueError in _normalize_float is the right shape and the right place: it is the single choke point both pickup and dropoff coordinates pass through, so build_location now always raises the ValueError that call_uber maps to 400. The message names the offending type and chains the original exception (raise ... from exc). Diffed against main — this is the only semantic change in the module.

The root cause checks out: main.py types geolocation as dict[str, Any], _geo_value only filters None/"", and call_uber catches ValueError only (plugins/uber_call/main.py:142), so a list/object coordinate previously escaped as TypeError -> 500. The existing test_bad_geolocation_returns_400 covered only the string case, which is exactly the gap claimed.

plugins/uber_call/test_geolocation_types.py — good coverage: unit tests assert ValueError with the type name for list/dict/tuple on both latitude and longitude, pin no-behavior-change for numeric strings/empty/None, and the endpoint tests use TestClient(app, raise_server_exceptions=False), which is the correct way to assert "400, never an unhandled 500". The skipIf guard keeps it runnable where fastapi/httpx are absent. Ran the suite locally on this head: 7/7 pass, including both endpoint tests.

.github/checks-manifest.yaml — the uber-call-geolocation-type-tests entry is well-formed and matches the manifest's existing shape (command, triggers on plugins/uber_call/** and the manifest itself, both lanes).

One non-blocking follow-up, same class of bug on the sibling path: a non-scalar geolocation.formatted_address (e.g. ["123 Main St"]) reaches _clean_text, where value.split() raises AttributeError and still returns a 500 on this head — verified via TestClient. No need to widen this PR; worth a follow-up issue or small change covering the address fields the same way.

Nice first contribution — clean scope, precise PR description, and the tests pin the contract properly. Leaving for human maintainer merge.

🤖 Automated review on behalf of the 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 positive-signal Automation verified a genuine fix/quality contribution python labels Sep 23, 2026

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

Verified real bug reproduced against current main (root cause confirmed by direct source inspection), scoped diff, regression tests added and shown to fail on unpatched code. Confidence 5/5 — merging.

@kodjima33
kodjima33 merged commit 6c49372 into BasedHardware:main Sep 23, 2026
1 check passed
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants