Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

fix: require confirmed LightRAG rebuild configuration

NoxsMedia7847197dd4f3
diff --git a/deeptutor/api/routers/knowledge.py b/deeptutor/api/routers/knowledge.py
index 8a5a646b7..9c0ec14ad 100644
--- a/deeptutor/api/routers/knowledge.py
+++ b/deeptutor/api/routers/knowledge.py
@@ -3488,9 +3488,14 @@ async def reindex_knowledge_base(
detail="Configure LightRAG models in Settings; per-knowledge-base overrides are no longer supported.",
)
if kb_provider == LIGHTRAG_PROVIDER:
+ if not config_fingerprint:
+ raise HTTPException(
+ status_code=409,
+ detail="Review the current rebuild configuration and confirm before rebuilding.",
+ )
indexing_snapshot = _freeze_default_indexing_llm()
- if indexing_snapshot is not None and config_fingerprint:
+ if indexing_snapshot is not None:
from deeptutor.services.rag.pipelines.lightrag.indexing_policy import (
public_rebuild_config,
)
diff --git a/tests/api/test_knowledge_router.py b/tests/api/test_knowledge_router.py
index e01ad8962..6cc8b83f6 100644
--- a/tests/api/test_knowledge_router.py
+++ b/tests/api/test_knowledge_router.py
@@ -2453,10 +2453,15 @@ def test_reindex_passes_frozen_lightrag_snapshot_to_background_task(
lambda: snapshot,
)
monkeypatch.setattr(knowledge_router_module, "run_reindex_task", capture_task)
+ monkeypatch.setattr(
+ "deeptutor.services.rag.pipelines.lightrag.indexing_policy.public_rebuild_config",
+ lambda accepted: {"fingerprint": "confirmed"} if accepted is snapshot else {},
+ )
with TestClient(_build_app()) as client:
response = client.post(
"/api/knowledge-bases/kb/reindex",
+ data={"config_fingerprint": "confirmed"},
)
assert response.status_code == 200
diff --git a/tests/services/rag/test_lightrag_roles.py b/tests/services/rag/test_lightrag_roles.py
index 56f0d8218..9aab8022d 100644
--- a/tests/services/rag/test_lightrag_roles.py
+++ b/tests/services/rag/test_lightrag_roles.py
@@ -901,15 +901,16 @@ def test_task_publishes_actual_frozen_embedding_after_defaults_change(
assert "fake" not in json.dumps(meta)
[email protected]("status", ["ready", "error"])
def test_rebuild_confirmation_rejects_changed_defaults_without_queueing(
- role_environment, tmp_path, monkeypatch
+ role_environment, tmp_path, monkeypatch, status
):
from fastapi import FastAPI
from fastapi.testclient import TestClient
from deeptutor.api.routers import knowledge
- entry = {"rag_provider": "lightrag", "status": "ready"}
+ entry = {"rag_provider": "lightrag", "status": status}
monkeypatch.setattr(knowledge, "_writable_kb", lambda _name: (object(), "kb", tmp_path))
monkeypatch.setattr(knowledge, "_load_kb_entry_or_404", lambda *_a: entry)
monkeypatch.setattr(knowledge, "_assert_provider_ready", lambda _provider: None)
@@ -926,6 +927,11 @@ def test_rebuild_confirmation_rejects_changed_defaults_without_queueing(
app = FastAPI()
app.include_router(knowledge.router, prefix="/api")
with TestClient(app) as client:
+ for data in ({}, {"config_fingerprint": ""}):
+ response = client.post("/api/knowledge-bases/kb/reindex", data=data)
+ assert response.status_code == 409
+ assert "confirm" in response.json()["detail"]
+ assert not queued and not captured
preview = client.get("/api/knowledge-bases/kb/reindex-config")
assert preview.status_code == 200
payload = preview.json()