#1407·khoj

:latest (1.42.10) crashes on OpenAI-compatible backends that omit content on role/finish chunks — fix exists on main, never backported

Author: inman-sebastianCreated Aug 20, 2026Updated Aug 20, 2026

What happened

Running khoj against a local, spec-compliant OpenAI-compatible inference server (oMLX — https://github.com/jundot/omlx), every /api/chat call fails once the model starts responding, with:

TypeError: can only concatenate str (not "NoneType") to str

Traceback bottoms out in ain_stream_thought_processor() (src/khoj/processor/conversation/openai/utils.py:613 in 1.42.10):

buf += chunk.choices[0].delta.content

Root cause

The backend's streamed chunks omit the content key entirely on the role-announcement chunk and the finish_reason chunk — which the openai SDK deserializes as None. That's valid per the OpenAI streaming spec and is what several non-OpenAI-official servers do. Confirmed directly against the raw SSE stream before assuming it was a khoj bug:

data: {"choices":[{"index":0,"delta":{"role":"assistant"}}]}
data: {"choices":[{"index":0,"delta":{"content":"PONG! "}}]}
data: {"choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

This is already fixed — just not released

d57c597 (https://github.com/khoj-ai/khoj/commit/d57c59724568be4f8a8c3c4e310eda6f158a6d62, 2025-11-16) adds exactly this None-guard on main. But that commit landed after khoj moved to the 2.0.0-beta.x line — there was no 1.43.x (or later 1.42.x) point release, and ghcr.io/khoj-ai/khoj:latest still resolves to 1.42.10 (2025-07-15), four months before the fix. So anyone pulling :latest today — which is presumably most self-hosted/Docker users — still hits this.

Ask

Would you consider either:

  • backporting d57c597 to a 1.42.x point release, or
  • repointing :latest at the 2.0.0-beta line (or documenting that self-hosters should pin a beta tag instead of :latest for now)

Happy to open a backport PR against a maintenance branch if one exists / if that's the preferred path.

Aside: also hit a SynchronousOnlyOperation crash on 1.42.10

Separately, /api/chat also 500s via ConversationAdapters.get_default_chat_model() (a sync Django ORM call) being invoked from send_message_to_model_wrapper_sync() inside an async request handler — Django's asgiref raises SynchronousOnlyOperation. I'm flagging this for awareness only: the relevant code has clearly been refactored significantly since 1.42.10 (e.g. api_chat.py's main handler no longer calls get_default_chat_model directly), so I can't confirm whether it still reproduces on main/2.0.0-beta, and I haven't been able to verify it there. Not asking for action on this one without a repro against current main.

Environment

  • khoj: ghcr.io/khoj-ai/khoj:latest → v1.42.10, Docker
  • Backend: oMLX (OpenAI+Anthropic-compatible local inference server), not OpenAI