Skip to content

OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.

Python

fix: cli no longer reports all services started even if docling-serve fails to start (#2173)

Zephyrus3da5d0787dd3
diff --git a/src/tui/cli.py b/src/tui/cli.py
index 4df9210fb..3cee40c77 100644
--- a/src/tui/cli.py
+++ b/src/tui/cli.py
@@ -227,15 +227,18 @@ def _setup_walkthrough(
_, _, already_running = _get_service_states(container_manager, docling_manager)
if already_running:
_stop_services_cli(container_manager, docling_manager)
- _start_services_cli(container_manager, docling_manager)
+ fully_started = _start_services_cli(container_manager, docling_manager)
- console.print()
- frontend_url = f"http://localhost:{os.getenv('FRONTEND_PORT', '3000')}"
- console.print(f"[bold green]OpenRAG is running at {frontend_url}[/bold green]")
- try:
- webbrowser.open(frontend_url)
- except Exception:
- pass
+ # Only announce the app URL / open the browser once everything is up;
+ # _start_services_cli already surfaced a warning for a partial startup.
+ if fully_started:
+ console.print()
+ frontend_url = f"http://localhost:{os.getenv('FRONTEND_PORT', '3000')}"
+ console.print(f"[bold green]OpenRAG is running at {frontend_url}[/bold green]")
+ try:
+ webbrowser.open(frontend_url)
+ except Exception:
+ pass
def _collect_config(
@@ -353,11 +356,14 @@ def _start_services_cli(
console.print("Starting OpenRAG services...", style="bold")
async def _inner():
+ containers_ok = True
+ docling_ok = docling_manager.is_running()
+
# Start container services
if container_manager.is_available():
async for item in container_manager.start_services():
# start_services yields (success, message) or (success, message, replace_last)
- success = item[0]
+ containers_ok = item[0]
message = item[1]
replace_last = item[2] if len(item) > 2 else False
if replace_last:
@@ -366,24 +372,40 @@ def _start_services_cli(
else:
console.print(f" {message}")
- if not success and "error" in message.lower():
- console.print(f" [red]✗ {message}[/red]")
+ if not containers_ok:
+ statuses = await container_manager.get_service_status(force_refresh=True)
+ containers_ok = bool(statuses) and all(
+ s.status == ServiceStatus.RUNNING for s in statuses.values()
+ )
else:
console.print(" [yellow]No container runtime available[/yellow]")
+ containers_ok = False
- # Start docling
- if not docling_manager.is_running():
- success, message = await docling_manager.start()
- if success:
+ if not docling_ok:
+ docling_ok, message = await docling_manager.start()
+ if docling_ok:
console.print(f" {message}")
else:
console.print(f" [yellow]{message}[/yellow]")
+ return containers_ok, docling_ok
+
try:
- asyncio.run(_inner())
- console.print("[green]✓ All services started[/green]")
+ containers_ok, docling_ok = asyncio.run(_inner())
+
+ # On full success the menu header already reports "Services are running",
+ # so only surface partial/failed startup here to avoid a duplicate message.
+ results = {"containers": containers_ok, "docling-serve": docling_ok}
+ failed = [name for name, ok in results.items() if not ok]
+ if failed:
+ console.print(
+ f"[yellow]⚠ Startup incomplete: {', '.join(failed)} did not start "
+ "(run Show status for details)[/yellow]"
+ )
+ return not failed
except Exception as e:
console.print(f"[red]✗ Error starting services: {e}[/red]")
+ return False
def _stop_services_cli(
@@ -401,7 +423,7 @@ def _stop_services_cli(
console.print(f" {message}")
# Stop docling
if docling_manager.is_running():
- success, message = await docling_manager.stop()
+ _success, message = await docling_manager.stop()
console.print(f" {message}")
try:
diff --git a/tests/unit/test_cli.py b/tests/unit/test_cli.py
new file mode 100644
index 000000000..b41df2a21
--- /dev/null
+++ b/tests/unit/test_cli.py
@@ -0,0 +1,99 @@
+from types import SimpleNamespace
+
+from rich.console import Console
+
+from tui import cli
+from tui.managers.container_manager import ServiceStatus
+
+
+class StubContainerManager:
+ def __init__(self, events, available=True, statuses=None):
+ self._events = events
+ self._available = available
+ self._statuses = statuses or {}
+
+ def is_available(self):
+ return self._available
+
+ async def start_services(self):
+ for event in self._events:
+ yield event
+
+ async def get_service_status(self, force_refresh=False):
+ return self._statuses
+
+
+class StubDoclingManager:
+ def __init__(
+ self, running=False, start_result=(True, "Docling serve starting on http://localhost:5001")
+ ):
+ self._running = running
+ self._start_result = start_result
+
+ def is_running(self):
+ return self._running
+
+ async def start(self):
+ return self._start_result
+
+
+def _run(container_manager, docling_manager):
+ """Invoke the CLI helper with a recording console.
+
+ Returns (fully_started, output) — the boolean is what the walkthrough
+ gates its "OpenRAG is running" message and browser launch on.
+ """
+ original = cli.console
+ recorder = Console(record=True, width=120)
+ cli.console = recorder
+ try:
+ result = cli._start_services_cli(container_manager, docling_manager)
+ return result, recorder.export_text()
+ finally:
+ cli.console = original
+
+
+def test_full_success_prints_no_summary_line():
+ """Everything up: returns True, no warning, no redundant success line (menu header covers it)."""
+ fully_started, output = _run(
+ StubContainerManager(events=[(True, "Services started successfully", False)]),
+ StubDoclingManager(start_result=(True, "Docling serve starting on http://localhost:5001")),
+ )
+
+ assert fully_started is True
+ assert "Startup incomplete" not in output
+ assert "All services started" not in output
+
+
+def test_docling_failure_reports_partial_startup():
+ """Containers up but the docling port is taken: returns False, warns, does not claim success."""
+ fully_started, output = _run(
+ StubContainerManager(events=[(True, "Services started successfully", False)]),
+ StubDoclingManager(
+ start_result=(False, "Port 5001 on 0.0.0.0 is already in use by another process."),
+ ),
+ )
+
+ assert fully_started is False
+ assert "Startup incomplete" in output
+ assert "docling-serve" in output
+ assert "All services started" not in output
+
+
+def test_container_port_conflict_from_own_containers_is_not_a_failure():
+ """start_services reports a port conflict, but the containers are our own
+ already-running ones so the status guard must treat them as up, not failed."""
+ running = {
+ "opensearch": SimpleNamespace(status=ServiceStatus.RUNNING),
+ "openrag-backend": SimpleNamespace(status=ServiceStatus.RUNNING),
+ }
+ fully_started, output = _run(
+ StubContainerManager(
+ events=[(False, "ERROR: Port conflicts detected:", False)],
+ statuses=running,
+ ),
+ StubDoclingManager(running=True), # docling already running
+ )
+
+ assert fully_started is True
+ assert "Startup incomplete" not in output