~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.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
fix: formatBytes shows "undefined" for sizes >= 1 TB (#4982)
Syed Osama Ali Shahea7bbcf17553
diff --git a/changelog.d/+format-bytes-terabyte-units.bugfix.md b/changelog.d/+format-bytes-terabyte-units.bugfix.mdnew file mode 100644index 0000000000..fefed9e9c3--- /dev/null+++ b/changelog.d/+format-bytes-terabyte-units.bugfix.md@@ -0,0 +1 @@+Fixed `formatBytes` rendering sizes of 1 TB or larger as `"N undefined"` (e.g. a library blob total of 1 TB showed as `1 undefined`). The shared byte formatter only defined units up to GB; it now covers TB through EB and clamps the unit index at both ends, so very large values no longer index past the end of the unit list and sub-1-byte values no longer produce a negative index.diff --git a/src/local_deep_research/web/static/js/utils/format-bytes.js b/src/local_deep_research/web/static/js/utils/format-bytes.jsindex 3c8a614db9..35ec7f5643 100644--- a/src/local_deep_research/web/static/js/utils/format-bytes.js+++ b/src/local_deep_research/web/static/js/utils/format-bytes.js@@ -17,8 +17,11 @@function formatBytes(bytes) {if (bytes === 0) return '0 Bytes';const k = 1024;- const sizes = ['Bytes', 'KB', 'MB', 'GB'];- const i = Math.floor(Math.log(bytes) / Math.log(k));+ const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'];+ // Clamp both ends: the upper bound stops indexing past the unit list+ // for very large values, and the lower bound keeps sub-1-byte inputs+ // (log < 0) from producing a negative index -> undefined unit.+ const i = Math.max(0, Math.min(Math.floor(Math.log(bytes) / Math.log(k)), sizes.length - 1));return parseFloat((bytes / k ** i).toFixed(2)) + ' ' + sizes[i];}diff --git a/tests/js/utils/format-bytes.test.js b/tests/js/utils/format-bytes.test.jsindex 30ee4b64bf..6253323305 100644--- a/tests/js/utils/format-bytes.test.js+++ b/tests/js/utils/format-bytes.test.js@@ -41,4 +41,19 @@ describe('formatBytes', () => {expect(formatBytes(1024 * 1024 - 1)).toContain('KB');expect(formatBytes(1024 * 1024)).toContain('MB');});++ it('formats terabyte-and-larger sizes without "undefined"', () => {+ // Regression: sizes only went up to GB, so i>=4 yielded "N undefined".+ expect(formatBytes(1024 ** 4)).toBe('1 TB');+ expect(formatBytes(5 * 1024 ** 4)).toBe('5 TB');+ expect(formatBytes(1024 ** 5)).toBe('1 PB');+ expect(formatBytes(1024 ** 6)).toBe('1 EB');+ // Beyond the largest unit, clamp to EB rather than emit undefined.+ expect(formatBytes(1024 ** 7)).toBe('1024 EB');+ });++ it('handles sub-1-byte values without a negative index (lower-bound clamp)', () => {+ // log(bytes) < 0 for bytes < 1 would give a negative index -> undefined.+ expect(formatBytes(0.5)).toBe('0.5 Bytes');+ });});