Summary
GET /api/update returns HTTP 500 (Failed to update content index) on a fresh Khoj 2.0.0b28 install when the default t=all search type is used. Scoping to t=markdown (or any non-image, non-docx type) works correctly.
Root cause
In khoj/routers/helpers.py::configure_content(), the image and docx branches use bracket lookup on files:
# line ~3142 (image)
if (search_type == state.SearchType.All.value or search_type == state.SearchType.Image.value) and files["image"]:
# line ~3157 (docx)
if (search_type == state.SearchType.All.value or search_type == state.SearchType.Docx.value) and files["docx"]:
Every other content type in the same function uses files.get(...) and is safe against a missing key:
# org (~3024), markdown (~3046), pdf (~3064), plaintext (~3082)
if ... and files.get("markdown"):
When a client (or a call from /api/update) does not populate files with "image" and "docx" keys, the bracket lookup raises KeyError. The inner try/except Exception on those two blocks catches it, logs Failed to setup images: 'image' / Failed to setup docx: 'docx', and sets success = False. The outer caller then raises RuntimeError("Failed to update content index") -> 500.
Logs from affected install
🚨 Failed to setup images: 'image'
Traceback (most recent call last):
KeyError: 'image'
🚨 Failed to setup docx: 'docx'
Traceback (most recent call last):
KeyError: 'docx'
🚨 Failed to update server indexed content via API: Failed to update content index
Workaround
Scope the request to a non-image, non-docx type:
GET /api/update?force=true&t=markdown
Short-circuits the two buggy guards before the bracket lookup.
Suggested fix
Two-character change:
- ) and files["image"]:
+ ) and files.get("image"):
And the same for files["docx"]. Consistent with how every other file-type branch already works in the same function.
Environment
- Khoj: 2.0.0b28 (from PyPI, 2026-03-26 release)
- Python: 3.12
- OS: macOS 15.4 (Apple Silicon)
- Deployment: native process,
--no-gui, single-user
Summary
GET /api/updatereturns HTTP 500 (Failed to update content index) on a fresh Khoj 2.0.0b28 install when the defaultt=allsearch type is used. Scoping tot=markdown(or any non-image, non-docx type) works correctly.Root cause
In
khoj/routers/helpers.py::configure_content(), theimageanddocxbranches use bracket lookup onfiles:Every other content type in the same function uses
files.get(...)and is safe against a missing key:When a client (or a call from
/api/update) does not populatefileswith"image"and"docx"keys, the bracket lookup raisesKeyError. The innertry/except Exceptionon those two blocks catches it, logsFailed to setup images: 'image'/Failed to setup docx: 'docx', and setssuccess = False. The outer caller then raisesRuntimeError("Failed to update content index")-> 500.Logs from affected install
Workaround
Scope the request to a non-image, non-docx type:
Short-circuits the two buggy guards before the bracket lookup.
Suggested fix
Two-character change:
And the same for
files["docx"]. Consistent with how every other file-type branch already works in the same function.Environment
--no-gui, single-user