fix(cli): preload deferred rich/typer modules before in-place upgrade#966
Merged
Conversation
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>
Member
Author
|
CI note: the |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Every successful
bm update(Homebrew or uv tool install) ends with a crash from the old process:brew upgrade basic-memoryremoves the old keg (e.g.Cellar/basic-memory/0.21.6/) while the 0.21.6 Python process that launched it is still running. Whenrun_auto_updatereturns and the CLI prints the final status via rich, rich lazily importsrich._emoji_codesfrom files that no longer exist — and typer's excepthook then fails the same way trying to lazily importtyper.rich_utilsto 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_updateimmediately before launching the upgrade subprocess, while this install's files still exist. Covers bothbm updateand the periodic auto-update path.Verification
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 typecheckclean.🤖 Generated with Claude Code