You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(cli): prevent analytics thread from blocking command exit - #1342
The CLI analytics helper starts a background request thread for the cloud promo path. Because the thread was non-daemon, one-shot commands such as bm schema validate could finish their work and output while Python interpreter shutdown waited indefinitely for the analytics request.
This change makes the best-effort analytics thread daemonized, so analytics cannot keep the CLI process alive. The existing request timeout and silent failure behavior are unchanged. A regression assertion verifies the thread is created as a daemon.
Tests
uv run --frozen pytest tests/cli/test_analytics.py tests/cli/test_cli_schema.py -q --no-cov (28 passed)
uv run --frozen ruff check src/basic_memory/cli/analytics.py tests/cli/test_analytics.py
uv run --frozen ruff format --check src/basic_memory/cli/analytics.py tests/cli/test_analytics.py
Thanks for looking at #1333. I dug into it with a clean-env repro on 3.13, and the analytics thread turns out not to be the cause: the hang reproduces non-interactively, where the promo (and therefore track()) never runs, and the surviving thread in both my dump and the reporter's sample is an AnyIO worker thread parked in queue.get, not a socket wait. bm tool schema-validate also runs the same promo callback and exits fine.
The actual cause is nest_asyncio (applied in alembic/env.py on Python < 3.14) swallowing the done-callback anyio uses to stop its worker, plus a sync FastAPI dependency that dispatched one — fixed in #1349. The analytics thread being non-daemon is deliberate (the 3s request timeout bounds it), so I'd rather not flip it as part of this bug. Closing in favour of #1349; appreciate the PR.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1333
Summary
The CLI analytics helper starts a background request thread for the cloud promo path. Because the thread was non-daemon, one-shot commands such as
bm schema validatecould finish their work and output while Python interpreter shutdown waited indefinitely for the analytics request.This change makes the best-effort analytics thread daemonized, so analytics cannot keep the CLI process alive. The existing request timeout and silent failure behavior are unchanged. A regression assertion verifies the thread is created as a daemon.
Tests
uv run --frozen pytest tests/cli/test_analytics.py tests/cli/test_cli_schema.py -q --no-cov(28 passed)uv run --frozen ruff check src/basic_memory/cli/analytics.py tests/cli/test_analytics.pyuv run --frozen ruff format --check src/basic_memory/cli/analytics.py tests/cli/test_analytics.pygit diff --check