Skip to content

fix(ui): give a file that fails in a folder add a library row - #8140

Merged
kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:kalin/folder-add-failed-rows
Nov 13, 2026
Merged

kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:kalin/folder-add-failed-rows

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

Before: when you added a folder, any file that failed to index disappeared. It had no library row, no "failed" badge and no retry, and the chat then said its answer wasn't in the documents. A file that indexed to nothing was marked complete and attached anyway. The notice also called the folder's photos "a type GAIA doesn't index". After: each failed file shows in the library as failed, with its reason and the usual retry, and stays out of the chat. The notice says how many images were left out and that adding each one on its own lets GAIA read it.

The embedder reload that made a valid file fail in the first place is #8048, fixed by #8049. This PR covers what the user sees when any file in a folder fails.

Closes #8138
Closes #8139

Test plan

  • pytest tests/unit/chat/ui/test_library_index_errors.py tests/unit/chat/ui/test_folder_index_one_embedder_load.py: 32 passed; the 4 new tests fail on main
  • npx vitest run src/components/__tests__/DocumentLibrary.test.tsx (34 passed, new English and Arabic notice tests) and npx vitest run src/i18n (41 passed)
  • npx tsc --noEmit -p . clean; API types regenerated from the backend models
  • npm run test:rtl screenshots of the folder notice (not run here; the notice has no visual scene yet)
  • Replayed in the app
🔍 Technical details
  • index_folder treats a 0-chunk result as a failure, as upload_by_path does. A failed file whose bytes could be hashed gets an add_document row set to failed with last_error and error_kind. A complete row for the same bytes elsewhere is left alone.
  • An unreadable file that can't be hashed still has no row, because there is no content key to file it under. It stays in errors and the notice.
  • New skipped_images field on IndexFolderResponse; skipped now counts only unsupported types.

Adding a folder dropped any file that failed to index: no row, no
"failed" badge, no retry, and the chat then said its answer wasn't in the
documents. A file that indexed to nothing got a "complete" row and was
attached anyway. Each such file now gets a failed row with its reason,
which the library already offers to retry, and stays out of the chat.

The folder notice also counted the folder's images as files of a type
GAIA doesn't index. Images are now counted apart, and the notice says to
add each one on its own so GAIA reads it.

Closes amd#8138
Closes amd#8139
@github-actions github-actions Bot added documentation Documentation changes tests Test changes labels Nov 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

When a folder is added, a file that fails to index now shows in the library as failed, with its reason and a retry, instead of vanishing. A file that indexes to nothing is no longer marked complete. The folder notice now counts images separately and says how to add them. The logic is sound and well tested, and the docs match the code.

Two things are worth a look before merging:

  • A database error during a folder add can now fail the whole request. Recording the failed row runs inside the error handler. If the database is what failed, the same write fails again, and the whole folder add returns a server error that hides the files that did index. Before this change only that one file was reported as failed. Guard the recording step so this can't happen.
  • Follow-up: Adding a folder from the file browser still says nothing when files fail or images are left out. That path ignores the failure count and the new image count, so the improved notice shows only in the document library. If this PR shouldn't fix it, file an issue.

Real-world evidence

N/A: no evidence bundle was produced for this run. The verdict rests on a static review. The changed route was not called, and I couldn't run the backend tests here because pytest isn't installed on the runner. The PR reports 32 backend and 34 front-end tests passing, but it has neither a screenshot of the new notice nor a replay in the app. Both are still unchecked in its test plan. Add a before→after screenshot of the folder notice in English and Arabic once the RTL scene exists.

🔍 Technical details

🟡 Recording a failed row can raise inside the except and 500 the whole folder (src/gaia/ui/routers/documents.py:856)

_record_failed_document calls db.add_document and db.update_document_status from inside the handler. If the original failure was the db.add_document at line ~841 (for example, sqlite locked or the disk full), the retry in the handler most likely raises too. That exception escapes the loop, so indexed_docs and errors for the rest of the folder are lost and the client gets a 500. Keep the failure per file:

                # Unhashable means unreadable: no content key to file a row under.
                if file_hash is not None:
                    try:
                        _record_failed_document(db, filepath, file_hash, e)
                    except Exception as record_err:  # keep this a per-file failure
                        logger.error(
                            "Could not record failed row for %s: %s",
                            filepath,
                            record_err,
                            exc_info=True,
                        )
                        errors[-1] += f" (no library row: {record_err})"

This logs the error and adds it to the message the user sees, so nothing is swallowed.

🟡 Follow-up: Folder add from FileBrowser ignores failed, errors and skipped_images (src/gaia/apps/webui/src/components/FileBrowser.tsx:137-143)

The folder branch only collects result.documents. A folder where every file fails counts as neither a success nor a failure there, and the new image count never reaches the user. DocumentLibrary's describeFolderResult is the pattern to reuse.

🟢 A failed row can overwrite an in-flight row for the same bytes (documents.py:199)

The early return protects only a row that is complete with chunks. If the same content is pending/indexing from a concurrent upload elsewhere, add_document returns that row and it is set to failed under the other task. This is rare, but if doc.get("indexing_status") in ("pending", "indexing"): return would close it.

Strengths

  • Treating 0 chunks as a failure brings folder add in line with upload_by_path, and the reindex test shows the new row can actually be retried.
  • Splitting skipped_images from skipped gives the user an honest, actionable message in both locales, and the API docs and the chat guide already agree with it.
  • An unhashable file is deliberately left without a row and stays in errors, which avoids inventing a content key.

Recording a failed file's row ran inside the error handler, so a database error there turned the whole folder add into a server error and lost the files that indexed. It is now logged and added to that file's error. A row another upload is still indexing is left alone. Adding a folder from the file browser now counts the files that failed, refreshes the library to show their rows, and says how many images were left out.
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Nov 13, 2026
Merged via the queue into amd:main with commit 1b35064 Nov 13, 2026
90 of 91 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/folder-add-failed-rows branch November 13, 2026 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Documentation changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding a folder leaves out its images without saying so A file that fails in a folder add gets no library row, so it can't be seen or retried

2 participants