Skip to content

fix(cli): preload deferred rich/typer modules before in-place upgrade#966

Merged
groksrc merged 1 commit into
mainfrom
fix/preload-lazy-imports-before-upgrade
Jun 11, 2026
Merged

fix(cli): preload deferred rich/typer modules before in-place upgrade#966
groksrc merged 1 commit into
mainfrom
fix/preload-lazy-imports-before-upgrade

Conversation

@groksrc

@groksrc groksrc commented Jun 11, 2026

Copy link
Copy Markdown
Member

Problem

Every successful bm update (Homebrew or uv tool install) ends with a crash from the old process:

ImportError: cannot import name 'rich_utils' from 'typer' ...
ModuleNotFoundError: No module named 'rich._emoji_codes'

brew upgrade basic-memory removes the old keg (e.g. Cellar/basic-memory/0.21.6/) while the 0.21.6 Python process that launched it is still running. When run_auto_update returns and the CLI prints the final status via rich, rich lazily imports rich._emoji_codes from files that no longer exist — and typer's excepthook then fails the same way trying to lazily import typer.rich_utils to render the traceback. The upgrade itself succeeds; it's the dying process crashing on its last words.

Fix

Import both deferred modules in run_auto_update immediately before launching the upgrade subprocess, while this install's files still exist. Covers both bm update and the periodic auto-update path.

Verification

  • New regression test pops the modules from sys.modules, calls the preload, asserts they're back.
  • uv run pytest tests/cli/test_auto_update.py tests/cli/test_update_command.py — 24 passed.
  • just lint + just typecheck clean.

🤖 Generated with Claude Code

brew upgrade / uv tool upgrade delete the running install's files while the old process is still alive. rich defers importing rich._emoji_codes until print time and typer defers typer.rich_utils until excepthook time, so printing the post-upgrade status message crashed the exiting process with ModuleNotFoundError (and the traceback renderer crashed too). Import both before launching the upgrade subprocess, while the files still exist.

Signed-off-by: Drew Cain <groksrc@gmail.com>
@groksrc

groksrc commented Jun 11, 2026

Copy link
Copy Markdown
Member Author

CI note: the Test SQLite Integration (ubuntu-latest, Python 3.14) failure was test_mcp_sse_forces_local, the known timing flake tracked in #940 (this PR doesn't touch the MCP command path). Re-ran the failed job.

@groksrc groksrc merged commit 497a4e0 into main Jun 11, 2026
37 of 38 checks passed
@groksrc groksrc deleted the fix/preload-lazy-imports-before-upgrade branch June 11, 2026 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant