Skip to content

Self-hosted AI workspace.

Python

Fix vision attachment timeout and stale cache

Juan Pablo Jiménez051413bff546
diff --git a/src/chat_handler.py b/src/chat_handler.py
index 0110ddb4f..ccfcd4cd6 100644
--- a/src/chat_handler.py
+++ b/src/chat_handler.py
@@ -223,19 +223,22 @@ class ChatHandler:
if os.path.exists(_vcache):
try:
with open(_vcache) as _vf:
- vl_desc = _vf.read()
+ cached_desc = _vf.read().strip()
+ if cached_desc and not cached_desc.startswith("["):
+ vl_desc = cached_desc
except Exception:
vl_desc = None
if not vl_desc:
vl_result = analyze_image_with_vl_result(file_info["path"])
vl_desc = vl_result.get("text", "")
vl_model = vl_result.get("model", "")
- try:
- os.makedirs(os.path.join(UPLOAD_DIR, ".vision"), exist_ok=True)
- with open(_vcache, "w") as _vf:
- _vf.write(vl_desc or "")
- except Exception:
- pass
+ if vl_desc and not vl_desc.startswith("["):
+ try:
+ os.makedirs(os.path.join(UPLOAD_DIR, ".vision"), exist_ok=True)
+ with open(_vcache, "w") as _vf:
+ _vf.write(vl_desc)
+ except Exception:
+ pass
enhanced_message = f"{enhanced_message}\n\n[Image: {file_info['name']}]\n{vl_desc}"
# Surface the description to the client live so it renders as a
# collapsible "image description" on the user bubble (not just
diff --git a/src/document_processor.py b/src/document_processor.py
index 5493f89f9..7b88cbb01 100644
--- a/src/document_processor.py
+++ b/src/document_processor.py
@@ -230,7 +230,7 @@ def analyze_image_with_vl_result(image_path: str) -> dict:
last_err = None
for i, (_url, _model, _headers) in enumerate([c for c in _vl_candidates if c and c[0] and c[1]]):
try:
- description = llm_call(_url, _model, vl_messages, headers=_headers, timeout=30)
+ description = llm_call(_url, _model, vl_messages, headers=_headers, timeout=120)
logger.info("VL analysis complete with model %s", _model)
return {"text": description, "model": _model}
except Exception as e: