Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix: remove unencrypted file writes for user data

LearningCircuit7fee0b24ed97
diff --git a/.github/scripts/check-file-writes.sh b/.github/scripts/check-file-writes.sh
index 01ae6869e8..a09bdfb98a 100755
--- a/.github/scripts/check-file-writes.sh
+++ b/.github/scripts/check-file-writes.sh
@@ -55,6 +55,10 @@ EXCLUDE_DIRS=(
"build"
".next"
"coverage"
+ "examples"
+ "scripts"
+ ".github"
+ "cookiecutter-docker"
)
# Files to exclude
@@ -100,27 +104,30 @@ ALL_MATCHES=""
echo "Scanning codebase for suspicious patterns..."
+# Search only in src/ directory to avoid .venv and other non-source directories
+SEARCH_PATHS="src/"
+
# Single pass to collect all matches
for pattern in "${SUSPICIOUS_PATTERNS[@]}"; do
# Use grep with binary files excluded and max line length to avoid issues with minified files
- matches=$(grep -rn -I -- "$pattern" . $EXCLUDE_ARGS --include="*.py" --include="*.js" --include="*.ts" 2>/dev/null | head -1000 || true)
+ matches=$(grep -rn -I -- "$pattern" $SEARCH_PATHS $EXCLUDE_ARGS --include="*.py" --include="*.js" --include="*.ts" 2>/dev/null | head -1000 || true)
if [ -n "$matches" ]; then
ALL_MATCHES="$ALL_MATCHES$matches\n"
fi
done
# Also check for specific problematic patterns in one pass
-temp_matches=$(grep -rn -I -E "get_report_as_temp_file|tmp_path|tempfile|/tmp/" . $EXCLUDE_ARGS --include="*.py" 2>/dev/null | head -500 || true)
+temp_matches=$(grep -rn -I -E "get_report_as_temp_file|tmp_path|tempfile|/tmp/" $SEARCH_PATHS $EXCLUDE_ARGS --include="*.py" 2>/dev/null | head -500 || true)
if [ -n "$temp_matches" ]; then
ALL_MATCHES="$ALL_MATCHES$temp_matches\n"
fi
-db_matches=$(grep -rn -I -E "report_content.*open|report_content.*write|markdown_content.*open|markdown_content.*write" . $EXCLUDE_ARGS --include="*.py" 2>/dev/null | head -500 || true)
+db_matches=$(grep -rn -I -E "report_content.*open|report_content.*write|markdown_content.*open|markdown_content.*write" $SEARCH_PATHS $EXCLUDE_ARGS --include="*.py" 2>/dev/null | head -500 || true)
if [ -n "$db_matches" ]; then
ALL_MATCHES="$ALL_MATCHES$db_matches\n"
fi
-export_matches=$(grep -rn -I -E "export.*Path|export.*path\.open|export.*\.write" . $EXCLUDE_ARGS --include="*.py" 2>/dev/null | head -500 || true)
+export_matches=$(grep -rn -I -E "export.*Path|export.*path\.open|export.*\.write" $SEARCH_PATHS $EXCLUDE_ARGS --include="*.py" 2>/dev/null | head -500 || true)
if [ -n "$export_matches" ]; then
ALL_MATCHES="$ALL_MATCHES$export_matches\n"
fi
diff --git a/src/local_deep_research/web/services/research_service.py b/src/local_deep_research/web/services/research_service.py
index 9486bb5bd7..6c7245adb8 100644
--- a/src/local_deep_research/web/services/research_service.py
+++ b/src/local_deep_research/web/services/research_service.py
@@ -1473,29 +1473,42 @@ def run_research_process(
len(enhanced_report_content),
)
- # Save enhanced error report as the actual report file
+ # Save enhanced error report to encrypted database
try:
- reports_folder = OUTPUT_DIR
- report_filename = f"research_{research_id}_error_report.md"
- report_path = reports_folder / report_filename
-
- with open(report_path, "w", encoding="utf-8") as f:
- f.write(enhanced_report_content)
-
- logger.info(
- "Saved enhanced error report to: %s", report_path
+ # Get username from the research context
+ username = getattr(g, "username", None) or session.get(
+ "username"
)
+ if username:
+ from ...storage import get_report_storage
- # Store the report path so it can be retrieved later
- report_path_to_save = str(
- report_path.relative_to(reports_folder.parent)
- )
+ with get_user_db_session(username) as db_session:
+ storage = get_report_storage(session=db_session)
+ success = storage.save_report(
+ research_id=research_id,
+ content=enhanced_report_content,
+ metadata={"error_report": True},
+ username=username,
+ )
+ if success:
+ logger.info(
+ "Saved enhanced error report to encrypted database for research %s",
+ research_id,
+ )
+ else:
+ logger.warning(
+ "Failed to save enhanced error report to database for research %s",
+ research_id,
+ )
+ else:
+ logger.warning(
+ "Cannot save error report: username not available"
+ )
except Exception as report_error:
logger.exception(
"Failed to save enhanced error report: %s", report_error
)
- report_path_to_save = None
except Exception as error_gen_error:
logger.exception(
@@ -1503,7 +1516,6 @@ def run_research_process(
error_gen_error,
)
enhanced_report_content = None
- report_path_to_save = None
# Get existing metadata from database first
existing_metadata = {}
@@ -1596,11 +1608,6 @@ def run_research_process(
from ..queue.processor import queue_processor
if username:
- # Determine report path if available
- report_path_to_queue = None
- if "report_path_to_save" in locals() and report_path_to_save:
- report_path_to_queue = report_path_to_save
-
queue_processor.queue_error_update(
username=username,
research_id=research_id,
@@ -1608,7 +1615,7 @@ def run_research_process(
error_message=message,
metadata=metadata,
completed_at=completed_at,
- report_path=report_path_to_queue,
+ report_path=None,
)
logger.info(
f"Queued error update for research {research_id} with status '{status}'"
diff --git a/src/local_deep_research/web/routes/benchmark_routes.py b/src/local_deep_research/web/templates/benchmark/dashboard.html
similarity index 51%
rename from src/local_deep_research/web/routes/benchmark_routes.py
rename to src/local_deep_research/web/templates/benchmark/dashboard.html
index 679c7a8617..bc461023f1 100644
--- a/src/local_deep_research/web/routes/benchmark_routes.py
+++ b/src/local_deep_research/web/templates/benchmark/dashboard.html
@@ -1,240 +1,4 @@
-"""
-Web routes for benchmarking.
-This module provides Flask routes for the benchmark web interface.
-"""
-
-import threading
-from pathlib import Path
-
-from flask import Blueprint, jsonify, render_template, request
-from loguru import logger
-
-from ...api.benchmark_functions import (
- compare_configurations,
- evaluate_browsecomp,
- evaluate_simpleqa,
- evaluate_xbench_deepsearch,
- get_available_benchmarks,
-)
-
-# Create blueprint
-benchmark_bp = Blueprint("benchmark", __name__, url_prefix="/benchmark")
-
-# Store running jobs
-running_jobs = {}
-
-
-def run_benchmark_task(job_id, benchmark_type, params, callback=None):
- """
- Run a benchmark task in a separate thread.
-
- Args:
- job_id: Unique job ID
- benchmark_type: Type of benchmark to run
- params: Parameters for the benchmark
- callback: Optional callback to run when job completes
- """
- try:
- # Update job status to running
- running_jobs[job_id]["status"] = "running"
-
- # Run the benchmark based on type
- if benchmark_type == "simpleqa":
- result = evaluate_simpleqa(**params)
- elif benchmark_type == "browsecomp":
- result = evaluate_browsecomp(**params)
- elif benchmark_type == "xbench_deepsearch":
- result = evaluate_xbench_deepsearch(**params)
- elif benchmark_type == "compare":
- result = compare_configurations(**params)
- else:
- result = {"error": f"Unknown benchmark type: {benchmark_type}"}
-
- # Update job with result
- running_jobs[job_id]["status"] = "completed"
- running_jobs[job_id]["result"] = result
-
- # Call callback if provided
- if callback:
- callback(job_id, result)
-
- except Exception as e:
- logger.exception(f"Error running benchmark job {job_id}: {e!s}")
- running_jobs[job_id]["status"] = "error"
- running_jobs[job_id]["error"] = str(e)
-
-
-@benchmark_bp.route("/", methods=["GET"])
-def benchmark_dashboard():
- """Render benchmark dashboard."""
- return render_template(
- "pages/benchmark.html", benchmarks=get_available_benchmarks()
- )
-
-
-@benchmark_bp.route("/run", methods=["POST"])
-def run_benchmark_endpoint():
- """Run benchmark with specified parameters."""
- data = request.json
-
- # Extract benchmark type
- benchmark_type = data.get("benchmark_type")
- if not benchmark_type:
- return jsonify({"error": "benchmark_type is required"}), 400
-
- # Generate job ID
- import uuid
-
- job_id = str(uuid.uuid4())
-
- # Extract parameters
- params = {
- "num_examples": data.get("num_examples", 100),
- "search_iterations": data.get("search_iterations", 3),
- "questions_per_iteration": data.get("questions_per_iteration", 3),
- "search_tool": data.get("search_tool", "searxng"),
- "human_evaluation": data.get("human_evaluation", False),
- "output_dir": str(Path("benchmark_results") / job_id),
- }
-
- # Add optional parameters if present
- if "evaluation_model" in data:
- params["evaluation_model"] = data["evaluation_model"]
- if "evaluation_provider" in data:
- params["evaluation_provider"] = data["evaluation_provider"]
-
- # Store job info
- import time
-
- running_jobs[job_id] = {
- "id": job_id,
- "benchmark_type": benchmark_type,
- "params": params,
- "status": "pending",
- "start_time": time.time(),
- }
-
- # Start job in background thread
- thread = threading.Thread(
- target=run_benchmark_task, args=(job_id, benchmark_type, params)
- )
- thread.daemon = True
- thread.start()
-
- return jsonify(
- {
- "status": "started",
- "job_id": job_id,
- "message": f"Benchmark job started: {benchmark_type}",
- }
- )
-
-
-@benchmark_bp.route("/status/<job_id>", methods=["GET"])
-def benchmark_status(job_id):
- """Get status of a benchmark job."""
- if job_id not in running_jobs:
- return jsonify({"error": "Job not found"}), 404
-
- job = running_jobs[job_id]
-
- # Calculate runtime if job is running
- if job["status"] == "running":
- import time
-
- job["runtime"] = time.time() - job["start_time"]
-
- return jsonify(job)
-
-
-@benchmark_bp.route("/results/<job_id>", methods=["GET"])
-def benchmark_results(job_id):
- """Get results of a completed benchmark job."""
- if job_id not in running_jobs:
- return jsonify({"error": "Job not found"}), 404
-
- job = running_jobs[job_id]
-
- if job["status"] != "completed":
- return jsonify({"error": f"Job is not completed: {job['status']}"}), 400
-
- # Return job result
- return jsonify(job["result"])
-
-
-@benchmark_bp.route("/list", methods=["GET"])
-def list_benchmarks():
- """List available benchmarks."""
- return jsonify(get_available_benchmarks())
-
-
-@benchmark_bp.route("/jobs", methods=["GET"])
-def list_jobs():
- """List all benchmark jobs."""
- return jsonify(running_jobs)
-
-
-@benchmark_bp.route("/config", methods=["GET"])
-def get_benchmark_config():
- """Get benchmark configuration options."""
- return jsonify(
- {
- "search_tools": [
- {"id": "searxng", "name": "SearXNG"},
- {"id": "wikipedia", "name": "Wikipedia"},
- {"id": "arxiv", "name": "ArXiv"},
- {"id": "pubmed", "name": "PubMed"},
- {"id": "auto", "name": "Auto (Multiple Engines)"},
- ],
- "evaluation_providers": [
- {"id": "openai_endpoint", "name": "Claude (via OpenRouter)"},
- {"id": "openai", "name": "OpenAI"},
- {"id": "anthropic", "name": "Anthropic"},
- {"id": "ollama", "name": "Ollama (Local)"},
- ],
- "evaluation_models": {
- "openai_endpoint": [
- {
- "id": "anthropic/claude-3.7-sonnet",
- "name": "Claude 3.7 Sonnet",
- }
- ],
- "openai": [
- {"id": "gpt-4o", "name": "GPT-4o"},
- {"id": "gpt-4-turbo", "name": "GPT-4 Turbo"},
- {"id": "gpt-3.5-turbo", "name": "GPT-3.5 Turbo"},
- ],
- "anthropic": [
- {"id": "claude-3-opus", "name": "Claude 3 Opus"},
- {"id": "claude-3-sonnet", "name": "Claude 3 Sonnet"},
- {"id": "claude-3-haiku", "name": "Claude 3 Haiku"},
- ],
- "ollama": [
- {"id": "llama3", "name": "Llama 3"},
- {"id": "gemma:7b", "name": "Gemma 7B"},
- {"id": "mistral", "name": "Mistral"},
- ],
- },
- }
- )
-
-
-# Function to register routes with the main app
-def register_blueprint(app):
- """Register benchmark routes with the Flask app."""
- app.register_blueprint(benchmark_bp)
-
- # Create templates directory if it doesn't exist
- template_dir = Path(app.root_path).parent / "templates" / "benchmark"
- template_dir.mkdir(parents=True, exist_ok=True)
-
- # Create dashboard template if it doesn't exist
- dashboard_template = template_dir / "dashboard.html"
- if not dashboard_template.exists():
- with open(dashboard_template, "w") as f:
- f.write(
- """
{% extends "base.html" %}
{% block title %}Benchmarks{% endblock %}
{% block content %}
@@ -291,8 +55,8 @@ def register_blueprint(app):
<h2>Benchmark Status</h2>
</div>
<div class="card-body">
- <div class="progress mb-3">
- <div class="progress-bar" id="benchmarkProgress" role="progressbar" style="width: 0%"></div>
+ <div class="ldr-progress mb-3">
+ <div class="ldr-progress-bar" id="benchmarkProgress" role="progressbar" style="width: 0%"></div>
</div>
<p id="statusMessage">Initializing benchmark...</p>
<button class="btn btn-secondary" id="viewResults" style="display: none;">View Results</button>
@@ -419,7 +183,3 @@ def register_blueprint(app):
}
</script>
{% endblock %}
- """
- )
-
- logger.info("Benchmark routes registered")