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.

chore(ui): share the truncated-upload predicate and pin the pdf upload restore wording (#7358)

LearningCircuit375c7adca88b
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 9c6f5d8441..62440490c7 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
@@ -376,7 +376,7 @@ class PDFUploadHandler {
if (this.uploadedPDFs.length > 0) {
const pdfCount = this.uploadedPDFs.length;
const totalPages = this.uploadedPDFs.reduce((sum, pdf) => sum + pdf.pages, 0);
- const partial = this.uploadedPDFs.some(pdf => pdf.truncated);
+ const partial = this.hasPersistentTruncated();
const pageSummary = partial
? `at least ${totalPages} pages, partial text`
: `${totalPages} pages total`;
@@ -435,6 +435,23 @@ class PDFUploadHandler {
this.statusTimers = [];
}
+ /**
+ * Whether any uploaded PDF was only partially extracted.
+ *
+ * The only place that asks this of the session's uploads (#7333).
+ * Three callers consult it: showSuccess (the partial styling, wording
+ * and warning, plus the early return that keeps a partial warning
+ * visible until the upload state changes), the restore decision in
+ * showError's timer, and updatePlaceholder's "partial text" page
+ * summary. A new status kind should call it rather than re-derive the
+ * answer. The `filter` in showSuccess that lists WHICH PDFs the
+ * warning names is a different computation (a list, not a yes/no)
+ * and stays inline; it only runs once this returns true.
+ */
+ hasPersistentTruncated() {
+ return this.uploadedPDFs.some(pdf => pdf.truncated);
+ }
+
/**
* Show success message
*/
@@ -443,8 +460,7 @@ class PDFUploadHandler {
this.clearStatusTimers();
const statusDiv = this.getOrCreateStatusDiv();
- const partialPDFs = this.uploadedPDFs.filter(pdf => pdf.truncated);
- const partial = partialPDFs.length > 0;
+ const partial = this.hasPersistentTruncated();
// Clear existing content safely
statusDiv.textContent = '';
@@ -464,6 +480,7 @@ class PDFUploadHandler {
container.appendChild(text);
if (partial) {
+ const partialPDFs = this.uploadedPDFs.filter(pdf => pdf.truncated);
const warning = document.createElement('p');
warning.textContent = `Only part of these PDFs was extracted: ${partialPDFs.map(pdf => pdf.filename).join('; ')}. Some content is missing.`;
container.appendChild(warning);
@@ -520,7 +537,15 @@ class PDFUploadHandler {
statusDiv.style.display = 'block';
const timerId = setTimeout(() => {
- if (this.uploadedPDFs.some(pdf => pdf.truncated)) {
+ if (this.hasPersistentTruncated()) {
+ // Restore the resting-state summary of the SESSION's
+ // uploads, i.e. the PDF count and the partial-file warning
+ // read from this.uploadedPDFs. showError never renders a
+ // "Some files had issues" sub-line: only showSuccess does,
+ // for the errors of the batch it was called with. A partial
+ // status has no hide timer, so such a sub-line stays up
+ // until this error replaces it, and it is not restored
+ // because a batch's errors are not stored.
this.showSuccess(this.uploadedPDFs.length, []);
} else {
statusDiv.style.display = 'none';
diff --git a/tests/js/pdf-upload-handler-migration-contract.test.js b/tests/js/pdf-upload-handler-migration-contract.test.js
index f536ab2462..90f44d0a32 100644
--- a/tests/js/pdf-upload-handler-migration-contract.test.js
+++ b/tests/js/pdf-upload-handler-migration-contract.test.js
@@ -473,7 +473,7 @@ describe('partial PDF warning after transient feedback', () => {
return { handler, fetchMock, status: document.getElementById('pdf-upload-status') };
}
- it.each(['invalid selection', 'API error', 'network error'])(
+ it.each(['invalid selection', 'API error', 'network error', 'file too large'])(
'restores the retained partial warning five seconds after %s',
async (feedback) => {
const { handler, fetchMock, status } = await loadPartialUpload();
@@ -487,6 +487,10 @@ describe('partial PDF warning after transient feedback', () => {
if (feedback === 'invalid selection') {
await invalidSelection(handler);
message = 'Please select PDF files only';
+ } else if (feedback === 'file too large') {
+ const big = new File([new Uint8Array(101)], 'big.pdf', { type: 'application/pdf' });
+ await handler.handleFiles([big]);
+ message = 'PDF files must be smaller than 100 bytes';
} else {
if (feedback === 'API error') {
fetchMock.mockResolvedValueOnce(jsonResponse({ status: 'error', message: 'Extraction failed' }));
@@ -530,6 +534,52 @@ describe('partial PDF warning after transient feedback', () => {
expect(document.getElementById('query').placeholder).toContain('drop a PDF paper here');
});
+ it('restores the session summary without re-showing the batch errors sub-line', async () => {
+ // A partial upload whose batch ALSO carried file errors: its
+ // showSuccess renders the "Some files had issues" sub-line, and a
+ // partial status has no hide timer, so the sub-line stays up. An
+ // unrelated transient error then replaces it. showError never
+ // renders that sub-line and a batch's errors are not stored (they
+ // are only passed to showSuccess), so the restore rebuilds the
+ // session summary from the retained uploads alone, without the
+ // sub-line. The restored partial warning has no hide timer either,
+ // so no status timer is left behind.
+ 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(jsonResponse({
+ status: 'success',
+ processed_files: 1,
+ extracted_texts: [{
+ filename: 'partial.pdf',
+ text: `${partialNotice}\nPartial paper`,
+ pages: 501,
+ truncated: true,
+ }],
+ combined_text: `${partialNotice}\nPartial paper`,
+ errors: ['other.pdf was corrupt'],
+ }));
+ }
+ throw new Error(`Unexpected request: ${url}`);
+ });
+ const handler = await loadHandler(fetchMock);
+ vi.useFakeTimers();
+ await handler.handleFiles([pdf('partial.pdf')]);
+ const status = document.getElementById('pdf-upload-status');
+ // The direct path shows the batch's errors sub-line.
+ expect(status.textContent).toContain('Some files had issues: other.pdf was corrupt');
+
+ await invalidSelection(handler);
+ await vi.advanceTimersByTimeAsync(5000);
+
+ expect(status.textContent).toContain('Processed 1 PDF');
+ expect(status.textContent).toContain('Only part of these PDFs was extracted: partial.pdf.');
+ expect(status.textContent).not.toContain('Some files had issues');
+ expect(handler.statusTimers).toHaveLength(0);
+ });
+
it('keeps complete reupload feedback for its own timeout after clearing a partial PDF', async () => {
const { handler, fetchMock, status } = await loadPartialUpload();
await invalidSelection(handler);
@@ -600,3 +650,73 @@ describe('partial PDF warning after transient feedback', () => {
expect(status.querySelector('.fa-spinner')).toBeNull();
});
});
+
+describe('shared truncated-upload predicate', () => {
+ // hasPersistentTruncated() is the one place that asks whether any
+ // upload was only partially extracted. Each consumer must ask it
+ // instead of re-reading uploadedPDFs, so the consumer tests below make
+ // the predicate DISAGREE with the stored uploads: a consumer that
+ // re-derives the answer inline keeps following the uploads and fails.
+ async function loadWithUploads(truncatedFlags) {
+ const handler = await loadHandler(vi.fn((url) => {
+ if (url === '/api/config/limits') {
+ return Promise.resolve(jsonResponse({ max_file_size: 100, max_files: 2 }));
+ }
+ throw new Error(`Unexpected request: ${url}`);
+ }));
+ handler.addPDFsToUploaded([], truncatedFlags.map((truncated, index) => ({
+ filename: `upload-${index}.pdf`,
+ text: 'text',
+ pages: 3,
+ truncated,
+ })));
+ return handler;
+ }
+
+ it.each([
+ ['no uploads', [], false],
+ ['only complete uploads', [false, false], false],
+ ['a single partial upload', [true], true],
+ ['a partial upload between complete ones', [false, true, false], true],
+ ])('is true exactly when some upload is partial: %s', async (_case, flags, expected) => {
+ const handler = await loadWithUploads(flags);
+ expect(handler.hasPersistentTruncated()).toBe(expected);
+ });
+
+ it('drives the placeholder page summary', async () => {
+ const handler = await loadWithUploads([true, false]);
+ vi.spyOn(handler, 'hasPersistentTruncated').mockReturnValue(false);
+
+ handler.updatePlaceholder();
+
+ expect(document.getElementById('query').placeholder)
+ .toContain('2 PDFs loaded, 6 pages total');
+ });
+
+ it('drives showSuccess wording and its hide timer', async () => {
+ const handler = await loadWithUploads([true, false]);
+ vi.useFakeTimers();
+ vi.spyOn(handler, 'hasPersistentTruncated').mockReturnValue(false);
+
+ handler.showSuccess(2, []);
+
+ const status = document.getElementById('pdf-upload-status');
+ expect(status.textContent).toContain('Successfully processed 2 PDFs');
+ expect(status.textContent).not.toContain('Only part of these PDFs');
+ expect(handler.statusTimers).toHaveLength(1);
+ await vi.advanceTimersByTimeAsync(5000);
+ expect(status.style.display).toBe('none');
+ });
+
+ it('drives the restore decision after an error', async () => {
+ const handler = await loadWithUploads([true, false]);
+ vi.useFakeTimers();
+ vi.spyOn(handler, 'hasPersistentTruncated').mockReturnValue(false);
+
+ handler.showError('A transient error');
+ const status = document.getElementById('pdf-upload-status');
+ await vi.advanceTimersByTimeAsync(5000);
+
+ expect(status.style.display).toBe('none');
+ });
+});