bare except in VDB text_exists() swallows KeyboardInterrupt/SystemExit
- Dominant language
- TypeScript
- Stars
- 156k
- Forks
- 24.6k
- Avg merge
- 22h 9m
- Merged PRs (30d)
- 610
Description
### Self Checks
- [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542).
- [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general).
- [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones.
- [x] I confirm that I am using English to submit this report, otherwise it will be closed.
- [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
- [x] Please do not modify this template :) and fill in all the required fields.
## 1. Environment
- Dify version: main (f5e1f1590f)
## 2. Describe the problem
The `text_exists()` methods in the OpenSearch and Lindorm vector backends use a bare `except:` that catches every exception, including `KeyboardInterrupt` and `SystemExit`:
- `api/providers/vdb/vdb-opensearch/src/dify_vdb_opensearch/opensearch_vector.py:194`
- `api/providers/vdb/vdb-lindorm/src/dify_vdb_lindorm/lindorm_vector.py:251`
```python
def text_exists(self, id: str) -> bool:
try:
self._client.get(index=self._collection_name.lower(), id=id)
return True
except: # catches KeyboardInterrupt / SystemExit too
return False
```
A user pressing Ctrl+C (or a worker shutting down) mid-call gets the interrupt silently swallowed and the document reported as "does not exist".
## 3. Steps to reproduce
1. Configure the vector store as OpenSearch or Lindorm.
2. Call `text_exists()` and interrupt the process during the `get` call.
## 4. ✔️ Expected Behavior
Only "document not found" (HTTP 404) errors are caught and reported as `False`; `KeyboardInterrupt`/`SystemExit` and other transport errors propagate normally.
## 5. ❌ Actual Behavior
The bare `except:` swallows `KeyboardInterrupt`/`SystemExit`, hiding real exits.
## 6. Fix
`opensearchpy` raises `NotFoundError` for HTTP 404 responses (missing documents), so narrow the handler to `except NotFoundError:`. Keep the existing `BulkIndexError` import (still used by `delete_by_ids()`) and add the `NotFoundError` import. Unit tests are updated accordingly to raise `NotFoundError` instead of a generic `RuntimeError`.
Contributor guide
Research direction
Start with text_exists() in api/providers/vdb/vdb-opensearch/src/dify_vdb_opensearch/opensearch_vector.py and api/providers/vdb/vdb-lindorm/src/dify_vdb_lindorm/lindorm_vector.py. Review the existing unit tests, update their missing-document cases to use the documented not-found exception, and verify that only missing documents return False while other exceptions propagate.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 84/100