Skip to content

fix(ui): show why indexing failed instead of a generic server error - #5643

Merged
kovtcharov-amd merged 3 commits into
amd:mainfrom
kovtcharov:fix/2741-show-server-error-detail
Oct 23, 2026
Merged

kovtcharov-amd merged 3 commits into
amd:mainfrom
kovtcharov:fix/2741-show-server-error-detail

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

When a document failed to index, the Agent UI showed only "Server error. Please try again.", even when the backend said exactly why (in #2741, a missing spreadsheet library). Users had nothing to act on. A 500 now shows the backend's reason. The generic text stays only when the body carries no real cause: an empty body, a bare "Internal server error", an HTML page, or raw JSON.

Refs #2741. The root cause there (openpyxl missing) was already fixed by #2932.

Test plan

  • npx vitest run src/services/__tests__/api.test.ts src/services/__tests__/api.sendError.test.ts: 21 pass, including 500-with-detail through fetch and upload, and the fallback cases
  • npx tsc --noEmit is clean
  • In the Agent UI, upload a corrupt .xlsx: the error names the indexing failure instead of "Server error"

When a document failed to index, the Agent UI showed only "Server error.
Please try again." even though the backend had said why (e.g. a missing
dependency), so users had nothing to act on. A 500 now shows the backend's
detail, falling back to the generic text only when the body carries no real
cause (empty, Starlette's bare "Internal Server Error", HTML, or raw JSON).

The RAG SDK also sent legacy .xls files to openpyxl, which cannot read them;
it now raises a clear "save it as .xlsx" error instead.

Refs amd#2741
That branch already refuses .xls with the shared convert-to-.xlsx message;
keeping a second copy here would conflict with it.

Refs amd#2741
The UI server's catch-all answers {"detail": "Internal server error"}, which the case-sensitive check showed verbatim instead of the friendly fallback. Compare case-insensitively in both the fetch and streaming paths.

Refs amd#2741
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Request changes — the code is right; what's missing is proof it works in the app.

When indexing fails with a server error, the Agent UI now shows the backend's actual reason instead of "Server error. Please try again.", and keeps the generic text only when the server gave no real cause. The logic is small, well-tested, and doesn't regress any existing case.

  • Show it working in the Agent UI. Your test plan's own manual item (upload a corrupt .xlsx, see the real reason) is still unchecked, and the PR has no screenshot. Add a before→after screenshot of the upload error, or at least the real failing upload request and its response.
  • Optional: some genuine server errors start with a bracket (e.g. [Errno 13] Permission denied…), and these still collapse to the generic message. That's how they behaved before this PR, so it isn't a regression, but it's a cheap fix.

Real-world evidence

N/A: no evidence bundle was produced for this run, so nothing ran on the live surface. This verdict comes from static review plus the PR's reported unit-test results. The Agent UI screenshot is still owed (see above).

🔍 Technical details

🟡 Missing real-world evidence for a UI-visible change
This changes the error text users see on failed uploads and every other 500 through apiFetch and uploadDocumentBlob. Vitest only covers the mapping logic. Per the rubric, add a Playwright screenshot from gaia chat --ui of a failed .xlsx upload. If that has to wait, add the underlying evidence instead: the POST upload request and its 500 body, with the message the UI now shows.

🟢 The bracket heuristic drops real str(OSError) details (api.ts, hasUsefulServerDetail)
/^[<{[]/ is meant to catch raw JSON passed through by parseErrorDetail, but it also rejects [Errno N] …. Several routes return detail=str(e) on 500, including routers/environment.py, skills.py, changes.py and hub.py. Checking for JSON directly keeps the intent and avoids that:

function hasUsefulServerDetail(detail: string): boolean {
    const text = detail.trim();
    if (text === '' || isBareInternalError(text) || text.startsWith('<')) return false;
    try {
        JSON.parse(text);
        return false;
    } catch {
        return true;
    }
}

If you take this, add one it.each row for {"detail": "[Errno 13] Permission denied: 'x'"} that expects the detail to come through.

Strengths

  • The SSE path and getFriendlyError now share one isBareInternalError check, which also fixes the case mismatch with the UI server's lowercase catch-all ("Internal server error").
  • The fallback table in the tests (empty, Starlette bare, catch-all, HTML, empty detail, no detail) pins exactly the cases that must stay generic.
  • Array and object detail shapes are covered, so [object Object] can't come back.

@kovtcharov

Copy link
Copy Markdown
Contributor Author

Real-world evidence from the live Agent UI. A corrupt .xlsx dropped onto the Document library now shows the backend's reason. On main, the same upload shows the generic text.

  • main (243e435): Failed to index "bad.xlsx" — Server error. Please try again.
  • this PR: Failed to index "bad.xlsx" — Failed to index document: RAG indexing failed for a40ab65b2501_bad.xlsx: File is not a zip file

The backend returns the same 500 and the same detail on both; only what the UI does with it changed. Screenshots are available on request.

🔍 Technical details

gaia.ui.server was served from each tree (gaia.__file__ checked), with the webui built from that tree. Playwright did a real drag-and-drop onto the drop zone. The browser captured this request and response:

POST /api/documents/upload   (multipart, file=bad.xlsx, 4096 random bytes)
HTTP/1.1 500 Internal Server Error
{"detail":"Failed to index document: RAG indexing failed for a40ab65b2501_bad.xlsx: File is not a zip file"}

The message shows the server's stored filename (a40ab65b2501_bad.xlsx) rather than bad.xlsx. That string comes from the backend, predates this PR, and is left for a follow-up.

The bracket-prefixed case ([Errno 13] …) still falls back to the generic text, as it did before. That's deliberate, so raw JSON or HTML bodies never show up as the message.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 23, 2026
Merged via the queue into amd:main with commit a7b60b1 Oct 23, 2026
29 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the fix/2741-show-server-error-detail branch October 23, 2026 11:53
tylerbea pushed a commit to tylerbea/gaia that referenced this pull request Oct 26, 2026
…heets right (amd#5812)

Uploading a damaged `.xlsx`, a legacy `.xls` or password-protected
workbook, or one with no data used to fail with a 500 carrying
openpyxl's raw text ("File is not a zip file"). An empty workbook
"indexed" as nothing but sheet names. Each now shows a clear "can't be
read" message saying what to do, the same way damaged PDFs do.
Spreadsheets with a merged title row above the table, like a lab report,
lost their column names (LDL, HDL), so questions about a column found
nothing. Those now index with the right labels.

The crash in amd#2741 itself no longer reproduces on main: `openpyxl` was
added to the `ui` extra in amd#2932, and amd#5643 made the UI show the
backend's reason. On a cold `GAIA_HOME`, a simple sheet and a
multi-sheet workbook with formulas and merged cells both upload and
index. This PR fixes what was still wrong with Excel files after that.

Closes amd#2741

## Test plan
- [x] `pytest tests/unit/rag/test_xlsx_extraction.py`: real
LibreOffice-saved fixtures (formulas with cached values, merged title
row, merged note, empty sheet, real `.xls`), plus corrupt, empty,
`.xls`-named and missing-openpyxl cases, through both RAG and `POST
/api/documents/upload`
- [x] `pytest tests/unit/rag
tests/unit/chat/ui/test_library_index_errors.py
tests/unit/chat/ui/test_server.py`: 535 passed
- [x] `npx vitest run
src/components/__tests__/UnsupportedFeature.test.tsx
src/components/__tests__/DocumentLibrary.test.tsx` and `npx tsc
--noEmit`
- [x] `python util/lint.py --all` passes
- [x] Real server on an empty `GAIA_HOME` with live Lemonade embeddings:
valid workbooks return 200; a corrupt, a blank and a renamed `.xls`
workbook each return 422 with `corrupted` / `empty_file` /
`unsupported_workbook` and a remedy, on both `/upload` and
`/upload-path`

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants