From 4a040688185aa8099c59d2532a0675c307ffb6f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Jim=C3=A9nez?= <61767851+juanp-ctrl@users.noreply.github.com> Date: Sun, 31 May 2026 21:04:46 -0500 Subject: [PATCH] Fix vision attachment timeout and stale cache Increase local vision model timeout and avoid caching transient VL failure placeholders.\n\nCloses #202. --- src/chat_handler.py | 17 ++++++++++------- src/document_processor.py | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/chat_handler.py b/src/chat_handler.py index 0110ddb..ccfcd4c 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 5493f89..7b88cbb 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: