From 6186dae83f94808bf8121c7b778fc81adf8b0b79 Mon Sep 17 00:00:00 2001 From: Yiorgis Gozadinos Date: Thu, 13 Aug 2026 11:32:07 +0300 Subject: [PATCH] Move ingester telemetry setup behind argument parsing --- CHANGELOG.md | 2 +- haiku_rag_slim/haiku/rag/ingester/cli.py | 8 ++++---- tests/ingester/test_cli.py | 12 +++++++----- tests/test_cli.py | 12 +++++++----- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4752b636..c6ab455e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Fixed - `cross-encoder` reranking no longer ties the scores of strongly-relevant candidates, which left their order to the sort. Scores remain 0-1. -- haiku-rag CLI startup no longer imports `lancedb`, `pyarrow` and `pydantic_ai`. +- `haiku-rag` and `haiku-ingester` CLI startup no longer imports `lancedb`, `pyarrow` and `pydantic_ai`. - `haiku.rag.store` no longer re-exports `Store`; import it from `haiku.rag.store.engine`. ## [0.73.0] - 2026-08-06 diff --git a/haiku_rag_slim/haiku/rag/ingester/cli.py b/haiku_rag_slim/haiku/rag/ingester/cli.py index 0caf90eb..eb6d62e6 100644 --- a/haiku_rag_slim/haiku/rag/ingester/cli.py +++ b/haiku_rag_slim/haiku/rag/ingester/cli.py @@ -59,15 +59,15 @@ def main( ) -> None: """Top-level callback so every subcommand inherits --config without each one redeclaring it. Mirrors haiku-rag's CLI shape.""" + from haiku.rag.telemetry import configure as configure_telemetry + _load_config_with_override(config) + configure_cli_logging() + configure_telemetry(service_name="haiku-ingester") def cli() -> None: """Entry point that translates store-state errors into a clean exit.""" - from haiku.rag.telemetry import configure as configure_telemetry - - configure_cli_logging() - configure_telemetry(service_name="haiku-ingester") try: _cli() except (MigrationRequiredError, ReadOnlyError) as e: diff --git a/tests/ingester/test_cli.py b/tests/ingester/test_cli.py index c32e3c48..793fd7e6 100644 --- a/tests/ingester/test_cli.py +++ b/tests/ingester/test_cli.py @@ -26,15 +26,17 @@ from haiku.rag.ingester.queue.models import JobOp runner = CliRunner() -def test_importing_ingester_cli_does_not_load_lancedb(): - """Test that lancedb is not imported automatically by the cli. Doing so is - expensive. Must be run in a subprocess because lancedb might be imported by - other tests in the same session.""" +def test_importing_ingester_cli_does_not_load_heavy_dependencies(): + """Importing the CLI must not pull the heavy runtime dependencies; they cost + seconds of startup. Runs in a subprocess because another test in the same + session may already have imported them.""" result = subprocess.run( [ sys.executable, "-c", - "import haiku.rag.ingester.cli, sys; assert 'lancedb' not in sys.modules", + "import haiku.rag.ingester.cli, sys; " + "loaded = {'lancedb', 'pyarrow', 'pydantic_ai'} & sys.modules.keys(); " + "assert not loaded, loaded", ], capture_output=True, text=True, diff --git a/tests/test_cli.py b/tests/test_cli.py index 4e00cbb2..5abee1a3 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -14,15 +14,17 @@ from haiku.rag.store.exceptions import MigrationRequiredError runner = CliRunner() -def test_importing_cli_does_not_load_lancedb(): - """Test that lancedb is not imported automatically by the cli. Doing so is - expensive. Must be run in a subprocess because lancedb might be imported by - other tests in the same session.""" +def test_importing_cli_does_not_load_heavy_dependencies(): + """Importing the CLI must not pull the heavy runtime dependencies; they cost + seconds of startup. Runs in a subprocess because another test in the same + session may already have imported them.""" result = subprocess.run( [ sys.executable, "-c", - "import haiku.rag.cli, sys; assert 'lancedb' not in sys.modules", + "import haiku.rag.cli, sys; " + "loaded = {'lancedb', 'pyarrow', 'pydantic_ai'} & sys.modules.keys(); " + "assert not loaded, loaded", ], capture_output=True, text=True,