Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix(parser): reject empty Understanding files (#4356)

Qin Haojiefd35c06f0bb1
diff --git a/openviking/parse/understanding_api.py b/openviking/parse/understanding_api.py
index fd772914b..8e80a3a2f 100644
--- a/openviking/parse/understanding_api.py
+++ b/openviking/parse/understanding_api.py
@@ -37,6 +37,7 @@ from openviking.parse.parsers.media.constants import (
)
from openviking.storage.viking_fs import get_viking_fs
from openviking.utils.zip_safe import normalize_zip_filenames, safe_extract_zip
+from openviking_cli.exceptions import InvalidArgumentError
from openviking_cli.utils.logger import get_logger
logger = get_logger(__name__)
@@ -333,6 +334,8 @@ class UnderstandingAPI(BaseParser):
async def _create_file(self, *, local_path: Path) -> Dict[str, Any]:
file_size = local_path.stat().st_size
+ if file_size == 0:
+ raise InvalidArgumentError("Understanding parser does not support empty files.")
if file_size > self._upload_simple_max_bytes:
if not self._enable_resumable_upload:
raise ValueError(
diff --git a/tests/parse/test_understanding_api.py b/tests/parse/test_understanding_api.py
index 021f746c6..9b92590c5 100644
--- a/tests/parse/test_understanding_api.py
+++ b/tests/parse/test_understanding_api.py
@@ -4,6 +4,7 @@ from unittest.mock import AsyncMock
import pytest
from openviking.parse.understanding_api import UnderstandingAPI
+from openviking_cli.exceptions import InvalidArgumentError
@pytest.mark.asyncio
@@ -56,10 +57,21 @@ async def test_parse_uses_downloaded_file_and_resolved_extension(monkeypatch, tm
@pytest.mark.asyncio
-async def test_submit_file_returns_response_id(tmp_path):
+async def test_submit_file_validates_input_and_returns_response_id(tmp_path):
+ empty_source = tmp_path / "empty.pdf"
+ empty_source.touch()
+ api = UnderstandingAPI.__new__(UnderstandingAPI)
+
+ with pytest.raises(
+ InvalidArgumentError,
+ match="Understanding parser does not support empty files",
+ ) as exc_info:
+ await api.submit_file(empty_source)
+
+ assert exc_info.value.code == "INVALID_ARGUMENT"
+
source = tmp_path / "download.pdf"
source.write_bytes(b"%PDF-1.7")
- api = UnderstandingAPI.__new__(UnderstandingAPI)
api._create_file = AsyncMock(return_value={"id": "file-1"})
api._create_response_for_file = AsyncMock(return_value={"id": "response-1"})