fix(api): return the REQ-010 error envelope on every error path (DEBT-033)#112
Conversation
…-033)
Endpoints that raised HTTPException with a plain string detail returned
FastAPI's bare {"detail": "..."} - no code, no remediation, no request
id, so a client could not branch on an error code. The DOCS-009 caveat
named four such endpoints; a grep of the handlers found four more
(POST /query, the admin auth dependency, api-key creation, and admin
/health?detail=full), so removing the caveat as written would have
re-asserted a universality those still broke.
All of them now raise ErrorResponse.to_envelope() at the same HTTP status
they returned before (shape-only; no test asserted the bare shape).
Reused ERR-CONFIG-001/002 for internal registry/key-store faults; added
ERR-CONV-001/002/003, ERR-QUERY-005, ERR-ADMIN-008 and ERR-INDEX-003/004,
each registered in errors.py, _CODE_STATUS_OVERRIDE and error-codes.md.
Removed the "not every endpoint uses the envelope" caveat from api.md.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 30 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (11)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request addresses DEBT-033 by ensuring that all API error paths return the standard REQ-010 error envelope instead of bare FastAPI details, introducing several new error codes across components. The review feedback is highly constructive and identifies opportunities to improve code quality and consistency: specifically, registering the new error codes as constants in errors.py, mapping them in _CODE_STATUS_OVERRIDE, and using dedicated helper functions to construct the error envelopes rather than doing so inline at the raise sites. Additionally, the feedback suggests updating imports and test suites to verify these new helper functions and error codes.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Address the review: promote ERR-ADMIN-008 to a constant and add service_initializing(), query_pipeline_unavailable() and key_store_unavailable() factories in vektra_shared.errors, then raise through them instead of constructing the envelope inline (matching the auth_* / conversation_* factory pattern already in that module). This also removes the duplicated ERR-ADMIN-008 block in the health handler. No status changes; the TRANSIENT codes still resolve to 503 via the category default, so no _CODE_STATUS_OVERRIDE entries are needed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Summary
DEBT-033: the REQ-010 error envelope (
{"error": {category, code, message, remediation, request_id}}) was documented as universal but wasn't. Endpoints that raisedHTTPException(status_code=..., detail="some string")returned FastAPI's bare{"detail": "..."}— no code to branch on, no remediation, no request id. This makes the envelope actually universal.What changed
The DOCS-009 caveat named four bare-shape endpoints (reindex ×2, core conversations, admin conversation turns). Grepping the handlers found the caveat had undercounted — the same bare shape lived on four more paths, so removing the caveat as written would have re-asserted a universality those still broke:
POST /api/v1/query— registry-not-initialized (500), query-pipeline-not-configured (503)GET /api/v1/admin/health?detail=full— service-initializing (503, ×2)All of them (the four scoped + the four found) now raise
ErrorResponse.to_envelope()at the same HTTP status they returned before — the change is shape-only. No test asserted the bare shape, so none needed rewriting; existing status-code assertions still hold.Error codes
ERR-CONFIG-001(reused)ERR-CONFIG-002(reused)ERR-CONV-001(new)ERR-CONV-002(new)ERR-CONV-003(new)ERR-QUERY-005(new)ERR-ADMIN-008(new)ERR-INDEX-003(new)ERR-INDEX-004(new)Reused codes match the global unhandled-exception handler's treatment of internal faults. New codes are registered in
vektra_shared/errors.py,_CODE_STATUS_OVERRIDE, anddocs/reference/error-codes.md. The "not every endpoint uses the envelope" caveat is removed fromdocs/reference/api.md.Follow-up spawned (DEBT-034)
The wire shape is
{"detail": {"error": {...}}}for everyHTTPException-based error — FastAPI wraps the detail, so the envelope sits one level down for every enveloped endpoint (auth included), while the top-level{"error": {...}}only comes from the global 500 handler. The whole test suite already asserts["detail"]["error"]["code"], so this is the de-facto contract. api.md shows the logical top-level form; reconciling that representation predates this work and affects every endpoint, so it's filed as DEBT-034 rather than expanded into here.Verification
make lint: ruff +ruff format --check+ mypy (76 files) + import-linter (8 contracts) — cleanmake test: 781 passed, 3 skipped, 52 deselected (integration)test_errors.py(codes, overrides, factories),test_reindex.py(envelope on 400/404), and envelope-code assertions added to the existing conversation and admin-turns tests{"detail":{"error":{code}}}shape end-to-endNo CI workflows were touched; the
CI gateandIntegration tests + NFR gateschecks are unchanged.🤖 Generated with Claude Code