Skip to content

fix(email): list the /query routes' error statuses in the OpenAPI contract - #6910

Merged
kovtcharov-amd merged 1 commit into
amd:mainfrom
wasiulhaque:fix/email-query-openapi-responses
Nov 7, 2026
Merged

kovtcharov-amd merged 1 commit into
amd:mainfrom
wasiulhaque:fix/email-query-openapi-responses

Conversation

@wasiulhaque

Copy link
Copy Markdown
Contributor

Summary

openapi.email.json listed only 200 and 422 for the three /query routes, although they also return 400, 404, 409, 500 and 502. This PR declares those statuses on the route decorators, regenerates openapi.email.json and specification.html, and adds a test that fails if a /query route raises a status the spec doesn't list.

Why

openapi.email.json is the contract the npm client and generated clients are built from. A client generated from it had no typed path for a stale needs_input answer (409), a busy session (409), or an agent that failed to start (502), even though npm/SPEC.md already documents them in prose. This is the last item of #4429; the docs part landed in #6879.

Linked issue

Closes #4429

Changes

  • query_routes.py: POST /v1/email/query declares 400, 409, 500 and 502 next to its SSE 200; /query/{run_id}/cancel declares 404; /query/{run_id}/respond declares 404 and 409. Each description says when that status is returned. No handler logic changed.
  • openapi.email.json: regenerated with python -m gaia_agent_email.export_openapi.
  • spec_html.py / specification.html: the /query block is hand-written and listed no errors, so it gets one paragraph naming them (cancel and respond already did); regenerated with python -m gaia_agent_email.spec_html.
  • tests/test_rest_contract.py: test_query_routes_document_every_status_they_raise reads every HTTPException(status_code=...) in each /query handler from the source and asserts the spec lists it, so a new status added without a responses entry fails CI.
  • CHANGELOG.md: an Unreleased "Fixed" entry.
  • No SCHEMA_VERSION bump: no request or response shape changed and no operation was added. I followed fix(email): declare the sidecar bearer gate in the OpenAPI contract #3002, which also only added to what the OpenAPI document declares and did not bump. Happy to bump to 2.16 if you'd rather treat this as a contract change.

Test plan

  • python -m gaia_agent_email.export_openapi --check and python -m gaia_agent_email.spec_html --check both report up to date after regenerating (the OpenAPI check failed before).
  • pytest hub/agents/email/python/tests tests/test_email_openapi_conformance.py: 2378 passed, 3 skipped (Python 3.12, .[dev,api,publish] + the email package, as in test_email_agent_unit.yml).
  • Removed the 409 from /respond's responses on purpose: the new test failed with POST /v1/email/query/{run_id}/respond raises ['409'] undocumented, then passed again once restored.
  • python util/lint.py --all: everything passes except two Pylint E1120 errors in src/gaia/utils/awake_clock.py:47 and src/gaia/utils/terminal.py:109, files this PR doesn't touch.

Evidence

  • Agent exposed in the Agent UI: N/A, no UI change.
  • MCP tools / servers: N/A, no MCP change.
  • CLI: N/A, no CLI change.
  • HTTP API / REST: real requests through the routers the sidecar mounts (export_openapi.build_app() in a TestClient), next to what the regenerated spec now lists:
$ POST /v1/email/query/{run_id}/cancel  -> 404 {'detail': "No in-flight run for run_id '0f5caf10-…'."}
  openapi.email.json lists: ['200', '404', '422']
$ POST /v1/email/query/{run_id}/respond  -> 404 {'detail': "No in-flight run for run_id '0f5caf10-…'. It has already finished or been cancelled, so there is nothing to answer."}
  openapi.email.json lists: ['200', '404', '409', '422']
$ POST /v1/email/query  (provider: "openai") -> 400 {'detail': "provider 'openai' is not supported: the email agent runs local inference only. Omit 'provider' or set it to 'lemonade'."}
  openapi.email.json lists: ['200', '400', '409', '422', '500', '502']

Before this PR, all three listed only ['200', '422'].

Checklist

  • I have linked a GitHub issue above (Closes #N / Fixes #N / Refs #N).
  • I have described why this change is being made, not just what changed.
  • I have run linting and tests locally (python util/lint.py --all, pytest tests/unit/).
  • I have attached real-world evidence matched to the surface I changed (see Evidence above), or marked each surface N/A.
  • I have updated documentation if user-visible behavior changed (see CONTRIBUTING.md).

…tract

openapi.email.json listed only 200/422 for /query, /query/{run_id}/cancel and /query/{run_id}/respond, though they return 400/404/409/500/502. Declare them on the routes, regenerate openapi.email.json and specification.html, and add a test that every status a /query handler raises is documented.

Closes amd#4429
@github-actions github-actions Bot added the agent::email Email agent changes label Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Verdict: Approve

The email agent's published API contract now lists the errors its three /query routes already return: bad provider, busy session, agent failed to start, and a stale or unknown run. Before this, generated clients only knew about success and validation errors. I checked every status and description against the route code, and they match. A new test makes CI fail if a route starts returning a status the contract doesn't list. No request or response shape changes, so not bumping the schema version is reasonable.

Real-world evidence

N/A here: no evidence bundle was produced for this run. The PR description includes real requests through the mounted routers: cancel and respond return 404, and /query with provider: "openai" returns 400, each next to what the regenerated spec now lists. That is the right evidence for an HTTP contract change. I couldn't run the tests or the --check regenerators in this job because the environment lacks pytest and pydantic, so my verdict on the regenerated files rests on reading the diff.

🔍 Technical details

Issues found

🟢 The guard test only sees statuses raised directly in the handler (tests/test_rest_contract.py, _statuses_raised_by_query_routes). It reads HTTPException(status_code=<literal>) calls in each handler's own body. All eight raises sit there today (query_routes.py:588–768, 875, 907–916), so it's complete for now. A future status raised from a helper, or passed as a variable or status.HTTP_… constant, would get past it. Consider adding a one-line note to the docstring so nobody assumes it covers more.

Checked

  • Every status in _QUERY_SSE_RESPONSES, _RUN_NOT_IN_FLIGHT and _RESPOND_RESPONSES matches a real raise, and each description matches what triggers it:
    • 400: provider allowlist.
    • 409: run_lock busy, or a registry.add collision.
    • 502: get_or_create, a model-switch rebuild, or build_query_agent failing.
    • 500: a start-up failure that isn't already an HTTPException.
    • 404 and 409 on respond: unknown run, or resolve_user_input refused.
  • Documentation drift: grepped the email package's *.md for the old "200 and 422 only" claim and found it only in the new CHANGELOG entry. The /query block in spec_html.py is hand-written, and its new paragraph matches specification.html word for word. It correctly says that once the stream is open, failures arrive as error events.
  • Sibling paths: the cancel and respond routes now declare their errors too, and the test checks that the route set is exactly these three, so an added /query* route fails until it's covered.

Strengths

  • The test was proven to work: the author deleted a documented status and watched the test fail before restoring it.
  • Descriptions say when each status fires, not just its name. That's what a client author needs.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Nov 7, 2026
Merged via the queue into amd:main with commit 6d556dc Nov 7, 2026
31 checks passed
@kovtcharov-amd kovtcharov-amd mentioned this pull request Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent::email Email agent changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docs(email): npm SPEC/SKILL say the undo window is 30s; the agent uses 120s

2 participants