Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix(ui): restore partial PDF warning after upload errors (#7209)

Chanhyo Jungba13a7efe61a
diff --git a/changelog.d/7205.bugfix.md b/changelog.d/7205.bugfix.md
new file mode 100644
index 0000000000..fc3712952f
--- /dev/null
+++ b/changelog.d/7205.bugfix.md
@@ -0,0 +1 @@
+Restore the persistent partial-PDF warning after temporary upload errors while truncated PDFs remain loaded.
diff --git a/src/local_deep_research/web/static/js/pdf_upload_handler.js b/src/local_deep_research/web/static/js/pdf_upload_handler.js
index 69a274ea2d..9c6f5d8441 100644
--- a/src/local_deep_research/web/static/js/pdf_upload_handler.js
+++ b/src/local_deep_research/web/static/js/pdf_upload_handler.js
@@ -391,6 +391,7 @@ class PDFUploadHandler {
* Show processing indicator
*/
showProcessing(fileCount) {
+ this.clearStatusTimers();
const statusDiv = this.getOrCreateStatusDiv();
// Clear existing content safely
@@ -518,9 +519,12 @@ class PDFUploadHandler {
statusDiv.appendChild(container);
statusDiv.style.display = 'block';
- // Auto-hide after 5 seconds (store timer ID to prevent leaks)
const timerId = setTimeout(() => {
- statusDiv.style.display = 'none';
+ if (this.uploadedPDFs.some(pdf => pdf.truncated)) {
+ this.showSuccess(this.uploadedPDFs.length, []);
+ } else {
+ statusDiv.style.display = 'none';
+ }
}, 5000);
this.statusTimers.push(timerId);
}
diff --git a/tests/js/pdf-upload-handler-migration-contract.test.js b/tests/js/pdf-upload-handler-migration-contract.test.js
index 2068b2a800..f536ab2462 100644
--- a/tests/js/pdf-upload-handler-migration-contract.test.js
+++ b/tests/js/pdf-upload-handler-migration-contract.test.js
@@ -431,3 +431,172 @@ it('retains partial-file warnings and lower-bound totals after another complete
await vi.advanceTimersByTimeAsync(10_000);
expect(status.style.display).toBe('block');
});
+
+describe('partial PDF warning after transient feedback', () => {
+ const partialNotice = '[Partial PDF extraction: only part of this document\'s text is included.]';
+ const apiFilename = '<img src=x onerror="window.__pdfUploadXss=true">.pdf';
+
+ function uploadResponse(filename = apiFilename, truncated = true) {
+ const text = truncated ? `${partialNotice}\nPartial paper` : 'Complete paper';
+ return jsonResponse({
+ status: 'success',
+ processed_files: 1,
+ extracted_texts: [{ filename, text, pages: truncated ? 501 : 3, truncated }],
+ combined_text: text,
+ errors: [],
+ });
+ }
+
+ function pdf(filename = 'selected.pdf') {
+ return new File(['%PDF'], filename, { type: 'application/pdf' });
+ }
+
+ function invalidSelection(handler) {
+ return handler.handleFiles([
+ new File(['plain'], 'notes.txt', { type: 'text/plain' }),
+ ]);
+ }
+
+ async function loadPartialUpload() {
+ const fetchMock = vi.fn((url, options = {}) => {
+ if (url === '/api/config/limits') {
+ return Promise.resolve(jsonResponse({ max_file_size: 100, max_files: 2 }));
+ }
+ if (url === '/api/upload/pdf' && options.method === 'POST') {
+ return Promise.resolve(uploadResponse());
+ }
+ throw new Error(`Unexpected request: ${url}`);
+ });
+ const handler = await loadHandler(fetchMock);
+ vi.useFakeTimers();
+ await handler.handleFiles([pdf()]);
+ return { handler, fetchMock, status: document.getElementById('pdf-upload-status') };
+ }
+
+ it.each(['invalid selection', 'API error', 'network error'])(
+ 'restores the retained partial warning five seconds after %s',
+ async (feedback) => {
+ const { handler, fetchMock, status } = await loadPartialUpload();
+ const query = document.getElementById('query');
+ const originalQuery = query.value;
+ const originalPlaceholder = query.placeholder;
+ const uploaded = handler.getUploadedPDFs();
+ expect(uploaded[0].truncated).toBe(true);
+ expect(originalQuery).toContain(partialNotice);
+ let message;
+ if (feedback === 'invalid selection') {
+ await invalidSelection(handler);
+ message = 'Please select PDF files only';
+ } else {
+ if (feedback === 'API error') {
+ fetchMock.mockResolvedValueOnce(jsonResponse({ status: 'error', message: 'Extraction failed' }));
+ message = 'Extraction failed';
+ } else {
+ fetchMock.mockRejectedValueOnce(new Error('Connection lost'));
+ message = 'Failed to upload PDFs. Please try again.';
+ }
+ await handler.handleFiles([pdf('failed.pdf')]);
+ }
+
+ expect(status.textContent).toContain(message);
+ await vi.advanceTimersByTimeAsync(4999);
+ expect(status.style.display).toBe('block');
+ expect(status.textContent).toContain(message);
+ await vi.advanceTimersByTimeAsync(1);
+ expect(handler.getUploadedPDFs()).toEqual(uploaded);
+ expect(query.value).toBe(originalQuery);
+ expect(query.placeholder).toBe(originalPlaceholder);
+ expect(status.style.display).toBe('block');
+ expect(status.textContent).toContain(`Only part of these PDFs was extracted: ${apiFilename}.`);
+ expect(status.textContent).toContain('Some content is missing');
+ expect(status.textContent).not.toContain(message);
+ expect(status.querySelector('.fa-exclamation-triangle')).not.toBeNull();
+ expect(status.querySelector('img')).toBeNull();
+ expect(window.__pdfUploadXss).toBeUndefined();
+ await vi.advanceTimersByTimeAsync(10_000);
+ expect(status.style.display).toBe('block');
+ },
+ );
+
+ it('does not restore a warning after clearing during an error timeout', async () => {
+ const { handler, status } = await loadPartialUpload();
+ await invalidSelection(handler);
+ await vi.advanceTimersByTimeAsync(1000);
+ handler.clearUploadedPDFs();
+
+ await vi.advanceTimersByTimeAsync(10_000);
+ expect(handler.getUploadedPDFs()).toEqual([]);
+ expect(status.style.display).toBe('none');
+ expect(document.getElementById('query').placeholder).toContain('drop a PDF paper here');
+ });
+
+ it('keeps complete reupload feedback for its own timeout after clearing a partial PDF', async () => {
+ const { handler, fetchMock, status } = await loadPartialUpload();
+ await invalidSelection(handler);
+ await vi.advanceTimersByTimeAsync(4000);
+ handler.clearUploadedPDFs();
+ fetchMock.mockResolvedValueOnce(uploadResponse('complete.pdf', false));
+ await handler.handleFiles([pdf('complete.pdf')]);
+
+ await vi.advanceTimersByTimeAsync(1000);
+ expect(status.style.display).toBe('block');
+ expect(status.textContent).toContain('Successfully processed 1 PDF');
+ expect(status.textContent).not.toContain('Only part');
+ expect(handler.getUploadedPDFs().map(file => file.truncated)).toEqual([false]);
+ await vi.advanceTimersByTimeAsync(4000);
+ expect(status.style.display).toBe('none');
+ });
+
+ it('restores current partial filenames and totals from mixed uploads', async () => {
+ const { handler, fetchMock, status } = await loadPartialUpload();
+ fetchMock.mockResolvedValueOnce(uploadResponse('second-partial.pdf'));
+ await handler.handleFiles([pdf('second-partial.pdf')]);
+ fetchMock.mockResolvedValueOnce(uploadResponse('complete.pdf', false));
+ await handler.handleFiles([pdf('complete.pdf')]);
+ await invalidSelection(handler);
+
+ await vi.advanceTimersByTimeAsync(5000);
+ expect(handler.getUploadedPDFs().map(file => file.truncated)).toEqual([true, true, false]);
+ expect(status.style.display).toBe('block');
+ expect(status.textContent).toContain('Processed 3 PDFs');
+ expect(status.querySelector('p').textContent).toBe(
+ `Only part of these PDFs was extracted: ${apiFilename}; second-partial.pdf. Some content is missing.`,
+ );
+ expect(document.getElementById('query').placeholder)
+ .toContain('3 PDFs loaded, at least 1005 pages, partial text');
+ });
+
+ it('gives a replacement error its full timeout before restoring the partial warning', async () => {
+ const { handler, status } = await loadPartialUpload();
+ await invalidSelection(handler);
+ await vi.advanceTimersByTimeAsync(4000);
+ await handler.handleFiles([pdf('one.pdf'), pdf('two.pdf'), pdf('three.pdf')]);
+
+ await vi.advanceTimersByTimeAsync(4999);
+ expect(status.style.display).toBe('block');
+ expect(status.textContent).toContain('Maximum 2 PDF files allowed at once');
+ await vi.advanceTimersByTimeAsync(1);
+ expect(status.style.display).toBe('block');
+ expect(status.textContent).toContain(`Only part of these PDFs was extracted: ${apiFilename}.`);
+ });
+
+ it.each([500, 1500])('preserves a newer upload and its success when the response takes %i ms', async (delay) => {
+ const { handler, fetchMock, status } = await loadPartialUpload();
+ await invalidSelection(handler);
+ await vi.advanceTimersByTimeAsync(4000);
+ const response = deferred();
+ fetchMock.mockReturnValueOnce(response.promise);
+ const upload = handler.handleFiles([pdf('latest.pdf')]);
+
+ await vi.advanceTimersByTimeAsync(delay);
+ expect(status.style.display).toBe('block');
+ expect(status.textContent).toContain('Processing 1 PDF...');
+ expect(status.querySelector('.fa-spinner')).not.toBeNull();
+ response.resolve(uploadResponse('latest.pdf'));
+ await upload;
+ await vi.advanceTimersByTimeAsync(10_000);
+ expect(status.style.display).toBe('block');
+ expect(status.textContent).toContain(`${apiFilename}; latest.pdf`);
+ expect(status.querySelector('.fa-spinner')).toBeNull();
+ });
+});