Merge pull request #2161 from alphaliujin/fix/mineru-readiness-home

fix(readiness): fail closed when the MinerU model cache root is unreadable
This commit is contained in:
Bingxi Zhao
2026-10-31 18:30:24 +08:00
committed by GitHub
4 changed files with 54 additions and 13 deletions

View File

@@ -214,6 +214,7 @@ RUN mkdir -p \
# skipped (no CAP_SETUID) and UID 1000 matches the typical host user.
RUN groupadd --system --gid 1000 deeptutor \
&& useradd --system --uid 1000 --gid 1000 --no-create-home --shell /usr/sbin/nologin deeptutor \
&& install -d -o deeptutor -g deeptutor -m 0755 /home/deeptutor \
&& chown -R deeptutor:deeptutor /app/data /app/web/.next
# supervisord config is split into two files so the production and development
@@ -259,7 +260,7 @@ stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
stderr_logfile=/dev/fd/2
stderr_logfile_maxbytes=0
environment=PYTHONPATH="/app",PYTHONUNBUFFERED="1"
environment=PYTHONPATH="/app",PYTHONUNBUFFERED="1",HOME="/home/deeptutor"
[program:frontend]
command=/bin/bash /app/start-frontend.sh
@@ -272,7 +273,7 @@ stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
stderr_logfile=/dev/fd/2
stderr_logfile_maxbytes=0
environment=NODE_ENV="production"
environment=NODE_ENV="production",HOME="/home/deeptutor"
EOF
RUN sed -i 's/\r$//' /etc/supervisor/conf.d/programs.conf
@@ -599,7 +600,7 @@ stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
stderr_logfile=/dev/fd/2
stderr_logfile_maxbytes=0
environment=PYTHONPATH="/app",PYTHONUNBUFFERED="1"
environment=PYTHONPATH="/app",PYTHONUNBUFFERED="1",HOME="/home/deeptutor"
[program:frontend]
command=/bin/bash -c "cd /app/web && node scripts/dev.mjs -H 0.0.0.0 -p ${FRONTEND_PORT:-3782}"
@@ -612,7 +613,7 @@ stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
stderr_logfile=/dev/fd/2
stderr_logfile_maxbytes=0
environment=NODE_ENV="development"
environment=NODE_ENV="development",HOME="/home/deeptutor"
EOF
RUN sed -i 's/\r$//' /etc/supervisor/conf.d/programs.conf

View File

@@ -27,11 +27,14 @@ from __future__ import annotations
import asyncio
from collections import Counter
import importlib.util
import logging
from typing import Any, Literal
from deeptutor.services.config.model_catalog import SERVICE_NAMES
from deeptutor.tools.builtin import USER_TOGGLEABLE_TOOL_NAMES
logger = logging.getLogger(__name__)
ReadinessState = Literal[
"enabled_verified",
"available_disabled",
@@ -933,6 +936,10 @@ async def build_settings_readiness() -> dict[str, Any]:
engine_id, parser, config
)
except Exception:
# Keep the row fail-closed, but leave a trail: without this the
# UI only ever says "parser_probe_failed" and the real cause
# (permissions, import errors, ...) is unrecoverable.
logger.warning("Parser readiness probe failed for %r", engine_id, exc_info=True)
parser_readiness[engine_id] = {
"ready": False,
"reason": "parser_probe_failed",

View File

@@ -44,16 +44,22 @@ def _modelscope_dir() -> Path:
def mineru_models_ready(_source: str = "huggingface") -> bool:
"""Best-effort check for already-downloaded MinerU weights (fail-closed)."""
modelscope_root = _modelscope_dir()
roots = [_hf_hub_dir()]
try:
modelscope_root = _modelscope_dir()
roots = [_hf_hub_dir()]
# With MODELSCOPE_CACHE set, ModelScope stores downloaded repositories
# below <cache>/models. Keep scanning the cache root as well for existing
# installations that use the previously supported flat layout.
modelscope_models = modelscope_root / "models"
if modelscope_models.is_dir():
roots.append(modelscope_models)
roots.append(modelscope_root)
# With MODELSCOPE_CACHE set, ModelScope stores downloaded repositories
# below <cache>/models. Keep scanning the cache root as well for existing
# installations that use the previously supported flat layout.
modelscope_models = modelscope_root / "models"
if modelscope_models.is_dir():
roots.append(modelscope_models)
roots.append(modelscope_root)
except (OSError, RuntimeError):
# An unreadable cache root — e.g. a container process whose HOME
# points at another user's home, or a passwd entry without a home —
# means "cannot confirm", not "the probe crashed". Stay fail-closed.
return False
for root in roots:
try:

View File

@@ -219,6 +219,33 @@ def test_mineru_models_ready_ignores_unrelated_modelscope_repositories(
assert rd.mineru_models_ready() is False
def test_mineru_models_ready_is_fail_closed_when_cache_root_is_unreadable(
tmp_path, monkeypatch
) -> None:
"""An unreadable HOME must read as "models missing", not crash the probe.
The container backend runs as ``deeptutor`` while supervisor leaves HOME
pointing at root's home; probing ``/root/.cache`` then raises
PermissionError, which the readiness matrix used to surface as the
unactionable ``parser_probe_failed`` instead of ``models_missing``.
"""
from deeptutor.services.parsing.engines.mineru import readiness as rd
monkeypatch.setenv("HF_HOME", str(tmp_path / "empty-huggingface"))
class _UnreadableModels:
def is_dir(self) -> bool:
raise PermissionError(13, "Permission denied", "/root/.cache/modelscope/hub/models")
class _UnreadableRoot:
def __truediv__(self, _part: str) -> _UnreadableModels:
return _UnreadableModels()
monkeypatch.setattr(rd, "_modelscope_dir", lambda: _UnreadableRoot())
assert rd.mineru_models_ready() is False
def test_mineru_cloud_readiness_needs_token() -> None:
from deeptutor.services.parsing.engines.mineru.config import MinerUConfig
from deeptutor.services.parsing.engines.mineru.readiness import mineru_readiness